L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a...

32
LECTURE 8 Announcements

Transcript of L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a...

Page 1: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

LECTURE 8Announcements

Page 2: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

• 3pm in the CIT lobby– We’ll be contrib-

combing!

• Sign up to get a shirt at http://tiny.cc/bgdshirts– The more signups

we get the cheaper they’ll be

on Sunday

Page 3: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

CS195U: 3D Game Engines• Running next semester!

– Timeslot probably 3p-5:20 Wed

• Requires 123 and one of 195N or 32• Topics include physics, world/level

representation, pathfinding over navigation meshes

• 4 projects: warmup, minecraft, platformer, final

• http://cs.brown.edu/courses/cs195u/– See the website from last semester

for more details

• You can run the project demos in /course/cs195u/demo

Page 4: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

cs195n_editor• We’ve received very

little feedback about it– Not sure if this is a good

or bad sign

• How has using it been?– What’s missing?– Is there anything

unnecessary in it?

Page 5: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Final Project Group signups• They’re out now!• 1-person groups must

sign up for a 15min slot• All others must sign up for

two adjacent slots (30 minutes total)

• No explicit preparation necessary, but think about engine feature breakdown

Page 6: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

QUESTIONS?Announcements

Page 7: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

LECTURE 8Entity I/O Case Studies

Page 8: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

DISCLAIMEREntity I/O Case Studies

Page 9: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

ADVANCED ENTITY I/OEntity I/O Case Studies

Page 10: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Existing system• Every entity (that

wants to take part in I/O) has to have a name

• All inputs/outputs hardcoded in

• All connections defined point-to-point on map load

Page 11: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Limitations• Targeting multiple

entities requires a new connection for each

• Impossible to target entities that are:– Nameless– Dynamically created

• No way to change connections at runtime

Page 12: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Targeting multiple entities• Target doesn’t

have to be a single entity name

• Comma-separated list

• Wildcards: * ?– Or even regexes

• Even entity classes– But be careful!

Page 13: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Special targets• !self

– Entity the input is being fired on (good when duplicating entities)

• !caller– Source entity of the connection

that fired this connnection

• !activator– Entity that started the chain of

I/O events

• !picker– Entity the cursor is over (good

for debugging)

sensor

relay.onFired -> wall.doRemovesensor.onPlayerTouch -> relay.fireIfEnabled

relay!self

!caller!activator

wall

Page 14: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

onUser and doUser• Every entity has outputs

onUser[1,n] and inputs doUser[1,n]– doUser2 simply fires onUser2

• Allows for “dynamic dispatch”– Different entities have

different “implementations”

• Only really useful combined with multiple/special targets

Page 15: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

doAddOutput input• Input that dynamically creates

a new connection with the current target entity as the source

• New connection’s other data is defined as properties of the connection– Output to bind to– Target– Input to target

• Useful whenever using a relay is impractical/impossible

Page 16: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

ENTITY CASE STUDIESEntity I/O Case Studies

Page 17: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Counter entity• Keeps track of an integer internally

that can be incremented and decremented

• Fires outputs accordingly when the value changes

• Sample inputs:– doIncrement– doDecrement– doReset– doEnable, doDisable

• Sample outputs:– onMaxHit– onMaxLeft– onValueChange

Page 18: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Physics entities• Force volumes

– Apply a force to all entities contained within it

– Useful for making wind, fast-moving water, areas with different gravity...

• Physicsplosions– Basically what your M III

“grenades” did

push

Page 19: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Filter entity• Referred to by other

entities (as a property) to restrict activation– Esp. sensors, force

volumes

• Can filter by entity name, entity class, or any other property

• Can combine filters with e.g. AndFilter, OrFilter

Page 20: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Template spawner entity• Has references to one or more

“template entities” via properties

• Removes template entities from world as soon as level loads

• doSpawn input spawns a copy of the template entities– Appends # to end to distinguish

between copies

• Can also copy connections with source = a template entity

Page 21: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Further inspiration• CS195N entity I/O is based on the entity I/O

system of the Source engine• For more information and inspiration, entity

I/O is fairly well documented the Valve developer wiki :– https://developer.valvesoftware.com/wiki/Targetname– https

://developer.valvesoftware.com/wiki/Inputs_and_Outputs– https://developer.valvesoftware.com/wiki/List_of_entities

Page 22: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

QUESTIONS?Entity I/O Case Studies

Page 23: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

LECTURE 8Tips for M IV

Page 24: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

This week is very open-ended

• This week you can pick from a large number of reqs to implement– If you have an idea not on

the list, just ask a TA to approve it!

• You’ve built a very extensive engine over the past several weeks– Time to enjoy it!

Page 25: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

JAVA TIP OF THE WEEKTips for M IV

Page 26: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

public class InitBlockExample {{

System.out.print(“what is this”);

}

public static final String s;static {

String temp;// complicated logic

heres = temp;

}

{System.out.println(“i

don’t even”);}

}

Initializer blocks!• Constructors alone leave a

few things to be desired– Repeated code in constructors– No “static” constructor– Would be nicer to have

initialization code near field declaration

• Initializer blocks solve all of these– Unlabelled blocks of code directly

in the class body

• Concatenated and run in order when– an instance is made, for non-static

blocks– when the class is loaded, for static

blocks (usually right before first instantiation)

Page 27: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Field initialization shorthand• Field initialization is just shorthand for initializer

blocks

public class MyClass {private static int i =

12;private String str = “”;

}

public class MyClass {private static int i;static {i = 12;}

private String str;{str = “”;}

}

Page 28: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

class Super {public Super() {

System.out.println(“Superconstructor!”);}

}

public class InitBlockExample extends Super {{ System.out.println(“Regular init!”);

}

static { System.out.println(“Static init!”); }

public InitBlockExample() {super();

System.out.println(“Constructor!”);}

public static void main(String[] args) {

System.out.println(“Main!”);new InitBlockExample();

}}

Order of evaluation• What output does

the code on the right yield?

• Answer:– Static init!

Main!Superconstructor!Regular init!Constructor!

• Why?

Page 29: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Main-less Java Programs• When you specify a main

class to run, the JVM:– Loads class via reflection– Calls main() via reflection

• Thus, static initializers are actually run before main()– Can System.exit(0) at the end

of the static initializer to exit gracefully rather than crash with NoSuchMethodException

• But never actually do this

public class Mainless {static {

String s = “Look, ma! ”;

s += “No main!”;

System.out.println(s);System.exit(0);

}}

Page 30: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

Good uses• Immutable final

collections– Lists, maps, etc.

• Keeping complicated initialization code near field

• Debugging!

public class GoodUses {static final Map<String, String> m;static {

Map<String, String> t = /*…*/;

// lots of puts herem =

Collections.immutableMap(t);}

int complicatedInit;{

// complicated init code}

GoodUses(int ap) {}GoodUses(int ap, String s) {}GoodUses() {}

}

Page 31: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

QUESTIONS?Tips for M IV

Page 32: L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a shirt at  .

M III PLAYTESTING!

Woohoo!