[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 { | ||||
| public: | ||||
|   Game(void); | ||||
|   ~Game(void); | ||||
| 	Game(void); | ||||
| 	~Game(void); | ||||
| 
 | ||||
|   void New(const string& savegameIDArg); | ||||
|   void Load(const string& savegameIDArg); | ||||
| 	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; | ||||
| }; | ||||
|  | ||||
| @ -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);
 | ||||
| //	}
 | ||||
| 	// Overload new and delete operators to utilize MemManager.
 | ||||
| 	inline void* operator new(size_t size) { | ||||
| 		return gMemManager.Allocate(size); | ||||
| 	} | ||||
| 
 | ||||
|   enum { | ||||
|     FACING_UP, | ||||
|     FACING_RIGHT, | ||||
|     FACING_DOWN, | ||||
|     FACING_LEFT | ||||
|   }; | ||||
| 	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); | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| #pragma once | ||||
| #include <list> | ||||
| #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); | ||||
| 	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); | ||||
| 	bool CheckCollision(const SDL_Rect& charRect, Character* exclude); | ||||
| 
 | ||||
|   int  GetNPCCount() { return _npcs.size(); } | ||||
| 	int  GetNPCCount() { return _npcs.size(); } | ||||
| 
 | ||||
|   void OnPlayerAttack(Player* player); | ||||
|   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: | ||||
|   LevelGen* _level; | ||||
|   std::list<NPC*> _npcs; | ||||
| 	LevelGen* _level; | ||||
| 	std::list<NPC*> _npcs; | ||||
| }; | ||||
|  | ||||
| @ -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,15 +25,15 @@ 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 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 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); | ||||
| @ -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 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 BOUNDARIES_X = (SCREEN_WIDTH / TILE_WIDTH); | ||||
| 	static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT); | ||||
| 
 | ||||
|   TextureManager _tileTextures; | ||||
|   TextureManager _entityTextures; | ||||
| 	TextureManager _tileTextures; | ||||
| 	TextureManager _entityTextures; | ||||
| 
 | ||||
|   WorldManager _world; | ||||
| 	WorldManager _world; | ||||
| 
 | ||||
|   Player* _player; | ||||
| 	Player* _player; | ||||
| }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Rtch90
						Rtch90