From 6c3c234be19b72d40fa1b02cfd98665fdfb6edd9 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Mon, 20 Jan 2014 15:47:52 +0100 Subject: [PATCH] GameLogic - pree-sprint merge --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 2 +- .../Game/DanBiasGame/GameClientRecieverFunc.h | 1 - .../DanBiasLauncher/DanBiasLauncher.vcxproj | 5 - Code/Game/DanBiasLauncher/Launcher.cpp | 1 + Code/Game/DanBiasServer/DanBiasServer.vcxproj | 11 +- .../DanBiasServer/GameSession/GameClient.cpp | 9 +- .../DanBiasServer/GameSession/GameClient.h | 10 +- .../DanBiasServer/GameSession/GameSession.h | 24 +-- .../GameSession/GameSession_Events.cpp | 27 +-- .../GameSession/GameSession_General.cpp | 58 ++++-- .../GameSession/GameSession_Logic.cpp | 66 +++---- Code/Game/GameLogic/Game.cpp | 167 +++++++++++------- Code/Game/GameLogic/Game.h | 134 ++++++-------- Code/Game/GameLogic/GameAPI.h | 160 +++++++++++++++++ Code/Game/GameLogic/GameLogic.vcxproj | 13 +- Code/Game/GameLogic/GameLogicStates.h | 3 +- Code/Game/GameLogic/GameMode.cpp | 19 +- Code/Game/GameLogic/GameMode.h | 4 +- Code/Game/GameLogic/Game_LevelData.cpp | 27 ++- Code/Game/GameLogic/Game_PlayerData.cpp | 10 +- Code/Game/GameLogic/Level.cpp | 74 +++----- Code/Game/GameLogic/Level.h | 17 +- Code/Game/GameLogic/Object.cpp | 16 +- Code/Game/GameLogic/Object.h | 10 +- Code/Game/GameLogic/Player.cpp | 27 +-- Code/Game/GameLogic/Player.h | 7 - Code/Game/GameLogic/Team.cpp | 58 +++--- Code/Game/GameLogic/Team.h | 6 +- Code/Game/GameLogic/TeamManager.cpp | 83 ++++----- Code/Game/GameLogic/TeamManager.h | 7 +- Code/Game/GameLogic/Weapon.cpp | 4 +- Code/Game/GameProtocols/ControlProtocols.h | 1 + Code/Misc/Misc.vcxproj | 8 + Code/Misc/Misc.vcxproj.filters | 6 + Code/Misc/Thread/OysterThread_Impl.cpp | 2 +- Code/Network/NetworkAPI/NetworkClient.cpp | 5 + 36 files changed, 631 insertions(+), 451 deletions(-) create mode 100644 Code/Game/GameLogic/GameAPI.h diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index da6b5290..930d4bad 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -75,7 +75,7 @@ namespace DanBias if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient)) return DanBiasClientReturn_Error; - m_data->timer = new Utility::WinTimer(); + m_data->timer = new Utility::WinTimer(); //why dynamic memory? m_data->timer->reset(); return DanBiasClientReturn_Sucess; } diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 0a42d33a..68cb19d6 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -56,7 +56,6 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject case protocol_Gameplay_CreateObject: { - Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; protocolData->object_ID = p[1].value.netInt; protocolData->path = p[2].value.netCharPtr; diff --git a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj index fec9d7dd..5e543af9 100644 --- a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj +++ b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj @@ -173,11 +173,6 @@ - - - {2a1bc987-af42-4500-802d-89cd32fc1309} - - diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 3d3c5fdc..38f499eb 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -20,6 +20,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh //gameDesc.port = 15152; //gameDesc.IP = "193.11.184.196"; //gameDesc.IP = "193.11.184.31"; + //gameDesc.IP = "194.47.150.56"; gameDesc.IP = "127.0.0.1"; gameDesc.hinst = hinst; gameDesc.nCmdShow = cmdShow; diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index 82b62bee..b491c65e 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -112,7 +112,7 @@ Windows true - GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll;GamePhysics_$(PlatformShortName)D.dll + GameLogic_$(PlatformShortName)D.dll;NetworkAPI_$(PlatformShortName)D.dll;%(DelayLoadDLLs) NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -128,7 +128,7 @@ Windows true - GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName)D.dll;GamePhysics_$(PlatformShortName)D.dll + GameLogic_$(PlatformShortName)D.dll;NetworkAPI_$(PlatformShortName)D.dll;%(DelayLoadDLLs) NetworkAPI_$(PlatformShortName)D.lib;WindowManager_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -148,7 +148,7 @@ true true true - GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll;GamePhysics_$(PlatformShortName).dll + GameLogic_$(PlatformShortName).dll;NetworkAPI_$(PlatformShortName).dll;%(DelayLoadDLLs) NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -168,7 +168,7 @@ true true true - GameLogic_$(PlatformShortName).dll;%(DelayLoadDLLs);NetworkAPI_$(PlatformShortName).dll;GamePhysics_$(PlatformShortName).dll + GameLogic_$(PlatformShortName).dll;NetworkAPI_$(PlatformShortName).dll;%(DelayLoadDLLs) NetworkAPI_$(PlatformShortName).lib;WindowManager_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -206,9 +206,6 @@ - - {104fa3e9-94d9-4e1d-a941-28a03bc8a095} - {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.cpp b/Code/Game/DanBiasServer/GameSession/GameClient.cpp index 479aedfd..23f0f3e2 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameClient.cpp @@ -4,7 +4,6 @@ #include "GameClient.h" #include "..\LobbySessions\NetworkSession.h" -#include #include using namespace Utility::DynamicMemory; @@ -13,7 +12,7 @@ using namespace GameLogic; static int gameClientIDCount = 1; -GameClient::GameClient(SmartPointer client, Game::PlayerData* player, Oyster::Callback::OysterCallback value) +GameClient::GameClient(SmartPointer client, IPlayerData* player, Oyster::Callback::OysterCallback value) { this->callbackValue = value; this->client = client; @@ -37,13 +36,13 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallbackcallbackValue = value; } -GameLogic::Game::PlayerData* GameClient::GetPlayer() +GameLogic::IPlayerData* GameClient::GetPlayer() { return this->player; } -GameLogic::Game::PlayerData* GameClient::ReleasePlayer() +GameLogic::IPlayerData* GameClient::ReleasePlayer() { - GameLogic::Game::PlayerData *temp = this->player; + GameLogic::IPlayerData *temp = this->player; this->player = 0; return temp; } diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.h b/Code/Game/DanBiasServer/GameSession/GameClient.h index 3a714bd6..0a74479a 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.h +++ b/Code/Game/DanBiasServer/GameSession/GameClient.h @@ -6,22 +6,22 @@ #include "..\LobbySessions\LobbyClient.h" #include -#include +#include namespace DanBias { class GameClient: Oyster::Callback::CallbackObject { public: - GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::Game::PlayerData* player, Oyster::Callback::OysterCallback value); + GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::IPlayerData* player, Oyster::Callback::OysterCallback value); virtual~GameClient(); void SetCallback(Oyster::Callback::OysterCallback value); /* */ - GameLogic::Game::PlayerData* GetPlayer(); + GameLogic::IPlayerData* GetPlayer(); - GameLogic::Game::PlayerData* ReleasePlayer(); + GameLogic::IPlayerData* ReleasePlayer(); LobbyClient* GetClient() const; Utility::DynamicMemory::SmartPointer ReleaseClient(); @@ -29,7 +29,7 @@ namespace DanBias private: //Utility::DynamicMemory::SmartPointer player; - GameLogic::Game::PlayerData* player; + GameLogic::IPlayerData* player; Utility::DynamicMemory::SmartPointer client; Oyster::Callback::OysterCallback callbackValue; int id; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.h b/Code/Game/DanBiasServer/GameSession/GameSession.h index 95514ba2..aee9b29d 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.h +++ b/Code/Game/DanBiasServer/GameSession/GameSession.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include namespace DanBias @@ -30,19 +30,6 @@ namespace DanBias NetworkSession* owner; Utility::DynamicMemory::DynamicArray> clients; }; - - struct GameSessionEvent - { - union EventData - { - GameLogic::Game::PlayerData* player; - } data; - enum EventType - { - EventType_Player, - EventType_DynamicObject, - } value; - }; public: GameSession(); @@ -77,7 +64,7 @@ namespace DanBias //Handles all general events void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); //Adds a client to the client list - void AddClient(Utility::DynamicMemory::SmartPointer obj); + void InsertClient(Utility::DynamicMemory::SmartPointer obj); //Removes a client from the client list void RemoveClient(DanBias::GameClient* obj); //Sends a protocol ta all clients in session @@ -97,11 +84,14 @@ namespace DanBias Utility::DynamicMemory::DynamicArray> clients; Oyster::IPostBox *box; Oyster::Thread::OysterThread worker; - GameLogic::Game gameInstance; + GameLogic::GameAPI& gameInstance; + GameLogic::ILevelData *levelData; NetworkSession* owner; bool isCreated; bool isRunning; - Utility::Container::Queue modifiedClient; + Utility::WinTimer timer; + + static void ObjectMove(GameLogic::IObjectData* movedObject); private: friend class AdminInterface; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index 51d052ba..164e5748 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -25,7 +25,9 @@ namespace DanBias if( !this->box->IsEmpty() ) { NetworkSession::NetEvent &e = this->box->Fetch(); - + static int ii = 0; + printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value); + if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) ) @@ -38,10 +40,6 @@ namespace DanBias void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) { - GameSessionEvent e; - e.data.player = c->GetPlayer(); - e.value = GameSessionEvent::EventType_Player; - switch (p[protocol_INDEX_ID].value.netShort) { case protocol_Gameplay_PlayerNavigation: @@ -60,9 +58,6 @@ namespace DanBias if(p[6].value.netBool) //bool bStrafeLeft; //world.v[3].y = -2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - - - } break; case protocol_Gameplay_PlayerMouseMovement: @@ -77,11 +72,7 @@ namespace DanBias case protocol_Gameplay_ObjectPosition: break; - - } - - this->modifiedClient.Push(e); } void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) @@ -92,7 +83,7 @@ namespace DanBias switch (p[1].value.netInt) { case GameLogic::Protocol_General_Status::States_bussy: - + break; case GameLogic::Protocol_General_Status::States_disconected: @@ -116,5 +107,15 @@ namespace DanBias } } + + void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) + { + //if (movedObject->) + //{ + // + //} + //movedObject->GetOrientation(); + } + }//End namespace DanBias diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp index 7a3b87b4..0f9f3c57 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp @@ -20,6 +20,7 @@ using namespace GameLogic; namespace DanBias { GameSession::GameSession() + :gameInstance(GameAPI::Instance()) { this->owner = 0; this->box = 0; @@ -36,30 +37,60 @@ namespace DanBias bool GameSession::Create(GameDescription& desc) { + /* Do some error checking */ if(desc.clients.Size() == 0) return false; if(!desc.owner) return false; if(!desc.mapName.size()) return false; if(this->isCreated) return false; + /* standard initialization of some data */ this->clients.Resize(desc.clients.Size()); - this->box = new PostBox(); this->owner = desc.owner; - Oyster::Callback::OysterCallback c; - c.value.callbackPostBox = this->box; - c.callbackType = Oyster::Callback::CallbackType_PostBox; - - for (unsigned int i = 0; i < desc.clients.Size(); i++) + /* Initiate the game instance */ + if(!this->gameInstance.Initiate()) { - this->clients[i] = new GameClient(desc.clients[i], gameInstance.CreatePlayer(), c); + printf("Failed to initiate the game instance\n"); } - if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return false; + /* Create the game level */ + if(!(this->levelData = this->gameInstance.CreateLevel())) + { + printf("Level not created!"); + return false; + } + + /* Create a callback object */ + Oyster::Callback::OysterCallback c; + c.value.callbackPostBox = this->box; + c.callbackType = Oyster::Callback::CallbackType_PostBox; + + /* Create the players in the game instance */ + GameLogic::IPlayerData* p = 0; + for (unsigned int i = 0; i < desc.clients.Size(); i++) + { + if( (p = this->gameInstance.CreatePlayer()) ) + { + this->clients[i] = new GameClient(desc.clients[i], p, c); + } + else + { + printf("Failed to create player (%i)\n", i); + } + } + + /* Create the worker thread */ + if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) + return false; + + this->worker.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_3); + + /* Set some gameinstance data options */ + this->gameInstance.SetSubscription(GameLogic::GameEvent::ObjectEventFunctionType_OnMove, GameSession::ObjectMove); this->isCreated = true; - - return true; + return this->isCreated; } void GameSession::Run() @@ -69,8 +100,7 @@ namespace DanBias if(this->clients.Size() > 0) { - - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2); + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); this->isRunning = true; } } @@ -84,7 +114,7 @@ namespace DanBias c.callbackType = Oyster::Callback::CallbackType_PostBox; SmartPointer obj = new GameClient(client, this->gameInstance.CreatePlayer(), c); - AddClient(obj); + InsertClient(obj); return true; } @@ -105,7 +135,7 @@ namespace DanBias this->Clean(); } - void GameSession::AddClient(SmartPointer obj) + void GameSession::InsertClient(SmartPointer obj) { for (unsigned int i = 0; i < clients.Size(); i++) { diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp index 50979092..275347ed 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -10,6 +10,11 @@ #include #include +#define DELTA_TIME_24 0.04166666666666666666666666666667f +#define DELTA_TIME_30 0.03333333333333333333333333333333f +#define DELTA_TIME_60 0.01666666666666666666666666666667f +#define DELTA_TIME_120 0.00833333333333333333333333333333f + using namespace Utility::DynamicMemory; using namespace Oyster; using namespace Oyster::Network; @@ -20,53 +25,48 @@ namespace DanBias { bool GameSession::DoWork( ) { - if(GetAsyncKeyState(VK_UP)) + if(this->isRunning) { - Protocol_General_Status p(Protocol_General_Status::States_ready); - Send(p.GetProtocol()); - Sleep(100); - } - if(GetAsyncKeyState(VK_DOWN)) - { - Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; - Protocol_CreateObject p(world, 2, "../Content/crate"); - Send(p.GetProtocol()); - Sleep(100); - } - - + if(GetAsyncKeyState(VK_UP)) + { + Protocol_General_Status p(Protocol_General_Status::States_ready); + Send(p.GetProtocol()); + Sleep(100); + } + if(GetAsyncKeyState(VK_DOWN)) + { + Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; + Protocol_CreateObject p(world, 2, "../Content/crate"); + Send(p.GetProtocol()); + Sleep(100); + } - this->ParseEvents(); + double dt = this->timer.getElapsedSeconds(); + gameInstance.SetFrameTimeLength((float)dt); - this->gameInstance.NewFrame(); + if(dt >= DELTA_TIME_60) + { + this->ParseEvents(); - this->UpdateGameObjects(); + this->gameInstance.NewFrame(); + + this->UpdateGameObjects(); + + this->timer.reset(); + } + } return this->isRunning; } void GameSession::UpdateGameObjects() { - while(!this->modifiedClient.IsEmpty()) - { - //There is something that needs update - GameSessionEvent e = this->modifiedClient.Pop(); - - switch (e.value) - { - case GameSessionEvent::EventType_Player: - //e.data.player->GetOrientation(); - break; - } - - } - - if(clients.Size() == 1) + if(clients.Size() >= 1 && clients[0]) { Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation(); Protocol_ObjectPosition p(world, 1); Send(p.GetProtocol()); - Sleep(100); + //Sleep(100); } } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index af1e9d8c..d1760629 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -1,19 +1,10 @@ #include "Game.h" -#include "Player.h" -#include "Level.h" -#include -#include -#include -#include using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; -#define DELTA_TIME 0.01666666666666666666666666666667f - -template -int InsertObject(DynamicArray& list, T* obj) +template int InsertObject(DynamicArray& list, T* obj) { for (unsigned int i = 0; i < list.Size(); i++) { @@ -26,8 +17,7 @@ int InsertObject(DynamicArray& list, T* obj) list.Push(obj); return list.Size() - 1; } -template -int RemoveObject(DynamicArray& list, T* obj) +template int RemoveObject(DynamicArray& list, T* obj) { for (unsigned int i = 0; i < list.Size(); i++) { @@ -41,37 +31,33 @@ int RemoveObject(DynamicArray& list, T* obj) return list.Size() - 1; } -struct Game::PrivateData + +Game gameInstance; +GameAPI& GameAPI::Instance() { - PrivateData() - { } - - ~PrivateData() - { - for (unsigned int i = 0; i < players.Size(); i++) - { - this->players[i]->player = 0; - } - } - - DynamicArray players; - LevelData* level; - Utility::WinTimer timer; - -}myData; + return gameInstance; +} Game::Game(void) -{ - myData = new PrivateData(); -} + : initiated(false) + , onMoveFnc(0) + , onDeadFnc(0) + , frameTime(1.0f/120.0f) +{} Game::~Game(void) -{ - if(myData) +{ + for (unsigned int i = 0; i < gameInstance.players.Size(); i++) { - delete myData; + delete gameInstance.players[i]; } + gameInstance.players.Clear(); + + delete this->level; + this->level = 0; + + initiated = false; } void Game::GetAllPlayerPositions() const @@ -81,21 +67,23 @@ void Game::GetAllPlayerPositions() const Game::PlayerData* Game::CreatePlayer() { - Player *newPlayer = new Player(); - PlayerData *newPdata = new PlayerData(); - newPdata->player = newPlayer; - int id = InsertObject(this->myData->players, newPdata); - return this->myData->players[id]; + // Find a free space in array or insert at end + int id = InsertObject(this->players, (PlayerData*)0); + + this->players[id] = new PlayerData(); + this->players[id]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + + return this->players[id]; } Game::LevelData* Game::CreateLevel() { - Level *newLevel = new Level(); - newLevel->InitiateLevel(1000); - LevelData *newLdata = new LevelData(); - newLdata->level = newLevel; - myData->level = newLdata; - return myData->level; + if(this->level) return this->level; + + this->level = new LevelData(); + this->level->level->InitiateLevel(1000); + + return this->level; } void Game::CreateTeam() @@ -103,27 +91,72 @@ void Game::CreateTeam() } -void Game::NewFrame() +bool Game::NewFrame() { - double dt = this->myData->timer.getElapsedSeconds(); - - //60 fps sec is currently staticly - - - if(dt >= DELTA_TIME) + for (unsigned int i = 0; i < this->players.Size(); i++) { - for (int i = 0; i < this->myData->players.Size(); i++) - { - if(this->myData->players[i]->player) - this->myData->players[i]->player->BeginFrame(); - } - API::Instance().Update(); - - for (int i = 0; i < this->myData->players.Size(); i++) - { - if(this->myData->players[i]->player) - this->myData->players[i]->player->EndFrame(); - } - this->myData->timer.reset(); + if(this->players[i]->player) this->players[i]->player->BeginFrame(); } -} \ No newline at end of file + + API::Instance().Update(); + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + return true; +} + +void Game::SetFPS(int FPS) +{ + this->frameTime = 1.0f / FPS; +} + +void Game::SetFrameTimeLength( float seconds ) +{ + this->frameTime = seconds; +} + +void Game::SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer) +{ + switch (type) + { + case GameLogic::GameEvent::ObjectEventFunctionType_OnMove: + this->onMoveFnc = functionPointer; + break; + case GameLogic::GameEvent::ObjectEventFunctionType_OnDead: + this->onDeadFnc = functionPointer; + break; + } + +} + +bool Game::Initiate() +{ + API::Instance().Init((int)pow(2u, 9u), 1u, Oyster::Math::Float3()); + API::Instance().SetSubscription(Game::PhysicsOnDestroy); + this->initiated = true; + return true; +} + + +float Game::GetFrameTime() const +{ + return this->frameTime; +} + +/**********************************************/ +/*********** Private methods ******************/ +/***************************************************************************************************/ + +void Game::PhysicsOnMove(const ICustomBody *object) +{ + IObjectData* temp = 0; + //IObjectData* temp = ((IObjectData*)object->GetDataTag()); + if(gameInstance.onMoveFnc) gameInstance.onMoveFnc(temp); +} +void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto) +{ + if(gameInstance.onDeadFnc) gameInstance.onDeadFnc(0); +} + diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 1550001d..95f67a6b 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -5,112 +5,84 @@ #ifndef GAME_H #define GAME_H -#include "GameLogicDef.h" -#include "GameLogicStates.h" -#include +//Includes windows so we need to undef minmax +#define NOMINMAX +#include + +#include "GameAPI.h" +#include "Player.h" +#include "Level.h" + +#include +#include +#include +#include namespace GameLogic { - class Player; - class Level; - class DANBIAS_GAMELOGIC_DLL Game + class Game :public GameAPI { public: - struct DANBIAS_GAMELOGIC_DLL PlayerData + class PlayerData :public IPlayerData { - private: - friend class Game; - Player *player; + public: PlayerData(); PlayerData(int playerID,int teamID); ~PlayerData(); - - public: - /******************************************************** - * 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 Move(const PLAYER_MOVEMENT &movement); - /******************************************************** - * Uses the chosen players weapon based on input - * @param playerID: ID of the player you want to recieve the message - * @param Usage: enum value on what kind of action is to be taken - ********************************************************/ - void UseWeapon(int playerID, const WEAPON_FIRE &usage); + void Move(const PLAYER_MOVEMENT &movement) override; + void UseWeapon(int playerID, const WEAPON_FIRE &usage) override; + int GetTeamID() const override; + PLAYER_STATE GetState() const override; + Oyster::Math::Float3 GetPosition() override; + Oyster::Math::Float4x4 GetOrientation() override; + int GetID() const override; + OBJECT_TYPE GetObjectType() const override; - /******************************************************** - * Gets players position - * @param playerID: ID of the player whos position you want - ********************************************************/ - Oyster::Math::Float3 GetPosition(); - - /******************************************************** - * Gets players current orientation - * @param playerID: ID of the player whos position you want - ********************************************************/ - Oyster::Math::Float4x4 GetOrientation(); - - /******************************************************** - * Check player state - * @return The current player state - ********************************************************/ - PLAYER_STATE GetState() const; - - /***/ - int GetID() const; - - /***/ - int GetTeamID() const; + Player *player; }; - struct DANBIAS_GAMELOGIC_DLL LevelData + class LevelData :public ILevelData { - private: - friend class Game; - Level *level; + public: LevelData(); ~LevelData(); - - public: + Oyster::Math::Float3 GetPosition() override; + Oyster::Math::Float4x4 GetOrientation() override; + int GetID() const override; + OBJECT_TYPE GetObjectType() const override; - + Level *level; }; public: - Game(void); - ~Game(void); + Game(); + ~Game(); - /******************************************************** - * Gets the position of all players currently in the game - ********************************************************/ - void GetAllPlayerPositions() const; + void GetAllPlayerPositions() const override; + PlayerData* CreatePlayer() override; + LevelData* CreateLevel() override; + void CreateTeam() override; + bool NewFrame() override; + void SetFPS( int FPS ) override; + void SetFrameTimeLength( float seconds ) override; + void SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer) override; + bool Initiate() override; - /******************************************************** - * Creates a player and returns PlayerData - ********************************************************/ - PlayerData* CreatePlayer(); + float GetFrameTime() const; - /******************************************************** - * Creates a level and returns LevelData - ********************************************************/ - LevelData* CreateLevel(); - - /******************************************************** - * Creates a team - ********************************************************/ - void CreateTeam(); - - /******************************************************** - * Runs a update of the gamelogic and physics - ********************************************************/ - void NewFrame(); - private: - struct PrivateData; - PrivateData *myData; + static void PhysicsOnMove(const Oyster::Physics::ICustomBody *object); + static void PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto); + + private: + Utility::DynamicMemory::DynamicArray players; + LevelData* level; + float frameTime; + bool initiated; + GameEvent::ObjectEventFunction onDeadFnc; + GameEvent::ObjectEventFunction onMoveFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h new file mode 100644 index 00000000..ffd13341 --- /dev/null +++ b/Code/Game/GameLogic/GameAPI.h @@ -0,0 +1,160 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Erik Persson] [2013] +///////////////////////////////////////////////////////////////////// + +#ifndef GAME_API_H +#define GAME_API_H + +//Includes windows so we need to undef minmax +#define NOMINMAX +#include + +#include "GameLogicDef.h" +#include "GameLogicStates.h" +#include + + +namespace GameLogic +{ + class IObjectData; + + /** + * Collection of various event structures that may be used to get events grom the game. + */ + namespace GameEvent + { + /** + * The type of event to listen on. + */ + enum ObjectEventFunctionType + { + ObjectEventFunctionType_OnMove, + ObjectEventFunctionType_OnDead, + }; + + typedef void(*ObjectEventFunction)(IObjectData* object); // Callback method that recieves and object + //etc... + }; + + /** + * An object that collects the standard usage functions + */ + class IObjectData + { + public: + /******************************************************** + * Gets players position + * @param playerID: ID of the player whos position you want + ********************************************************/ + virtual Oyster::Math::Float3 GetPosition() = 0; + + /******************************************************** + * Gets players current orientation + * @param playerID: ID of the player whos position you want + ********************************************************/ + virtual Oyster::Math::Float4x4 GetOrientation() = 0; + + /** Get the uniuqe id for the object + * @return The id for the object. + */ + virtual int GetID() const = 0; + + /** Get the type of the object + * @return The OBJECT_TYPE of the object is returned + */ + virtual OBJECT_TYPE GetObjectType() const = 0; + }; + + class IPlayerData :public IObjectData + { + public: + /******************************************************** + * 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 + ********************************************************/ + virtual void Move(const PLAYER_MOVEMENT &movement) = 0; + + /******************************************************** + * Uses the chosen players weapon based on input + * @param playerID: ID of the player you want to recieve the message + * @param Usage: enum value on what kind of action is to be taken + ********************************************************/ + virtual void UseWeapon(int playerID, const WEAPON_FIRE &usage) = 0; + + /***/ + virtual int GetTeamID() const = 0; + + /******************************************************** + * Check player state + * @return The current player state + ********************************************************/ + virtual PLAYER_STATE GetState() const = 0; + }; + + class ILevelData :public IObjectData + { + public: + + }; + + class DANBIAS_GAMELOGIC_DLL GameAPI + { + public: + /** A global function to get an instance of the API + * @return Returns the GameAPI instance + */ + static GameAPI& Instance( void ); + + public: + /** Initiates the Game instance. + * - This method must be called before the API can be used. + * @return If the return value is false, something went wrong. + */ + virtual bool Initiate( void ) = 0; + + /******************************************************** + * Gets the position of all players currently in the game + ********************************************************/ + virtual void GetAllPlayerPositions( void ) const = 0; + + /** Creates a player + * @return Returns a IPlayerData container to use for player manipulation. + */ + virtual IPlayerData* CreatePlayer( void ) = 0; + + /** Creates a level + * @return Returns a ILevelData container to use for level manipulation + */ + virtual ILevelData* CreateLevel( void ) = 0; + + /** Creates a team + * @return ? + */ + virtual void CreateTeam( void ) = 0; + + /** Runs a update of the gamelogic and physics + * @return Returns true if a frame was proccessed + */ + virtual bool NewFrame( void ) = 0; + + /** Set the frame time in fps + * @param FPS The fps to set + */ + virtual void SetFPS( int FPS = 60 ) = 0; + + /** Set the frames time in seconds + * @param seconds The frame length + */ + virtual void SetFrameTimeLength( float seconds ) = 0; + + /** Set a specific object event subscription callback + * @param + */ + virtual void SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::ObjectEventFunction functionPointer) = 0; + + }; +} + + +#endif diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 3c5ae258..6b66a9d5 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -69,26 +69,30 @@ $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) .dll + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D - $(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) $(SolutionDir)..\Bin\DLL\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) - $(SolutionDir)..\Bin\DLL;$(LibraryPath) + $(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath) + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) @@ -174,6 +178,7 @@ + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 2a4f6b41..4c7c4197 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -24,7 +24,8 @@ namespace GameLogic { OBJECT_TYPE_PLAYER = 0, OBJECT_TYPE_BOX = 1, - OBJECT_TYPE_UNKNOWN = 2, + OBJECT_TYPE_WORLD = 2, + OBJECT_TYPE_UNKNOWN = -1, }; enum WEAPON_FIRE diff --git a/Code/Game/GameLogic/GameMode.cpp b/Code/Game/GameLogic/GameMode.cpp index bcd87de5..ba240fca 100644 --- a/Code/Game/GameLogic/GameMode.cpp +++ b/Code/Game/GameLogic/GameMode.cpp @@ -3,28 +3,13 @@ using namespace GameLogic; -struct GameMode::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; - - GameMode::GameMode() { - myData = new PrivateData(); + } GameMode::~GameMode(void) { - delete myData; + } diff --git a/Code/Game/GameLogic/GameMode.h b/Code/Game/GameLogic/GameMode.h index 06ba6681..d910c78c 100644 --- a/Code/Game/GameLogic/GameMode.h +++ b/Code/Game/GameLogic/GameMode.h @@ -13,9 +13,9 @@ namespace GameLogic public: GameMode(void); ~GameMode(void); + private: - struct PrivateData; - PrivateData *myData; + }; } diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index a9a5394e..a9434f69 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -5,10 +5,33 @@ using namespace GameLogic; Game::LevelData::LevelData() { - + this->level = new Level(); } Game::LevelData::~LevelData() { + delete this->level; + this->level = 0; +} -} \ No newline at end of file + +Oyster::Math::Float3 Game::LevelData::GetPosition() +{ + //return this->level->GetCenter(); + return Oyster::Math::Float3(); +} +Oyster::Math::Float4x4 Game::LevelData::GetOrientation() +{ + //return this->level->GetOrientation(); + return Oyster::Math::Float4x4(); +} +int Game::LevelData::GetID() const +{ + //this->level->GetID(); + return -1; +} +OBJECT_TYPE Game::LevelData::GetObjectType() const +{ + //return this->level->GetType(); + return OBJECT_TYPE_UNKNOWN; +} diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index c393a18d..6cc5e9a5 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -5,15 +5,15 @@ using namespace GameLogic; Game::PlayerData::PlayerData() { - + this->player = new Player(); } Game::PlayerData::PlayerData(int playerID,int teamID) { - + this->player = new Player(); } Game::PlayerData::~PlayerData() { - + delete this->player; } void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement) @@ -43,4 +43,8 @@ int Game::PlayerData::GetID() const int Game::PlayerData::GetTeamID() const { return this->player->GetTeamID(); +} +OBJECT_TYPE Game::PlayerData::GetObjectType() const +{ + return this->player->GetType(); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4ce96dee..90dc1865 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -1,47 +1,16 @@ #include "Level.h" -#include "StaticObject.h" -#include "DynamicObject.h" -#include "GameMode.h" -#include "Player.h" -#include "PhysicsAPI.h" -#include "TeamManager.h" -#include "DynamicArray.h" +#include "CollisionManager.h" using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; -struct Level::PrivateData -{ - PrivateData() - { - - } - ~PrivateData() - { - } - - SmartPointer teamManager; - - DynamicArray> staticObjects; - - DynamicArray> dynamicObjects; - - SmartPointer gameMode; - - SmartPointer rigidBodyLevel; - -}myData; Level::Level(void) { - myData = new PrivateData(); } - - Level::~Level(void) { - delete myData; } void Level::InitiateLevel(std::string levelPath) @@ -50,39 +19,40 @@ void Level::InitiateLevel(std::string levelPath) } void Level::InitiateLevel(float radius) { - API::SphericalBodyDescription sbDesc; - sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); - sbDesc.ignoreGravity = true; - sbDesc.radius = radius; - sbDesc.mass = 1e16; //10^16 - sbDesc.subscription = CollisionManager::LevelCollision; - - ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - API::Instance().AddObject(rigidBody); - - API::Gravity gravityWell; - - gravityWell.gravityType = API::Gravity::GravityType_Well; - gravityWell.well.mass = (float)1e16; - gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); - - API::Instance().AddGravity(gravityWell); + //API::SphericalBodyDescription sbDesc; + //sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); + //sbDesc.ignoreGravity = true; + //sbDesc.radius = radius; + //sbDesc.mass = 1e16f; //10^16 + //sbDesc.mass = 0; //10^16 + //sbDesc.subscription_onCollision = CollisionManager::LevelCollision; + // + //ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + //API::Instance().AddObject(rigidBody); + + //API::Gravity gravityWell; + // + //gravityWell.gravityType = API::Gravity::GravityType_Well; + //gravityWell.well.mass = 1e16f; + //gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); + // + //API::Instance().AddGravity(gravityWell); } void Level::AddPlayerToTeam(Player *player, int teamID) { - myData->teamManager->AddPlayerToTeam(player,teamID); + this->teamManager.AddPlayerToTeam(player,teamID); } void Level::CreateTeam(int teamSize) { - myData->teamManager->CreateTeam(teamSize); + this->teamManager.CreateTeam(teamSize); } void Level::RespawnPlayer(Player *player) { - myData->teamManager->RespawnPlayerRandom(player); + this->teamManager.RespawnPlayerRandom(player); } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 68dfca0f..2242a8b2 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -4,7 +4,15 @@ #ifndef LEVEL_H #define LEVEL_H #include + #include "Player.h" +#include "StaticObject.h" +#include "DynamicObject.h" +#include "GameMode.h" +#include "Player.h" +#include "PhysicsAPI.h" +#include "TeamManager.h" +#include "DynamicArray.h" namespace GameLogic { @@ -44,10 +52,11 @@ namespace GameLogic void RespawnPlayer(Player *player); private: - - private: - struct PrivateData; - PrivateData *myData; + TeamManager teamManager; + Utility::DynamicMemory::DynamicArray> staticObjects; + Utility::DynamicMemory::DynamicArray> dynamicObjects; + GameMode gameMode; + Utility::DynamicMemory::SmartPointer rigidBodyLevel; }; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index cf8c8d9e..7e137c37 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -3,6 +3,7 @@ #include "CollisionManager.h" #include "GID.h" #include "PhysicsAPI.h" +#include "Game.h" using namespace GameLogic; @@ -10,6 +11,8 @@ using namespace GameLogic; using namespace Oyster::Math; using namespace Oyster::Physics; +const Game *Object::gameInstance = (Game*)(&Game::Instance()); + Object::Object() { API::SimpleBodyDescription sbDesc; @@ -34,7 +37,7 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) //sbDesc.centerPosition = //poi - ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); Oyster::Physics::API::Instance().AddObject(rigidBody); @@ -66,3 +69,14 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody() { return this->rigidBody; } + + +void Object::BeginFrame() +{ + this->rigidBody->SetState(this->setState); +} +void Object::EndFrame() +{ + this->rigidBody->GetState(this->getState); + this->setState = this->getState; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index d7fd02d9..1316b287 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -6,12 +6,13 @@ #ifndef OBJECT_H #define OBJECT_H - #include "GameLogicStates.h" #include namespace GameLogic { + class Game; + class Object { public: @@ -21,17 +22,22 @@ namespace GameLogic OBJECT_TYPE GetType() const; int GetID() const; - Oyster::Physics::ICustomBody* GetRigidBody(); + void BeginFrame(); + void EndFrame(); + private: OBJECT_TYPE type; int objectID; + protected: Oyster::Physics::ICustomBody *rigidBody; Oyster::Physics::ICustomBody::State setState; Oyster::Physics::ICustomBody::State getState; + static const Game* gameInstance; + }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 05a20503..51e13b68 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -1,6 +1,8 @@ #include "Player.h" #include "Weapon.h" +#include "CollisionManager.h" +#include "Game.h" using namespace GameLogic; using namespace Oyster::Physics; @@ -14,17 +16,11 @@ Player::Player() teamID = -1; playerState = PLAYER_STATE::PLAYER_STATE_IDLE; lookDir = Oyster::Math::Float4(0,0,-1,0); - Oyster::Physics::ICustomBody::State state; - this->rigidBody->GetState( this->setState ); - setState.SetLinearMomentum( Oyster::Math::Float4(20, 0, 0, 0) ); - this->rigidBody->SetState( setState ); - } Player::~Player(void) { delete weapon; - weapon = NULL; } @@ -57,26 +53,26 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - setState.ApplyLinearImpulse(this->lookDir * 100); + setState.ApplyLinearImpulse(this->lookDir * (100 * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { - setState.ApplyLinearImpulse(-this->lookDir * 100); + setState.ApplyLinearImpulse(-this->lookDir * 100 * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); //Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); - setState.ApplyLinearImpulse(r * 100); + setState.ApplyLinearImpulse(r * 100 * this->gameInstance->GetFrameTime()); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); - //Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); - setState.ApplyLinearImpulse(-r * 100); + //Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero + setState.ApplyLinearImpulse(-r * 100 * this->gameInstance->GetFrameTime()); } void Player::UseWeapon(const WEAPON_FIRE &usage) @@ -136,12 +132,3 @@ void Player::DamageLife(int damage) this->life -= damage; } -void Player::BeginFrame() -{ - this->rigidBody->SetState(this->setState); -} -void Player::EndFrame() -{ - this->rigidBody->GetState(this->getState); - this->setState = this->getState; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0f080b3b..37592d11 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -7,9 +7,6 @@ #include "GameLogicStates.h" #include "OysterMath.h" #include "Object.h" -#include "OysterMath.h" -#include "CollisionManager.h" - namespace GameLogic @@ -58,10 +55,6 @@ namespace GameLogic void DamageLife(int damage); - //Do frame calculations - void BeginFrame(); - void EndFrame(); - private: void Jump(); diff --git a/Code/Game/GameLogic/Team.cpp b/Code/Game/GameLogic/Team.cpp index 27a19bcd..b7c9d6ea 100644 --- a/Code/Game/GameLogic/Team.cpp +++ b/Code/Game/GameLogic/Team.cpp @@ -1,60 +1,54 @@ #include "Team.h" -#include "Player.h" using namespace GameLogic; -struct Team::PrivateData -{ - PrivateData() - { - players = 0; - nrOfPlayers = 0; - teamSize = 0; - } - ~PrivateData() - { - - } - - Player **players; - int nrOfPlayers; - - int teamSize; - -}myData; Team::Team(void) -{ - myData = new PrivateData(); -} + : players(5) + , teamSize(5) +{} Team::Team(int teamSize) -{ - myData = new PrivateData(); - myData->teamSize = teamSize; -} + : players((unsigned int)teamSize) + , teamSize(teamSize) +{} Team::~Team(void) { - delete myData; + this->players.Clear(); } Player* Team::GetPlayer(int playerID) { - return myData->players[playerID]; + if(playerID >= 0 && playerID < this->teamSize) + return this->players[playerID]; + + return NULL; } bool Team::AddPlayer(Player *player) { - if (myData->nrOfPlayers >= myData->teamSize) + if ((int)this->players.Size() >= this->teamSize) { return false; } else { - myData->players[myData->nrOfPlayers] = player; - myData->nrOfPlayers++; + int k = -1; + for (int i = 0; k == -1 && i < this->teamSize; i++) + { + if(!this->players[i]) + k = i; + } + if(k == -1) + { + this->players.Push(player); + } + else + { + this->players[k] = player; + } } return true; diff --git a/Code/Game/GameLogic/Team.h b/Code/Game/GameLogic/Team.h index b1bdbc6c..c12e5489 100644 --- a/Code/Game/GameLogic/Team.h +++ b/Code/Game/GameLogic/Team.h @@ -4,7 +4,9 @@ #ifndef TEAM_H #define TEAM_H + #include "Player.h" +#include "DynamicArray.h" namespace GameLogic { @@ -29,8 +31,8 @@ namespace GameLogic bool AddPlayer(Player *player); private: - struct PrivateData; - PrivateData *myData; + Utility::DynamicMemory::DynamicArray players; + int teamSize; }; } #endif diff --git a/Code/Game/GameLogic/TeamManager.cpp b/Code/Game/GameLogic/TeamManager.cpp index 6110707d..d1379c63 100644 --- a/Code/Game/GameLogic/TeamManager.cpp +++ b/Code/Game/GameLogic/TeamManager.cpp @@ -1,69 +1,56 @@ #include "TeamManager.h" -#include "Team.h" - using namespace GameLogic; -struct TeamManager::PrivateData -{ - PrivateData() - { - teams = 0; - nrOfTeams = 0; - } - ~PrivateData() - { - } - - Team **teams; - int nrOfTeams; - int maxNrOfTeams; - -}myData; TeamManager::TeamManager(void) + : teams(10) + , maxNrOfTeams(10) { - myData = new PrivateData(); - myData->maxNrOfTeams = 10; - myData->teams = new Team*[myData->maxNrOfTeams]; + for (int i = 0; i < 10; i++) + { + teams[i] = 0; + } } TeamManager::TeamManager(int maxNrOfTeams) + : teams(maxNrOfTeams) + , maxNrOfTeams(maxNrOfTeams) { - myData = new PrivateData(); - myData->maxNrOfTeams = maxNrOfTeams; - - myData->teams = new Team*[myData->maxNrOfTeams]; - for (int i = 0; i < myData->maxNrOfTeams; i++) + for (int i = 0; i < this->maxNrOfTeams; i++) { - myData->teams[i] = 0; + teams[i] = 0; } - } TeamManager::~TeamManager(void) { - delete myData; + for (int i = 0; i < this->maxNrOfTeams; i++) + { + delete this->teams[i]; + this->teams[i] = 0; + } } void TeamManager::RespawnPlayerRandom(Player *player) { - - int teamID = player->GetTeamID(); - - Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0); - - player->Respawn(respawnOnThis->GetPosition()); + // Whats going on here? + int teamID = player->GetTeamID(); // ? + // ? + Player *respawnOnThis = this->teams[teamID]->GetPlayer(0); // ? + // ? + player->Respawn(respawnOnThis->GetPosition()); // ? + // player->Respawn(player->GetPosition()); ? } void TeamManager::CreateTeam(int teamSize) { - if (myData->nrOfTeams < myData->maxNrOfTeams) - { - myData->teams[myData->nrOfTeams] = new Team(teamSize); - myData->nrOfTeams++; - } + //if (this->nrOfTeams < this->maxNrOfTeams) + //{ + // this->teams[this->nrOfTeams] = new Team(teamSize); + // this->nrOfTeams++; + //} } void TeamManager::RemoveTeam(int teamID) @@ -73,10 +60,10 @@ void TeamManager::RemoveTeam(int teamID) bool TeamManager::AddPlayerToTeam(Player *player,int teamID) { - if (IsValidTeam(teamID)) - { - return myData->teams[teamID]->AddPlayer(player); - } + //if (IsValidTeam(teamID)) + //{ + // return this->teams[teamID]->AddPlayer(player); + //} return false; } @@ -87,10 +74,10 @@ bool TeamManager::AddPlayerToTeam(Player *player) bool TeamManager::IsValidTeam(int teamID) { - if (teamID < myData->nrOfTeams && teamID > 0 && myData->teams[teamID] != NULL) - { - return true; - } + //if (teamID < this->nrOfTeams && teamID > 0 && this->teams[teamID] != NULL) + //{ + // return true; + //} return false; } \ No newline at end of file diff --git a/Code/Game/GameLogic/TeamManager.h b/Code/Game/GameLogic/TeamManager.h index 80715210..d5fa1c86 100644 --- a/Code/Game/GameLogic/TeamManager.h +++ b/Code/Game/GameLogic/TeamManager.h @@ -4,7 +4,10 @@ #ifndef TEAMMANAGER_H #define TEAMMANAGER_H + #include "Player.h" +#include "Team.h" +#include namespace GameLogic { @@ -56,8 +59,8 @@ namespace GameLogic bool IsValidTeam(int teamID); private: - struct PrivateData; - PrivateData *myData; + Utility::DynamicMemory::DynamicArray teams; + int maxNrOfTeams; }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 9e6b6bd2..28765cf3 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -83,7 +83,7 @@ bool Weapon::IsReloading() bool Weapon::IsValidSocket(int socketID) { - if(socketID < myData->attatchmentSockets.Size() && socketID >= 0) + if(socketID < (int)myData->attatchmentSockets.Size() && socketID >= 0) { if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) { @@ -102,7 +102,7 @@ int Weapon::GetCurrentSocketID() void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) { - if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size()) + if(myData->currentNrOfAttatchments < (int)myData->attatchmentSockets.Size()) { myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); myData->currentNrOfAttatchments++; diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/ControlProtocols.h index 46268b75..0aba4dc6 100644 --- a/Code/Game/GameProtocols/ControlProtocols.h +++ b/Code/Game/GameProtocols/ControlProtocols.h @@ -46,6 +46,7 @@ namespace GameLogic struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject { char* text; + int destination; Protocol_General_Text() { diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 744d1ed2..0b7bf576 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -150,6 +150,10 @@ + + true + true + @@ -165,6 +169,10 @@ + + true + true + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 97d25b7d..44348332 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -45,6 +45,9 @@ Source Files + + Source Files + @@ -104,5 +107,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index 534c992f..6c89567c 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -101,7 +101,7 @@ using namespace Utility::DynamicMemory; else this->threadData->state = OYSTER_THREAD_STATE_IDLE; threadData->ownerObj = worker; - threadData->prio = OYSTER_THREAD_PRIORITY_3; + threadData->prio = OYSTER_THREAD_PRIORITY_2; workerThread = std::thread(fnc, this->threadData); diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 2a0c4dc0..b55e4d7e 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -73,6 +73,7 @@ struct ClientDataContainer }; unsigned int ClientDataContainer::currID = 0; + struct NetworkClient::PrivateData : public IThreadObject { Utility::DynamicMemory::SmartPointer data; @@ -92,6 +93,7 @@ struct NetworkClient::PrivateData : public IThreadObject return true; } + void Send(CustomNetProtocol* protocol) { if(!data) return; @@ -175,12 +177,14 @@ struct NetworkClient::PrivateData : public IThreadObject NetworkClient::NetworkClient() { privateData = new PrivateData(); + this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1); } NetworkClient::NetworkClient(unsigned int socket) { privateData = new PrivateData(socket); this->privateData->data->thread.Create(this->privateData, true); + this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1); } NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type) @@ -196,6 +200,7 @@ NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType this->privateData->data->callbackType = type; this->privateData->data->recvObj = recvObj; this->privateData->data->thread.Create(this->privateData, true); + this->privateData->data->thread.SetPriority(Oyster::Thread::OYSTER_THREAD_PRIORITY_1); } NetworkClient::NetworkClient(const NetworkClient& obj)