Gamelogic - Merge with network

This commit is contained in:
Dennis Andersen 2013-12-17 11:35:34 +01:00
commit 682a28513b
6 changed files with 39 additions and 3 deletions

View File

@ -32,7 +32,6 @@ struct CustomNetProtocol::PrivateData
attributes[i->first] = i->second;
}
}
attributes = o.attributes;
}
~PrivateData()
{

View File

@ -48,8 +48,8 @@ struct ClientDataContainer
InitWinSock();
callbackType = NetworkProtocolCallbackType_Unknown;
sendPostBox = new PostBox<CustomNetProtocol>();
connection.SetBlockingMode(false);
connection.InitiateClient();
connection.SetBlockingMode(false);
}
ClientDataContainer(IThreadObject* o, unsigned int socket )
:connection(socket), ID(currID++)
@ -204,6 +204,7 @@ NetworkClient::~NetworkClient()
bool NetworkClient::Connect(unsigned short port, const char serverIP[])
{
privateData->data->connection.SetBlockingMode(true);
int result = this->privateData->data->connection.Connect(port, serverIP);
//Connect has succeeded

View File

@ -35,6 +35,7 @@ struct Translator::PrivateData
auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end();
size = 4; //size(int)
message.SetSize(0);
message.PackInt(size, bytes);
//Find all the data types

View File

@ -44,6 +44,7 @@ void OysterByte::Resize(unsigned int cap)
{
delete[] byteArray;
byteArray = new unsigned char[cap];
capacity = cap;
}
}
@ -109,6 +110,25 @@ OysterByte::operator unsigned char*()
return byteArray;
}
OysterByte& OysterByte::operator +=(const OysterByte& obj)
{
int newSize = this->size + obj.size;
if(newSize >= (int)capacity)
{
IncreaseCapacity(this->size);
}
for(int i = size, j = 0; i < newSize; i++, j++)
{
this->byteArray[i] = obj.byteArray[j];
}
this->size = newSize;
return *this;
}
/////////////
// Private //
/////////////

View File

@ -40,6 +40,8 @@ namespace Oyster
operator const char*();
operator unsigned char*();
OysterByte& operator +=(const OysterByte& obj);
private:
//Expands the byteArray
void IncreaseCapacity(unsigned int cap);

View File

@ -1,15 +1,24 @@
#include <iostream>
#include <vector>
#include <vld.h>
#include <mutex>
#include "../NetworkDependencies/WinsockFunctions.h"
#include "../NetworkAPI/NetworkServer.h"
#include "../NetworkAPI/CustomNetProtocol.h"
#include "../NetworkAPI/NetworkCallbackHelper.h"
using namespace Oyster::Network;
using namespace std;
std::mutex m;
vector<NetworkClient> clients;
void proc(NetworkClient client)
{
cout << "Hej" << endl;
m.lock();
clients.push_back(client);
m.unlock();
}
int main()
@ -38,9 +47,13 @@ int main()
while(1)
{
Sleep(1000);
m.lock();
cout << clients.size() << endl;
m.unlock();
}
server.Stop();
system("pause");