Merge remote-tracking branch 'origin/GameLogic' into GameClient

This commit is contained in:
lindaandersson 2014-02-21 15:42:21 +01:00
commit 4f838bb39e
12 changed files with 100 additions and 50 deletions

View File

@ -62,6 +62,8 @@ bool LanMenuState::Init( SharedStateContent &shared )
this->privData->connectIP->ReserveLines( 1 ); this->privData->connectIP->ReserveLines( 1 );
this->privData->connectIP->AppendText( L"127.0.0.1" ); this->privData->connectIP->AppendText( L"127.0.0.1" );
//this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server //this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
//this->privData->connectIP->AppendText( L"194.47.150.189" ); // HACK: connecting to Robins server
this->privData->connectIP->SetFontHeight( 0.08f ); this->privData->connectIP->SetFontHeight( 0.08f );
this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetLineSpacing( 0.005f );
this->privData->connectIP->SetTopAligned(); this->privData->connectIP->SetTopAligned();

View File

@ -56,19 +56,14 @@ void AttatchmentMassDriver::Update(float dt)
//update position of heldObject if there is an object being held //update position of heldObject if there is an object being held
if(hasObject) if(hasObject)
{ {
//Oyster::Physics::ICustomBody::State state;
//state = heldObject->GetState();
Oyster::Math::Float3 ownerPos = owner->GetPosition(); Oyster::Math::Float3 ownerPos = owner->GetPosition();
Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState(); Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState();
Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2]; Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2];
up *= -0.3f; up *= -0.3f;
Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5); Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*2);
//state.centerPos = pos;
heldObject->SetPosition(pos); heldObject->SetPosition(pos);
heldObject->SetLinearVelocity(Oyster::Math::Float3::null); heldObject->SetLinearVelocity(Oyster::Math::Float3::null);
//heldObject->SetState(state);
} }
} }
@ -149,7 +144,7 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt)
{ {
Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*5; Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*2;
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,10); Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,10);
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp);

View File

@ -108,13 +108,31 @@ using namespace GameLogic;
obj.SetPosition(target); obj.SetPosition(target);
} }
void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss)
{ {
int forceThreashHold = 200000; //how much force for the box to explode of the impact
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed? Object *realObjA = ((Object*)(objA->GetCustomTag()));
Object *realObjB = (Object*)objB->GetCustomTag(); //needs to be changed?
ExplosiveCrate* crate;
switch (realObj->GetObjectType()) if(!realObjA)
return;
if(!realObjB)
return;
//check who is player and who is the object
if(realObjA->GetObjectType() == ObjectSpecialType::ObjectSpecialType_RedExplosiveBox)
{
crate = (ExplosiveCrate*)realObjA;
}
else
{
crate = (ExplosiveCrate*)realObjB;
realObjB = realObjA;
}
switch (realObjB->GetObjectType())
{ {
case ObjectSpecialType::ObjectSpecialType_Generic: case ObjectSpecialType::ObjectSpecialType_Generic:
break; break;
@ -122,29 +140,15 @@ using namespace GameLogic;
break; break;
case ObjectSpecialType::ObjectSpecialType_Player: case ObjectSpecialType::ObjectSpecialType_Player:
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); if(crate->hasExploaded) return;
Oyster::Math::Float3 pos = crate->GetRigidBody()->GetState().centerPos;
Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos;
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius); Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius);
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
crate->hasExploaded = true;
delete hitSphere; delete hitSphere;
break; break;
} }
/*if(kineticEnergyLoss > forceThreashHold)
{
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag());
Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos;
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius);
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
delete hitSphere;
}*/
} }
void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args) void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args)
@ -155,16 +159,17 @@ using namespace GameLogic;
Oyster::Math::Float3 explosionCenterPos = ExplosionSource->GetPosition(); Oyster::Math::Float3 explosionCenterPos = ExplosionSource->GetPosition();
Oyster::Math::Float3 hitObjectPos = obj->GetState().centerPos; Oyster::Math::Float3 hitObjectPos = obj->GetState().centerPos;
Oyster::Math::Float3 force = (((hitObjectPos- explosionCenterPos).GetNormalized()) * ExplosionSource->pushForceMagnitude); Oyster::Math::Float3 force = (((hitObjectPos- explosionCenterPos).GetNormalized()) * ExplosionSource->pushForceMagnitude);
if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player) if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player)
{ {
Player *hitPlayer = (Player*)realObj; Player *hitPlayer = (Player*)realObj;
//hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); //hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
hitPlayer->GetRigidBody()->ApplyImpulse(force);
//do shredding damage //do shredding damage
} }
realObj->GetRigidBody()->ApplyImpulse(force);
} }
@ -173,16 +178,32 @@ using namespace GameLogic;
//Collision between a player and a general static or dynamic object //Collision between a player and a general static or dynamic object
//use kinetic energyloss of the collision in order too determin how much damage to take //use kinetic energyloss of the collision in order too determin how much damage to take
//use as part of the damage algorithm //use as part of the damage algorithm
//Oyster::Math::Float3 prevVel = obj.GetRigidBody()->GetState().prev Oyster::Math::Float3 objPrevVel = obj.GetRigidBody()->GetState().previousVelocity;
Oyster::Math::Float3 playerPrevVel = player.GetRigidBody()->GetState().previousVelocity;
Oyster::Math::Float3 deltaPos = (player.GetPosition() - obj.GetPosition());
Oyster::Math::Float deltaSpeed = (objPrevVel - playerPrevVel).GetMagnitude();
Oyster::Math::Float angularFactor = deltaPos.GetNormalized().Dot( (objPrevVel - playerPrevVel).GetNormalized());
Oyster::Math::Float impactPower = deltaSpeed * angularFactor;
Oyster::Math::Float damageFactor = 0.01f;
int damageDone = 0; int damageDone = 0;
int forceThreashHold = 200000; int forceThreashHold = 30; //FIX: balance this
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough if(impactPower > forceThreashHold) //should only take damage if the force is high enough
{ {
damageDone = (int)(kineticEnergyLoss * 0.10f); if(obj.GetRigidBody()->GetState().mass == 0)
//player.DamageLife(damageDone); {
damageDone = impactPower * damageFactor;
}
else
{
damageDone = (impactPower * obj.GetRigidBody()->GetState().mass)* damageFactor;
}
player.DamageLife(damageDone);
} }
} }

