From 54240b217c4807d8fec10c2a64d7676d9eb87fe2 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 14 Jan 2014 10:28:12 +0100 Subject: [PATCH] GameLogic - game interface updated(not finnished) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit förlåt dennis --- Code/Game/GameLogic/AttatchmentSocket.cpp | 22 +++++-------- Code/Game/GameLogic/Game.cpp | 18 +++++----- Code/Game/GameLogic/Game.h | 40 +++++++++++++---------- Code/Game/GameLogic/Game_PlayerData.cpp | 14 ++++++++ Code/Game/GameLogic/Level.cpp | 17 +++++----- Code/Game/GameLogic/Weapon.cpp | 26 ++++----------- 6 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 Code/Game/GameLogic/Game_PlayerData.cpp diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp index 5d997a45..a3d9097c 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.cpp +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -1,6 +1,9 @@ #include "AttatchmentSocket.h" #include "IAttatchment.h" +#include "DynamicArray.h" + using namespace GameLogic; +using namespace Utility::DynamicMemory; struct AttatchmentSocket::PrivateData { @@ -14,7 +17,7 @@ struct AttatchmentSocket::PrivateData } - IAttatchment *attatchment; + SmartPointer attatchment; }myData; @@ -26,10 +29,7 @@ AttatchmentSocket::AttatchmentSocket(void) AttatchmentSocket::~AttatchmentSocket(void) { - if (myData->attatchment) - { - delete myData->attatchment; - } + } IAttatchment* AttatchmentSocket::GetAttatchment() @@ -39,18 +39,12 @@ IAttatchment* AttatchmentSocket::GetAttatchment() void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment) { - if (myData->attatchment) - { - delete myData->attatchment; - } - myData->attatchment = attatchment; } void AttatchmentSocket::RemoveAttatchment() { - if (myData->attatchment) - { - delete myData->attatchment; - } + + myData->attatchment = 0; + } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 806ac6d2..e2879e10 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -1,8 +1,10 @@ #include "Game.h" #include "Player.h" #include "Level.h" +#include using namespace GameLogic; +using namespace Utility::DynamicMemory; struct Game::PrivateData { @@ -15,9 +17,9 @@ struct Game::PrivateData { } - - Player **players; - Level *level; + //DynamicArray> players; + DynamicArray> players; + SmartPointer level; }myData; @@ -35,14 +37,10 @@ Game::~Game(void) } } -void Game::MovePlayer(int playerID, const PLAYER_MOVEMENT &movement) -{ - -} void Game::PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage) { - + } void Game::GetPlayerPos(int playerID) @@ -57,7 +55,9 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { - + SmartPointer newPlayer = new Player(); + + myData->players.Push(newPlayer); } void Game::CreateTeam() diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index a70dc842..dc3c898f 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -4,44 +4,50 @@ #include "GameLogicStates.h" namespace GameLogic { + class Player; class Game { public: struct PlayerData { + private: + friend class Game; + Player *player; + + + public: + int playerID; int teamID; - PlayerData() - { - playerID = 0; - teamID = 0; - } - PlayerData(int playerID,int teamID) - { - this->playerID = playerID; - this->teamID = teamID; - - } + PlayerData(); + + PlayerData(int playerID,int teamID); + ~PlayerData() { } + + /******************************************************** + * Moves the chosen player based on input + * @param playerID: ID of the player you want to recieve the message + * @param movement: enum value on what kind of action is to be taken + ********************************************************/ + void MovePlayer(const PLAYER_MOVEMENT &movement); + + }; public: Game(void); ~Game(void); - /******************************************************** - * Moves the chosen player based on input - * @param playerID: ID of the player you want to recieve the message - * @param movement: enum value on what kind of action is to be taken - ********************************************************/ - void MovePlayer(int playerID, const PLAYER_MOVEMENT &movement); + + /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp new file mode 100644 index 00000000..258c164c --- /dev/null +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -0,0 +1,14 @@ +#include "Game.h" +#include "Player.h" + +using namespace GameLogic; + +Game::PlayerData::PlayerData() +{ + +} + +void Game::PlayerData::MovePlayer(const PLAYER_MOVEMENT &movement) +{ + +} diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9f4416aa..9b3c90ff 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -5,8 +5,11 @@ #include "Player.h" #include "PhysicsAPI.h" #include "TeamManager.h" +#include "DynamicArray.h" using namespace GameLogic; +using namespace Utility::DynamicMemory; + struct Level::PrivateData { @@ -18,17 +21,15 @@ struct Level::PrivateData { } - TeamManager *teamManager; + SmartPointer teamManager; - StaticObject** staticObjects; - int nrOfStaticObjects; + DynamicArray> staticObjects; + + DynamicArray> dynamicObjects; - DynamicObject** dynamicObjects; - int nrOfDynamicObjects; + SmartPointer gameMode; - GameMode* gameMode; - - Oyster::Physics::ICustomBody *rigidBodyLevel; + SmartPointer rigidBodyLevel; }myData; diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 7f4b3308..6ac989c5 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -1,8 +1,10 @@ #include "Weapon.h" #include "AttatchmentSocket.h" #include "AttatchmentMassDriver.h" +#include "DynamicArray.h" using namespace GameLogic; +using namespace Utility::DynamicMemory; struct Weapon::PrivateData { @@ -12,7 +14,6 @@ struct Weapon::PrivateData selectedAttatchment = 0; currentNrOfAttatchments = 0; selectedSocketID = 0; - maxNrOfSockets = 0; attatchmentSockets = 0; } @@ -22,11 +23,9 @@ struct Weapon::PrivateData WEAPON_STATE weaponState; - AttatchmentSocket **attatchmentSockets; - int maxNrOfSockets; + DynamicArray> attatchmentSockets; int currentNrOfAttatchments; - - IAttatchment *selectedAttatchment; + SmartPointer selectedAttatchment; int selectedSocketID; }myData; @@ -39,23 +38,12 @@ Weapon::Weapon() Weapon::Weapon(int MaxNrOfSockets) { myData = new PrivateData(); - myData->maxNrOfSockets = MaxNrOfSockets; - myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets]; - for (int i = 0; i < MaxNrOfSockets; i++) - { - myData->attatchmentSockets[i] = new AttatchmentSocket(); - } + myData->attatchmentSockets.Resize(MaxNrOfSockets); } Weapon::~Weapon(void) { - for (int i = 0; i < myData->currentNrOfAttatchments; i++) - { - delete myData->attatchmentSockets[i]; - } - delete[] myData->attatchmentSockets; - delete myData; } @@ -95,7 +83,7 @@ bool Weapon::IsReloading() bool Weapon::IsValidSocket(int socketID) { - if(socketID < myData->maxNrOfSockets && socketID >= 0) + if(socketID < myData->attatchmentSockets.Size() && socketID >= 0) { if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) { @@ -114,7 +102,7 @@ int Weapon::GetCurrentSocketID() void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) { - if(myData->currentNrOfAttatchments < myData->maxNrOfSockets) + if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size()) { myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); myData->currentNrOfAttatchments++;