|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread hermes.World
public class World
The World defines a 'game state': it keeps track of all the Beings, Groups, and their interaction. This is done through registration, HObjects and Interactors must be registered with the World in order to be drawn or updated.
The World is a Thread
. When start
is called, the World
will automatically update all registered objects and apply all Interactors between
them. This runs on the World's thread, which is separate from the Processing's draw
thread. This multithreading can be bypassed by not calling start
,
and instead calling update
within Processing's draw
method.
By default to update rate is locked to 60Hz. You can change this, or unlock the rate,
by calling lockUpdateRate
and unlockUpdateRate
.
There are two basic ways of working with a World. One is to set up all of your
objects and Interactors outside of the World, and register them in Processing's setup
.
The other is to create a subclass of World, declare many variables inside this class,
and override the empty World setup
and shutdown
methods. This allows for
more control as additional computations can be done in the preUpdate
and postUpdate
methods, called by the thread before and after update
, respectively.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected HCamera |
_camera
|
protected PostOffice |
_postOffice
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
World()
Constructor that automatically creates PostOffice and HCamera |
|
World(HCamera view)
Constructor that automatically creates PostOffice |
|
World(int portIn,
int portOut)
Constructor that automatically creates PostOffice and HCamera, and sets up OSC |
|
World(int portIn,
int portOut,
HCamera view)
Constructor that automatically creates PostOffice and sets up OSC |
|
World(PostOffice postOffice)
Constructor that automatically creates HCamera |
|
World(PostOffice postOffice,
HCamera view)
Instantiates the world with a PostOffice to handle I/O and a Camera to handle drawing. |
Method Summary | |
---|---|
void |
addToGroup(HObject object,
GenericGroup<?,?> group)
Queues an HObject to be added to a group at the end of the current update. |
void |
deactivate()
Tells the world to stop running. |
void |
delete(HObject object)
Queues an HObject to be removed from all of the groups it is in at the end of the current update. |
void |
draw()
|
PostOffice |
getPostOffice()
|
boolean |
isActive()
Returns true after start() has been called. |
void |
lockUpdateRate(int rate)
Locks the update rate to happen no more than rate times per second. |
void |
postUpdate()
Will be executed on each loop after update is called. |
void |
preUpdate()
Will be executed on each loop before update is called. |
void |
register(Being being)
Shortcut for adding Being w/ update |
void |
register(Being being,
boolean update)
Registers a being with the world, making it be drawn when it is on camera, its update method will be called by the loop if update is true. |
void |
register(GenericGroup group)
register a group to have its update called in the update loop |
void |
register(GenericGroup A,
GenericGroup B,
Interactor inter)
Register an interaction to be handled on the update loop. |
void |
register(GenericGroup A,
GenericGroup B,
Interactor inter,
Optimizer optimizer)
Register an interaction to be handled on the update loop. |
void |
register(GenericGroup A,
HObject B,
Interactor inter)
register an interaction between B and all objects in A |
void |
register(HObject A,
GenericGroup B,
Interactor inter)
register an interaction between A and all objects in B |
void |
register(HObject A,
HObject B,
Interactor inter)
Register an interaction between HOjbects A and B. |
void |
remove(HObject object,
GenericGroup<?,?> group)
Queues an HObject to be removed from a group at the end of the current update. |
void |
resolveGroupQueues()
Resolves the add, remove, and delete queues, in that order. |
void |
run()
DO NOT CALL THIS METHOD. |
void |
setup()
Will be called once when the world is run, before the update loop. |
void |
shutdown()
Will be called once the world has finished running. |
void |
subscribe(KeySubscriber sub,
char key)
Registers a subscription to messages sent by a specific keyboard key. |
void |
subscribe(KeySubscriber sub,
int key)
Registers a subscription to messages sent by a specific keyboard key. |
void |
subscribe(MouseSubscriber sub,
POCodes.Button button)
Registers a subscription to messages sent by a specific mouse button. |
void |
subscribe(MouseSubscriber sub,
POCodes.Button button,
HShape region)
A version of registerMouseSubscription that subscribes only to the requested button events that occur in the given region. |
void |
subscribe(MouseWheelSubscriber sub)
Registers a subscription to the mouse wheel (one subscription gets you everything). |
void |
subscribe(OscSubscriber sub,
java.lang.String address)
Registers a subscription to messages received on a specific OSC address. |
void |
unlockUpdateRate()
Unlocks the update rate (the rate is set to 60Hz by default). |
void |
update()
Executes the update loop. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected PostOffice _postOffice
protected HCamera _camera
Constructor Detail |
---|
public World(PostOffice postOffice, HCamera view)
postOffice
- the PostOffice that will handle mouse, keyboard and OSC I/Oview
- the camera that will be used for drawingpublic World()
public World(HCamera view)
public World(int portIn, int portOut)
public World(int portIn, int portOut, HCamera view)
public World(PostOffice postOffice)
Method Detail |
---|
public boolean isActive()
start()
has been called.
public void deactivate()
stop
method).
public void register(Being being, boolean update)
update
method will be called by the loop if update is true.
being
- the being to registerupdate
- whether or not to update the being during the update looppublic void register(Being being)
being
- the being to registerpublic void addToGroup(HObject object, GenericGroup<?,?> group)
object
- the object to addgroup
- the group to add the object topublic void remove(HObject object, GenericGroup<?,?> group)
object
- the object to removegroup
- the group to add the object topublic void delete(HObject object)
object
- the object to deletepublic void resolveGroupQueues()
public void register(GenericGroup A, GenericGroup B, Interactor inter)
A
- the first interacting groupB
- the second interacting groupinter
- the Interactor that detects and handles this interactionpublic void register(GenericGroup A, GenericGroup B, Interactor inter, Optimizer optimizer)
A
- the first interacting groupB
- the second interacting groupinter
- the Interactor that detects and handles this interactionoptimizer
- optimizer to use for the interactionpublic void register(HObject A, GenericGroup B, Interactor inter)
A
- an HObjectsB
- a groupinter
- the Interactor that detects and handles this interactionpublic void register(GenericGroup A, HObject B, Interactor inter)
A
- a groupB
- a beinginter
- the Interactor that detects and handles this interactionpublic void register(HObject A, HObject B, Interactor inter)
A
- the first objectB
- the second objectinter
- the interaction handler
upon detection or laterpublic void register(GenericGroup group)
group
- the group to updatepublic void subscribe(KeySubscriber sub, int key)
sub
- the KeySubscriber signing upkey
- the code of the keyboard key whose messages the subscriber wants (use value from POConstants)public void subscribe(KeySubscriber sub, char key)
sub
- the KeySubscriber signing upkey
- the char of the keyboard key whose messages the subscriber wantspublic void subscribe(MouseSubscriber sub, POCodes.Button button)
Buttons are defined by constants in the POConstants class; subscribe with "NO_BUTTON" to receive information about mouse movements when no button is pressed.
sub
- the MouseSubscriber signing upbutton
- the code of the button whose messages the subscriber wants (use value from POContants)public void subscribe(MouseSubscriber sub, POCodes.Button button, HShape region)
sub
- the MouseSubscriber signing upbutton
- the code of the button whose messages the subscriber wants (use value from POContants)region
- the region on screen the subscriber wants to limit its subscription topublic void subscribe(MouseWheelSubscriber sub)
sub
- the MouseWheelSubscriber signing uppublic void subscribe(OscSubscriber sub, java.lang.String address)
sub
- the OscSubscriber signing upaddress
- the address whose messages the subscriber wantspublic void run()
World.start
instead, for threading purposes.
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void setup()
public void shutdown()
public void preUpdate()
public void postUpdate()
public void update()
start
has not been called
and threading is not desired.
public void lockUpdateRate(int rate)
rate
times per second.
Default value is 60Hz.
public void unlockUpdateRate()
public void draw()
public PostOffice getPostOffice()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |