El regreso tras mucho tiempo...
Sinceramente, no sé lo que puede haber aquí.
This commit is contained in:
@@ -6,30 +6,36 @@ Repositorio principal de UberEngine. Sin mucho más.
|
|||||||
## To-Do:
|
## To-Do:
|
||||||
|
|
||||||
### General / Arquitectura
|
### General / Arquitectura
|
||||||
- Reestructuración completa de la clase Game y del "Entry Point".
|
- [ ] Reestructuración completa de la clase Game y del "Entry Point".
|
||||||
- Convertir la clase Game a Static completamente.
|
- [ ] Convertir la clase Game a Static completamente.
|
||||||
- Unificar todas las inicialziaciones de librerias en una función en UberEngine.
|
- [ ] Unificar todas las inicialziaciones de librerias en una función en UberEngine.
|
||||||
- ¿¡Dividir entre la inicialización del propio juego/app y la de los sistemas del motor!?
|
- [ ] ¿¡Dividir entre la inicialización del propio juego/app y la de los sistemas del motor!?
|
||||||
- Revisar la inclusión de librerias en los headers.
|
- [ ] Limpiar dependencias entre clases (no es necesario que las texturas o el AssetManager almacenen un ptr al renderer y cosas así).
|
||||||
- ¡DOCUMENTACIÓN DE LA ARQUITECTURA! Quizás comentar un poco lo que hace o se supone que hace cada método. O si alguno es muy complejo, comentar el funcionamiento.
|
- [ ] Revisar la inclusión de librerias en los headers.
|
||||||
- Crear un conjunto de tipos (typedef) de UberEngine para encapsular los vectores de GLM. (Son muy largos: glm::vec<4, int, glm::highpacked> -> UE_Color ó UE_Vec4).
|
- [ ] ¡DOCUMENTACIÓN DE LA ARQUITECTURA! Quizás comentar un poco lo que hace o se supone que hace cada método. O si alguno es muy complejo, comentar el funcionamiento.
|
||||||
- Algún día, tocara revisar los cientos de Warning que hay...
|
- [ ] Crear un conjunto de tipos (typedef) de UberEngine para encapsular los vectores de GLM. (Son muy largos: glm::vec<4, int, glm::highpacked> -> UE_Color ó UE_Vec4).
|
||||||
|
- [ ] Algún día, tocara revisar los cientos de Warning que hay...
|
||||||
|
|
||||||
### Renderer:
|
### Renderer:
|
||||||
- Reestructurar la arquitectura de cola de renderizado del Renderer (El sistema de DrawCalls tiene sus problemillas...).
|
- [ ] Reestructurar la arquitectura de cola de renderizado del Renderer (El sistema de DrawCalls tiene sus problemillas...).
|
||||||
-
|
- [ ] Revisar Método IsObjectVisible (estoy mezclando vectores de cosas diferentes).
|
||||||
|
- [ ] Añadir un sistema de zoom/tamaño para la cámara.
|
||||||
|
|
||||||
### Drawables:
|
### Drawables:
|
||||||
- ¿Mover isActive al Drawable e implementarlo a nivel global (en el renderer)?
|
- [ ] ¿Mover isActive al Drawable e implementarlo a nivel global (en el renderer)?
|
||||||
- Métodos para la conversión de coord World-Screen / Screen-World.
|
- [X] Métodos para la conversión de coord World-Screen / Screen-World.
|
||||||
|
|
||||||
|
|
||||||
### Fonts / Text rendering / TextBox
|
### Fonts / Text rendering / TextBox
|
||||||
- Las fuentes no siguen el modelo estandar de Assets. El Asset contiene directamente el objeto, no un documento de datos del objeto.
|
- [X] Las fuentes no siguen el modelo estandar de Assets. El Asset contiene directamente el objeto, no un documento de datos del objeto.
|
||||||
- Revisar el sistema de fuentes de assetManager.
|
- [X] Revisar el sistema de fuentes de assetManager.
|
||||||
- No se cierran (TTF_CloseFont) las fuentes al salir.
|
- [X] No se cierran (TTF_CloseFont) las fuentes al salir.
|
||||||
- Revisar el correcto funcionamiento de los métodos de TextBox.
|
- [ ] Revisar el correcto funcionamiento de los métodos de TextBox.
|
||||||
- Investigar formas de cambiar el tamaño al texto (TextBoxs) sin tener que modificar la fuente.
|
- [X] Investigar formas de cambiar el tamaño al texto (TextBoxs) sin tener que modificar la fuente.
|
||||||
|
|
||||||
### Memory Leaks:
|
### Memory Leaks:
|
||||||
- AssetManager: Al eliminar una textura, no limpiamos el conjunto de SDL_Rects asociado.
|
- [ ] AssetManager: Al eliminar una textura, no limpiamos el conjunto de SDL_Rects asociado.
|
||||||
- AssetManager: Creo que también hay que limpiar las fonts cargadas....
|
- [X] AssetManager: Creo que también hay que limpiar las fonts cargadas....
|
||||||
|
|
||||||
|
### JSON / AssetManager
|
||||||
|
- [ ] Crear un sistema sencillo (un método o algo común para todas las veces que sea necesario) para añadir seguridad al parse y uso de los JSON. De tal forma que se devuelva el error por consola pero no salten exepciones ni mierdas.
|
||||||
@@ -38,7 +38,7 @@ namespace UE
|
|||||||
//Destruye todas las texturas de SDL.
|
//Destruye todas las texturas de SDL.
|
||||||
for (auto i = _textures.begin(); i != _textures.end(); i++)
|
for (auto i = _textures.begin(); i != _textures.end(); i++)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(i->second);
|
i->second->~Texture();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Limpiamos las fuentes.
|
//Limpiamos las fuentes.
|
||||||
@@ -51,7 +51,6 @@ namespace UE
|
|||||||
//CPP se debería de encargar de ellos, pero bueno.
|
//CPP se debería de encargar de ellos, pero bueno.
|
||||||
_assetQueue.clear();
|
_assetQueue.clear();
|
||||||
_textures.clear();
|
_textures.clear();
|
||||||
_textureRects.clear();
|
|
||||||
|
|
||||||
|
|
||||||
IMG_Quit();
|
IMG_Quit();
|
||||||
@@ -62,11 +61,14 @@ namespace UE
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AssetManager::LoadAssetsFromFile(std::string filePath, LoadMethod loadMethod)
|
void AssetManager::LoadAssetsFromFile(std::string filePath)
|
||||||
{
|
{
|
||||||
std::fstream file(filePath.c_str());
|
std::fstream file(filePath.c_str());
|
||||||
|
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("No se ha podido abrir la lista de assets: {0}", filePath);
|
||||||
|
}
|
||||||
|
|
||||||
//Load Asset data from JSON.
|
//Load Asset data from JSON.
|
||||||
json jread = json::parse(file);
|
json jread = json::parse(file);
|
||||||
@@ -76,29 +78,22 @@ namespace UE
|
|||||||
json Sounds = jread["Sounds"];
|
json Sounds = jread["Sounds"];
|
||||||
json Others = jread["Others"];
|
json Others = jread["Others"];
|
||||||
|
|
||||||
if (loadMethod == LoadMethod::Queue)
|
/* Add assets struct to asset map. */
|
||||||
|
for (int i = 0; i < Textures.size(); i++)
|
||||||
{
|
{
|
||||||
/* Add assets struct to asset map. */
|
_assetQueue.push_back(Textures.at(i));
|
||||||
for (int i = 0; i < Textures.size(); i++)
|
|
||||||
{
|
|
||||||
_assetQueue.push_back(Textures.at(i));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < Fonts.size(); i++)
|
|
||||||
{
|
|
||||||
_assetQueue.push_back(Fonts.at(i));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < Sounds.size(); i++)
|
|
||||||
{
|
|
||||||
_assetQueue.push_back(Sounds.at(i));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < Others.size(); i++)
|
|
||||||
{
|
|
||||||
_assetQueue.push_back(Others.at(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (loadMethod == LoadMethod::Now)
|
for (int i = 0; i < Fonts.size(); i++)
|
||||||
{
|
{
|
||||||
//TODO
|
_assetQueue.push_back(Fonts.at(i));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Sounds.size(); i++)
|
||||||
|
{
|
||||||
|
_assetQueue.push_back(Sounds.at(i));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Others.size(); i++)
|
||||||
|
{
|
||||||
|
_assetQueue.push_back(Others.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,17 +101,9 @@ namespace UE
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AssetManager::LoadAsset(Asset& as, LoadMethod loadMethod)
|
void AssetManager::LoadAsset(Asset& as)
|
||||||
{
|
{
|
||||||
if (loadMethod == LoadMethod::Queue)
|
_assetQueue.push_back(as);
|
||||||
{
|
|
||||||
_assetQueue.push_back(as);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadMethod == LoadMethod::Now)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -158,44 +145,45 @@ namespace UE
|
|||||||
|
|
||||||
void AssetManager::LoadTexture(std::string name, std::string txPath)
|
void AssetManager::LoadTexture(std::string name, std::string txPath)
|
||||||
{
|
{
|
||||||
std::fstream file(txPath.c_str());
|
Texture* tx = new Texture(txPath, _SDL_Renderer);
|
||||||
|
|
||||||
json jread = json::parse(file);
|
|
||||||
std::string path = jread["TexturePath"];
|
|
||||||
|
|
||||||
//Cargamos la textura.
|
|
||||||
SDL_Surface* loadSurface = IMG_Load(path.c_str());
|
|
||||||
SDL_Texture* tx = SDL_CreateTextureFromSurface(_mainRenderer, loadSurface);
|
|
||||||
_textures.insert(std::make_pair(name, tx));
|
_textures.insert(std::make_pair(name, tx));
|
||||||
SDL_FreeSurface(loadSurface);
|
|
||||||
|
|
||||||
//Almacenamos los Rects (sprites) de esa textura.
|
//std::fstream file(txPath.c_str());
|
||||||
json textureRects = jread["TextureRects"];
|
|
||||||
|
|
||||||
_textureRects.insert(std::make_pair(name, std::vector<SDL_Rect>()));
|
//json jread = json::parse(file);
|
||||||
std::vector<SDL_Rect>& vector = _textureRects.at(name);
|
//std::string path = jread["TexturePath"];
|
||||||
|
|
||||||
for (int i = 0; i < textureRects.size(); i++)
|
////Cargamos la textura.
|
||||||
{
|
//SDL_Surface* loadSurface = IMG_Load(path.c_str());
|
||||||
//json rectData = textureRects.at(i);
|
//SDL_Texture* tx = SDL_CreateTextureFromSurface(_mainRenderer, loadSurface);
|
||||||
//SDL_Rect rect;
|
//_textures.insert(std::make_pair(name, tx));
|
||||||
//rect.x = rectData.at()
|
//SDL_FreeSurface(loadSurface);
|
||||||
|
|
||||||
vector.push_back(textureRects.at(i).get<SDL_Rect>());
|
////Almacenamos los Rects (sprites) de esa textura.
|
||||||
}
|
//json textureRects = jread["TextureRects"];
|
||||||
|
|
||||||
|
//_textureRects.insert(std::make_pair(name, std::vector<SDL_Rect>()));
|
||||||
|
//std::vector<SDL_Rect>& vector = _textureRects.at(name);
|
||||||
|
|
||||||
|
//for (int i = 0; i < textureRects.size(); i++)
|
||||||
|
//{
|
||||||
|
// //json rectData = textureRects.at(i);
|
||||||
|
// //SDL_Rect rect;
|
||||||
|
// //rect.x = rectData.at()
|
||||||
|
|
||||||
|
// vector.push_back(textureRects.at(i).get<SDL_Rect>());
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
file.close();
|
//file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AssetManager::RemoveTexture(std::string name)
|
void AssetManager::RemoveTexture(std::string name)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(_textures.at(name));
|
//Se supone que el erase del map llama al destructor del objeto...
|
||||||
|
//Pero no lo he comprobado del todo.
|
||||||
_textures.erase(name);
|
_textures.erase(name);
|
||||||
|
|
||||||
SDL_Rect rect();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -207,6 +195,14 @@ namespace UE
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AssetManager::RemoveFont(std::string name)
|
||||||
|
{
|
||||||
|
//Se supone que el erase del map llama al destructor del objeto...
|
||||||
|
//Pero no lo he comprobado del todo.
|
||||||
|
_fonts.erase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////DEBUG//////////
|
//////////DEBUG//////////
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
/*LIB Includes*/
|
/*LIB Includes*/
|
||||||
#include <SDL_render.h>
|
#include <SDL_render.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <SDL_ttf.h>
|
|
||||||
|
|
||||||
/*UberEngine Includes*/
|
/*UberEngine Includes*/
|
||||||
#include "Assets\Asset.h"
|
#include "Assets\Asset.h"
|
||||||
|
#include "Assets\Texture.h"
|
||||||
#include "Assets\Font.h"
|
#include "Assets\Font.h"
|
||||||
|
|
||||||
using json = nlohmann::ordered_json;
|
using json = nlohmann::ordered_json;
|
||||||
@@ -34,24 +34,13 @@ using json = nlohmann::ordered_json;
|
|||||||
namespace UE
|
namespace UE
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class LoadMethod
|
|
||||||
{
|
|
||||||
//Añade los Assets a una cola, que será procesada poco a poco mediante ProcessAssetQueue().
|
|
||||||
Queue,
|
|
||||||
|
|
||||||
//Carga el Asset directamente sin pasar por la cola. Cargar muchos assets a la vez así puede detener
|
|
||||||
//el programa hasta que se termine la carga, dando una sensación de unresponsividad.
|
|
||||||
Now
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Gestiona todos assets primitivos, almacenando sus ptrs en un lugar seguro. */
|
/* Gestiona todos assets primitivos, almacenando sus ptrs en un lugar seguro. */
|
||||||
class AssetManager
|
class AssetManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Constructor. */
|
/* Constructor. */
|
||||||
AssetManager(SDL_Renderer* SDLrenderer)
|
AssetManager(SDL_Renderer* SDLrenderer)
|
||||||
: _mainRenderer(SDLrenderer) {}
|
: _SDL_Renderer(SDLrenderer) {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +67,7 @@ namespace UE
|
|||||||
* \param loadMethod: Forma de carga. Procesado al momento o añadido a la cola de carga.
|
* \param loadMethod: Forma de carga. Procesado al momento o añadido a la cola de carga.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void LoadAssetsFromFile(std::string filePath, LoadMethod loadMethod = LoadMethod::Queue);
|
void LoadAssetsFromFile(std::string filePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Carga el Asset pasado por parámetro.
|
* Carga el Asset pasado por parámetro.
|
||||||
@@ -87,7 +76,7 @@ namespace UE
|
|||||||
* \param loadMethod: Forma de carga. Procesado al momento o añadido a la cola de carga.
|
* \param loadMethod: Forma de carga. Procesado al momento o añadido a la cola de carga.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void LoadAsset(Asset& as, LoadMethod loadMethod = LoadMethod::Queue);
|
void LoadAsset(Asset& as);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,12 +94,16 @@ namespace UE
|
|||||||
*/
|
*/
|
||||||
inline int GetAssetQueueSize() { return _assetQueue.size(); }
|
inline int GetAssetQueueSize() { return _assetQueue.size(); }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comprueba si la cola de carga de Assets está vacía.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>El resultado de la cola.</returns>
|
||||||
inline bool IsAssetQueueEmpty() { return _assetQueue.empty(); }
|
inline bool IsAssetQueueEmpty() { return _assetQueue.empty(); }
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*--------------------------------------/
|
||||||
Métodos para manejar las SDL_Texture* almacenados.
|
* Métodos para manejar las texturas. *
|
||||||
*/
|
*--------------------------------------*/
|
||||||
|
|
||||||
//Crea una textura de SDL y la añade al mapa de texturas identificada por su nombre.
|
//Crea una textura de SDL y la añade al mapa de texturas identificada por su nombre.
|
||||||
void LoadTexture(std::string name, std::string txPath);
|
void LoadTexture(std::string name, std::string txPath);
|
||||||
@@ -119,17 +112,40 @@ namespace UE
|
|||||||
void RemoveTexture(std::string name);
|
void RemoveTexture(std::string name);
|
||||||
|
|
||||||
//Obtiene una textura del mapa a partir de su nombre.
|
//Obtiene una textura del mapa a partir de su nombre.
|
||||||
inline SDL_Texture* getTexture(std::string textureName) { return _textures.at(textureName); }
|
//inline SDL_Texture* getTexture(std::string textureName) { return _textures.at(textureName); }
|
||||||
|
inline Texture* getTexture(std::string textureName) { return _textures.at(textureName); }
|
||||||
|
|
||||||
inline std::vector<SDL_Rect>* getTexureRects(std::string textureName) { return &_textureRects.at(textureName); }
|
//inline std::vector<SDL_Rect>* getTexureRects(std::string textureName) { return &_textureRects.at(textureName); }
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*------------------------------------/
|
||||||
Métodos para manejar las fuentes.
|
* Métodos para manejar las fuentes. *
|
||||||
|
*------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crea un objeto UE:Font y lo añade al mapa de fuentes.
|
||||||
|
*
|
||||||
|
* @param name : Nombre del asset (key para el mapa de fuentes).
|
||||||
|
* @param fontPath : Ubicación del archivo de datos sobre la fuente.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
//Carga una fuente.
|
|
||||||
void LoadFont(std::string name, std::string fontPath);
|
void LoadFont(std::string name, std::string fontPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elimina una fuente (y en teoría limpia la fuente) dado su nombre de Asset.
|
||||||
|
*
|
||||||
|
* @param name : Nombre del Asset (key del mapa de fuentes).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void RemoveFont(std::string name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene y devuelve el ptr a una fuente dado su nombre de asset.
|
||||||
|
*
|
||||||
|
* @param fontName : Nombre del Asset.
|
||||||
|
* @return UE::Font* : El ptr a la fuente solicitada.
|
||||||
|
*
|
||||||
|
*/
|
||||||
inline Font* GetFont(std::string fontName) { return _fonts.at(fontName); }
|
inline Font* GetFont(std::string fontName) { return _fonts.at(fontName); }
|
||||||
|
|
||||||
|
|
||||||
@@ -153,15 +169,16 @@ namespace UE
|
|||||||
/* Almacenes de asssets */
|
/* Almacenes de asssets */
|
||||||
|
|
||||||
//Almacén de SDL_Texture* (ptrs, pues lo gestiona SDL).
|
//Almacén de SDL_Texture* (ptrs, pues lo gestiona SDL).
|
||||||
std::unordered_map<std::string, SDL_Texture*> _textures = {};
|
//std::unordered_map<std::string, SDL_Texture*> _textures = {};
|
||||||
std::unordered_map<std::string, std::vector<SDL_Rect>> _textureRects = {};
|
//std::unordered_map<std::string, std::vector<SDL_Rect>> _textureRects = {};
|
||||||
|
std::unordered_map <std::string, Texture*> _textures = {};
|
||||||
|
|
||||||
//Almacen de TTF_Fonts* (Para las fuentes de SDL_TTF).
|
//Almacen de TTF_Fonts* (Para las fuentes de SDL_TTF).
|
||||||
std::unordered_map<std::string, Font*> _fonts = {};
|
std::unordered_map<std::string, Font*> _fonts = {};
|
||||||
|
|
||||||
|
|
||||||
//Necesario para crear las SDL_Texture a partir de SDL_Surface.
|
//Necesario para crear las SDL_Texture a partir de SDL_Surface.
|
||||||
SDL_Renderer* _mainRenderer = NULL;
|
SDL_Renderer* _SDL_Renderer = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ void UE::Font::InitFont()
|
|||||||
//Cargamos los datos desde el archivo.
|
//Cargamos los datos desde el archivo.
|
||||||
std::fstream file(_dataPath.c_str());
|
std::fstream file(_dataPath.c_str());
|
||||||
|
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("No se ha podido abrir el archivo de datos de fuente: {0}", _fontPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
json jread = json::parse(file);
|
json jread = json::parse(file);
|
||||||
|
|
||||||
_fontPath = jread["FontPath"].get<std::string>();
|
_fontPath = jread["FontPath"].get<std::string>();
|
||||||
@@ -41,6 +47,8 @@ void UE::Font::InitFont()
|
|||||||
{
|
{
|
||||||
CreateFontSize(it);
|
CreateFontSize(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UE::Font::CleanFont()
|
void UE::Font::CleanFont()
|
||||||
|
|||||||
@@ -7,10 +7,19 @@
|
|||||||
|
|
||||||
namespace UE
|
namespace UE
|
||||||
{
|
{
|
||||||
//Clase que representa una fuente. El objetivo es poder tener múltiples tamaños de esta de forma sencilla.
|
/**
|
||||||
|
* Clase Wrapper para las SDL_Fonts.
|
||||||
|
* También sirve de "cache" para los diferentes tamaños de la fuente, de esta forma
|
||||||
|
* reducimos las veces que generamos las fuentes y podemos utilizar múltiples tamaños de forma sencilla.
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Font
|
class Font
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//-----------------------
|
||||||
|
//----- Constructor -----
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
Font(std::string dataPath)
|
Font(std::string dataPath)
|
||||||
: _dataPath(dataPath)
|
: _dataPath(dataPath)
|
||||||
{
|
{
|
||||||
@@ -22,26 +31,54 @@ namespace UE
|
|||||||
CleanFont();
|
CleanFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Devuelve la fuente del tamaño indicado. En caso de no estar disponible, la carga y la devuelve.
|
//-----------------------
|
||||||
|
//------- Methods -------
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Devuelve la fuente del tamaño pedido.
|
||||||
|
* En caso de no estar disponible, la genera y la añade al cache antes de devolverla.
|
||||||
|
*
|
||||||
|
* @param size : tamaño de la fuente.
|
||||||
|
* @return TTF_Font* : Fuente del tamaño solicitado.
|
||||||
|
*/
|
||||||
TTF_Font* GetFont(int size);
|
TTF_Font* GetFont(int size);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Crea la fuente a partir del archivo de datos.
|
||||||
|
*/
|
||||||
void InitFont();
|
void InitFont();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limpia la fuente, eliminando todos sus tamaños y vaciando toda la memoria.
|
||||||
|
*/
|
||||||
void CleanFont();
|
void CleanFont();
|
||||||
|
|
||||||
//Crea la fuente del tamaño deseado y devuelve su ptr.
|
/**
|
||||||
|
* Se encarga de generar el tamaño de fuente deseado.
|
||||||
|
*
|
||||||
|
* @param size : tamaño a generar.
|
||||||
|
* @return TTF_Font* : Ptr al nuevo tamaño generado. Hay que guardarlo en algún sitio.
|
||||||
|
*/
|
||||||
TTF_Font* CreateFontSize(int size);
|
TTF_Font* CreateFontSize(int size);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------
|
||||||
|
//------ Variables ------
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//Ubicación del archivo de datos (.json).
|
||||||
std::string _dataPath = "";
|
std::string _dataPath = "";
|
||||||
|
|
||||||
|
//Ubicación de la tipografía (.ttf).
|
||||||
std::string _fontPath = "";
|
std::string _fontPath = "";
|
||||||
|
|
||||||
//Mapa que contiene un ptr a la fuente con diferentes tamaños.
|
//Caché de los diferentes tamaños de la fuente.
|
||||||
std::unordered_map<int, TTF_Font*> _fonts;
|
std::unordered_map<int, TTF_Font*> _fonts = {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#include "Texture.h"
|
||||||
|
#include "Logging\Logger.h"
|
||||||
|
|
||||||
|
#include "Asset.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <json\json.hpp>
|
||||||
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
|
SDL_Rect* UE::Texture::GetTextureRect(int i)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SDL_Rect* rect = &_txRects.at(i);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
catch (const std::out_of_range&)
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("La textura {0} no tiene rect {1}", _txPath, i);
|
||||||
|
return &_txRects.at(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UE::Texture::InitTexture()
|
||||||
|
{
|
||||||
|
std::fstream file(_dataPath);
|
||||||
|
//Comprobamos si el archivo se ha abierto.
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
UE_LOG_ERROR("No se ha podido abrir el archivo de datos de textura: {0}", _dataPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
json jread = json::parse(file);
|
||||||
|
_txPath = jread["TexturePath"].get<std::string>();
|
||||||
|
|
||||||
|
//Creamos la textura.
|
||||||
|
CreateTexture();
|
||||||
|
|
||||||
|
//Cargamos los Rects.
|
||||||
|
json textureRects = jread["TextureRects"];
|
||||||
|
|
||||||
|
for (int i = 0; i < textureRects.size(); i++)
|
||||||
|
{
|
||||||
|
AddRect(textureRects.at(i).get<SDL_Rect>());
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UE::Texture::CleanTexture()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(_texture);
|
||||||
|
_txRects.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UE::Texture::CreateTexture()
|
||||||
|
{
|
||||||
|
SDL_Surface* loadSurface = IMG_Load(_txPath.c_str());
|
||||||
|
_texture = SDL_CreateTextureFromSurface(_SDL_Renderer, loadSurface);
|
||||||
|
SDL_FreeSurface(loadSurface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UE::Texture::AddRect(SDL_Rect newRect)
|
||||||
|
{
|
||||||
|
_txRects.push_back(newRect);
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <SDL_image.h>
|
||||||
|
#include <SDL_render.h>
|
||||||
|
|
||||||
|
namespace UE
|
||||||
|
{
|
||||||
|
|
||||||
|
class Texture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//-----------------------
|
||||||
|
//----- Constructor -----
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
Texture(std::string dataPath, SDL_Renderer* renderer)
|
||||||
|
: _dataPath(dataPath), _SDL_Renderer(renderer)
|
||||||
|
{
|
||||||
|
InitTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
~Texture()
|
||||||
|
{
|
||||||
|
CleanTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------
|
||||||
|
//------- Methods -------
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retorna la textura.
|
||||||
|
*/
|
||||||
|
inline SDL_Texture* GetTexture() { return _texture; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retorna los Rects de la textura.
|
||||||
|
*/
|
||||||
|
inline std::vector<SDL_Rect>* GetRectsVector() { return &_txRects; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retorna el Rect pedido. Comprobando que está disponible.
|
||||||
|
* Si no está disponible, devuelve el rect de index 0 (que debería ser el por defecto).
|
||||||
|
*
|
||||||
|
* @param i : Índice del rect.
|
||||||
|
* @return El SDL_Rect* solicitado (o el por defecto en caso de error).
|
||||||
|
*/
|
||||||
|
SDL_Rect* GetTextureRect(int i);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Carga los datos desde el archivo de datos y crea la textura y sus rects.
|
||||||
|
*/
|
||||||
|
void InitTexture();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limpia todos los datos guardados.
|
||||||
|
*/
|
||||||
|
void CleanTexture();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Método encargado de generar la textura a partir de los valores de la clase.
|
||||||
|
*/
|
||||||
|
void CreateTexture();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Método que añade un SDL_Rect al vector correspondiente.
|
||||||
|
* @param newRect : Nuevo Rect que añadir al vector de Rects.
|
||||||
|
*/
|
||||||
|
void AddRect(SDL_Rect newRect);
|
||||||
|
|
||||||
|
//-----------------------
|
||||||
|
//------ Variables ------
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Ubicación del archivo de datos (.json).
|
||||||
|
std::string _dataPath = "";
|
||||||
|
|
||||||
|
//El propio renderer de SDL. Es necesario para crear y operar con las SDL_Textures.
|
||||||
|
SDL_Renderer* _SDL_Renderer = nullptr;
|
||||||
|
|
||||||
|
//Ubicación de la textura (.png).
|
||||||
|
std::string _txPath = "";
|
||||||
|
|
||||||
|
//La propia textura.
|
||||||
|
SDL_Texture* _texture = nullptr;
|
||||||
|
//Conjunto de rects que hay en la textura.
|
||||||
|
std::vector<SDL_Rect> _txRects = {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,12 @@
|
|||||||
|
|
||||||
void UE::Sprite::SetTextureRect(int textureID)
|
void UE::Sprite::SetTextureRect(int textureID)
|
||||||
{
|
{
|
||||||
_actualTxRect = &_txRects->at(textureID);
|
SDL_Rect* newRect = _texture->GetTextureRect(textureID);
|
||||||
|
|
||||||
|
if (newRect != nullptr)
|
||||||
|
{
|
||||||
|
_actualTxRect = newRect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UE::Sprite::SetActive(bool active)
|
void UE::Sprite::SetActive(bool active)
|
||||||
@@ -25,7 +30,11 @@ bool UE::Sprite::IsActive()
|
|||||||
|
|
||||||
void UE::Sprite::Draw(Renderer* renderer)
|
void UE::Sprite::Draw(Renderer* renderer)
|
||||||
{
|
{
|
||||||
SDL_Rect position = { _pos.x, _pos.y, _size.x, _size.y };
|
//Convertimos a ScreenCoords.
|
||||||
|
glm::ivec2 screenCoords = renderer->WorldToSreenCoords(_pos);
|
||||||
|
|
||||||
|
SDL_Rect position = { screenCoords.x, screenCoords.y, _size.x, _size.y };
|
||||||
|
|
||||||
//destination.x = _pos.x;
|
//destination.x = _pos.x;
|
||||||
//destination.y = _pos.y;
|
//destination.y = _pos.y;
|
||||||
//
|
//
|
||||||
@@ -33,6 +42,12 @@ void UE::Sprite::Draw(Renderer* renderer)
|
|||||||
//destination.h = _size.y;
|
//destination.h = _size.y;
|
||||||
|
|
||||||
//std::cout << "Sprite Rendered to: " << destination.x << "-" << destination.y << std::endl;
|
//std::cout << "Sprite Rendered to: " << destination.x << "-" << destination.y << std::endl;
|
||||||
renderer->QueueDrawCall(_renderLayer, position, _txPtr, *_actualTxRect);
|
renderer->QueueDrawCall(_renderLayer, position, _texture->GetTexture(), *_actualTxRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect UE::Sprite::getPositionRect()
|
||||||
|
{
|
||||||
|
SDL_Rect position = { _pos.x, _pos.y, _size.x, _size.y };
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "Render\Drawable.h"
|
#include "Render\Drawable.h"
|
||||||
#include "Render\Transformable.h"
|
#include "Render\Transformable.h"
|
||||||
|
#include "Assets\Texture.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -45,14 +46,13 @@ namespace UE
|
|||||||
\param textureRectID: El número de Rect del conjunto de rects.
|
\param textureRectID: El número de Rect del conjunto de rects.
|
||||||
\param renderLayer: La Layer en que se renderizará.
|
\param renderLayer: La Layer en que se renderizará.
|
||||||
*/
|
*/
|
||||||
Sprite(SDL_Texture* texturePtr,
|
Sprite(UE::Texture* texture,
|
||||||
std::vector<SDL_Rect>* textureRects,
|
|
||||||
int textureRectID = 0,
|
int textureRectID = 0,
|
||||||
int renderLayer = 1,
|
int renderLayer = 1,
|
||||||
glm::vec2 position = glm::vec2(0, 0),
|
glm::vec2 position = glm::vec2(0, 0),
|
||||||
glm::vec2 size = glm::vec2(100, 100))
|
glm::vec2 size = glm::vec2(100, 100))
|
||||||
|
|
||||||
: _txPtr(texturePtr), _txRects(textureRects)
|
: _texture(texture)
|
||||||
{
|
{
|
||||||
SetTextureRect(textureRectID);
|
SetTextureRect(textureRectID);
|
||||||
|
|
||||||
@@ -79,13 +79,13 @@ namespace UE
|
|||||||
//Implementa el Draw de Drawable.
|
//Implementa el Draw de Drawable.
|
||||||
void Draw(Renderer* renderer) override;
|
void Draw(Renderer* renderer) override;
|
||||||
|
|
||||||
|
SDL_Rect getPositionRect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//Datos de la textura. Sirven para pedirla al AssetManager.
|
//Datos de la textura. Sirven para pedirla al AssetManager.
|
||||||
|
|
||||||
SDL_Texture* _txPtr = nullptr;
|
UE::Texture* _texture = nullptr;
|
||||||
std::vector<SDL_Rect>* _txRects = nullptr;
|
|
||||||
|
|
||||||
//El que se va a renderizar.
|
//El que se va a renderizar.
|
||||||
SDL_Rect* _actualTxRect = nullptr;
|
SDL_Rect* _actualTxRect = nullptr;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ namespace UE
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TextBox(UE::Font* font,
|
TextBox(UE::Font* font,
|
||||||
std::string text = "Texto por defecto",
|
std::string text = "Texto por defecto",
|
||||||
int textSize = 18,
|
int textSize = 18,
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ namespace UE
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
//Quizás deberíamos limpiar la cola y las Layers aquí para eliminar residuos...
|
//Quizás deberíamos limpiar la cola y las Layers aquí para eliminar residuos...
|
||||||
|
//callCounter = 0;
|
||||||
|
//rendererCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::RenderData()
|
void Renderer::RenderData()
|
||||||
@@ -153,7 +154,7 @@ namespace UE
|
|||||||
|
|
||||||
SDL_RenderPresent(main_Renderer);
|
SDL_RenderPresent(main_Renderer);
|
||||||
|
|
||||||
|
//UE_LOG_INFO("CallCounter: {0} ; Renderer: {1}", callCounter, rendererCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +178,42 @@ namespace UE
|
|||||||
//UE_LOG_TRACE("Cam position chaged to: {0}x{1}", posX, posY);
|
//UE_LOG_TRACE("Cam position chaged to: {0}x{1}", posX, posY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glm::ivec2 Renderer::WorldToSreenCoords(glm::ivec2 worldCoord)
|
||||||
|
{
|
||||||
|
//Convertimos las coordenas de WorldCoords a ScreenCoords relativas a la camPosition.
|
||||||
|
glm::ivec2 fPos = worldCoord - camPosition;
|
||||||
|
|
||||||
|
return fPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::ivec2 Renderer::ScreenToWorldCoords(glm::ivec2 screenCoord)
|
||||||
|
{
|
||||||
|
//Convertimos las coordenas de ScreenCoords a WorldCoords relativas a la camPosition.
|
||||||
|
glm::ivec2 fPos = screenCoord + camPosition;
|
||||||
|
|
||||||
|
return fPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CREO QUE ESTE MÉTODO NO FUNCIONA.
|
||||||
|
//LAS COORDS QUE USAMOS EN LA COMPROBACIÓN NO SON LAS ADECUADAS.
|
||||||
|
bool Renderer::IsObjectVisible(SDL_Rect* objectRect)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Generamos un rect que representa la pantalla.
|
||||||
|
SDL_Rect screen{ camPosition.x, camPosition.y, screenSize.x, screenSize.y };
|
||||||
|
//Comprobamos si hay intersección entre ambos.
|
||||||
|
if (!SDL_HasIntersection(&screen, objectRect))
|
||||||
|
{
|
||||||
|
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la cámara.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//¿Deberíamos operar la posición para que tenga en cuenta la cámara?
|
//¿Deberíamos operar la posición para que tenga en cuenta la cámara?
|
||||||
void Renderer::DrawObject(SDL_Rect* position, SDL_Rect* texture_pos, SDL_Texture* texture)
|
void Renderer::DrawObject(SDL_Rect* position, SDL_Rect* texture_pos, SDL_Texture* texture)
|
||||||
{
|
{
|
||||||
@@ -187,32 +224,26 @@ namespace UE
|
|||||||
|
|
||||||
void Renderer::QueueDrawCall(DrawCall drawCall)
|
void Renderer::QueueDrawCall(DrawCall drawCall)
|
||||||
{
|
{
|
||||||
|
//callCounter++;
|
||||||
//Add item i to layer number i.layer.
|
//Add item i to layer number i.layer.
|
||||||
if (drawCall.layer > LAYER_AMOUNT)
|
if (drawCall.layer > LAYER_AMOUNT)
|
||||||
{
|
{
|
||||||
UE_LOG_ERROR("Can't add DrawCall to Layer {0} -> out of range\n", drawCall.layer);
|
UE_LOG_ERROR("Can't add DrawCall to Layer {0} -> out of range\n", drawCall.layer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//Comprobamos si el objeto es visible.
|
||||||
//Comprobamos si el objeto es visible (está dentro de la cámara). En caso contrario, no tiene sentido renderizarlo.
|
//
|
||||||
SDL_Rect screen{ camPosition.x, camPosition.y, screenSize.x, screenSize.y };
|
//Generamos un rect que representa la pantalla.
|
||||||
|
SDL_Rect screen{ 0, 0, screenSize.x, screenSize.y };
|
||||||
|
//Comprobamos si hay intersección entre ambos.
|
||||||
if (!SDL_HasIntersection(&screen, &drawCall.pos_rect))
|
if (!SDL_HasIntersection(&screen, &drawCall.pos_rect))
|
||||||
{
|
{
|
||||||
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la cámara.");
|
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la cámara.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Convertimos la posición del objeto de WorldCoords y ScreenCoords relativas a la camPosition.
|
|
||||||
//Únicamente cambiamos las coords. Se podría añadir un modificador para el tamaño en relación al tamaño de la cam o algo así.
|
|
||||||
//WorldCoords = ScreenPos + CamPos -> ScreenPos = WorldCoords - CamPos;
|
|
||||||
glm::ivec2 oPos{ drawCall.pos_rect.x, drawCall.pos_rect.y };
|
|
||||||
glm::ivec2 fPos = oPos - camPosition;
|
|
||||||
|
|
||||||
drawCall.pos_rect.x = fPos.x;
|
|
||||||
drawCall.pos_rect.y = fPos.y;
|
|
||||||
|
|
||||||
renderLayers.at(drawCall.layer).push_back(drawCall);
|
renderLayers.at(drawCall.layer).push_back(drawCall);
|
||||||
|
//rendererCounter++;
|
||||||
//renderQueue.push_back(drawCall);
|
//renderQueue.push_back(drawCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,17 @@ namespace UE
|
|||||||
inline glm::ivec2 GetCamPosition() { return camPosition; }
|
inline glm::ivec2 GetCamPosition() { return camPosition; }
|
||||||
void SetCamPosition(int posX, int posY);
|
void SetCamPosition(int posX, int posY);
|
||||||
|
|
||||||
|
/* Métodos para transformar las coordenadas entre Screen y Wolrd. */
|
||||||
|
//WorldCoords = ScreenPos + CamPos -> ScreenPos = WorldCoords - CamPos;
|
||||||
|
//Convierte coordenadas de mundo a la pantalla (en función de la cámara).
|
||||||
|
glm::ivec2 WorldToSreenCoords(glm::ivec2 worldCoord);
|
||||||
|
//Convierte coordenadas de la pantalla al mundo.
|
||||||
|
glm::ivec2 ScreenToWorldCoords(glm::ivec2 screenCoord);
|
||||||
|
|
||||||
|
//Comprueba si un objeto está dentro del rectángulo de la cámara.
|
||||||
|
//Usada para saber si un objeto se debería de renderizar o no.
|
||||||
|
bool IsObjectVisible(SDL_Rect* objectRect);
|
||||||
|
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
//Función para renderizar un objeto un objeto en concreto directamente en el SDL_Renderer.
|
//Función para renderizar un objeto un objeto en concreto directamente en el SDL_Renderer.
|
||||||
@@ -119,6 +130,11 @@ namespace UE
|
|||||||
glm::ivec2 screenSize{ 640,480 };
|
glm::ivec2 screenSize{ 640,480 };
|
||||||
glm::ivec2 camPosition{ 0,0 };
|
glm::ivec2 camPosition{ 0,0 };
|
||||||
|
|
||||||
|
|
||||||
|
//DEBUG
|
||||||
|
int callCounter = 0;
|
||||||
|
int rendererCounter = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include <glm\vec2.hpp>
|
#include <glm\vec2.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace UE
|
namespace UE
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -37,6 +36,7 @@ namespace UE
|
|||||||
inline glm::vec2 GetSize() { return _size; }
|
inline glm::vec2 GetSize() { return _size; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Se almacena la posición y el tamaño del objeto. Con esto se puede crear un SDL_Rect.
|
//Se almacena la posición y el tamaño del objeto. Con esto se puede crear un SDL_Rect.
|
||||||
glm::vec<2, float> _pos;
|
glm::vec<2, float> _pos;
|
||||||
|
|||||||
+9
-3
@@ -49,7 +49,7 @@ void Load()
|
|||||||
|
|
||||||
|
|
||||||
//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()->NewLoadScene(LasEscenas::mainMenu);
|
Game::GetSceneManager()->NewLoadScene(LasEscenas::mainMenu);
|
||||||
}
|
}
|
||||||
@@ -92,6 +92,12 @@ void Loop()
|
|||||||
while (SDL_PollEvent(&eventHandler) != 0)
|
while (SDL_PollEvent(&eventHandler) != 0)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&eventHandler);
|
ImGui_ImplSDL2_ProcessEvent(&eventHandler);
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
//Si ImGui ha capturado el evento, no lo seguimos pasando.
|
||||||
|
if (io.WantCaptureKeyboard) { continue; }
|
||||||
|
if (io.WantCaptureMouse) { continue; }
|
||||||
|
|
||||||
|
|
||||||
Game::GetSceneManager()->GetActiveScenePtr()->SceneHandleEvents(&eventHandler);
|
Game::GetSceneManager()->GetActiveScenePtr()->SceneHandleEvents(&eventHandler);
|
||||||
if (eventHandler.type == SDL_QUIT)
|
if (eventHandler.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
@@ -125,7 +131,7 @@ void Loop()
|
|||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_F])
|
if (keyStates[SDL_SCANCODE_F])
|
||||||
{
|
{
|
||||||
GAME_LOG_TRACE("FPS: {0} / dT: {1}", 60, UE::Time::deltaTime);
|
GAME_LOG_TRACE("FPS: NULL / dT: {1}", UE::Time::deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyStates[SDL_SCANCODE_W])
|
if (keyStates[SDL_SCANCODE_W])
|
||||||
@@ -169,7 +175,7 @@ void Loop()
|
|||||||
//Renderiza la escena.
|
//Renderiza la escena.
|
||||||
Game::GetSceneManager()->GetActiveScenePtr()->SceneRender();
|
Game::GetSceneManager()->GetActiveScenePtr()->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);
|
||||||
|
|
||||||
|
|||||||
@@ -31,17 +31,21 @@ 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 = Game::GetAssetManager();
|
||||||
SDL_Texture* test1Texture = as->getTexture("test1");
|
UE::Texture* test1Texture = as->getTexture("test1");
|
||||||
|
|
||||||
UE::Sprite sp1(test1Texture, as->getTexureRects("test1"), 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, as->getTexureRects("test1"), 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 mapSP(as->getTexture("PruebaMap"), 0, 2, glm::vec2(50, 45), glm::vec2(145, 145));
|
||||||
|
|
||||||
UE::Sprite bg(as->getTexture("bg1"), as->getTexureRects("bg1"), 1, 0, glm::vec2(0, 0), Game::GetRenderer()->GetScreenSize());
|
|
||||||
|
|
||||||
sprites.push_back(sp1);
|
sprites.push_back(sp1);
|
||||||
sprites.push_back(sp2);
|
sprites.push_back(sp2);
|
||||||
sprites.push_back(bg);
|
sprites.push_back(bg);
|
||||||
|
sprites.push_back(mapSP);
|
||||||
|
|
||||||
UE::Font* OP_Regular = as->GetFont("OpenSans_Regular");
|
UE::Font* OP_Regular = as->GetFont("OpenSans_Regular");
|
||||||
//TTF_Font* OP_Bold = as->GetFont("OpenSans_Bold");
|
//TTF_Font* OP_Bold = as->GetFont("OpenSans_Bold");
|
||||||
@@ -92,7 +96,7 @@ public:
|
|||||||
ImguiRender();
|
ImguiRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneHandleEvents(SDL_Event* event)
|
void SceneHandleEvents(SDL_Event* event) override
|
||||||
{
|
{
|
||||||
if (event->type == SDL_KEYDOWN)
|
if (event->type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
@@ -130,14 +134,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
void ImguiRender()
|
void ImguiRender()
|
||||||
{
|
{
|
||||||
ImGui::Begin("DEBUG Stuff", &debugGUI);
|
|
||||||
|
|
||||||
ImGui::Checkbox("AssetManager Inspector: ", &assetMngGUI);
|
//ImGui::Begin("DEBUG Stuff", &debugGUI);
|
||||||
ImGui::Checkbox("Renderer Inspector: ", &rendererGUI);
|
//ImGui::Checkbox("AssetManager Inspector: ", &assetMngGUI);
|
||||||
ImGui::Checkbox("SceneManager Inspector: ", &sceneMngGUI);
|
//ImGui::Checkbox("Renderer Inspector: ", &rendererGUI);
|
||||||
|
//ImGui::Checkbox("SceneManager Inspector: ", &sceneMngGUI);
|
||||||
|
//ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
if (debugGUI) { TestGUI(); }
|
if (debugGUI) { TestGUI(); }
|
||||||
if(assetMngGUI) {}
|
if(assetMngGUI) {}
|
||||||
@@ -145,7 +149,7 @@ private:
|
|||||||
|
|
||||||
void TestGUI()
|
void TestGUI()
|
||||||
{
|
{
|
||||||
ImGui::Begin("MainScene Test Stuff", &_windowOpen);
|
ImGui::Begin("MainScene Test Stuff", &debugGUI);
|
||||||
|
|
||||||
ImGui::Text("En esta escena, hacemos pruebas del funcionamiento de UberEngine.");
|
ImGui::Text("En esta escena, hacemos pruebas del funcionamiento de UberEngine.");
|
||||||
|
|
||||||
@@ -198,6 +202,14 @@ private:
|
|||||||
|
|
||||||
ImGui::Text("Rendering: ");
|
ImGui::Text("Rendering: ");
|
||||||
ImGui::Text("El sprite esta en la layer: %d", sp.GetLayer());
|
ImGui::Text("El sprite esta en la layer: %d", sp.GetLayer());
|
||||||
|
|
||||||
|
ImGui::Text("Cambiar rect del Sprite: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
int textRect = 0;
|
||||||
|
if (ImGui::InputInt("TextureRect", &textRect))
|
||||||
|
{
|
||||||
|
sp.SetTextureRect(textRect);
|
||||||
|
}
|
||||||
//Añadir un input para modificar la layer.
|
//Añadir un input para modificar la layer.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,206 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Scene\Scene.h"
|
#include "Scene\Scene.h"
|
||||||
|
#include "Render\Renderer.h"
|
||||||
|
#include "Logging\Logger.h"
|
||||||
|
|
||||||
|
#include "Assets\AssetManager.h"
|
||||||
|
#include "Assets\Texture.h"
|
||||||
|
|
||||||
|
#include "Drawables\Sprite.h"
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class TestScene2 : public UE::Scene
|
class TestScene2 : public UE::Scene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Scene::Scene;
|
TestScene2(std::string sceneName) : Scene(sceneName) {}
|
||||||
|
|
||||||
void SceneLoad() override
|
void SceneLoad() override
|
||||||
{
|
{
|
||||||
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
||||||
|
|
||||||
|
srand(255);
|
||||||
|
|
||||||
|
UE::AssetManager* as = Game::GetAssetManager();
|
||||||
|
|
||||||
|
UE::Texture* tx = as->getTexture("PruebaMap");
|
||||||
|
|
||||||
|
for (int y = 0; y < vAmount; y++)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int x = 0; x < hAmount; x++)
|
||||||
|
{
|
||||||
|
glm::vec2 i(x, y);
|
||||||
|
glm::vec2 size(100, 100);
|
||||||
|
glm::vec2 pos = size * i;
|
||||||
|
|
||||||
|
UE::Sprite sp(tx, rand()%5, 1, pos, size);
|
||||||
|
sprites.push_back(sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneUpdate() override
|
void SceneUpdate() override
|
||||||
{
|
{
|
||||||
UE_LOG_INFO("Escena {0} UPDATE", _sceneName);
|
//UE_LOG_INFO("Escena {0} UPDATE", _sceneName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneRender() override
|
||||||
|
{
|
||||||
|
UE::Renderer* renderer;
|
||||||
|
renderer = Game::GetRenderer();
|
||||||
|
|
||||||
|
for (UE::Sprite& sp : sprites)
|
||||||
|
{
|
||||||
|
//Si el obj. no está activo, lo saltamos.
|
||||||
|
if (sp.IsActive())
|
||||||
|
{
|
||||||
|
renderer->Render(sp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TestImGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneHandleEvents(SDL_Event* event) override
|
||||||
|
{
|
||||||
|
if (event->type == SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
switch (event->key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_F2:
|
||||||
|
{
|
||||||
|
debugGUI = !debugGUI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event->type == SDL_MOUSEBUTTONDOWN)
|
||||||
|
{
|
||||||
|
UE::Renderer* rend = Game::GetRenderer();
|
||||||
|
glm::ivec2 mPos(event->button.x, event->button.y);
|
||||||
|
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);
|
||||||
|
ModificarSprite(wPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneUnload() override
|
void SceneUnload() override
|
||||||
{
|
{
|
||||||
UE_LOG_INFO("Escena {0} se ha descargado.", _sceneName);
|
GAME_LOG_INFO("Escena {0} se ha descargado.", _sceneName);
|
||||||
|
|
||||||
|
sprites.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ModificarSprite(glm::ivec2 wPos)
|
||||||
|
{
|
||||||
|
SDL_Rect mouseRect = { wPos.x, wPos.y, 2, 2 };
|
||||||
|
|
||||||
|
for (int i = 0; i < sprites.size(); i++)
|
||||||
|
{
|
||||||
|
UE::Sprite& sp = sprites.at(i);
|
||||||
|
|
||||||
|
if (SDL_HasIntersection(&mouseRect, &sp.getPositionRect()))
|
||||||
|
{
|
||||||
|
int i = rand() % 5;
|
||||||
|
sp.SetTextureRect(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestImGui()
|
||||||
|
{
|
||||||
|
if (!debugGUI) { return; }
|
||||||
|
|
||||||
|
ImGui::Begin("Sprite Debug Stuff", &debugGUI);
|
||||||
|
|
||||||
|
//ImVec4 buttonColor;
|
||||||
|
//if(ImGui::ColorEdit4("TestColor", &buttonColor.x)) {}
|
||||||
|
|
||||||
|
ImGui::Text("Elementos del vector Sprites: ");
|
||||||
|
|
||||||
|
if (ImGui::TreeNode("Sprites"))
|
||||||
|
{
|
||||||
|
//Generamos un Selectable para cada Sprite en el vector.
|
||||||
|
int c = sprites.size();
|
||||||
|
ImGui::Text("Seleccione un Sprite (0-%d)x(0-%d)", vAmount, hAmount);
|
||||||
|
ImGui::InputInt2("Sprite Map Pos", _selectSpritePos);
|
||||||
|
|
||||||
|
int i = _selectSpritePos[1] * hAmount + _selectSpritePos[0];
|
||||||
|
if (i > c) { i = -1; }
|
||||||
|
_selectedSprite = i;
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::TreeNode("Selected Sprite Settings"))
|
||||||
|
{
|
||||||
|
if (_selectedSprite != -1)
|
||||||
|
{
|
||||||
|
UE::Sprite& sp = sprites.at(_selectedSprite);
|
||||||
|
|
||||||
|
ImGui::Text("Status: ");
|
||||||
|
const char* st = (sp.IsActive() ? "Sprite Activado" : "Sprite Desactivado");
|
||||||
|
ImGui::Text("El Sprite esta: %s", st);
|
||||||
|
|
||||||
|
if (ImGui::Button("Activar Sprite")) { sp.SetActive(true); }
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("desactivar Sprite")) { sp.SetActive(false); }
|
||||||
|
|
||||||
|
ImGui::Text("Transform: ");
|
||||||
|
glm::vec2 pos = sp.GetPosition();
|
||||||
|
glm::vec2 size = sp.GetSize();
|
||||||
|
if (ImGui::SliderFloat2("Sprite Position", &pos.x, -5000, 5000))
|
||||||
|
{
|
||||||
|
sp.SetPosition(pos);
|
||||||
|
}
|
||||||
|
if (ImGui::SliderFloat2("Sprite Size", &size.x, -2000, 2000))
|
||||||
|
{
|
||||||
|
sp.SetSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Text("Rendering: ");
|
||||||
|
ImGui::Text("El sprite esta en la layer: %d", sp.GetLayer());
|
||||||
|
|
||||||
|
ImGui::Text("Cambiar rect del Sprite: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
int textRect = 0;
|
||||||
|
if (ImGui::InputInt("TextureRect", &textRect))
|
||||||
|
{
|
||||||
|
sp.SetTextureRect(textRect);
|
||||||
|
}
|
||||||
|
//Añadir un input para modificar la layer.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int vAmount = 10;
|
||||||
|
const int hAmount = 10;
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<UE::Sprite> sprites = {};
|
||||||
|
|
||||||
|
|
||||||
|
//IMGUI
|
||||||
|
bool debugGUI = false;
|
||||||
|
int _selectedSprite = 0;
|
||||||
|
int _selectSpritePos[2] = { 0,0 };
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -24,17 +24,32 @@
|
|||||||
"name": "Tilemap",
|
"name": "Tilemap",
|
||||||
"Path": "resources/Sprites/Data/TX_Tilemap.json",
|
"Path": "resources/Sprites/Data/TX_Tilemap.json",
|
||||||
"Type": 0
|
"Type": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "PruebaMap",
|
||||||
|
"Path": "resources/Sprites/Data/TX_PruebaMap.json",
|
||||||
|
"Type": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Pizzas",
|
||||||
|
"Path": "resources/Sprites/Data/TX_Pizzas.json",
|
||||||
|
"Type": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Fonts": [
|
"Fonts": [
|
||||||
{
|
{
|
||||||
"name": "OpenSans_Regular",
|
"name": "OpenSans_Regular",
|
||||||
"Path": "resources/AssetsData/FontsData/OpenSansFont.json",
|
"Path": "resources/AssetsData/FontsData/OpenSansRegular.json",
|
||||||
"Type": 1
|
"Type": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "OpenSans_Bold",
|
"name": "OpenSans_Bold",
|
||||||
"Path": "resources/AssetsData/FontsData/OpenSansFont.json",
|
"Path": "resources/AssetsData/FontsData/OpenSansBold.json",
|
||||||
|
"Type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "OpenSans_Italic",
|
||||||
|
"Path": "resources/AssetsData/FontsData/OpenSansItalic.json",
|
||||||
"Type": 1
|
"Type": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"FontPath": "resources/Fonts/OpenSans-Bold.ttf",
|
||||||
|
"FontSizes": [18, 28]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"FontPath": "resources/Fonts/OpenSans-Italic.ttf",
|
||||||
|
"FontSizes": [18]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"TexturePath": "resources/Sprites/Textures/Pizza1.png",
|
||||||
|
"TextureRects": [
|
||||||
|
{
|
||||||
|
"posX": 0,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 6,
|
||||||
|
"sizeY": 6
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"TexturePath": "resources/Sprites/Textures/PruebaMap.png",
|
||||||
|
"TextureRects": [
|
||||||
|
{
|
||||||
|
"posX": 0,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 8,
|
||||||
|
"sizeY": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"posX": 8,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 8,
|
||||||
|
"sizeY": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"posX": 16,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 8,
|
||||||
|
"sizeY": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"posX": 24,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 8,
|
||||||
|
"sizeY": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"posX": 32,
|
||||||
|
"posY": 0,
|
||||||
|
"sizeX": 8,
|
||||||
|
"sizeY": 8
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 166 B |
Binary file not shown.
|
After Width: | Height: | Size: 623 B |
Reference in New Issue
Block a user