From 47e6d9395715e924a74c45c13f9c60312954f7c0 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 25 Feb 2014 18:25:51 +0100 Subject: [PATCH 1/4] Fixed player going bonkers on lower hemisphere --- Code/Game/GameLogic/Player.cpp | 8 +-- .../Implementation/SimpleRigidBody.cpp | 70 +++++++++++-------- .../Implementation/SimpleRigidBody.h | 2 +- Code/Physics/GamePhysics/PhysicsAPI.h | 2 +- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 7166f539..7da6fde5 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -80,13 +80,9 @@ void Player::BeginFrame() Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly + this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); - Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotation(secondTurn*firstUp); - // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); @@ -272,7 +268,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - this->rotationUp += deltaRadians; + this->rotationUp = deltaRadians; } void Player::Jump() diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 25c57e3b..9b9c7739 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -163,25 +163,15 @@ void SimpleRigidBody::SetRotation(::Oyster::Math::Float4x4 rotation) this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); } -void SimpleRigidBody::SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis) +void SimpleRigidBody::AddRotationAroundY(::Oyster::Math::Float angle) { - if(angularAxis.xyz.GetMagnitude() == 0) - { - return; - } - - float s = sin(angularAxis.w/2); - float x = angularAxis.x * s; - float y = angularAxis.y * s; - float z = angularAxis.z * s; - float w = cos(angularAxis.w/2); - btTransform trans; - btVector3 vector(angularAxis.x, angularAxis.y, angularAxis.z); - btQuaternion quaternion(x,y,z,w); + btQuaternion quaternion; trans = this->rigidBody->getWorldTransform(); - trans.setRotation(quaternion); + + quaternion = btQuaternion(trans.getBasis().getColumn(1), angle); + trans.setRotation(quaternion*trans.getRotation()); this->rigidBody->setWorldTransform(trans); this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); @@ -245,23 +235,45 @@ void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math: void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up) { - Float3 vector = Float3(0, 1, 0).Cross(up); - - if(vector == Float3::null) - { - return; - } - - Float sine = vector.GetLength(); - Float cosine = acos(Float3(0, 1, 0).Dot(up)); - - btQuaternion quaternion(btVector3(vector.x, vector.y, vector.z),cosine); - + btQuaternion newRotation; btTransform trans; trans = this->rigidBody->getWorldTransform(); - trans.setRotation(quaternion); + + btVector3 v1 = trans.getBasis().getColumn(1); + btVector3 v2(up.x, up.y, up.z); + + btQuaternion q; + btVector3 a = v1.cross(v2); + + if (v1.dot(v2) < -0.999999) + { + btVector3 xCrossPre = btVector3(1, 0 ,0).cross(v1); + if(xCrossPre.length() < 0.000001) + xCrossPre = btVector3(0, 1 ,0).cross(v1); + xCrossPre.normalize(); + q.setRotation(xCrossPre, 3.1415); + } + else if (v1.dot(v2) > 0.999999) + { + q = btQuaternion(0, 0, 0, 1); + } + else + { + q.setX(a.x()); + q.setY(a.y()); + q.setZ(a.z()); + + q.setW(1 + v1.dot(v2)); + + q.normalize(); + } + + newRotation = q*trans.getRotation(); + + trans.setRotation(newRotation); this->rigidBody->setWorldTransform(trans); - this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); + + this->state.quaternion = Quaternion(Float3(newRotation.x(), newRotation.y(), newRotation.z()), newRotation.w()); } Float4x4 SimpleRigidBody::GetRotation() const diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index f3e7e0c6..65c59820 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -29,7 +29,7 @@ namespace Oyster void SetRotation(Math::Quaternion quaternion); void SetRotation(Math::Float3 eulerAngles); void SetRotation(::Oyster::Math::Float4x4 rotation); - void SetRotationAsAngularAxis(Math::Float4 angularAxis); + void AddRotationAroundY(Math::Float angle); void SetAngularFactor(Math::Float factor); void SetMass(Math::Float mass); diff --git a/Code/Physics/GamePhysics/PhysicsAPI.h b/Code/Physics/GamePhysics/PhysicsAPI.h index 33dc24a8..a536bdce 100644 --- a/Code/Physics/GamePhysics/PhysicsAPI.h +++ b/Code/Physics/GamePhysics/PhysicsAPI.h @@ -147,7 +147,7 @@ namespace Oyster virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0; virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0; virtual void SetRotation(::Oyster::Math::Float4x4 rotation) = 0; - virtual void SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis) = 0; + virtual void AddRotationAroundY(::Oyster::Math::Float angle) = 0; virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0; virtual void SetMass(::Oyster::Math::Float mass) = 0; From ca693c412f504e3341757aef4260b23acda8b50f Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 26 Feb 2014 08:51:18 +0100 Subject: [PATCH 2/4] Player air check function --- Code/Game/GameLogic/Player.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 7da6fde5..508067a4 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -129,7 +129,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f) + if(key_jump <= 0.001 && IsWalking()) { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -147,7 +147,7 @@ void Player::BeginFrame() walkDirection.Normalize(); // If on the ground, accelerate normally - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { if(forwardSpeed < maxSpeed) { @@ -159,7 +159,7 @@ void Player::BeginFrame() } } // If in the air, accelerate slower - if(this->rigidBody->GetLambda() >= 0.9f) + if(IsJumping()) { if(forwardSpeed < maxSpeed) { @@ -183,15 +183,13 @@ void Player::BeginFrame() if(key_jump > 0.001) { this->key_jump -= this->gameInstance->GetFrameTime(); - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } - - //this->weapon->Update(0.01f); @@ -278,15 +276,15 @@ void Player::Jump() bool Player::IsWalking() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); + return (this->rigidBody->GetLambda() < 0.99f); } bool Player::IsJumping() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); + return (this->rigidBody->GetLambda() < 1.0f); } bool Player::IsIdle() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); + return (this->rigidBody->GetLambda() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); } void Player::Inactivate() From 4d077106dcf9195fc3822f0f0a9bd0391b3b639d Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 08:51:56 +0100 Subject: [PATCH 3/4] Weapon action enum added --- Code/Game/LevelLoader/ObjectDefines.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index aadc3382..3eae71a5 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -99,6 +99,11 @@ namespace GameLogic PlayerAction_Walk, PlayerAction_Idle, }; + enum WeaponAction + { + WeaponAtcion_PrimaryShoot, + WeaponAction_SecondaryShoot + }; enum PickupType { From 13d6a062fc58cc9c801bfd94fa133bed4f11ce08 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 10:05:07 +0100 Subject: [PATCH 4/4] Added collision and weapon events and send them to client --- .../GameClient/GameClientState/GameState.cpp | 31 +++++++++++++ Code/Game/GameLogic/AttatchmentMassDriver.cpp | 10 ++++- Code/Game/GameLogic/CollisionManager.cpp | 3 +- Code/Game/GameLogic/Game.cpp | 4 ++ Code/Game/GameLogic/Game.h | 2 + Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/Level.cpp | 42 ++++++++++++------ Code/Game/GameProtocols/ObjectProtocols.h | 44 ++++++++++++++++++- .../GameProtocols/ProtocolIdentificationID.h | 1 + Code/Game/GameServer/GameSession.h | 1 + .../Implementation/GameSession_Gameplay.cpp | 5 +++ .../Implementation/GameSession_General.cpp | 1 + Code/Game/LevelLoader/ObjectDefines.h | 20 ++++++--- 13 files changed, 143 insertions(+), 24 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..c5dd45c5 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -750,6 +750,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; + + case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_Reload: + break; + + default: break; } @@ -757,6 +766,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectCollision: + { + Protocol_ObjectCollision decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + if( object ) + { + switch (decoded.collisionID) + { + case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: + break; + default: + break; + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 62f3599e..13ef8fef 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,7 +1,7 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" #include "GameLogicStates.h" - +#include "Game.h" using namespace GameLogic; @@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForcePush(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } break; @@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(currentEnergy >= 1.0f) { currentEnergy -= 1.0f; - ForcePull(usage,dt); + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); } break; @@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForceZip(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } break; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..72057e2b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -69,7 +69,8 @@ using namespace GameLogic; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } - + // send collision event message + ((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision); //return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 5879bd86..87216b3b 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { this->onPickupEventFnc = functionPointer; } +void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) +{ + this->onCollisionEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index abef28f4..28ad9772 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -87,6 +87,7 @@ namespace GameLogic void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; + void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -108,6 +109,7 @@ namespace GameLogic GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; + GameEvent::CollisionEventFunction onCollisionEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 653fc26b..80b255bd 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -33,6 +33,7 @@ namespace GameLogic typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer + typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); //etc... }; @@ -188,7 +189,7 @@ namespace GameLogic virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; - + virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..40a2b55a 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,6 +16,7 @@ using namespace Oyster::Math; Level::Level(void) { + srand (time(NULL)); objID = 100; } Level::~Level(void) @@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (!this->playerObjects[i]) + { + this->playerObjects[i] = player; + return; + } + } + // if no free space, allocate a new spot this->playerObjects.Push(player); } void Level::RemovePlayerFromGame(Player *player) @@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player) { if ((Player*)this->playerObjects[i] == player) { - //this->playerObjects[i]. + this->playerObjects[i] = nullptr; } } } @@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player) { //this->teamManager.RespawnPlayerRandom(player); - Float3 spawnPoint = spawnPoints[0]; + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; player->Respawn(spawnPoint); } void Level::Update(float deltaTime) @@ -434,19 +445,22 @@ void Level::Update(float deltaTime) // update lvl-things for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + if(this->playerObjects[i]) { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); - } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) - { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 48fa71f7..9b469bbc 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -969,7 +969,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 369 + //#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -1010,4 +1010,46 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectCollision 370 + struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject + { + short objectID; + int collisionID; + // TODO: maybe position, impact, and velocity + + Protocol_ObjectCollision() + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = -1; + this->collisionID = -1; + } + Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netShort; + this->collisionID = p[2].value.netInt; + } + Protocol_ObjectCollision( int id, int collisionID) + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = id; + this->collisionID = collisionID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = collisionID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 95e10ba1..f4f2b136 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -72,6 +72,7 @@ #define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectAction 369 +#define protocol_Gameplay_ObjectCollision 370 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 79b50395..d449ff2d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -105,6 +105,7 @@ namespace DanBias static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); + static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..218721be 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -176,6 +176,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } + void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ca869fb7..d19fcecf 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); + this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 3eae71a5..e77174f7 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -95,16 +95,26 @@ namespace GameLogic enum PlayerAction { - PlayerAction_Jump, - PlayerAction_Walk, - PlayerAction_Idle, + PlayerAction_Jump = 0, + PlayerAction_Walk = 1, + PlayerAction_Idle = 2, }; + // continue ID counting from playerAction enum WeaponAction { - WeaponAtcion_PrimaryShoot, - WeaponAction_SecondaryShoot + WeaponAction_PrimaryShoot = 3, + WeaponAction_SecondaryShoot = 4, + WeaponAction_UtilityActivate = 5, + WeaponAction_Reload = 6, + WeaponAction_EnergyDepleted = 7, + }; + // TODO: add more collision Events + enum CollisionEvent + { + CollisionEvent_BasicCollision, + }; enum PickupType { PickupType_Health,