Wasabi::~Wasabi() { if (WindowComponent) WindowComponent->Cleanup(); W_SAFE_DELETE(SoundComponent); W_SAFE_DELETE(WindowComponent); vkDestroyInstance(vkInstance, nullptr); }
void Wasabi::SwitchState(WGameState* state) { if (curState) { curState->Cleanup(); W_SAFE_DELETE(curState); } curState = state; if (curState) curState->Load(); }
void WSoundComponent::m_RegisterSound(WSound* sound) { //sign a sound in the sound's list, delete a sound if it already exists with the same ID (this should be used by the system only) if (sound->GetID()) for (uint i = 0; i < m_soundV.size(); i++) if (m_soundV[i]->GetID() == sound->GetID()) { WSound* temp = m_soundV[i]; W_SAFE_DELETE(temp); } m_soundV.push_back(sound); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) { WInitializeTimers(); Wasabi* app = WInitialize(); app->maxFPS = 60.0f; app->SoundComponent = new WSoundComponent(); #ifdef _WIN32 app->WindowComponent = new WWC_Win32(app); app->InputComponent = new WIC_Win32(app); #elif defined(__linux__) app->WindowComponent = new WWC_Linux(app); app->InputComponent = new WIC_Linux(app); #endif if (app->Setup()) { WTimer tmr(W_TIMER_SECONDS); WTimer fpsChangeTmr(W_TIMER_SECONDS); fpsChangeTmr.Start(); UINT numFrames = 0; float deltaTime = 0.0f; while (!app->__EXIT) { tmr.Reset(); tmr.Start(); if (!app->WindowComponent->Loop()) continue; if (deltaTime) { if (!app->Loop(deltaTime)) break; if (app->curState) app->curState->Update(deltaTime); } // TODO: render //while (app->core->Update(deltaTime) == HX_WINDOWMINIMIZED) // hx->core->Loop(); numFrames++; deltaTime = app->FPS < 0.0001 ? 1.0f / 60.0f : 1.0f / app->FPS; if (app->maxFPS > 0.001) { float maxDeltaTime = 1.0f / app->maxFPS; // delta time at max FPS if (deltaTime < maxDeltaTime) { WTimer sleepTimer(W_TIMER_SECONDS); sleepTimer.Start(); while (sleepTimer.GetElapsedTime() < (maxDeltaTime - deltaTime)); deltaTime = maxDeltaTime; } } if (fpsChangeTmr.GetElapsedTime() >= 0.5f) //0.5 second passed -> update FPS { app->FPS = (float)numFrames * 2.0f; numFrames = 0; fpsChangeTmr.Reset(); } } app->Cleanup(); } W_SAFE_DELETE(app); WUnInitializeTimers(); return 0; }
WCore::~WCore() { W_SAFE_DELETE(SoundComponent); W_SAFE_DELETE(WindowComponent); }