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[i->first] = i->second;
} }
} }
attributes = o.attributes;
} }
~PrivateData() ~PrivateData()
{ {

View File

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

View File

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

View File

@ -44,6 +44,7 @@ void OysterByte::Resize(unsigned int cap)
{ {
delete[] byteArray; delete[] byteArray;
byteArray = new unsigned char[cap]; byteArray = new unsigned char[cap];
capacity = cap;
} }
} }
@ -109,6 +110,25 @@ OysterByte::operator unsigned char*()
return byteArray; 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 // // Private //
///////////// /////////////

View File

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

View File

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