diff --git a/.gitignore b/.gitignore index d5d239c2..57ccce7f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ Bin/DLL/ Bin/Executable/ Obj/ External/ +Code/Game/GameClient/GameClient.vcxproj.user diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 81650049..b978597c 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -64,7 +64,12 @@ namespace DanBias { WindowShell::CreateConsoleWindow(); //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) - if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC())) + + WindowShell::WINDOW_INIT_DESC winDesc; + winDesc.windowSize.x = 1280; + winDesc.windowSize.y = 720; + + if(! data.window->CreateWin(winDesc) ) return DanBiasClientReturn_Error; if( FAILED( InitDirect3D() ) ) @@ -136,9 +141,11 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - Oyster::Graphics::API::SetOptions(p); + p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f ); + //! @todo fix proper amb value + p.AmbientValue = 1.0f; - if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess) + if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, p) != Oyster::Graphics::API::Sucsess) return E_FAIL; return S_OK; } diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 3daafff3..349a88ec 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -201,7 +201,9 @@ + + @@ -226,7 +228,9 @@ + + diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h index f4dd69e1..7f3db825 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h @@ -21,21 +21,37 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() {} diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c6b54a7e..3ae09043 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -30,32 +30,40 @@ namespace DanBias class EventButtonGUI : public Oyster::Event::EventButton { public: - EventButtonGUI() - : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(1, 1, 1, 1) - {} - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); @@ -77,23 +85,23 @@ namespace DanBias if(EventButton::Enabled()) { // let the using dev decide what is rendered - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f)); + //Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f)); //Render att xPos and yPos //With width and height - //if(EventButton::GetState() == ButtonState_None) - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); - //} - //else if(EventButton::GetState() == ButtonState_Hover) - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); - //} - //else - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); - //} + if(EventButton::GetState() == ButtonState_None) + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, backColor); + } + else if(EventButton::GetState() == ButtonState_Hover) + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, hoverColor); + } + else + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, pressedColor); + } } } @@ -102,7 +110,7 @@ namespace DanBias { if(buttonText.size() > 0) { - Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, 0.0f), size*2.0f, size.y * 0.5f, textColor); + Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, -0.001f), size, size.y * 0.5f, textColor); } } @@ -126,6 +134,10 @@ namespace DanBias std::wstring buttonText; Oyster::Math::Float4 textColor; + + Oyster::Math::Float4 backColor; + Oyster::Math::Float4 hoverColor; + Oyster::Math::Float4 pressedColor; }; } } diff --git a/Code/Game/GameClient/GameClientState/Buttons/TextField.h b/Code/Game/GameClient/GameClientState/Buttons/TextField.h index c1fa79ac..18e5d23b 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/TextField.h +++ b/Code/Game/GameClient/GameClientState/Buttons/TextField.h @@ -20,7 +20,7 @@ namespace DanBias { namespace Client { public: TextField(); - TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); + TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); virtual ~TextField(); virtual void RenderText(); @@ -62,8 +62,8 @@ namespace DanBias { namespace Client } template - TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) - : ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize ) + TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) + : ButtonRectangle( backgroundTexture, L"", textColor, backColor, backColor, backColor, owner, pos, size, resize ) { this->fontHeight = 0.025f; this->lineSpacing = 0.001f; diff --git a/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp b/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp new file mode 100644 index 00000000..8454b3bd --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp @@ -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 ); +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_BasicV2.h b/Code/Game/GameClient/GameClientState/Camera_BasicV2.h new file mode 100644 index 00000000..aaa9d491 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_BasicV2.h @@ -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 \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp new file mode 100644 index 00000000..12506d3c --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -0,0 +1,186 @@ +#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::SetRotation( const Quaternion &rotation ) +{ + this->body.rotation = rotation; + this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) ); +} + +void Camera_FPSV2::SetAngular( const Float3 &axis ) +{ + this->SetRotation( Rotation(axis) ); +} + +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 ); +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h new file mode 100644 index 00000000..7f66b185 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -0,0 +1,63 @@ +#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 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 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 \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.cpp b/Code/Game/GameClient/GameClientState/GameClientState.cpp index dab88b2e..add8c15b 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.cpp +++ b/Code/Game/GameClient/GameClientState/GameClientState.cpp @@ -3,9 +3,14 @@ using namespace DanBias::Client; using namespace ::Oyster::Network; +const GameClientState::NetEvent GameClientState::event_processed = GameClientState::NetEvent(); + GameClientState::GameClientState() {} GameClientState::~GameClientState() {} -void GameClientState::DataRecieved( NetEvent e ) -{ /* do nothing */ } \ No newline at end of file +const GameClientState::NetEvent & GameClientState::DataRecieved( const GameClientState::NetEvent &message ) +{ + /* do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 3822c7b0..9891a16c 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -22,7 +22,9 @@ namespace DanBias { namespace Client ClientState_Quit }; - public: + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + GameClientState(); virtual ~GameClientState(); virtual bool Init( SharedStateContent &shared ) = 0; @@ -31,7 +33,11 @@ namespace DanBias { namespace Client virtual bool Release() = 0; virtual void ChangeState( ClientState next ) = 0; - virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + /****************************************************************** + * @param message of the event + * @return message or GameClientState::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); }; } } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 38ded541..bfd15532 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -2,7 +2,7 @@ #include "DllInterfaces/GFXAPI.h" #include #include "NetworkClient.h" -#include "Camera_FPS.h" +#include "Camera_FPSV2.h" #include #include "C_obj/C_Player.h" @@ -17,6 +17,7 @@ using namespace ::Oyster::Math3D; using namespace ::GameLogic; using namespace ::Utility::DynamicMemory; using namespace ::Utility::String; +using namespace ::Utility::Value; struct GameState::MyData { @@ -35,8 +36,10 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + bool key_Reload_Shaders; + C_Player player; - Camera_FPS camera; + Camera_FPSV2 camera; int myId; @@ -76,9 +79,14 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; + Graphics::API::Option gfxOp = Graphics::API::GetOption(); + Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; + this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); + //tell server ready this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); - + return true; } @@ -98,6 +106,9 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); + Float3 offset = Float3( 0.0f ); + offset.y = this->privData->player.getScale().y * 0.9f; + this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); } } @@ -113,6 +124,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { + this->ReadKeyInput(); return this->privData->nextState; } @@ -134,7 +146,8 @@ bool GameState::Render() auto dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - dynamicObject->second->Render(); + if( dynamicObject->second ) + dynamicObject->second->Render(); } Oyster::Graphics::API::EndFrame(); @@ -216,11 +229,25 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->privData->key_Reload_Shaders ) + { + //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); +#ifdef _DEBUG + Graphics::API::ReloadShaders(); +#endif + this->privData->key_Reload_Shaders = true; + } + } + else + this->privData->key_Reload_Shaders = false; + //send delta mouse movement { - this->privData->camera.YawRight( -this->privData->input->GetYaw() ); - this->privData->camera.PitchUp( this->privData->input->GetPitch() ); + this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); + this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f ); this->privData->camera.UpdateOrientation(); privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); @@ -285,13 +312,22 @@ void GameState::ReadKeyInput() // TODO: implement sub-menu } -void GameState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. - + if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) + { // TODO: Reconnect + const char *breakpoint = "temp trap"; + this->privData->nwClient->Disconnect(); + this->ChangeState( GameClientState::ClientState_Main ); + } + + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; + if( ProtocolIsGameplay(ID) ) { + CustomNetProtocol data = message.args.data.protocol; + switch(ID) { case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ @@ -307,13 +343,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); @@ -321,11 +357,11 @@ void GameState::DataRecieved( NetEventprivData->myId == decoded.object_ID ) - this->privData->camera.SetAngular( AngularAxis(rotation) ); + this->privData->camera.SetRotation( rotation ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: { Protocol_ObjectPositionRotation decoded(data); @@ -336,14 +372,17 @@ void GameState::DataRecieved( NetEventprivData->myId == decoded.object_ID ) { this->privData->camera.SetPosition( position ); - this->privData->camera.SetAngular( AngularAxis(rotation) ); + this->privData->camera.SetRotation( rotation ); } C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; - object->setPos( position ); - object->setRot( rotation ); + if( object ) + { + object->setPos( position ); + object->setRot( rotation ); + } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisabled: { @@ -356,7 +395,7 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects->erase( object ); } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: { Protocol_ObjectCreate decoded(data); @@ -377,13 +416,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID] = object; } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreatePlayer: { Protocol_ObjectCreatePlayer decoded(data); - this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotation, decoded.scale, decoded.owner ); + this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ @@ -402,4 +441,6 @@ void GameState::DataRecieved( NetEvent e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 0615f209..11ca95da 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -55,12 +55,13 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->nwClient = shared.network; this->privData->input = shared.input; - this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); // create guiElements - this->privData->connectIP = new TextField( L"earth_md.png", Float4(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); + this->privData->connectIP = new TextField( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); 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->SetFontHeight( 0.08f ); this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetTopAligned(); @@ -68,10 +69,10 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->guiElements.AddButton( this->privData->connectIP ); ButtonRectangle *guiElements; - guiElements = new ButtonRectangle( L"earth_md.png", L"Connect", Float4(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"color_white.png", L"Connect", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); - guiElements = new ButtonRectangle( L"earth_md.png", L"Exit", Float4(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"color_white.png", L"Exit", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); // bind guiElements collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index b05e90dc..43419e88 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -50,7 +50,7 @@ bool LobbyAdminState::Init( SharedStateContent &shared ) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler @@ -112,10 +112,10 @@ void LobbyAdminState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyAdminState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyAdminState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,7 @@ void LobbyAdminState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.h b/Code/Game/GameClient/GameClientState/LobbyAdminState.h index 49ae9274..7e201e94 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.h +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.h @@ -29,8 +29,8 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); - + const NetEvent & DataRecieved( const NetEvent &message ); + private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 23b27e3f..0b117016 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -50,7 +50,7 @@ bool LobbyState::Init( SharedStateContent &shared ) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), Float4(0.0f), Float4(0.0f), Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler @@ -112,10 +112,10 @@ void LobbyState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,8 @@ void LobbyState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyState.h b/Code/Game/GameClient/GameClientState/LobbyState.h index 694aaa38..496c54ed 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.h +++ b/Code/Game/GameClient/GameClientState/LobbyState.h @@ -31,7 +31,7 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index d71b050e..f34b9ad6 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -49,18 +49,22 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->nwClient = shared.network; this->privData->input = shared.input; - this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); // create buttons ButtonRectangle *button; + Float4 TextCol = Float4(1.0f,0.0f,1.0f,1.0f); + Float4 BackCol = Float4(1.0f,1.0f,1.0f,0.5f); + Float4 HoverCol = Float4(0.0f,1.0f,0.0f,1.0f); + Float4 PressCol = Float4(0.0f,0.0f,1.0f,1.0f); - button = new ButtonRectangle( L"earth_md.png", L"Create", Float4(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Create",TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float4(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Join", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float4(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Quit", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler @@ -73,6 +77,11 @@ GameClientState::ClientState MainState::Update( float deltaTime ) { MouseInput mouseState; { + bool test = this->privData->input->IsMousePressed(); + if(test) + { + int i = 0; + }; this->privData->input->GetMousePos( mouseState.x, mouseState.y ); mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } @@ -87,7 +96,7 @@ bool MainState::Render() Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); - Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); + Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) ); this->privData->guiElements.RenderTexture(); Graphics::API::StartTextRender(); diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index f50db40c..29906d77 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -90,16 +90,25 @@ void NetLoadState::ChangeState( ClientState next ) this->privData->nextState = next; } -void NetLoadState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & NetLoadState::DataRecieved( const GameClientState::NetEvent &message ) { // fetching the id data. - short ID = e.args.data.protocol[0].value.netShort; + short ID = message.args.data.protocol[0].value.netShort; - if( ID == protocol_Lobby_CreateGame && !this->privData->loading ) + if( ID == protocol_Lobby_CreateGame ) { - this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName ); - this->ChangeState( ClientState_Game ); - this->privData->loading = false; + if( !this->privData->loading ) + { + this->LoadGame( Protocol_LobbyCreateGame(message.args.data.protocol).mapName ); + this->ChangeState( ClientState_Game ); + this->privData->loading = false; + } + return GameClientState::event_processed; + } + else + { // HACK: Debug trap + const char *breakPoint = "Being greedy."; + return message; } } @@ -107,7 +116,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) { this->privData->loading = true; - LevelLoader loader; + LevelLoader loader( "..\\Content\\Worlds\\" ); auto objects = loader.LoadLevel( fileName ); auto object = objects.begin(); ObjectTypeHeader *oth; diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.h b/Code/Game/GameClient/GameClientState/NetLoadState.h index ea9f9f6a..16e32867 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.h +++ b/Code/Game/GameClient/GameClientState/NetLoadState.h @@ -21,7 +21,7 @@ namespace DanBias bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 0b817975..5d1a95ec 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -170,12 +170,12 @@ using namespace GameLogic; void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage) { - int damageDone = 0; - int forceThreashHold = 200000; + Oyster::Math::Float damageDone = 0; + Oyster::Math::Float forceThreashHold = 200000; if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough { - damageDone = (int)(kineticEnergyLoss * 0.10f); + damageDone = (kineticEnergyLoss * 0.10f); damageDone += ExtraDamage; //player.DamageLife(damageDone); } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 900799e3..ba294349 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -76,14 +76,12 @@ Game::PlayerData* Game::CreatePlayer() return this->players[i]; } -Game::LevelData* Game::CreateLevel() +Game::LevelData* Game::CreateLevel(const wchar_t mapName[255]) { if(this->level) return this->level; this->level = new LevelData(); - //this->level->level->InitiateLevel(1000); - this->level->level->InitiateLevel("../Content/Worlds/ccc.bias"); - + this->level->level->InitiateLevel(mapName); return this->level; } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 93e130f5..6623756f 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -58,9 +58,11 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - ObjectSpecialType GetObjectType() const override; + ObjectSpecialType GetObjectType() const override; int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; + void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const override; + Level *level; }; @@ -70,7 +72,7 @@ namespace GameLogic void GetAllPlayerPositions() const override; PlayerData* CreatePlayer() override; - LevelData* CreateLevel() override; + LevelData* CreateLevel(const wchar_t mapName[255] ) override; void CreateTeam() override; bool NewFrame() override; void SetFPS( int FPS ) override; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 30e86e8c..65d606d8 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -13,6 +13,7 @@ #include "GameLogicStates.h" #include #include "LevelLoader\ObjectDefines.h" +#include "DynamicArray.h" namespace GameLogic @@ -107,6 +108,7 @@ namespace GameLogic public: virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; + virtual void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& destMem) const = 0; }; class DANBIAS_GAMELOGIC_DLL GameAPI @@ -137,7 +139,7 @@ namespace GameLogic /** Creates a level * @return Returns a ILevelData container to use for level manipulation */ - virtual ILevelData* CreateLevel( void ) = 0; + virtual ILevelData* CreateLevel( const wchar_t mapName[255] ) = 0; /** Creates a team * @return ? diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index b007ce01..903cb959 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -50,4 +50,13 @@ int Game::LevelData::getNrOfDynamicObj()const IObjectData* Game::LevelData::GetObjectAt(int ID) const { return this->level->GetObj(ID); +} + +void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const +{ + mem.Resize(level->dynamicObjects.Size()); + for(int i = 0; i < (int)level->dynamicObjects.Size(); i++) + { + mem[i] = level->dynamicObjects[i]; + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 1b725b02..e7a77bbd 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -27,9 +27,7 @@ Game::PlayerData::PlayerData() } Game::PlayerData::PlayerData(int playerID,int teamID) { - Oyster::Physics::ICustomBody* rigidBody; this->player = new Player(); - } Game::PlayerData::~PlayerData() { diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 030f0eca..4106dabf 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -63,9 +63,9 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_RedExplosiveBox: { - int dmg = 50; + Oyster::Math::Float dmg = 50; Oyster::Math::Float force = 50; - int radie = 50; + Oyster::Math::Float radie = 50; gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); } break; @@ -197,12 +197,16 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic); return rigidBody; } -void Level::InitiateLevel(std::string levelPath) +bool Level::InitiateLevel(std::wstring levelPath) { LevelLoader ll; + ll.SetFolderPath(L"..\\Content\\Worlds\\"); std::vector> objects; objects = ll.LoadLevel(levelPath); + if(objects.size() == 0) + return false; + API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); API::Instance().SetGravity(200); int objCount = objects.size(); @@ -332,8 +336,9 @@ void Level::InitiateLevel(std::string levelPath) break; } } + return true; } -void Level::InitiateLevel(float radius) +bool Level::InitiateLevel(float radius) { API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); API::Instance().SetGravity(200); @@ -353,7 +358,7 @@ void Level::InitiateLevel(float radius) int offset = 0; for(int i =0; i< nrOfBoxex; i ++) { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); + rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); } @@ -385,17 +390,18 @@ void Level::InitiateLevel(float radius) }*/ // add crystal - ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++)); // add jumppad - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); + return true; } void Level::AddPlayerToTeam(Player *player, int teamID) @@ -419,7 +425,7 @@ int Level::getNrOfDynamicObj() } Object* Level::GetObj( int ID) const { - for (int i = 0; i < this->dynamicObjects.Size(); i++) + for (int i = 0; i < (int)this->dynamicObjects.Size(); i++) { if(this->dynamicObjects[i]->GetID() == ID) return this->dynamicObjects[i]; diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 623d04b2..14269c73 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -30,8 +30,8 @@ namespace GameLogic * Initiates a level for players to play on * @param levelPath: Path to a file that contains all information on the level ********************************************************/ - void InitiateLevel(std::string levelPath); - void InitiateLevel(float radius); + bool InitiateLevel(std::wstring levelPath); + bool InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index 8fe880f3..205da712 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -11,17 +11,17 @@ using namespace GameLogic::LevelFileLoader; struct LevelLoader::PrivData { LevelParser parser; - std::string folderPath; + std::wstring folderPath; }; LevelLoader::LevelLoader() : pData(new PrivData) { //standard path - pData->folderPath = ""; + pData->folderPath = L""; } -LevelLoader::LevelLoader(std::string folderPath) +LevelLoader::LevelLoader(std::wstring folderPath) : pData(new PrivData) { pData->folderPath = folderPath; @@ -31,22 +31,22 @@ LevelLoader::~LevelLoader() { } -std::vector> LevelLoader::LoadLevel(std::string fileName) +std::vector> LevelLoader::LoadLevel(std::wstring fileName) { return pData->parser.Parse(pData->folderPath + fileName); } -LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) +LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName) { return pData->parser.ParseHeader(pData->folderPath + fileName); } -std::string LevelLoader::GetFolderPath() +std::wstring LevelLoader::GetFolderPath() { return this->pData->folderPath; } -void LevelLoader::SetFolderPath(std::string folderPath) +void LevelLoader::SetFolderPath(std::wstring folderPath) { - + this->pData->folderPath = folderPath; } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index aa67c4f5..c14e2c4c 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -20,7 +20,7 @@ namespace GameLogic /*********************************************************** * Lets you set the standard folderpath for the levels ********************************************************/ - LevelLoader(std::string folderPath); + LevelLoader(std::wstring folderPath); ~LevelLoader(); /******************************************************** @@ -28,24 +28,24 @@ namespace GameLogic * @param fileName: Path/name to the level-file that you want to load. * @return: Returns all structs with objects and information about the level. ********************************************************/ - std::vector> LoadLevel(std::string fileName); + std::vector> LoadLevel(std::wstring fileName); /******************************************************** * Just for fast access for the meta information about the level. * @param fileName: Path to the level-file that you want to load. * @return: Returns the meta information about the level. ********************************************************/ - LevelMetaData LoadLevelHeader(std::string fileName); //. + LevelMetaData LoadLevelHeader(std::wstring fileName); //. /*********************************************************** * @return: Returns the current standard folder path ********************************************************/ - std::string GetFolderPath(); + std::wstring GetFolderPath(); /*********************************************************** * Sets the standard folder path ********************************************************/ - void SetFolderPath(std::string folderPath); + void SetFolderPath(std::wstring folderPath); private: struct PrivData; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 1e33361d..2d23f069 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -20,7 +20,7 @@ LevelParser::~LevelParser() { } -std::vector> LevelParser::Parse(std::string filename) +std::vector> LevelParser::Parse(std::wstring filename) { int bufferSize = 0; int counter = 0; @@ -32,6 +32,12 @@ std::vector> LevelParser::Parse(std::string filen Loader loader; char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + // Check if file was loaded, else return empty vector + if(!buffer) + { + return std::vector>(); + } + //Read format version LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); @@ -215,7 +221,7 @@ std::vector> LevelParser::Parse(std::string filen } //för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::string filename) +LevelMetaData LevelParser::ParseHeader(std::wstring filename) { int bufferSize = 0; int counter = 0; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 8f2a9150..d0cb1f03 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -17,10 +17,10 @@ namespace GameLogic ~LevelParser(); // - std::vector> Parse(std::string filename); + std::vector> Parse(std::wstring filename); // - LevelMetaData ParseHeader(std::string filename); + LevelMetaData ParseHeader(std::wstring filename); private: LevelLoaderInternal::FormatVersion formatVersion; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index 3e15315c..19ffa0f1 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -9,13 +9,13 @@ using namespace GameLogic::LevelFileLoader; using namespace Oyster::Resource; using namespace std; -char* Loader::LoadFile(std::string fileName, int &size) +char* Loader::LoadFile(std::wstring fileName, int &size) { //convert from string to wstring - std::wstring temp(fileName.begin(), fileName.end()); + //std::wstring temp(fileName.begin(), fileName.end()); //convert from wstring to wchar then loads the file - char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + char* buffer = (char*)OysterResource::LoadResource(fileName.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); size = OysterResource::GetResourceSize(buffer); return buffer; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h index 0433194e..6deb8900 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -17,7 +17,7 @@ namespace GameLogic public: Loader (){}; ~Loader(){}; - char* LoadFile(std::string fileName, int &size); + char* LoadFile(std::wstring fileName, int &size); //TODO: //Add functionality to load physicsObjects (hitboxes) diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 01d17c3e..131b2938 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -52,6 +52,7 @@ namespace GameLogic CollisionGeometryType_Box, CollisionGeometryType_Sphere, CollisionGeometryType_Cylinder, + CollisionGeometryType_TriangleMesh, CollisionGeometryType_Count, CollisionGeometryType_Unknown = -1 @@ -161,6 +162,12 @@ namespace GameLogic float radius; }; + struct BoundingVolumeTriangleMesh : public BoundingVolumeBase + { + //Null terminated + wchar_t* filename; + }; + struct BoundingVolume { CollisionGeometryType geoType; @@ -169,7 +176,16 @@ namespace GameLogic LevelLoaderInternal::BoundingVolumeBox box; LevelLoaderInternal::BoundingVolumeSphere sphere; LevelLoaderInternal::BoundingVolumeCylinder cylinder; + LevelLoaderInternal::BoundingVolumeTriangleMesh triangleMesh; }; + + virtual ~BoundingVolume() + { + if(geoType == CollisionGeometryType_TriangleMesh) + { + delete[] triangleMesh.filename; + } + } }; } diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index 826a52be..76d7d6c3 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -5,6 +5,7 @@ #include "ParseFunctions.h" #include "Packing/Packing.h" #include "Loader.h" +#include "Utilities.h" #include using namespace Oyster::Packing; @@ -119,7 +120,7 @@ namespace GameLogic int temp; - for(int i = 0; i < tempSize; i++) + for(int i = 0; i < (int)tempSize; i++) { memcpy(&temp, &buffer[start], 4); start += 4; @@ -149,7 +150,7 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength); + char* buf = loader.LoadFile(L"../Content/Worlds/cgf/" + Utility::String::StringToWstring(fileName, wstring()), fileLength); start = 0; LevelLoaderInternal::FormatVersion version; @@ -175,6 +176,17 @@ namespace GameLogic start += sizeof(volume.cylinder); break; + case CollisionGeometryType_TriangleMesh: + //Get string size + memcpy(&tempSize, &buf[start], sizeof(tempSize)); + start += sizeof(tempSize); + + //Get actual string + volume.triangleMesh.filename = new wchar_t[tempSize+1]; + memcpy(volume.triangleMesh.filename, &buf[start], tempSize); + volume.triangleMesh.filename[tempSize] = '\0'; + break; + default: break; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 79f34245..80969b29 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -90,7 +90,7 @@ void Player::BeginFrame() forwardDir.Normalize(); rightDir.Normalize(); Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->moveSpeed*0.2; + Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f; if (key_forward > 0.001) { @@ -122,7 +122,7 @@ void Player::BeginFrame() if (key_forward <= 0.001 && key_backward <= 0.001 && key_strafeRight <= 0.001 && key_strafeLeft <= 0.001 && key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.7f) { /* Dampen when on the ground and not being moved by the player */ - linearVelocity *= 0.2; + linearVelocity *= 0.2f; this->rigidBody->SetLinearVelocity (linearVelocity); } else diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 71202898..26909bbf 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -41,61 +41,41 @@ namespace GameLogic struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject { - short clientID; // The unuiqe id reprsenting a specific client - std::string modelName; - float worldMatrix[16]; - + char majorVersion; + char minorVersion; + std::string mapName; + Protocol_LobbyCreateGame() { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].type = Oyster::Network::NetAttributeType_Float; - } - this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].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; } - Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16]) + Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name) { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].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; - for (int i = 0; i <= 16; i++) - { - 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); + this->majorVersion = majorVersion; + this->minorVersion = minorVersion; + this->mapName = name; } Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o) { - int c = 1; - clientID = o[c++].value.netInt; - for (int i = 0; i <= 16; i++) - { - this->worldMatrix[i] = o[c++].value.netFloat; - } - modelName.assign(o[c++].value.netCharPtr); + this->majorVersion = o[1].value.netChar; + this->minorVersion = o[2].value.netChar; + this->mapName.assign(o[3].value.netCharPtr); } Oyster::Network::CustomNetProtocol GetProtocol() override { - int c = 1; - protocol[c++].value = clientID; - - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].value = this->worldMatrix[i]; - } - protocol.Set(c++, this->modelName); + protocol[1].value = this->majorVersion; + protocol[2].value = this->minorVersion; + protocol.Set(3, this->mapName); return protocol; } diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index a9c33cf3..6fcf6b05 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -5,6 +5,7 @@ #define DANBIASSERVER_CLIENT_OBJECT_H #include +#include #include #include #include @@ -17,27 +18,59 @@ namespace DanBias class GameClient { public: - GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::IPlayerData* player); + enum ClientState + { + ClientState_CreatingGame, + ClientState_Ready, + }; + + public: + GameClient(Utility::DynamicMemory::SmartPointer nwClient); virtual~GameClient(); - GameLogic::IPlayerData* GetPlayer(); - GameLogic::IPlayerData* ReleasePlayer(); - Utility::DynamicMemory::SmartPointer GetClient(); - Utility::DynamicMemory::SmartPointer ReleaseClient(); + inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } - float GetSinceLastResponse() const; - bool IsReady() const; - bool Equals(const Oyster::Network::NetworkClient* c); + inline bool Equals(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool Equals(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } + 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; } + ClientState GetState() const { return this->state; } + + + void SetPlayer(GameLogic::IPlayerData* player); void SetReadyState(bool isReady); + void SetAlias(std::wstring alias); + void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); + void SetState(ClientState state); + + GameLogic::IPlayerData* ReleasePlayer(); + Oyster::Network::NetClient ReleaseClient(); + + //NetworkSpecific + void SetOwner(Oyster::Network::NetworkSession* owner); + void UpdateClient(); private: GameLogic::IPlayerData* player; - Utility::DynamicMemory::SmartPointer client; + Oyster::Network::NetClient client; + bool isReady; float secondsSinceLastResponse; - }; + std::wstring alias; + std::wstring character; + + ClientState state; + }; }//End namespace DanBias + +typedef Utility::DynamicMemory::SmartPointer gClient; + #endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index d0cbbcc3..f62baa63 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -15,11 +15,18 @@ namespace DanBias { struct LobbyLevelData { - int mapNumber; int maxClients; - int gameMode; - int gameTime; - std::string gameName; + int gameTimeInMinutes; + std::wstring gameMode; + 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 { @@ -31,35 +38,44 @@ namespace DanBias void SetGameDesc(const LobbyLevelData& desc); void GetGameDesc(LobbyLevelData& desc); - bool StartGameSession(); + /** + * If param is true, the server will start a game session regardless of clients connected. + */ + bool StartGameSession( bool forceStart ); + + int GetGameSessionClientCount(); private: void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c); - 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 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 LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join: - 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 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 LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: - void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: + 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 LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: + void LobbyJoin(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 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 LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: + void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: + + private: + int FindClient(Oyster::Network::NetworkClient* c); private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; + void ProcessClients() override; + bool Attach(Utility::DynamicMemory::SmartPointer client) override; private: - Utility::WinTimer timer; - float refreshFrequency; + //Utility::WinTimer timer; + //float refreshFrequency; + Utility::DynamicMemory::LinkedList readyList; GameSession gameSession; LobbyLevelData description; Utility::DynamicMemory::SmartPointer sessionOwner; - + Utility::DynamicMemory::DynamicArray> gClients; }; }//End namespace DanBias #endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h index a9e8c63f..0a5a8a88 100644 --- a/Code/Game/GameServer/GameServerAPI.h +++ b/Code/Game/GameServer/GameServerAPI.h @@ -55,16 +55,24 @@ namespace DanBias static void NotifyWhenClientConnect(ClientConnectedNotify 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 int GameGetMapId(); - static int GameGetMaxClients(); - static int GameGetGameMode(); + static void GameSetMaxClients(const int& val); + static void GameSetGameName(const wchar_t* val); + static void GameSetMapName(const wchar_t* val); + static void GameSetGameMode(const wchar_t* val); + static int GameGetGameTime(); - static const char* GameGetGameName(); - static bool GameStart(); + static int GameGetMaxClients(); + static const wchar_t* GameGetGameMode(); + static const wchar_t* GameGetGameName(); + static const wchar_t* GameGetMapName(); + static int GetConnectedClientCount(); + + /* Starts a game + * @param forceStart If forceStart is true, server will start with or without clients. + * If there are clients not "ready" the will be stareted anyways. + */ + static bool GameStart(bool forceStart); };//End class DanBiasServer diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 3d86ea78..28e8bde3 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -31,12 +31,12 @@ namespace DanBias */ struct GameDescription { - int maxClients; - int mapNumber; - int gameMode; - int gameTime; + unsigned int maxClients; + std::wstring mapName; + std::wstring gameMode; + int gameTimeMinutes; Oyster::Network::NetworkSession* owner; - Utility::DynamicMemory::DynamicArray clients; + Utility::DynamicMemory::DynamicArray> clients; }; public: @@ -44,7 +44,7 @@ namespace DanBias virtual~GameSession(); /** Initiates and creates a game session. */ - bool Create(GameDescription& desc); + bool Create(GameDescription& desc, bool forceStart); /** Runs the game session (ie starts the game loop). */ void Run(); @@ -52,23 +52,27 @@ namespace DanBias /** Join an existing/running game session * @param client The client to attach to the session */ - bool Attach(Oyster::Network::NetClient client) override; - void CloseSession( bool dissconnectClients ) override; + bool Join(gClient client); + + //void CloseSession( bool dissconnectClients ) override; inline bool IsCreated() const { return this->isCreated; } 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: - // TODO: find out what this method does.. + // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent 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); //Derived from IThreadObject - void ThreadEntry() override; + void ThreadEntry( ) override; bool DoWork ( ) override; @@ -98,8 +102,8 @@ namespace DanBias //Private member variables private: - Utility::DynamicMemory::DynamicArray> clients; - Utility::DynamicMemory::SmartPointer sessionOwner; + Utility::DynamicMemory::DynamicArray gClients; + gClient sessionOwner; Oyster::Thread::OysterThread worker; GameLogic::GameAPI& gameInstance; GameLogic::ILevelData *levelData; @@ -115,6 +119,7 @@ namespace DanBias //TODO: Remove this uggly hax static GameSession* gameSession; + };//End GameSession }//End namespace DanBias #endif // !DANBIASSERVER_GAME_SESSION_H \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 3956fe57..81066450 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -12,51 +12,27 @@ using namespace DanBias; using namespace GameLogic; -GameClient::GameClient(SmartPointer client, GameLogic::IPlayerData* player) +GameClient::GameClient(Utility::DynamicMemory::SmartPointer nwClient) { - this->client = client; - this->player = player; + this->client = nwClient; + this->player = 0; isReady = false; + this->character = L"Unknown"; + this->alias = L"Unknown"; + this->secondsSinceLastResponse = 0.0f; } GameClient::~GameClient() { - this->client->Disconnect(); 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; -} -GameLogic::IPlayerData* GameClient::ReleasePlayer() -{ - GameLogic::IPlayerData *temp = this->player; - this->player = 0; - return temp; -} -SmartPointer GameClient::GetClient() -{ - return this->client; -} -SmartPointer GameClient::ReleaseClient() -{ - SmartPointer 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()); + this->player = player; } void GameClient::SetReadyState(bool r) { @@ -66,5 +42,44 @@ void GameClient::SetSinceLastResponse(float s) { this->secondsSinceLastResponse = s; } +void GameClient::SetAlias(std::wstring alias) +{ + this->alias = alias; +} +void GameClient::SetCharacter(std::wstring character) +{ + this->character = character; +} +void GameClient::SetState(ClientState state) +{ + this->state = state; +} +void GameClient::SetOwner(Oyster::Network::NetworkSession* owner) +{ + this->client->SetOwner(owner); +} +void GameClient::UpdateClient() +{ + switch (this->state) + { + case ClientState_Ready: + this->client->Update(); + break; + } +} + + +IPlayerData* GameClient::ReleasePlayer() +{ + IPlayerData* temp = this->player; + this->player = 0; + return temp; +} +NetClient GameClient::ReleaseClient() +{ + NetClient temp = this->client; + this->client = 0; + return temp; +} diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 6f4f0a47..cadfa53a 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -14,10 +14,10 @@ using namespace GameLogic; using namespace DanBias; GameLobby::GameLobby() -{ } +{ } GameLobby::~GameLobby() { - this->clients.Clear(); + this->gClients.Clear(); } void GameLobby::Release() { @@ -26,62 +26,86 @@ void GameLobby::Release() } void GameLobby::Update() { - 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]) { - this->clients[i]->Update(); + this->gClients[i]->GetClient()->Update(); } } } void GameLobby::SetGameDesc(const LobbyLevelData& desc) { this->description.gameMode = desc.gameMode; - this->description.gameTime = desc.gameTime; - this->description.mapNumber = desc.mapNumber; + this->description.gameName = desc.gameName; + this->description.mapName = desc.mapName; + this->description.gameTimeInMinutes = desc.gameTimeInMinutes; 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) { - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; + desc.gameTimeInMinutes = this->description.gameTimeInMinutes; 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( bool forceStart ) { -//Check if all clients is ready - if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) +//Check if all clients is ready, in not force start + if(!forceStart) { - GameSession::GameDescription desc; - desc.maxClients = this->description.maxClients; - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; - desc.owner = this; - desc.clients = this->clients; + if(!this->GetClientCount()) + { /*None connected*/ return false;} + else if( this->GetClientCount() != this->readyList.Size() ) + { /*Not enough connected*/ return false; } + } - if(desc.gameTime == 0.0f) - desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. + GameSession::GameDescription desc; + desc.maxClients = this->description.maxClients; + desc.gameMode = this->description.gameMode; + desc.gameTimeMinutes = this->description.gameTimeInMinutes; + desc.mapName = this->description.mapName; + desc.owner = this; + desc.clients = this->gClients; - if(desc.maxClients == 0) - desc.maxClients = 10; //note: should be fetched somewhere else.. + if(desc.gameTimeMinutes == 0) + desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. - this->clients.Clear(); //Remove clients from lobby list + if(desc.maxClients == 0) + desc.maxClients = 10; //note: should be fetched somewhere else.. + + this->gClients.Clear(); //Remove clients from lobby list - if(this->gameSession.Create(desc)) - { - this->gameSession.Run(); - - return true; - } - } - else + if(this->gameSession.Create(desc, forceStart)) { - //? + this->gameSession.Run(); + + return true; } + + return false; } +int GameLobby::GetGameSessionClientCount() +{ + return this->gameSession.GetClientCount(); +} void GameLobby::ClientEventCallback(NetEvent e) { @@ -95,9 +119,9 @@ void GameLobby::ClientEventCallback(NetEventGetID(), e.sender->GetIpAddress().c_str()); - e.sender->Disconnect(); - this->readyList.Remove(e.sender); - this->clients.Remove(e.sender); + //e.sender->Disconnect(); + //this->readyList.Remove(e.sender); + //this->gClients.Remove(e.sender); break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); @@ -111,21 +135,30 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointergameSession) { - Attach(client); + if(!this->Attach(client)) + { + client->Disconnect(); + } } else { - Attach(client); + if(!this->Attach(client)) + { + //Send message that lobby full + client->Disconnect(); + return; + } + Protocol_LobbyClientData p1; 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; - t.id = this->clients[i]->GetID(); - t.ip = this->clients[i]->GetIpAddress(); + t.id = client->GetID(); + t.ip = client->GetIpAddress(); t.team = 0; t.name = "Dennis är kung tycker Erik!"; p1.list.Push(t); @@ -139,4 +172,44 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointerSend(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 client) +{ + if(this->clientCount == this->description.maxClients) return false; + + client->SetOwner(this); + + 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; +} + + + + + + + + diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index d49f83fc..2c4f148a 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -12,27 +12,23 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie { switch (p[0].value.netShort) { - case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); + case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); break; - case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); + case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); 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; - //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); - //break; - case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); + case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c); break; - case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); + case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; - case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); + case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); break; - case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); + case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); break; - case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); break; - case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c); break; } } @@ -44,52 +40,75 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net { case Protocol_General_Status::States_ready: { - + int temp = FindClient(c); + if(temp != -1 ) + { + switch (this->gClients[temp]->GetState()) + { + case GameClient::ClientState_CreatingGame: + { + this->gameSession.Join(this->gClients[temp]); + this->gClients[temp] = 0; + } + break; + } + } + else + { + c->Disconnect(); + } } + break; case Protocol_General_Status::States_idle: { } + break; case Protocol_General_Status::States_leave: + break; case Protocol_General_Status::States_disconected: { Detach(c)->Disconnect(); } + break; } } void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c) { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->GetClient()->Send(p); + } + } 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) { if(this->sessionOwner->GetClient()->GetID() == c->GetID()) { - + //Send countdown timer before lobby shuts down + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + this->gClients[i]->GetClient()->Send(Protocol_LobbyStartGame(3.0f)); + } } else { //Someone else tried to start the server.. } } -//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& 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) +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::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c) { @@ -112,31 +131,48 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: else { this->readyList.Remove(c); + } } void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) { - NetClient temp; - bool found = false; - - //find client in waiting list - for (unsigned int i = 0; !found && i < this->clients.Size(); i++) + if(this->gameSession) { - if(this->clients[i]->GetID() == c->GetID()) + int temp = FindClient(c); + + //Something is wrong + if(temp == -1) { - temp = this->clients[i]; - found = true; + c->Disconnect(); + } + else + { + //Send game data + Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); + c->Send(lcg); + this->gClients[temp]->SetState(GameClient::ClientState_CreatingGame); } - } - - //Something is wrong - if(!found) - { - c->Disconnect(); } else { - //Send game data - this->gameSession.Attach(temp); + // Nothing.- } } + + +int GameLobby::FindClient(Oyster::Network::NetworkClient* c) +{ + int temp = -1; + + //find client in waiting list + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]->GetClient()->GetID() == c->GetID()) + { + temp = i; + break; + } + } + + return temp; +} \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 087fa7ff..f003fc50 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -118,69 +118,81 @@ void GameServerAPI::NotifyWhenClientDisconnect(ClientDisconnectedNotify func) else clientDisconnectedCallback = func; } -void GameServerAPI::GameSetMapName(const wchar_t* val) +void GameServerAPI::GameSetMapName(const wchar_t* val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.mapNumber = val; //TODO: implement + d.mapName = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetMaxClients(const int& val) +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); +} +void GameServerAPI::GameSetMaxClients(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); d.maxClients = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameMode(const wchar_t* val) +void GameServerAPI::GameSetGameTime(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.gameMode = val; //TODO: implement + d.gameTimeInMinutes = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameTime(const int& val) + +const wchar_t* GameServerAPI::GameGetMapName() { LobbyLevelData d; lobby.GetGameDesc(d); - d.gameTime = val; - lobby.SetGameDesc(d); + return d.mapName.c_str(); } -int GameServerAPI::GameGetMapId() -{ - LobbyLevelData d; - lobby.GetGameDesc(d); - return d.mapNumber; -} -int GameServerAPI::GameGetMaxClients() +int GameServerAPI::GameGetMaxClients() { LobbyLevelData d; lobby.GetGameDesc(d); return d.maxClients; } -int GameServerAPI::GameGetGameMode() +const wchar_t* GameServerAPI::GameGetGameMode() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameMode; + return d.gameMode.c_str(); } -int GameServerAPI::GameGetGameTime() +int GameServerAPI::GameGetGameTime() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameTime; + return d.gameTimeInMinutes; } -const char* GameServerAPI::GameGetGameName() +const wchar_t* GameServerAPI::GameGetGameName() { LobbyLevelData d; lobby.GetGameDesc(d); return d.gameName.c_str(); } -bool GameServerAPI::GameStart() +int GameServerAPI::GetConnectedClientCount() { - if(lobby.StartGameSession()) + return lobby.GetGameSessionClientCount(); +} + +bool GameServerAPI::GameStart( bool forceStart ) +{ + if(lobby.StartGameSession( forceStart )) { - return true; } return false; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index ca1572a1..6a9c09c2 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -19,11 +19,8 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias -{ - Utility::WinTimer testTimer; - int testID = -1; bool GameSession::DoWork( ) { @@ -46,9 +43,9 @@ namespace DanBias { int temp = -1; //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] && this->gClients[i]->Equals(e.sender)) { temp = i; } @@ -59,7 +56,7 @@ namespace DanBias this->Detach(e.sender)->Disconnect(); return; } - SmartPointer cl = this->clients[temp]; + SmartPointer cl = this->gClients[temp]; switch (e.args.type) { @@ -73,15 +70,48 @@ namespace DanBias break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: 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); 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) { @@ -246,7 +276,6 @@ namespace DanBias printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str()); } -}//End namespace DanBias diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index cf82cc61..933807a4 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -3,6 +3,7 @@ ///////////////////////////////////////////////////////////////////// #include "..\GameSession.h" #include "..\GameClient.h" +#include "..\GameLobby.h" #include #include #include @@ -24,217 +25,253 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias +GameSession* GameSession::gameSession = nullptr; + +GameSession::GameSession() + :gameInstance(GameAPI::Instance()) { - GameSession* GameSession::gameSession = nullptr; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; + this->gameSession = this; + this->logicFrameTime = DELTA_TIME_20; + this->networkFrameTime = DELTA_TIME_20; + this->networkTimer.reset(); + this->logicTimer.reset(); - GameSession::GameSession() - :gameInstance(GameAPI::Instance()) + memset(&this->description, 0, sizeof(GameDescription)); +} + +GameSession::~GameSession() +{ + this->worker.Terminate(); + this->clients.Clear(); + this->gameInstance; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; +} + +bool GameSession::Create(GameDescription& desc, bool forceStart) +{ + this->description = desc; +/* Do some error checking */ + if(!forceStart && desc.clients.Size() == 0) return false; + if(!desc.owner) return false; + if(this->isCreated) return false; + +/* standard initialization of some data */ + this->gClients.Resize((unsigned int)desc.maxClients); + for (unsigned int i = 0; i < desc.clients.Size(); i++) { - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - this->gameSession = this; - this->logicFrameTime = DELTA_TIME_20; - this->networkFrameTime = DELTA_TIME_20; - this->networkTimer.reset(); - this->logicTimer.reset(); - - memset(&this->description, 0, sizeof(GameDescription)); - } - - GameSession::~GameSession() - { - this->worker.Terminate(); - this->clients.Clear(); - this->gameInstance; - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - } - - bool GameSession::Create(GameDescription& desc) - { - this->description = desc; - /* Do some error checking */ - if(desc.clients.Size() == 0) return false; - if(!desc.owner) return false; - if(this->isCreated) return false; - - /* standard initialization of some data */ - NetworkSession::clients = desc.clients; - NetworkSession::clients.Resize((unsigned int)desc.maxClients); - this->clients.Resize((unsigned int)desc.maxClients); - this->owner = desc.owner; - - /* Initiate the game instance */ - if(!this->gameInstance.Initiate()) + if(desc.clients[i]) { - printf("Failed to initiate the game instance\n"); + this->clientCount++; + this->gClients[i] = desc.clients[i]; + this->gClients[i]->SetOwner(this); } + } + this->owner = desc.owner; - /* Create the players in the game instance */ - GameLogic::IPlayerData* p = 0; - for (unsigned int i = 0; i < desc.clients.Size(); i++) +/* Initiate the game instance */ + if(!this->gameInstance.Initiate()) + { + printf("Failed to initiate the game instance\n"); + } + +/* Create the players in the game instance */ + GameLogic::IPlayerData* p = 0; + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) { - if(desc.clients[i]) + if( (p = this->gameInstance.CreatePlayer()) ) { - if( (p = this->gameInstance.CreatePlayer()) ) - { - desc.clients[i]->SetOwner(this); - this->clients[i] = (new GameClient(desc.clients[i], p)); - } - else - { - printf("Failed to create player (%i)\n", i); - } + this->gClients[i]->SetPlayer(p); + } + else + { + printf("Failed to create player (%i)\n", i); } } - - /* Create the game level */ - if(!(this->levelData = this->gameInstance.CreateLevel())) - { - printf("Level not created!"); - return false; - } - - /* Set some game instance data options */ - this->gameInstance.SetSubscription(GameSession::ObjectMove); - this->gameInstance.SetSubscription(GameSession::ObjectDisabled); - this->gameInstance.SetFPS(60); - - this->description.clients.Clear(); - - this->isCreated = true; - - /* Create the worker thread */ - if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) - return false; - - return this->isCreated; } - void GameSession::Run() +/* Create the game level */ + if(!(this->levelData = this->gameInstance.CreateLevel(this->description.mapName.c_str()))) { - if(this->isRunning) return; - - if(this->clients.Size() > 0) - { - this->worker.Start(); - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); - this->isRunning = true; - } + printf("Level not created!"); + return false; } - void GameSession::ThreadEntry( ) - { - //List with clients that we are waiting on.. - DynamicArray> readyList;// = this->clients; +/* Set some game instance data options */ + this->gameInstance.SetSubscription(GameSession::ObjectMove); + this->gameInstance.SetSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetFPS(60); - //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++) - { - if(this->clients[i]) - { - if(this->clients[i]->IsReady()) - { - 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); - } - } - } + this->description.clients.Clear(); + + this->isCreated = true; + + /* Create the worker thread */ + if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) + return false; + + return this->isCreated; +} + +void GameSession::Run() +{ + if(this->isRunning) return; + + this->worker.Start(); + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); + this->isRunning = true; - unsigned int readyCounter = readyList.Size(); +} - //Sync with clients - while (readyCounter != 0) +void GameSession::ThreadEntry( ) +{ +//List with clients that we are waiting on.. + DynamicArray readyList;// = this->clients; + +//First we need to clean invalid clients, if any, and tell them to start loading game data + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) { - this->ProcessClients(); - for (unsigned int i = 0; i < readyList.Size(); i++) + readyList.Push(this->gClients[i]); + Protocol_LobbyCreateGame p((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); + readyList[readyList.Size() - 1]->GetClient()->Send(p); + } + } + + unsigned int readyCounter = readyList.Size(); + +//Sync with clients + while (readyCounter != 0) + { + this->ProcessClients(); + for (unsigned int i = 0; i < readyList.Size(); i++) + { + if(readyList[i] && readyList[i]->IsReady()) { - if(readyList[i] && readyList[i]->IsReady()) + //Need to send information about other players, to all players + for (unsigned int k = 0; k < this->gClients.Size(); k++) { - //Need to send information about other players, to all players - for (unsigned int k = 0; k < this->clients.Size(); k++) + if((this->gClients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->gClients[k]->GetClient()->GetID()) { - if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) - { - //Protocol_ObjectCreatePlayer - Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(), - this->clients[k]->GetPlayer()->GetRotation(), - this->clients[k]->GetPlayer()->GetScale(), - this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later.. - readyList[i]->GetClient()->Send(p); - } + IPlayerData* pl = this->gClients[k]->GetPlayer(); + Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), + pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + readyList[i]->GetClient()->Send(p); } - - readyCounter-- ; - readyList[i] = 0; } - } - Sleep(5); //TODO: This might not be needed here. - } - - for (unsigned int i = 0; i < this->clients.Size(); i++) - { - if(this->clients[i]) - { - this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + + readyCounter-- ; + readyList[i] = 0; } } + Sleep(5); //TODO: This might not be needed here. } - bool GameSession::Attach(Utility::DynamicMemory::SmartPointer client) +//Sync with clients before starting countdown + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(!this->isCreated) return false; - if(this->GetClientCount() == this->clients.Capacity()) return false; - - client->SetOwner(this); - - IPlayerData* player = this->gameInstance.CreatePlayer(); - if(!player) return false; - - SmartPointer obj = new GameClient(client, player); - - // Send the chosen mesh name - 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->gClients[i]) { - if(this->clients[i]) - { - IPlayerData* p = this->clients[i]->GetPlayer(); - Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - //Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - this->clients[i]->GetClient()->Send(oc); - } + this->gClients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5.0f)); } - - obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0)); - - for (unsigned int i = 0; i < this->clients.Size(); i++) - { - if(!clients[i]) - { - NetworkSession::clients[i] = client; - clients[i] = obj; - return true; - } - } - - return true; } +} - void GameSession::CloseSession( bool dissconnectClients ) +bool GameSession::Join(gClient gameClient) +{ + if(!this->isCreated) return false; + if(this->GetClientCount() == this->gClients.Capacity()) return false; + + gameClient->SetOwner(this); + + IPlayerData* playerData = this->gameInstance.CreatePlayer(); + if(!playerData) return false; + + gameClient->SetPlayer(playerData); + NetworkClient* nwClient = gameClient->GetClient(); + +// Send the player data only { - this->worker.Terminate(); - NetworkSession::CloseSession(true); - this->clients.Clear(); + Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), + playerData->GetID(), true, playerData->GetTeamID(), + /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); } -}//End namespace DanBias +// Send information about other clients + { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + IPlayerData* temp = this->gClients[i]->GetPlayer(); + Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), + temp->GetID(), false, temp->GetTeamID(), + /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); + } + } + } + +//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client + { + DynamicArray 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++; + } + } + } + + gameClient->SetState(GameClient::ClientState_Ready); + + return added; +} + +//DynamicArray 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(); +//} + diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp index 3a10b6ce..1065a28a 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp @@ -72,26 +72,32 @@ void StandaloneGameServerCLI::GameSetMapName(String^ value) pin_ptr wch = PtrToStringChars(value); DanBias::GameServerAPI::GameSetMapName(wch); } +void StandaloneGameServerCLI::GameSetGameMode(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameMode(wch); +} +void StandaloneGameServerCLI::GameSetGameName(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameName(wch); +} void StandaloneGameServerCLI::GameSetMaxClients(const int val) { DanBias::GameServerAPI::GameSetMaxClients(val); } -void StandaloneGameServerCLI::GameSetGameMode(String^ value) -{ - pin_ptr wch = PtrToStringChars(value); - DanBias::GameServerAPI::GameSetGameMode(wch); -} + void StandaloneGameServerCLI::GameSetGameTime(const int val) { DanBias::GameServerAPI::GameSetGameTime(val); } -int StandaloneGameServerCLI::GameGetMapId() +String^ StandaloneGameServerCLI::GameGetMapName() { - return DanBias::GameServerAPI::GameGetMapId(); + return gcnew String( DanBias::GameServerAPI::GameGetMapName()); } int StandaloneGameServerCLI::GameGetMaxClients() @@ -99,9 +105,9 @@ int StandaloneGameServerCLI::GameGetMaxClients() return DanBias::GameServerAPI::GameGetMaxClients(); } -int StandaloneGameServerCLI::GameGetGameMode() +String^ StandaloneGameServerCLI::GameGetGameMode() { - return DanBias::GameServerAPI::GameGetGameMode(); + return gcnew String( DanBias::GameServerAPI::GameGetGameMode()); } int StandaloneGameServerCLI::GameGetGameTime() @@ -111,10 +117,17 @@ int StandaloneGameServerCLI::GameGetGameTime() String^ StandaloneGameServerCLI::GameGetGameName() { - return gcnew String(DanBias::GameServerAPI::GameGetGameName()); + return gcnew String( DanBias::GameServerAPI::GameGetGameName()); } -bool StandaloneGameServerCLI::GameStart() +bool StandaloneGameServerCLI::GameStart(bool f) { - return DanBias::GameServerAPI::GameStart(); -} \ No newline at end of file + return DanBias::GameServerAPI::GameStart(f); +} +int StandaloneGameServerCLI::GetClientsConnectedCount() +{ + return DanBias::GameServerAPI::GetConnectedClientCount(); +} + + + diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h index 3fdd0713..576a7433 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h @@ -47,15 +47,18 @@ namespace System { namespace Windows { namespace Interop bool ServerIsRunning(); void GameSetMapName(String^ val); - void GameSetMaxClients(const int val); void GameSetGameMode(String^ val); + void GameSetGameName(String^ val); + void GameSetMaxClients(const int val); void GameSetGameTime(const int val); - int GameGetMapId(); + int GameGetMaxClients(); - int GameGetGameMode(); int GameGetGameTime(); + System::String^ GameGetMapName(); + System::String^ GameGetGameMode(); System::String^ GameGetGameName(); - bool GameStart(); + bool GameStart( bool forceStart ); + int GetClientsConnectedCount(); }; } } } diff --git a/Code/Game/LanServer/StandAloneLauncher/App.config b/Code/Game/LanServer/StandAloneLauncher/App.config index 32412984..efeb1570 100644 --- a/Code/Game/LanServer/StandAloneLauncher/App.config +++ b/Code/Game/LanServer/StandAloneLauncher/App.config @@ -1,5 +1,10 @@  + + +
+ + @@ -8,4 +13,11 @@ + + + + .\..\Content\ + + + diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs index df569295..73ef627c 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs @@ -36,32 +36,58 @@ this.label_listenPort = new System.Windows.Forms.Label(); this.panel_serverOptions = new System.Windows.Forms.Panel(); this.panel_commands = new System.Windows.Forms.Panel(); + this.timeLimit = new System.Windows.Forms.NumericUpDown(); + this.gameModes = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.forceStart = new System.Windows.Forms.CheckBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.labelClientsConnected = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.nrOfClients = new System.Windows.Forms.NumericUpDown(); + this.buttonStartGame = new System.Windows.Forms.Button(); this.panel_clientArea = new System.Windows.Forms.Panel(); this.ServerInfoTextArea = new System.Windows.Forms.RichTextBox(); this.splitter1 = new System.Windows.Forms.Splitter(); this.clientInfoBox = new System.Windows.Forms.ListBox(); - this.buttonStartGame = new System.Windows.Forms.Button(); - this.nrOfClients = new System.Windows.Forms.NumericUpDown(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.gameModes = new System.Windows.Forms.ComboBox(); - this.timeLimit = new System.Windows.Forms.NumericUpDown(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.mapName = new System.Windows.Forms.TextBox(); + this.panel_CommanArea = new System.Windows.Forms.Panel(); + this.label5 = new System.Windows.Forms.Label(); + this.mapName = new System.Windows.Forms.ComboBox(); + this.panelServerCommands = new System.Windows.Forms.Panel(); + this.buttonExecuteSend = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.dataProtocolFields = new System.Windows.Forms.TableLayoutPanel(); + this.buttonAddNewDataField = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.buttonsAtBottom = new System.Windows.Forms.TableLayoutPanel(); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit(); this.panel_serverOptions.SuspendLayout(); this.panel_commands.SuspendLayout(); - this.panel_clientArea.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); + this.panel_clientArea.SuspendLayout(); + this.panel_CommanArea.SuspendLayout(); + this.panelServerCommands.SuspendLayout(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); + this.dataProtocolFields.SuspendLayout(); + this.buttonsAtBottom.SuspendLayout(); this.SuspendLayout(); // // serverToggle // - this.serverToggle.Location = new System.Drawing.Point(9, 81); + this.serverToggle.Dock = System.Windows.Forms.DockStyle.Bottom; + this.serverToggle.Location = new System.Drawing.Point(0, 83); this.serverToggle.Name = "serverToggle"; - this.serverToggle.Size = new System.Drawing.Size(75, 23); + this.serverToggle.Size = new System.Drawing.Size(241, 20); this.serverToggle.TabIndex = 0; this.serverToggle.Text = "Start server"; this.serverToggle.UseVisualStyleBackColor = true; @@ -111,7 +137,7 @@ this.listenPort.Size = new System.Drawing.Size(95, 20); this.listenPort.TabIndex = 5; this.listenPort.Value = new decimal(new int[] { - 2048, + 15151, 0, 0, 0}); @@ -133,83 +159,123 @@ this.panel_serverOptions.Controls.Add(this.label_listenPort); this.panel_serverOptions.Controls.Add(this.lanBroadcast); this.panel_serverOptions.Controls.Add(this.label_serverName); - this.panel_serverOptions.Location = new System.Drawing.Point(12, 12); + this.panel_serverOptions.Dock = System.Windows.Forms.DockStyle.Top; + this.panel_serverOptions.Location = new System.Drawing.Point(0, 0); this.panel_serverOptions.Name = "panel_serverOptions"; - this.panel_serverOptions.Size = new System.Drawing.Size(183, 113); + this.panel_serverOptions.Size = new System.Drawing.Size(241, 103); this.panel_serverOptions.TabIndex = 6; // // panel_commands // - this.panel_commands.Controls.Add(this.mapName); this.panel_commands.Controls.Add(this.timeLimit); + this.panel_commands.Controls.Add(this.mapName); this.panel_commands.Controls.Add(this.gameModes); this.panel_commands.Controls.Add(this.label3); + this.panel_commands.Controls.Add(this.forceStart); this.panel_commands.Controls.Add(this.label2); this.panel_commands.Controls.Add(this.label4); + this.panel_commands.Controls.Add(this.label5); + this.panel_commands.Controls.Add(this.labelClientsConnected); this.panel_commands.Controls.Add(this.label1); this.panel_commands.Controls.Add(this.nrOfClients); this.panel_commands.Controls.Add(this.buttonStartGame); - this.panel_commands.Location = new System.Drawing.Point(12, 131); + this.panel_commands.Dock = System.Windows.Forms.DockStyle.Top; + this.panel_commands.Location = new System.Drawing.Point(0, 103); this.panel_commands.Name = "panel_commands"; - this.panel_commands.Size = new System.Drawing.Size(183, 230); + this.panel_commands.Size = new System.Drawing.Size(241, 188); this.panel_commands.TabIndex = 7; this.panel_commands.Visible = false; // - // panel_clientArea + // timeLimit // - this.panel_clientArea.Controls.Add(this.ServerInfoTextArea); - this.panel_clientArea.Controls.Add(this.splitter1); - this.panel_clientArea.Controls.Add(this.clientInfoBox); - this.panel_clientArea.Location = new System.Drawing.Point(202, 12); - this.panel_clientArea.Name = "panel_clientArea"; - this.panel_clientArea.Size = new System.Drawing.Size(303, 349); - this.panel_clientArea.TabIndex = 8; + this.timeLimit.Location = new System.Drawing.Point(112, 89); + this.timeLimit.Minimum = new decimal(new int[] { + 5, + 0, + 0, + 0}); + this.timeLimit.Name = "timeLimit"; + this.timeLimit.Size = new System.Drawing.Size(123, 20); + this.timeLimit.TabIndex = 11; + this.timeLimit.ThousandsSeparator = true; + this.timeLimit.Value = new decimal(new int[] { + 15, + 0, + 0, + 0}); // - // ServerInfoTextArea + // gameModes // - this.ServerInfoTextArea.BackColor = System.Drawing.SystemColors.ActiveCaptionText; - this.ServerInfoTextArea.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill; - this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info; - this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 152); - this.ServerInfoTextArea.Name = "ServerInfoTextArea"; - this.ServerInfoTextArea.ReadOnly = true; - this.ServerInfoTextArea.Size = new System.Drawing.Size(303, 197); - this.ServerInfoTextArea.TabIndex = 1; - this.ServerInfoTextArea.Text = ""; + this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.gameModes.FormattingEnabled = true; + this.gameModes.Items.AddRange(new object[] { + "Free-for-all", + "Team death-match"}); + this.gameModes.Location = new System.Drawing.Point(77, 61); + this.gameModes.Name = "gameModes"; + this.gameModes.Size = new System.Drawing.Size(158, 21); + this.gameModes.TabIndex = 10; // - // splitter1 + // label3 // - this.splitter1.Dock = System.Windows.Forms.DockStyle.Top; - this.splitter1.Location = new System.Drawing.Point(0, 147); - this.splitter1.Name = "splitter1"; - this.splitter1.Size = new System.Drawing.Size(303, 5); - this.splitter1.TabIndex = 2; - this.splitter1.TabStop = false; + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(8, 96); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(95, 13); + this.label3.TabIndex = 9; + this.label3.Text = "Time limit (minutes)"; // - // clientInfoBox + // forceStart // - this.clientInfoBox.Dock = System.Windows.Forms.DockStyle.Top; - this.clientInfoBox.FormattingEnabled = true; - this.clientInfoBox.Location = new System.Drawing.Point(0, 0); - this.clientInfoBox.Name = "clientInfoBox"; - this.clientInfoBox.Size = new System.Drawing.Size(303, 147); - this.clientInfoBox.TabIndex = 0; + this.forceStart.AutoSize = true; + this.forceStart.Checked = true; + this.forceStart.CheckState = System.Windows.Forms.CheckState.Checked; + this.forceStart.Location = new System.Drawing.Point(12, 120); + this.forceStart.Name = "forceStart"; + this.forceStart.Size = new System.Drawing.Size(115, 17); + this.forceStart.TabIndex = 1; + this.forceStart.Text = "Ignore empty lobby"; + this.forceStart.UseVisualStyleBackColor = true; // - // buttonStartGame + // label2 // - this.buttonStartGame.Location = new System.Drawing.Point(53, 195); - this.buttonStartGame.Name = "buttonStartGame"; - this.buttonStartGame.Size = new System.Drawing.Size(75, 23); - this.buttonStartGame.TabIndex = 6; - this.buttonStartGame.Text = "Start game"; - this.buttonStartGame.UseVisualStyleBackColor = true; - this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(8, 69); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(64, 13); + this.label2.TabIndex = 9; + this.label2.Text = "Game mode"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(9, 15); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(57, 13); + this.label4.TabIndex = 8; + this.label4.Text = "Map name"; + // + // labelClientsConnected + // + this.labelClientsConnected.AutoSize = true; + this.labelClientsConnected.Location = new System.Drawing.Point(131, 147); + this.labelClientsConnected.Name = "labelClientsConnected"; + this.labelClientsConnected.Size = new System.Drawing.Size(80, 13); + this.labelClientsConnected.TabIndex = 8; + this.labelClientsConnected.Text = "Game clients: 0"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 13); + this.label1.TabIndex = 8; + this.label1.Text = "Client limit"; // // nrOfClients // - this.nrOfClients.Location = new System.Drawing.Point(78, 36); + this.nrOfClients.Location = new System.Drawing.Point(72, 34); this.nrOfClients.Maximum = new decimal(new int[] { 20, 0, @@ -221,105 +287,307 @@ 0, 0}); this.nrOfClients.Name = "nrOfClients"; - this.nrOfClients.Size = new System.Drawing.Size(39, 20); + this.nrOfClients.Size = new System.Drawing.Size(163, 20); this.nrOfClients.TabIndex = 7; this.nrOfClients.Value = new decimal(new int[] { - 2, + 10, 0, 0, 0}); // - // label1 + // buttonStartGame // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(8, 38); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(53, 13); - this.label1.TabIndex = 8; - this.label1.Text = "Client limit"; + this.buttonStartGame.Dock = System.Windows.Forms.DockStyle.Bottom; + this.buttonStartGame.Location = new System.Drawing.Point(0, 166); + this.buttonStartGame.Name = "buttonStartGame"; + this.buttonStartGame.Size = new System.Drawing.Size(241, 22); + this.buttonStartGame.TabIndex = 6; + this.buttonStartGame.Text = "Start game"; + this.buttonStartGame.UseVisualStyleBackColor = true; + this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click); // - // label2 + // panel_clientArea // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(8, 69); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(64, 13); - this.label2.TabIndex = 9; - this.label2.Text = "Game mode"; + this.panel_clientArea.Controls.Add(this.ServerInfoTextArea); + this.panel_clientArea.Controls.Add(this.splitter1); + this.panel_clientArea.Controls.Add(this.clientInfoBox); + this.panel_clientArea.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_clientArea.Location = new System.Drawing.Point(241, 0); + this.panel_clientArea.Name = "panel_clientArea"; + this.panel_clientArea.Size = new System.Drawing.Size(494, 616); + this.panel_clientArea.TabIndex = 8; // - // gameModes + // ServerInfoTextArea // - this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.gameModes.FormattingEnabled = true; - this.gameModes.Items.AddRange(new object[] { - "Free-for-all", - "Team death-match"}); - this.gameModes.Location = new System.Drawing.Point(78, 66); - this.gameModes.Name = "gameModes"; - this.gameModes.Size = new System.Drawing.Size(99, 21); - this.gameModes.TabIndex = 10; + this.ServerInfoTextArea.BackColor = System.Drawing.SystemColors.ActiveCaptionText; + this.ServerInfoTextArea.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill; + this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info; + this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 269); + this.ServerInfoTextArea.Name = "ServerInfoTextArea"; + this.ServerInfoTextArea.ReadOnly = true; + this.ServerInfoTextArea.Size = new System.Drawing.Size(494, 347); + this.ServerInfoTextArea.TabIndex = 1; + this.ServerInfoTextArea.Text = ""; // - // timeLimit + // splitter1 // - this.timeLimit.Location = new System.Drawing.Point(109, 94); - this.timeLimit.Minimum = new decimal(new int[] { - 5, - 0, - 0, - 0}); - this.timeLimit.Name = "timeLimit"; - this.timeLimit.Size = new System.Drawing.Size(68, 20); - this.timeLimit.TabIndex = 11; - this.timeLimit.ThousandsSeparator = true; - this.timeLimit.Value = new decimal(new int[] { - 5, - 0, - 0, - 0}); + this.splitter1.Dock = System.Windows.Forms.DockStyle.Top; + this.splitter1.Location = new System.Drawing.Point(0, 264); + this.splitter1.Name = "splitter1"; + this.splitter1.Size = new System.Drawing.Size(494, 5); + this.splitter1.TabIndex = 2; + this.splitter1.TabStop = false; // - // label3 + // clientInfoBox // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(8, 96); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(95, 13); - this.label3.TabIndex = 9; - this.label3.Text = "Time limit (minutes)"; + this.clientInfoBox.Dock = System.Windows.Forms.DockStyle.Top; + this.clientInfoBox.FormattingEnabled = true; + this.clientInfoBox.Location = new System.Drawing.Point(0, 0); + this.clientInfoBox.Name = "clientInfoBox"; + this.clientInfoBox.Size = new System.Drawing.Size(494, 264); + this.clientInfoBox.TabIndex = 0; // - // label4 + // panel_CommanArea // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(9, 15); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(57, 13); - this.label4.TabIndex = 8; - this.label4.Text = "Map name"; + this.panel_CommanArea.Controls.Add(this.panelServerCommands); + this.panel_CommanArea.Controls.Add(this.panel_commands); + this.panel_CommanArea.Controls.Add(this.panel_serverOptions); + this.panel_CommanArea.Dock = System.Windows.Forms.DockStyle.Left; + this.panel_CommanArea.Location = new System.Drawing.Point(0, 0); + this.panel_CommanArea.Name = "panel_CommanArea"; + this.panel_CommanArea.Size = new System.Drawing.Size(241, 616); + this.panel_CommanArea.TabIndex = 9; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(23, 147); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(81, 13); + this.label5.TabIndex = 8; + this.label5.Text = "Lobby clients: 0"; // // mapName // - this.mapName.Location = new System.Drawing.Point(78, 7); + this.mapName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.mapName.FormattingEnabled = true; + this.mapName.IntegralHeight = false; + this.mapName.Items.AddRange(new object[] { + "Set default"}); + this.mapName.Location = new System.Drawing.Point(72, 7); this.mapName.Name = "mapName"; - this.mapName.Size = new System.Drawing.Size(98, 20); - this.mapName.TabIndex = 12; + this.mapName.Size = new System.Drawing.Size(163, 21); + this.mapName.TabIndex = 10; + // + // panelServerCommands + // + this.panelServerCommands.Controls.Add(this.dataProtocolFields); + this.panelServerCommands.Dock = System.Windows.Forms.DockStyle.Top; + this.panelServerCommands.Location = new System.Drawing.Point(0, 291); + this.panelServerCommands.Name = "panelServerCommands"; + this.panelServerCommands.Size = new System.Drawing.Size(241, 85); + this.panelServerCommands.TabIndex = 8; + this.panelServerCommands.Visible = false; + // + // buttonExecuteSend + // + this.buttonExecuteSend.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonExecuteSend.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonExecuteSend.Location = new System.Drawing.Point(116, 0); + this.buttonExecuteSend.Margin = new System.Windows.Forms.Padding(0); + this.buttonExecuteSend.Name = "buttonExecuteSend"; + this.buttonExecuteSend.Size = new System.Drawing.Size(117, 21); + this.buttonExecuteSend.TabIndex = 0; + this.buttonExecuteSend.Text = "Send"; + this.buttonExecuteSend.UseVisualStyleBackColor = true; + // + // panel2 + // + this.panel2.Controls.Add(this.button2); + this.panel2.Controls.Add(this.textBox1); + this.panel2.Controls.Add(this.comboBox1); + this.panel2.Controls.Add(this.numericUpDown1); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(4, 32); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(233, 21); + this.panel2.TabIndex = 0; + // + // comboBox1 + // + this.comboBox1.Dock = System.Windows.Forms.DockStyle.Left; + this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox1.FormattingEnabled = true; + this.comboBox1.IntegralHeight = false; + this.comboBox1.Items.AddRange(new object[] { + "netBool;", + "netChar;", + "netUChar;", + "netShort;", + "netUShort;", + "netInt;", + "netUInt;", + "netInt64;", + "netUInt64;", + "netFloat;", + "netDouble;", + "netCharPtr;"}); + this.comboBox1.Location = new System.Drawing.Point(42, 0); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(78, 21); + this.comboBox1.TabIndex = 10; + // + // numericUpDown1 + // + this.numericUpDown1.Dock = System.Windows.Forms.DockStyle.Left; + this.numericUpDown1.Location = new System.Drawing.Point(0, 0); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(42, 20); + this.numericUpDown1.TabIndex = 11; + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Left; + this.textBox1.Location = new System.Drawing.Point(120, 0); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(64, 20); + this.textBox1.TabIndex = 12; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35.29412F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 64.70588F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 110F)); + this.tableLayoutPanel1.Controls.Add(this.label6, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.label7, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.label8, 2, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(4, 4); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 1; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 27.05882F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(233, 21); + this.tableLayoutPanel1.TabIndex = 9; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(4, 1); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(18, 13); + this.label6.TabIndex = 8; + this.label6.Text = "ID"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(46, 1); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(31, 13); + this.label7.TabIndex = 8; + this.label7.Text = "Type"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(123, 1); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(34, 13); + this.label8.TabIndex = 8; + this.label8.Text = "Value"; + // + // dataProtocolFields + // + this.dataProtocolFields.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; + this.dataProtocolFields.ColumnCount = 1; + this.dataProtocolFields.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 21F)); + this.dataProtocolFields.Controls.Add(this.panel2, 0, 1); + this.dataProtocolFields.Controls.Add(this.tableLayoutPanel1, 0, 0); + this.dataProtocolFields.Controls.Add(this.buttonsAtBottom, 0, 2); + this.dataProtocolFields.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataProtocolFields.Location = new System.Drawing.Point(0, 0); + this.dataProtocolFields.Margin = new System.Windows.Forms.Padding(0); + this.dataProtocolFields.Name = "dataProtocolFields"; + this.dataProtocolFields.RowCount = 3; + this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 27F)); + this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 27F)); + this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.dataProtocolFields.Size = new System.Drawing.Size(241, 85); + this.dataProtocolFields.TabIndex = 9; + // + // buttonAddNewDataField + // + this.buttonAddNewDataField.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonAddNewDataField.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonAddNewDataField.Location = new System.Drawing.Point(0, 0); + this.buttonAddNewDataField.Margin = new System.Windows.Forms.Padding(0); + this.buttonAddNewDataField.Name = "buttonAddNewDataField"; + this.buttonAddNewDataField.Size = new System.Drawing.Size(116, 21); + this.buttonAddNewDataField.TabIndex = 1; + this.buttonAddNewDataField.Text = "Add field"; + this.buttonAddNewDataField.UseVisualStyleBackColor = true; + this.buttonAddNewDataField.Click += new System.EventHandler(this.buttonAddNewDataField_Click); + // + // button2 + // + this.button2.Dock = System.Windows.Forms.DockStyle.Fill; + this.button2.FlatAppearance.BorderColor = System.Drawing.Color.Black; + this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button2.Location = new System.Drawing.Point(184, 0); + this.button2.Margin = new System.Windows.Forms.Padding(0); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(49, 21); + this.button2.TabIndex = 0; + this.button2.Text = "remove"; + this.button2.UseVisualStyleBackColor = true; + // + // buttonsAtBottom + // + this.buttonsAtBottom.ColumnCount = 2; + this.buttonsAtBottom.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.buttonsAtBottom.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.buttonsAtBottom.Controls.Add(this.buttonAddNewDataField, 0, 0); + this.buttonsAtBottom.Controls.Add(this.buttonExecuteSend, 1, 0); + this.buttonsAtBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonsAtBottom.Location = new System.Drawing.Point(4, 60); + this.buttonsAtBottom.Name = "buttonsAtBottom"; + this.buttonsAtBottom.RowCount = 1; + this.buttonsAtBottom.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.buttonsAtBottom.Size = new System.Drawing.Size(233, 21); + this.buttonsAtBottom.TabIndex = 10; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(517, 373); + this.ClientSize = new System.Drawing.Size(735, 616); this.Controls.Add(this.panel_clientArea); - this.Controls.Add(this.panel_commands); - this.Controls.Add(this.panel_serverOptions); + this.Controls.Add(this.panel_CommanArea); this.Name = "Form1"; this.Text = "Form1"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClosingEvent); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).EndInit(); this.panel_serverOptions.ResumeLayout(false); this.panel_serverOptions.PerformLayout(); this.panel_commands.ResumeLayout(false); this.panel_commands.PerformLayout(); - this.panel_clientArea.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); + this.panel_clientArea.ResumeLayout(false); + this.panel_CommanArea.ResumeLayout(false); + this.panelServerCommands.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.dataProtocolFields.ResumeLayout(false); + this.buttonsAtBottom.ResumeLayout(false); this.ResumeLayout(false); } @@ -346,7 +614,25 @@ private System.Windows.Forms.NumericUpDown timeLimit; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox mapName; + private System.Windows.Forms.CheckBox forceStart; + private System.Windows.Forms.Label labelClientsConnected; + private System.Windows.Forms.Panel panel_CommanArea; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.ComboBox mapName; + private System.Windows.Forms.Panel panelServerCommands; + private System.Windows.Forms.Button buttonExecuteSend; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.TableLayoutPanel dataProtocolFields; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Button buttonAddNewDataField; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TableLayoutPanel buttonsAtBottom; } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.cs index 1240c333..8b7e9474 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.cs @@ -9,6 +9,9 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Interop; using System.Runtime.InteropServices; +using System.Threading; +using System.Timers; +using System.IO; namespace StandAloneLauncher { @@ -16,12 +19,22 @@ namespace StandAloneLauncher { System.Windows.Interop.StandaloneGameServerCLI gameServer; bool serverIsRunning = false; + bool gameIsStarted = false; public Form1() { InitializeComponent(); - + string[] maps = Directory.GetFiles("..\\Content\\Worlds\\"); + + for (int i = 0; i < maps.Length; i++) + { + string temp = maps[i].Split('\\').Last() ; + this.mapName.Items.Add(temp); + } + + this.gameModes.SelectedIndex = 0; + this.mapName.SelectedIndex = 0; } public bool Initiate() @@ -30,17 +43,17 @@ namespace StandAloneLauncher return true; } + public void Run() { while (this.Created) { Application.DoEvents(); - - //Do some stuff this.gameServer.ServerUpdate(); + this.labelClientsConnected.Text = "Clients connected: " + this.gameServer.GetClientsConnectedCount().ToString(); } } - + private void button1_serverToggle_Click(object sender, EventArgs e) { if (this.serverIsRunning) @@ -53,6 +66,7 @@ namespace StandAloneLauncher this.serverToggle.Text = "Start server"; this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server terminated!\n"); this.panel_commands.Visible = false; + this.panelServerCommands.Visible = false; } else { @@ -75,6 +89,7 @@ namespace StandAloneLauncher this.gameServer.ServerStart(); this.panel_commands.Visible = true; this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server initiated!\n\tListening on port " + this.listenPort.Value.ToString() + "\n\tLocal IP: " + info.serverIp + "\n"); + this.panelServerCommands.Visible = true; } else { @@ -85,18 +100,59 @@ namespace StandAloneLauncher private void buttonStartGame_Click(object sender, EventArgs e) { - //this.gameServer.GameSetGameMode(this.gameModes.SelectedText); - this.gameServer.GameSetGameTime((int)this.timeLimit.Value); - //this.gameServer.GameSetMapId(0); - this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value); - if (!this.gameServer.GameStart()) + if (!gameIsStarted) { - this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n"); + //this.gameServer.GameSetGameMode(this.gameModes.SelectedText); + this.gameServer.GameSetGameTime((int)this.timeLimit.Value); + this.gameServer.GameSetMapName(this.mapName.Text); + this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value); + + if (!(gameIsStarted = this.gameServer.GameStart(this.forceStart.Checked))) + { + this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n"); + } + else + { + this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n"); + this.buttonStartGame.Text = "Stop Game"; + + this.mapName.Enabled = false; + this.nrOfClients.Enabled = false; + this.gameModes.Enabled = false; + this.timeLimit.Enabled = false; + this.forceStart.Enabled = false; + } } else { - this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n"); + this.gameIsStarted = false; + this.buttonStartGame.Text = "Start Game"; + this.mapName.Enabled = true; + this.nrOfClients.Enabled = true; + this.gameModes.Enabled = true; + this.timeLimit.Enabled = true; + this.forceStart.Enabled = true; } } + + private void FormClosingEvent(object sender, FormClosingEventArgs e) + { + if (serverIsRunning) + { + this.gameServer.ServerStop(); + } + } + + private void buttonAddNewDataField_Click(object sender, EventArgs e) + { + this.dataProtocolFields.RowCount++; + this.dataProtocolFields.SetRow(this.buttonsAtBottom, this.dataProtocolFields.RowCount - 1); + + Panel p = new Panel(); + p = this.panel2; + + this.dataProtocolFields.RowStyles.Add(new RowStyle(SizeType.Absolute, 27)); + + } } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.Designer.cs b/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.Designer.cs index 18c7c5f4..5c383ce6 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.Designer.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.Designer.cs @@ -8,23 +8,31 @@ // //------------------------------------------------------------------------------ -namespace StandAloneLauncher.Properties -{ - - +namespace StandAloneLauncher.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute(".\\..\\Content\\")] + public string Dennis { + get { + return ((string)(this["Dennis"])); + } + set { + this["Dennis"] = value; + } + } } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.settings b/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.settings index 39645652..f260c659 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.settings +++ b/Code/Game/LanServer/StandAloneLauncher/Properties/Settings.settings @@ -1,7 +1,9 @@  - - - - - - + + + + + .\..\Content\ + + + \ No newline at end of file diff --git a/Code/Game/LanServer/StandAloneLauncher/StandAloneLauncher.csproj b/Code/Game/LanServer/StandAloneLauncher/StandAloneLauncher.csproj index 2d2c86fe..ec2a45b0 100644 --- a/Code/Game/LanServer/StandAloneLauncher/StandAloneLauncher.csproj +++ b/Code/Game/LanServer/StandAloneLauncher/StandAloneLauncher.csproj @@ -80,6 +80,7 @@ + diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index da790f75..f5ea5951 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -36,6 +36,7 @@ namespace LinearAlgebra const ScalarType & operator [] ( int i ) const; Quaternion & operator = ( const Quaternion &quaternion ); + Quaternion & operator *= ( const Quaternion &quaternion ); Quaternion & operator *= ( const ScalarType &scalar ); Quaternion & operator /= ( const ScalarType &scalar ); Quaternion & operator += ( const Quaternion &quaternion ); @@ -112,6 +113,12 @@ namespace LinearAlgebra return *this; } + template + Quaternion & Quaternion::operator *= ( const Quaternion &quaternion ) + { + return *this = *this * quaternion; + } + template Quaternion & Quaternion::operator *= ( const ScalarType &scalar ) { diff --git a/Code/Misc/Utilities/Resource/OResourceHandler.cpp b/Code/Misc/Utilities/Resource/OResourceHandler.cpp index 52d93af0..cc297f67 100644 --- a/Code/Misc/Utilities/Resource/OResourceHandler.cpp +++ b/Code/Misc/Utilities/Resource/OResourceHandler.cpp @@ -52,6 +52,8 @@ OHRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType ty } } + if(!resourceData) return 0; + return resourceData->GetResourceHandle(); } OHRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force) diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index c259a845..b97d62d7 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -337,7 +337,11 @@ namespace Utility template inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) - { return value < min ? Max( value, max ) : min; } + { + if( value < min ) return min; + if( value > max ) return max; + return value; + } template inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index ecb57bf9..90fb100d 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -40,12 +40,13 @@ CustomNetProtocol::CustomNetProtocol() { this->privateData = new PrivateData(); } -CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o) +CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) { this->privateData = new PrivateData(); this->privateData->attributes = o.privateData->attributes; } -const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) + +CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) { if(this->privateData) { @@ -56,11 +57,29 @@ const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) this->privateData->attributes = o.privateData->attributes; return *this; } + CustomNetProtocol::~CustomNetProtocol() { delete this->privateData; this->privateData = 0; } + +const NetAttributeContainer& CustomNetProtocol::operator[](int ID) const +{ + //if(!this->privateData) this->privateData = new PrivateData(); + if((unsigned int)ID >= this->privateData->attributes.Size()) + { + NetAttributeContainer temp; + + temp.type = NetAttributeType_UNKNOWN; + memset(&temp.value, 0, sizeof(NetAttributeValue)); + + this->privateData->attributes.Push(ID, temp); + } + + return this->privateData->attributes[ID]; +} + NetAttributeContainer& CustomNetProtocol::operator[](int ID) { //if(!this->privateData) this->privateData = new PrivateData(); diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index 48feb3a9..24df6ebf 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -130,10 +130,12 @@ namespace Oyster public: CustomNetProtocol(); ~CustomNetProtocol(); - CustomNetProtocol(CustomNetProtocol& o); - const CustomNetProtocol& operator=(CustomNetProtocol& o); + CustomNetProtocol( const CustomNetProtocol& o); + CustomNetProtocol& operator=(const CustomNetProtocol& o); + + const NetAttributeContainer& operator[](int ID) const; + NetAttributeContainer& operator[](int ID); - NetAttributeContainer& operator[](int ID); void Set(int id, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type); void Set(int ID, std::string s); const NetAttributeContainer& Get(int id); diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 96d149f3..69872fc1 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -96,6 +96,10 @@ struct NetworkClient::PrivateData : public IThreadObject //printf("\t(%i)\n", this->sendQueue.Size()); OysterByte temp; CustomNetProtocol p = this->sendQueue.Pop(); + + if(p[0].value.netShort == 304) + int i = 0; + this->translator.Pack(temp, p); errorCode = this->connection.Send(temp); diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 58d81360..6f037117 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -133,13 +133,7 @@ namespace Oyster */ virtual void DataRecieved(NetEvent e); - /** ! Deprecate ! - * Do not use this furthermore, instead use void DataRecieved(NetEvent e); - * @see DataRecieved - */ - //virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p); - - virtual std::string GetIpAddress(); + std::string GetIpAddress(); private: NetworkClient(const NetworkClient& obj); diff --git a/Code/Network/NetworkAPI/NetworkSession.h b/Code/Network/NetworkAPI/NetworkSession.h index f0677c77..b4e8e8fe 100644 --- a/Code/Network/NetworkAPI/NetworkSession.h +++ b/Code/Network/NetworkAPI/NetworkSession.h @@ -98,9 +98,9 @@ namespace Oyster protected: NetClientList clients; - - private: int clientCount; + + private: struct PrivateSessionData; PrivateSessionData* data; }; diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index ffd2869a..fcfd865c 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -61,8 +61,7 @@ namespace Oyster struct PostData { - int x; - int y; + float Amb; }; struct Text2D diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index f4ce303f..96e2bbe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -19,11 +19,19 @@ namespace Oyster Math::Float4x4 Projection; std::vector Lights; float deltaTime; +#ifdef _DEBUG + Model::Model* cube; + Model::Model* sphere; + + ID3D11RasterizerState* wire; +#endif } - API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion) + API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, API::Option o) { - Core::resolution = resulotion; + Core::resolution = o.Resolution; + Core::modelPath = o.modelPath; + Core::texturePath = o.texturePath; if(Core::Init::FullInit(Window, MSAA_Quality, Fullscreen) == Core::Init::Fail) { @@ -32,7 +40,33 @@ namespace Oyster Render::Resources::Gui::Text::Font = (ID3D11ShaderResourceView*)API::CreateTexture(L"font_generic.png"); Render::Resources::Init(); + Definitions::PostData pd; + pd.Amb = o.AmbientValue; + + void* data = Render::Resources::Post::Data.Map(); + memcpy(data,&pd,sizeof(Definitions::PostData)); + Render::Resources::Post::Data.Unmap(); + Render::Preparations::Basic::SetViewPort(); +#ifdef _DEBUG + //fix load model + cube = CreateModel(L"debug_cube.dan"); + sphere = CreateModel(L"debug_sphere.dan"); + + D3D11_RASTERIZER_DESC desc; + desc.CullMode = D3D11_CULL_BACK; + desc.FillMode = D3D11_FILL_WIREFRAME; + desc.FrontCounterClockwise = false; + desc.DepthBias = 0; + desc.DepthBiasClamp = 0; + desc.DepthClipEnable = true; + desc.SlopeScaledDepthBias = 0; + desc.ScissorEnable = false; + desc.MultisampleEnable = false; + desc.AntialiasedLineEnable = false; + + Core::device->CreateRasterizerState(&desc,&wire); +#endif return API::Sucsess; } @@ -77,6 +111,14 @@ namespace Oyster { Core::modelPath = option.modelPath; Core::texturePath = option.texturePath; + + Definitions::PostData pd; + pd.Amb = option.AmbientValue; + + void* data = Render::Resources::Post::Data.Map(); + memcpy(data,&pd,sizeof(Definitions::PostData)); + Render::Resources::Post::Data.Unmap(); + return API::Sucsess; } @@ -113,6 +155,11 @@ namespace Oyster void API::Clean() { +#ifdef _DEBUG + DeleteModel(cube); + DeleteModel(sphere); + SAFE_RELEASE(wire); +#endif DeleteTexture(Render::Resources::Gui::Text::Font); SAFE_DELETE(Core::viewPort); Core::loader.Clean(); @@ -127,6 +174,7 @@ namespace Oyster SAFE_RELEASE(Core::swapChain); SAFE_RELEASE(Core::deviceContext); SAFE_RELEASE(Core::device); + } void API::AddLight(Definitions::Pointlight light) @@ -145,6 +193,24 @@ namespace Oyster Render::Resources::InitShaders(); return State::Sucsess; } + + void API::StartRenderWireFrame() + { + Core::deviceContext->RSSetState(wire); + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); + } + + void API::RenderDebugCube(Math::Matrix world) + { + cube->WorldMatrix = world; + Render::DefaultRenderer::RenderScene(cube,1,View,Projection); + } + + void API::RenderDebugSphere(Math::Matrix world) + { + sphere->WorldMatrix = world; + Render::DefaultRenderer::RenderScene(sphere,1,View,Projection); + } #endif API::Option API::GetOption() @@ -153,6 +219,7 @@ namespace Oyster o.BytesUsed = Core::UsedMem; o.modelPath = Core::modelPath; o.texturePath = Core::texturePath; + o.Resolution = Core::resolution; return o; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index eea53939..71e12662 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -27,13 +27,30 @@ namespace Oyster struct Option { std::wstring modelPath, texturePath; + //between 0-1 + float AmbientValue; + + Math::Float2 Resolution; + + //Bytes on the GPU int BytesUsed; }; typedef void* Texture; - static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); + static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Option options); #ifdef _DEBUG static State ReloadShaders(); + + //should be called after rendered normal models, before GUI or Text rendering + static void StartRenderWireFrame(); + + //Render a unit cube with the presented WorldMatrix + static void RenderDebugCube(Math::Matrix world); + + //Render a unit Sphere with the presented WorldMatrix + static void RenderDebugSphere(Math::Matrix world); + + static void StartRenderFullModel(); #endif //! @todo Memory Leaks diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 9a0b0ae0..3f030911 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - true + false \ No newline at end of file diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index c0c2990e..22b71df7 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -16,7 +16,8 @@ namespace Oyster void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) { - Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1)); + Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); + Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass); Lights[1]; @@ -38,14 +39,6 @@ namespace Oyster data = Resources::Light::PointLightsData.Map(); memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); Resources::Light::PointLightsData.Unmap(); - - Definitions::PostData pd; - pd.x = (int)lc.Pixels.x; - pd.y = (int)lc.Pixels.y; - - data = Resources::Post::Data.Map(); - memcpy(data, &pd, sizeof(Definitions::PostData)); - Resources::Post::Data.Unmap(); } void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime) @@ -57,8 +50,8 @@ namespace Oyster if(models[i].Visible) { Definitions::PerModel pm; - pm.WV = View * models[i].WorldMatrix; - pm.WVP = Projection * pm.WV; + pm.WV = View * models[i].WorldMatrix.GetTranspose().GetInverse(); + pm.WVP = Projection * View * models[i].WorldMatrix; Model::ModelInfo* info = models[i].info; diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index b17fdfef..02e202e4 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -9,7 +9,7 @@ namespace Oyster namespace Render { const int TEXT_NR_LETTERS=95; - const float TEXT_SPACING=1.8f; + const float TEXT_SPACING=2.0f; void Gui::Begin2DRender() { @@ -20,8 +20,8 @@ namespace Oyster { Core::deviceContext->PSSetShaderResources(0,1,&tex); - pos *= 2; - pos -= 1; + pos.xy *= 2; + pos.xy -= 1; pos.y *= -1; Definitions::GuiData gd; diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 0c5bf592..124b1bf1 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -62,6 +62,7 @@ namespace Oyster ID3D11BlendState* Resources::RenderStates::bs = NULL; ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; + ID3D11DepthStencilView* Resources::Gui::depth = NULL; #pragma endregion @@ -159,7 +160,7 @@ namespace Oyster D3D11_RASTERIZER_DESC rdesc; rdesc.CullMode = D3D11_CULL_BACK; rdesc.FillMode = D3D11_FILL_SOLID; - rdesc.FrontCounterClockwise = false; + rdesc.FrontCounterClockwise = true; rdesc.DepthBias = 0; rdesc.DepthBiasClamp = 0; rdesc.DepthClipEnable = true; @@ -304,6 +305,7 @@ namespace Oyster ID3D11Texture1D *pTexture1; Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1 ); + Core::UsedMem += T1desc.Width * 16; Core::device->CreateShaderResourceView( pTexture1, 0, &Light::SSAOKernel ); pTexture1->Release(); @@ -323,8 +325,33 @@ namespace Oyster ID3D11Texture2D *pTexture2; Core::device->CreateTexture2D( &T2desc, &rnd, &pTexture2 ); + Core::UsedMem += T2desc.Height * T2desc.Width * 16; Core::device->CreateShaderResourceView( (pTexture2), 0, &Light::SSAORandom ); pTexture2->Release(); + + //create Depth Buffer + D3D11_TEXTURE2D_DESC dTDesc; + dTDesc.MipLevels=1; + dTDesc.ArraySize=1; + dTDesc.Format = DXGI_FORMAT_D32_FLOAT; + dTDesc.Usage = D3D11_USAGE_DEFAULT; + dTDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + dTDesc.CPUAccessFlags=0; + dTDesc.MiscFlags=0; + dTDesc.Height = (UINT)Core::resolution.y; + dTDesc.Width = (UINT)Core::resolution.x; + dTDesc.SampleDesc.Count=1; + dTDesc.SampleDesc.Quality=0; + + ID3D11Texture2D* depthstencil; + Core::device->CreateTexture2D(&dTDesc,0,&depthstencil); + Core::UsedMem += dTDesc.Height * dTDesc.Width * 4; + Core::device->CreateDepthStencilView(depthstencil,NULL,&Gui::depth); + depthstencil->Release(); + + + D3D11_DEPTH_STENCIL_DESC dDesc; + return Core::Init::Success; } @@ -390,10 +417,13 @@ namespace Oyster Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D"); Gui::Pass.Shaders.Pixel = GetShader::Pixel(L"2D"); Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D"); + Gui::Pass.RTV.push_back(GBufferRTV[2]); Gui::Pass.CBuffers.Geometry.push_back(Gui::Data); Gui::Pass.CBuffers.Pixel.push_back(Color); + Gui::Pass.depth = Gui::depth; + D3D11_INPUT_ELEMENT_DESC indesc2D[] = { { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, @@ -405,6 +435,7 @@ namespace Oyster Gui::Pass.RenderStates.SampleCount = 1; Gui::Pass.RenderStates.SampleState = RenderStates::ss; Gui::Pass.RenderStates.BlendState = RenderStates::bs; + Gui::Pass.RenderStates.DepthStencil = RenderStates::dsState; ////---------------- Blur Pass Setup ---------------------------- Blur::HorPass.Shaders.Compute = GetShader::Compute(L"BlurHor"); @@ -442,9 +473,13 @@ namespace Oyster Gui::Text::Pass.CBuffers.Pixel.push_back(Color); Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font); Gui::Text::Pass.RTV.push_back(GBufferRTV[2]); + + Gui::Text::Pass.depth = Gui::depth; + Gui::Text::Pass.RenderStates.SampleCount = 1; Gui::Text::Pass.RenderStates.SampleState = RenderStates::ss; Gui::Text::Pass.RenderStates.BlendState = RenderStates::bs; + Gui::Text::Pass.RenderStates.DepthStencil = RenderStates::dsState; return Core::Init::Success; } @@ -510,6 +545,8 @@ namespace Oyster SAFE_RELEASE(Gui::Text::Pass.RenderStates.BlendState); SAFE_RELEASE(Gui::Text::Pass.IAStage.Layout); + + SAFE_RELEASE(Gui::depth); } } } diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index 6b4e140e..665ab8dc 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -64,6 +64,7 @@ namespace Oyster { static Core::PipelineManager::RenderPass Pass; static Core::Buffer Data; + static ID3D11DepthStencilView* depth; struct Text { static Core::PipelineManager::RenderPass Pass; diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl index 86fea579..56b6294f 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl @@ -4,19 +4,19 @@ void main(point Vertex2DIn input[1],inout TriangleStream Quads) { Pixel2DIn output; - output.Pos = mul(float4(-1,-1,1,1) ,Translation); + output.Pos = mul(float4(-1,-1,0,1) ,Translation); output.Uv = float2(0,1); Quads.Append(output); - output.Pos = mul(float4(-1,1,1,1), Translation); + output.Pos = mul(float4(-1,1,0,1), Translation); output.Uv = float2(0,0); Quads.Append(output); - output.Pos = mul(float4(1,-1,1,1), Translation); + output.Pos = mul(float4(1,-1,0,1), Translation); output.Uv = float2(1,1); Quads.Append(output); - output.Pos = mul(float4(1,1,1,1), Translation); + output.Pos = mul(float4(1,1,0,1), Translation); output.Uv = float2(1,0); Quads.Append(output); } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl b/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl index 4e0bed02..feefbed7 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl @@ -7,22 +7,22 @@ void main(point Text2DIn input[1],inout TriangleStream Quads) float endoff=startoff+input[0].coff; Pixel2DIn output; - output.Pos = mul(float4(-1,-1,1,1), Translation); + output.Pos = mul(float4(-1,-1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(startoff,1); Quads.Append(output); - output.Pos = mul(float4(-1,1,1,1), Translation); + output.Pos = mul(float4(-1,1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(startoff,0); Quads.Append(output); - output.Pos = mul(float4(1,-1,1,1), Translation); + output.Pos = mul(float4(1,-1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(endoff,1); Quads.Append(output); - output.Pos = mul(float4(1,1,1,1), Translation); + output.Pos = mul(float4(1,1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(endoff,0); Quads.Append(output); diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl index aeb89bda..a6843985 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl @@ -27,7 +27,7 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask); + outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask); //outTex[ThreadID.xy + Start] = inTex[ThreadID.xy + Start]; } diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl index 24f873db..2933283e 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl @@ -11,10 +11,10 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID } if(gThreadID.y >= N-blurRadius) { - int y = min(ThreadID.y+blurRadius, Stop.y-1); + int y = min(ThreadID.y +blurRadius, Stop.y-1); gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start]; } - gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)]; + gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);; + outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);; //outTex[ThreadID.xy + Start] = inTex[ThreadID.xy+ Start]; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 0c6ad9ca..decf5526 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -8,11 +8,9 @@ SamplerState S1 : register(s0); cbuffer Size : register(b0) { - int2 Pixels; + float AmbFactor; } -#define AmbFactor 0.1f; - float4 SuperSample(float4 Glow, uint3 DTid) { // Line X @@ -20,7 +18,7 @@ float4 SuperSample(float4 Glow, uint3 DTid) index += float2(0,Output.Length.y/2); index = index / Output.Length; Glow = Ambient.SampleLevel(S1, index,1); - Glow = Glow * Glow.w*10; + Glow = Glow; return Glow; } @@ -30,13 +28,10 @@ void main( uint3 DTid : SV_DispatchThreadID ) { float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w*/, 0); - //float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; - - Glow = SuperSample(Glow,DTid); float4 GUI; - uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); + uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; PostLight = PostLight + Light.xyz + Glow; GUI = float4(Ambient[index]); @@ -44,4 +39,5 @@ void main( uint3 DTid : SV_DispatchThreadID ) Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1); //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(0,Output.Length.y*0.5f)].xyz,1); + //Output[DTid.xy] = Ambient[DTid.xy]; } \ No newline at end of file