/** * go(): This is in fact the main game loop. * For the moment it computes physics and output sounds on each frame * but this could be optimized further. It also computes IA on each frame... */ bool HOO::Application::go(){ startup(); while(keepRunning()){ renderOneFrame(); computePhysics(); computeIA(); outputSound(); } shutDown(); return 0; }
void gameUpdateAndRender(GameMemory* memory, OffScreenBuffer *buf, GameSoundOutput* sb, const InputContext* inputContext, real32_t secsSinceLastFrame) { GameState* state = (GameState*)memory->permanentStorage; if(!state->isInited) { state->tone = 512; state->isInited = true; } for(uint32_t i = 0; i < ARRAY_SIZE(inputContext->controllers); i++) { const ControllerInput* ci = &inputContext->controllers[i]; if(ci->isAnalog) { state->tone = 512 + (int)(256.0f*ci->avgY); state->blueOffset += ci->avgX * 4 * secsSinceLastFrame; state->greenOffset += ci->avgY * 4 * secsSinceLastFrame ; } else { real32_t velocity = 500 * secsSinceLastFrame; if(ci->directionLeft.isEndedDown) { state->blueOffset -= velocity; } else if(ci->directionRight.isEndedDown) { state->blueOffset += velocity; } if(ci->directionUp.isEndedDown) { state->greenOffset -= velocity; } else if(ci->directionDown.isEndedDown) { state->greenOffset += velocity; } } } outputSound(sb, state->tone); renderWeirdGradient(buf, state->blueOffset, state->greenOffset); }