Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameServer
This commit is contained in:
commit
8cf0087a95
|
@ -327,7 +327,11 @@ void GameState::ReadKeyInput()
|
||||||
{
|
{
|
||||||
static const float mouseSensitivity = Radian( 1.0f );
|
static const float mouseSensitivity = Radian( 1.0f );
|
||||||
this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity );
|
this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity );
|
||||||
this->privData->nwClient->Send( Protocol_PlayerLeftTurn(this->privData->input->GetYaw() * mouseSensitivity) );
|
float yaw = this->privData->input->GetYaw();
|
||||||
|
if( yaw != 0.0f )
|
||||||
|
{
|
||||||
|
this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shoot
|
// shoot
|
||||||
|
|
|
@ -300,6 +300,7 @@ bool Level::InitiateLevel(std::wstring levelPath)
|
||||||
Object* dynamicGameObj = CreateGameObj(dynamicObjData, rigidBody_Dynamic);
|
Object* dynamicGameObj = CreateGameObj(dynamicObjData, rigidBody_Dynamic);
|
||||||
if (dynamicGameObj != NULL)
|
if (dynamicGameObj != NULL)
|
||||||
{
|
{
|
||||||
|
dynamicGameObj->GetRigidBody()->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||||
this->dynamicObjects.Push((DynamicObject*)dynamicGameObj);
|
this->dynamicObjects.Push((DynamicObject*)dynamicGameObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,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)
|
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 */
|
/* Dampen when on the ground and not being moved by the player */
|
||||||
linearVelocity *= 0.2f;
|
linearVelocity *= 0.2f;
|
||||||
|
|
|
@ -97,6 +97,8 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn;
|
this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn;
|
||||||
this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
|
this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
|
||||||
|
// deltaRadian
|
||||||
|
this->protocol[1].type = ::Oyster::Network::NetAttributeType_Float;
|
||||||
this->deltaRadian = deltaRadian;
|
this->deltaRadian = deltaRadian;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
<ClCompile Include="Source\Win32\Win32Mouse.cpp" />
|
<ClCompile Include="Source\Win32\Win32Mouse.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Include\ApplicationKeyboard.h" />
|
||||||
<ClInclude Include="Include\Common.h" />
|
<ClInclude Include="Include\Common.h" />
|
||||||
<ClInclude Include="Include\Input.h" />
|
<ClInclude Include="Include\Input.h" />
|
||||||
<ClInclude Include="Include\InputManager.h" />
|
<ClInclude Include="Include\InputManager.h" />
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
<ClInclude Include="Include\Keyboard.h" />
|
<ClInclude Include="Include\Keyboard.h" />
|
||||||
<ClInclude Include="Include\Mouse.h" />
|
<ClInclude Include="Include\Mouse.h" />
|
||||||
<ClInclude Include="Include\PreReq.h" />
|
<ClInclude Include="Include\PreReq.h" />
|
||||||
|
<ClInclude Include="Include\Win32\Win32ApplicationKeyboard.h" />
|
||||||
<ClInclude Include="Include\Win32\Win32Input.h" />
|
<ClInclude Include="Include\Win32\Win32Input.h" />
|
||||||
<ClInclude Include="Include\Win32\Win32Keyboard.h" />
|
<ClInclude Include="Include\Win32\Win32Keyboard.h" />
|
||||||
<ClInclude Include="Include\Win32\Win32Mouse.h" />
|
<ClInclude Include="Include\Win32\Win32Mouse.h" />
|
||||||
|
|
|
@ -189,7 +189,7 @@ float InputClass::GetPitch( )
|
||||||
float InputClass::GetYaw( )
|
float InputClass::GetYaw( )
|
||||||
{
|
{
|
||||||
float dX = (static_cast<float>( m_mouseState.lX)/5);
|
float dX = (static_cast<float>( m_mouseState.lX)/5);
|
||||||
return -dX;
|
return dX;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputClass::IsMousePressed()
|
bool InputClass::IsMousePressed()
|
||||||
|
|
|
@ -0,0 +1,218 @@
|
||||||
|
#include "ConnectionUDP.h"
|
||||||
|
|
||||||
|
#include <WinSock2.h>
|
||||||
|
|
||||||
|
using namespace Oyster::Network;
|
||||||
|
|
||||||
|
ConnectionUDP::ConnectionUDP()
|
||||||
|
{
|
||||||
|
this->ipSize = 16;
|
||||||
|
this->socket = -1;
|
||||||
|
this->stillSending = false;
|
||||||
|
this->closed = true;
|
||||||
|
this->Address = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionUDP::ConnectionUDP( int socket )
|
||||||
|
{
|
||||||
|
this->ipSize = 16;
|
||||||
|
this->socket = socket;
|
||||||
|
this->stillSending = false;
|
||||||
|
this->closed = true;
|
||||||
|
this->Address = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionUDP::~ConnectionUDP()
|
||||||
|
{
|
||||||
|
closesocket( this->socket );
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::Connect(unsigned short port, const char serverName[])
|
||||||
|
{
|
||||||
|
this->port = port;
|
||||||
|
|
||||||
|
closed = false;
|
||||||
|
stillSending = true;
|
||||||
|
|
||||||
|
struct hostent *hostEnt;
|
||||||
|
if((hostEnt = gethostbyname(serverName)) == NULL)
|
||||||
|
{
|
||||||
|
return SOCKET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this->Address = *(unsigned long*)hostEnt->h_addr;
|
||||||
|
this->port = htons(this->port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::Disconnect()
|
||||||
|
{
|
||||||
|
int result = closesocket(this->socket);
|
||||||
|
|
||||||
|
if(result == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::InitiateServer(unsigned short port)
|
||||||
|
{
|
||||||
|
int errorCode = 0;
|
||||||
|
|
||||||
|
if((errorCode = InitiateSocket()) != 0)
|
||||||
|
{
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in server;
|
||||||
|
server.sin_family = AF_INET;
|
||||||
|
server.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
server.sin_port = htons(port);
|
||||||
|
|
||||||
|
if(bind(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
errorCode = SOCKET_ERROR;
|
||||||
|
closesocket(this->socket);
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
closed = false;
|
||||||
|
stillSending = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::InitiateClient()
|
||||||
|
{
|
||||||
|
return InitiateSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::InitiateBroadcast(unsigned short port)
|
||||||
|
{
|
||||||
|
int result = InitiateSocket();
|
||||||
|
|
||||||
|
|
||||||
|
int flag = 1;
|
||||||
|
result = setsockopt(this->socket, /* socket affected */
|
||||||
|
SOL_SOCKET, /* set option at TCP level */
|
||||||
|
SO_BROADCAST, /* name of option */
|
||||||
|
(char *) &flag, /* the cast is historical cruft */
|
||||||
|
sizeof(flag)); /* length of option value */
|
||||||
|
if (result < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::Send(OysterByte &bytes)
|
||||||
|
{
|
||||||
|
int nBytes;
|
||||||
|
struct sockaddr_in reciever;
|
||||||
|
reciever.sin_family = AF_INET;
|
||||||
|
reciever.sin_addr.s_addr = this->Address;
|
||||||
|
reciever.sin_port = port;
|
||||||
|
|
||||||
|
//printf("Send: %d\n", bytes.GetSize());
|
||||||
|
nBytes = sendto(this->socket,
|
||||||
|
bytes,
|
||||||
|
bytes.GetSize(),
|
||||||
|
0,
|
||||||
|
(sockaddr*)&reciever,
|
||||||
|
sizeof(sockaddr_in)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( nBytes != bytes.GetSize() )
|
||||||
|
{
|
||||||
|
return nBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::Recieve(OysterByte &bytes)
|
||||||
|
{
|
||||||
|
int nBytes;
|
||||||
|
sockaddr_in from;
|
||||||
|
int fromLength = sizeof( from );
|
||||||
|
|
||||||
|
bytes.Resize(1000);
|
||||||
|
nBytes = recvfrom(this->socket,
|
||||||
|
bytes,
|
||||||
|
1000,
|
||||||
|
0,
|
||||||
|
(sockaddr*)&from,
|
||||||
|
&fromLength
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if(nBytes <= 0)
|
||||||
|
{
|
||||||
|
bytes.SetSize(0);
|
||||||
|
return WSAGetLastError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bytes.SetSize(nBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//address and port of the client who sent the message
|
||||||
|
unsigned int from_address = ntohl( from.sin_addr.s_addr );
|
||||||
|
unsigned int from_port = ntohs( from.sin_port );
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConnectionUDP::IsSending()
|
||||||
|
{
|
||||||
|
return stillSending;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConnectionUDP::IsConnected()
|
||||||
|
{
|
||||||
|
if(closed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionUDP::SetBlockingMode( bool blocking )
|
||||||
|
{
|
||||||
|
DWORD nonBlocking;
|
||||||
|
|
||||||
|
if(blocking)
|
||||||
|
{
|
||||||
|
nonBlocking = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nonBlocking = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = ioctlsocket(this->socket, FIONBIO, &nonBlocking);
|
||||||
|
if(result != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Success
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//////////////////////////////////////
|
||||||
|
// Private Methods
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
int ConnectionUDP::InitiateSocket()
|
||||||
|
{
|
||||||
|
this->socket = (int)::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
|
if(this->socket == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
#ifndef NETWORK_DEPENDENCIES_CONNECTIONUDP_H
|
||||||
|
#define NETWORK_DEPENDENCIES_CONNECTIONUDP_H
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Created by Sam Svensson 2013 //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
#include "IConnection.h"
|
||||||
|
#include "../NetworkDependencies/OysterByte.h"
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
class ConnectionUDP : public IConnection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConnectionUDP();
|
||||||
|
ConnectionUDP( int socket);
|
||||||
|
virtual ~ConnectionUDP();
|
||||||
|
|
||||||
|
virtual int InitiateServer( unsigned short port );
|
||||||
|
virtual int InitiateClient();
|
||||||
|
|
||||||
|
virtual int InitiateBroadcast(unsigned short port);
|
||||||
|
|
||||||
|
virtual int Send ( OysterByte &byte );
|
||||||
|
virtual int Recieve( OysterByte &byte );
|
||||||
|
|
||||||
|
virtual int Connect( unsigned short port, const char serverName[] );
|
||||||
|
|
||||||
|
virtual int Disconnect();
|
||||||
|
|
||||||
|
bool IsSending();
|
||||||
|
bool IsConnected();
|
||||||
|
int GetIpSize();
|
||||||
|
|
||||||
|
int SetBlockingMode( bool blocking );
|
||||||
|
|
||||||
|
private:
|
||||||
|
int InitiateSocket();
|
||||||
|
|
||||||
|
int socket;
|
||||||
|
//char ipAddress[16];
|
||||||
|
//unsigned short port;
|
||||||
|
int ipSize;
|
||||||
|
|
||||||
|
unsigned long Address;
|
||||||
|
unsigned short port;
|
||||||
|
|
||||||
|
bool stillSending;
|
||||||
|
bool closed;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -147,6 +147,7 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Connection.cpp" />
|
<ClCompile Include="Connection.cpp" />
|
||||||
|
<ClCompile Include="ConnectionUDP.cpp" />
|
||||||
<ClCompile Include="Listener.cpp" />
|
<ClCompile Include="Listener.cpp" />
|
||||||
<ClCompile Include="Messages\MessageHeader.cpp" />
|
<ClCompile Include="Messages\MessageHeader.cpp" />
|
||||||
<ClCompile Include="Messages\MessagePlayerPos.cpp" />
|
<ClCompile Include="Messages\MessagePlayerPos.cpp" />
|
||||||
|
@ -157,6 +158,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Connection.h" />
|
<ClInclude Include="Connection.h" />
|
||||||
|
<ClInclude Include="ConnectionUDP.h" />
|
||||||
<ClInclude Include="IConnection.h" />
|
<ClInclude Include="IConnection.h" />
|
||||||
<ClInclude Include="IPostBox.h" />
|
<ClInclude Include="IPostBox.h" />
|
||||||
<ClInclude Include="Listener.h" />
|
<ClInclude Include="Listener.h" />
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<ClCompile Include="OysterByte.cpp" />
|
<ClCompile Include="OysterByte.cpp" />
|
||||||
<ClCompile Include="ThreadedClient.cpp" />
|
<ClCompile Include="ThreadedClient.cpp" />
|
||||||
<ClCompile Include="WinsockFunctions.cpp" />
|
<ClCompile Include="WinsockFunctions.cpp" />
|
||||||
|
<ClCompile Include="ConnectionUDP.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Connection.h" />
|
<ClInclude Include="Connection.h" />
|
||||||
|
@ -25,5 +26,6 @@
|
||||||
<ClInclude Include="Protocols.h" />
|
<ClInclude Include="Protocols.h" />
|
||||||
<ClInclude Include="ThreadedClient.h" />
|
<ClInclude Include="ThreadedClient.h" />
|
||||||
<ClInclude Include="WinsockFunctions.h" />
|
<ClInclude Include="WinsockFunctions.h" />
|
||||||
|
<ClInclude Include="ConnectionUDP.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -283,6 +283,11 @@ void API_Impl::UpdateWorld()
|
||||||
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
|
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
|
||||||
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
|
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
|
||||||
simpleBody->PreStep(this->dynamicsWorld);
|
simpleBody->PreStep(this->dynamicsWorld);
|
||||||
|
|
||||||
|
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
|
||||||
|
{
|
||||||
|
this->customBodies[i]->CallSubscription_Move();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);
|
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);
|
||||||
|
@ -296,11 +301,6 @@ void API_Impl::UpdateWorld()
|
||||||
trans = simpleBody->GetRigidBody()->getWorldTransform();
|
trans = simpleBody->GetRigidBody()->getWorldTransform();
|
||||||
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
|
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
|
||||||
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
|
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
|
||||||
|
|
||||||
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
|
|
||||||
{
|
|
||||||
this->customBodies[i]->CallSubscription_Move();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
|
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
|
||||||
|
|
Loading…
Reference in New Issue