diff --git a/src/Unuk/Game.h b/src/Unuk/Game.h index f393464..e76bfba 100644 --- a/src/Unuk/Game.h +++ b/src/Unuk/Game.h @@ -23,46 +23,46 @@ enum gameNavVal_t { gameMainMenu, gameQuitGame }; class Game { public: - Game(void); - ~Game(void); - - void New(const string& savegameIDArg); - void Load(const string& savegameIDArg); + Game(void); + ~Game(void); + + void New(const string& savegameIDArg); + void Load(const string& savegameIDArg); + + gameNavVal_t Run(void); - gameNavVal_t Run(void); - private: - void HandleInput(void); - void UpdateGame(void); - void Render(void); + void HandleInput(void); + void UpdateGame(void); + void Render(void); - void NewSavegame(const string savegameIDArg); - void LoadSavegame(const string savegameIDArg); - void SaveSavegame(void); + void NewSavegame(const string savegameIDArg); + void LoadSavegame(const string savegameIDArg); + void SaveSavegame(void); static const int MAX_FPS = 200; - static const int GAME_UPDATES_PER_SECOND = 60; - static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND; + static const int GAME_UPDATES_PER_SECOND = 60; + static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND; - bool _gameRunning; + bool _gameRunning; - gameNavVal_t _runGameReturnValue; + gameNavVal_t _runGameReturnValue; - string _saveGameID; - string _mapID; + string _saveGameID; + string _mapID; - Text _gameUpdateTime; - Text _gameRenderTime; - Text _playerXY; - Text _npcHealth; + Text _gameUpdateTime; + Text _gameRenderTime; + Text _playerXY; + Text _npcHealth; - IngameMenu _ingameMenu; + IngameMenu _ingameMenu; LevelGen _map; - Player* _player; + Player* _player; - Text _playerHealth; - Text _playerExp; - Bar _playerHealthBar; - Bar _playerExpBar; + Text _playerHealth; + Text _playerExp; + Bar _playerHealthBar; + Bar _playerExpBar; }; diff --git a/src/libUnuk/Engine/Character.h b/src/libUnuk/Engine/Character.h index 587ca38..6843146 100644 --- a/src/libUnuk/Engine/Character.h +++ b/src/libUnuk/Engine/Character.h @@ -45,28 +45,29 @@ public: void OnAttack(void); -// inline void* operator new(size_t size) { -// return gMemManager.Allocate(size); -// } -// -// inline void operator delete(void* object) { -// gMemManager.Free(object); -// } -// -// inline void* operator new [](size_t size) { -// return gMemManager.Allocate(size); -// } -// -// inline void operator delete [](void* object) { -// gMemManager.Free(object); -// } - - enum { - FACING_UP, - FACING_RIGHT, - FACING_DOWN, - FACING_LEFT - }; + // Overload new and delete operators to utilize MemManager. + inline void* operator new(size_t size) { + return gMemManager.Allocate(size); + } + + inline void operator delete(void* object) { + gMemManager.Free(object); + } + + inline void* operator new [](size_t size) { + return gMemManager.Allocate(size); + } + + inline void operator delete [](void* object) { + gMemManager.Free(object); + } + + enum { + FACING_UP, + FACING_RIGHT, + FACING_DOWN, + FACING_LEFT + }; protected: void HealthBarScroll(void); diff --git a/src/libUnuk/Engine/WorldManager.h b/src/libUnuk/Engine/WorldManager.h index 5833abf..eced73e 100644 --- a/src/libUnuk/Engine/WorldManager.h +++ b/src/libUnuk/Engine/WorldManager.h @@ -1,5 +1,6 @@ #pragma once #include +#include "MemClass.h" class Character; class NPC; @@ -10,26 +11,43 @@ class LevelGen; class WorldManager { public: - WorldManager(LevelGen* level); - ~WorldManager(void); + WorldManager(LevelGen* level); + ~WorldManager(void); - void Update(void); - void Render(void); + void Update(void); + void Render(void); - void AddNPC(NPC* npc); - void RemoveNPC(int index); - NPC* GetNPC(int index); - NPC* GetNPCAt(int xArg, int yArg); - void CreateNPC(int x, int y); - - bool CheckCollision(const SDL_Rect& charRect, Character* exclude); + void AddNPC(NPC* npc); + void RemoveNPC(int index); + NPC* GetNPC(int index); + NPC* GetNPCAt(int xArg, int yArg); + void CreateNPC(int x, int y); - int GetNPCCount() { return _npcs.size(); } + bool CheckCollision(const SDL_Rect& charRect, Character* exclude); - void OnPlayerAttack(Player* player); - void OnPlayerMove(Player* player); + int GetNPCCount() { return _npcs.size(); } + + void OnPlayerAttack(Player* player); + void OnPlayerMove(Player* player); + + // Overload new and delete operators to utilize MemManager. + inline void* operator new(size_t size) { + return gMemManager.Allocate(size); + } + + inline void operator delete(void* object) { + gMemManager.Free(object); + } + + inline void* operator new [](size_t size) { + return gMemManager.Allocate(size); + } + + inline void operator delete [](void* object) { + gMemManager.Free(object); + } private: - LevelGen* _level; - std::list _npcs; + LevelGen* _level; + std::list _npcs; }; diff --git a/src/libUnuk/LevelGen/LevelGen.h b/src/libUnuk/LevelGen/LevelGen.h index a3b1bb0..7221c72 100644 --- a/src/libUnuk/LevelGen/LevelGen.h +++ b/src/libUnuk/LevelGen/LevelGen.h @@ -14,6 +14,7 @@ #include "../LevelGen/MapTile.h" #include "../System/Debug.h" #include "../Engine/WorldManager.h" +#include "../Engine/MemClass.h" using namespace std; class Character; @@ -24,16 +25,16 @@ public: LevelGen(void); ~LevelGen(void); - void New(void); - void Load(const string& filename); - void Save(const string& filename); - void Update(void); - void Render(void); - - void FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight); - void MoveIfPossible(Character* character, float xVel, float yVel, bool isPlayer = false); - bool CanMoveToPoint(int xArg, int yArg); - + void New(void); + void Load(const string& filename); + void Save(const string& filename); + void Update(void); + void Render(void); + + void FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight); + void MoveIfPossible(Character* character, float xVel, float yVel, bool isPlayer = false); + bool CanMoveToPoint(int xArg, int yArg); + bool GetTileSolidity(int xArg, int yArg); int GetTileX(int xArg, int yArg); int GetTileY(int xArg, int yArg); @@ -46,35 +47,35 @@ public: int GetTileZLevel(int xArg, int yArg); - MapTile& GetTile(int xArg, int yArg); + MapTile& GetTile(int xArg, int yArg); string GetCurrentMap(void); WorldManager& GetWorld(void) { return _world; } - void SetPlayer(Player* player) { _player = player; } - + void SetPlayer(Player* player) { _player = player; } + private: - void Unload(void); - void DoMagic(void); - void GenerateEntities(const std::string& name, int frequency); - void MakeWalkingPaths(void); - void GenerateEnemies(void); + void Unload(void); + void DoMagic(void); + void GenerateEntities(const std::string& name, int frequency); + void MakeWalkingPaths(void); + void GenerateEnemies(void); - string _currentMap; - int x; - int y; + string _currentMap; + int x; + int y; - static const int TILE_ARRAY_SIZE = 150; - MapTile _tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE]; - - static const int BOUNDARIES_X = (SCREEN_WIDTH / TILE_WIDTH); - static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT); + static const int TILE_ARRAY_SIZE = 150; + MapTile _tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE]; - TextureManager _tileTextures; - TextureManager _entityTextures; + static const int BOUNDARIES_X = (SCREEN_WIDTH / TILE_WIDTH); + static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT); - WorldManager _world; - - Player* _player; + TextureManager _tileTextures; + TextureManager _entityTextures; + + WorldManager _world; + + Player* _player; };