L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a...
-
Upload
arnold-terry -
Category
Documents
-
view
214 -
download
0
Transcript of L ECTURE 8 Announcements. 3pm in the CIT lobby – We’ll be contrib- combing! Sign up to get a...
LECTURE 8Announcements
• 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
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
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?
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
QUESTIONS?Announcements
LECTURE 8Entity I/O Case Studies
DISCLAIMEREntity I/O Case Studies
ADVANCED ENTITY I/OEntity I/O Case Studies
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
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
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!
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
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
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
ENTITY CASE STUDIESEntity I/O Case Studies
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
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
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
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
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
QUESTIONS?Entity I/O Case Studies
LECTURE 8Tips for M IV
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!
JAVA TIP OF THE WEEKTips for M IV
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)
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 = “”;}
}
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?
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);
}}
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() {}
}
QUESTIONS?Tips for M IV
M III PLAYTESTING!
Woohoo!