diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h index 7d9a9a5d..57c6008d 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h @@ -7,9 +7,6 @@ #include "EventButtonGUI.h" -//Only for testing because we don't have any other input -#include "../WindowManager/WindowShell.h" - namespace DanBias { namespace Client @@ -18,24 +15,25 @@ namespace DanBias class ButtonEllipse : public EventButtonGUI { public: - ButtonEllipse() - : EventButtonGUI(), radius(0) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, owner, pos, size, resize) {} - ButtonEllipse(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) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, pos, size, resize) {} - ButtonEllipse(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) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, owner, pos, size, resize) {} - ButtonEllipse(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) - {} - ButtonEllipse(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) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonEllipse() {} @@ -43,7 +41,6 @@ namespace DanBias //Circle vs point collision bool Collision(Oyster::Event::MouseInput& input) { - //Should come from the InputClass float xMouse = input.x, yMouse = input.y; double normx = (xMouse - pos.x) / size.x; diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h index 7f3db825..33098568 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h @@ -6,9 +6,6 @@ #define DANBIAS_CLIENT_BUTTON_RECTANGLE_H #include "EventButtonGUI.h" -#include -//Only for testing because we don't have any other input -#include "../WindowManager/WindowShell.h" namespace DanBias { @@ -18,55 +15,46 @@ namespace DanBias class ButtonRectangle : public EventButtonGUI { public: - ButtonRectangle() - : EventButtonGUI(), width(0), height(0) - {} 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) + 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, 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) + 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, 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) + 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, 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) + 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() {} - //Circle vs point collision + //Rectangle vs point collision bool Collision(Oyster::Event::MouseInput& input) { - //Should come from the InputClass float xMouse = input.x, yMouse = input.y; float widthTemp = pos.x - size.x * 0.5f; float widthTemp2 = pos.x + size.x * 0.5f; float heightTemp = pos.y - size.y * 0.5f; float heightTemp2 = pos.y + size.y * 0.5f; - //std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl; if(xMouse >= widthTemp && xMouse <= widthTemp2 && yMouse >= heightTemp && yMouse <= heightTemp2) diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index 3ae09043..c14d24f2 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -7,6 +7,7 @@ #include "EventHandler/EventButton.h" #include "DllInterfaces/GFXAPI.h" +#include "../WindowManager/WindowShell.h" namespace DanBias { @@ -37,26 +38,27 @@ namespace DanBias textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } 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) + 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); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } 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) + 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); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } EventButtonGUI(std::wstring textureName, std::wstring buttonText, @@ -66,6 +68,7 @@ namespace DanBias textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } virtual ~EventButtonGUI() @@ -92,15 +95,15 @@ namespace DanBias if(EventButton::GetState() == ButtonState_None) { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, backColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, backColor); } else if(EventButton::GetState() == ButtonState_Hover) { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, hoverColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, hoverColor); } else { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, pressedColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, pressedColor); } } @@ -121,15 +124,18 @@ namespace DanBias GetClientRect(WindowShell::GetHWND(), &r); if(resize == ResizeAspectRatio_Height) - size.y *= (float)r.right/(float)r.bottom; + resizedSize.y = size.y * ((float)r.right/(float)r.bottom); else if(resize == ResizeAspectRatio_Width) - size.x *= (float)r.bottom/(float)r.right; + resizedSize.x = size.x * ((float)r.bottom/(float)r.right); } protected: Oyster::Math::Float3 pos; Oyster::Math::Float2 size; + //The new calculated resize, it's only used for the button not the text right now. + Oyster::Math::Float2 resizedSize; + Oyster::Graphics::API::Texture texture; std::wstring buttonText; diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp index 12506d3c..0cf4500d 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -4,12 +4,19 @@ using namespace ::Oyster::Math3D; using namespace ::Utility::Value; +inline Quaternion Transform( const Quaternion &transformer, const Quaternion &transformee ) +{ +// return transformer * transformee; + return transformee * transformer; +} + 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; + this->pitchHaveChanged = false; } Camera_FPSV2::~Camera_FPSV2() {} @@ -21,6 +28,7 @@ Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera ) this->headOffset = camera.headOffset; this->body.translation = camera.body.translation; this->body.rotation = camera.body.rotation; + this->pitchHaveChanged = camera.pitchHaveChanged; return *this; } @@ -38,8 +46,14 @@ void Camera_FPSV2::SetPosition( const Float3 &translation ) void Camera_FPSV2::SetRotation( const Quaternion &rotation ) { + if( !Within(rotation.GetNorm(), .99f, 1.01f) ) + { // HACK: bug trap + const char *breakPoint = "Caught an invalid rotation!"; + } + this->body.rotation = rotation; - this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) ); + this->head.SetRotation( Transform(rotation, Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::SetAngular( const Float3 &axis ) @@ -64,6 +78,12 @@ void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRati void Camera_FPSV2::UpdateOrientation() { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; + } + Float4x4 orientation; OrientationMatrix( this->body.rotation, this->body.translation, orientation ); @@ -73,7 +93,8 @@ void Camera_FPSV2::UpdateOrientation() 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) ); + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::Move( const Float3 &deltaPosition ) @@ -84,8 +105,8 @@ void Camera_FPSV2::Move( const Float3 &deltaPosition ) void Camera_FPSV2::Rotate( const Quaternion &deltaRotation ) { - this->head.Rotate( deltaRotation ); this->body.rotation *= deltaRotation; + this->pitchHaveChanged = true; } void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis ) @@ -115,8 +136,13 @@ void Camera_FPSV2::StrafeLeft( Float distance ) void Camera_FPSV2::PitchUp( Float radian ) { + if( radian >= 0.5f ) + { // HACK: debugging + const char *breakPoint = ""; + } + 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) ); + this->pitchHaveChanged = true; } void Camera_FPSV2::PitchDown( Float radian ) @@ -147,6 +173,12 @@ const Float3 & Camera_FPSV2::GetPosition() const Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewMatrix( targetMem ); } @@ -157,11 +189,23 @@ const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewsProjMatrix( targetMem ); } Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( axis ); } @@ -177,6 +221,12 @@ Float3 Camera_FPSV2::GetUp() const Float3 Camera_FPSV2::GetLook() const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( -Float3::standard_unit_z ); } diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h index 7f66b185..210c9707 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -50,7 +50,7 @@ public: ::Oyster::Math::Float3 GetForward() const; private: - Camera_BasicV2 head; + mutable Camera_BasicV2 head; ::Oyster::Math::Float pitchUp; ::Oyster::Math::Float3 headOffset; struct @@ -58,6 +58,7 @@ private: ::Oyster::Math::Float3 translation; ::Oyster::Math::Quaternion rotation; } body; + mutable bool pitchHaveChanged; }; #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index ed04c009..4192779f 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -480,6 +480,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) { + if( !Within(position.Dot(position), 2500.0f, 90000.0f) ) + { // HACK: bug trap + const char *breakPoint = "Something is wrong."; + //position = Float3( 0.0f, 160.0f, 0.0f ); + } + this->privData->camera.SetPosition( position ); this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 7bd709cc..8c096617 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -126,9 +126,6 @@ void LanMenuState::ChangeState( ClientState next ) // attempt to connect to lobby if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) return; - //this->privData->nwClient->Disconnect(); - //if( !this->privData->nwClient->Reconnect() ) - //return; break; default: break; } diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 0c450f71..5f5a5341 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -157,8 +157,6 @@ std::vector> LevelParser::Parse(std::string filen break; } //this is a hotfix, fix so you only load the relevant data when the file is updated - - default: //Couldn't find specialType break; diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index f5ea5951..b2390a2d 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -49,7 +49,16 @@ namespace LinearAlgebra Quaternion operator - ( const Quaternion &quaternion ) const; Quaternion operator - ( ) const; + Quaternion & Conjugate( ); + Quaternion & Normalize( ); + Quaternion & Inverse( ); + Quaternion GetConjugate( ) const; + Quaternion GetNormalized( ) const; + Quaternion GetInversed( ) const; + ScalarType GetNorm( ) const; + ScalarType GetModulus( ) const; + }; /////////////////////////////////////////////////////////////////////////////////// @@ -205,11 +214,54 @@ namespace LinearAlgebra return Quaternion(-this->imaginary, -this->real); } + template + inline Quaternion & Quaternion::Conjugate( ) + { + this->imaginary = -this->imaginary; + return *this; + } + + template + inline Quaternion & Quaternion::Normalize( ) + { + return *this /= this->GetModulus(); + } + + template + inline Quaternion & Quaternion::Inverse( ) + { + return this->Conjugate() /= this->GetNorm(); + } + template inline Quaternion Quaternion::GetConjugate( ) const { return Quaternion(-this->imaginary, this->real ); } + + template + inline Quaternion Quaternion::GetNormalized( ) const + { + return *this / this->GetModulus(); + } + + template + inline Quaternion Quaternion::GetInversed( ) const + { + return this->GetConjugate() /= this->GetNorm(); + } + + template + inline ScalarType Quaternion::GetNorm( ) const + { + return this->imaginary.Dot(this->imaginary) + this->real * this->real; + } + + template + inline ScalarType Quaternion::GetModulus( ) const + { + return (ScalarType)::std::sqrt( this->GetNorm() ); + } } #endif \ No newline at end of file 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/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 5bd10165..fc561845 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -290,9 +290,12 @@ bool NetworkClient::Connect(ConnectionInfo& socket) bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { - if(this->IsConnected()) return false; - if(this->privateData) return false; - if(!this->privateData) this->privateData = new PrivateData(); + //Return true if you are already connected. + if(this->IsConnected()) + return true; + + if(!this->privateData) + this->privateData = new PrivateData(); int result = this->privateData->connection.Connect(port, serverIP, false); @@ -319,10 +322,10 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) bool NetworkClient::Reconnect() { + //Return true if you are already connected. if(this->IsConnected()) - return false; - //if(this->privateData) - //return false; + return true; + if(!this->privateData) this->privateData = new PrivateData(); int result = this->privateData->connection.Reconnect(); @@ -342,11 +345,10 @@ void NetworkClient::Disconnect() { if(!privateData) return; - privateData->thread.Terminate(); + privateData->thread.Stop(); privateData->connection.Disconnect(); this->privateData->sendQueue.Clear(); this->privateData->recieveQueue.Clear(); - } void NetworkClient::Send(CustomProtocolObject& protocol) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index a9abf75c..2cd992a2 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -91,14 +91,14 @@ int Connection::Reconnect() if(this->socket == -1 || this->socket == 0) InitiateSocket(); struct hostent *hostEnt; - if((hostEnt = gethostbyname(lastConnectAddr.c_str())) == NULL) + if((hostEnt = gethostbyname(this->lastConnectAddr.c_str())) == NULL) { return WSAGetLastError(); } struct sockaddr_in server; server.sin_family = AF_INET; - server.sin_port = htons(lastConnectPort); + server.sin_port = htons(this->lastConnectPort); server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr; SetBlockingMode(true);