Gamelogic - Added threading functionality to NetworkClient
This commit is contained in:
parent
b351a7bac4
commit
ec3c5f1290
|
@ -47,6 +47,8 @@ namespace Oyster
|
||||||
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
|
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
|
||||||
bool IsActive();
|
bool IsActive();
|
||||||
void SetPriority(OYSTER_THREAD_PRIORITY priority);
|
void SetPriority(OYSTER_THREAD_PRIORITY priority);
|
||||||
|
|
||||||
|
bool IsCreated() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,12 @@ using namespace Utility::DynamicMemory;
|
||||||
};
|
};
|
||||||
struct OysterThread::PrivateData
|
struct OysterThread::PrivateData
|
||||||
{
|
{
|
||||||
|
bool isCreated;
|
||||||
SmartPointer<ThreadData> threadData;
|
SmartPointer<ThreadData> threadData;
|
||||||
|
|
||||||
PrivateData()
|
PrivateData()
|
||||||
{
|
{
|
||||||
|
isCreated = false;
|
||||||
threadData = new ThreadData();
|
threadData = new ThreadData();
|
||||||
threadData->first = true;
|
threadData->first = true;
|
||||||
threadData->owner = 0;
|
threadData->owner = 0;
|
||||||
|
@ -73,6 +75,7 @@ using namespace Utility::DynamicMemory;
|
||||||
}
|
}
|
||||||
PrivateData(const PrivateData& o)
|
PrivateData(const PrivateData& o)
|
||||||
{
|
{
|
||||||
|
isCreated = o.isCreated;
|
||||||
threadData = o.threadData;
|
threadData = o.threadData;
|
||||||
}
|
}
|
||||||
const PrivateData& operator=(const PrivateData& o)
|
const PrivateData& operator=(const PrivateData& o)
|
||||||
|
@ -276,4 +279,7 @@ void OysterThread::SetPriority(OYSTER_THREAD_PRIORITY priority)
|
||||||
{
|
{
|
||||||
this->privateData->threadData->prio = priority;
|
this->privateData->threadData->prio = priority;
|
||||||
}
|
}
|
||||||
|
bool OysterThread::IsCreated() const
|
||||||
|
{
|
||||||
|
return privateData->isCreated;
|
||||||
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||||
|
@ -88,12 +88,14 @@
|
||||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||||
|
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||||
|
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
|
|
|
@ -166,6 +166,7 @@ NetworkClient::NetworkClient()
|
||||||
NetworkClient::NetworkClient(unsigned int socket)
|
NetworkClient::NetworkClient(unsigned int socket)
|
||||||
{
|
{
|
||||||
privateData = new PrivateData(socket);
|
privateData = new PrivateData(socket);
|
||||||
|
this->privateData->data->thread.Create(this->privateData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type)
|
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type)
|
||||||
|
@ -179,6 +180,7 @@ NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType
|
||||||
privateData = new PrivateData(socket);
|
privateData = new PrivateData(socket);
|
||||||
this->privateData->data->recvObj = SmartPointer<RecieverObject>(&recvObj);
|
this->privateData->data->recvObj = SmartPointer<RecieverObject>(&recvObj);
|
||||||
this->privateData->data->callbackType = type;
|
this->privateData->data->callbackType = type;
|
||||||
|
this->privateData->data->thread.Create(this->privateData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkClient::NetworkClient(const NetworkClient& obj)
|
NetworkClient::NetworkClient(const NetworkClient& obj)
|
||||||
|
@ -209,7 +211,10 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[])
|
||||||
//Connect has succeeded
|
//Connect has succeeded
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
privateData->data->thread.Start();
|
if(this->privateData->data->thread.IsCreated()) return false;
|
||||||
|
|
||||||
|
this->privateData->data->thread.Create(this->privateData, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "NetworkCallbackHelper.h"
|
#include "NetworkCallbackHelper.h"
|
||||||
#include <vld.h>
|
//#include <vld.h>
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue