Nueva Clase Engine.
Se ha eliminado la antigua clase Game y movido a la nueva clase Engine. La clase Engine, encargada de iniciar las cosas, ahora está en el Engine Además, tiene seguridad en la inicialización. Ya no se inicia el juego si hay error al cargar libs o sistemas.
This commit is contained in:
@@ -12,24 +12,6 @@ namespace UE
|
|||||||
|
|
||||||
void AssetManager::InitAssetManager()
|
void AssetManager::InitAssetManager()
|
||||||
{
|
{
|
||||||
if (IMG_Init(IMG_INIT_PNG))
|
|
||||||
{
|
|
||||||
UE_LOG_INFO("SDL_Image Init.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG_ERROR("SDL_Image - Error al inicarse: {0}", IMG_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TTF_Init()) //Retorna 0 si está correcto.
|
|
||||||
{
|
|
||||||
UE_LOG_INFO("SDL_TTF se ha inicializado correctamente.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG_ERROR("SDL_TTF - Error al inicarse: {0}", TTF_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
UE_LOG_INFO("AssetManager Iniciado con éxito.");
|
UE_LOG_INFO("AssetManager Iniciado con éxito.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,9 +34,6 @@ namespace UE
|
|||||||
_assetQueue.clear();
|
_assetQueue.clear();
|
||||||
_textures.clear();
|
_textures.clear();
|
||||||
|
|
||||||
|
|
||||||
IMG_Quit();
|
|
||||||
|
|
||||||
UE_LOG_INFO("AssetManager Cleaned");
|
UE_LOG_INFO("AssetManager Cleaned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,9 @@
|
|||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
|
|
||||||
/*UberEngine Includes*/
|
/*UberEngine Includes*/
|
||||||
//#include "Assets\Asset.h"
|
#include "Assets/Asset.h"
|
||||||
#include "Assets/Texture.h"
|
#include "Assets/Texture.h"
|
||||||
#include "Assets/Font.h"
|
#include "Assets/Font.h"
|
||||||
#include "Assets/Asset.h"
|
|
||||||
|
|
||||||
using json = nlohmann::ordered_json;
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
#include "Engine.h"
|
||||||
|
|
||||||
|
#include "Logging/Logger.h"
|
||||||
|
|
||||||
|
#include "Render/Renderer.h"
|
||||||
|
#include "Assets/AssetManager.h"
|
||||||
|
#include "Scene/SceneManager.h"
|
||||||
|
|
||||||
|
namespace UE
|
||||||
|
{
|
||||||
|
//Le decimos a C++ que son objetos static y que los cree cuando vea.
|
||||||
|
|
||||||
|
Renderer* Engine::_renderer;
|
||||||
|
AssetManager* Engine::_assetManager;
|
||||||
|
SceneManager* Engine::_sceneManager;
|
||||||
|
|
||||||
|
|
||||||
|
int Engine::Init()
|
||||||
|
{
|
||||||
|
//Lo primero, es iniciar el Logger, para poder imprimir errores.
|
||||||
|
UE::Logger::InitLogger();
|
||||||
|
|
||||||
|
|
||||||
|
//Etapa de carga de librerías.
|
||||||
|
if(InitLibs() < 0) //Retorna negativos en caso de error.
|
||||||
|
{
|
||||||
|
UE_LOG_CRITICAL("Engine - Error al inicial las librerías");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Iniciamos los sistemas del motor.
|
||||||
|
if(InitRenderer() < 0)
|
||||||
|
{
|
||||||
|
UE_LOG_CRITICAL("Engine - Error al iniciar el renderer.");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(InitAssetManager() < 0)
|
||||||
|
{
|
||||||
|
UE_LOG_CRITICAL("Engine - Error al inicial el AssetManager.");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(InitSceneManager() < 0)
|
||||||
|
{
|
||||||
|
UE_LOG_CRITICAL("Engine - Error al inicial el SceneManager.");
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG_INFO("Engine - El motor se ha iniciado correctamente.");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::Clean()
|
||||||
|
{
|
||||||
|
//Etapa para limpiar los sistemas del motor.
|
||||||
|
_sceneManager->CleanSceneManager();
|
||||||
|
delete _sceneManager;
|
||||||
|
|
||||||
|
_assetManager->CleanAssetManager();
|
||||||
|
delete _assetManager;
|
||||||
|
|
||||||
|
_renderer->CleanRenderer();
|
||||||
|
delete _renderer;
|
||||||
|
|
||||||
|
//Etapa para desactivar y limpiar todas las librerías.
|
||||||
|
QuitLibs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Engine::InitLibs()
|
||||||
|
{
|
||||||
|
//Iniciamos SDL.
|
||||||
|
SDL_HINT_RENDER_DRIVER "opengl";
|
||||||
|
|
||||||
|
Uint32 SDL_Flags = SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS;
|
||||||
|
if (SDL_Init(SDL_Flags) < 0)
|
||||||
|
{
|
||||||
|
UE_LOG_CRITICAL("Engine - SDL: Error al iniciar SDL: {0}", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
UE_LOG_TRACE("Engine - SDL se ha iniciado correctamente");
|
||||||
|
|
||||||
|
//Iniciamos SDL_Image
|
||||||
|
if (IMG_Init(IMG_INIT_PNG) == 0) //Retorna 0 en caso de fallo.
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("Engine - SDL_Image: Error al iniciarse: {0}", IMG_GetError());
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
UE_LOG_TRACE("Engine - SDL_Image se ha iniciado correctamente");
|
||||||
|
|
||||||
|
//Iniciamos el SDL_TTF
|
||||||
|
if (TTF_Init() < 0) //Retorna -1 en caso de error.
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("Engine - SDL_TTF: Error al inicarse: {0}", TTF_GetError());
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
UE_LOG_TRACE("Engine - SDL_TTF se ha iniciado correctamente");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Engine::InitRenderer()
|
||||||
|
{
|
||||||
|
//Cargamos el Renderer.
|
||||||
|
//Hay que implementar un sistema de flags o
|
||||||
|
// una struct de configuración para la inicialización del renderer.
|
||||||
|
_renderer = new UE::Renderer(640, 480, 5);
|
||||||
|
if(_renderer->InitRenderer() < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
UE_LOG_TRACE("Engine - Renderer: Se ha iniciado correctamente");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Engine::InitAssetManager()
|
||||||
|
{
|
||||||
|
//Cargamos el AssetManager
|
||||||
|
//Faltaría control de errores en caso de haberlo.
|
||||||
|
_assetManager = new UE::AssetManager(_renderer->GetSDLRenderer());
|
||||||
|
_assetManager->InitAssetManager();
|
||||||
|
|
||||||
|
|
||||||
|
UE_LOG_TRACE("Engine - AssetManager: Se ha iniciado correctamente");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Engine::InitSceneManager()
|
||||||
|
{
|
||||||
|
//Cargamos el SceneManager
|
||||||
|
//Faltaría control de errores en caso de haberlo.
|
||||||
|
_sceneManager = new UE::SceneManager();
|
||||||
|
|
||||||
|
UE_LOG_TRACE("Engine - SceneManager: Se ha iniciado correctamente.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Engine::QuitLibs()
|
||||||
|
{
|
||||||
|
TTF_Quit();
|
||||||
|
IMG_Quit();
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace UE
|
||||||
|
{
|
||||||
|
//Declaraciones de clases de UberEngine
|
||||||
|
|
||||||
|
class Renderer;
|
||||||
|
class AssetManager;
|
||||||
|
class SceneManager;
|
||||||
|
|
||||||
|
/* Clase Principal del motor.
|
||||||
|
* Carga todas los sistemas y librerías al inicio y los descarga al final.
|
||||||
|
* Contiene ptrs a los sistemas principales.
|
||||||
|
*/
|
||||||
|
class Engine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*
|
||||||
|
* Inicia todos los sistemas y librerías necesarias.
|
||||||
|
* Retornará 0 o un código de error negativo.
|
||||||
|
*/
|
||||||
|
static int Init();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Limpia todas las cosas del motor.
|
||||||
|
*/
|
||||||
|
static void Clean();
|
||||||
|
|
||||||
|
inline static UE::Renderer* GetRenderer() { return _renderer; }
|
||||||
|
inline static UE::AssetManager* GetAssetManager() { return _assetManager; }
|
||||||
|
inline static UE::SceneManager* GetSceneManager() { return _sceneManager; }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//Vamos a crear un método para la inicialización de cada sistema.
|
||||||
|
// de esta forma, debería ser más fácil modificar la inicialización cuando sea necesario.
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inicializa las librerías de SDL.
|
||||||
|
* Retorna códigos de error negativos.
|
||||||
|
*/
|
||||||
|
static int InitLibs();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inicializa el renderer.
|
||||||
|
* En un futuro, debería ser configurable, además de soportar distintos backends.
|
||||||
|
*/
|
||||||
|
static int InitRenderer();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inicializa el AssetManager.
|
||||||
|
* Es necesario iniciar primero el Renderer para poder acceder al SDL_Renderer.
|
||||||
|
* (al menos, mientras usemos el SDL_Renderer.)
|
||||||
|
*/
|
||||||
|
static int InitAssetManager();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inicializa el SceneManager.
|
||||||
|
*/
|
||||||
|
static int InitSceneManager();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Al igual que se inician, hay que limpiar las libs.
|
||||||
|
*/
|
||||||
|
static int QuitLibs();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ptrs de los sistemas.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static Renderer* _renderer;
|
||||||
|
static AssetManager* _assetManager;
|
||||||
|
static SceneManager* _sceneManager;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace UE
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//Macros para el Logging. Es m�s c�modo que estar poniendo la l�nea entera cada vez...
|
//Macros para el Logging. Es más cómodo que estar poniendo la línea entera cada vez...
|
||||||
#define UE_LOG_TRACE(...) ::UE::Logger::GetEngineLogger()->trace(__VA_ARGS__)
|
#define UE_LOG_TRACE(...) ::UE::Logger::GetEngineLogger()->trace(__VA_ARGS__)
|
||||||
#define UE_LOG_DEBUG(...) ::UE::Logger::GetEngineLogger()->debug(__VA_ARGS__)
|
#define UE_LOG_DEBUG(...) ::UE::Logger::GetEngineLogger()->debug(__VA_ARGS__)
|
||||||
#define UE_LOG_INFO(...) ::UE::Logger::GetEngineLogger()->info(__VA_ARGS__)
|
#define UE_LOG_INFO(...) ::UE::Logger::GetEngineLogger()->info(__VA_ARGS__)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <ImGui/imgui.h>
|
#include <ImGui/imgui.h>
|
||||||
#include <ImGui/imgui_impl_sdl.h>
|
#include <ImGui/imgui_impl_sdl.h>
|
||||||
#include <ImGui/imgui_impl_sdlrenderer.h>
|
#include <ImGui/imgui_impl_sdlrenderer.h>
|
||||||
//#include <ImGui\imgui_impl_opengl3.h>
|
//#include <ImGui/imgui_impl_opengl3.h>
|
||||||
|
|
||||||
#include <SDL_opengl.h>
|
#include <SDL_opengl.h>
|
||||||
|
|
||||||
@@ -13,20 +13,8 @@
|
|||||||
|
|
||||||
namespace UE
|
namespace UE
|
||||||
{
|
{
|
||||||
//class Game;
|
|
||||||
|
|
||||||
int Renderer::InitRenderer()
|
int Renderer::InitRenderer()
|
||||||
{
|
{
|
||||||
//Iniciamos SDL.
|
|
||||||
SDL_HINT_RENDER_DRIVER "opengl";
|
|
||||||
|
|
||||||
Uint32 SDL_Flags = SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS;
|
|
||||||
if (SDL_Init(SDL_Flags) < 0)
|
|
||||||
{
|
|
||||||
UE_LOG_CRITICAL("No se ha podido iniciar SDL, sufre mam�n: {0}", SDL_GetError());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Configuramos los par�metros de la ventana de SDL.
|
//Configuramos los par�metros de la ventana de SDL.
|
||||||
Uint32 windowFlags = (SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
|
Uint32 windowFlags = (SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
@@ -34,15 +22,16 @@ namespace UE
|
|||||||
_window = SDL_CreateWindow("UberGame1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenSize.x, screenSize.y, windowFlags);
|
_window = SDL_CreateWindow("UberGame1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenSize.x, screenSize.y, windowFlags);
|
||||||
if (_window == NULL)
|
if (_window == NULL)
|
||||||
{
|
{
|
||||||
UE_LOG_CRITICAL("No se ha podido crear la ventana de SDL con OpenGL y esas mierdas: {0}", SDL_GetError());
|
UE_LOG_CRITICAL("Renderer - CreateWindow: No se ha podido crear la ventana con OpenGL: {0}", SDL_GetError());
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Creamos el Renderer de SDL.
|
//Creamos el Renderer de SDL.
|
||||||
main_Renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
|
main_Renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
if (main_Renderer == NULL)
|
if (main_Renderer == NULL)
|
||||||
{
|
{
|
||||||
UE_LOG_CRITICAL("No se ha podido crear el Renderer de SDL: {0}", SDL_GetError());
|
UE_LOG_CRITICAL("Renderer - SDL_Renderer: No se ha podido crear el Renderer de SDL: {0}", SDL_GetError());
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
SDL_SetRenderDrawColor(main_Renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
SDL_SetRenderDrawColor(main_Renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||||
|
|
||||||
@@ -63,7 +52,7 @@ namespace UE
|
|||||||
|
|
||||||
|
|
||||||
//Init layers.
|
//Init layers.
|
||||||
for (int i = 0; i < LAYER_AMOUNT; i++)
|
for (int i = 0; i <= LAYER_AMOUNT; i++)
|
||||||
{
|
{
|
||||||
renderLayers.push_back(std::vector<DrawCall>());
|
renderLayers.push_back(std::vector<DrawCall>());
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-31
@@ -6,8 +6,8 @@
|
|||||||
#include <ImGui/imgui_impl_sdl.h>
|
#include <ImGui/imgui_impl_sdl.h>
|
||||||
#include <ImGui/imgui_impl_opengl3.h>
|
#include <ImGui/imgui_impl_opengl3.h>
|
||||||
|
|
||||||
#include "UberGame1.h"
|
|
||||||
|
|
||||||
|
#include "Engine.h"
|
||||||
#include "UberEngine.h"
|
#include "UberEngine.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
static bool _quit = false;
|
static bool _quit = false;
|
||||||
|
|
||||||
void Init();
|
int Init();
|
||||||
void Load();
|
void Load();
|
||||||
void Loop();
|
void Loop();
|
||||||
void Clean();
|
void Clean();
|
||||||
@@ -24,7 +24,9 @@ void Clean();
|
|||||||
int main(int argc, char* args[])
|
int main(int argc, char* args[])
|
||||||
{
|
{
|
||||||
|
|
||||||
Init();
|
//Si falla la inicialización, terminamos el juego.
|
||||||
|
if(Init() < 0) { return -1; }
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
Loop();
|
Loop();
|
||||||
Clean();
|
Clean();
|
||||||
@@ -32,25 +34,28 @@ int main(int argc, char* args[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init()
|
int Init()
|
||||||
{
|
{
|
||||||
UE::Logger::InitLogger();
|
if(UE::Engine::Init() < 0)
|
||||||
|
{
|
||||||
Game::InitGame();
|
GAME_LOG_CRITICAL("No se ha podido cargar el motor.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Load()
|
void Load()
|
||||||
{
|
{
|
||||||
Game::GetAssetManager()->LoadAssetsFromFile("resources/AssetList/MainAssets.json");
|
UE::Engine::GetAssetManager()->LoadAssetsFromFile("resources/AssetList/MainAssets.json");
|
||||||
Game::GetAssetManager()->ProcessAssetQueue();
|
UE::Engine::GetAssetManager()->ProcessAssetQueue();
|
||||||
|
|
||||||
|
|
||||||
//Cargamos la escena que queramos tras tener todos los Assets pertinentes cargados.
|
//Cargamos la escena que queramos tras tener todos los Assets pertinentes cargados.
|
||||||
//Si la escena contiene su propio AssetManager y los carga ella misma, no ser� necesario.
|
//Si la escena contiene su propio AssetManager y los carga ella misma, no ser� necesario.
|
||||||
//Game::GetSceneManager()->LoadScene("Main");
|
//Game::GetSceneManager()->LoadScene("Main");
|
||||||
Game::GetSceneManager()->LoadScene(new MainScene());
|
UE::Engine::GetSceneManager()->LoadScene(new MainScene());
|
||||||
Game::GetSceneManager()->SwitchScene("MainScene");
|
UE::Engine::GetSceneManager()->SwitchScene("MainScene");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,10 +87,17 @@ void Loop()
|
|||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
//Almacenamos el renderer para ya tenerlo por aquí.
|
||||||
|
UE::Renderer* UE_Renderer = UE::Engine::GetRenderer();
|
||||||
|
|
||||||
|
|
||||||
while (!_quit)
|
while (!_quit)
|
||||||
{
|
{
|
||||||
UE::Time::StartFrame();
|
UE::Time::StartFrame();
|
||||||
|
|
||||||
|
//Almacenamos la escena actual.
|
||||||
|
UE::Scene* currentScene = UE::Engine::GetSceneManager()->GetCurrentScenePtr();
|
||||||
|
|
||||||
//TEMP Event Handler:
|
//TEMP Event Handler:
|
||||||
SDL_Event eventHandler;
|
SDL_Event eventHandler;
|
||||||
while (SDL_PollEvent(&eventHandler) != 0)
|
while (SDL_PollEvent(&eventHandler) != 0)
|
||||||
@@ -97,7 +109,7 @@ void Loop()
|
|||||||
if (io.WantCaptureMouse) { continue; }
|
if (io.WantCaptureMouse) { continue; }
|
||||||
|
|
||||||
|
|
||||||
Game::GetSceneManager()->GetCurrentScenePtr()->SceneHandleEvents(&eventHandler);
|
currentScene->SceneHandleEvents(&eventHandler);
|
||||||
if (eventHandler.type == SDL_QUIT)
|
if (eventHandler.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
_quit = true;
|
_quit = true;
|
||||||
@@ -105,17 +117,17 @@ void Loop()
|
|||||||
if (eventHandler.type == SDL_WINDOWEVENT && eventHandler.window.event == SDL_WINDOWEVENT_RESIZED)
|
if (eventHandler.type == SDL_WINDOWEVENT && eventHandler.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||||
{
|
{
|
||||||
//GAME_LOG_CRITICAL("Window Size chaged {0}x{1}", eventHandler.window.data1, eventHandler.window.data2);
|
//GAME_LOG_CRITICAL("Window Size chaged {0}x{1}", eventHandler.window.data1, eventHandler.window.data2);
|
||||||
Game::GetRenderer()->SetScreenSize(eventHandler.window.data1, eventHandler.window.data2);
|
UE_Renderer->SetScreenSize(eventHandler.window.data1, eventHandler.window.data2);
|
||||||
}
|
}
|
||||||
if (eventHandler.type == SDL_KEYDOWN)
|
if (eventHandler.type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
switch (eventHandler.key.keysym.sym)
|
switch (eventHandler.key.keysym.sym)
|
||||||
{
|
{
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
Game::GetSceneManager()->LoadAndSwitchScene(new MainScene());
|
UE::Engine::GetSceneManager()->LoadAndSwitchScene(new MainScene());
|
||||||
break;
|
break;
|
||||||
case SDLK_2:
|
case SDLK_2:
|
||||||
Game::GetSceneManager()->LoadAndSwitchScene(new TestScene2());
|
UE::Engine::GetSceneManager()->LoadAndSwitchScene(new TestScene2());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -133,32 +145,33 @@ void Loop()
|
|||||||
GAME_LOG_TRACE("FPS: NULL / dT: {1}", UE::Time::deltaTime);
|
GAME_LOG_TRACE("FPS: NULL / dT: {1}", UE::Time::deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (keyStates[SDL_SCANCODE_W])
|
if (keyStates[SDL_SCANCODE_W])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = Game::GetRenderer()->GetCamPosition();
|
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||||
camPos.y -= 5;
|
camPos.y -= 5;
|
||||||
Game::GetRenderer()->SetCamPosition(camPos.x, camPos.y);
|
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_S])
|
if (keyStates[SDL_SCANCODE_S])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = Game::GetRenderer()->GetCamPosition();
|
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||||
camPos.y += 5;
|
camPos.y += 5;
|
||||||
Game::GetRenderer()->SetCamPosition(camPos.x, camPos.y);
|
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_D])
|
if (keyStates[SDL_SCANCODE_D])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = Game::GetRenderer()->GetCamPosition();
|
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||||
camPos.x += 5;
|
camPos.x += 5;
|
||||||
Game::GetRenderer()->SetCamPosition(camPos.x, camPos.y);
|
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_A])
|
if (keyStates[SDL_SCANCODE_A])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = Game::GetRenderer()->GetCamPosition();
|
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||||
camPos.x -= 5;
|
camPos.x -= 5;
|
||||||
Game::GetRenderer()->SetCamPosition(camPos.x, camPos.y);
|
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::GetSceneManager()->GetCurrentScenePtr()->SceneUpdate();
|
currentScene->SceneUpdate();
|
||||||
|
|
||||||
//Game::GetRenderer()->QueueDrawCall(4, DestR2, test1);
|
//Game::GetRenderer()->QueueDrawCall(4, DestR2, test1);
|
||||||
//Game::GetRenderer()->QueueDrawCall(1, DestR, background);
|
//Game::GetRenderer()->QueueDrawCall(1, DestR, background);
|
||||||
@@ -169,20 +182,20 @@ void Loop()
|
|||||||
//
|
//
|
||||||
|
|
||||||
//Iniciamos un nuevo Frame.
|
//Iniciamos un nuevo Frame.
|
||||||
Game::GetRenderer()->NewFrame();
|
UE_Renderer->NewFrame();
|
||||||
|
|
||||||
//Renderiza la escena.
|
//Renderiza la escena.
|
||||||
Game::GetSceneManager()->GetCurrentScenePtr()->SceneRender();
|
currentScene->SceneRender();
|
||||||
|
|
||||||
//As� podemos renderizar cosas de ImGui cuando estemos entre NewFrame y EndFrame.
|
//As� podemos renderizar cosas de ImGui cuando estemos entre NewFrame y EndFrame.
|
||||||
bool show = true;
|
bool show = true;
|
||||||
ImGui::ShowDemoWindow(&show);
|
ImGui::ShowDemoWindow(&show);
|
||||||
|
|
||||||
//Dibuja las cosas del Renderer.
|
//Dibuja las cosas del Renderer.
|
||||||
Game::GetRenderer()->RenderData();
|
UE_Renderer->RenderData();
|
||||||
|
|
||||||
//Terminamos el Frame.
|
//Terminamos el Frame.
|
||||||
Game::GetRenderer()->EndFrame();
|
UE_Renderer->EndFrame();
|
||||||
|
|
||||||
UE::Time::EndFrame();
|
UE::Time::EndFrame();
|
||||||
|
|
||||||
@@ -193,7 +206,5 @@ void Loop()
|
|||||||
|
|
||||||
void Clean()
|
void Clean()
|
||||||
{
|
{
|
||||||
Game::CleanGame();
|
UE::Engine::Clean();
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
}
|
||||||
@@ -33,14 +33,14 @@ public:
|
|||||||
{
|
{
|
||||||
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
||||||
|
|
||||||
UE::AssetManager* as = Game::GetAssetManager();
|
UE::AssetManager* as = UE::Engine::GetAssetManager();
|
||||||
UE::Texture* test1Texture = as->getTexture("test1");
|
UE::Texture* test1Texture = as->getTexture("test1");
|
||||||
|
|
||||||
UE::Sprite sp1(test1Texture, 0, 2, glm::vec2(55, 60), glm::vec2(100, 100));
|
UE::Sprite sp1(test1Texture, 0, 2, glm::vec2(55, 60), glm::vec2(100, 100));
|
||||||
|
|
||||||
UE::Sprite sp2(test1Texture, 0, 1, glm::vec2(50, 45), glm::vec2(145, 145));
|
UE::Sprite sp2(test1Texture, 0, 1, glm::vec2(50, 45), glm::vec2(145, 145));
|
||||||
|
|
||||||
UE::Sprite bg(as->getTexture("bg1"), 1, 0, glm::vec2(0, 0), Game::GetRenderer()->GetScreenSize());
|
UE::Sprite bg(as->getTexture("bg1"), 1, 0, glm::vec2(0, 0), UE::Engine::GetRenderer()->GetScreenSize());
|
||||||
|
|
||||||
UE::Sprite mapSP(as->getTexture("PruebaMap"), 0, 2, glm::vec2(50, 45), glm::vec2(145, 145));
|
UE::Sprite mapSP(as->getTexture("PruebaMap"), 0, 2, glm::vec2(50, 45), glm::vec2(145, 145));
|
||||||
|
|
||||||
@@ -65,9 +65,9 @@ public:
|
|||||||
//UE_LOG_INFO("Escena {0} UPDATE", _sceneName);
|
//UE_LOG_INFO("Escena {0} UPDATE", _sceneName);
|
||||||
|
|
||||||
UE::Renderer* renderer;
|
UE::Renderer* renderer;
|
||||||
renderer = Game::GetRenderer();
|
renderer = UE::Engine::GetRenderer();
|
||||||
|
|
||||||
glm::vec2 screenSize = Game::GetRenderer()->GetScreenSize();
|
glm::vec2 screenSize = UE::Engine::GetRenderer()->GetScreenSize();
|
||||||
|
|
||||||
UE::Sprite& sp1 = sprites.at(0);
|
UE::Sprite& sp1 = sprites.at(0);
|
||||||
glm::vec2 pos = sp1.GetPosition();
|
glm::vec2 pos = sp1.GetPosition();
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
void SceneRender() override
|
void SceneRender() override
|
||||||
{
|
{
|
||||||
UE::Renderer* renderer;
|
UE::Renderer* renderer;
|
||||||
renderer = Game::GetRenderer();
|
renderer = UE::Engine::GetRenderer();
|
||||||
|
|
||||||
for (UE::Sprite& sp : sprites)
|
for (UE::Sprite& sp : sprites)
|
||||||
{
|
{
|
||||||
@@ -239,7 +239,7 @@ private:
|
|||||||
|
|
||||||
void AssetMngGUI()
|
void AssetMngGUI()
|
||||||
{
|
{
|
||||||
UE::AssetManager* asmng = Game::GetAssetManager();
|
UE::AssetManager* asmng = UE::Engine::GetAssetManager();
|
||||||
|
|
||||||
ImGui::Begin("Asset Manager Inspector", &assetMngGUI);
|
ImGui::Begin("Asset Manager Inspector", &assetMngGUI);
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public:
|
|||||||
|
|
||||||
srand(255);
|
srand(255);
|
||||||
|
|
||||||
UE::AssetManager* as = Game::GetAssetManager();
|
UE::AssetManager* as = UE::Engine::GetAssetManager();
|
||||||
|
|
||||||
UE::Texture* tx = as->getTexture("PruebaMap");
|
UE::Texture* tx = as->getTexture("PruebaMap");
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
void SceneRender() override
|
void SceneRender() override
|
||||||
{
|
{
|
||||||
UE::Renderer* renderer;
|
UE::Renderer* renderer;
|
||||||
renderer = Game::GetRenderer();
|
renderer = UE::Engine::GetRenderer();
|
||||||
|
|
||||||
for (UE::Sprite& sp : sprites)
|
for (UE::Sprite& sp : sprites)
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (event->type == SDL_MOUSEBUTTONDOWN)
|
if (event->type == SDL_MOUSEBUTTONDOWN)
|
||||||
{
|
{
|
||||||
UE::Renderer* rend = Game::GetRenderer();
|
UE::Renderer* rend = UE::Engine::GetRenderer();
|
||||||
glm::ivec2 mPos(event->button.x, event->button.y);
|
glm::ivec2 mPos(event->button.x, event->button.y);
|
||||||
glm::ivec2 wPos = rend->ScreenToWorldCoords(mPos);
|
glm::ivec2 wPos = rend->ScreenToWorldCoords(mPos);
|
||||||
GAME_LOG_TRACE("Posicion del raton: \n\tPantalla: {0}x{1}, Mundo: {2}x{3}: ", mPos.x, mPos.y, wPos.x, wPos.y);
|
GAME_LOG_TRACE("Posicion del raton: \n\tPantalla: {0}x{1}, Mundo: {2}x{3}: ", mPos.x, mPos.y, wPos.x, wPos.y);
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#include "UberGame1.h"
|
|
||||||
|
|
||||||
#include "Logging/Logger.h"
|
|
||||||
#include "Render/Renderer.h"
|
|
||||||
#include "Assets/AssetManager.h"
|
|
||||||
|
|
||||||
#include "Scene/SceneManager.h"
|
|
||||||
|
|
||||||
//Sobrecarga de SceneBuilder que devuelve las escenas correctas para este juego.
|
|
||||||
//#include "GameScenes.hpp"
|
|
||||||
|
|
||||||
UE::Renderer* Game::mainRenderer;
|
|
||||||
UE::AssetManager* Game::asManager;
|
|
||||||
UE::SceneManager* Game::scManager;
|
|
||||||
|
|
||||||
void Game::InitGame()
|
|
||||||
{
|
|
||||||
//Cargamos el Renderer.
|
|
||||||
//Hay que implementar un sistema de flags o
|
|
||||||
// una struct de configuración para la inicialización del renderer.
|
|
||||||
mainRenderer = new UE::Renderer(640, 480, 5);
|
|
||||||
mainRenderer->InitRenderer();
|
|
||||||
|
|
||||||
UE_LOG_INFO("Renderer Created.");
|
|
||||||
|
|
||||||
//Cargamos el AssetManager
|
|
||||||
asManager = new UE::AssetManager(mainRenderer->GetSDLRenderer());
|
|
||||||
asManager->InitAssetManager();
|
|
||||||
UE_LOG_INFO("AssetManager Created.");
|
|
||||||
|
|
||||||
//Cargamos el SceneManager
|
|
||||||
scManager = new UE::SceneManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::CleanGame()
|
|
||||||
{
|
|
||||||
asManager->CleanAssetManager();
|
|
||||||
delete asManager;
|
|
||||||
|
|
||||||
mainRenderer->CleanRenderer();
|
|
||||||
delete mainRenderer;
|
|
||||||
|
|
||||||
scManager->CleanSceneManager();
|
|
||||||
delete scManager;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace UE
|
|
||||||
{
|
|
||||||
class Renderer;
|
|
||||||
class AssetManager;
|
|
||||||
class SceneManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Game
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void InitGame();
|
|
||||||
static void CleanGame();
|
|
||||||
|
|
||||||
inline static UE::Renderer* GetRenderer() { return mainRenderer; }
|
|
||||||
inline static UE::AssetManager* GetAssetManager() { return asManager; }
|
|
||||||
inline static UE::SceneManager* GetSceneManager() { return scManager; }
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
static UE::Renderer* mainRenderer;
|
|
||||||
static UE::AssetManager* asManager;
|
|
||||||
static UE::SceneManager* scManager;
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user