diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 3a606491..68c4cdfa 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -44,6 +44,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameP EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Game\DanBiasServerLauncher\DanBiasServerLauncher.vcxproj", "{060B1890-CBF3-4808-BA99-A4776222093B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Mixed Platforms = Debug|Mixed Platforms @@ -270,6 +272,18 @@ Global {060B1890-CBF3-4808-BA99-A4776222093B}.Release|Win32.Build.0 = Release|Win32 {060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.ActiveCfg = Release|x64 {060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.Build.0 = Release|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -285,5 +299,6 @@ Global {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A} {060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A} EndGlobalSection EndGlobal diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 68cb19d6..5e129fca 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -26,7 +26,7 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject } } break; - case protocol_Gameplay_PlayerNavigation: + case protocol_Gameplay_PlayerMovement: { Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; for(int i = 0; i< 6; i++) @@ -40,21 +40,21 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject protocolData = NULL; } break; - case protocol_Gameplay_PlayerPosition: - { - Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; - for(int i = 0; i< 3; i++) - { - protocolData->playerPos[i] = p[i].value.netFloat; - } - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - delete protocolData; - protocolData = NULL; - } - break; + //case protocol_Gameplay_PlayerPosition: + // { + // Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; + // for(int i = 0; i< 3; i++) + // { + // protocolData->playerPos[i] = p[i].value.netFloat; + // } + // if(dynamic_cast(gameClientState)) + // ((Client::GameState*)gameClientState)->Protocol(protocolData); + // delete protocolData; + // protocolData = NULL; + // } + // break; - case protocol_Gameplay_CreateObject: + case protocol_Gameplay_ObjectCreate: { Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; protocolData->object_ID = p[1].value.netInt; @@ -72,7 +72,7 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject protocolData = NULL; } break; - case protocol_Gameplay_RemoveObject: + case protocol_Gameplay_ObjectDisabled: { Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; protocolData->object_ID = p[1].value.netInt; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index e0b0054a..f1474eed 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -131,10 +131,8 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI GameLogic::Protocol_PlayerMovement movePlayer; movePlayer.bForward = false; movePlayer.bBackward = false; - movePlayer.bStrafeLeft = false; - movePlayer.bStrafeRight = false; - movePlayer.bTurnLeft = false; - movePlayer.bTurnRight = false; + movePlayer.bLeft = false; + movePlayer.bRight = false; if(KeyInput->IsKeyPressed(DIK_W)) { @@ -165,7 +163,7 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI { if(!key_strafeLeft) { - movePlayer.bStrafeLeft = true; + movePlayer.bLeft = true; send = true; key_strafeLeft = true; } @@ -177,7 +175,7 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI { if(!key_strafeRight) { - movePlayer.bStrafeRight = true; + movePlayer.bRight = true; send = true; key_strafeRight = true; } @@ -221,7 +219,7 @@ bool GameState::Render() Oyster::Graphics::API::SetView(privData->view); Oyster::Graphics::API::SetProjection(privData->proj); Oyster::Graphics::API::NewFrame(); - for (int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < privData->object.size(); i++) { privData->object[i]->Render(); } @@ -230,7 +228,7 @@ bool GameState::Render() } bool GameState::Release() { - for (int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < privData->object.size(); i++) { privData->object[i]->Release(); delete privData->object[i]; @@ -305,7 +303,7 @@ void GameState::Protocol( NewObj* newObj ) void DanBias::Client::GameState::Protocol( RemoveObj* obj ) { - for (int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < privData->object.size(); i++) { if(privData->object[i]->GetId() == obj->object_ID) { diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index 164e5748..1fa526f5 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -42,35 +42,29 @@ namespace DanBias { switch (p[protocol_INDEX_ID].value.netShort) { - case protocol_Gameplay_PlayerNavigation: + case protocol_Gameplay_PlayerMovement: { - - //Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; if(p[1].value.netBool) //bool bForward; - //world.v[3].x = 2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); if(p[2].value.netBool) //bool bBackward; - //world.v[3].x = -2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); - if(p[5].value.netBool) //bool bStrafeRight; - //world.v[3].y = 2; - c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); - if(p[6].value.netBool) //bool bStrafeLeft; - //world.v[3].y = -2; + if(p[3].value.netBool) //bool bStrafeLeft; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); + if(p[4].value.netBool) //bool bStrafeRight; + c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); } break; case protocol_Gameplay_PlayerMouseMovement: + { + Protocol_PlayerMouse m; m = p; + c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse); + } + break; + case protocol_Gameplay_PlayerChangeWeapon: break; - case protocol_Gameplay_PlayerPosition: - - break; - case protocol_Gameplay_CreateObject: - - break; - case protocol_Gameplay_ObjectPosition: - + case protocol_Gameplay_PlayerDamage: + break; } } @@ -110,11 +104,9 @@ namespace DanBias void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) { - //if (movedObject->) - //{ - // - //} - //movedObject->GetOrientation(); + movedObject->GetID(); + movedObject->GetOrientation(); + } }//End namespace DanBias diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp index a0010f1f..7c47d4a7 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -67,7 +67,6 @@ namespace DanBias Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation(); Protocol_ObjectPosition p(world, 1); Send(p.GetProtocol()); - //Sleep(100); } } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 5ab72dcc..4380777e 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -151,9 +151,9 @@ float Game::GetFrameTime() const void Game::PhysicsOnMove(const ICustomBody *object) { - IObjectData* temp = 0; - //IObjectData* temp = ((IObjectData*)object->GetDataTag()); - if(gameInstance.onMoveFnc) gameInstance.onMoveFnc(temp); + IObjectData* temp = (IObjectData*)object->GetCustomTag(); + + if(gameInstance.onMoveFnc && temp) gameInstance.onMoveFnc(temp); } void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto) { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index b6f19eb8..11c8d325 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -39,6 +39,8 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; OBJECT_TYPE GetObjectType() const override; + void Rotate(const float x, const float y) override; + Player *player; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 8e05c8cd..12f5022f 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -75,6 +75,12 @@ namespace GameLogic ********************************************************/ virtual void Move(const PLAYER_MOVEMENT &movement) = 0; + /** Relative rotation around given axis + * @param x: The relative x axis + * @param y: The relative y axis + **/ + virtual void Rotate(const float x, const float y) = 0; + /******************************************************** * Uses the chosen players weapon based on input * @param Usage: enum value on what kind of action is to be taken diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 58fe6616..e651a02f 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -6,6 +6,7 @@ using namespace GameLogic; Game::PlayerData::PlayerData() { this->player = new Player(); + this->player->GetRigidBody()->SetCustomTag(this); } Game::PlayerData::PlayerData(int playerID,int teamID) { @@ -47,4 +48,8 @@ int Game::PlayerData::GetTeamID() const OBJECT_TYPE Game::PlayerData::GetObjectType() const { return this->player->GetType(); +} +void Game::PlayerData::Rotate(const float x, const float y) +{ + this->player->Rotate(x, y); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index a7ca4df4..96ee5cfd 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -88,6 +88,11 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->lookDir = Oyster::Math::Float4(1,0,0); } +void Player::Rotate(float x, float y) +{ + this->setState.AddRotation(Oyster::Math::Float4(x, y)); +} + void Player::Jump() { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 5244f541..39e8f5f6 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -41,6 +41,7 @@ namespace GameLogic ********************************************************/ void Respawn(Oyster::Math::Float3 spawnPoint); + void Rotate(float x, float y); bool IsWalking(); bool IsJumping(); diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 2a538714..e52a4d2f 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -5,9 +5,128 @@ #include "ProtocolIdentificationID.h" - namespace GameLogic { + struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject + { + int object_ID; + float worldMatrix[16]; + // look at dir + + Protocol_ObjectPosition() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (int i = 2; i <= 17; i++) + { + this->protocol[i].type = Oyster::Network::NetAttributeType_Float; + } + object_ID = -1; + memset(&worldMatrix[0], 0, sizeof(float) * 16); + } + Protocol_ObjectPosition(float m[16], int id) + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (int i = 2; i <= 17; i++) + { + this->protocol[i].type = Oyster::Network::NetAttributeType_Float; + } + + object_ID = id; + memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = object_ID; + for (int i = 2; i <= 17; i++) + { + this->protocol[i].value = worldMatrix[i-2]; + } + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_ObjectEnable :public Oyster::Network::CustomProtocolObject + { + int object_ID; + float worldMatrix[16]; + // look at dir + + Protocol_ObjectEnable() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (int i = 2; i <= 17; i++) + { + this->protocol[i].type = Oyster::Network::NetAttributeType_Float; + } + object_ID = -1; + memset(&worldMatrix[0], 0, sizeof(float) * 16); + } + Protocol_ObjectEnable(float m[16], int id) + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (int i = 2; i <= 17; i++) + { this->protocol[i].type = Oyster::Network::NetAttributeType_Float; } + + object_ID = id; + memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = object_ID; + for (int i = 2; i <= 17; i++) + { + this->protocol[i].value = worldMatrix[i-2]; + } + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject + { + int object_ID; + float timer; + + Protocol_ObjectDisable() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = object_ID; + this->protocol[2].value = timer; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + struct Protocol_CreateObject :public Oyster::Network::CustomProtocolObject { int object_ID; @@ -17,7 +136,7 @@ namespace GameLogic Protocol_CreateObject() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject; + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -30,7 +149,7 @@ namespace GameLogic } Protocol_CreateObject(float m[16], int id, char *path) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject; + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -70,77 +189,6 @@ namespace GameLogic - return &protocol; - } - - private: - Oyster::Network::CustomNetProtocol protocol; - }; - - struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject - { - int object_ID; - float worldMatrix[16]; - // look at dir - - Protocol_ObjectPosition() - { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - - for (int i = 2; i <= 17; i++) - { - this->protocol[i].type = Oyster::Network::NetAttributeType_Float; - } - object_ID = -1; - memset(&worldMatrix[0], 0, sizeof(float) * 16); - } - Protocol_ObjectPosition(float m[16], int id) - { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - - for (int i = 2; i <= 17; i++) - { - this->protocol[i].type = Oyster::Network::NetAttributeType_Float; - } - - object_ID = id; - memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); - } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { - this->protocol[1].value = object_ID; - for (int i = 2; i <= 17; i++) - { - this->protocol[i].value = worldMatrix[i-2]; - } - return &protocol; - } - - private: - Oyster::Network::CustomNetProtocol protocol; - }; - - struct Protocol_RemoveObject :public Oyster::Network::CustomProtocolObject - { - int object_ID; - - Protocol_RemoveObject() - { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_RemoveObject; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { - - this->protocol[1].value = object_ID; return &protocol; } diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 96686807..eb89b1c6 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -10,7 +10,6 @@ #include "ProtocolIdentificationID.h" - namespace GameLogic { struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject @@ -18,31 +17,25 @@ namespace GameLogic bool bForward; bool bBackward; - bool bTurnLeft; - bool bTurnRight; - bool bStrafeRight; - bool bStrafeLeft; + bool bLeft; + bool bRight; Protocol_PlayerMovement() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerNavigation; + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMovement; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; this->protocol[4].type = Oyster::Network::NetAttributeType_Bool; - this->protocol[5].type = Oyster::Network::NetAttributeType_Bool; - this->protocol[6].type = Oyster::Network::NetAttributeType_Bool; } const Protocol_PlayerMovement& operator=(Oyster::Network::CustomNetProtocol& val) { bForward = val[1].value.netBool; bBackward = val[2].value.netBool; - bTurnLeft = val[3].value.netBool; - bTurnRight = val[4].value.netBool; - bStrafeRight = val[5].value.netBool; - bStrafeLeft = val[6].value.netBool; + bLeft = val[3].value.netBool; + bRight = val[4].value.netBool; return *this; } @@ -50,10 +43,8 @@ namespace GameLogic { this->protocol[1].value = bForward; this->protocol[2].value = bBackward; - this->protocol[3].value = bTurnLeft; - this->protocol[4].value = bTurnRight; - this->protocol[5].value = bStrafeRight; - this->protocol[6].value = bStrafeLeft; + this->protocol[3].value = bLeft; + this->protocol[4].value = bRight; return &protocol; } @@ -97,15 +88,14 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_PlayerPosition :public Oyster::Network::CustomProtocolObject + struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject { - float position[3]; - // look at dir + int ID; - Protocol_PlayerPosition() + Protocol_PlayerChangeWeapon() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPosition; + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerChangeWeapon; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; @@ -113,19 +103,69 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; } - const Protocol_PlayerPosition& operator=(Oyster::Network::CustomNetProtocol& val) + const Protocol_PlayerChangeWeapon& operator=(Oyster::Network::CustomNetProtocol& val) { - position[0] = val[1].value.netFloat; - position[1] = val[2].value.netFloat; - position[2] = val[3].value.netFloat; + return *this; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_PlayerDamage :public Oyster::Network::CustomProtocolObject + { + + int hp; + // look at dir + + Protocol_PlayerDamage() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerDamage; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + } + const Protocol_PlayerDamage& operator=(Oyster::Network::CustomNetProtocol& val) + { + hp = val[1].value.netInt; + return *this; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value =hp; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_PlayerPickup :public Oyster::Network::CustomProtocolObject + { + int pickupID; + + Protocol_PlayerPickup() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPickup; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + } + const Protocol_PlayerPickup& operator=(Oyster::Network::CustomNetProtocol& val) + { + pickupID = val[3].value.netInt; return *this; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value = position[0]; - this->protocol[2].value = position[1]; - this->protocol[3].value = position[2]; + this->protocol[3].value = pickupID; return &protocol; } diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index fb54e403..a48d5594 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -45,13 +45,16 @@ /********* GAMEPLAY PROTOCOLS ***************************************************************************************************/ /***********[ 300 - 400 ]***********/ #define protocol_GameplayMIN 300 -#define protocol_Gameplay_PlayerNavigation 300 +#define protocol_Gameplay_PlayerMovement 300 #define protocol_Gameplay_PlayerMouseMovement 301 -#define protocol_Gameplay_PlayerPosition 302 -#define protocol_Gameplay_CreateObject 303 -#define protocol_Gameplay_RemoveObject 304 +#define protocol_Gameplay_PlayerChangeWeapon 302 +#define protocol_Gameplay_PlayerDamage 303 +#define protocol_Gameplay_PlayerPickup 304 #define protocol_Gameplay_ObjectPosition 305 -#define protocol_Gameplay_Initiate 306 +#define protocol_Gameplay_ObjectEnabled 306 +#define protocol_Gameplay_ObjectDisabled 307 +#define protocol_Gameplay_ObjectCreate 308 +#define protocol_Gameplay_Initiate 309 #define protocol_GameplayMAX 399 diff --git a/Code/Game/aDanBiasGameLauncher/Launcher.cpp b/Code/Game/aDanBiasGameLauncher/Launcher.cpp new file mode 100644 index 00000000..8f8e6252 --- /dev/null +++ b/Code/Game/aDanBiasGameLauncher/Launcher.cpp @@ -0,0 +1,62 @@ + +#define NOMINMAX +#include +#include + +#include "DanBiasGame.h" +#include + +#include + + +void ServerFnc() +{ + + if( DanBias::DanBiasServerAPI::Initiate() == DanBias::DanBiasServerReturn_Sucess) + { + DanBias::DanBiasServerAPI::Run(); + DanBias::DanBiasServerAPI::Release(); + } + Sleep(100); +} +void ClientFnc() +{ + // Game client starter code goes here + DanBias::DanBiasGameDesc gameDesc; + gameDesc.port = 15151; + //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"; + + if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Sucess) + { + DanBias::DanBiasGame::Run(); + DanBias::DanBiasGame::Release(); + } + Sleep(100); +} + + +int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) +{ + std::thread serverThread; + std::thread clientThread; + + if(SetDllDirectory(L"..\\DLL") == FALSE) + { + return cmdShow; + } + + serverThread = std::thread(ServerFnc); + + Sleep(100); + + clientThread = std::thread(ClientFnc); + + if (serverThread.joinable()) serverThread.join(); + if (clientThread.joinable()) clientThread.join(); + + return cmdShow; +} \ No newline at end of file diff --git a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj new file mode 100644 index 00000000..1a9d892f --- /dev/null +++ b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj @@ -0,0 +1,187 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {666FEA52-975F-41CD-B224-B19AF3C0ABBA} + Win32Proj + aDanBiasGameLauncher + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\Bin\Executable\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + + + true + $(SolutionDir)..\Bin\Executable\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + + + false + $(SolutionDir)..\Bin\Executable\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + + + false + $(SolutionDir)..\Bin\Executable\ + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\External\Include\;C:\Program Files %28x86%29\Visual Leak Detector\include;C:\Users\Dennis\Desktop\Skola\DV1477 - Stort spelutvecklingsprojekt\DanBias\Code\Game\DanBiasServer;$(IncludePath) + $(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + + + Windows + true + DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + + + Windows + true + DanBiasGame_$(PlatformShortName)D.dll;DanBiasServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + + + Windows + true + true + true + DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)Game\DanBiasServer\Include;$(SolutionDir)Game\DanBiasGame\Include + + + Windows + true + true + true + DanBiasGame_$(PlatformShortName).dll;DanBiasServer_$(PlatformShortName).dll;%(DelayLoadDLLs) + DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + + + + + + + + {2a1bc987-af42-4500-802d-89cd32fc1309} + + + {52380daa-0f4a-4d97-8e57-98df39319caf} + + + + + + \ No newline at end of file diff --git a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj.user b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj.user new file mode 100644 index 00000000..2e28d6f7 --- /dev/null +++ b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj.user @@ -0,0 +1,22 @@ + + + + true + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Code/Misc/DynamicArray.h b/Code/Misc/DynamicArray.h index 35df725f..e2041f99 100644 --- a/Code/Misc/DynamicArray.h +++ b/Code/Misc/DynamicArray.h @@ -35,6 +35,8 @@ namespace Utility void Resize(unsigned int size); + void Reserve(unsigned int size); + void Swap(unsigned int a, unsigned int b); unsigned int Size() const; @@ -201,6 +203,11 @@ namespace Utility this->data = temp; } + template void DynamicArray::Reserve(unsigned int size) + { + Expand(size); + } + template void DynamicArray::Swap(unsigned int a, unsigned int b) { T temp = this->data[a]; diff --git a/Code/Misc/Resource/ResourceManager.cpp b/Code/Misc/Resource/ResourceManager.cpp new file mode 100644 index 00000000..133ce00b --- /dev/null +++ b/Code/Misc/Resource/ResourceManager.cpp @@ -0,0 +1,247 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// + + +#include "ResourceManager.h" + +using namespace Oyster::Resource; + +struct Oyster::Resource::ResourceData +{ + +} + +ResourceData* FindResource(std::map resources, const HRESOURCE& h) const +{ + for (auto i = resources.begin(); i != resources.end() ; i++) + { + if(i->second->GetResourceHandle() == h) + { + return i->second; + } + } + return 0; +} +ResourceData* FindResource(std::map resources, const wchar_t c[]) const +{ + std::wstring temp = c; + auto t = this->resources.find(c); + if(t == this->resources.end()) return 0; + + return t->second; +} +void SaveResource( std::map resources, OResource* r, bool addNew ) +{ + if(!r) return; + + if(addNew) + { + this->resources[r->GetResourceFilename()] = r; + } + + r->resourceRef.Incref(); +} + + +ResourceManager::ResourceManager() +{ + +} +ResourceManager:: +HRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType type, int customID, bool force) +{ + if(!filename) return 0; + + OResource *resourceData = FindResource(filename); + + if(resourceData) + { + if(force) + { + return OysterResource::ReloadResource(filename); + } + else + { + //Add new reference + resourcePrivate.SaveResource(resourceData, false); + return resourceData->GetResourceHandle(); + } + } + else + { + resourceData = OResource::Load(filename, type); + if(resourceData) + { + resourceData->SetResourceID(customID); + resourcePrivate.SaveResource(resourceData); + } + } + + return resourceData->GetResourceHandle(); +} +HRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force) +{ + if(!filename) + { + return 0; + } + if(!loadFnc) + { + return 0; + } + + OResource *resourceData = resourcePrivate.FindResource(filename); + if(resourceData) + { + if(force) + { + return OysterResource::ReloadResource(filename); + } + else + { + //Add new reference + resourcePrivate.SaveResource(resourceData, false); + return resourceData->GetResourceHandle(); + } + } + else + { + resourceData = OResource::Load(filename, loadFnc); + if(resourceData) + { + resourceData->SetResourceID(customId); + resourcePrivate.SaveResource(resourceData); + } + } + if(!resourceData) + { + return 0; + } + return (OHRESOURCE)resourceData->GetResourceHandle(); +} + +OHRESOURCE OysterResource::ReloadResource(const wchar_t filename[]) +{ + OResource *resourceData = resourcePrivate.FindResource(filename); + if(!resourceData) return 0; //The resource has not been loaded + + return OResource::Reload(resourceData)->GetResourceHandle(); +} +OHRESOURCE OysterResource::ReloadResource(OHRESOURCE resource) +{ + OResource *resourceData = resourcePrivate.FindResource(resource); + if(!resourceData) return 0; //The resource has not been loaded + + return OResource::Reload(resourceData)->GetResourceHandle(); +} + +void OysterResource::Clean() +{ + auto i = resourcePrivate.resources.begin(); + auto last = resourcePrivate.resources.end(); + + for (i; i != last; i++) + { + //Remove all the references + while (!OResource::Release(i->second)); + + std::wstring temp = i->second->GetResourceFilename(); + delete resourcePrivate.resources[temp]; + + + } + resourcePrivate.resources.clear(); +} +void OysterResource::ReleaseResource(const OHRESOURCE& resourceData) +{ + OResource* t = resourcePrivate.FindResource(resourceData); + if(t) + { + if(OResource::Release(t)) + { + std::wstring temp = t->GetResourceFilename(); + delete resourcePrivate.resources[temp]; + resourcePrivate.resources.erase(temp); + } + } +} +void OysterResource::ReleaseResource(const wchar_t filename[]) +{ + OResource* t = resourcePrivate.FindResource(filename); + if(t) + { + if(OResource::Release(t)) + { + std::wstring temp = t->GetResourceFilename(); + delete resourcePrivate.resources[temp]; + resourcePrivate.resources.erase(temp); + } + } +} + +void OysterResource::SetResourceId (const OHRESOURCE& resourceData, unsigned int id) +{ + OResource* t = resourcePrivate.FindResource(resourceData); + + if(t) t->SetResourceID(id); +} +void OysterResource::SetResourceId(const wchar_t c[], unsigned int id) +{ + OResource* t = resourcePrivate.FindResource(c); + + if(t) t->SetResourceID(id); +} +ResourceType OysterResource::GetResourceType (const OHRESOURCE& resourceData) +{ + OResource* t = resourcePrivate.FindResource(resourceData); + + if(t) return t->GetResourceType(); + + return ResourceType_INVALID; +} +ResourceType OysterResource::GetResourceType (const wchar_t c[]) +{ + OResource* t = resourcePrivate.FindResource(c); + + if(t) return t->GetResourceType(); + + return ResourceType_INVALID; +} +const wchar_t* OysterResource::GetResourceFilename (const OHRESOURCE& resourceData) +{ + OResource* t = resourcePrivate.FindResource(resourceData); + + if(t) return t->GetResourceFilename(); + + return 0; +} +OHRESOURCE OysterResource::GetResourceHandle(const wchar_t filename[]) +{ + OResource* t = resourcePrivate.FindResource(filename); + + if(t) return t->GetResourceHandle(); + + return 0; +} +int OysterResource::GetResourceId (const OHRESOURCE& resourceData) +{ + OResource* t = resourcePrivate.FindResource(resourceData); + + if(t) return t->GetResourceID(); + + return -1; +} +int OysterResource::GetResourceId(const wchar_t c[]) +{ + OResource* t = resourcePrivate.FindResource(c); + + if(t) return t->GetResourceID(); + + return -1; +} + + + + + diff --git a/Code/Misc/Resource/ResourceManager.h b/Code/Misc/Resource/ResourceManager.h new file mode 100644 index 00000000..0b24b3e4 --- /dev/null +++ b/Code/Misc/Resource/ResourceManager.h @@ -0,0 +1,160 @@ +#ifndef MISC_RESOURCELOADER_H +#define MISC_RESOURCELOADER_H + +#include +#include + +namespace Oyster +{ + namespace Resource + { + struct ResourceData; + + typedef void* HRESOURCE; + /** Typedef on a fuction required for custom unloading */ + typedef void(*UnloadFunction)(void* loadedData); + + /** Typedef on a fuction required for custom loading */ + typedef void*(*LoadFunction)(const wchar_t filename[]); + + /** An enum class representing all avalible resources that is supported. */ + enum ResourceType + { + //Byte + ResourceType_Byte_Raw, /**< Handle can be interpeted as char[] or char* */ + ResourceType_Byte_ANSI, /**< Handle can be interpeted as char[] or char* */ + ResourceType_Byte_UTF8, /**< Handle can be interpeted as char[] or char* */ + ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */ + ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */ + + ResourceType_COUNT, /**< Handle can be interpeted as ? */ + + ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */ + ResourceType_INVALID = -2, /**< Invalid or non existing resource */ + }; + + /** A resource handler interface to interact with when loading resources. + * The resource handler uses the filename to make resources unuiqe. + */ + class ResourceManager + { + public: + ResourceManager(); + ~ResourceManager(); + ResourceManager(const ResourceManager&) = delete; + const ResourceManager& operator=(const ResourceManager&) = delete; + + /** + * Load a resource given a type. + * @param filename The path to the resource. + * @param customId An optional custom ID to associate with the resource. + * @param type The resource type to load. + * @param force If set to true, the resource will be reloaded if it already exists. If it does not, nothing happens. + * @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned. + */ + char* LoadBytes(const wchar_t filename[], ResourceType type, int customId = -1, bool force = false); + + /** + * Load a resource with a custom loading function + * @param filename The path to the resource. + * @param loadFnc The function that will load the data. + * @param unloadFnc The function that will unload the loaded data. + * @param customId An optional custom ID to associate with the resource. + * @param force If set to true, the resource will be removed and loaded if exists. + * @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned. + */ + HRESOURCE LoadResource(const wchar_t filename[], LoadFunction loadFnc = 0, UnloadFunction unloadFnc = 0, int customId = -1, bool force = false); + + /** + * Reload a resource + * @param filename The path to the resource. + * @return If function suceeds, the return value is true. + */ + bool ReloadResource(const wchar_t filename[]); + + /** + * Reload a resource + * @param filename The path to the resource. + * @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned. + */ + bool ReloadResource(HRESOURCE resource); + + /** + * Releases all resources loaded by the resource handler. + * @return Nothing + */ + void Clean(); + + /** + * Release a reference to the resource handle + * @param resource The handle to release. + * @return Nothing + */ + void ReleaseResource(const HRESOURCE& resource); + + /** + * Release a reference to the resource handle + * @param resource The resource filename to release reference. + * @return Nothing + */ + void ReleaseResource(const wchar_t filename[]); + + /** Set a user defined ID + * @param resource A handle to accociate the id with. + * @param id A user defined identifier that the resource handler does not touch. + */ + void SetResourceId(const HRESOURCE& resource, unsigned int id); + + /** Set a user defined ID + * If the resource is not loaded the id will not be set. + * @param resource A filename to accociate the id with. + * @param id A user defined identifier that the resource handler does not touch. + */ + void SetResourceId(const wchar_t filename[], unsigned int id); + + /** Get a resource type given a OHRESOURCE handle + * @param resource The handle to check + * @return Returns the resource type of the handle + */ + ResourceType GetResourceType(const HRESOURCE& resource); + + /** Get a resource type given a filename + * If the resource is not loaded the id will not be set. + * @param resource The filename to check + * @return Returns the resource type of the handle + */ + ResourceType GetResourceType (const wchar_t filename[]); + + /** Get a resource filename given a OHRESOURCE handle + * @param resource The handle to check + * @return Returns the accociated filename + */ + const wchar_t* GetResourceFilename(const HRESOURCE& resource); + + /** Get a resource handle given a filename + * If the resource is not loaded function returns 0. + * @param resource The filename to check + * @return Returns the accociated handle + */ + HRESOURCE GetResourceHandle(const wchar_t filename[]); + + /** Get a user defined ID accociated with a handle + * @param resource The handle to check + * @return Returns the accociated ID + */ + int GetResourceId(const HRESOURCE& resource); + + /** Get a user defined ID accociated with a filename + * @param resource The filename to check + * @return Returns the accociated ID + */ + int GetResourceId(const wchar_t filename[]); + + private: + std::map resources; + + }; + } +} + +#endif // !MISC_RESOURCELOADER_H diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp deleted file mode 100644 index d25a9adc..00000000 --- a/Code/Tester/MainTest.cpp +++ /dev/null @@ -1,253 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: TemplateMain.cpp -// -// BTH-D3D-Template -// -// Copyright (c) Stefan Petersson 2011. All rights reserved. -//-------------------------------------------------------------------------------------- -#define NOMINMAX -#include -#include -#include "DllInterfaces\GFXAPI.h" - - - -//-------------------------------------------------------------------------------------- -// Global Variables -//-------------------------------------------------------------------------------------- -HINSTANCE g_hInst = NULL; -HWND g_hWnd = NULL; -Oyster::Graphics::Model::Model* m = NULL; -Oyster::Graphics::Model::Model* m2 = NULL; -Oyster::Graphics::Model::Model* m3 = NULL; -Oyster::Math::Float4x4 V; -Oyster::Math::Float4x4 P; - - -//-------------------------------------------------------------------------------------- -// Forward declarations -//-------------------------------------------------------------------------------------- -HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -HRESULT Render(float deltaTime); -HRESULT Update(float deltaTime); -HRESULT InitDirect3D(); - - - - -//-------------------------------------------------------------------------------------- -// Entry point to the program. Initializes everything and goes into a message processing -// loop. Idle time is used to render the scene. -//-------------------------------------------------------------------------------------- -int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) -{ - - BOOL b = SetDllDirectoryW(L"..\\DLL"); - - if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) - return 0; - - if( FAILED( InitDirect3D() ) ) - return 0; - - __int64 cntsPerSec = 0; - QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec); - float secsPerCnt = 1.0f / (float)cntsPerSec; - - __int64 prevTimeStamp = 0; - QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); - - std::string fps = "FPS:"; - char count[100]; - // Main message loop - MSG msg = {0}; - float fpsCounter = 0; - while(WM_QUIT != msg.message) - { - if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - else - { - __int64 currTimeStamp = 0; - QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp); - float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt; - - //render - Update(dt); - Render(dt); - fpsCounter += dt; - if(fpsCounter>0.1f) - { - sprintf_s(count, "%f",1/dt); - SetWindowTextA(g_hWnd, (fps + count).c_str()); - fpsCounter = 0; - } - prevTimeStamp = currTimeStamp; - } - } - - Oyster::Graphics::API::DeleteModel(m); - Oyster::Graphics::API::DeleteModel(m2); - Oyster::Graphics::API::DeleteModel(m3); - Oyster::Graphics::API::Clean(); - return (int) msg.wParam; -} - -//-------------------------------------------------------------------------------------- -// Register class and create window -//-------------------------------------------------------------------------------------- -HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ) -{ - // Register class - WNDCLASSEX wcex; - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = 0; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = L"BTH_D3D_Template"; - wcex.hIconSm = 0; - if( !RegisterClassEx(&wcex) ) - return E_FAIL; - - // Adjust and create window - g_hInst = hInstance; - RECT rc = { 0, 0, 1024, 768 }; - AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); - - if(!(g_hWnd = CreateWindow( - L"BTH_D3D_Template", - L"BTH - Direct3D 11.0 Template", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - rc.right - rc.left, - rc.bottom - rc.top, - NULL, - NULL, - hInstance, - NULL))) - { - return E_FAIL; - } - - ShowWindow( g_hWnd, nCmdShow ); - - return S_OK; -} - - - -//-------------------------------------------------------------------------------------- -// Create Direct3D device and swap chain -//-------------------------------------------------------------------------------------- -HRESULT InitDirect3D() -{ - HRESULT hr = S_OK;; - - if(Oyster::Graphics::API::Init(g_hWnd,false,false, Oyster::Math::Float2( 1024, 768 )) == Oyster::Graphics::API::Fail) - { - return E_FAIL; - } - - m = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); - m2 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); - m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); - m3 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); - m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); - - - P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100); - Oyster::Graphics::API::SetProjection(P); - - V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,15.4f)); - V = V.GetInverse(); - - - Oyster::Graphics::Definitions::Pointlight pl; - pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; - pl.Pos = Oyster::Math::Float3(0,5,5.4f); - pl.Radius = 15; - - Oyster::Graphics::API::AddLight(pl); - - - return S_OK; -} -float angle = 0; -HRESULT Update(float deltaTime) -{ - - angle += Oyster::Math::pi/8 * deltaTime; - m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle); - m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null); - m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null); - return S_OK; -} - -HRESULT Render(float deltaTime) -{ - Oyster::Graphics::API::SetView(V); - Oyster::Graphics::API::NewFrame(); - - Oyster::Graphics::API::RenderModel(*m); - Oyster::Graphics::API::RenderModel(*m2); - Oyster::Graphics::API::RenderModel(*m3); - - Oyster::Graphics::API::EndFrame(); - - return S_OK; -} - -//-------------------------------------------------------------------------------------- -// Called every time the application receives a message -//-------------------------------------------------------------------------------------- -LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) -{ - PAINTSTRUCT ps; - HDC hdc; - - switch (message) - { - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - EndPaint(hWnd, &ps); - break; - - case WM_DESTROY: - PostQuitMessage(0); - break; - - case WM_KEYDOWN: - - switch(wParam) - { - case VK_ESCAPE: - PostQuitMessage(0); - break; - //R - case 0x52: -#ifdef _DEBUG - Oyster::Graphics::API::ReloadShaders(); -#endif - break; - } - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - - return 0; -} - diff --git a/Code/Tester/Tester.vcxproj b/Code/Tester/Tester.vcxproj deleted file mode 100644 index 3c61ce46..00000000 --- a/Code/Tester/Tester.vcxproj +++ /dev/null @@ -1,99 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3} - Win32Proj - Tester - - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - ..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories) - - - Windows - true - OysterGraphics_$(PlatformShortName)D.dll; - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - - - - {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} - - - {0ec83e64-230e-48ef-b08c-6ac9651b4f82} - - - {f10cbc03-9809-4cba-95d8-327c287b18ee} - - - - - - \ No newline at end of file diff --git a/Code/Tester/Tester.vcxproj.filters b/Code/Tester/Tester.vcxproj.filters deleted file mode 100644 index 5657bd66..00000000 --- a/Code/Tester/Tester.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/Code/Tester/Tester.vcxproj.user b/Code/Tester/Tester.vcxproj.user deleted file mode 100644 index 9a0b0ae0..00000000 --- a/Code/Tester/Tester.vcxproj.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - true - - \ No newline at end of file