View File

@ -7,6 +7,7 @@ ExplosiveCrate::ExplosiveCrate(void)
{ {
this->pushForceMagnitude = 0; this->pushForceMagnitude = 0;
this->ExplosionRadius = 0; this->ExplosionRadius = 0;
this->hasExploaded = false;
} }
ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float extraDamageOnCollision, Oyster::Math::Float pushForceMagnitude, Oyster::Math::Float ExplosionRadius) ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float extraDamageOnCollision, Oyster::Math::Float pushForceMagnitude, Oyster::Math::Float ExplosionRadius)
@ -15,6 +16,7 @@ ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpe
this->extraDamageOnCollision = extraDamageOnCollision; this->extraDamageOnCollision = extraDamageOnCollision;
this->pushForceMagnitude = pushForceMagnitude; this->pushForceMagnitude = pushForceMagnitude;
this->ExplosionRadius = ExplosionRadius; this->ExplosionRadius = ExplosionRadius;
this->hasExploaded = false;
} }
ExplosiveCrate::~ExplosiveCrate(void) ExplosiveCrate::~ExplosiveCrate(void)

View File

@ -18,6 +18,7 @@ namespace GameLogic
private: private:
Oyster::Math::Float pushForceMagnitude; Oyster::Math::Float pushForceMagnitude;
Oyster::Math::Float ExplosionRadius; Oyster::Math::Float ExplosionRadius;
bool hasExploaded;
}; };

View File

@ -70,8 +70,8 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
case ObjectSpecialType_RedExplosiveBox: case ObjectSpecialType_RedExplosiveBox:
{ {
Oyster::Math::Float dmg = 50; Oyster::Math::Float dmg = 50;
Oyster::Math::Float force = 50; Oyster::Math::Float force = 500;
Oyster::Math::Float radie = 50; Oyster::Math::Float radie = 3;
gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie);
} }
break; break;

View File

