Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameClient
This commit is contained in:
commit
ded860c98b
|
@ -201,7 +201,9 @@
|
||||||
<ClCompile Include="DanBiasGame_Impl.cpp" />
|
<ClCompile Include="DanBiasGame_Impl.cpp" />
|
||||||
<ClCompile Include="GameClientState\Camera_Basic.cpp" />
|
<ClCompile Include="GameClientState\Camera_Basic.cpp" />
|
||||||
<ClCompile Include="GameClientState\Camera.cpp" />
|
<ClCompile Include="GameClientState\Camera.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\Camera_BasicV2.cpp" />
|
||||||
<ClCompile Include="GameClientState\Camera_FPS.cpp" />
|
<ClCompile Include="GameClientState\Camera_FPS.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\Camera_FPSV2.cpp" />
|
||||||
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
|
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
|
||||||
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
|
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
|
||||||
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
|
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
|
||||||
|
@ -226,7 +228,9 @@
|
||||||
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
|
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
|
||||||
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
|
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
|
||||||
<ClInclude Include="GameClientState\Camera.h" />
|
<ClInclude Include="GameClientState\Camera.h" />
|
||||||
|
<ClInclude Include="GameClientState\Camera_BasicV2.h" />
|
||||||
<ClInclude Include="GameClientState\Camera_FPS.h" />
|
<ClInclude Include="GameClientState\Camera_FPS.h" />
|
||||||
|
<ClInclude Include="GameClientState\Camera_FPSV2.h" />
|
||||||
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
|
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
|
||||||
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
|
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
|
||||||
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />
|
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
#include "Camera_BasicV2.h"
|
||||||
|
|
||||||
|
using namespace ::Oyster::Math3D;
|
||||||
|
|
||||||
|
Camera_BasicV2::Camera_BasicV2()
|
||||||
|
{
|
||||||
|
this->translation = Float3::null;
|
||||||
|
this->rotation = Quaternion::identity;
|
||||||
|
this->projection = Float4x4::identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera_BasicV2::Camera_BasicV2( const Float3 &position, const Quaternion &rotation, const Float4x4 &projection )
|
||||||
|
{
|
||||||
|
this->translation = position;
|
||||||
|
this->rotation = rotation;
|
||||||
|
this->projection = projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera_BasicV2::~Camera_BasicV2() {}
|
||||||
|
|
||||||
|
Camera_BasicV2 & Camera_BasicV2::operator = ( const Camera_BasicV2 &camera )
|
||||||
|
{
|
||||||
|
this->translation = camera.translation;
|
||||||
|
this->rotation = camera.rotation;
|
||||||
|
this->projection = camera.projection;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetPosition( const Float3 &translation )
|
||||||
|
{
|
||||||
|
this->translation = translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetRotation( const Quaternion &rotation )
|
||||||
|
{
|
||||||
|
this->rotation = rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetAngular( const Float3 &axis )
|
||||||
|
{
|
||||||
|
this->rotation = Rotation( axis );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetProjection( const Float4x4 &matrix )
|
||||||
|
{
|
||||||
|
this->projection = matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
|
||||||
|
{
|
||||||
|
ProjectionMatrix_Orthographic( width, height, nearClip, farClip, this->projection );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
|
||||||
|
{
|
||||||
|
ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, this->projection );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::Move( const Float3 &deltaPosition )
|
||||||
|
{
|
||||||
|
this->translation += deltaPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::Rotate( const Quaternion &deltaRotation )
|
||||||
|
{
|
||||||
|
this->rotation *= deltaRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_BasicV2::Rotate( const Float3 &deltaAngularAxis )
|
||||||
|
{
|
||||||
|
this->rotation *= Rotation( deltaAngularAxis );
|
||||||
|
}
|
||||||
|
|
||||||
|
const Float3 & Camera_BasicV2::GetPosition() const
|
||||||
|
{
|
||||||
|
return this->translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 & Camera_BasicV2::GetAngularAxis( Float3 &targetMem ) const
|
||||||
|
{
|
||||||
|
return targetMem = AngularAxis( this->rotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_BasicV2::GetNormalOf( const Float3 &axis ) const
|
||||||
|
{
|
||||||
|
return WorldAxisOf( this->rotation, axis );
|
||||||
|
}
|
||||||
|
|
||||||
|
const Quaternion & Camera_BasicV2::GetRotation() const
|
||||||
|
{
|
||||||
|
return this->rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3x3 & Camera_BasicV2::GetRotationMatrix( Float3x3 &targetMem ) const
|
||||||
|
{
|
||||||
|
return RotationMatrix( this->rotation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & Camera_BasicV2::GetRotationMatrix( Float4x4 &targetMem ) const
|
||||||
|
{
|
||||||
|
return RotationMatrix( this->rotation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & Camera_BasicV2::GetViewMatrix( Float4x4 &targetMem ) const
|
||||||
|
{
|
||||||
|
return ViewMatrix( this->rotation, this->translation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
const Float4x4 & Camera_BasicV2::GetProjectionMatrix() const
|
||||||
|
{
|
||||||
|
return this->projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & Camera_BasicV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
|
||||||
|
{
|
||||||
|
return TransformMatrix( this->projection, this->GetViewMatrix(), targetMem );
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef CAMERA_BASIC_V2_H
|
||||||
|
#define CAMERA_BASIC_V2_H
|
||||||
|
|
||||||
|
#include "OysterMath.h"
|
||||||
|
|
||||||
|
class Camera_BasicV2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera_BasicV2();
|
||||||
|
Camera_BasicV2( const ::Oyster::Math::Float3 &position, const ::Oyster::Math::Quaternion &rotation, const ::Oyster::Math::Float4x4 &projection );
|
||||||
|
virtual ~Camera_BasicV2();
|
||||||
|
|
||||||
|
Camera_BasicV2 & operator = ( const Camera_BasicV2 &camera );
|
||||||
|
|
||||||
|
void SetPosition( const ::Oyster::Math::Float3 &translation );
|
||||||
|
void SetRotation( const ::Oyster::Math::Quaternion &rotation );
|
||||||
|
void SetAngular( const ::Oyster::Math::Float3 &axis );
|
||||||
|
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
|
||||||
|
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||||
|
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||||
|
|
||||||
|
void Move( const ::Oyster::Math::Float3 &deltaPosition );
|
||||||
|
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
|
||||||
|
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
|
||||||
|
|
||||||
|
const ::Oyster::Math::Float3 & GetPosition() const;
|
||||||
|
::Oyster::Math::Float3 & GetAngularAxis( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
|
||||||
|
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
|
||||||
|
const ::Oyster::Math::Quaternion & GetRotation() const;
|
||||||
|
::Oyster::Math::Float3x3 & GetRotationMatrix( ::Oyster::Math::Float3x3 &targetMem ) const;
|
||||||
|
::Oyster::Math::Float4x4 & GetRotationMatrix( ::Oyster::Math::Float4x4 &targetMem ) const;
|
||||||
|
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||||
|
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
|
||||||
|
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
::Oyster::Math::Float3 translation;
|
||||||
|
mutable ::Oyster::Math::Quaternion rotation;
|
||||||
|
::Oyster::Math::Float4x4 projection;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,182 @@
|
||||||
|
#include "Camera_FPSV2.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
using namespace ::Oyster::Math3D;
|
||||||
|
using namespace ::Utility::Value;
|
||||||
|
|
||||||
|
Camera_FPSV2::Camera_FPSV2()
|
||||||
|
{ // this->head is default set to identity uniformprojection at origo
|
||||||
|
this->pitchUp = 0.0f;
|
||||||
|
this->headOffset =
|
||||||
|
this->body.translation = Float3::null;
|
||||||
|
this->body.rotation = Quaternion::identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera_FPSV2::~Camera_FPSV2() {}
|
||||||
|
|
||||||
|
Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera )
|
||||||
|
{
|
||||||
|
this->head = camera.head;
|
||||||
|
this->pitchUp = camera.pitchUp;
|
||||||
|
this->headOffset = camera.headOffset;
|
||||||
|
this->body.translation = camera.body.translation;
|
||||||
|
this->body.rotation = camera.body.rotation;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetHeadOffset( const Float3 &translation )
|
||||||
|
{
|
||||||
|
this->head.Move( translation - this->headOffset );
|
||||||
|
this->headOffset = translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetPosition( const Float3 &translation )
|
||||||
|
{
|
||||||
|
this->head.Move( translation - this->body.translation );
|
||||||
|
this->body.translation = translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetAngular( const Float3 &axis )
|
||||||
|
{
|
||||||
|
this->body.rotation = Rotation( axis );
|
||||||
|
this->head.SetRotation( this->body.rotation );
|
||||||
|
this->pitchUp = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetProjection( const Float4x4 &matrix )
|
||||||
|
{
|
||||||
|
this->head.SetProjection( matrix );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
|
||||||
|
{
|
||||||
|
this->head.SetOrthographicProjection( width, height, nearClip, farClip );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
|
||||||
|
{
|
||||||
|
this->head.SetPerspectiveProjection( verticalFoV, aspectRatio, nearClip, farClip );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::UpdateOrientation()
|
||||||
|
{
|
||||||
|
Float4x4 orientation;
|
||||||
|
OrientationMatrix( this->body.rotation, this->body.translation, orientation );
|
||||||
|
|
||||||
|
this->head.SetPosition( (orientation * Float4(this->headOffset, 1.0f)).xyz );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::SnapUpToNormal( const Float3 &normal )
|
||||||
|
{
|
||||||
|
this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) );
|
||||||
|
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::Move( const Float3 &deltaPosition )
|
||||||
|
{
|
||||||
|
this->head.Move( deltaPosition );
|
||||||
|
this->body.translation += deltaPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::Rotate( const Quaternion &deltaRotation )
|
||||||
|
{
|
||||||
|
this->head.Rotate( deltaRotation );
|
||||||
|
this->body.rotation *= deltaRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis )
|
||||||
|
{
|
||||||
|
this->Rotate( Rotation(deltaAngularAxis) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::MoveForward( Float distance )
|
||||||
|
{
|
||||||
|
this->MoveBackward( -distance );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::MoveBackward( Float distance )
|
||||||
|
{
|
||||||
|
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_z) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::StrafeRight( Float distance )
|
||||||
|
{
|
||||||
|
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_x) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::StrafeLeft( Float distance )
|
||||||
|
{
|
||||||
|
this->StrafeRight( -distance );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::PitchUp( Float radian )
|
||||||
|
{
|
||||||
|
this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi );
|
||||||
|
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::PitchDown( Float radian )
|
||||||
|
{
|
||||||
|
this->PitchUp( -radian );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::YawRight( Float radian )
|
||||||
|
{
|
||||||
|
this->YawLeft( -radian );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera_FPSV2::YawLeft( Float radian )
|
||||||
|
{
|
||||||
|
Quaternion deltaRotation = Rotation( radian, WorldAxisOf(this->body.rotation, Float3::standard_unit_y) );
|
||||||
|
this->Rotate( deltaRotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
const Float3 & Camera_FPSV2::GetHeadOffset() const
|
||||||
|
{
|
||||||
|
return this->headOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Float3 & Camera_FPSV2::GetPosition() const
|
||||||
|
{
|
||||||
|
return this->body.translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const
|
||||||
|
{
|
||||||
|
return this->head.GetViewMatrix( targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const
|
||||||
|
{
|
||||||
|
return this->head.GetProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
|
||||||
|
{
|
||||||
|
return this->head.GetViewsProjMatrix( targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const
|
||||||
|
{
|
||||||
|
return this->head.GetNormalOf( axis );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_FPSV2::GetRight() const
|
||||||
|
{
|
||||||
|
return WorldAxisOf( this->body.rotation, Float3::standard_unit_x );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_FPSV2::GetUp() const
|
||||||
|
{
|
||||||
|
return WorldAxisOf( this->body.rotation, Float3::standard_unit_y );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_FPSV2::GetLook() const
|
||||||
|
{
|
||||||
|
return this->head.GetNormalOf( -Float3::standard_unit_z );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 Camera_FPSV2::GetForward() const
|
||||||
|
{
|
||||||
|
return WorldAxisOf( this->body.rotation, -Float3::standard_unit_z );
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef CAMERA_FPSV2_H
|
||||||
|
#define CAMERA_FPSV2_H
|
||||||
|
|
||||||
|
#include "OysterMath.h"
|
||||||
|
#include "Camera_BasicV2.h"
|
||||||
|
|
||||||
|
class Camera_FPSV2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera_FPSV2();
|
||||||
|
virtual ~Camera_FPSV2();
|
||||||
|
|
||||||
|
Camera_FPSV2 & operator = ( const Camera_FPSV2 &camera );
|
||||||
|
|
||||||
|
void SetHeadOffset( const ::Oyster::Math::Float3 &translation );
|
||||||
|
void SetPosition( const ::Oyster::Math::Float3 &translation );
|
||||||
|
void SetAngular( const ::Oyster::Math::Float3 &axis );
|
||||||
|
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
|
||||||
|
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||||
|
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||||
|
|
||||||
|
void UpdateOrientation();
|
||||||
|
|
||||||
|
void SnapUpToNormal( const ::Oyster::Math::Float3 &normal );
|
||||||
|
|
||||||
|
void Move( const ::Oyster::Math::Float3 &deltaPosition );
|
||||||
|
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
|
||||||
|
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
|
||||||
|
|
||||||
|
void MoveForward( ::Oyster::Math::Float distance );
|
||||||
|
void MoveBackward( ::Oyster::Math::Float distance );
|
||||||
|
void StrafeRight( ::Oyster::Math::Float distance );
|
||||||
|
void StrafeLeft( ::Oyster::Math::Float distance );
|
||||||
|
|
||||||
|
void PitchUp( ::Oyster::Math::Float radian );
|
||||||
|
void PitchDown( ::Oyster::Math::Float radian );
|
||||||
|
void YawRight( ::Oyster::Math::Float radian );
|
||||||
|
void YawLeft( ::Oyster::Math::Float radian );
|
||||||
|
|
||||||
|
const ::Oyster::Math::Float3 & GetHeadOffset() const;
|
||||||
|
const ::Oyster::Math::Float3 & GetPosition() const;
|
||||||
|
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||||
|
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
|
||||||
|
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||||
|
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
|
||||||
|
::Oyster::Math::Float3 GetRight() const;
|
||||||
|
::Oyster::Math::Float3 GetUp() const;
|
||||||
|
::Oyster::Math::Float3 GetLook() const;
|
||||||
|
::Oyster::Math::Float3 GetForward() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Camera_BasicV2 head;
|
||||||
|
::Oyster::Math::Float pitchUp;
|
||||||
|
::Oyster::Math::Float3 headOffset;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
::Oyster::Math::Float3 translation;
|
||||||
|
::Oyster::Math::Quaternion rotation;
|
||||||
|
} body;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -85,11 +85,7 @@ bool GameState::Init( SharedStateContent &shared )
|
||||||
Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() );
|
Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() );
|
||||||
|
|
||||||
//tell server ready
|
//tell server ready
|
||||||
//this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
|
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
|
||||||
|
|
||||||
// Debugg hack
|
|
||||||
this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true );
|
|
||||||
// end debug hack
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +107,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
|
||||||
this->privData->myId = id;
|
this->privData->myId = id;
|
||||||
this->privData->camera.SetPosition( this->privData->player.getPos() );
|
this->privData->camera.SetPosition( this->privData->player.getPos() );
|
||||||
Float3 offset = Float3( 0.0f );
|
Float3 offset = Float3( 0.0f );
|
||||||
offset.y = this->privData->player.getScale().y + 0.5f; // debug hack +0.5f
|
offset.y = this->privData->player.getScale().y * 0.9f;
|
||||||
this->privData->camera.SetHeadOffset( offset );
|
this->privData->camera.SetHeadOffset( offset );
|
||||||
this->privData->camera.UpdateOrientation();
|
this->privData->camera.UpdateOrientation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,11 +54,8 @@ bool NetLoadState::Init( SharedStateContent &shared )
|
||||||
|
|
||||||
// we may assume that nwClient is properly connected to the server
|
// we may assume that nwClient is properly connected to the server
|
||||||
// signals querry to server for loading instructions
|
// signals querry to server for loading instructions
|
||||||
//this->privData->nwClient->Send( Protocol_QuerryGameType() );
|
this->privData->nwClient->Send( Protocol_QuerryGameType() );
|
||||||
|
|
||||||
// debugg
|
|
||||||
this->LoadGame( "..//Content//Worlds//2ofAll_updated.bias");
|
|
||||||
this->ChangeState( ClientState_Game );
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +97,7 @@ void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientE
|
||||||
|
|
||||||
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
|
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
|
||||||
{
|
{
|
||||||
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
|
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName );
|
||||||
this->ChangeState( ClientState_Game );
|
this->ChangeState( ClientState_Game );
|
||||||
this->privData->loading = false;
|
this->privData->loading = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,8 @@ namespace GameLogic
|
||||||
ObjectSpecialType GetObjectType() const override;
|
ObjectSpecialType GetObjectType() const override;
|
||||||
int getNrOfDynamicObj()const override;
|
int getNrOfDynamicObj()const override;
|
||||||
IObjectData* GetObjectAt(int ID) const override;
|
IObjectData* GetObjectAt(int ID) const override;
|
||||||
|
void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& mem) const override;
|
||||||
|
|
||||||
Level *level;
|
Level *level;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "GameLogicStates.h"
|
#include "GameLogicStates.h"
|
||||||
#include <OysterMath.h>
|
#include <OysterMath.h>
|
||||||
#include "LevelLoader\ObjectDefines.h"
|
#include "LevelLoader\ObjectDefines.h"
|
||||||
|
#include "DynamicArray.h"
|
||||||
|
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
|
@ -107,6 +108,7 @@ namespace GameLogic
|
||||||
public:
|
public:
|
||||||
virtual int getNrOfDynamicObj()const = 0;
|
virtual int getNrOfDynamicObj()const = 0;
|
||||||
virtual IObjectData* GetObjectAt(int ID) const = 0;
|
virtual IObjectData* GetObjectAt(int ID) const = 0;
|
||||||
|
virtual void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& destMem) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DANBIAS_GAMELOGIC_DLL GameAPI
|
class DANBIAS_GAMELOGIC_DLL GameAPI
|
||||||
|
|
|
@ -51,3 +51,11 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const
|
||||||
{
|
{
|
||||||
return this->level->GetObj(ID);
|
return this->level->GetObj(ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& mem) const
|
||||||
|
{
|
||||||
|
for(int i = 0; i < level->dynamicObjects.Size(); i++)
|
||||||
|
{
|
||||||
|
mem[i] = level->dynamicObjects[i];
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,61 +41,41 @@ namespace GameLogic
|
||||||
|
|
||||||
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
|
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
short clientID; // The unuiqe id reprsenting a specific client
|
char majorVersion;
|
||||||
std::string modelName;
|
char minorVersion;
|
||||||
float worldMatrix[16];
|
std::string mapName;
|
||||||
|
|
||||||
Protocol_LobbyCreateGame()
|
Protocol_LobbyCreateGame()
|
||||||
{
|
{
|
||||||
int c = 0;
|
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
for (int i = 0; i <= 16; i++)
|
|
||||||
{
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
|
||||||
}
|
}
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name)
|
||||||
}
|
|
||||||
Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16])
|
|
||||||
{
|
{
|
||||||
int c = 0;
|
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->majorVersion = majorVersion;
|
||||||
for (int i = 0; i <= 16; i++)
|
this->minorVersion = minorVersion;
|
||||||
{
|
this->mapName = name;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
|
||||||
|
|
||||||
clientID = _clientID;
|
|
||||||
modelName = name;
|
|
||||||
memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16);
|
|
||||||
}
|
}
|
||||||
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
|
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
|
||||||
{
|
{
|
||||||
int c = 1;
|
this->majorVersion = o[1].value.netChar;
|
||||||
clientID = o[c++].value.netInt;
|
this->minorVersion = o[2].value.netChar;
|
||||||
for (int i = 0; i <= 16; i++)
|
this->mapName.assign(o[3].value.netCharPtr);
|
||||||
{
|
|
||||||
this->worldMatrix[i] = o[c++].value.netFloat;
|
|
||||||
}
|
|
||||||
modelName.assign(o[c++].value.netCharPtr);
|
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol GetProtocol() override
|
Oyster::Network::CustomNetProtocol GetProtocol() override
|
||||||
{
|
{
|
||||||
int c = 1;
|
protocol[1].value = this->majorVersion;
|
||||||
protocol[c++].value = clientID;
|
protocol[2].value = this->minorVersion;
|
||||||
|
protocol.Set(3, this->mapName);
|
||||||
for (int i = 0; i <= 16; i++)
|
|
||||||
{
|
|
||||||
this->protocol[c++].value = this->worldMatrix[i];
|
|
||||||
}
|
|
||||||
protocol.Set(c++, this->modelName);
|
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#define DANBIASSERVER_CLIENT_OBJECT_H
|
#define DANBIASSERVER_CLIENT_OBJECT_H
|
||||||
|
|
||||||
#include <NetworkClient.h>
|
#include <NetworkClient.h>
|
||||||
|
#include <NetworkSession.h>
|
||||||
#include <PostBox\PostBox.h>
|
#include <PostBox\PostBox.h>
|
||||||
#include <GameAPI.h>
|
#include <GameAPI.h>
|
||||||
#include <Utilities.h>
|
#include <Utilities.h>
|
||||||
|
@ -17,27 +18,48 @@ namespace DanBias
|
||||||
class GameClient
|
class GameClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client, GameLogic::IPlayerData* player);
|
GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> nwClient);
|
||||||
virtual~GameClient();
|
virtual~GameClient();
|
||||||
|
|
||||||
GameLogic::IPlayerData* GetPlayer();
|
inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; }
|
||||||
GameLogic::IPlayerData* ReleasePlayer();
|
inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); }
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> GetClient();
|
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> ReleaseClient();
|
|
||||||
|
|
||||||
float GetSinceLastResponse() const;
|
inline bool Equals(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; }
|
||||||
bool IsReady() const;
|
inline bool Equals(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); }
|
||||||
bool Equals(const Oyster::Network::NetworkClient* c);
|
|
||||||
|
|
||||||
|
inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; }
|
||||||
|
inline std::wstring GetAlias() const { return this->alias; }
|
||||||
|
inline std::wstring GetCharacter() const { return this->character; }
|
||||||
|
inline bool IsReady() const { return this->isReady; }
|
||||||
|
inline GameLogic::IPlayerData* GetPlayer() const { return this->player; }
|
||||||
|
Oyster::Network::NetClient GetClient() const { return this->client; }
|
||||||
|
|
||||||
|
|
||||||
|
void SetPlayer(GameLogic::IPlayerData* player);
|
||||||
void SetReadyState(bool isReady);
|
void SetReadyState(bool isReady);
|
||||||
|
void SetAlias(std::wstring alias);
|
||||||
|
void SetCharacter(std::wstring character);
|
||||||
void SetSinceLastResponse(float seconds);
|
void SetSinceLastResponse(float seconds);
|
||||||
|
|
||||||
|
GameLogic::IPlayerData* ReleasePlayer();
|
||||||
|
Oyster::Network::NetClient ReleaseClient();
|
||||||
|
|
||||||
|
//NetworkSpecific
|
||||||
|
void SetOwner(Oyster::Network::NetworkSession* owner);
|
||||||
|
void UpdateClient();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameLogic::IPlayerData* player;
|
GameLogic::IPlayerData* player;
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
|
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
|
||||||
|
|
||||||
bool isReady;
|
bool isReady;
|
||||||
float secondsSinceLastResponse;
|
float secondsSinceLastResponse;
|
||||||
};
|
|
||||||
|
|
||||||
|
std::wstring alias;
|
||||||
|
std::wstring character;
|
||||||
|
};
|
||||||
}//End namespace DanBias
|
}//End namespace DanBias
|
||||||
|
|
||||||
|
typedef Utility::DynamicMemory::SmartPointer<DanBias::GameClient> gClient;
|
||||||
|
|
||||||
#endif // !DANBIASSERVER_CLIENT_OBJECT_H
|
#endif // !DANBIASSERVER_CLIENT_OBJECT_H
|
||||||
|
|
|
@ -15,11 +15,18 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
struct LobbyLevelData
|
struct LobbyLevelData
|
||||||
{
|
{
|
||||||
int mapNumber;
|
|
||||||
int maxClients;
|
int maxClients;
|
||||||
int gameMode;
|
int gameTimeInMinutes;
|
||||||
int gameTime;
|
std::wstring gameMode;
|
||||||
std::string gameName;
|
std::wstring mapName;
|
||||||
|
std::wstring gameName;
|
||||||
|
LobbyLevelData()
|
||||||
|
: maxClients(10)
|
||||||
|
, gameTimeInMinutes(10)
|
||||||
|
, gameMode(L"unknown")
|
||||||
|
, mapName(L"unknown")
|
||||||
|
, gameName(L"unknown")
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
class GameLobby :public Oyster::Network::NetworkSession
|
class GameLobby :public Oyster::Network::NetworkSession
|
||||||
{
|
{
|
||||||
|
@ -38,10 +45,8 @@ namespace DanBias
|
||||||
|
|
||||||
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
|
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
|
||||||
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
|
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
|
||||||
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
|
|
||||||
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
|
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
|
||||||
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
|
void LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
||||||
void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
|
||||||
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
|
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
|
||||||
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
|
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
|
||||||
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
|
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
|
||||||
|
@ -51,15 +56,18 @@ namespace DanBias
|
||||||
private:
|
private:
|
||||||
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
||||||
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
||||||
|
void ProcessClients() override;
|
||||||
|
bool Attach(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utility::WinTimer timer;
|
//Utility::WinTimer timer;
|
||||||
float refreshFrequency;
|
//float refreshFrequency;
|
||||||
|
|
||||||
Utility::DynamicMemory::LinkedList<Oyster::Network::NetworkClient*> readyList;
|
Utility::DynamicMemory::LinkedList<Oyster::Network::NetworkClient*> readyList;
|
||||||
GameSession gameSession;
|
GameSession gameSession;
|
||||||
LobbyLevelData description;
|
LobbyLevelData description;
|
||||||
Utility::DynamicMemory::SmartPointer<DanBias::GameClient> sessionOwner;
|
Utility::DynamicMemory::SmartPointer<DanBias::GameClient> sessionOwner;
|
||||||
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> gClients;
|
||||||
};
|
};
|
||||||
}//End namespace DanBias
|
}//End namespace DanBias
|
||||||
#endif // !DANBIASGAME_GAMELOBBY_H
|
#endif // !DANBIASGAME_GAMELOBBY_H
|
||||||
|
|
|
@ -55,15 +55,18 @@ namespace DanBias
|
||||||
static void NotifyWhenClientConnect(ClientConnectedNotify func);
|
static void NotifyWhenClientConnect(ClientConnectedNotify func);
|
||||||
static void NotifyWhenClientDisconnect(ClientDisconnectedNotify func);
|
static void NotifyWhenClientDisconnect(ClientDisconnectedNotify func);
|
||||||
|
|
||||||
static void GameSetMapName(const wchar_t* val);
|
|
||||||
static void GameSetMaxClients(const int& val);
|
|
||||||
static void GameSetGameMode(const wchar_t* val);
|
|
||||||
static void GameSetGameTime(const int& val);
|
static void GameSetGameTime(const int& val);
|
||||||
static int GameGetMapId();
|
static void GameSetMaxClients(const int& val);
|
||||||
static int GameGetMaxClients();
|
static void GameSetGameName(const wchar_t* val);
|
||||||
static int GameGetGameMode();
|
static void GameSetMapName(const wchar_t* val);
|
||||||
|
static void GameSetGameMode(const wchar_t* val);
|
||||||
|
|
||||||
static int GameGetGameTime();
|
static int GameGetGameTime();
|
||||||
static const char* GameGetGameName();
|
static int GameGetMaxClients();
|
||||||
|
static const wchar_t* GameGetGameMode();
|
||||||
|
static const wchar_t* GameGetGameName();
|
||||||
|
static const wchar_t* GameGetMapName();
|
||||||
|
|
||||||
static bool GameStart();
|
static bool GameStart();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,12 @@ namespace DanBias
|
||||||
*/
|
*/
|
||||||
struct GameDescription
|
struct GameDescription
|
||||||
{
|
{
|
||||||
int maxClients;
|
unsigned int maxClients;
|
||||||
int mapNumber;
|
std::wstring mapName;
|
||||||
int gameMode;
|
std::wstring gameMode;
|
||||||
int gameTime;
|
int gameTimeMinutes;
|
||||||
Oyster::Network::NetworkSession* owner;
|
Oyster::Network::NetworkSession* owner;
|
||||||
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -52,23 +52,27 @@ namespace DanBias
|
||||||
/** Join an existing/running game session
|
/** Join an existing/running game session
|
||||||
* @param client The client to attach to the session
|
* @param client The client to attach to the session
|
||||||
*/
|
*/
|
||||||
bool Attach(Oyster::Network::NetClient client) override;
|
bool Join(gClient client);
|
||||||
void CloseSession( bool dissconnectClients ) override;
|
|
||||||
|
//void CloseSession( bool dissconnectClients ) override;
|
||||||
|
|
||||||
inline bool IsCreated() const { return this->isCreated; }
|
inline bool IsCreated() const { return this->isCreated; }
|
||||||
inline bool IsRunning() const { return this->isRunning; }
|
inline bool IsRunning() const { return this->isRunning; }
|
||||||
operator bool() { return (this->isCreated && this->isCreated); }
|
operator bool() { return (this->isCreated && this->isRunning); }
|
||||||
|
|
||||||
//Private member functions
|
//Private member functions
|
||||||
private:
|
private:
|
||||||
// TODO: find out what this method does..
|
// Client event callback function
|
||||||
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
||||||
|
void ProcessClients() override;
|
||||||
|
bool Send(Oyster::Network::CustomNetProtocol& message) override;
|
||||||
|
bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override;
|
||||||
|
|
||||||
//Sends a client to the owner, if obj is NULL then all clients is sent
|
//Sends a client to the owner, if param is NULL then all clients is sent
|
||||||
void SendToOwner(DanBias::GameClient* obj);
|
void SendToOwner(DanBias::GameClient* obj);
|
||||||
|
|
||||||
//Derived from IThreadObject
|
//Derived from IThreadObject
|
||||||
void ThreadEntry() override;
|
void ThreadEntry( ) override;
|
||||||
bool DoWork ( ) override;
|
bool DoWork ( ) override;
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,8 +102,8 @@ namespace DanBias
|
||||||
|
|
||||||
//Private member variables
|
//Private member variables
|
||||||
private:
|
private:
|
||||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
Utility::DynamicMemory::DynamicArray<gClient> gClients;
|
||||||
Utility::DynamicMemory::SmartPointer<DanBias::GameClient> sessionOwner;
|
gClient sessionOwner;
|
||||||
Oyster::Thread::OysterThread worker;
|
Oyster::Thread::OysterThread worker;
|
||||||
GameLogic::GameAPI& gameInstance;
|
GameLogic::GameAPI& gameInstance;
|
||||||
GameLogic::ILevelData *levelData;
|
GameLogic::ILevelData *levelData;
|
||||||
|
@ -115,6 +119,7 @@ namespace DanBias
|
||||||
//TODO: Remove this uggly hax
|
//TODO: Remove this uggly hax
|
||||||
static GameSession* gameSession;
|
static GameSession* gameSession;
|
||||||
|
|
||||||
|
|
||||||
};//End GameSession
|
};//End GameSession
|
||||||
}//End namespace DanBias
|
}//End namespace DanBias
|
||||||
#endif // !DANBIASSERVER_GAME_SESSION_H
|
#endif // !DANBIASSERVER_GAME_SESSION_H
|
|
@ -12,51 +12,27 @@ using namespace DanBias;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
|
||||||
GameClient::GameClient(SmartPointer<NetworkClient> client, GameLogic::IPlayerData* player)
|
GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> nwClient)
|
||||||
{
|
{
|
||||||
this->client = client;
|
this->client = nwClient;
|
||||||
this->player = player;
|
this->player = 0;
|
||||||
isReady = false;
|
isReady = false;
|
||||||
|
this->character = L"Unknown";
|
||||||
|
this->alias = L"Unknown";
|
||||||
|
this->secondsSinceLastResponse = 0.0f;
|
||||||
}
|
}
|
||||||
GameClient::~GameClient()
|
GameClient::~GameClient()
|
||||||
{
|
{
|
||||||
this->client->Disconnect();
|
|
||||||
this->player = 0;
|
this->player = 0;
|
||||||
isReady = false;
|
this->isReady = false;
|
||||||
|
this->character = L"Unknown";
|
||||||
|
this->alias = L"Unknown";
|
||||||
|
this->secondsSinceLastResponse = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLogic::IPlayerData* GameClient::GetPlayer()
|
void GameClient::SetPlayer(GameLogic::IPlayerData* player)
|
||||||
{
|
{
|
||||||
return this->player;
|
this->player = player;
|
||||||
}
|
|
||||||
GameLogic::IPlayerData* GameClient::ReleasePlayer()
|
|
||||||
{
|
|
||||||
GameLogic::IPlayerData *temp = this->player;
|
|
||||||
this->player = 0;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::GetClient()
|
|
||||||
{
|
|
||||||
return this->client;
|
|
||||||
}
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::ReleaseClient()
|
|
||||||
{
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> temp = this->client;
|
|
||||||
this->client = 0;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GameClient::GetSinceLastResponse() const
|
|
||||||
{
|
|
||||||
return this->secondsSinceLastResponse;
|
|
||||||
}
|
|
||||||
bool GameClient::IsReady() const
|
|
||||||
{
|
|
||||||
return this->isReady;
|
|
||||||
}
|
|
||||||
bool GameClient::Equals(const NetworkClient* c)
|
|
||||||
{
|
|
||||||
return (c->GetID() == this->client->GetID());
|
|
||||||
}
|
}
|
||||||
void GameClient::SetReadyState(bool r)
|
void GameClient::SetReadyState(bool r)
|
||||||
{
|
{
|
||||||
|
@ -66,5 +42,35 @@ void GameClient::SetSinceLastResponse(float s)
|
||||||
{
|
{
|
||||||
this->secondsSinceLastResponse = s;
|
this->secondsSinceLastResponse = s;
|
||||||
}
|
}
|
||||||
|
void GameClient::SetAlias(std::wstring alias)
|
||||||
|
{
|
||||||
|
this->alias = alias;
|
||||||
|
}
|
||||||
|
void GameClient::SetCharacter(std::wstring character)
|
||||||
|
{
|
||||||
|
this->character = character;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GameClient::SetOwner(Oyster::Network::NetworkSession* owner)
|
||||||
|
{
|
||||||
|
this->client->SetOwner(owner);
|
||||||
|
}
|
||||||
|
void GameClient::UpdateClient()
|
||||||
|
{
|
||||||
|
this->client->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IPlayerData* GameClient::ReleasePlayer()
|
||||||
|
{
|
||||||
|
IPlayerData* temp = this->player;
|
||||||
|
this->player = 0;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
NetClient GameClient::ReleaseClient()
|
||||||
|
{
|
||||||
|
NetClient temp = this->client;
|
||||||
|
this->client = 0;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
|
@ -37,16 +37,33 @@ void GameLobby::Update()
|
||||||
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
|
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
|
||||||
{
|
{
|
||||||
this->description.gameMode = desc.gameMode;
|
this->description.gameMode = desc.gameMode;
|
||||||
this->description.gameTime = desc.gameTime;
|
this->description.gameName = desc.gameName;
|
||||||
this->description.mapNumber = desc.mapNumber;
|
this->description.mapName = desc.mapName;
|
||||||
|
this->description.gameTimeInMinutes = desc.gameTimeInMinutes;
|
||||||
this->description.maxClients = desc.maxClients;
|
this->description.maxClients = desc.maxClients;
|
||||||
|
|
||||||
|
if(this->gClients.Size() > (unsigned int)desc.maxClients)
|
||||||
|
{
|
||||||
|
//Kick overflow
|
||||||
|
for (unsigned int i = (unsigned int)desc.maxClients - 1; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->gClients[i])
|
||||||
|
{
|
||||||
|
this->gClients[i]->GetClient()->Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->gClients.Resize((unsigned int)desc.maxClients);
|
||||||
|
|
||||||
}
|
}
|
||||||
void GameLobby::GetGameDesc(LobbyLevelData& desc)
|
void GameLobby::GetGameDesc(LobbyLevelData& desc)
|
||||||
{
|
{
|
||||||
desc.gameMode = this->description.gameMode;
|
desc.gameTimeInMinutes = this->description.gameTimeInMinutes;
|
||||||
desc.gameTime = this->description.gameTime;
|
|
||||||
desc.mapNumber = this->description.mapNumber;
|
|
||||||
desc.maxClients = this->description.maxClients;
|
desc.maxClients = this->description.maxClients;
|
||||||
|
desc.mapName = this->description.mapName;
|
||||||
|
desc.gameName = this->description.gameName;
|
||||||
|
desc.gameMode = this->description.gameMode;
|
||||||
|
|
||||||
}
|
}
|
||||||
bool GameLobby::StartGameSession( )
|
bool GameLobby::StartGameSession( )
|
||||||
{
|
{
|
||||||
|
@ -56,18 +73,18 @@ bool GameLobby::StartGameSession( )
|
||||||
GameSession::GameDescription desc;
|
GameSession::GameDescription desc;
|
||||||
desc.maxClients = this->description.maxClients;
|
desc.maxClients = this->description.maxClients;
|
||||||
desc.gameMode = this->description.gameMode;
|
desc.gameMode = this->description.gameMode;
|
||||||
desc.gameTime = this->description.gameTime;
|
desc.gameTimeMinutes = this->description.gameTimeInMinutes;
|
||||||
desc.mapNumber = this->description.mapNumber;
|
//desc.mapName = this->description.mapNumber;
|
||||||
desc.owner = this;
|
desc.owner = this;
|
||||||
desc.clients = this->clients;
|
desc.clients = this->gClients;
|
||||||
|
|
||||||
if(desc.gameTime == 0.0f)
|
if(desc.gameTimeMinutes == 0)
|
||||||
desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere.
|
desc.gameTimeMinutes = 10; //note: should be fetched from somewhere.
|
||||||
|
|
||||||
if(desc.maxClients == 0)
|
if(desc.maxClients == 0)
|
||||||
desc.maxClients = 10; //note: should be fetched somewhere else..
|
desc.maxClients = 10; //note: should be fetched somewhere else..
|
||||||
|
|
||||||
this->clients.Clear(); //Remove clients from lobby list
|
this->gClients.Clear(); //Remove clients from lobby list
|
||||||
|
|
||||||
if(this->gameSession.Create(desc))
|
if(this->gameSession.Create(desc))
|
||||||
{
|
{
|
||||||
|
@ -96,8 +113,8 @@ void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::Clie
|
||||||
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
|
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
|
||||||
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
||||||
e.sender->Disconnect();
|
e.sender->Disconnect();
|
||||||
this->readyList.Remove(e.sender);
|
//this->readyList.Remove(e.sender);
|
||||||
this->clients.Remove(e.sender);
|
//this->gClients.Remove(e.sender);
|
||||||
break;
|
break;
|
||||||
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
||||||
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
||||||
|
@ -111,21 +128,30 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster
|
||||||
|
|
||||||
if(this->gameSession)
|
if(this->gameSession)
|
||||||
{
|
{
|
||||||
Attach(client);
|
if(!this->Attach(client))
|
||||||
|
{
|
||||||
|
client->Disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Attach(client);
|
if(!this->Attach(client))
|
||||||
|
{
|
||||||
|
//Send message that lobby full
|
||||||
|
client->Disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Protocol_LobbyClientData p1;
|
Protocol_LobbyClientData p1;
|
||||||
Protocol_LobbyGameData p2;
|
Protocol_LobbyGameData p2;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
if(this->gClients[i])
|
||||||
{
|
{
|
||||||
Protocol_LobbyClientData::PlayerData t;
|
Protocol_LobbyClientData::PlayerData t;
|
||||||
t.id = this->clients[i]->GetID();
|
t.id = client->GetID();
|
||||||
t.ip = this->clients[i]->GetIpAddress();
|
t.ip = client->GetIpAddress();
|
||||||
t.team = 0;
|
t.team = 0;
|
||||||
t.name = "Dennis är kung tycker Erik!";
|
t.name = "Dennis är kung tycker Erik!";
|
||||||
p1.list.Push(t);
|
p1.list.Push(t);
|
||||||
|
@ -139,4 +165,42 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster
|
||||||
client->Send(p2.GetProtocol());
|
client->Send(p2.GetProtocol());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void GameLobby::ProcessClients()
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->gClients[i])
|
||||||
|
{
|
||||||
|
this->gClients[i]->UpdateClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool GameLobby::Attach(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
|
||||||
|
{
|
||||||
|
if(this->clientCount = this->description.maxClients) return false;
|
||||||
|
|
||||||
|
bool added = false;
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(!this->gClients[i])
|
||||||
|
{
|
||||||
|
added = true;
|
||||||
|
this->gClients[i] = new GameClient(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!added)
|
||||||
|
{
|
||||||
|
this->gClients.Push(new GameClient(client));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,9 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
||||||
break;
|
break;
|
||||||
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
||||||
break;
|
break;
|
||||||
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
|
|
||||||
//break;
|
|
||||||
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
||||||
break;
|
break;
|
||||||
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
|
case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c);
|
||||||
//break;
|
|
||||||
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c);
|
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
||||||
break;
|
break;
|
||||||
|
@ -32,7 +28,7 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,37 +55,40 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net
|
||||||
}
|
}
|
||||||
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->clients[i])
|
||||||
|
{
|
||||||
|
this->clients[i]->Send(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
printf(p.text.c_str());
|
printf(p.text.c_str());
|
||||||
}
|
}
|
||||||
//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
||||||
{
|
{
|
||||||
|
//Send countdown timer before lobby shuts down
|
||||||
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
|
{
|
||||||
|
this->clients[i]->Send(Protocol_LobbyStartGame(3.0f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Someone else tried to start the server..
|
//Someone else tried to start the server..
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
||||||
//{
|
|
||||||
// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
|
||||||
// //{
|
|
||||||
// // if (this->gameLobby[i]->GetID() == p.value)
|
|
||||||
// // {
|
|
||||||
// // this->gameLobby[i]->Attach(Detach(c));
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
|
||||||
{
|
{
|
||||||
|
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
||||||
|
//{
|
||||||
|
// if (this->gameLobby[i]->GetID() == p.value)
|
||||||
|
// {
|
||||||
|
// this->gameLobby[i]->Attach(Detach(c));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
|
@ -112,19 +111,22 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->readyList.Remove(c);
|
this->readyList.Remove(c);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
NetClient temp;
|
if(this->gameSession)
|
||||||
|
{
|
||||||
|
gClient temp;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
//find client in waiting list
|
//find client in waiting list
|
||||||
for (unsigned int i = 0; !found && i < this->clients.Size(); i++)
|
for (unsigned int i = 0; !found && i < this->clients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i]->GetID() == c->GetID())
|
if(this->gClients[i]->GetClient()->GetID() == c->GetID())
|
||||||
{
|
{
|
||||||
temp = this->clients[i];
|
temp = this->gClients[i];
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,6 +139,11 @@ void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyste
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Send game data
|
//Send game data
|
||||||
this->gameSession.Attach(temp);
|
this->gameSession.Join(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,21 @@ void GameServerAPI::GameSetMapName(const wchar_t* val)
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
//d.mapNumber = val; //TODO: implement
|
d.mapName = val;
|
||||||
|
lobby.SetGameDesc(d);
|
||||||
|
}
|
||||||
|
void GameServerAPI::GameSetGameMode(const wchar_t* val)
|
||||||
|
{
|
||||||
|
LobbyLevelData d;
|
||||||
|
lobby.GetGameDesc(d);
|
||||||
|
d.gameMode = val;
|
||||||
|
lobby.SetGameDesc(d);
|
||||||
|
}
|
||||||
|
void GameServerAPI::GameSetGameName(const wchar_t* val)
|
||||||
|
{
|
||||||
|
LobbyLevelData d;
|
||||||
|
lobby.GetGameDesc(d);
|
||||||
|
d.gameName = val;
|
||||||
lobby.SetGameDesc(d);
|
lobby.SetGameDesc(d);
|
||||||
}
|
}
|
||||||
void GameServerAPI::GameSetMaxClients(const int& val)
|
void GameServerAPI::GameSetMaxClients(const int& val)
|
||||||
|
@ -132,25 +146,19 @@ void GameServerAPI::GameSetMaxClients(const int& val)
|
||||||
d.maxClients = val;
|
d.maxClients = val;
|
||||||
lobby.SetGameDesc(d);
|
lobby.SetGameDesc(d);
|
||||||
}
|
}
|
||||||
void GameServerAPI::GameSetGameMode(const wchar_t* val)
|
|
||||||
{
|
|
||||||
LobbyLevelData d;
|
|
||||||
lobby.GetGameDesc(d);
|
|
||||||
//d.gameMode = val; //TODO: implement
|
|
||||||
lobby.SetGameDesc(d);
|
|
||||||
}
|
|
||||||
void GameServerAPI::GameSetGameTime(const int& val)
|
void GameServerAPI::GameSetGameTime(const int& val)
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
d.gameTime = val;
|
d.gameTimeInMinutes = val;
|
||||||
lobby.SetGameDesc(d);
|
lobby.SetGameDesc(d);
|
||||||
}
|
}
|
||||||
int GameServerAPI::GameGetMapId()
|
|
||||||
|
const wchar_t* GameServerAPI::GameGetMapName()
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
return d.mapNumber;
|
return d.mapName.c_str();
|
||||||
}
|
}
|
||||||
int GameServerAPI::GameGetMaxClients()
|
int GameServerAPI::GameGetMaxClients()
|
||||||
{
|
{
|
||||||
|
@ -158,24 +166,25 @@ int GameServerAPI::GameGetMaxClients()
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
return d.maxClients;
|
return d.maxClients;
|
||||||
}
|
}
|
||||||
int GameServerAPI::GameGetGameMode()
|
const wchar_t* GameServerAPI::GameGetGameMode()
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
return d.gameMode;
|
return d.gameMode.c_str();
|
||||||
}
|
}
|
||||||
int GameServerAPI::GameGetGameTime()
|
int GameServerAPI::GameGetGameTime()
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
return d.gameTime;
|
return d.gameTimeInMinutes;
|
||||||
}
|
}
|
||||||
const char* GameServerAPI::GameGetGameName()
|
const wchar_t* GameServerAPI::GameGetGameName()
|
||||||
{
|
{
|
||||||
LobbyLevelData d;
|
LobbyLevelData d;
|
||||||
lobby.GetGameDesc(d);
|
lobby.GetGameDesc(d);
|
||||||
return d.gameName.c_str();
|
return d.gameName.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameServerAPI::GameStart()
|
bool GameServerAPI::GameStart()
|
||||||
{
|
{
|
||||||
if(lobby.StartGameSession())
|
if(lobby.StartGameSession())
|
||||||
|
|
|
@ -19,11 +19,8 @@ using namespace Oyster;
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
using namespace Oyster::Thread;
|
using namespace Oyster::Thread;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
using namespace DanBias;
|
||||||
|
|
||||||
namespace DanBias
|
|
||||||
{
|
|
||||||
Utility::WinTimer testTimer;
|
|
||||||
int testID = -1;
|
|
||||||
|
|
||||||
bool GameSession::DoWork( )
|
bool GameSession::DoWork( )
|
||||||
{
|
{
|
||||||
|
@ -46,9 +43,9 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
int temp = -1;
|
int temp = -1;
|
||||||
//Find the idiot
|
//Find the idiot
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i]->Equals(e.sender))
|
if(this->gClients[i]->Equals(e.sender))
|
||||||
{
|
{
|
||||||
temp = i;
|
temp = i;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +56,7 @@ namespace DanBias
|
||||||
this->Detach(e.sender)->Disconnect();
|
this->Detach(e.sender)->Disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SmartPointer<GameClient> cl = this->clients[temp];
|
SmartPointer<GameClient> cl = this->gClients[temp];
|
||||||
|
|
||||||
switch (e.args.type)
|
switch (e.args.type)
|
||||||
{
|
{
|
||||||
|
@ -73,15 +70,48 @@ namespace DanBias
|
||||||
break;
|
break;
|
||||||
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
||||||
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
|
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
|
||||||
testID = 2;
|
|
||||||
if(cl->GetPlayer()->GetID() == testID)//TODO: TEST
|
|
||||||
{
|
|
||||||
testTimer.reset();
|
|
||||||
}
|
|
||||||
this->ParseProtocol(e.args.data.protocol, cl);
|
this->ParseProtocol(e.args.data.protocol, cl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void GameSession::ProcessClients()
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->gClients[i])
|
||||||
|
{
|
||||||
|
this->gClients[i]->UpdateClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool GameSession::Send(Oyster::Network::CustomNetProtocol& message)
|
||||||
|
{
|
||||||
|
bool returnValue = false;
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->gClients[i])
|
||||||
|
{
|
||||||
|
this->gClients[i]->GetClient()->Send(message);
|
||||||
|
returnValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
bool GameSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->gClients[i] && this->gClients[i]->GetClient()->GetID() == ID)
|
||||||
|
{
|
||||||
|
this->gClients[i]->GetClient()->Send(protocol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
|
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
|
||||||
{
|
{
|
||||||
|
@ -246,7 +276,6 @@ namespace DanBias
|
||||||
printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str());
|
printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}//End namespace DanBias
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
#include "..\GameSession.h"
|
#include "..\GameSession.h"
|
||||||
#include "..\GameClient.h"
|
#include "..\GameClient.h"
|
||||||
|
#include "..\GameLobby.h"
|
||||||
#include <Protocols.h>
|
#include <Protocols.h>
|
||||||
#include <PostBox\PostBox.h>
|
#include <PostBox\PostBox.h>
|
||||||
#include <GameLogicStates.h>
|
#include <GameLogicStates.h>
|
||||||
|
@ -24,14 +25,13 @@ using namespace Oyster;
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
using namespace Oyster::Thread;
|
using namespace Oyster::Thread;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
using namespace DanBias;
|
||||||
|
|
||||||
namespace DanBias
|
GameSession* GameSession::gameSession = nullptr;
|
||||||
{
|
|
||||||
GameSession* GameSession::gameSession = nullptr;
|
|
||||||
|
|
||||||
GameSession::GameSession()
|
GameSession::GameSession()
|
||||||
:gameInstance(GameAPI::Instance())
|
:gameInstance(GameAPI::Instance())
|
||||||
{
|
{
|
||||||
this->owner = 0;
|
this->owner = 0;
|
||||||
this->isCreated = false;
|
this->isCreated = false;
|
||||||
this->isRunning = false;
|
this->isRunning = false;
|
||||||
|
@ -42,48 +42,54 @@ namespace DanBias
|
||||||
this->logicTimer.reset();
|
this->logicTimer.reset();
|
||||||
|
|
||||||
memset(&this->description, 0, sizeof(GameDescription));
|
memset(&this->description, 0, sizeof(GameDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSession::~GameSession()
|
GameSession::~GameSession()
|
||||||
{
|
{
|
||||||
this->worker.Terminate();
|
this->worker.Terminate();
|
||||||
this->clients.Clear();
|
this->clients.Clear();
|
||||||
this->gameInstance;
|
this->gameInstance;
|
||||||
this->owner = 0;
|
this->owner = 0;
|
||||||
this->isCreated = false;
|
this->isCreated = false;
|
||||||
this->isRunning = false;
|
this->isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameSession::Create(GameDescription& desc)
|
bool GameSession::Create(GameDescription& desc)
|
||||||
{
|
{
|
||||||
this->description = desc;
|
this->description = desc;
|
||||||
/* Do some error checking */
|
/* Do some error checking */
|
||||||
if(desc.clients.Size() == 0) return false;
|
if(desc.clients.Size() == 0) return false;
|
||||||
if(!desc.owner) return false;
|
if(!desc.owner) return false;
|
||||||
if(this->isCreated) return false;
|
if(this->isCreated) return false;
|
||||||
|
|
||||||
/* standard initialization of some data */
|
/* standard initialization of some data */
|
||||||
NetworkSession::clients = desc.clients;
|
this->gClients.Resize((unsigned int)desc.maxClients);
|
||||||
NetworkSession::clients.Resize((unsigned int)desc.maxClients);
|
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
||||||
this->clients.Resize((unsigned int)desc.maxClients);
|
{
|
||||||
|
if(desc.clients[i])
|
||||||
|
{
|
||||||
|
this->clientCount++;
|
||||||
|
this->gClients[i] = desc.clients[i];
|
||||||
|
this->gClients[i]->SetOwner(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
this->owner = desc.owner;
|
this->owner = desc.owner;
|
||||||
|
|
||||||
/* Initiate the game instance */
|
/* Initiate the game instance */
|
||||||
if(!this->gameInstance.Initiate())
|
if(!this->gameInstance.Initiate())
|
||||||
{
|
{
|
||||||
printf("Failed to initiate the game instance\n");
|
printf("Failed to initiate the game instance\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the players in the game instance */
|
/* Create the players in the game instance */
|
||||||
GameLogic::IPlayerData* p = 0;
|
GameLogic::IPlayerData* p = 0;
|
||||||
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(desc.clients[i])
|
if(this->gClients[i])
|
||||||
{
|
{
|
||||||
if( (p = this->gameInstance.CreatePlayer()) )
|
if( (p = this->gameInstance.CreatePlayer()) )
|
||||||
{
|
{
|
||||||
desc.clients[i]->SetOwner(this);
|
this->gClients[i]->SetPlayer(p);
|
||||||
this->clients[i] = (new GameClient(desc.clients[i], p));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -92,14 +98,14 @@ namespace DanBias
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the game level */
|
/* Create the game level */
|
||||||
if(!(this->levelData = this->gameInstance.CreateLevel()))
|
if(!(this->levelData = this->gameInstance.CreateLevel()))
|
||||||
{
|
{
|
||||||
printf("Level not created!");
|
printf("Level not created!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set some game instance data options */
|
/* Set some game instance data options */
|
||||||
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
||||||
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
||||||
this->gameInstance.SetFPS(60);
|
this->gameInstance.SetFPS(60);
|
||||||
|
@ -113,10 +119,10 @@ namespace DanBias
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return this->isCreated;
|
return this->isCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSession::Run()
|
void GameSession::Run()
|
||||||
{
|
{
|
||||||
if(this->isRunning) return;
|
if(this->isRunning) return;
|
||||||
|
|
||||||
if(this->clients.Size() > 0)
|
if(this->clients.Size() > 0)
|
||||||
|
@ -125,30 +131,27 @@ namespace DanBias
|
||||||
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
|
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
|
||||||
this->isRunning = true;
|
this->isRunning = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSession::ThreadEntry( )
|
void GameSession::ThreadEntry( )
|
||||||
{
|
{
|
||||||
//List with clients that we are waiting on..
|
//List with clients that we are waiting on..
|
||||||
DynamicArray<SmartPointer<GameClient>> readyList;// = this->clients;
|
DynamicArray<gClient> readyList;// = this->clients;
|
||||||
|
|
||||||
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
if(this->gClients[i])
|
||||||
{
|
{
|
||||||
if(this->clients[i]->IsReady())
|
readyList.Push(this->gClients[i]);
|
||||||
{
|
Protocol_LobbyCreateGame p((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string()));
|
||||||
readyList.Push(this->clients[i]);
|
|
||||||
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
|
|
||||||
readyList[readyList.Size() - 1]->GetClient()->Send(p);
|
readyList[readyList.Size() - 1]->GetClient()->Send(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int readyCounter = readyList.Size();
|
unsigned int readyCounter = readyList.Size();
|
||||||
|
|
||||||
//Sync with clients
|
//Sync with clients
|
||||||
while (readyCounter != 0)
|
while (readyCounter != 0)
|
||||||
{
|
{
|
||||||
this->ProcessClients();
|
this->ProcessClients();
|
||||||
|
@ -157,15 +160,14 @@ namespace DanBias
|
||||||
if(readyList[i] && readyList[i]->IsReady())
|
if(readyList[i] && readyList[i]->IsReady())
|
||||||
{
|
{
|
||||||
//Need to send information about other players, to all players
|
//Need to send information about other players, to all players
|
||||||
for (unsigned int k = 0; k < this->clients.Size(); k++)
|
for (unsigned int k = 0; k < this->gClients.Size(); k++)
|
||||||
{
|
{
|
||||||
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
|
if((this->gClients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->gClients[k]->GetClient()->GetID())
|
||||||
{
|
{
|
||||||
//Protocol_ObjectCreatePlayer
|
IPlayerData* pl = this->gClients[k]->GetPlayer();
|
||||||
Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(),
|
Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(),
|
||||||
this->clients[k]->GetPlayer()->GetRotation(),
|
pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(),
|
||||||
this->clients[k]->GetPlayer()->GetScale(),
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later..
|
|
||||||
readyList[i]->GetClient()->Send(p);
|
readyList[i]->GetClient()->Send(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,64 +179,105 @@ namespace DanBias
|
||||||
Sleep(5); //TODO: This might not be needed here.
|
Sleep(5); //TODO: This might not be needed here.
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
//Sync with clients before starting countdown
|
||||||
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
if(this->gClients[i])
|
||||||
{
|
{
|
||||||
this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5));
|
this->gClients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5.0f));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GameSession::Attach(Utility::DynamicMemory::SmartPointer<NetworkClient> client)
|
bool GameSession::Join(gClient gameClient)
|
||||||
{
|
{
|
||||||
if(!this->isCreated) return false;
|
if(!this->isCreated) return false;
|
||||||
if(this->GetClientCount() == this->clients.Capacity()) return false;
|
if(this->GetClientCount() == this->gClients.Capacity()) return false;
|
||||||
|
|
||||||
client->SetOwner(this);
|
gameClient->SetOwner(this);
|
||||||
|
|
||||||
IPlayerData* player = this->gameInstance.CreatePlayer();
|
IPlayerData* playerData = this->gameInstance.CreatePlayer();
|
||||||
if(!player) return false;
|
if(!playerData) return false;
|
||||||
|
|
||||||
SmartPointer<GameClient> obj = new GameClient(client, player);
|
gameClient->SetPlayer(playerData);
|
||||||
|
NetworkClient* nwClient = gameClient->GetClient();
|
||||||
|
|
||||||
// Send the chosen mesh name
|
// Send the level information
|
||||||
Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation());
|
|
||||||
obj->GetClient()->Send(lcg);
|
|
||||||
|
|
||||||
// Send the player data only
|
|
||||||
for (unsigned int i = 0; i < this->clients.Capacity(); i++)
|
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string()));
|
||||||
|
nwClient->Send(lcg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the player data only
|
||||||
{
|
{
|
||||||
IPlayerData* p = this->clients[i]->GetPlayer();
|
Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(),
|
||||||
Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
|
playerData->GetID(), true, playerData->GetTeamID(),
|
||||||
//Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
this->clients[i]->GetClient()->Send(oc);
|
nwClient->Send(oc);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0));
|
// Send information about other clients
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
|
||||||
{
|
{
|
||||||
if(!clients[i])
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
{
|
{
|
||||||
NetworkSession::clients[i] = client;
|
if(this->gClients[i])
|
||||||
clients[i] = obj;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameSession::CloseSession( bool dissconnectClients )
|
|
||||||
{
|
{
|
||||||
this->worker.Terminate();
|
IPlayerData* temp = this->gClients[i]->GetPlayer();
|
||||||
NetworkSession::CloseSession(true);
|
Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(),
|
||||||
this->clients.Clear();
|
temp->GetID(), false, temp->GetTeamID(),
|
||||||
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
|
nwClient->Send(oc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}//End namespace DanBias
|
//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client
|
||||||
|
{
|
||||||
|
DynamicArray<IObjectData*> objects;
|
||||||
|
this->levelData->GetAllDynamicObjects(objects);
|
||||||
|
for (unsigned int i = 0; i < objects.Size(); i++)
|
||||||
|
{
|
||||||
|
//Protocol_ObjectPosition p(movedObject->GetPosition(), id);
|
||||||
|
Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID());
|
||||||
|
GameSession::gameSession->Send(p.GetProtocol());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the new client to the update list
|
||||||
|
bool added = false;
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; !added && i < this->gClients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(!this->gClients[i])
|
||||||
|
{
|
||||||
|
this->gClients[i] = gameClient;
|
||||||
|
// Send the start signal
|
||||||
|
{
|
||||||
|
nwClient->Send(GameLogic::Protocol_LobbyStartGame(0));
|
||||||
|
}
|
||||||
|
added = true;
|
||||||
|
this->clientCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
//DynamicArray<gClient> GameSession::CloseSession( bool dissconnectClients )
|
||||||
|
//{
|
||||||
|
// this->worker.Terminate();
|
||||||
|
// //TODO: Send clients to lobby
|
||||||
|
//
|
||||||
|
// //for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||||
|
// //{
|
||||||
|
// // if(this->gClients[i])
|
||||||
|
// // {
|
||||||
|
// // ((GameLobby*)this->owner)-> this->gClients[i]
|
||||||
|
// // }
|
||||||
|
// //}
|
||||||
|
//
|
||||||
|
// this->gClients.Clear();
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,26 +72,32 @@ void StandaloneGameServerCLI::GameSetMapName(String^ value)
|
||||||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||||
DanBias::GameServerAPI::GameSetMapName(wch);
|
DanBias::GameServerAPI::GameSetMapName(wch);
|
||||||
}
|
}
|
||||||
|
void StandaloneGameServerCLI::GameSetGameMode(String^ value)
|
||||||
|
{
|
||||||
|
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||||
|
DanBias::GameServerAPI::GameSetGameMode(wch);
|
||||||
|
}
|
||||||
|
void StandaloneGameServerCLI::GameSetGameName(String^ value)
|
||||||
|
{
|
||||||
|
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||||
|
DanBias::GameServerAPI::GameSetGameName(wch);
|
||||||
|
}
|
||||||
|
|
||||||
void StandaloneGameServerCLI::GameSetMaxClients(const int val)
|
void StandaloneGameServerCLI::GameSetMaxClients(const int val)
|
||||||
{
|
{
|
||||||
DanBias::GameServerAPI::GameSetMaxClients(val);
|
DanBias::GameServerAPI::GameSetMaxClients(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandaloneGameServerCLI::GameSetGameMode(String^ value)
|
|
||||||
{
|
|
||||||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
|
||||||
DanBias::GameServerAPI::GameSetGameMode(wch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StandaloneGameServerCLI::GameSetGameTime(const int val)
|
void StandaloneGameServerCLI::GameSetGameTime(const int val)
|
||||||
{
|
{
|
||||||
DanBias::GameServerAPI::GameSetGameTime(val);
|
DanBias::GameServerAPI::GameSetGameTime(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int StandaloneGameServerCLI::GameGetMapId()
|
String^ StandaloneGameServerCLI::GameGetMapName()
|
||||||
{
|
{
|
||||||
return DanBias::GameServerAPI::GameGetMapId();
|
return gcnew String( DanBias::GameServerAPI::GameGetMapName());
|
||||||
}
|
}
|
||||||
|
|
||||||
int StandaloneGameServerCLI::GameGetMaxClients()
|
int StandaloneGameServerCLI::GameGetMaxClients()
|
||||||
|
@ -99,9 +105,9 @@ int StandaloneGameServerCLI::GameGetMaxClients()
|
||||||
return DanBias::GameServerAPI::GameGetMaxClients();
|
return DanBias::GameServerAPI::GameGetMaxClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
int StandaloneGameServerCLI::GameGetGameMode()
|
String^ StandaloneGameServerCLI::GameGetGameMode()
|
||||||
{
|
{
|
||||||
return DanBias::GameServerAPI::GameGetGameMode();
|
return gcnew String( DanBias::GameServerAPI::GameGetGameMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
int StandaloneGameServerCLI::GameGetGameTime()
|
int StandaloneGameServerCLI::GameGetGameTime()
|
||||||
|
@ -111,7 +117,7 @@ int StandaloneGameServerCLI::GameGetGameTime()
|
||||||
|
|
||||||
String^ StandaloneGameServerCLI::GameGetGameName()
|
String^ StandaloneGameServerCLI::GameGetGameName()
|
||||||
{
|
{
|
||||||
return gcnew String(DanBias::GameServerAPI::GameGetGameName());
|
return gcnew String( DanBias::GameServerAPI::GameGetGameName());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StandaloneGameServerCLI::GameStart()
|
bool StandaloneGameServerCLI::GameStart()
|
||||||
|
|
|
@ -47,13 +47,15 @@ namespace System { namespace Windows { namespace Interop
|
||||||
bool ServerIsRunning();
|
bool ServerIsRunning();
|
||||||
|
|
||||||
void GameSetMapName(String^ val);
|
void GameSetMapName(String^ val);
|
||||||
void GameSetMaxClients(const int val);
|
|
||||||
void GameSetGameMode(String^ val);
|
void GameSetGameMode(String^ val);
|
||||||
|
void GameSetGameName(String^ val);
|
||||||
|
void GameSetMaxClients(const int val);
|
||||||
void GameSetGameTime(const int val);
|
void GameSetGameTime(const int val);
|
||||||
int GameGetMapId();
|
|
||||||
int GameGetMaxClients();
|
int GameGetMaxClients();
|
||||||
int GameGetGameMode();
|
|
||||||
int GameGetGameTime();
|
int GameGetGameTime();
|
||||||
|
System::String^ GameGetMapName();
|
||||||
|
System::String^ GameGetGameMode();
|
||||||
System::String^ GameGetGameName();
|
System::String^ GameGetGameName();
|
||||||
bool GameStart();
|
bool GameStart();
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace LinearAlgebra
|
||||||
const ScalarType & operator [] ( int i ) const;
|
const ScalarType & operator [] ( int i ) const;
|
||||||
|
|
||||||
Quaternion<ScalarType> & operator = ( const Quaternion<ScalarType> &quaternion );
|
Quaternion<ScalarType> & operator = ( const Quaternion<ScalarType> &quaternion );
|
||||||
|
Quaternion<ScalarType> & operator *= ( const Quaternion<ScalarType> &quaternion );
|
||||||
Quaternion<ScalarType> & operator *= ( const ScalarType &scalar );
|
Quaternion<ScalarType> & operator *= ( const ScalarType &scalar );
|
||||||
Quaternion<ScalarType> & operator /= ( const ScalarType &scalar );
|
Quaternion<ScalarType> & operator /= ( const ScalarType &scalar );
|
||||||
Quaternion<ScalarType> & operator += ( const Quaternion<ScalarType> &quaternion );
|
Quaternion<ScalarType> & operator += ( const Quaternion<ScalarType> &quaternion );
|
||||||
|
@ -112,6 +113,12 @@ namespace LinearAlgebra
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const Quaternion<ScalarType> &quaternion )
|
||||||
|
{
|
||||||
|
return *this = *this * quaternion;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ScalarType>
|
template<typename ScalarType>
|
||||||
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const ScalarType &scalar )
|
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||||
{
|
{
|
||||||
|
|
|
@ -133,13 +133,7 @@ namespace Oyster
|
||||||
*/
|
*/
|
||||||
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
||||||
|
|
||||||
/** ! Deprecate !
|
std::string GetIpAddress();
|
||||||
* Do not use this furthermore, instead use void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
|
||||||
* @see DataRecieved
|
|
||||||
*/
|
|
||||||
//virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
|
|
||||||
|
|
||||||
virtual std::string GetIpAddress();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetworkClient(const NetworkClient& obj);
|
NetworkClient(const NetworkClient& obj);
|
||||||
|
|
|
@ -98,9 +98,9 @@ namespace Oyster
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NetClientList clients;
|
NetClientList clients;
|
||||||
|
int clientCount;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int clientCount;
|
|
||||||
struct PrivateSessionData;
|
struct PrivateSessionData;
|
||||||
PrivateSessionData* data;
|
PrivateSessionData* data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue