From e8536cc5d4d97ba45dadf587ebe0d872e2206660 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 12 Feb 2014 13:11:35 +0100 Subject: [PATCH] GL - removed before collision event, sending look and right dir to server --- .../DanBiasGame/GameClientState/GameState.cpp | 13 ++-- Code/Game/GameLogic/CollisionManager.cpp | 17 +---- Code/Game/GameLogic/DynamicObject.cpp | 12 ++-- Code/Game/GameLogic/DynamicObject.h | 6 +- Code/Game/GameLogic/Game.h | 2 +- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 11 +-- Code/Game/GameLogic/JumpPad.cpp | 4 +- Code/Game/GameLogic/JumpPad.h | 1 - Code/Game/GameLogic/Level.cpp | 12 ++-- Code/Game/GameLogic/Level.h | 1 - Code/Game/GameLogic/Object.cpp | 10 +-- Code/Game/GameLogic/Object.h | 7 +- Code/Game/GameLogic/Player.cpp | 23 ++++--- Code/Game/GameLogic/Player.h | 10 +-- Code/Game/GameLogic/StaticObject.cpp | 12 ++-- Code/Game/GameLogic/StaticObject.h | 6 +- Code/Game/GameProtocols/ObjectProtocols.h | 2 +- Code/Game/GameProtocols/PlayerProtocols.h | 68 ++++++++++++------- .../Implementation/GameSession_Gameplay.cpp | 10 ++- 20 files changed, 110 insertions(+), 119 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 5c620021..8eff1be2 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -449,15 +449,12 @@ void GameState::readKeyInput(InputClass* KeyInput) camera->Yaw(-KeyInput->GetYaw()); camera->Pitch(KeyInput->GetPitch()); pitch = KeyInput->GetPitch(); - camera->UpdateViewMatrix(); - GameLogic::Protocol_PlayerLook playerLookDir; - Oyster::Math::Float4 look = camera->GetRight(); - playerLookDir.lookDirX = look.x; - playerLookDir.lookDirY = look.y; - playerLookDir.lookDirZ = look.z; - playerLookDir.deltaX = -KeyInput->GetYaw(); + camera->UpdateViewMatrix(); + Oyster::Math::Float3 look = camera->GetLook(); + Oyster::Math::Float3 right = camera->GetRight(); + GameLogic::Protocol_PlayerLook playerLook(look, right); - privData->nwClient->Send(playerLookDir); + privData->nwClient->Send(playerLook); } // shoot diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 27949cc9..0ef2a204 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -38,7 +38,7 @@ using namespace GameLogic; break; case OBJECT_TYPE::OBJECT_TYPE_WORLD: PlayerVObject(*player,*realObj, kineticEnergyLoss); - player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; + //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } @@ -89,28 +89,15 @@ using namespace GameLogic; } } - Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) - { - return Physics::ICustomBody::SubscriptMessage_none; - } + Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; } - Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) - { - return Physics::ICustomBody::SubscriptMessage_player_collision_response; - } Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; } - //Oyster::Physics::ICustomBody::SubscriptMessage - Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) - { - return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; - } - Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::IgnoreCollision(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody *obj) { return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 437dca2c..05a4138d 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -20,18 +20,18 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYP } -DynamicObject::DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :Object(collisionFuncBefore,collisionFuncAfter,type) +DynamicObject::DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type) + :Object(collisionFuncAfter,type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) + :Object(rigidBody, collisionFuncAfter, type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) - :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) + :Object(rigidBody, collisionFuncAfter, type) { } diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 3fcdae39..815875b3 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -16,9 +16,9 @@ namespace GameLogic DynamicObject(); DynamicObject(OBJECT_TYPE type); DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); ~DynamicObject(void); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 601b0f0c..d88ddd7b 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -41,7 +41,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; OBJECT_TYPE GetObjectType() const override; - void Rotate(const Oyster::Math3D::Float4 lookDir) override; + void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; Player *player; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index d51cf4a6..79656878 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -83,7 +83,7 @@ namespace GameLogic * @param x: The relative x axis * @param y: The relative y axis **/ - virtual void Rotate(const Oyster::Math3D::Float4 lookDir) = 0; + virtual void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) = 0; /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 908dd42f..56df13c4 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -18,13 +18,8 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body - this->player = new Player(rigidBody,Level::LevelCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); - - //Oyster::Physics::ICustomBody::State state; - //this->player->GetRigidBody()->GetState(state); - ////state.SetRotation(Oyster::Math::Float3(0, Oyster::Math::pi, 0)); - //this->player->GetRigidBody()->SetState(state); player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) @@ -77,7 +72,7 @@ OBJECT_TYPE Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } -void Game::PlayerData::Rotate(const Oyster::Math3D::Float4 lookDir) +void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) { - this->player->Rotate(lookDir); + this->player->Rotate(lookDir, right); } \ No newline at end of file diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp index c60e248c..15b80dc8 100644 --- a/Code/Game/GameLogic/JumpPad.cpp +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -8,8 +8,8 @@ JumpPad::JumpPad(void) { } -JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) - :StaticObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) + :StaticObject(rigidBody, collisionFuncAfter, type) { } diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h index b9fe2253..8d645a00 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -9,7 +9,6 @@ namespace GameLogic JumpPad(void); JumpPad(Oyster::Physics::ICustomBody *rigidBody - ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter) ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index e7b10eac..04324fcc 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -82,7 +82,7 @@ void Level::InitiateLevel(std::string levelPath) // add rigidbody to the logical obj // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this // set object_type to objID - this->staticObjects.Push(new StaticObject(rigidBody,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->staticObjects.Push(new StaticObject(rigidBody, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->staticObjects[staticObjCount]->objectID = modelCount++; rigidBody->SetCustomTag(this->staticObjects[staticObjCount]); @@ -97,7 +97,7 @@ void Level::InitiateLevel(std::string levelPath) rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); } @@ -117,7 +117,7 @@ void Level::InitiateLevel(float radius) int idCount = 100; // add level sphere ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); + levelObj = new StaticObject(rigidBody, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); this->levelObj->objectID = idCount++; rigidBody->SetCustomTag(levelObj); @@ -130,7 +130,7 @@ void Level::InitiateLevel(float radius) { rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects[i]->objectID = idCount++; rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); } @@ -168,7 +168,7 @@ void Level::InitiateLevel(float radius) // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); this->dynamicObjects[nrOfBoxex]->objectID = idCount++; @@ -176,7 +176,7 @@ void Level::InitiateLevel(float radius) // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); rigidBody_House->SetCustomTag(this->staticObjects[0]); this->staticObjects[0]->objectID = idCount++; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 581d1ee0..15f4a832 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -60,7 +60,6 @@ namespace GameLogic * @param rigidBodyLevel: physics object of the level * @param obj: physics object for the object that collided with the level ********************************************************/ - static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); int getNrOfDynamicObj(); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 78141e5f..631ae1b7 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -36,7 +36,7 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) this->objectID = GID(); } -Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) { this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); @@ -44,18 +44,18 @@ Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) { this->rigidBody = rigidBody; - + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) { this->rigidBody = rigidBody; - + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; this->objectID = GID(); } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 293ba85d..677aef13 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -20,9 +20,9 @@ namespace GameLogic Object(); Object(OBJECT_TYPE type); Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Object(void* collisionFuncAfter, OBJECT_TYPE type); + Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); + Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); ~Object(void); OBJECT_TYPE GetObjectType() const override; @@ -43,7 +43,6 @@ namespace GameLogic void setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)); void setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)); - static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); public: //HACK: This should be private when level is dynamic diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 31a436bf..f6267876 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -7,7 +7,7 @@ using namespace GameLogic; using namespace Oyster::Physics; const int MOVE_FORCE = 30; -const float KEY_TIMER = 0.04f; +const float KEY_TIMER = 0.03f; Player::Player() :DynamicObject() { @@ -23,18 +23,18 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) { InitPlayer(); } -Player::Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :DynamicObject(collisionFuncBefore,collisionFuncAfter,type) +Player::Player( void* collisionFuncAfter, OBJECT_TYPE type) + :DynamicObject(collisionFuncAfter,type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) + :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) - :DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) + :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); } @@ -74,7 +74,7 @@ void Player::BeginFrame() Oyster::Math::Float3 moveDirection(0,0,0); if (key_forward > 0.001) { - key_forward -= gameInstance->GetFrameTime(); + key_forward -= gameInstance->GetFrameTime(); // fixed timer forward = this->rigidBody->GetState().GetOrientation().v[2].GetNormalized(); } if (key_backward > 0.001) @@ -160,19 +160,20 @@ void Player::UseWeapon(const WEAPON_FIRE &usage) void Player::Respawn(Oyster::Math::Float3 spawnPoint) { + key_jump = this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); this->rigidBody->SetPosition(spawnPoint); } -void Player::Rotate(const Oyster::Math3D::Float4 lookDir) +void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) { // this is the camera right vector - this->lookDir = lookDir.xyz; + this->lookDir = lookDir; Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; - this->rigidBody->SetUpAndRight(up, lookDir.xyz); + this->rigidBody->SetUpAndRight(up, right); this->rigidBody->SetUpAndRight(this->rigidBody->GetState().centerPos.GetNormalized(), this->rigidBody->GetState().GetOrientation().v[0].xyz.GetNormalized()); } diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index bb00c23b..d2adb4be 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -18,9 +18,9 @@ namespace GameLogic Player(void); Player(OBJECT_TYPE type); Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Player( void* collisionFuncAfter, OBJECT_TYPE type); + Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); + Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); ~Player(void); void InitPlayer(); @@ -48,7 +48,7 @@ namespace GameLogic void Respawn(Oyster::Math::Float3 spawnPoint); - void Rotate(const Oyster::Math3D::Float4 lookDir); + void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -73,7 +73,6 @@ namespace GameLogic void BeginFrame(); void EndFrame(); - static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); @@ -91,6 +90,7 @@ namespace GameLogic float key_backward; float key_strafeRight; float key_strafeLeft; + float key_jump; bool hasTakenDamage; float invincibleCooldown; diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 65cc0577..12725595 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -22,18 +22,18 @@ StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); } -StaticObject::StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :Object(collisionFuncBefore,collisionFuncAfter,type) +StaticObject::StaticObject( void* collisionFuncAfter, OBJECT_TYPE type) + :Object(collisionFuncAfter,type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) - :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) + :Object(rigidBody, collisionFuncAfter, type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) - :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) + :Object(rigidBody, collisionFuncAfter, type) { } diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index c51f93a1..585594e6 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -18,9 +18,9 @@ namespace GameLogic StaticObject(); StaticObject(OBJECT_TYPE type); StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + StaticObject( void* collisionFuncAfter, OBJECT_TYPE type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); ~StaticObject(void); diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 6dd32d62..f265141d 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -326,7 +326,7 @@ namespace GameLogic this->rotation[2] = p[7].value.netFloat; this->rotation[3] = p[8].value.netFloat; } - Protocol_ObjectPositionRotation(float p[3], float r[3], int id) + Protocol_ObjectPositionRotation(float p[3], float r[4], int id) { this->protocol[0].value = protocol_Gameplay_ObjectPositionRotation; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index a3c3501e..b7d79d6c 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -76,12 +76,37 @@ namespace GameLogic struct Protocol_PlayerLook :public Oyster::Network::CustomProtocolObject { - float lookDirX; - float lookDirY; - float lookDirZ; - float deltaX; + // can be swapped to a quaternion later + float lookDir[3]; + float right[3]; Protocol_PlayerLook() + { + this->protocol[0].value = protocol_Gameplay_PlayerLookDir; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + // LookDir + this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + // Right + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->protocol[5].type = Oyster::Network::NetAttributeType_Float; + this->protocol[6].type = Oyster::Network::NetAttributeType_Float; + + memset(&this->lookDir[0], 0, sizeof(float) * 3); + memset(&this->right[0], 0, sizeof(float) * 3); + } + Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p) + { + this->lookDir[0] = p[1].value.netFloat; + this->lookDir[1] = p[2].value.netFloat; + this->lookDir[2] = p[3].value.netFloat; + + this->right[0] = p[4].value.netFloat; + this->right[1] = p[5].value.netFloat; + this->right[2] = p[6].value.netFloat; + } + Protocol_PlayerLook(float l[3], float r[3]) { this->protocol[0].value = protocol_Gameplay_PlayerLookDir; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; @@ -89,32 +114,23 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - - } - Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p) - { - lookDirX = p[1].value.netFloat; - lookDirY = p[2].value.netFloat; - lookDirZ = p[3].value.netFloat; - deltaX = p[4].value.netFloat; - } - const Protocol_PlayerLook& operator=(Oyster::Network::CustomNetProtocol& val) - { - lookDirX = val[1].value.netFloat; - lookDirY = val[2].value.netFloat; - lookDirZ = val[3].value.netFloat; - deltaX = val[4].value.netFloat; - return *this; + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->protocol[5].type = Oyster::Network::NetAttributeType_Float; + this->protocol[6].type = Oyster::Network::NetAttributeType_Float; + + memcpy(&this->lookDir[0], &l[0], sizeof(float) * 3); + memcpy(&this->right[0], &r[0], sizeof(float) * 3); } + Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = lookDirX; - this->protocol[2].value = lookDirY; - this->protocol[3].value = lookDirZ; - this->protocol[4].value = deltaX; - + this->protocol[1].value = this->lookDir[0]; + this->protocol[2].value = this->lookDir[1]; + this->protocol[3].value = this->lookDir[2]; + this->protocol[4].value = this->right[0]; + this->protocol[5].value = this->right[1]; + this->protocol[6].value = this->right[2]; return protocol; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 9fed11f2..66893573 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -186,12 +186,10 @@ namespace DanBias } void GameSession::Gameplay_PlayerLookDir ( Protocol_PlayerLook& p, DanBias::GameClient* c ) { - Oyster::Math3D::Float4 lookDir; - lookDir.x = p.lookDirX; - lookDir.y = p.lookDirY; - lookDir.z = p.lookDirZ; - lookDir.w = p.deltaX; - c->GetPlayer()->Rotate(lookDir); + Oyster::Math3D::Float3 lookDir = p.lookDir; + Oyster::Math3D::Float3 right = p.right; + + c->GetPlayer()->Rotate(lookDir, right); } void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) {