Class manufacturingState
- All Implemented Interfaces:
com.jme3.app.state.AppState,iZodiacState
'Builders' build things... each builder has a buildQueue of build tickets.
New manufacturing facilities are added to the planetary buildQueue, one exists per planet. Once completed such facilities are commissioned and become available to use. Equipment such as engines will be built using an industry and added to that industries buildQueue. Once completed items are delivered to the planets warehouse.
- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<com.simsilica.es.EntityId,buildQueue>Map builder ->buildqueue.Map of planet entityid ->warehouse.private com.jme3.asset.AssetManagerprivate com.google.common.collect.EvictingQueue<build>The completed tickets waiting to be processed.private com.google.common.collect.EvictingQueue<build>private com.jme3.input.InputManagerThese tickets involve multiple parts.private static org.slf4j.LoggerIncoming ticket requests.private com.jme3.scene.Nodeprivate com.jme3.app.state.AppStateManagerprivate com.jme3.renderer.ViewPortprivate iZodiacApp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate com.simsilica.es.EntityIdaddToIndustryQueue(build bticket, com.simsilica.es.EntityId peid)private com.simsilica.es.EntityIdaddToOrbitalQueue(build bticket, com.simsilica.es.EntityId peid)Find shipyards orbiting this planet and choose one.private com.simsilica.es.EntityIdaddToPlanetQueue(build bticket, com.simsilica.es.EntityId peid)private buildQueueaddtoQueue(build bticket, com.simsilica.es.EntityId buildereid, com.simsilica.es.EntityId peid)Utility function to add a build ticket to a specific buildQueue.private booleanassignTicket(build bticket, com.simsilica.es.EntityId peid)Assign a build request into the correct buildqueue.protected voidcleanup(com.jme3.app.Application app)private voidconstruct(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)Request manufacture of new equipment or facilities with the specified specification on the specified planet.private voidconstruct_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)Request manufacture of new equipment or facilities with the specified specification on the specified planet.voidRespond to gameEvents broadcast on the eventbus.getWarehouse(com.simsilica.es.EntityId planeteid)Find the warehouse associated with a planet, create it if not present.voidinitialize(com.jme3.app.Application a)Called once when attached, copies the JME application for local use, loads XML specifications and a default game.private voidinstall_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId installinto)Request an install of equipment into an existing entity.private booleanisBuilder(com.simsilica.es.EntityId s)protected voidprotected voidonEnable()private com.simsilica.es.EntityIdrequestWhere(com.simsilica.es.EntityId wherewhat)Where is this request taking place? Needed to identify the correct buildqueue.voidsetwarehouse(com.simsilica.es.EntityId planeteid, List<com.simsilica.es.EntityId> items)TEMP to add things directly to a warehouse for testing.private voidProcess an initial request ticket into the fully structured series of tickets/prerequisites required to fulfill that request.private voidtoCompleted(build ticket, com.simsilica.es.EntityId planet)Ticket final destination, the ticket HAS just completed.private voidtoInprogress(build ticket, com.simsilica.es.EntityId planet)Can this ticket be moved from BLOCKED -> INPROGRESS?voidtrace()Output a detailed report to LOGGER.trace appropriate to this state - typically of the contents of the entity repository.voidupdate(float tpf)Called automatically and repeatedly while the state is enabled and attached.Methods inherited from class com.jme3.app.state.BaseAppState
cleanup, getApplication, getId, getState, getState, getState, getState, getStateManager, initialize, isEnabled, isInitialized, postRender, render, setEnabled, setId, stateAttached, stateDetachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface name.moore.kevin.ze.game.states.iZodiacState
trace, windowEvent
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
zapp
-
rootNode
private com.jme3.scene.Node rootNode -
assetManager
private com.jme3.asset.AssetManager assetManager -
stateManager
private com.jme3.app.state.AppStateManager stateManager -
inputManager
private com.jme3.input.InputManager inputManager -
viewPort
private com.jme3.renderer.ViewPort viewPort -
requestedTickets
Incoming ticket requests.Since the message will be on the async event bus we should make access to this list synchronized between different threads.
Maps build ticket -> planet entity -
isComposite
These tickets involve multiple parts. new ticket -> parent delivery ticket -
allBuildqueues
Map builder ->buildqueue. Each unique builder entity (planet/shipyard/industry) has a queue to hold tickets. Populated lazily as we manufacture items and locate builders. -
allWarehouses
Map of planet entityid ->warehouse. Each planet has it's own warehouse where some constructed items are stored once completed. -
completedSent
The completed tickets waiting to be processed. Done since the COMPLETED message is sent async, and this avoids sending the message twice. The queue gives us some breathing space between different threads, but cleans up itself. -
constructSent
-
-
Constructor Details
-
manufacturingState
- Parameters:
id-
-
-
Method Details
-
initialize
public void initialize(com.jme3.app.Application a)Called once when attached, copies the JME application for local use, loads XML specifications and a default game.- Specified by:
initializein classcom.jme3.app.state.BaseAppState- Parameters:
a- A zodiac object.- See Also:
zodiac
-
cleanup
protected void cleanup(com.jme3.app.Application app)- Specified by:
cleanupin classcom.jme3.app.state.BaseAppState
-
onEnable
protected void onEnable()- Specified by:
onEnablein classcom.jme3.app.state.BaseAppState
-
onDisable
protected void onDisable()- Specified by:
onDisablein classcom.jme3.app.state.BaseAppState
-
update
public void update(float tpf)Called automatically and repeatedly while the state is enabled and attached. Process any tickets in the buildqueues.- Specified by:
updatein interfacecom.jme3.app.state.AppState- Overrides:
updatein classcom.jme3.app.state.BaseAppState- Parameters:
tpf-
-
gameEvent
Respond to gameEvents broadcast on the eventbus.Since the bus is async the code will run on a different thread from the main application. best to make the event handling short and sharp!
Handle requested manufacturing events, which may have been generated by this manufacturingState.- Specified by:
gameEventin interfaceiZodiacState- Parameters:
event-
-
construct_request
@AsyncThread private void construct_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)Request manufacture of new equipment or facilities with the specified specification on the specified planet.Construct an initial ticket and add the ticket to the generic REQUEST buildQueue, it will then be processed by
update(float).- Parameters:
speceid- the spec of the thing to be builtpeid- the planet where we are building
-
install_request
@AsyncThread private void install_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId installinto)Request an install of equipment into an existing entity.- Parameters:
speceid- the spec to try installing, we will try to getEntityComponent this from a warehouse or by construction.targetid- the entity to receive the installation - it's location determines the planet
-
toBlocked
Process an initial request ticket into the fully structured series of tickets/prerequisites required to fulfill that request.creates other tickets and organises prerequisites.
-
requestWhere
private com.simsilica.es.EntityId requestWhere(com.simsilica.es.EntityId wherewhat)Where is this request taking place? Needed to identify the correct buildqueue. -
toInprogress
Can this ticket be moved from BLOCKED -> INPROGRESS?This can be done by all the prerequisites being completed, or being able to reserve from the warehouse.
- Parameters:
ticket-
-
toCompleted
Ticket final destination, the ticket HAS just completed.- Parameters:
ticket-planet-
-
construct
@AsyncThread private void construct(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)Request manufacture of new equipment or facilities with the specified specification on the specified planet.Construct a buildticket to track construction and add the ticket to the generic REQUEST buildQueue, it will then be processed by
update(float).- Parameters:
speceid- the spec of the thing to be builtpeid- the planet where we are building
-
assignTicket
Assign a build request into the correct buildqueue. If the assignment fails, return false so the ticket can be removed.REQUEST ->BLOCKED,
- Parameters:
ticket-peid- planet where this activity is happening
-
addToPlanetQueue
-
addToOrbitalQueue
Find shipyards orbiting this planet and choose one.- Parameters:
bticket-peid-- Returns:
-
isBuilder
private boolean isBuilder(com.simsilica.es.EntityId s) -
addToIndustryQueue
private com.simsilica.es.EntityId addToIndustryQueue(build bticket, com.simsilica.es.EntityId peid) -
addtoQueue
private buildQueue addtoQueue(build bticket, com.simsilica.es.EntityId buildereid, com.simsilica.es.EntityId peid)Utility function to add a build ticket to a specific buildQueue.If the queue doesn't yet exist it will be created and associated with the builder.
- Parameters:
bticket-buildereid-peid- planet this builder is located on- Returns:
- See Also:
allBuildqueues
-
setwarehouse
public void setwarehouse(com.simsilica.es.EntityId planeteid, List<com.simsilica.es.EntityId> items)TEMP to add things directly to a warehouse for testing. Dont use in live code.- Parameters:
planeteid-items-
-
getWarehouse
Find the warehouse associated with a planet, create it if not present.- Parameters:
planeteid-- Returns:
-
trace
public void trace()Description copied from interface:iZodiacStateOutput a detailed report to LOGGER.trace appropriate to this state - typically of the contents of the entity repository.- Specified by:
tracein interfaceiZodiacState
-