Files
LifeProject/LifeGame/src/Game.h
T

167 lines
4.0 KiB
C++
Raw Normal View History

2025-05-13 02:46:21 +03:00
#ifndef Game_h__
#define Game_h__
#include "Entity.h"
#include "IPhysicsWorld.h"
#include "World.h"
#include "InputSystemOIS.h"
#include "script/ScriptSystem.h"
#include <GUIManager.h>
#include <CGUIRenderer.h>
#include <IRenderWindow.h>
#include "CGUIDataManager.h"
namespace LifeGame
{
#define MAX_FPS_COUNTER 100
class Game
{
protected:
LifeCore::DisplayMode* modes;
IPhysicsWorld* physicsWorld;
LifeGraphics::LifeEngine* pGraphics;
LifeCore::IRenderWindow* output;
int mainWindow;
World* gameWorld;
float gameTime;
bool bRunning;
bool customWindow;
LifeCore::InputSystemOIS* input;
int frameCounter;
ScriptSystem* pScriptSystem;
CGUIRenderer* gui_renderer;
LifeGUI::GUIManager* gui_manager;
public:
Game();
LifeCore::IRenderWindow* GetWindow()
{
return output;
}
void DrawDebug()
{
physicsWorld->CompileDebug();
pGraphics->debugDrawer->Render();
pGraphics->debugDrawer->Flush();
}
LifeGraphics::LifeEngine* GetGraphics()
{
return pGraphics;
}
IPhysicsWorld* GetPhysics()
{
return physicsWorld;
}
void InitVideo(LifeGraphics::RENDERER_TYPE renderer, int width, int height)
{
pGraphics = new LifeGraphics::LifeEngine();
pGraphics->Init(renderer, LifeGraphics::RenderParams(false, false));
physicsWorld->SetDebugDrawer(pGraphics->debugDrawer);
LifeGUI::GUIManager::me()->Init(new CGUIRenderer(pGraphics->GetRenderer()), new CGUIDataManager());
}
void SetResourcesPath(const String& path)
{
LifeGraphics::ResourceManager::me()->SetCentralDirectory(path);
}
void SetWindow(RenderWindowWin* window)
{
output = window;
}
void SetWindow(int width, int height)
{
output = new RenderWindowWin();
output->SetSize(width, height);
}
void InitInput(int screenWidth, int screenHeight, LifeCore::IRenderWindow* wnd)
{
input = new LifeCore::InputSystemOIS();
input->Init(wnd->GetWidth(), wnd->GetHeight(), false, wnd->GetWindowHandle());
}
LifeCore::IInputSystem* GetInput()
{
return input;
}
int Run()
{
bRunning = true;
while(IsRunning())
{
process();
Sleep(0);
}
return 0;
}
bool IsRunning()
{
return bRunning;
}
void Exit()
{
bRunning = false;
}
virtual ~Game()
{
SAFE_DELETE(physicsWorld);
}
World* GetWorld()
{
return gameWorld;
}
void processWorld(World* world){
input->Capture();
world->Update(0.001f);
world->Render();
DrawDebug();
world->GetOutput()->GetSwapChain()->Present();
world->GetOutput()->GetWindow()->Update();
}
void process()
{
gameTime += pGraphics->GetTimeElapsed();
//pGraphics->GetRenderer()->ClearBuffers(CF_COLOR_TARGET | CF_DEPTH_BUFFER, 0xffff00, 1, 0);
//stateManager.Update(); //to world
// stateManager.Render();
frameCounter++;
avgFps[fcPos++] = 1.0f / GetGraphics()->GetTimeElapsed();
if(fcPos >= MAX_FPS_COUNTER)
{
fcPos = 0;
fps = 0.0f;
for(int i = 0; i<MAX_FPS_COUNTER; i++)
{
fps += avgFps[i];
}
fps /= (float)MAX_FPS_COUNTER;
printf("FPS: %f\n", fps);
}
}
private:
float fps;
float avgFps[MAX_FPS_COUNTER];
int fcPos;
};
}
#endif // LifeGame_h__