/** * Calls cleanup on attached states, do not call directly. */ public void cleanup(){ AppState[] array = getStates(); for (AppState state : array){ state.cleanup(); } } }
protected void initializePending(){ AppState[] array = getInitializing(); if (array.length == 0) return; synchronized( states ) { // Move the states that will be initialized // into the active array. In all but one case the // order doesn't matter but if we do this here then // a state can detach itself in initialize(). If we // did it after then it couldn't. List<AppState> transfer = Arrays.asList(array); states.addAll(transfer); initializing.removeAll(transfer); } for (AppState state : array) { state.initialize(this, app); } }
/** * Calls render for all attached and initialized states, do not call directly. */ public void postRender(){ AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.postRender(); } } }
/** * Calls update for attached states, do not call directly. * @param tpf Time per frame. */ public void update(float tpf){ // Cleanup any states pending terminatePending(); // Initialize any states pending initializePending(); // Update enabled states AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.update(tpf); } } }
/** * Attach a state to the AppStateManager, the same state cannot be attached * twice. * * @param state The state to attach * @return True if the state was successfully attached, false if the state * was already attached. */ public boolean attach(AppState state){ synchronized (states){ if (!states.contains(state) && !initializing.contains(state)){ state.stateAttached(this); initializing.add(state); return true; }else{ return false; } } }
/** * Detaches the state from the AppStateManager. * * @param state The state to detach * @return True if the state was detached successfully, false * if the state was not attached in the first place. */ public boolean detach(AppState state){ synchronized (states){ if (states.contains(state)){ state.stateDetached(this); states.remove(state); terminating.add(state); return true; } else if(initializing.contains(state)){ state.stateDetached(this); initializing.remove(state); return true; }else{ return false; } } }
@Override public void onKeyEvent(KeyInputEvent evt) { if (evt.isPressed() && evt.getKeyCode() == ConsoleState.KEY) { app.setEnabled(false); } }
/** * Calls update for attached states, do not call directly. * @param tpf Time per frame. */ public void update(float tpf){ // Cleanup any states pending terminatePending(); // Initialize any states pending initializePending(); // Update enabled states AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.update(tpf); } } }
/** * Attach a state to the AppStateManager, the same state cannot be attached * twice. * * @param state The state to attach * @return True if the state was successfully attached, false if the state * was already attached. */ public boolean attach(AppState state){ synchronized (states){ if (!states.contains(state) && !initializing.contains(state)){ state.stateAttached(this); initializing.add(state); return true; }else{ return false; } } }
/** * Detaches the state from the AppStateManager. * * @param state The state to detach * @return True if the state was detached successfully, false * if the state was not attached in the first place. */ public boolean detach(AppState state){ synchronized (states){ if (states.contains(state)){ state.stateDetached(this); states.remove(state); terminating.add(state); return true; } else if(initializing.contains(state)){ state.stateDetached(this); initializing.remove(state); return true; }else{ return false; } } }
/** * Calls render for all attached and initialized states, do not call directly. */ public void postRender(){ AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.postRender(); } } }
/** * Calls update for attached states, do not call directly. * @param tpf Time per frame. */ public void update(float tpf){ // Cleanup any states pending terminatePending(); // Initialize any states pending initializePending(); // Update enabled states AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.update(tpf); } } }
protected void terminatePending(){ AppState[] array = getTerminating(); if (array.length == 0) return; for (AppState state : array) { state.cleanup(); } synchronized( states ) { // Remove just the states that were terminated... // which might now be a subset of the total terminating // list. terminating.removeAll(Arrays.asList(array)); } }
protected void initializePending(){ AppState[] array = getInitializing(); synchronized( states ) { // Move the states that will be initialized // into the active array. In all but one case the // order doesn't matter but if we do this here then // a state can detach itself in initialize(). If we // did it after then it couldn't. List<AppState> transfer = Arrays.asList(array); states.addAll(transfer); initializing.removeAll(transfer); } for (AppState state : array) { state.initialize(this, app); } }
/** * Attach a state to the AppStateManager, the same state cannot be attached * twice. * * @param state The state to attach * @return True if the state was successfully attached, false if the state * was already attached. */ public boolean attach(AppState state){ synchronized (states){ if (!states.contains(state) && !initializing.contains(state)){ state.stateAttached(this); initializing.add(state); return true; }else{ return false; } } }
/** * Detaches the state from the AppStateManager. * * @param state The state to detach * @return True if the state was detached successfully, false * if the state was not attached in the first place. */ public boolean detach(AppState state){ synchronized (states){ if (states.contains(state)){ state.stateDetached(this); states.remove(state); terminating.add(state); return true; } else if(initializing.contains(state)){ state.stateDetached(this); initializing.remove(state); return true; }else{ return false; } } }
/** * Calls render for all attached and initialized states, do not call directly. */ public void postRender(){ AppState[] array = getStates(); for (AppState state : array){ if (state.isEnabled()) { state.postRender(); } } }