GameLogic - Pre merge with Linda
This commit is contained in:
parent
682a28513b
commit
097fa1da34
|
@ -6,7 +6,7 @@
|
||||||
#include <vld.h>
|
#include <vld.h>
|
||||||
|
|
||||||
#include "DanBiasServerAPI.h"
|
#include "DanBiasServerAPI.h"
|
||||||
//#include "DanBiasGame.h"
|
#include "DanBiasGame.h"
|
||||||
|
|
||||||
|
|
||||||
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)
|
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)
|
||||||
|
|
|
@ -28,6 +28,7 @@ Oyster::Network::NetworkClient* ClientObject::NetClient_Object()
|
||||||
|
|
||||||
void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol)
|
void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol)
|
||||||
{
|
{
|
||||||
|
//this->client->Send(&protocol);
|
||||||
if(!this->box) return;
|
if(!this->box) return;
|
||||||
|
|
||||||
NetworkSession::NetEvent _event;
|
NetworkSession::NetEvent _event;
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "NetworkSession.h"
|
#include "NetworkSession.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
static std::mutex ClientListLock;
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
NetworkSession::NetworkSession()
|
NetworkSession::NetworkSession()
|
||||||
|
@ -16,16 +18,27 @@ namespace DanBias
|
||||||
|
|
||||||
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client)
|
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < this->clients.size(); i++)
|
while (!ClientListLock.try_lock()); //Possible Deadlock
|
||||||
|
|
||||||
|
int k = -1;
|
||||||
|
for (unsigned int i = 0; (k == -1) && i < this->clients.size(); i++)
|
||||||
{
|
{
|
||||||
if(!this->clients[i])
|
if(!this->clients[i])
|
||||||
|
k = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(k == -1)
|
||||||
{
|
{
|
||||||
this->clients[i] = client;
|
|
||||||
this->clients[i]->SetPostbox(&this->box);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->clients.push_back(client);
|
this->clients.push_back(client);
|
||||||
|
this->clients[this->clients.size() - 1]->SetPostbox(&this->box);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->clients[k]->SetPostbox(&this->box);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientListLock.unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
|
void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
|
||||||
|
|
|
@ -118,7 +118,8 @@ theBegining:
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
break;
|
break;
|
||||||
case Oyster::Thread::OYSTER_THREAD_PRIORITY_3:
|
case Oyster::Thread::OYSTER_THREAD_PRIORITY_3:
|
||||||
std::this_thread::yield();
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
//std::this_thread::yield();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(w->owner)
|
if(w->owner)
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace Oyster
|
||||||
struct ProtocolRecieverObject
|
struct ProtocolRecieverObject
|
||||||
{
|
{
|
||||||
virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0;
|
virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0;
|
||||||
|
virtual void DisconnectedCallback(CustomNetProtocol& protocol) { };
|
||||||
};
|
};
|
||||||
|
|
||||||
union RecieverObject
|
union RecieverObject
|
||||||
|
|
|
@ -238,6 +238,11 @@ void NetworkClient::Send(CustomProtocolObject& protocol)
|
||||||
this->privateData->Send(protocol.GetProtocol());
|
this->privateData->Send(protocol.GetProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkClient::Send(CustomNetProtocol* protocol)
|
||||||
|
{
|
||||||
|
this->privateData->Send(protocol);
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type)
|
void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type)
|
||||||
{
|
{
|
||||||
if (type == NetworkProtocolCallbackType_Unknown) return; //It should probably still be set even if it is unknown.
|
if (type == NetworkProtocolCallbackType_Unknown) return; //It should probably still be set even if it is unknown.
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace Oyster
|
||||||
|
|
||||||
//Adds the protocol to the queue of protocols to be sent.
|
//Adds the protocol to the queue of protocols to be sent.
|
||||||
void Send(CustomProtocolObject& protocol);
|
void Send(CustomProtocolObject& protocol);
|
||||||
|
void Send(CustomNetProtocol* protocol);
|
||||||
|
|
||||||
void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type);
|
void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type);
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ namespace Oyster
|
||||||
//bool (1-bit)
|
//bool (1-bit)
|
||||||
bool Unpackb(unsigned char buffer[])
|
bool Unpackb(unsigned char buffer[])
|
||||||
{
|
{
|
||||||
return buffer;
|
return *buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//char (8-bit)
|
//char (8-bit)
|
||||||
|
|
Loading…
Reference in New Issue