@ -90,7 +90,7 @@ using namespace DanBias;
{ {
for (unsigned int i = 0; i < this->gClients.Size(); i++) for (unsigned int i = 0; i < this->gClients.Size(); i++)
{ {
if(this->gClients[i] ) if(this->gClients[i] && !this->gClients[i]->IsInvalid())
{ {
this->gClients[i]->UpdateClient(); this->gClients[i]->UpdateClient();
} }
@ -101,7 +101,7 @@ using namespace DanBias;
bool returnValue = false; bool returnValue = false;
for (unsigned int i = 0; i < this->gClients.Size(); i++) for (unsigned int i = 0; i < this->gClients.Size(); i++)
{ {
if(this->gClients[i]) if(this->gClients[i] && !this->gClients[i]->IsInvalid())
{ {
this->gClients[i]->GetClient()->Send(message); this->gClients[i]->GetClient()->Send(message);
returnValue = true; returnValue = true;
@ -115,7 +115,7 @@ using namespace DanBias;
{ {
for (unsigned int i = 0; i < this->gClients.Size(); i++) for (unsigned int i = 0; i < this->gClients.Size(); i++)
{ {
if(this->gClients[i] && this->gClients[i]->GetClient()->GetID() == ID) if(this->gClients[i] && !this->gClients[i]->IsInvalid() && this->gClients[i]->GetClient()->GetID() == ID)
{ {
this->gClients[i]->GetClient()->Send(protocol); this->gClients[i]->GetClient()->Send(protocol);
return true; return true;

View File

@ -36,8 +36,8 @@ GameSession::GameSession()
this->isCreated = false; this->isCreated = false;
this->isRunning = false; this->isRunning = false;
this->gameSession = this; this->gameSession = this;
this->logicFrameTime = DELTA_TIME_20; this->logicFrameTime = DELTA_TIME_60;
this->networkFrameTime = DELTA_TIME_20; this->networkFrameTime = DELTA_TIME_60;
this->networkTimer.reset(); this->networkTimer.reset();
this->logicTimer.reset(); this->logicTimer.reset();

View File

@ -32,7 +32,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
GameServerAPI::GameSetGameMode(L"free-for-all"); GameServerAPI::GameSetGameMode(L"free-for-all");
GameServerAPI::GameSetGameName(L"DebugServer"); GameServerAPI::GameSetGameName(L"DebugServer");
GameServerAPI::GameSetGameTime(15); GameServerAPI::GameSetGameTime(15);
GameServerAPI::GameSetMapName(L"2ofAll.bias"); GameServerAPI::GameSetMapName(L"erik_250.bias");
GameServerAPI::GameSetMaxClients(10); GameServerAPI::GameSetMaxClients(10);
if(GameServerAPI::GameStart(true)) if(GameServerAPI::GameStart(true))

View File

@ -288,10 +288,10 @@ void API_Impl::UpdateWorld()
{ {
this->customBodies[i]->CallSubscription_Move(); this->customBodies[i]->CallSubscription_Move();
} }
simpleBody->SetPreviousVelocity(simpleBody->GetState().previousVelocity); simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity());
} }
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep); this->dynamicsWorld->stepSimulation(this->timeStep, 10, this->timeStep);
ICustomBody::State state; ICustomBody::State state;
@ -314,8 +314,33 @@ void API_Impl::UpdateWorld()
ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer(); ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer();
ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer(); ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer();
bodyA->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
bodyB->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
if(bodyA->GetState().mass == 40 && bodyB->GetState().centerPos == Float3::null)
{
const char* breakPoint = "STOP";
}
if(bodyB->GetState().mass == 40 && bodyA->GetState().centerPos == Float3::null)
{
const char* breakPoint = "STOP";
}
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
bodyA->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
bodyB->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
}
}
} }
} }

View File

@ -22,6 +22,8 @@ SimpleRigidBody::SimpleRigidBody()
this->state.restitutionCoeff = 0.0f; this->state.restitutionCoeff = 0.0f;
this->state.reach = Float3(0.0f, 0.0f, 0.0f); this->state.reach = Float3(0.0f, 0.0f, 0.0f);
this->collisionFlags = 0;
this->afterCollision = NULL; this->afterCollision = NULL;
this->onMovement = NULL; this->onMovement = NULL;
@ -85,7 +87,7 @@ void SimpleRigidBody::SetMotionState(btDefaultMotionState* motionState)
void SimpleRigidBody::SetRigidBody(btRigidBody* rigidBody) void SimpleRigidBody::SetRigidBody(btRigidBody* rigidBody)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->collisionFlags = rigidBody->getCollisionFlags();
} }
void SimpleRigidBody::SetSubscription(EventAction_AfterCollisionResponse function) void SimpleRigidBody::SetSubscription(EventAction_AfterCollisionResponse function)
@ -421,7 +423,7 @@ void SimpleRigidBody::MoveToLimbo()
void SimpleRigidBody::ReleaseFromLimbo() void SimpleRigidBody::ReleaseFromLimbo()
{ {
this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT); this->rigidBody->setCollisionFlags(this->collisionFlags);
} }
void SimpleRigidBody::SetPreviousVelocity(::Oyster::Math::Float3 velocity) void SimpleRigidBody::SetPreviousVelocity(::Oyster::Math::Float3 velocity)

View File

@ -93,6 +93,8 @@ namespace Oyster
btVector3 raySource[2]; btVector3 raySource[2];
btVector3 rayTarget[2]; btVector3 rayTarget[2];
btScalar rayLambda[2]; btScalar rayLambda[2];
int collisionFlags;
}; };
} }
} }