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