GameLogic - Merged with GameServer and fixed some merge errors
This commit is contained in:
commit
53c0c74c7c
|
@ -34,3 +34,4 @@ Bin/DLL/
|
|||
Bin/Executable/
|
||||
Obj/
|
||||
External/
|
||||
Code/Game/GameClient/GameClient.vcxproj.user
|
||||
|
|
|
@ -20,10 +20,13 @@
|
|||
|
||||
#include "EventHandler/EventHandler.h"
|
||||
|
||||
#include "GameClientState\SharedStateContent.h"
|
||||
|
||||
using namespace ::Oyster;
|
||||
using namespace ::Oyster::Event;
|
||||
using namespace ::Oyster::Network;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
using namespace ::DanBias::Client;
|
||||
|
||||
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
|
||||
|
||||
|
@ -32,15 +35,17 @@ namespace DanBias
|
|||
#pragma region Game Data
|
||||
class DanBiasGamePrivateData
|
||||
{
|
||||
|
||||
public:
|
||||
WindowShell* window;
|
||||
InputClass* inputObj;
|
||||
InputClass inputObj;
|
||||
Utility::WinTimer timer;
|
||||
UniquePointer<Client::GameClientState> state;
|
||||
NetworkClient networkClient;
|
||||
bool serverOwner;
|
||||
|
||||
UniquePointer<Client::GameClientState> state;
|
||||
SharedStateContent sharedStateContent;
|
||||
NetworkClient networkClient;
|
||||
|
||||
|
||||
bool serverOwner;
|
||||
float capFrame;
|
||||
|
||||
DanBiasGamePrivateData()
|
||||
|
@ -59,7 +64,12 @@ namespace DanBias
|
|||
{
|
||||
WindowShell::CreateConsoleWindow();
|
||||
//if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT())))
|
||||
if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
|
||||
|
||||
WindowShell::WINDOW_INIT_DESC winDesc;
|
||||
winDesc.windowSize.x = 1280;
|
||||
winDesc.windowSize.y = 720;
|
||||
|
||||
if(! data.window->CreateWin(winDesc) )
|
||||
return DanBiasClientReturn_Error;
|
||||
|
||||
if( FAILED( InitDirect3D() ) )
|
||||
|
@ -72,10 +82,13 @@ namespace DanBias
|
|||
|
||||
data.networkClient.SetMessagePump( ClientEventFunction );
|
||||
|
||||
data.sharedStateContent.network = &data.networkClient;
|
||||
data.sharedStateContent.input = &data.inputObj;
|
||||
|
||||
// Start in main menu state
|
||||
data.state = new Client::MainState();
|
||||
|
||||
if( !data.state->Init( &data.networkClient ) )
|
||||
if( !data.state->Init( data.sharedStateContent ) )
|
||||
return DanBiasClientReturn_Error;
|
||||
|
||||
data.timer.reset();
|
||||
|
@ -92,9 +105,6 @@ namespace DanBias
|
|||
|
||||
Graphics::API::Update( dt );
|
||||
|
||||
if(data.networkClient.IsConnected())
|
||||
data.networkClient.Update();
|
||||
|
||||
data.capFrame += dt;
|
||||
if(data.capFrame > 0.03)
|
||||
{
|
||||
|
@ -110,6 +120,9 @@ namespace DanBias
|
|||
data.capFrame = 0;
|
||||
}
|
||||
|
||||
if(data.networkClient.IsConnected())
|
||||
data.networkClient.Update();
|
||||
|
||||
}
|
||||
return DanBiasClientReturn_Success;
|
||||
}
|
||||
|
@ -128,9 +141,11 @@ namespace DanBias
|
|||
Oyster::Graphics::API::Option p;
|
||||
p.modelPath = L"..\\Content\\Models\\";
|
||||
p.texturePath = L"..\\Content\\Textures\\";
|
||||
Oyster::Graphics::API::SetOptions(p);
|
||||
p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f );
|
||||
//! @todo fix proper amb value
|
||||
p.AmbientValue = 1.0f;
|
||||
|
||||
if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
|
||||
if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, p) != Oyster::Graphics::API::Sucsess)
|
||||
return E_FAIL;
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -140,8 +155,7 @@ namespace DanBias
|
|||
//-------------------------------------------------------------------------------------
|
||||
HRESULT DanBiasGame::InitInput()
|
||||
{
|
||||
data.inputObj = new InputClass;
|
||||
if(!data.inputObj->Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth()))
|
||||
if(!data.inputObj.Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth()))
|
||||
{
|
||||
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
||||
return E_FAIL;
|
||||
|
@ -164,7 +178,7 @@ namespace DanBias
|
|||
float mouseNormalisedY = (float)(mousePos.y - windowVertex.top);
|
||||
mouseNormalisedY /= (float)(windowVertex.bottom - windowVertex.top);
|
||||
|
||||
data.inputObj->Update( mouseNormalisedX, mouseNormalisedY );
|
||||
data.inputObj.Update( mouseNormalisedX, mouseNormalisedY );
|
||||
}
|
||||
|
||||
if( data.serverOwner )
|
||||
|
@ -174,7 +188,7 @@ namespace DanBias
|
|||
|
||||
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
|
||||
|
||||
state = data.state->Update( deltaTime, data.inputObj );
|
||||
state = data.state->Update( deltaTime );
|
||||
|
||||
if( state != Client::GameClientState::ClientState_Same )
|
||||
{
|
||||
|
@ -217,7 +231,7 @@ namespace DanBias
|
|||
|
||||
if( stateChanged )
|
||||
{
|
||||
data.state->Init( &data.networkClient ); // send game client
|
||||
data.state->Init( data.sharedStateContent ); // send game client
|
||||
}
|
||||
}
|
||||
return Result_continue;
|
||||
|
@ -235,8 +249,6 @@ namespace DanBias
|
|||
if( data.networkClient.IsConnected() )
|
||||
data.networkClient.Disconnect();
|
||||
|
||||
delete data.inputObj;
|
||||
|
||||
data.state = nullptr;
|
||||
EventHandler::Instance().Clean();
|
||||
Graphics::API::Clean();
|
||||
|
|
|
@ -111,8 +111,8 @@
|
|||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -128,8 +128,8 @@
|
|||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -149,8 +149,8 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
@ -170,14 +170,23 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Misc\Input\Input.vcxproj">
|
||||
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Misc\OysterMath\OysterMath.vcxproj">
|
||||
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Misc\Utilities\Utilities.vcxproj">
|
||||
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Misc\WindowManager\WindowManager.vcxproj">
|
||||
<Project>{35aea3c0-e0a7-4e1e-88cd-514aa5a442b1}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Network\NetworkAPI\NetworkAPI.vcxproj">
|
||||
<Project>{460d625f-2ac9-4559-b809-0ba89ceaedf4}</Project>
|
||||
</ProjectReference>
|
||||
|
@ -192,7 +201,9 @@
|
|||
<ClCompile Include="DanBiasGame_Impl.cpp" />
|
||||
<ClCompile Include="GameClientState\Camera_Basic.cpp" />
|
||||
<ClCompile Include="GameClientState\Camera.cpp" />
|
||||
<ClCompile Include="GameClientState\Camera_BasicV2.cpp" />
|
||||
<ClCompile Include="GameClientState\Camera_FPS.cpp" />
|
||||
<ClCompile Include="GameClientState\Camera_FPSV2.cpp" />
|
||||
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
|
||||
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
|
||||
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
|
||||
|
@ -217,7 +228,9 @@
|
|||
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
|
||||
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
|
||||
<ClInclude Include="GameClientState\Camera.h" />
|
||||
<ClInclude Include="GameClientState\Camera_BasicV2.h" />
|
||||
<ClInclude Include="GameClientState\Camera_FPS.h" />
|
||||
<ClInclude Include="GameClientState\Camera_FPSV2.h" />
|
||||
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
|
||||
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
|
||||
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />
|
||||
|
@ -233,6 +246,7 @@
|
|||
<ClInclude Include="GameClientState\LobbyAdminState.h" />
|
||||
<ClInclude Include="GameClientState\MainState.h" />
|
||||
<ClInclude Include="GameClientState\NetLoadState.h" />
|
||||
<ClInclude Include="GameClientState\SharedStateContent.h" />
|
||||
<ClInclude Include="Include\GameClient.h" />
|
||||
<ClInclude Include="GameClientState\LobbyState.h" />
|
||||
<ClInclude Include="GameClientState\C_Object.h" />
|
||||
|
|
|
@ -21,19 +21,19 @@ namespace DanBias
|
|||
ButtonEllipse()
|
||||
: EventButtonGUI(), radius(0)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos,
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos,
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos,
|
||||
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize)
|
||||
{}
|
||||
|
|
|
@ -21,21 +21,37 @@ namespace DanBias
|
|||
ButtonRectangle()
|
||||
: EventButtonGUI(), width(0), height(0)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize)
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButtonGUI(textureName, buttonText,
|
||||
textColor, backColor, hoverColor, pressedColor,
|
||||
owner, pos, size, resize)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize)
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButtonGUI(textureName, buttonText,
|
||||
textColor, backColor, hoverColor, pressedColor,
|
||||
func, pos, size, resize)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize)
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButtonGUI(textureName, buttonText,
|
||||
textColor, backColor, hoverColor, pressedColor,
|
||||
func, owner, pos, size, resize)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize)
|
||||
ButtonRectangle(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButtonGUI(textureName, buttonText,
|
||||
textColor, backColor, hoverColor, pressedColor,
|
||||
func, owner, userData, pos, size, resize)
|
||||
{}
|
||||
virtual ~ButtonRectangle()
|
||||
{}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#include "EventHandler/EventButton.h"
|
||||
#include "DllInterfaces/GFXAPI.h"
|
||||
|
||||
|
||||
|
||||
namespace DanBias
|
||||
{
|
||||
namespace Client
|
||||
|
@ -32,32 +30,40 @@ namespace DanBias
|
|||
class EventButtonGUI : public Oyster::Event::EventButton<Owner>
|
||||
{
|
||||
public:
|
||||
EventButtonGUI()
|
||||
: EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0)
|
||||
{}
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
||||
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
||||
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Owner owner, Oyster::Math::Float3 pos,
|
||||
Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
||||
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||
: EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
||||
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
||||
EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
||||
: EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
||||
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||
|
@ -79,23 +85,23 @@ namespace DanBias
|
|||
if(EventButton<Owner>::Enabled())
|
||||
{
|
||||
// let the using dev decide what is rendered
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
|
||||
//Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
//Render att xPos and yPos
|
||||
//With width and height
|
||||
|
||||
//if(EventButton<Owner>::GetState() == ButtonState_None)
|
||||
//{
|
||||
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
|
||||
//}
|
||||
//else if(EventButton<Owner>::GetState() == ButtonState_Hover)
|
||||
//{
|
||||
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
|
||||
//}
|
||||
if(EventButton<Owner>::GetState() == ButtonState_None)
|
||||
{
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, backColor);
|
||||
}
|
||||
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
|
||||
{
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, hoverColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, pressedColor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +110,7 @@ namespace DanBias
|
|||
{
|
||||
if(buttonText.size() > 0)
|
||||
{
|
||||
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, 0.0f), size*2.0f, size.y * 0.5f, textColor);
|
||||
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, -0.001f), size, size.y * 0.5f, textColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +133,11 @@ namespace DanBias
|
|||
Oyster::Graphics::API::Texture texture;
|
||||
|
||||
std::wstring buttonText;
|
||||
Oyster::Math::Float3 textColor;
|
||||
Oyster::Math::Float4 textColor;
|
||||
|
||||
Oyster::Math::Float4 backColor;
|
||||
Oyster::Math::Float4 hoverColor;
|
||||
Oyster::Math::Float4 pressedColor;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace DanBias { namespace Client
|
|||
{
|
||||
public:
|
||||
TextField();
|
||||
TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height );
|
||||
TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height );
|
||||
virtual ~TextField();
|
||||
|
||||
virtual void RenderText();
|
||||
|
@ -62,8 +62,8 @@ namespace DanBias { namespace Client
|
|||
}
|
||||
|
||||
template<typename Owner>
|
||||
TextField<Owner>::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize )
|
||||
: ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize )
|
||||
TextField<Owner>::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize )
|
||||
: ButtonRectangle( backgroundTexture, L"", textColor, backColor, backColor, backColor, owner, pos, size, resize )
|
||||
{
|
||||
this->fontHeight = 0.025f;
|
||||
this->lineSpacing = 0.001f;
|
||||
|
|
|
@ -100,5 +100,9 @@ void C_Object::Render()
|
|||
}
|
||||
void C_Object::Release()
|
||||
{
|
||||
if( this->model )
|
||||
{
|
||||
Oyster::Graphics::API::DeleteModel(model);
|
||||
this->model = nullptr;
|
||||
}
|
||||
}
|
|
@ -16,9 +16,9 @@ namespace DanBias
|
|||
bool visible;
|
||||
};
|
||||
|
||||
class C_Object
|
||||
{
|
||||
private:
|
||||
class C_Object
|
||||
{
|
||||
private:
|
||||
Oyster::Math::Float4x4 world;
|
||||
Oyster::Math::Float3 position;
|
||||
Oyster::Math::Quaternion rotation;
|
||||
|
@ -26,9 +26,9 @@ private:
|
|||
|
||||
int id;
|
||||
void updateWorld();
|
||||
protected:
|
||||
protected:
|
||||
Oyster::Graphics::Model::Model *model;
|
||||
public:
|
||||
public:
|
||||
C_Object();
|
||||
virtual ~C_Object();
|
||||
virtual bool Init(ModelInitData modelInit);
|
||||
|
@ -48,5 +48,23 @@ public:
|
|||
virtual void Render();
|
||||
virtual void Release();
|
||||
virtual int GetId() const;
|
||||
};};};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include "Utilities.h"
|
||||
|
||||
namespace Utility { namespace DynamicMemory
|
||||
{
|
||||
template<>
|
||||
inline void SafeDeleteInstance( ::DanBias::Client::C_Object *dynamicInstance )
|
||||
{
|
||||
if( dynamicInstance )
|
||||
{
|
||||
dynamicInstance->Release();
|
||||
delete dynamicInstance;
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
#include "Camera_BasicV2.h"
|
||||
|
||||
using namespace ::Oyster::Math3D;
|
||||
|
||||
Camera_BasicV2::Camera_BasicV2()
|
||||
{
|
||||
this->translation = Float3::null;
|
||||
this->rotation = Quaternion::identity;
|
||||
this->projection = Float4x4::identity;
|
||||
}
|
||||
|
||||
Camera_BasicV2::Camera_BasicV2( const Float3 &position, const Quaternion &rotation, const Float4x4 &projection )
|
||||
{
|
||||
this->translation = position;
|
||||
this->rotation = rotation;
|
||||
this->projection = projection;
|
||||
}
|
||||
|
||||
Camera_BasicV2::~Camera_BasicV2() {}
|
||||
|
||||
Camera_BasicV2 & Camera_BasicV2::operator = ( const Camera_BasicV2 &camera )
|
||||
{
|
||||
this->translation = camera.translation;
|
||||
this->rotation = camera.rotation;
|
||||
this->projection = camera.projection;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetPosition( const Float3 &translation )
|
||||
{
|
||||
this->translation = translation;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetRotation( const Quaternion &rotation )
|
||||
{
|
||||
this->rotation = rotation;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetAngular( const Float3 &axis )
|
||||
{
|
||||
this->rotation = Rotation( axis );
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetProjection( const Float4x4 &matrix )
|
||||
{
|
||||
this->projection = matrix;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
|
||||
{
|
||||
ProjectionMatrix_Orthographic( width, height, nearClip, farClip, this->projection );
|
||||
}
|
||||
|
||||
void Camera_BasicV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
|
||||
{
|
||||
ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, this->projection );
|
||||
}
|
||||
|
||||
void Camera_BasicV2::Move( const Float3 &deltaPosition )
|
||||
{
|
||||
this->translation += deltaPosition;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::Rotate( const Quaternion &deltaRotation )
|
||||
{
|
||||
this->rotation *= deltaRotation;
|
||||
}
|
||||
|
||||
void Camera_BasicV2::Rotate( const Float3 &deltaAngularAxis )
|
||||
{
|
||||
this->rotation *= Rotation( deltaAngularAxis );
|
||||
}
|
||||
|
||||
const Float3 & Camera_BasicV2::GetPosition() const
|
||||
{
|
||||
return this->translation;
|
||||
}
|
||||
|
||||
Float3 & Camera_BasicV2::GetAngularAxis( Float3 &targetMem ) const
|
||||
{
|
||||
return targetMem = AngularAxis( this->rotation );
|
||||
}
|
||||
|
||||
Float3 Camera_BasicV2::GetNormalOf( const Float3 &axis ) const
|
||||
{
|
||||
return WorldAxisOf( this->rotation, axis );
|
||||
}
|
||||
|
||||
const Quaternion & Camera_BasicV2::GetRotation() const
|
||||
{
|
||||
return this->rotation;
|
||||
}
|
||||
|
||||
Float3x3 & Camera_BasicV2::GetRotationMatrix( Float3x3 &targetMem ) const
|
||||
{
|
||||
return RotationMatrix( this->rotation, targetMem );
|
||||
}
|
||||
|
||||
Float4x4 & Camera_BasicV2::GetRotationMatrix( Float4x4 &targetMem ) const
|
||||
{
|
||||
return RotationMatrix( this->rotation, targetMem );
|
||||
}
|
||||
|
||||
Float4x4 & Camera_BasicV2::GetViewMatrix( Float4x4 &targetMem ) const
|
||||
{
|
||||
return ViewMatrix( this->rotation, this->translation, targetMem );
|
||||
}
|
||||
|
||||
const Float4x4 & Camera_BasicV2::GetProjectionMatrix() const
|
||||
{
|
||||
return this->projection;
|
||||
}
|
||||
|
||||
Float4x4 & Camera_BasicV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
|
||||
{
|
||||
return TransformMatrix( this->projection, this->GetViewMatrix(), targetMem );
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef CAMERA_BASIC_V2_H
|
||||
#define CAMERA_BASIC_V2_H
|
||||
|
||||
#include "OysterMath.h"
|
||||
|
||||
class Camera_BasicV2
|
||||
{
|
||||
public:
|
||||
Camera_BasicV2();
|
||||
Camera_BasicV2( const ::Oyster::Math::Float3 &position, const ::Oyster::Math::Quaternion &rotation, const ::Oyster::Math::Float4x4 &projection );
|
||||
virtual ~Camera_BasicV2();
|
||||
|
||||
Camera_BasicV2 & operator = ( const Camera_BasicV2 &camera );
|
||||
|
||||
void SetPosition( const ::Oyster::Math::Float3 &translation );
|
||||
void SetRotation( const ::Oyster::Math::Quaternion &rotation );
|
||||
void SetAngular( const ::Oyster::Math::Float3 &axis );
|
||||
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
|
||||
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||
|
||||
void Move( const ::Oyster::Math::Float3 &deltaPosition );
|
||||
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
|
||||
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
|
||||
|
||||
const ::Oyster::Math::Float3 & GetPosition() const;
|
||||
::Oyster::Math::Float3 & GetAngularAxis( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
|
||||
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
|
||||
const ::Oyster::Math::Quaternion & GetRotation() const;
|
||||
::Oyster::Math::Float3x3 & GetRotationMatrix( ::Oyster::Math::Float3x3 &targetMem ) const;
|
||||
::Oyster::Math::Float4x4 & GetRotationMatrix( ::Oyster::Math::Float4x4 &targetMem ) const;
|
||||
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
|
||||
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||
|
||||
private:
|
||||
::Oyster::Math::Float3 translation;
|
||||
mutable ::Oyster::Math::Quaternion rotation;
|
||||
::Oyster::Math::Float4x4 projection;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,186 @@
|
|||
#include "Camera_FPSV2.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
using namespace ::Oyster::Math3D;
|
||||
using namespace ::Utility::Value;
|
||||
|
||||
Camera_FPSV2::Camera_FPSV2()
|
||||
{ // this->head is default set to identity uniformprojection at origo
|
||||
this->pitchUp = 0.0f;
|
||||
this->headOffset =
|
||||
this->body.translation = Float3::null;
|
||||
this->body.rotation = Quaternion::identity;
|
||||
}
|
||||
|
||||
Camera_FPSV2::~Camera_FPSV2() {}
|
||||
|
||||
Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera )
|
||||
{
|
||||
this->head = camera.head;
|
||||
this->pitchUp = camera.pitchUp;
|
||||
this->headOffset = camera.headOffset;
|
||||
this->body.translation = camera.body.translation;
|
||||
this->body.rotation = camera.body.rotation;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetHeadOffset( const Float3 &translation )
|
||||
{
|
||||
this->head.Move( translation - this->headOffset );
|
||||
this->headOffset = translation;
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetPosition( const Float3 &translation )
|
||||
{
|
||||
this->head.Move( translation - this->body.translation );
|
||||
this->body.translation = translation;
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetRotation( const Quaternion &rotation )
|
||||
{
|
||||
this->body.rotation = rotation;
|
||||
this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetAngular( const Float3 &axis )
|
||||
{
|
||||
this->SetRotation( Rotation(axis) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetProjection( const Float4x4 &matrix )
|
||||
{
|
||||
this->head.SetProjection( matrix );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
|
||||
{
|
||||
this->head.SetOrthographicProjection( width, height, nearClip, farClip );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
|
||||
{
|
||||
this->head.SetPerspectiveProjection( verticalFoV, aspectRatio, nearClip, farClip );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::UpdateOrientation()
|
||||
{
|
||||
Float4x4 orientation;
|
||||
OrientationMatrix( this->body.rotation, this->body.translation, orientation );
|
||||
|
||||
this->head.SetPosition( (orientation * Float4(this->headOffset, 1.0f)).xyz );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::SnapUpToNormal( const Float3 &normal )
|
||||
{
|
||||
this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) );
|
||||
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::Move( const Float3 &deltaPosition )
|
||||
{
|
||||
this->head.Move( deltaPosition );
|
||||
this->body.translation += deltaPosition;
|
||||
}
|
||||
|
||||
void Camera_FPSV2::Rotate( const Quaternion &deltaRotation )
|
||||
{
|
||||
this->head.Rotate( deltaRotation );
|
||||
this->body.rotation *= deltaRotation;
|
||||
}
|
||||
|
||||
void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis )
|
||||
{
|
||||
this->Rotate( Rotation(deltaAngularAxis) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::MoveForward( Float distance )
|
||||
{
|
||||
this->MoveBackward( -distance );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::MoveBackward( Float distance )
|
||||
{
|
||||
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_z) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::StrafeRight( Float distance )
|
||||
{
|
||||
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_x) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::StrafeLeft( Float distance )
|
||||
{
|
||||
this->StrafeRight( -distance );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::PitchUp( Float radian )
|
||||
{
|
||||
this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi );
|
||||
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::PitchDown( Float radian )
|
||||
{
|
||||
this->PitchUp( -radian );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::YawRight( Float radian )
|
||||
{
|
||||
this->YawLeft( -radian );
|
||||
}
|
||||
|
||||
void Camera_FPSV2::YawLeft( Float radian )
|
||||
{
|
||||
Quaternion deltaRotation = Rotation( radian, WorldAxisOf(this->body.rotation, Float3::standard_unit_y) );
|
||||
this->Rotate( deltaRotation );
|
||||
}
|
||||
|
||||
const Float3 & Camera_FPSV2::GetHeadOffset() const
|
||||
{
|
||||
return this->headOffset;
|
||||
}
|
||||
|
||||
const Float3 & Camera_FPSV2::GetPosition() const
|
||||
{
|
||||
return this->body.translation;
|
||||
}
|
||||
|
||||
Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const
|
||||
{
|
||||
return this->head.GetViewMatrix( targetMem );
|
||||
}
|
||||
|
||||
const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const
|
||||
{
|
||||
return this->head.GetProjectionMatrix();
|
||||
}
|
||||
|
||||
Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
|
||||
{
|
||||
return this->head.GetViewsProjMatrix( targetMem );
|
||||
}
|
||||
|
||||
Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const
|
||||
{
|
||||
return this->head.GetNormalOf( axis );
|
||||
}
|
||||
|
||||
Float3 Camera_FPSV2::GetRight() const
|
||||
{
|
||||
return WorldAxisOf( this->body.rotation, Float3::standard_unit_x );
|
||||
}
|
||||
|
||||
Float3 Camera_FPSV2::GetUp() const
|
||||
{
|
||||
return WorldAxisOf( this->body.rotation, Float3::standard_unit_y );
|
||||
}
|
||||
|
||||
Float3 Camera_FPSV2::GetLook() const
|
||||
{
|
||||
return this->head.GetNormalOf( -Float3::standard_unit_z );
|
||||
}
|
||||
|
||||
Float3 Camera_FPSV2::GetForward() const
|
||||
{
|
||||
return WorldAxisOf( this->body.rotation, -Float3::standard_unit_z );
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef CAMERA_FPSV2_H
|
||||
#define CAMERA_FPSV2_H
|
||||
|
||||
#include "OysterMath.h"
|
||||
#include "Camera_BasicV2.h"
|
||||
|
||||
class Camera_FPSV2
|
||||
{
|
||||
public:
|
||||
Camera_FPSV2();
|
||||
virtual ~Camera_FPSV2();
|
||||
|
||||
Camera_FPSV2 & operator = ( const Camera_FPSV2 &camera );
|
||||
|
||||
void SetHeadOffset( const ::Oyster::Math::Float3 &translation );
|
||||
void SetPosition( const ::Oyster::Math::Float3 &translation );
|
||||
void SetRotation( const ::Oyster::Math::Quaternion &rotation );
|
||||
void SetAngular( const ::Oyster::Math::Float3 &axis );
|
||||
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
|
||||
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
|
||||
|
||||
void UpdateOrientation();
|
||||
|
||||
void SnapUpToNormal( const ::Oyster::Math::Float3 &normal );
|
||||
|
||||
void Move( const ::Oyster::Math::Float3 &deltaPosition );
|
||||
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
|
||||
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
|
||||
|
||||
void MoveForward( ::Oyster::Math::Float distance );
|
||||
void MoveBackward( ::Oyster::Math::Float distance );
|
||||
void StrafeRight( ::Oyster::Math::Float distance );
|
||||
void StrafeLeft( ::Oyster::Math::Float distance );
|
||||
|
||||
void PitchUp( ::Oyster::Math::Float radian );
|
||||
void PitchDown( ::Oyster::Math::Float radian );
|
||||
void YawRight( ::Oyster::Math::Float radian );
|
||||
void YawLeft( ::Oyster::Math::Float radian );
|
||||
|
||||
const ::Oyster::Math::Float3 & GetHeadOffset() const;
|
||||
const ::Oyster::Math::Float3 & GetPosition() const;
|
||||
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
|
||||
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
|
||||
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
|
||||
::Oyster::Math::Float3 GetRight() const;
|
||||
::Oyster::Math::Float3 GetUp() const;
|
||||
::Oyster::Math::Float3 GetLook() const;
|
||||
::Oyster::Math::Float3 GetForward() const;
|
||||
|
||||
private:
|
||||
Camera_BasicV2 head;
|
||||
::Oyster::Math::Float pitchUp;
|
||||
::Oyster::Math::Float3 headOffset;
|
||||
struct
|
||||
{
|
||||
::Oyster::Math::Float3 translation;
|
||||
::Oyster::Math::Quaternion rotation;
|
||||
} body;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,9 +3,14 @@
|
|||
using namespace DanBias::Client;
|
||||
using namespace ::Oyster::Network;
|
||||
|
||||
GameClientState::GameClientState(void) {}
|
||||
const GameClientState::NetEvent GameClientState::event_processed = GameClientState::NetEvent();
|
||||
|
||||
GameClientState::~GameClientState(void) {}
|
||||
GameClientState::GameClientState() {}
|
||||
|
||||
void GameClientState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||
{ /* do nothing */ }
|
||||
GameClientState::~GameClientState() {}
|
||||
|
||||
const GameClientState::NetEvent & GameClientState::DataRecieved( const GameClientState::NetEvent &message )
|
||||
{
|
||||
/* do nothing */
|
||||
return message;
|
||||
}
|
|
@ -2,8 +2,7 @@
|
|||
#define DANBIAS_CLIENT_GAMECLIENTSTATE_H
|
||||
|
||||
#define NOMINMAX
|
||||
#include "L_inputClass.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "SharedStateContent.h"
|
||||
|
||||
namespace DanBias { namespace Client
|
||||
{
|
||||
|
@ -23,16 +22,22 @@ namespace DanBias { namespace Client
|
|||
ClientState_Quit
|
||||
};
|
||||
|
||||
public:
|
||||
GameClientState(void);
|
||||
virtual ~GameClientState(void);
|
||||
virtual bool Init(Oyster::Network::NetworkClient* nwClient) = 0;
|
||||
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
|
||||
typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent;
|
||||
static const NetEvent event_processed;
|
||||
|
||||
GameClientState();
|
||||
virtual ~GameClientState();
|
||||
virtual bool Init( SharedStateContent &shared ) = 0;
|
||||
virtual ClientState Update( float deltaTime ) = 0;
|
||||
virtual bool Render() = 0;
|
||||
virtual bool Release() = 0;
|
||||
virtual void ChangeState( ClientState next ) = 0;
|
||||
|
||||
virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
|
||||
/******************************************************************
|
||||
* @param message of the event
|
||||
* @return message or GameClientState::event_processed.
|
||||
******************************************************************/
|
||||
virtual const NetEvent & DataRecieved( const NetEvent &message );
|
||||
};
|
||||
} }
|
||||
|
||||
|
|
|
@ -2,232 +2,152 @@
|
|||
#include "DllInterfaces/GFXAPI.h"
|
||||
#include <Protocols.h>
|
||||
#include "NetworkClient.h"
|
||||
#include "Camera_FPS.h"
|
||||
#include "Camera_FPSV2.h"
|
||||
#include <GameServerAPI.h>
|
||||
|
||||
#include "C_obj/C_Player.h"
|
||||
#include "C_obj/C_DynamicObj.h"
|
||||
#include "C_obj/C_StaticObj.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
using namespace ::DanBias::Client;
|
||||
using namespace ::Oyster;
|
||||
using namespace ::Oyster::Network;
|
||||
using namespace ::Oyster::Math3D;
|
||||
using namespace ::GameLogic;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
using namespace ::Utility::String;
|
||||
using namespace ::Utility::Value;
|
||||
|
||||
struct GameState::MyData
|
||||
{
|
||||
MyData(){}
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
InputClass *input;
|
||||
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> *staticObjects;
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
|
||||
|
||||
bool key_forward;
|
||||
bool key_backward;
|
||||
bool key_strafeRight;
|
||||
bool key_strafeLeft;
|
||||
bool key_Shoot;
|
||||
bool key_Jump;
|
||||
|
||||
bool key_Reload_Shaders;
|
||||
|
||||
C_Player player;
|
||||
Camera_FPSV2 camera;
|
||||
|
||||
int myId;
|
||||
|
||||
} privData;
|
||||
|
||||
GameState::GameState(void)
|
||||
inline Quaternion ArrayToQuaternion( const float source[4] )
|
||||
{
|
||||
key_forward = false;
|
||||
key_backward = false;
|
||||
key_strafeRight = false;
|
||||
key_strafeLeft = false;
|
||||
return Quaternion( Float3(source[0], source[1], source[2]), source[3] );
|
||||
}
|
||||
|
||||
GameState::~GameState(void)
|
||||
GameState::GameState()
|
||||
{
|
||||
this->privData = nullptr;
|
||||
}
|
||||
|
||||
GameState::~GameState()
|
||||
{
|
||||
if( this->privData )
|
||||
this->Release();
|
||||
}
|
||||
|
||||
bool GameState::Init(NetworkClient* nwClient)
|
||||
bool GameState::Init( SharedStateContent &shared )
|
||||
{
|
||||
// load models
|
||||
privData = new MyData();
|
||||
// we may assume that shared.network is properly connected
|
||||
// and there is content in shared.dynamicObjects and shared.staticObjects
|
||||
|
||||
this->privData = new MyData();
|
||||
|
||||
this->privData->key_forward = false;
|
||||
this->privData->key_backward = false;
|
||||
this->privData->key_strafeRight = false;
|
||||
this->privData->key_strafeLeft = false;
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->input = shared.input;
|
||||
this->privData->staticObjects = &shared.staticObjects;
|
||||
this->privData->dynamicObjects = &shared.dynamicObjects;
|
||||
|
||||
LoadGame();
|
||||
Graphics::API::Option gfxOp = Graphics::API::GetOption();
|
||||
Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y;
|
||||
this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f );
|
||||
Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() );
|
||||
|
||||
//tell server ready
|
||||
nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) );
|
||||
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GameState::gameStateState GameState::LoadGame()
|
||||
void GameState::InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer )
|
||||
{
|
||||
|
||||
return gameStateState_playing;
|
||||
}
|
||||
|
||||
bool GameState::LoadModels(std::string mapFile)
|
||||
{
|
||||
GameLogic::LevelLoader levelLoader;
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<GameLogic::ObjectTypeHeader>> objects;
|
||||
objects = levelLoader.LoadLevel(mapFile);
|
||||
|
||||
int objCount = objects.size();
|
||||
int modelId = 0;
|
||||
ModelInitData modelData;
|
||||
for (int i = 0; i < objCount; i++)
|
||||
{
|
||||
GameLogic::ObjectTypeHeader* obj = objects.at(i);
|
||||
|
||||
switch (obj->typeID)
|
||||
{
|
||||
case GameLogic::ObjectType::ObjectType_LevelMetaData:
|
||||
|
||||
break;
|
||||
case GameLogic::ObjectType::ObjectType_Static:
|
||||
{
|
||||
GameLogic::ObjectHeader* staticObjData = ((GameLogic::ObjectHeader*)obj);
|
||||
|
||||
modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end());
|
||||
modelData.visible = true;
|
||||
//modelData.position = ;
|
||||
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
||||
//modelData.scale = Float3(2,2,2);
|
||||
modelData.id = modelId++;
|
||||
modelData.position = position;
|
||||
modelData.rotation = ArrayToQuaternion( rotation );
|
||||
modelData.scale = scale;
|
||||
StringToWstring( modelName, modelData.modelPath );
|
||||
modelData.id = id;
|
||||
|
||||
this->staticObjects.Push(new C_StaticObj());
|
||||
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
||||
}
|
||||
break;
|
||||
case GameLogic::ObjectType::ObjectType_Dynamic:
|
||||
if( isMyPlayer )
|
||||
{
|
||||
GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj);
|
||||
//modelData.position = ;
|
||||
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
||||
//modelData.scale = Float3(2,2,2);
|
||||
modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end());
|
||||
modelData.visible = true;
|
||||
modelData.id = modelId++;
|
||||
|
||||
this->dynamicObjects.Push(new C_DynamicObj());
|
||||
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
||||
}
|
||||
break;
|
||||
case GameLogic::ObjectType::ObjectType_Light:
|
||||
if( this->privData->player.Init(modelData) )
|
||||
{
|
||||
GameLogic::BasicLight* lightData = ((GameLogic::BasicLight*)obj);
|
||||
|
||||
switch( lightData->lightType )
|
||||
this->privData->myId = id;
|
||||
this->privData->camera.SetPosition( this->privData->player.getPos() );
|
||||
Float3 offset = Float3( 0.0f );
|
||||
offset.y = this->privData->player.getScale().y * 0.9f;
|
||||
this->privData->camera.SetHeadOffset( offset );
|
||||
this->privData->camera.UpdateOrientation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
case GameLogic::LightType_PointLight:
|
||||
C_DynamicObj *p = new C_DynamicObj();
|
||||
if( p->Init(modelData) )
|
||||
{
|
||||
//Oyster::Graphics::Definitions::Pointlight plight;
|
||||
//plight.Pos = ((GameLogic::PointLight*)lightData)->position;
|
||||
//plight.Color = lightData->diffuseColor;
|
||||
//plight.Radius = 100;
|
||||
//plight.Bright = 0.9f;
|
||||
//Oyster::Graphics::API::AddLight(plight);
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
(*this->privData->dynamicObjects)[id] = p;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
myId += modelId++;
|
||||
// add player model
|
||||
//modelData.position = ;
|
||||
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
||||
//modelData.scale = Float3(2,2,2);
|
||||
|
||||
|
||||
modelData.visible = true;
|
||||
modelData.modelPath = L"char_still_sizeref.dan";
|
||||
modelData.id = myId;
|
||||
// load models
|
||||
this->dynamicObjects.Push(new C_DynamicObj());
|
||||
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
||||
|
||||
/*C_Player* obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||
*/
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool GameState::InitCamera(Float3 startPos)
|
||||
GameClientState::ClientState GameState::Update( float deltaTime )
|
||||
{
|
||||
camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) );
|
||||
camera.SetPerspectiveProjection( pi / 4.0f, 1024.0f/768.0f, 1.0f, 1000.0f );
|
||||
camera.UpdateOrientation();
|
||||
Oyster::Graphics::API::SetProjection(camera.GetProjectionMatrix());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
|
||||
{
|
||||
myId = id;
|
||||
|
||||
ModelInitData modelData;
|
||||
C_Object* obj;
|
||||
modelData.visible = true;
|
||||
//modelData.world = world;
|
||||
modelData.position = Float3(world[12], world[13], world[14]);
|
||||
modelData.rotation = Quaternion(Float3(0,0,0), 1);
|
||||
modelData.scale = Float3(1,1,1);
|
||||
modelData.modelPath = modelName;
|
||||
modelData.id = myId;
|
||||
|
||||
obj = new C_Player();
|
||||
this->dynamicObjects.Push(obj);
|
||||
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
||||
|
||||
Float3 pos = Float3(world[12], world[13], world[14]);
|
||||
|
||||
camera.SetPosition( pos );
|
||||
camera.UpdateOrientation();
|
||||
}
|
||||
|
||||
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
|
||||
{
|
||||
//switch (privData->state)
|
||||
//{
|
||||
//case gameStateState_loading: //Will this ever happen in this scope??
|
||||
// {
|
||||
// // load map
|
||||
// // wait for all players
|
||||
// LoadGame();
|
||||
// GameLogic::Protocol_General_Status gameStatus;
|
||||
// gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
|
||||
// privData->nwClient->Send(gameStatus);
|
||||
// privData->state = gameStateState_playing;
|
||||
// }
|
||||
// break;
|
||||
//case gameStateState_playing:
|
||||
// // read server data
|
||||
// // update objects
|
||||
// {
|
||||
// readKeyInput(KeyInput);
|
||||
// camera.UpdateOrientation();
|
||||
// }
|
||||
// break;
|
||||
//case gameStateState_end:
|
||||
// return ClientState_Lobby;
|
||||
// break;
|
||||
//default:
|
||||
// break;
|
||||
//}
|
||||
//
|
||||
//// send key input to server.
|
||||
//return ClientState_Same;
|
||||
|
||||
this->ReadKeyInput();
|
||||
return this->privData->nextState;
|
||||
}
|
||||
|
||||
bool GameState::Render()
|
||||
{
|
||||
Oyster::Graphics::API::SetView( camera.GetViewMatrix() );
|
||||
Oyster::Graphics::API::SetView( this->privData->camera.GetViewMatrix() );
|
||||
|
||||
Oyster::Graphics::API::NewFrame();
|
||||
for (unsigned int i = 0; i < staticObjects.Size(); i++)
|
||||
|
||||
// for debugging to be replaced with render weapon
|
||||
this->privData->player.Render();
|
||||
|
||||
auto staticObject = this->privData->staticObjects->begin();
|
||||
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
|
||||
{
|
||||
staticObjects[i]->Render();
|
||||
staticObject->second->Render();
|
||||
}
|
||||
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
||||
|
||||
auto dynamicObject = this->privData->dynamicObjects->begin();
|
||||
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
|
||||
{
|
||||
dynamicObjects[i]->Render();
|
||||
if( dynamicObject->second )
|
||||
dynamicObject->second->Render();
|
||||
}
|
||||
|
||||
Oyster::Graphics::API::EndFrame();
|
||||
|
@ -236,8 +156,25 @@ bool GameState::Render()
|
|||
|
||||
bool GameState::Release()
|
||||
{
|
||||
if( privData )
|
||||
{
|
||||
auto staticObject = this->privData->staticObjects->begin();
|
||||
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
|
||||
{
|
||||
staticObject->second = nullptr;
|
||||
}
|
||||
|
||||
auto dynamicObject = this->privData->dynamicObjects->begin();
|
||||
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
|
||||
{
|
||||
dynamicObject->second = nullptr;
|
||||
}
|
||||
|
||||
this->privData->staticObjects->clear();
|
||||
this->privData->dynamicObjects->clear();
|
||||
|
||||
privData = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -246,147 +183,151 @@ void GameState::ChangeState( ClientState next )
|
|||
this->privData->nextState = next;
|
||||
}
|
||||
|
||||
void GameState::readKeyInput(InputClass* KeyInput)
|
||||
void GameState::ReadKeyInput()
|
||||
{
|
||||
if(KeyInput->IsKeyPressed(DIK_W))
|
||||
if( this->privData->input->IsKeyPressed(DIK_W) )
|
||||
{
|
||||
if(!key_forward)
|
||||
if(!this->privData->key_forward)
|
||||
{
|
||||
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementForward());
|
||||
key_forward = true;
|
||||
this->privData->nwClient->Send( Protocol_PlayerMovementForward() );
|
||||
this->privData->key_forward = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_forward = false;
|
||||
this->privData->key_forward = false;
|
||||
|
||||
if(KeyInput->IsKeyPressed(DIK_S))
|
||||
if( this->privData->input->IsKeyPressed(DIK_S) )
|
||||
{
|
||||
if(!key_backward)
|
||||
if( !this->privData->key_backward )
|
||||
{
|
||||
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementBackward());
|
||||
key_backward = true;
|
||||
this->privData->nwClient->Send( Protocol_PlayerMovementBackward() );
|
||||
this->privData->key_backward = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_backward = false;
|
||||
this->privData->key_backward = false;
|
||||
|
||||
if(KeyInput->IsKeyPressed(DIK_A))
|
||||
if( this->privData->input->IsKeyPressed(DIK_A) )
|
||||
{
|
||||
if(!key_strafeLeft)
|
||||
if( !this->privData->key_strafeLeft )
|
||||
{
|
||||
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementLeft());
|
||||
key_strafeLeft = true;
|
||||
this->privData->nwClient->Send( Protocol_PlayerMovementLeft() );
|
||||
this->privData->key_strafeLeft = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_strafeLeft = false;
|
||||
this->privData->key_strafeLeft = false;
|
||||
|
||||
if(KeyInput->IsKeyPressed(DIK_D))
|
||||
if( this->privData->input->IsKeyPressed(DIK_D) )
|
||||
{
|
||||
if(!key_strafeRight)
|
||||
if( !this->privData->key_strafeRight )
|
||||
{
|
||||
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementRight());
|
||||
key_strafeRight = true;
|
||||
this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
|
||||
this->privData->key_strafeRight = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_strafeRight = false;
|
||||
this->privData->key_strafeRight = false;
|
||||
|
||||
if( this->privData->input->IsKeyPressed(DIK_R) )
|
||||
{
|
||||
if( !this->privData->key_Reload_Shaders )
|
||||
{
|
||||
//this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
|
||||
#ifdef _DEBUG
|
||||
Graphics::API::ReloadShaders();
|
||||
#endif
|
||||
this->privData->key_Reload_Shaders = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
this->privData->key_Reload_Shaders = false;
|
||||
|
||||
|
||||
//send delta mouse movement
|
||||
//if (KeyInput->IsMousePressed())
|
||||
{
|
||||
camera.YawRight( -KeyInput->GetYaw() );
|
||||
camera.PitchUp( KeyInput->GetPitch() );
|
||||
camera.UpdateOrientation();
|
||||
this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f );
|
||||
this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f );
|
||||
this->privData->camera.UpdateOrientation();
|
||||
|
||||
GameLogic::Protocol_PlayerLook playerLookDir;
|
||||
Float4 look = camera.GetLook();
|
||||
|
||||
privData->nwClient->Send( playerLookDir );
|
||||
privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) );
|
||||
}
|
||||
|
||||
// shoot
|
||||
if(KeyInput->IsKeyPressed(DIK_Z))
|
||||
if( this->privData->input->IsKeyPressed(DIK_Z) )
|
||||
{
|
||||
if(!key_Shoot)
|
||||
if( !this->privData->key_Shoot )
|
||||
{
|
||||
GameLogic::Protocol_PlayerShot playerShot;
|
||||
Protocol_PlayerShot playerShot;
|
||||
playerShot.primaryPressed = true;
|
||||
playerShot.secondaryPressed = false;
|
||||
playerShot.utilityPressed = false;
|
||||
privData->nwClient->Send(playerShot);
|
||||
key_Shoot = true;
|
||||
this->privData->nwClient->Send( playerShot );
|
||||
this->privData->key_Shoot = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_Shoot = false;
|
||||
if(KeyInput->IsKeyPressed(DIK_X))
|
||||
this->privData->key_Shoot = false;
|
||||
if( this->privData->input->IsKeyPressed(DIK_X) )
|
||||
{
|
||||
if(!key_Shoot)
|
||||
if( !this->privData->key_Shoot )
|
||||
{
|
||||
GameLogic::Protocol_PlayerShot playerShot;
|
||||
Protocol_PlayerShot playerShot;
|
||||
playerShot.primaryPressed = false;
|
||||
playerShot.secondaryPressed = true;
|
||||
playerShot.utilityPressed = false;
|
||||
privData->nwClient->Send(playerShot);
|
||||
key_Shoot = true;
|
||||
this->privData->nwClient->Send( playerShot );
|
||||
this->privData->key_Shoot = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_Shoot = false;
|
||||
if(KeyInput->IsKeyPressed(DIK_C))
|
||||
this->privData->key_Shoot = false;
|
||||
if( this->privData->input->IsKeyPressed(DIK_C) )
|
||||
{
|
||||
if(!key_Shoot)
|
||||
if( !this->privData->key_Shoot )
|
||||
{
|
||||
GameLogic::Protocol_PlayerShot playerShot;
|
||||
Protocol_PlayerShot playerShot;
|
||||
playerShot.primaryPressed = false;
|
||||
playerShot.secondaryPressed = false;
|
||||
playerShot.utilityPressed = true;
|
||||
privData->nwClient->Send(playerShot);
|
||||
key_Shoot = true;
|
||||
this->privData->nwClient->Send( playerShot );
|
||||
this->privData->key_Shoot = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_Shoot = false;
|
||||
this->privData->key_Shoot = false;
|
||||
|
||||
// jump
|
||||
if(KeyInput->IsKeyPressed(DIK_SPACE))
|
||||
if( this->privData->input->IsKeyPressed(DIK_SPACE) )
|
||||
{
|
||||
if(!key_Jump)
|
||||
if(!this->privData->key_Jump)
|
||||
{
|
||||
privData->nwClient->Send(GameLogic::Protocol_PlayerJump());
|
||||
key_Jump = true;
|
||||
this->privData->nwClient->Send( Protocol_PlayerJump() );
|
||||
this->privData->key_Jump = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
key_Jump = false;
|
||||
this->privData->key_Jump = false;
|
||||
|
||||
// send event data
|
||||
//
|
||||
//if(KeyInput->IsKeyPressed(DIK_L))
|
||||
// privData->state = GameState::gameStateState_end;
|
||||
// TODO: implement sub-menu
|
||||
}
|
||||
|
||||
using namespace ::Oyster::Network;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
|
||||
// returns -1 if none found
|
||||
int FindObject( const DynamicArray<SmartPointer<C_Object>> &collection, int id )
|
||||
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
|
||||
{
|
||||
int num = collection.Size();
|
||||
for( int i = 0; i < num; ++i ) if( id == collection[i]->GetId() )
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
|
||||
{ // TODO: Reconnect
|
||||
const char *breakpoint = "temp trap";
|
||||
this->privData->nwClient->Disconnect();
|
||||
this->ChangeState( GameClientState::ClientState_Main );
|
||||
}
|
||||
|
||||
void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||
{
|
||||
CustomNetProtocol data = e.args.data.protocol;
|
||||
short ID = data[0].value.netShort; // fetching the id data.
|
||||
// fetching the id data.
|
||||
short ID = message.args.data.protocol[0].value.netShort;
|
||||
|
||||
if( ProtocolIsGameplay(ID) )
|
||||
{
|
||||
CustomNetProtocol data = message.args.data.protocol;
|
||||
|
||||
switch(ID)
|
||||
{
|
||||
case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */
|
||||
|
@ -394,76 +335,70 @@ void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEven
|
|||
case protocol_Gameplay_ObjectHealthStatus: break; /** @todo TODO: implement */
|
||||
case protocol_Gameplay_ObjectPosition:
|
||||
{
|
||||
GameLogic::Protocol_ObjectPosition decoded(data);
|
||||
Protocol_ObjectPosition decoded(data);
|
||||
|
||||
// if is this player. Remember to change camera
|
||||
if( this->myId == decoded.object_ID )
|
||||
camera.SetPosition( decoded.position );
|
||||
if( this->privData->myId == decoded.object_ID )
|
||||
this->privData->camera.SetPosition( decoded.position );
|
||||
|
||||
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
||||
if( i > -1 )
|
||||
this->dynamicObjects[i]->setPos( decoded.position );
|
||||
(*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position );
|
||||
}
|
||||
break;
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectScale:
|
||||
{
|
||||
GameLogic::Protocol_ObjectScale decoded(data);
|
||||
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
||||
if( i > -1 )
|
||||
this->dynamicObjects[i]->setScale( decoded.scale );
|
||||
Protocol_ObjectScale decoded(data);
|
||||
(*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale );
|
||||
}
|
||||
break;
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectRotation:
|
||||
{
|
||||
GameLogic::Protocol_ObjectRotation decoded(data);
|
||||
Protocol_ObjectRotation decoded(data);
|
||||
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
||||
|
||||
// if is this player. Remember to change camera
|
||||
if( this->myId == decoded.object_ID )
|
||||
camera.SetAngular( AngularAxis(rotation) );
|
||||
if( this->privData->myId == decoded.object_ID )
|
||||
this->privData->camera.SetRotation( rotation );
|
||||
|
||||
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
||||
if( i > -1 )
|
||||
this->dynamicObjects[i]->setRot( rotation );
|
||||
(*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation );
|
||||
}
|
||||
break;
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectPositionRotation:
|
||||
{
|
||||
GameLogic::Protocol_ObjectPositionRotation decoded(data);
|
||||
Protocol_ObjectPositionRotation decoded(data);
|
||||
Float3 position = decoded.position;
|
||||
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
||||
|
||||
// if is this player. Remember to change camera
|
||||
if( this->myId == decoded.object_ID )
|
||||
if( this->privData->myId == decoded.object_ID )
|
||||
{
|
||||
camera.SetPosition( position );
|
||||
camera.SetAngular( AngularAxis(rotation) );
|
||||
this->privData->camera.SetPosition( position );
|
||||
this->privData->camera.SetRotation( rotation );
|
||||
}
|
||||
|
||||
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
||||
if( i > -1 )
|
||||
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];
|
||||
if( object )
|
||||
{
|
||||
this->dynamicObjects[i]->setPos( position );
|
||||
this->dynamicObjects[i]->setRot( rotation );
|
||||
object->setPos( position );
|
||||
object->setRot( rotation );
|
||||
}
|
||||
}
|
||||
break;
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */
|
||||
case protocol_Gameplay_ObjectDisabled:
|
||||
{
|
||||
GameLogic::Protocol_ObjectDisable decoded(data);
|
||||
Protocol_ObjectDisable decoded(data);
|
||||
|
||||
int i = FindObject( this->dynamicObjects, decoded.objectID );
|
||||
if( i > -1 )
|
||||
auto object = this->privData->dynamicObjects->find( decoded.objectID );
|
||||
if( object != this->privData->dynamicObjects->end() )
|
||||
{
|
||||
this->dynamicObjects[i].Release();
|
||||
this->dynamicObjects.Pop(i);
|
||||
object->second = nullptr;
|
||||
this->privData->dynamicObjects->erase( object );
|
||||
}
|
||||
}
|
||||
break;
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectCreate:
|
||||
{
|
||||
GameLogic::Protocol_ObjectCreate decoded(data);
|
||||
Protocol_ObjectCreate decoded(data);
|
||||
C_DynamicObj* object = new C_DynamicObj();
|
||||
|
||||
ModelInitData modelData;
|
||||
|
@ -478,11 +413,16 @@ void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEven
|
|||
}
|
||||
object->Init(modelData);
|
||||
|
||||
dynamicObjects.Push(object);
|
||||
(*this->privData->dynamicObjects)[decoded.object_ID] = object;
|
||||
|
||||
}
|
||||
break;
|
||||
case protocol_Gameplay_ObjectCreatePlayer: break; /** @todo TODO: implement */
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectCreatePlayer:
|
||||
{
|
||||
Protocol_ObjectCreatePlayer decoded(data);
|
||||
this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner );
|
||||
}
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */
|
||||
case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */
|
||||
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
|
||||
|
@ -501,4 +441,6 @@ void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEven
|
|||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
#include "OysterMath.h"
|
||||
#include <string>
|
||||
|
||||
#include "Camera_FPS.h"
|
||||
#include "LevelLoader/LevelLoader.h"
|
||||
#include "C_obj/C_Player.h"
|
||||
#include "C_obj/C_DynamicObj.h"
|
||||
#include "C_obj/C_StaticObj.h"
|
||||
#include "DynamicArray.h"
|
||||
|
||||
namespace DanBias { namespace Client
|
||||
{
|
||||
class GameState : public GameClientState
|
||||
|
@ -25,38 +18,19 @@ namespace DanBias { namespace Client
|
|||
|
||||
GameState(void);
|
||||
~GameState(void);
|
||||
bool Init(Oyster::Network::NetworkClient* nwClient);
|
||||
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
|
||||
|
||||
bool LoadModels(std::string mapFile);
|
||||
bool InitCamera(Oyster::Math::Float3 startPos) ;
|
||||
void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world);
|
||||
gameStateState LoadGame();
|
||||
void readKeyInput(InputClass* KeyInput);
|
||||
|
||||
bool Init( SharedStateContent &shared );
|
||||
GameClientState::ClientState Update( float deltaTime ) override;
|
||||
void InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer );
|
||||
void ReadKeyInput();
|
||||
bool Render()override;
|
||||
bool Release()override;
|
||||
void ChangeState( ClientState next );
|
||||
|
||||
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
|
||||
const NetEvent & DataRecieved( const NetEvent &message );
|
||||
|
||||
private:
|
||||
struct MyData;
|
||||
::Utility::DynamicMemory::UniquePointer<MyData> privData;
|
||||
|
||||
bool key_forward;
|
||||
bool key_backward;
|
||||
bool key_strafeRight;
|
||||
bool key_strafeLeft;
|
||||
bool key_Shoot;
|
||||
bool key_Jump;
|
||||
Camera_FPS camera;
|
||||
|
||||
int myId;
|
||||
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_StaticObj>> staticObjects;
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_Object>> dynamicObjects;
|
||||
//Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_Player>> playObjects;
|
||||
};
|
||||
} }
|
||||
#endif
|
|
@ -28,6 +28,7 @@ struct LanMenuState::MyData
|
|||
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
InputClass *input;
|
||||
Graphics::API::Texture background;
|
||||
EventButtonCollection guiElements;
|
||||
|
||||
|
@ -46,19 +47,21 @@ LanMenuState::~LanMenuState()
|
|||
this->Release();
|
||||
}
|
||||
|
||||
bool LanMenuState::Init(Network::NetworkClient* nwClient)
|
||||
bool LanMenuState::Init( SharedStateContent &shared )
|
||||
{
|
||||
this->privData = new MyData();
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->input = shared.input;
|
||||
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
this->privData->background = Graphics::API::CreateTexture( L"color_white.png" );
|
||||
|
||||
// create guiElements
|
||||
this->privData->connectIP = new TextField<LanMenuState*>( L"earth_md.png", Float3(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
|
||||
this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
|
||||
this->privData->connectIP->ReserveLines( 1 );
|
||||
this->privData->connectIP->AppendText( L"127.0.0.1" );
|
||||
//this->privData->connectIP->AppendText( L"127.0.0.1" );
|
||||
this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
|
||||
this->privData->connectIP->SetFontHeight( 0.08f );
|
||||
this->privData->connectIP->SetLineSpacing( 0.005f );
|
||||
this->privData->connectIP->SetTopAligned();
|
||||
|
@ -66,10 +69,10 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient)
|
|||
this->privData->guiElements.AddButton( this->privData->connectIP );
|
||||
|
||||
ButtonRectangle<LanMenuState*> *guiElements;
|
||||
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"Connect", Float3(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
||||
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Connect", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
||||
this->privData->guiElements.AddButton( guiElements );
|
||||
|
||||
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"Exit", Float3(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
||||
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Exit", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
||||
this->privData->guiElements.AddButton( guiElements );
|
||||
|
||||
// bind guiElements collection to the singleton eventhandler
|
||||
|
@ -80,12 +83,12 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient)
|
|||
return true;
|
||||
}
|
||||
|
||||
GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput)
|
||||
GameClientState::ClientState LanMenuState::Update( float deltaTime )
|
||||
{
|
||||
MouseInput mouseState;
|
||||
{
|
||||
KeyInput->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
|
||||
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
|
||||
}
|
||||
|
||||
EventHandler::Instance().Update( mouseState );
|
||||
|
@ -121,8 +124,8 @@ void LanMenuState::ChangeState( ClientState next )
|
|||
{
|
||||
case GameClientState::ClientState_Lobby:
|
||||
// attempt to connect to lobby
|
||||
//if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
|
||||
// return; // TODO: temporary commented out
|
||||
if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
|
||||
return;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ namespace DanBias
|
|||
LanMenuState();
|
||||
virtual ~LanMenuState();
|
||||
|
||||
virtual bool Init(Oyster::Network::NetworkClient* nwClient);
|
||||
virtual ClientState Update(float deltaTime, InputClass* KeyInput);
|
||||
bool Init( SharedStateContent &shared );
|
||||
virtual ClientState Update( float deltaTime );
|
||||
|
||||
virtual bool Render();
|
||||
virtual bool Release();
|
||||
|
|
|
@ -22,6 +22,7 @@ struct LobbyAdminState::MyData
|
|||
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
InputClass *input;
|
||||
Graphics::API::Texture background;
|
||||
EventButtonCollection guiElements;
|
||||
} privData;
|
||||
|
@ -36,19 +37,20 @@ LobbyAdminState::~LobbyAdminState(void)
|
|||
this->Release();
|
||||
}
|
||||
|
||||
bool LobbyAdminState::Init(NetworkClient* nwClient)
|
||||
bool LobbyAdminState::Init( SharedStateContent &shared )
|
||||
{
|
||||
privData = new MyData();
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->input = shared.input;
|
||||
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
|
||||
// create buttons
|
||||
ButtonRectangle<LobbyAdminState*> *button;
|
||||
|
||||
button = new ButtonRectangle<LobbyAdminState*>( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
button = new ButtonRectangle<LobbyAdminState*>( L"earth_md.png", L"Ready", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
this->privData->guiElements.AddButton( button );
|
||||
|
||||
// bind button collection to the singleton eventhandler
|
||||
|
@ -57,7 +59,7 @@ bool LobbyAdminState::Init(NetworkClient* nwClient)
|
|||
return true;
|
||||
}
|
||||
|
||||
GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass* KeyInput)
|
||||
GameClientState::ClientState LobbyAdminState::Update( float deltaTime )
|
||||
{
|
||||
// Wishlist:
|
||||
// picking
|
||||
|
@ -70,8 +72,8 @@ GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass
|
|||
|
||||
MouseInput mouseState;
|
||||
{
|
||||
KeyInput->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
|
||||
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
|
||||
}
|
||||
|
||||
EventHandler::Instance().Update( mouseState );
|
||||
|
@ -110,10 +112,10 @@ void LobbyAdminState::ChangeState( ClientState next )
|
|||
|
||||
using namespace ::Oyster::Network;
|
||||
|
||||
void LobbyAdminState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||
const GameClientState::NetEvent & LobbyAdminState::DataRecieved( const GameClientState::NetEvent &message )
|
||||
{
|
||||
CustomNetProtocol data = e.args.data.protocol;
|
||||
short ID = data[0].value.netShort; // fetching the id data.
|
||||
// fetching the id data.
|
||||
short ID = message.args.data.protocol[0].value.netShort;
|
||||
|
||||
// Block irrelevant messages.
|
||||
if( ProtocolIsLobby(ID) )
|
||||
|
@ -139,6 +141,7 @@ void LobbyAdminState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::Clie
|
|||
default: break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyAdminState*>& e )
|
||||
|
|
|
@ -24,12 +24,12 @@ namespace DanBias
|
|||
LobbyAdminState();
|
||||
~LobbyAdminState();
|
||||
|
||||
bool Init( Oyster::Network::NetworkClient* nwClient );
|
||||
ClientState Update( float deltaTime, InputClass* KeyInput );
|
||||
bool Init( SharedStateContent &shared );
|
||||
ClientState Update( float deltaTime );
|
||||
bool Render();
|
||||
bool Release();
|
||||
void ChangeState( ClientState next );
|
||||
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
|
||||
const NetEvent & DataRecieved( const NetEvent &message );
|
||||
|
||||
private:
|
||||
struct MyData;
|
||||
|
|
|
@ -22,6 +22,7 @@ struct LobbyState::MyData
|
|||
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
InputClass *input;
|
||||
Graphics::API::Texture background;
|
||||
EventButtonCollection guiElements;
|
||||
} privData;
|
||||
|
@ -36,19 +37,20 @@ LobbyState::~LobbyState(void)
|
|||
this->Release();
|
||||
}
|
||||
|
||||
bool LobbyState::Init(NetworkClient* nwClient)
|
||||
bool LobbyState::Init( SharedStateContent &shared )
|
||||
{
|
||||
privData = new MyData();
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->input = shared.input;
|
||||
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
|
||||
// create buttons
|
||||
ButtonRectangle<LobbyState*> *button;
|
||||
|
||||
button = new ButtonRectangle<LobbyState*>( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
button = new ButtonRectangle<LobbyState*>( L"earth_md.png", L"Ready", Float4(1.0f), Float4(0.0f), Float4(0.0f), Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
this->privData->guiElements.AddButton( button );
|
||||
|
||||
// bind button collection to the singleton eventhandler
|
||||
|
@ -57,7 +59,7 @@ bool LobbyState::Init(NetworkClient* nwClient)
|
|||
return true;
|
||||
}
|
||||
|
||||
GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput)
|
||||
GameClientState::ClientState LobbyState::Update( float deltaTime )
|
||||
{
|
||||
// Wishlist:
|
||||
// picking
|
||||
|
@ -70,8 +72,8 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key
|
|||
|
||||
MouseInput mouseState;
|
||||
{
|
||||
KeyInput->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
|
||||
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
|
||||
}
|
||||
|
||||
EventHandler::Instance().Update( mouseState );
|
||||
|
@ -110,10 +112,10 @@ void LobbyState::ChangeState( ClientState next )
|
|||
|
||||
using namespace ::Oyster::Network;
|
||||
|
||||
void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||
const GameClientState::NetEvent & LobbyState::DataRecieved( const GameClientState::NetEvent &message )
|
||||
{
|
||||
CustomNetProtocol data = e.args.data.protocol;
|
||||
short ID = data[0].value.netShort; // fetching the id data.
|
||||
// fetching the id data.
|
||||
short ID = message.args.data.protocol[0].value.netShort;
|
||||
|
||||
// Block irrelevant messages.
|
||||
if( ProtocolIsLobby(ID) )
|
||||
|
@ -139,6 +141,8 @@ void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEve
|
|||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyState*>& e )
|
||||
|
|
|
@ -23,15 +23,15 @@ namespace DanBias
|
|||
class LobbyState : public GameClientState
|
||||
{
|
||||
public:
|
||||
LobbyState(void);
|
||||
~LobbyState(void);
|
||||
LobbyState();
|
||||
~LobbyState();
|
||||
|
||||
bool Init( Oyster::Network::NetworkClient* nwClient );
|
||||
ClientState Update( float deltaTime, InputClass* KeyInput );
|
||||
bool Init( SharedStateContent &shared );
|
||||
ClientState Update( float deltaTime );
|
||||
bool Render();
|
||||
bool Release();
|
||||
void ChangeState( ClientState next );
|
||||
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
|
||||
const NetEvent & DataRecieved( const NetEvent &message );
|
||||
|
||||
private:
|
||||
struct MyData;
|
||||
|
|
|
@ -24,6 +24,7 @@ struct MainState::MyData
|
|||
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
InputClass *input;
|
||||
Graphics::API::Texture background;
|
||||
EventButtonCollection guiElements;
|
||||
};
|
||||
|
@ -32,33 +33,38 @@ void OnButtonInteract_Create( Oyster::Event::ButtonEvent<MainState*>& e );
|
|||
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<MainState*>& e );
|
||||
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<MainState*>& e );
|
||||
|
||||
MainState::MainState(void) {}
|
||||
MainState::MainState() {}
|
||||
|
||||
MainState::~MainState(void)
|
||||
MainState::~MainState()
|
||||
{
|
||||
if( this->privData )
|
||||
this->Release();
|
||||
}
|
||||
|
||||
bool MainState::Init( NetworkClient* nwClient )
|
||||
bool MainState::Init( SharedStateContent &shared )
|
||||
{
|
||||
this->privData = new MyData();
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->input = shared.input;
|
||||
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
this->privData->background = Graphics::API::CreateTexture( L"color_white.png" );
|
||||
|
||||
// create buttons
|
||||
ButtonRectangle<MainState*> *button;
|
||||
Float4 TextCol = Float4(1.0f,0.0f,1.0f,1.0f);
|
||||
Float4 BackCol = Float4(1.0f,1.0f,1.0f,0.5f);
|
||||
Float4 HoverCol = Float4(0.0f,1.0f,0.0f,1.0f);
|
||||
Float4 PressCol = Float4(0.0f,0.0f,1.0f,1.0f);
|
||||
|
||||
button = new ButtonRectangle<MainState*>( L"earth_md.png", L"Create", Float3(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Create",TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f));
|
||||
this->privData->guiElements.AddButton( button );
|
||||
|
||||
button = new ButtonRectangle<MainState*>( L"skysphere_md.png", L"Join", Float3(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Join", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f));
|
||||
this->privData->guiElements.AddButton( button );
|
||||
|
||||
button = new ButtonRectangle<MainState*>( L"plane_texture_md.png", L"Quit", Float3(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Quit", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f));
|
||||
this->privData->guiElements.AddButton( button );
|
||||
|
||||
// bind button collection to the singleton eventhandler
|
||||
|
@ -67,12 +73,17 @@ bool MainState::Init( NetworkClient* nwClient )
|
|||
return true;
|
||||
}
|
||||
|
||||
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
|
||||
GameClientState::ClientState MainState::Update( float deltaTime )
|
||||
{
|
||||
MouseInput mouseState;
|
||||
{
|
||||
KeyInput->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
|
||||
bool test = this->privData->input->IsMousePressed();
|
||||
if(test)
|
||||
{
|
||||
int i = 0;
|
||||
};
|
||||
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
|
||||
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
|
||||
}
|
||||
|
||||
EventHandler::Instance().Update( mouseState );
|
||||
|
@ -85,7 +96,7 @@ bool MainState::Render()
|
|||
Graphics::API::NewFrame();
|
||||
Graphics::API::StartGuiRender();
|
||||
|
||||
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
|
||||
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) );
|
||||
this->privData->guiElements.RenderTexture();
|
||||
|
||||
Graphics::API::StartTextRender();
|
||||
|
|
|
@ -11,18 +11,18 @@ namespace DanBias
|
|||
{
|
||||
class MainState : public GameClientState
|
||||
{
|
||||
private:
|
||||
struct MyData;
|
||||
::Utility::DynamicMemory::UniquePointer<MyData> privData;
|
||||
public:
|
||||
MainState(void);
|
||||
~MainState(void);
|
||||
bool Init( Oyster::Network::NetworkClient* nwClient );
|
||||
ClientState Update(float deltaTime, InputClass* KeyInput);
|
||||
MainState();
|
||||
~MainState();
|
||||
bool Init( SharedStateContent &shared );
|
||||
ClientState Update( float deltaTime );
|
||||
|
||||
bool Render();
|
||||
bool Release();
|
||||
void ChangeState( ClientState next );
|
||||
private:
|
||||
struct MyData;
|
||||
::Utility::DynamicMemory::UniquePointer<MyData> privData;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
#include "NetLoadState.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "../Game/GameProtocols/Protocols.h"
|
||||
#include "OysterMath.h"
|
||||
#include "Protocols.h"
|
||||
#include "LevelLoader\LevelLoader.h"
|
||||
#include "Utilities.h"
|
||||
#include "C_obj\C_StaticObj.h"
|
||||
#include "C_obj\C_DynamicObj.h"
|
||||
|
||||
using namespace ::DanBias::Client;
|
||||
using namespace ::Oyster;
|
||||
using namespace ::Oyster::Math;
|
||||
using namespace ::Oyster::Network;
|
||||
using namespace ::GameLogic;
|
||||
using namespace ::Utility::String;
|
||||
|
||||
struct NetLoadState::MyData
|
||||
{
|
||||
|
@ -13,9 +20,18 @@ struct NetLoadState::MyData
|
|||
|
||||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
Graphics::API::Texture background;
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> *staticObjects;
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
|
||||
|
||||
bool loading;
|
||||
};
|
||||
|
||||
inline Quaternion ArrayToQuaternion( const float source[4] )
|
||||
{
|
||||
return Quaternion( Float3(source[0], source[1], source[2]), source[3] );
|
||||
}
|
||||
|
||||
NetLoadState::NetLoadState(void) {}
|
||||
|
||||
NetLoadState::~NetLoadState(void)
|
||||
|
@ -24,28 +40,39 @@ NetLoadState::~NetLoadState(void)
|
|||
this->Release();
|
||||
}
|
||||
|
||||
bool NetLoadState::Init( NetworkClient* nwClient )
|
||||
bool NetLoadState::Init( SharedStateContent &shared )
|
||||
{
|
||||
this->privData = new MyData();
|
||||
|
||||
this->privData->nextState = GameClientState::ClientState_Same;
|
||||
this->privData->nwClient = nwClient;
|
||||
this->privData->nwClient = shared.network;
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
this->privData->dynamicObjects = &shared.dynamicObjects;
|
||||
this->privData->staticObjects = &shared.staticObjects;
|
||||
|
||||
this->privData->loading = false;
|
||||
|
||||
// we may assume that nwClient is properly connected to the server
|
||||
// signals querry to server for loading instructions
|
||||
nwClient->Send( Protocol_QuerryGameType() );
|
||||
this->privData->nwClient->Send( Protocol_QuerryGameType() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput)
|
||||
GameClientState::ClientState NetLoadState::Update( float deltaTime )
|
||||
{
|
||||
return this->privData->nextState;
|
||||
}
|
||||
|
||||
bool NetLoadState::Render()
|
||||
{
|
||||
Graphics::API::NewFrame();
|
||||
Graphics::API::StartGuiRender();
|
||||
|
||||
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
|
||||
|
||||
Graphics::API::EndFrame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -63,14 +90,25 @@ void NetLoadState::ChangeState( ClientState next )
|
|||
this->privData->nextState = next;
|
||||
}
|
||||
|
||||
void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||
const GameClientState::NetEvent & NetLoadState::DataRecieved( const GameClientState::NetEvent &message )
|
||||
{
|
||||
// fetching the id data.
|
||||
short ID = e.args.data.protocol[0].value.netShort;
|
||||
short ID = message.args.data.protocol[0].value.netShort;
|
||||
|
||||
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
|
||||
if( ID == protocol_Lobby_CreateGame )
|
||||
{
|
||||
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
|
||||
if( !this->privData->loading )
|
||||
{
|
||||
this->LoadGame( Protocol_LobbyCreateGame(message.args.data.protocol).mapName );
|
||||
this->ChangeState( ClientState_Game );
|
||||
this->privData->loading = false;
|
||||
}
|
||||
return GameClientState::event_processed;
|
||||
}
|
||||
else
|
||||
{ // HACK: Debug trap
|
||||
const char *breakPoint = "Being greedy.";
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +116,73 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
|
|||
{
|
||||
this->privData->loading = true;
|
||||
|
||||
// TODO: ask Sam about level loader
|
||||
LevelLoader loader( "..\\Content\\Worlds\\" );
|
||||
auto objects = loader.LoadLevel( fileName );
|
||||
auto object = objects.begin();
|
||||
ObjectTypeHeader *oth;
|
||||
|
||||
int objectID = 100; // first 100 is reserved for players. This is how the server does it.
|
||||
|
||||
for( ; object != objects.end(); ++object )
|
||||
{
|
||||
++objectID;
|
||||
oth = (ObjectTypeHeader*)(*object._Ptr);
|
||||
switch( oth->typeID )
|
||||
{
|
||||
case ObjectType::ObjectType_Static:
|
||||
{
|
||||
ObjectHeader *oh = (ObjectHeader*)oth;
|
||||
|
||||
ModelInitData desc;
|
||||
desc.id = objectID;
|
||||
StringToWstring( oh->ModelFile, desc.modelPath );
|
||||
desc.position = oh->position;
|
||||
desc.rotation = ArrayToQuaternion( oh->rotation );
|
||||
desc.scale = oh->scale;
|
||||
desc.visible = true;
|
||||
|
||||
C_StaticObj *staticObject = new C_StaticObj();
|
||||
if( staticObject->Init( desc ) )
|
||||
{
|
||||
(*this->privData->staticObjects)[objectID] = staticObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete staticObject;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ObjectType::ObjectType_Dynamic:
|
||||
{
|
||||
ObjectHeader *oh = (ObjectHeader*)oth;
|
||||
|
||||
ModelInitData desc;
|
||||
desc.id = objectID;
|
||||
StringToWstring( oh->ModelFile, desc.modelPath );
|
||||
desc.position = oh->position;
|
||||
desc.rotation = ArrayToQuaternion( oh->rotation );
|
||||
desc.scale = oh->scale;
|
||||
desc.visible = true;
|
||||
|
||||
C_DynamicObj *dynamicObject = new C_DynamicObj();
|
||||
if( dynamicObject->Init( desc ) )
|
||||
{
|
||||
(*this->privData->dynamicObjects)[objectID] = dynamicObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete dynamicObject;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ObjectType::ObjectType_Light:
|
||||
{
|
||||
/* TODO: implement light into the leveformat */
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
this->privData->nextState = ClientState::ClientState_Game;
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ namespace DanBias
|
|||
NetLoadState( );
|
||||
virtual ~NetLoadState( );
|
||||
|
||||
bool Init( Oyster::Network::NetworkClient* nwClient );
|
||||
ClientState Update( float deltaTime, InputClass* KeyInput );
|
||||
bool Init( SharedStateContent &shared );
|
||||
ClientState Update( float deltaTime );
|
||||
|
||||
bool Render();
|
||||
bool Release();
|
||||
void ChangeState( ClientState next );
|
||||
|
||||
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
|
||||
const NetEvent & DataRecieved( const NetEvent &message );
|
||||
|
||||
private:
|
||||
struct MyData;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/********************************************************************
|
||||
* Created by Dan Andersson, 2014
|
||||
* Contains a shared memory struct.
|
||||
* Whihc reference passed seamlessly between the game states
|
||||
* at their Init calls.
|
||||
********************************************************************/
|
||||
|
||||
#ifndef SHAREDSTATECONTENT_H
|
||||
#define SHAREDSTATECONTENT_H
|
||||
|
||||
#include <map>
|
||||
#include "Utilities.h"
|
||||
#include "C_Object.h"
|
||||
#include "C_obj\C_StaticObj.h"
|
||||
#include "C_obj\C_DynamicObj.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "L_inputClass.h"
|
||||
|
||||
namespace DanBias { namespace Client
|
||||
{
|
||||
struct SharedStateContent
|
||||
{
|
||||
public:
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> staticObjects;
|
||||
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> dynamicObjects;
|
||||
::Oyster::Network::NetworkClient *network;
|
||||
InputClass* input;
|
||||
};
|
||||
} }
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
|
|
|
@ -54,10 +54,9 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const
|
|||
|
||||
void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& mem) const
|
||||
{
|
||||
|
||||
mem.Resize(level->dynamicObjects.Size());
|
||||
for(int i = 0; i < (int)level->dynamicObjects.Size(); i++)
|
||||
{
|
||||
mem[i] = level->dynamicObjects[i];
|
||||
}
|
||||
|
||||
}
|
|
@ -197,12 +197,15 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj)
|
|||
rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic);
|
||||
return rigidBody;
|
||||
}
|
||||
void Level::InitiateLevel(std::wstring levelPath)
|
||||
bool Level::InitiateLevel(std::wstring levelPath)
|
||||
{
|
||||
LevelLoader ll;
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
|
||||
objects = ll.LoadLevel(levelPath);
|
||||
|
||||
if(objects.size() == 0)
|
||||
return false;
|
||||
|
||||
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
|
||||
API::Instance().SetGravity(200);
|
||||
int objCount = objects.size();
|
||||
|
@ -332,8 +335,9 @@ void Level::InitiateLevel(std::wstring levelPath)
|
|||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void Level::InitiateLevel(float radius)
|
||||
bool Level::InitiateLevel(float radius)
|
||||
{
|
||||
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
|
||||
API::Instance().SetGravity(200);
|
||||
|
@ -396,6 +400,7 @@ void Level::InitiateLevel(float radius)
|
|||
|
||||
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f);
|
||||
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
void Level::AddPlayerToTeam(Player *player, int teamID)
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace GameLogic
|
|||
* Initiates a level for players to play on
|
||||
* @param levelPath: Path to a file that contains all information on the level
|
||||
********************************************************/
|
||||
void InitiateLevel(std::wstring levelPath);
|
||||
void InitiateLevel(float radius);
|
||||
bool InitiateLevel(std::wstring levelPath);
|
||||
bool InitiateLevel(float radius);
|
||||
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
|
||||
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::wstring file
|
|||
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||
|
||||
// Check if file was loaded, else return empty vector
|
||||
if(bufferSize == 0)
|
||||
if(!buffer)
|
||||
{
|
||||
return std::vector<SmartPointer<ObjectTypeHeader>>();
|
||||
}
|
||||
|
|
|
@ -41,61 +41,41 @@ namespace GameLogic
|
|||
|
||||
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
|
||||
{
|
||||
short clientID; // The unuiqe id reprsenting a specific client
|
||||
std::string modelName;
|
||||
float worldMatrix[16];
|
||||
char majorVersion;
|
||||
char minorVersion;
|
||||
std::string mapName;
|
||||
|
||||
Protocol_LobbyCreateGame()
|
||||
{
|
||||
int c = 0;
|
||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
||||
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
||||
for (int i = 0; i <= 16; i++)
|
||||
{
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
}
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
}
|
||||
Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16])
|
||||
Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name)
|
||||
{
|
||||
int c = 0;
|
||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
||||
for (int i = 0; i <= 16; i++)
|
||||
{
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
||||
}
|
||||
|
||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
|
||||
clientID = _clientID;
|
||||
modelName = name;
|
||||
memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16);
|
||||
this->majorVersion = majorVersion;
|
||||
this->minorVersion = minorVersion;
|
||||
this->mapName = name;
|
||||
}
|
||||
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
|
||||
{
|
||||
int c = 1;
|
||||
clientID = o[c++].value.netInt;
|
||||
for (int i = 0; i <= 16; i++)
|
||||
{
|
||||
this->worldMatrix[i] = o[c++].value.netFloat;
|
||||
}
|
||||
modelName.assign(o[c++].value.netCharPtr);
|
||||
this->majorVersion = o[1].value.netChar;
|
||||
this->minorVersion = o[2].value.netChar;
|
||||
this->mapName.assign(o[3].value.netCharPtr);
|
||||
}
|
||||
Oyster::Network::CustomNetProtocol GetProtocol() override
|
||||
{
|
||||
int c = 1;
|
||||
protocol[c++].value = clientID;
|
||||
|
||||
for (int i = 0; i <= 16; i++)
|
||||
{
|
||||
this->protocol[c++].value = this->worldMatrix[i];
|
||||
}
|
||||
protocol.Set(c++, this->modelName);
|
||||
protocol[1].value = this->majorVersion;
|
||||
protocol[2].value = this->minorVersion;
|
||||
protocol.Set(3, this->mapName);
|
||||
return protocol;
|
||||
}
|
||||
|
||||
|
|
|
@ -476,7 +476,21 @@ namespace GameLogic
|
|||
}
|
||||
Protocol_ObjectCreate( Oyster::Network::CustomNetProtocol& p )
|
||||
{
|
||||
/** @todo TODO: not implemented */
|
||||
this->object_ID = p[1].value.netInt;
|
||||
this->name.assign(p[2].value.netCharPtr);
|
||||
|
||||
this->position[0] = p[3].value.netFloat;
|
||||
this->position[1] = p[4].value.netFloat;
|
||||
this->position[2] = p[5].value.netFloat;
|
||||
|
||||
this->rotationQ[0] = p[6].value.netFloat;
|
||||
this->rotationQ[1] = p[7].value.netFloat;
|
||||
this->rotationQ[2] = p[8].value.netFloat;
|
||||
this->rotationQ[3] = p[9].value.netFloat;
|
||||
|
||||
this->scale[0] = p[10].value.netFloat;
|
||||
this->scale[1] = p[11].value.netFloat;
|
||||
this->scale[2] = p[12].value.netFloat;
|
||||
}
|
||||
Protocol_ObjectCreate(float p[3], float r[4], float s[3], int id, char *path)
|
||||
{
|
||||
|
@ -532,14 +546,14 @@ namespace GameLogic
|
|||
//#define protocol_Gameplay_ObjectCreatePlayer 359
|
||||
struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject
|
||||
{
|
||||
//ObjectType type; //ie player, box or whatever
|
||||
int object_ID;
|
||||
int teamId;
|
||||
std::string name;
|
||||
std::string meshName;
|
||||
float position[3];
|
||||
float rotation[3];
|
||||
float scale[3];
|
||||
/*1*/ int object_ID;
|
||||
/*2*/ int teamId;
|
||||
/*3*/ bool owner;
|
||||
/*4*/ std::string name;
|
||||
/*5*/ std::string meshName;
|
||||
/*6 - 8*/ float position[3];
|
||||
/*9 - 11*/ float rotationQ[4];
|
||||
/*12 - 14*/ float scale[3];
|
||||
|
||||
Protocol_ObjectCreatePlayer()
|
||||
{
|
||||
|
@ -550,28 +564,47 @@ namespace GameLogic
|
|||
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
|
||||
//TEAM_ID
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
|
||||
//OWNER
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
|
||||
//PLAYER-NAME
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//MESH-NAME
|
||||
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//MESH-NAME
|
||||
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//POSITION
|
||||
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
|
||||
//ROTATION
|
||||
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
|
||||
//ROTATION
|
||||
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
|
||||
//SCALE
|
||||
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
|
||||
//SCALE
|
||||
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
|
||||
}
|
||||
Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p)
|
||||
{
|
||||
this->object_ID = p[1].value.netInt;
|
||||
this->teamId = this->protocol[2].value.netInt;
|
||||
this->owner = this->protocol[3].value.netBool;
|
||||
this->name.assign(p[4].value.netCharPtr);
|
||||
this->meshName.assign(p[5].value.netCharPtr);
|
||||
|
||||
this->position[0] = p[6].value.netFloat;
|
||||
this->position[1] = p[7].value.netFloat;
|
||||
this->position[2] = p[8].value.netFloat;
|
||||
|
||||
this->rotationQ[0] = p[9].value.netFloat;
|
||||
this->rotationQ[1] = p[10].value.netFloat;
|
||||
this->rotationQ[2] = p[11].value.netFloat;
|
||||
this->rotationQ[3] = p[12].value.netFloat;
|
||||
|
||||
this->scale[0] = p[13].value.netFloat;
|
||||
this->scale[1] = p[14].value.netFloat;
|
||||
this->scale[2] = p[15].value.netFloat;
|
||||
}
|
||||
Protocol_ObjectCreatePlayer(float position[3], float rotation[3], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName)
|
||||
Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, bool owner, int teamID, std::string name, std::string meshName)
|
||||
{
|
||||
this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
|
@ -580,29 +613,33 @@ namespace GameLogic
|
|||
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
|
||||
//TEAM_ID
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
|
||||
//OWNER
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
|
||||
//PLAYER-NAME
|
||||
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//MESH-NAME
|
||||
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//MESH-NAME
|
||||
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
|
||||
//POSITION
|
||||
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
|
||||
//ROTATION
|
||||
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
|
||||
//ROTATION
|
||||
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
|
||||
//SCALE
|
||||
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
|
||||
//SCALE
|
||||
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
|
||||
this->protocol[15].type = Oyster::Network::NetAttributeType_Float;
|
||||
|
||||
this->object_ID = ObjectID;
|
||||
this->teamId = teamID;
|
||||
this->owner = owner;
|
||||
this->name = name;
|
||||
this->meshName = meshName;
|
||||
memcpy(&this->position[0], &position[0], sizeof(float)*3);
|
||||
memcpy(&this->rotation[0], &rotation[0], sizeof(float)*3);
|
||||
memcpy(&this->rotationQ[0], &rotation[0], sizeof(float)*4);
|
||||
memcpy(&this->scale[0], &scale[0], sizeof(float)*3);
|
||||
}
|
||||
Oyster::Network::CustomNetProtocol GetProtocol() override
|
||||
|
@ -610,21 +647,23 @@ namespace GameLogic
|
|||
|
||||
this->protocol[1].value = this->object_ID;
|
||||
this->protocol[2].value = this->teamId;
|
||||
this->protocol.Set(3, this->name);
|
||||
this->protocol.Set(4, this->meshName);
|
||||
this->protocol[3].value = this->owner;
|
||||
this->protocol.Set(4, this->name);
|
||||
this->protocol.Set(5, this->meshName);
|
||||
|
||||
//POSITION
|
||||
this->protocol[5].value = this->position[0];
|
||||
this->protocol[6].value = this->position[1];
|
||||
this->protocol[7].value = this->position[2];
|
||||
this->protocol[6].value = this->position[0];
|
||||
this->protocol[7].value = this->position[1];
|
||||
this->protocol[8].value = this->position[2];
|
||||
//ROTATION
|
||||
this->protocol[8].value = this->rotation[0];
|
||||
this->protocol[9].value = this->rotation[1];
|
||||
this->protocol[10].value = this->rotation[2];
|
||||
this->protocol[9].value = this->rotationQ[0];
|
||||
this->protocol[10].value = this->rotationQ[1];
|
||||
this->protocol[11].value = this->rotationQ[2];
|
||||
this->protocol[12].value = this->rotationQ[3];
|
||||
//SCALE
|
||||
this->protocol[11].value = this->scale[0];
|
||||
this->protocol[12].value = this->scale[1];
|
||||
this->protocol[13].value = this->scale[2];
|
||||
this->protocol[13].value = this->scale[0];
|
||||
this->protocol[14].value = this->scale[1];
|
||||
this->protocol[15].value = this->scale[2];
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#define DANBIASSERVER_CLIENT_OBJECT_H
|
||||
|
||||
#include <NetworkClient.h>
|
||||
#include <NetworkSession.h>
|
||||
#include <PostBox\PostBox.h>
|
||||
#include <GameAPI.h>
|
||||
#include <Utilities.h>
|
||||
|
@ -17,27 +18,59 @@ namespace DanBias
|
|||
class GameClient
|
||||
{
|
||||
public:
|
||||
GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client, GameLogic::IPlayerData* player);
|
||||
enum ClientState
|
||||
{
|
||||
ClientState_CreatingGame,
|
||||
ClientState_Ready,
|
||||
};
|
||||
|
||||
public:
|
||||
GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> nwClient);
|
||||
virtual~GameClient();
|
||||
|
||||
GameLogic::IPlayerData* GetPlayer();
|
||||
GameLogic::IPlayerData* ReleasePlayer();
|
||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> GetClient();
|
||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> ReleaseClient();
|
||||
inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; }
|
||||
inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); }
|
||||
|
||||
float GetSinceLastResponse() const;
|
||||
bool IsReady() const;
|
||||
bool Equals(const Oyster::Network::NetworkClient* c);
|
||||
inline bool Equals(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; }
|
||||
inline bool Equals(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); }
|
||||
|
||||
inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; }
|
||||
inline std::wstring GetAlias() const { return this->alias; }
|
||||
inline std::wstring GetCharacter() const { return this->character; }
|
||||
inline bool IsReady() const { return this->isReady; }
|
||||
inline GameLogic::IPlayerData* GetPlayer() const { return this->player; }
|
||||
Oyster::Network::NetClient GetClient() const { return this->client; }
|
||||
ClientState GetState() const { return this->state; }
|
||||
|
||||
|
||||
void SetPlayer(GameLogic::IPlayerData* player);
|
||||
void SetReadyState(bool isReady);
|
||||
void SetAlias(std::wstring alias);
|
||||
void SetCharacter(std::wstring character);
|
||||
void SetSinceLastResponse(float seconds);
|
||||
void SetState(ClientState state);
|
||||
|
||||
GameLogic::IPlayerData* ReleasePlayer();
|
||||
Oyster::Network::NetClient ReleaseClient();
|
||||
|
||||
//NetworkSpecific
|
||||
void SetOwner(Oyster::Network::NetworkSession* owner);
|
||||
void UpdateClient();
|
||||
|
||||
private:
|
||||
GameLogic::IPlayerData* player;
|
||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
|
||||
Oyster::Network::NetClient client;
|
||||
|
||||
bool isReady;
|
||||
float secondsSinceLastResponse;
|
||||
};
|
||||
|
||||
std::wstring alias;
|
||||
std::wstring character;
|
||||
|
||||
ClientState state;
|
||||
};
|
||||
}//End namespace DanBias
|
||||
|
||||
typedef Utility::DynamicMemory::SmartPointer<DanBias::GameClient> gClient;
|
||||
|
||||
#endif // !DANBIASSERVER_CLIENT_OBJECT_H
|
||||
|
|
|
@ -15,11 +15,18 @@ namespace DanBias
|
|||
{
|
||||
struct LobbyLevelData
|
||||
{
|
||||
int mapNumber;
|
||||
int maxClients;
|
||||
int gameMode;
|
||||
int gameTime;
|
||||
std::string gameName;
|
||||
int gameTimeInMinutes;
|
||||
std::wstring gameMode;
|
||||
std::wstring mapName;
|
||||
std::wstring gameName;
|
||||
LobbyLevelData()
|
||||
: maxClients(10)
|
||||
, gameTimeInMinutes(10)
|
||||
, gameMode(L"unknown")
|
||||
, mapName(L"unknown")
|
||||
, gameName(L"unknown")
|
||||
{ }
|
||||
};
|
||||
class GameLobby :public Oyster::Network::NetworkSession
|
||||
{
|
||||
|
@ -31,34 +38,44 @@ namespace DanBias
|
|||
|
||||
void SetGameDesc(const LobbyLevelData& desc);
|
||||
void GetGameDesc(LobbyLevelData& desc);
|
||||
bool StartGameSession();
|
||||
/**
|
||||
* If param is true, the server will start a game session regardless of clients connected.
|
||||
*/
|
||||
bool StartGameSession( bool forceStart );
|
||||
|
||||
int GetGameSessionClientCount();
|
||||
|
||||
private:
|
||||
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c);
|
||||
|
||||
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
|
||||
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
|
||||
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
|
||||
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
|
||||
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
|
||||
void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
||||
void LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
||||
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
|
||||
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
|
||||
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
|
||||
void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState:
|
||||
void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType:
|
||||
|
||||
private:
|
||||
int FindClient(Oyster::Network::NetworkClient* c);
|
||||
|
||||
private:
|
||||
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
||||
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
||||
void ProcessClients() override;
|
||||
bool Attach(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
||||
|
||||
private:
|
||||
Utility::WinTimer timer;
|
||||
float refreshFrequency;
|
||||
//Utility::WinTimer timer;
|
||||
//float refreshFrequency;
|
||||
|
||||
Utility::DynamicMemory::LinkedList<Oyster::Network::NetworkClient*> readyList;
|
||||
GameSession gameSession;
|
||||
LobbyLevelData description;
|
||||
Utility::DynamicMemory::SmartPointer<DanBias::GameClient> sessionOwner;
|
||||
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> gClients;
|
||||
};
|
||||
}//End namespace DanBias
|
||||
#endif // !DANBIASGAME_GAMELOBBY_H
|
||||
|
|
|
@ -55,16 +55,24 @@ namespace DanBias
|
|||
static void NotifyWhenClientConnect(ClientConnectedNotify func);
|
||||
static void NotifyWhenClientDisconnect(ClientDisconnectedNotify func);
|
||||
|
||||
static void GameSetMapName(const wchar_t* val);
|
||||
static void GameSetMaxClients(const int& val);
|
||||
static void GameSetGameMode(const wchar_t* val);
|
||||
static void GameSetGameTime(const int& val);
|
||||
static int GameGetMapId();
|
||||
static int GameGetMaxClients();
|
||||
static int GameGetGameMode();
|
||||
static void GameSetMaxClients(const int& val);
|
||||
static void GameSetGameName(const wchar_t* val);
|
||||
static void GameSetMapName(const wchar_t* val);
|
||||
static void GameSetGameMode(const wchar_t* val);
|
||||
|
||||
static int GameGetGameTime();
|
||||
static const char* GameGetGameName();
|
||||
static bool GameStart();
|
||||
static int GameGetMaxClients();
|
||||
static const wchar_t* GameGetGameMode();
|
||||
static const wchar_t* GameGetGameName();
|
||||
static const wchar_t* GameGetMapName();
|
||||
static int GetConnectedClientCount();
|
||||
|
||||
/* Starts a game
|
||||
* @param forceStart If forceStart is true, server will start with or without clients.
|
||||
* If there are clients not "ready" the will be stareted anyways.
|
||||
*/
|
||||
static bool GameStart(bool forceStart);
|
||||
|
||||
|
||||
};//End class DanBiasServer
|
||||
|
|
|
@ -31,12 +31,12 @@ namespace DanBias
|
|||
*/
|
||||
struct GameDescription
|
||||
{
|
||||
int maxClients;
|
||||
int mapNumber;
|
||||
int gameMode;
|
||||
int gameTime;
|
||||
unsigned int maxClients;
|
||||
std::wstring mapName;
|
||||
std::wstring gameMode;
|
||||
int gameTimeMinutes;
|
||||
Oyster::Network::NetworkSession* owner;
|
||||
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -44,7 +44,7 @@ namespace DanBias
|
|||
virtual~GameSession();
|
||||
|
||||
/** Initiates and creates a game session. */
|
||||
bool Create(GameDescription& desc);
|
||||
bool Create(GameDescription& desc, bool forceStart);
|
||||
|
||||
/** Runs the game session (ie starts the game loop). */
|
||||
void Run();
|
||||
|
@ -52,23 +52,27 @@ namespace DanBias
|
|||
/** Join an existing/running game session
|
||||
* @param client The client to attach to the session
|
||||
*/
|
||||
bool Attach(Oyster::Network::NetClient client) override;
|
||||
void CloseSession( bool dissconnectClients ) override;
|
||||
bool Join(gClient client);
|
||||
|
||||
//void CloseSession( bool dissconnectClients ) override;
|
||||
|
||||
inline bool IsCreated() const { return this->isCreated; }
|
||||
inline bool IsRunning() const { return this->isRunning; }
|
||||
operator bool() { return (this->isCreated && this->isCreated); }
|
||||
operator bool() { return (this->isCreated && this->isRunning); }
|
||||
|
||||
//Private member functions
|
||||
private:
|
||||
// TODO: find out what this method does..
|
||||
// Client event callback function
|
||||
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
||||
void ProcessClients() override;
|
||||
bool Send(Oyster::Network::CustomNetProtocol& message) override;
|
||||
bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override;
|
||||
|
||||
//Sends a client to the owner, if obj is NULL then all clients is sent
|
||||
//Sends a client to the owner, if param is NULL then all clients is sent
|
||||
void SendToOwner(DanBias::GameClient* obj);
|
||||
|
||||
//Derived from IThreadObject
|
||||
void ThreadEntry() override;
|
||||
void ThreadEntry( ) override;
|
||||
bool DoWork ( ) override;
|
||||
|
||||
|
||||
|
@ -98,8 +102,8 @@ namespace DanBias
|
|||
|
||||
//Private member variables
|
||||
private:
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
||||
Utility::DynamicMemory::SmartPointer<DanBias::GameClient> sessionOwner;
|
||||
Utility::DynamicMemory::DynamicArray<gClient> gClients;
|
||||
gClient sessionOwner;
|
||||
Oyster::Thread::OysterThread worker;
|
||||
GameLogic::GameAPI& gameInstance;
|
||||
GameLogic::ILevelData *levelData;
|
||||
|
@ -115,6 +119,7 @@ namespace DanBias
|
|||
//TODO: Remove this uggly hax
|
||||
static GameSession* gameSession;
|
||||
|
||||
|
||||
};//End GameSession
|
||||
}//End namespace DanBias
|
||||
#endif // !DANBIASSERVER_GAME_SESSION_H
|
|
@ -12,51 +12,27 @@ using namespace DanBias;
|
|||
using namespace GameLogic;
|
||||
|
||||
|
||||
GameClient::GameClient(SmartPointer<NetworkClient> client, GameLogic::IPlayerData* player)
|
||||
GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> nwClient)
|
||||
{
|
||||
this->client = client;
|
||||
this->player = player;
|
||||
this->client = nwClient;
|
||||
this->player = 0;
|
||||
isReady = false;
|
||||
this->character = L"Unknown";
|
||||
this->alias = L"Unknown";
|
||||
this->secondsSinceLastResponse = 0.0f;
|
||||
}
|
||||
GameClient::~GameClient()
|
||||
{
|
||||
this->client->Disconnect();
|
||||
this->player = 0;
|
||||
isReady = false;
|
||||
this->isReady = false;
|
||||
this->character = L"Unknown";
|
||||
this->alias = L"Unknown";
|
||||
this->secondsSinceLastResponse = 0.0f;
|
||||
}
|
||||
|
||||
GameLogic::IPlayerData* GameClient::GetPlayer()
|
||||
void GameClient::SetPlayer(GameLogic::IPlayerData* player)
|
||||
{
|
||||
return this->player;
|
||||
}
|
||||
GameLogic::IPlayerData* GameClient::ReleasePlayer()
|
||||
{
|
||||
GameLogic::IPlayerData *temp = this->player;
|
||||
this->player = 0;
|
||||
return temp;
|
||||
}
|
||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::GetClient()
|
||||
{
|
||||
return this->client;
|
||||
}
|
||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::ReleaseClient()
|
||||
{
|
||||
SmartPointer<Oyster::Network::NetworkClient> temp = this->client;
|
||||
this->client = 0;
|
||||
return temp;
|
||||
}
|
||||
|
||||
float GameClient::GetSinceLastResponse() const
|
||||
{
|
||||
return this->secondsSinceLastResponse;
|
||||
}
|
||||
bool GameClient::IsReady() const
|
||||
{
|
||||
return this->isReady;
|
||||
}
|
||||
bool GameClient::Equals(const NetworkClient* c)
|
||||
{
|
||||
return (c->GetID() == this->client->GetID());
|
||||
this->player = player;
|
||||
}
|
||||
void GameClient::SetReadyState(bool r)
|
||||
{
|
||||
|
@ -66,5 +42,44 @@ void GameClient::SetSinceLastResponse(float s)
|
|||
{
|
||||
this->secondsSinceLastResponse = s;
|
||||
}
|
||||
void GameClient::SetAlias(std::wstring alias)
|
||||
{
|
||||
this->alias = alias;
|
||||
}
|
||||
void GameClient::SetCharacter(std::wstring character)
|
||||
{
|
||||
this->character = character;
|
||||
}
|
||||
void GameClient::SetState(ClientState state)
|
||||
{
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
|
||||
void GameClient::SetOwner(Oyster::Network::NetworkSession* owner)
|
||||
{
|
||||
this->client->SetOwner(owner);
|
||||
}
|
||||
void GameClient::UpdateClient()
|
||||
{
|
||||
switch (this->state)
|
||||
{
|
||||
case ClientState_Ready:
|
||||
this->client->Update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IPlayerData* GameClient::ReleasePlayer()
|
||||
{
|
||||
IPlayerData* temp = this->player;
|
||||
this->player = 0;
|
||||
return temp;
|
||||
}
|
||||
NetClient GameClient::ReleaseClient()
|
||||
{
|
||||
NetClient temp = this->client;
|
||||
this->client = 0;
|
||||
return temp;
|
||||
}
|
||||
|
|
|
@ -11,77 +11,104 @@ using namespace Oyster::Network;
|
|||
using namespace Oyster;
|
||||
using namespace GameLogic;
|
||||
|
||||
namespace DanBias
|
||||
using namespace DanBias;
|
||||
|
||||
GameLobby::GameLobby()
|
||||
{ }
|
||||
GameLobby::~GameLobby()
|
||||
{
|
||||
this->gClients.Clear();
|
||||
}
|
||||
void GameLobby::Release()
|
||||
{
|
||||
GameLobby::GameLobby()
|
||||
{ }
|
||||
|
||||
GameLobby::~GameLobby()
|
||||
{
|
||||
this->clients.Clear();
|
||||
}
|
||||
|
||||
void GameLobby::Release()
|
||||
{
|
||||
NetworkSession::CloseSession(true);
|
||||
this->gameSession.CloseSession(true);
|
||||
}
|
||||
void GameLobby::Update()
|
||||
{
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->gClients[i]->GetClient()->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
|
||||
{
|
||||
this->description.gameMode = desc.gameMode;
|
||||
this->description.gameName = desc.gameName;
|
||||
this->description.mapName = desc.mapName;
|
||||
this->description.gameTimeInMinutes = desc.gameTimeInMinutes;
|
||||
this->description.maxClients = desc.maxClients;
|
||||
|
||||
if(this->gClients.Size() > (unsigned int)desc.maxClients)
|
||||
{
|
||||
//Kick overflow
|
||||
for (unsigned int i = (unsigned int)desc.maxClients - 1; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->gClients[i]->GetClient()->Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
this->gClients.Resize((unsigned int)desc.maxClients);
|
||||
|
||||
}
|
||||
void GameLobby::GetGameDesc(LobbyLevelData& desc)
|
||||
{
|
||||
desc.gameTimeInMinutes = this->description.gameTimeInMinutes;
|
||||
desc.maxClients = this->description.maxClients;
|
||||
desc.mapName = this->description.mapName;
|
||||
desc.gameName = this->description.gameName;
|
||||
desc.gameMode = this->description.gameMode;
|
||||
|
||||
}
|
||||
bool GameLobby::StartGameSession( bool forceStart )
|
||||
{
|
||||
//Check if all clients is ready, in not force start
|
||||
if(!forceStart)
|
||||
{
|
||||
if(!this->GetClientCount())
|
||||
{ /*None connected*/ return false;}
|
||||
else if( this->GetClientCount() != this->readyList.Size() )
|
||||
{ /*Not enough connected*/ return false; }
|
||||
}
|
||||
|
||||
void GameLobby::Update()
|
||||
{
|
||||
this->ProcessClients();
|
||||
}
|
||||
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
|
||||
{
|
||||
this->description.gameMode = desc.gameMode;
|
||||
this->description.gameTime = desc.gameTime;
|
||||
this->description.mapNumber = desc.mapNumber;
|
||||
this->description.maxClients = desc.maxClients;
|
||||
}
|
||||
void GameLobby::GetGameDesc(LobbyLevelData& desc)
|
||||
{
|
||||
desc.gameMode = this->description.gameMode;
|
||||
desc.gameTime = this->description.gameTime;
|
||||
desc.mapNumber = this->description.mapNumber;
|
||||
desc.maxClients = this->description.maxClients;
|
||||
}
|
||||
bool GameLobby::StartGameSession( )
|
||||
{
|
||||
//Check if all clients is ready
|
||||
if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size())
|
||||
{
|
||||
GameSession::GameDescription desc;
|
||||
desc.maxClients = this->description.maxClients;
|
||||
desc.gameMode = this->description.gameMode;
|
||||
desc.gameTime = this->description.gameTime;
|
||||
desc.mapNumber = this->description.mapNumber;
|
||||
desc.gameTimeMinutes = this->description.gameTimeInMinutes;
|
||||
desc.mapName = this->description.mapName;
|
||||
desc.owner = this;
|
||||
desc.clients = this->clients;
|
||||
desc.clients = this->gClients;
|
||||
|
||||
if(desc.gameTime == 0.0f)
|
||||
desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere.
|
||||
if(desc.gameTimeMinutes == 0)
|
||||
desc.gameTimeMinutes = 10; //note: should be fetched from somewhere.
|
||||
|
||||
if(desc.maxClients == 0)
|
||||
desc.maxClients = 10; //note: should be fetched somewhere else..
|
||||
|
||||
this->clients.Clear(); //Remove clients from lobby list
|
||||
this->gClients.Clear(); //Remove clients from lobby list
|
||||
|
||||
if(this->gameSession.Create(desc))
|
||||
if(this->gameSession.Create(desc, forceStart))
|
||||
{
|
||||
this->gameSession.Run();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//?
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
int GameLobby::GetGameSessionClientCount()
|
||||
{
|
||||
return this->gameSession.GetClientCount();
|
||||
}
|
||||
|
||||
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
|
||||
{
|
||||
switch (e.args.type)
|
||||
{
|
||||
case NetworkClient::ClientEventArgs::EventType_Disconnect:
|
||||
|
@ -92,37 +119,46 @@ namespace DanBias
|
|||
break;
|
||||
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
|
||||
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
||||
e.sender->Disconnect();
|
||||
this->readyList.Remove(e.sender);
|
||||
this->clients.Remove(e.sender);
|
||||
//e.sender->Disconnect();
|
||||
//this->readyList.Remove(e.sender);
|
||||
//this->gClients.Remove(e.sender);
|
||||
break;
|
||||
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
||||
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
||||
this->ParseProtocol(e.args.data.protocol, e.sender);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
|
||||
{
|
||||
}
|
||||
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
|
||||
{
|
||||
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
|
||||
|
||||
if(this->gameSession)
|
||||
{
|
||||
this->gameSession.Attach(client);
|
||||
if(!this->Attach(client))
|
||||
{
|
||||
client->Disconnect();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Attach(client);
|
||||
if(!this->Attach(client))
|
||||
{
|
||||
//Send message that lobby full
|
||||
client->Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
Protocol_LobbyClientData p1;
|
||||
Protocol_LobbyGameData p2;
|
||||
|
||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->clients[i])
|
||||
if(this->gClients[i])
|
||||
{
|
||||
Protocol_LobbyClientData::PlayerData t;
|
||||
t.id = this->clients[i]->GetID();
|
||||
t.ip = this->clients[i]->GetIpAddress();
|
||||
t.id = client->GetID();
|
||||
t.ip = client->GetIpAddress();
|
||||
t.team = 0;
|
||||
t.name = "Dennis är kung tycker Erik!";
|
||||
p1.list.Push(t);
|
||||
|
@ -135,6 +171,45 @@ namespace DanBias
|
|||
client->Send(p1.GetProtocol());
|
||||
client->Send(p2.GetProtocol());
|
||||
}
|
||||
}
|
||||
void GameLobby::ProcessClients()
|
||||
{
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->gClients[i]->UpdateClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
bool GameLobby::Attach(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
|
||||
{
|
||||
if(this->clientCount == this->description.maxClients) return false;
|
||||
|
||||
client->SetOwner(this);
|
||||
|
||||
bool added = false;
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(!this->gClients[i])
|
||||
{
|
||||
added = true;
|
||||
this->gClients[i] = new GameClient(client);
|
||||
}
|
||||
}
|
||||
|
||||
}//End namespace DanBias
|
||||
if(!added)
|
||||
{
|
||||
this->gClients.Push(new GameClient(client));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,13 +16,9 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
|||
break;
|
||||
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
||||
break;
|
||||
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
|
||||
//break;
|
||||
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
||||
break;
|
||||
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
|
||||
//break;
|
||||
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c);
|
||||
case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c);
|
||||
break;
|
||||
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
||||
break;
|
||||
|
@ -32,6 +28,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
|||
break;
|
||||
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
||||
break;
|
||||
case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,52 +40,75 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net
|
|||
{
|
||||
case Protocol_General_Status::States_ready:
|
||||
{
|
||||
|
||||
int temp = FindClient(c);
|
||||
if(temp != -1 )
|
||||
{
|
||||
switch (this->gClients[temp]->GetState())
|
||||
{
|
||||
case GameClient::ClientState_CreatingGame:
|
||||
{
|
||||
this->gameSession.Join(this->gClients[temp]);
|
||||
this->gClients[temp] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c->Disconnect();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Protocol_General_Status::States_idle:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case Protocol_General_Status::States_leave:
|
||||
break;
|
||||
case Protocol_General_Status::States_disconected:
|
||||
{
|
||||
Detach(c)->Disconnect();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->gClients[i]->GetClient()->Send(p);
|
||||
}
|
||||
}
|
||||
printf(p.text.c_str());
|
||||
}
|
||||
//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
||||
{
|
||||
|
||||
//Send countdown timer before lobby shuts down
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
this->gClients[i]->GetClient()->Send(Protocol_LobbyStartGame(3.0f));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Someone else tried to start the server..
|
||||
}
|
||||
}
|
||||
//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
|
||||
//{
|
||||
// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
||||
// //{
|
||||
// // if (this->gameLobby[i]->GetID() == p.value)
|
||||
// // {
|
||||
// // this->gameLobby[i]->Attach(Detach(c));
|
||||
// // return;
|
||||
// // }
|
||||
// //}
|
||||
//}
|
||||
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
||||
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
|
||||
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
||||
//{
|
||||
// if (this->gameLobby[i]->GetID() == p.value)
|
||||
// {
|
||||
// this->gameLobby[i]->Attach(Detach(c));
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
|
@ -110,6 +131,48 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster:
|
|||
else
|
||||
{
|
||||
this->readyList.Remove(c);
|
||||
|
||||
}
|
||||
}
|
||||
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
if(this->gameSession)
|
||||
{
|
||||
int temp = FindClient(c);
|
||||
|
||||
//Something is wrong
|
||||
if(temp == -1)
|
||||
{
|
||||
c->Disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Send game data
|
||||
Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string()));
|
||||
c->Send(lcg);
|
||||
this->gClients[temp]->SetState(GameClient::ClientState_CreatingGame);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing.-
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int GameLobby::FindClient(Oyster::Network::NetworkClient* c)
|
||||
{
|
||||
int temp = -1;
|
||||
|
||||
//find client in waiting list
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i]->GetClient()->GetID() == c->GetID())
|
||||
{
|
||||
temp = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
|
@ -61,8 +61,6 @@ void GameServerAPI::ServerStart()
|
|||
{
|
||||
timer.reset();
|
||||
server.Start();
|
||||
|
||||
|
||||
}
|
||||
void GameServerAPI::ServerStop()
|
||||
{
|
||||
|
@ -113,8 +111,6 @@ void GameServerAPI::NotifyWhenClientConnect(ClientConnectedNotify func)
|
|||
{
|
||||
if(!func) clientConnectedCallback = DefaultClientConnectedNotify;
|
||||
else clientConnectedCallback = func;
|
||||
|
||||
|
||||
}
|
||||
void GameServerAPI::NotifyWhenClientDisconnect(ClientDisconnectedNotify func)
|
||||
{
|
||||
|
@ -126,7 +122,21 @@ void GameServerAPI::GameSetMapName(const wchar_t* val)
|
|||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
//d.mapNumber = val; //TODO: implement
|
||||
d.mapName = val;
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
void GameServerAPI::GameSetGameMode(const wchar_t* val)
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
d.gameMode = val;
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
void GameServerAPI::GameSetGameName(const wchar_t* val)
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
d.gameName = val;
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
void GameServerAPI::GameSetMaxClients(const int& val)
|
||||
|
@ -136,25 +146,19 @@ void GameServerAPI::GameSetMaxClients(const int& val)
|
|||
d.maxClients = val;
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
void GameServerAPI::GameSetGameMode(const wchar_t* val)
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
//d.gameMode = val; //TODO: implement
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
void GameServerAPI::GameSetGameTime(const int& val)
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
d.gameTime = val;
|
||||
d.gameTimeInMinutes = val;
|
||||
lobby.SetGameDesc(d);
|
||||
}
|
||||
int GameServerAPI::GameGetMapId()
|
||||
|
||||
const wchar_t* GameServerAPI::GameGetMapName()
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
return d.mapNumber;
|
||||
return d.mapName.c_str();
|
||||
}
|
||||
int GameServerAPI::GameGetMaxClients()
|
||||
{
|
||||
|
@ -162,29 +166,33 @@ int GameServerAPI::GameGetMaxClients()
|
|||
lobby.GetGameDesc(d);
|
||||
return d.maxClients;
|
||||
}
|
||||
int GameServerAPI::GameGetGameMode()
|
||||
const wchar_t* GameServerAPI::GameGetGameMode()
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
return d.gameMode;
|
||||
return d.gameMode.c_str();
|
||||
}
|
||||
int GameServerAPI::GameGetGameTime()
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
return d.gameTime;
|
||||
return d.gameTimeInMinutes;
|
||||
}
|
||||
const char* GameServerAPI::GameGetGameName()
|
||||
const wchar_t* GameServerAPI::GameGetGameName()
|
||||
{
|
||||
LobbyLevelData d;
|
||||
lobby.GetGameDesc(d);
|
||||
return d.gameName.c_str();
|
||||
}
|
||||
bool GameServerAPI::GameStart()
|
||||
int GameServerAPI::GetConnectedClientCount()
|
||||
{
|
||||
if(lobby.StartGameSession())
|
||||
{
|
||||
return lobby.GetGameSessionClientCount();
|
||||
}
|
||||
|
||||
bool GameServerAPI::GameStart( bool forceStart )
|
||||
{
|
||||
if(lobby.StartGameSession( forceStart ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -19,11 +19,8 @@ using namespace Oyster;
|
|||
using namespace Oyster::Network;
|
||||
using namespace Oyster::Thread;
|
||||
using namespace GameLogic;
|
||||
using namespace DanBias;
|
||||
|
||||
namespace DanBias
|
||||
{
|
||||
Utility::WinTimer testTimer;
|
||||
int testID = -1;
|
||||
|
||||
bool GameSession::DoWork( )
|
||||
{
|
||||
|
@ -46,9 +43,9 @@ namespace DanBias
|
|||
{
|
||||
int temp = -1;
|
||||
//Find the idiot
|
||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->clients[i]->Equals(e.sender))
|
||||
if(this->gClients[i] && this->gClients[i]->Equals(e.sender))
|
||||
{
|
||||
temp = i;
|
||||
}
|
||||
|
@ -59,7 +56,7 @@ namespace DanBias
|
|||
this->Detach(e.sender)->Disconnect();
|
||||
return;
|
||||
}
|
||||
SmartPointer<GameClient> cl = this->clients[temp];
|
||||
SmartPointer<GameClient> cl = this->gClients[temp];
|
||||
|
||||
switch (e.args.type)
|
||||
{
|
||||
|
@ -73,15 +70,48 @@ namespace DanBias
|
|||
break;
|
||||
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
||||
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
|
||||
testID = 2;
|
||||
if(cl->GetPlayer()->GetID() == testID)//TODO: TEST
|
||||
{
|
||||
testTimer.reset();
|
||||
}
|
||||
this->ParseProtocol(e.args.data.protocol, cl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void GameSession::ProcessClients()
|
||||
{
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i] )
|
||||
{
|
||||
this->gClients[i]->UpdateClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
bool GameSession::Send(Oyster::Network::CustomNetProtocol& message)
|
||||
{
|
||||
bool returnValue = false;
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->gClients[i]->GetClient()->Send(message);
|
||||
returnValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
||||
}
|
||||
bool GameSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->gClients[i] && this->gClients[i]->GetClient()->GetID() == ID)
|
||||
{
|
||||
this->gClients[i]->GetClient()->Send(protocol);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
|
||||
{
|
||||
|
@ -246,7 +276,6 @@ namespace DanBias
|
|||
printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str());
|
||||
}
|
||||
|
||||
}//End namespace DanBias
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
#include "..\GameSession.h"
|
||||
#include "..\GameClient.h"
|
||||
#include "..\GameLobby.h"
|
||||
#include <Protocols.h>
|
||||
#include <PostBox\PostBox.h>
|
||||
#include <GameLogicStates.h>
|
||||
|
@ -24,14 +25,13 @@ using namespace Oyster;
|
|||
using namespace Oyster::Network;
|
||||
using namespace Oyster::Thread;
|
||||
using namespace GameLogic;
|
||||
using namespace DanBias;
|
||||
|
||||
namespace DanBias
|
||||
{
|
||||
GameSession* GameSession::gameSession = nullptr;
|
||||
GameSession* GameSession::gameSession = nullptr;
|
||||
|
||||
GameSession::GameSession()
|
||||
GameSession::GameSession()
|
||||
:gameInstance(GameAPI::Instance())
|
||||
{
|
||||
{
|
||||
this->owner = 0;
|
||||
this->isCreated = false;
|
||||
this->isRunning = false;
|
||||
|
@ -42,48 +42,54 @@ namespace DanBias
|
|||
this->logicTimer.reset();
|
||||
|
||||
memset(&this->description, 0, sizeof(GameDescription));
|
||||
}
|
||||
}
|
||||
|
||||
GameSession::~GameSession()
|
||||
{
|
||||
GameSession::~GameSession()
|
||||
{
|
||||
this->worker.Terminate();
|
||||
this->clients.Clear();
|
||||
this->gameInstance;
|
||||
this->owner = 0;
|
||||
this->isCreated = false;
|
||||
this->isRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool GameSession::Create(GameDescription& desc)
|
||||
{
|
||||
bool GameSession::Create(GameDescription& desc, bool forceStart)
|
||||
{
|
||||
this->description = desc;
|
||||
/* Do some error checking */
|
||||
if(desc.clients.Size() == 0) return false;
|
||||
/* Do some error checking */
|
||||
if(!forceStart && desc.clients.Size() == 0) return false;
|
||||
if(!desc.owner) return false;
|
||||
if(this->isCreated) return false;
|
||||
|
||||
/* standard initialization of some data */
|
||||
NetworkSession::clients = desc.clients;
|
||||
NetworkSession::clients.Resize((unsigned int)desc.maxClients);
|
||||
this->clients.Resize((unsigned int)desc.maxClients);
|
||||
/* standard initialization of some data */
|
||||
this->gClients.Resize((unsigned int)desc.maxClients);
|
||||
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
||||
{
|
||||
if(desc.clients[i])
|
||||
{
|
||||
this->clientCount++;
|
||||
this->gClients[i] = desc.clients[i];
|
||||
this->gClients[i]->SetOwner(this);
|
||||
}
|
||||
}
|
||||
this->owner = desc.owner;
|
||||
|
||||
/* Initiate the game instance */
|
||||
/* Initiate the game instance */
|
||||
if(!this->gameInstance.Initiate())
|
||||
{
|
||||
printf("Failed to initiate the game instance\n");
|
||||
}
|
||||
|
||||
/* Create the players in the game instance */
|
||||
/* Create the players in the game instance */
|
||||
GameLogic::IPlayerData* p = 0;
|
||||
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(desc.clients[i])
|
||||
if(this->gClients[i])
|
||||
{
|
||||
if( (p = this->gameInstance.CreatePlayer()) )
|
||||
{
|
||||
desc.clients[i]->SetOwner(this);
|
||||
this->clients[i] = (new GameClient(desc.clients[i], p));
|
||||
this->gClients[i]->SetPlayer(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -92,14 +98,14 @@ namespace DanBias
|
|||
}
|
||||
}
|
||||
|
||||
/* Create the game level */
|
||||
if(!(this->levelData = this->gameInstance.CreateLevel()))
|
||||
/* Create the game level */
|
||||
if(!(this->levelData = this->gameInstance.CreateLevel(this->description.mapName.c_str())))
|
||||
{
|
||||
printf("Level not created!");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Set some game instance data options */
|
||||
/* Set some game instance data options */
|
||||
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
||||
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
||||
this->gameInstance.SetFPS(60);
|
||||
|
@ -113,42 +119,37 @@ namespace DanBias
|
|||
return false;
|
||||
|
||||
return this->isCreated;
|
||||
}
|
||||
}
|
||||
|
||||
void GameSession::Run()
|
||||
{
|
||||
void GameSession::Run()
|
||||
{
|
||||
if(this->isRunning) return;
|
||||
|
||||
if(this->clients.Size() > 0)
|
||||
{
|
||||
this->worker.Start();
|
||||
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
|
||||
this->isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GameSession::ThreadEntry( )
|
||||
{
|
||||
//List with clients that we are waiting on..
|
||||
DynamicArray<SmartPointer<GameClient>> readyList;// = this->clients;
|
||||
}
|
||||
|
||||
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||
void GameSession::ThreadEntry( )
|
||||
{
|
||||
//List with clients that we are waiting on..
|
||||
DynamicArray<gClient> readyList;// = this->clients;
|
||||
|
||||
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->clients[i])
|
||||
if(this->gClients[i])
|
||||
{
|
||||
if(this->clients[i]->IsReady())
|
||||
{
|
||||
readyList.Push(this->clients[i]);
|
||||
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
|
||||
readyList.Push(this->gClients[i]);
|
||||
Protocol_LobbyCreateGame p((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string()));
|
||||
readyList[readyList.Size() - 1]->GetClient()->Send(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int readyCounter = readyList.Size();
|
||||
|
||||
//Sync with clients
|
||||
//Sync with clients
|
||||
while (readyCounter != 0)
|
||||
{
|
||||
this->ProcessClients();
|
||||
|
@ -157,15 +158,14 @@ namespace DanBias
|
|||
if(readyList[i] && readyList[i]->IsReady())
|
||||
{
|
||||
//Need to send information about other players, to all players
|
||||
for (unsigned int k = 0; k < this->clients.Size(); k++)
|
||||
for (unsigned int k = 0; k < this->gClients.Size(); k++)
|
||||
{
|
||||
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
|
||||
if((this->gClients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->gClients[k]->GetClient()->GetID())
|
||||
{
|
||||
//Protocol_ObjectCreatePlayer
|
||||
Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(),
|
||||
this->clients[k]->GetPlayer()->GetRotation(),
|
||||
this->clients[k]->GetPlayer()->GetScale(),
|
||||
this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later..
|
||||
IPlayerData* pl = this->gClients[k]->GetPlayer();
|
||||
Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(),
|
||||
pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(),
|
||||
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||
readyList[i]->GetClient()->Send(p);
|
||||
}
|
||||
}
|
||||
|
@ -177,63 +177,101 @@ namespace DanBias
|
|||
Sleep(5); //TODO: This might not be needed here.
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||
//Sync with clients before starting countdown
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(this->clients[i])
|
||||
if(this->gClients[i])
|
||||
{
|
||||
this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5));
|
||||
}
|
||||
this->gClients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GameSession::Attach(Utility::DynamicMemory::SmartPointer<NetworkClient> client)
|
||||
{
|
||||
bool GameSession::Join(gClient gameClient)
|
||||
{
|
||||
if(!this->isCreated) return false;
|
||||
if(this->GetClientCount() == this->clients.Capacity()) return false;
|
||||
if(this->GetClientCount() == this->gClients.Capacity()) return false;
|
||||
|
||||
client->SetOwner(this);
|
||||
gameClient->SetOwner(this);
|
||||
|
||||
IPlayerData* player = this->gameInstance.CreatePlayer();
|
||||
if(!player) return false;
|
||||
IPlayerData* playerData = this->gameInstance.CreatePlayer();
|
||||
if(!playerData) return false;
|
||||
|
||||
SmartPointer<GameClient> obj = new GameClient(client, player);
|
||||
gameClient->SetPlayer(playerData);
|
||||
NetworkClient* nwClient = gameClient->GetClient();
|
||||
|
||||
// Send the chosen mesh name
|
||||
Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation());
|
||||
obj->GetClient()->Send(lcg);
|
||||
|
||||
// Send the player data only
|
||||
for (unsigned int i = 0; i < this->clients.Capacity(); i++)
|
||||
// Send the player data only
|
||||
{
|
||||
if(this->clients[i])
|
||||
Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(),
|
||||
playerData->GetID(), true, playerData->GetTeamID(),
|
||||
/*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan");
|
||||
nwClient->Send(oc);
|
||||
}
|
||||
|
||||
// Send information about other clients
|
||||
{
|
||||
IPlayerData* p = this->clients[i]->GetPlayer();
|
||||
Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
|
||||
this->clients[i]->GetClient()->Send(oc);
|
||||
}
|
||||
}
|
||||
|
||||
obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0));
|
||||
|
||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(!clients[i])
|
||||
if(this->gClients[i])
|
||||
{
|
||||
NetworkSession::clients[i] = client;
|
||||
clients[i] = obj;
|
||||
return true;
|
||||
IPlayerData* temp = this->gClients[i]->GetPlayer();
|
||||
Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(),
|
||||
temp->GetID(), false, temp->GetTeamID(),
|
||||
/*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan");
|
||||
nwClient->Send(oc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameSession::CloseSession( bool dissconnectClients )
|
||||
//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client
|
||||
{
|
||||
this->worker.Terminate();
|
||||
NetworkSession::CloseSession(true);
|
||||
this->clients.Clear();
|
||||
DynamicArray<IObjectData*> objects;
|
||||
this->levelData->GetAllDynamicObjects(objects);
|
||||
for (unsigned int i = 0; i < objects.Size(); i++)
|
||||
{
|
||||
//Protocol_ObjectPosition p(movedObject->GetPosition(), id);
|
||||
Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID());
|
||||
GameSession::gameSession->Send(p.GetProtocol());
|
||||
}
|
||||
}
|
||||
|
||||
}//End namespace DanBias
|
||||
// Insert the new client to the update list
|
||||
bool added = false;
|
||||
{
|
||||
for (unsigned int i = 0; !added && i < this->gClients.Size(); i++)
|
||||
{
|
||||
if(!this->gClients[i])
|
||||
{
|
||||
this->gClients[i] = gameClient;
|
||||
// Send the start signal
|
||||
{
|
||||
nwClient->Send(GameLogic::Protocol_LobbyStartGame(0));
|
||||
}
|
||||
added = true;
|
||||
this->clientCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gameClient->SetState(GameClient::ClientState_Ready);
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
//DynamicArray<gClient> GameSession::CloseSession( bool dissconnectClients )
|
||||
//{
|
||||
// this->worker.Terminate();
|
||||
// //TODO: Send clients to lobby
|
||||
//
|
||||
// //for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
||||
// //{
|
||||
// // if(this->gClients[i])
|
||||
// // {
|
||||
// // ((GameLobby*)this->owner)-> this->gClients[i]
|
||||
// // }
|
||||
// //}
|
||||
//
|
||||
// this->gClients.Clear();
|
||||
//}
|
||||
|
||||
|
||||
|
|
|
@ -72,26 +72,32 @@ void StandaloneGameServerCLI::GameSetMapName(String^ value)
|
|||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||
DanBias::GameServerAPI::GameSetMapName(wch);
|
||||
}
|
||||
void StandaloneGameServerCLI::GameSetGameMode(String^ value)
|
||||
{
|
||||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||
DanBias::GameServerAPI::GameSetGameMode(wch);
|
||||
}
|
||||
void StandaloneGameServerCLI::GameSetGameName(String^ value)
|
||||
{
|
||||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||
DanBias::GameServerAPI::GameSetGameName(wch);
|
||||
}
|
||||
|
||||
void StandaloneGameServerCLI::GameSetMaxClients(const int val)
|
||||
{
|
||||
DanBias::GameServerAPI::GameSetMaxClients(val);
|
||||
}
|
||||
|
||||
void StandaloneGameServerCLI::GameSetGameMode(String^ value)
|
||||
{
|
||||
pin_ptr<const wchar_t> wch = PtrToStringChars(value);
|
||||
DanBias::GameServerAPI::GameSetGameMode(wch);
|
||||
}
|
||||
|
||||
|
||||
void StandaloneGameServerCLI::GameSetGameTime(const int val)
|
||||
{
|
||||
DanBias::GameServerAPI::GameSetGameTime(val);
|
||||
}
|
||||
|
||||
int StandaloneGameServerCLI::GameGetMapId()
|
||||
String^ StandaloneGameServerCLI::GameGetMapName()
|
||||
{
|
||||
return DanBias::GameServerAPI::GameGetMapId();
|
||||
return gcnew String( DanBias::GameServerAPI::GameGetMapName());
|
||||
}
|
||||
|
||||
int StandaloneGameServerCLI::GameGetMaxClients()
|
||||
|
@ -99,9 +105,9 @@ int StandaloneGameServerCLI::GameGetMaxClients()
|
|||
return DanBias::GameServerAPI::GameGetMaxClients();
|
||||
}
|
||||
|
||||
int StandaloneGameServerCLI::GameGetGameMode()
|
||||
String^ StandaloneGameServerCLI::GameGetGameMode()
|
||||
{
|
||||
return DanBias::GameServerAPI::GameGetGameMode();
|
||||
return gcnew String( DanBias::GameServerAPI::GameGetGameMode());
|
||||
}
|
||||
|
||||
int StandaloneGameServerCLI::GameGetGameTime()
|
||||
|
@ -111,10 +117,17 @@ int StandaloneGameServerCLI::GameGetGameTime()
|
|||
|
||||
String^ StandaloneGameServerCLI::GameGetGameName()
|
||||
{
|
||||
return gcnew String(DanBias::GameServerAPI::GameGetGameName());
|
||||
return gcnew String( DanBias::GameServerAPI::GameGetGameName());
|
||||
}
|
||||
|
||||
bool StandaloneGameServerCLI::GameStart()
|
||||
bool StandaloneGameServerCLI::GameStart(bool f)
|
||||
{
|
||||
return DanBias::GameServerAPI::GameStart();
|
||||
return DanBias::GameServerAPI::GameStart(f);
|
||||
}
|
||||
int StandaloneGameServerCLI::GetClientsConnectedCount()
|
||||
{
|
||||
return DanBias::GameServerAPI::GetConnectedClientCount();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -47,15 +47,18 @@ namespace System { namespace Windows { namespace Interop
|
|||
bool ServerIsRunning();
|
||||
|
||||
void GameSetMapName(String^ val);
|
||||
void GameSetMaxClients(const int val);
|
||||
void GameSetGameMode(String^ val);
|
||||
void GameSetGameName(String^ val);
|
||||
void GameSetMaxClients(const int val);
|
||||
void GameSetGameTime(const int val);
|
||||
int GameGetMapId();
|
||||
|
||||
int GameGetMaxClients();
|
||||
int GameGetGameMode();
|
||||
int GameGetGameTime();
|
||||
System::String^ GameGetMapName();
|
||||
System::String^ GameGetGameMode();
|
||||
System::String^ GameGetGameName();
|
||||
bool GameStart();
|
||||
bool GameStart( bool forceStart );
|
||||
int GetClientsConnectedCount();
|
||||
};
|
||||
|
||||
} } }
|
||||
|
|
|
@ -36,30 +36,34 @@
|
|||
this.label_listenPort = new System.Windows.Forms.Label();
|
||||
this.panel_serverOptions = new System.Windows.Forms.Panel();
|
||||
this.panel_commands = new System.Windows.Forms.Panel();
|
||||
this.mapName = new System.Windows.Forms.TextBox();
|
||||
this.timeLimit = new System.Windows.Forms.NumericUpDown();
|
||||
this.gameModes = new System.Windows.Forms.ComboBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.forceStart = new System.Windows.Forms.CheckBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.labelClientsConnected = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.nrOfClients = new System.Windows.Forms.NumericUpDown();
|
||||
this.buttonStartGame = new System.Windows.Forms.Button();
|
||||
this.panel_clientArea = new System.Windows.Forms.Panel();
|
||||
this.ServerInfoTextArea = new System.Windows.Forms.RichTextBox();
|
||||
this.splitter1 = new System.Windows.Forms.Splitter();
|
||||
this.clientInfoBox = new System.Windows.Forms.ListBox();
|
||||
this.buttonStartGame = new System.Windows.Forms.Button();
|
||||
this.nrOfClients = new System.Windows.Forms.NumericUpDown();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.gameModes = new System.Windows.Forms.ComboBox();
|
||||
this.timeLimit = new System.Windows.Forms.NumericUpDown();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.mapName = new System.Windows.Forms.TextBox();
|
||||
this.panel_CommanArea = new System.Windows.Forms.Panel();
|
||||
((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit();
|
||||
this.panel_serverOptions.SuspendLayout();
|
||||
this.panel_commands.SuspendLayout();
|
||||
this.panel_clientArea.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.timeLimit)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit();
|
||||
this.panel_clientArea.SuspendLayout();
|
||||
this.panel_CommanArea.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// serverToggle
|
||||
//
|
||||
this.serverToggle.Location = new System.Drawing.Point(9, 81);
|
||||
this.serverToggle.Location = new System.Drawing.Point(9, 106);
|
||||
this.serverToggle.Name = "serverToggle";
|
||||
this.serverToggle.Size = new System.Drawing.Size(75, 23);
|
||||
this.serverToggle.TabIndex = 0;
|
||||
|
@ -111,7 +115,7 @@
|
|||
this.listenPort.Size = new System.Drawing.Size(95, 20);
|
||||
this.listenPort.TabIndex = 5;
|
||||
this.listenPort.Value = new decimal(new int[] {
|
||||
2048,
|
||||
15151,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
|
@ -133,9 +137,10 @@
|
|||
this.panel_serverOptions.Controls.Add(this.label_listenPort);
|
||||
this.panel_serverOptions.Controls.Add(this.lanBroadcast);
|
||||
this.panel_serverOptions.Controls.Add(this.label_serverName);
|
||||
this.panel_serverOptions.Location = new System.Drawing.Point(12, 12);
|
||||
this.panel_serverOptions.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel_serverOptions.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel_serverOptions.Name = "panel_serverOptions";
|
||||
this.panel_serverOptions.Size = new System.Drawing.Size(183, 113);
|
||||
this.panel_serverOptions.Size = new System.Drawing.Size(200, 141);
|
||||
this.panel_serverOptions.TabIndex = 6;
|
||||
//
|
||||
// panel_commands
|
||||
|
@ -144,68 +149,113 @@
|
|||
this.panel_commands.Controls.Add(this.timeLimit);
|
||||
this.panel_commands.Controls.Add(this.gameModes);
|
||||
this.panel_commands.Controls.Add(this.label3);
|
||||
this.panel_commands.Controls.Add(this.forceStart);
|
||||
this.panel_commands.Controls.Add(this.label2);
|
||||
this.panel_commands.Controls.Add(this.label4);
|
||||
this.panel_commands.Controls.Add(this.labelClientsConnected);
|
||||
this.panel_commands.Controls.Add(this.label1);
|
||||
this.panel_commands.Controls.Add(this.nrOfClients);
|
||||
this.panel_commands.Controls.Add(this.buttonStartGame);
|
||||
this.panel_commands.Location = new System.Drawing.Point(12, 131);
|
||||
this.panel_commands.Location = new System.Drawing.Point(3, 150);
|
||||
this.panel_commands.Name = "panel_commands";
|
||||
this.panel_commands.Size = new System.Drawing.Size(183, 230);
|
||||
this.panel_commands.Size = new System.Drawing.Size(191, 202);
|
||||
this.panel_commands.TabIndex = 7;
|
||||
this.panel_commands.Visible = false;
|
||||
//
|
||||
// panel_clientArea
|
||||
// mapName
|
||||
//
|
||||
this.panel_clientArea.Controls.Add(this.ServerInfoTextArea);
|
||||
this.panel_clientArea.Controls.Add(this.splitter1);
|
||||
this.panel_clientArea.Controls.Add(this.clientInfoBox);
|
||||
this.panel_clientArea.Location = new System.Drawing.Point(202, 12);
|
||||
this.panel_clientArea.Name = "panel_clientArea";
|
||||
this.panel_clientArea.Size = new System.Drawing.Size(303, 349);
|
||||
this.panel_clientArea.TabIndex = 8;
|
||||
this.mapName.Location = new System.Drawing.Point(75, 10);
|
||||
this.mapName.Name = "mapName";
|
||||
this.mapName.Size = new System.Drawing.Size(113, 20);
|
||||
this.mapName.TabIndex = 12;
|
||||
this.mapName.Text = "2ofAll_updated.bias";
|
||||
//
|
||||
// ServerInfoTextArea
|
||||
// timeLimit
|
||||
//
|
||||
this.ServerInfoTextArea.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||
this.ServerInfoTextArea.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info;
|
||||
this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 152);
|
||||
this.ServerInfoTextArea.Name = "ServerInfoTextArea";
|
||||
this.ServerInfoTextArea.ReadOnly = true;
|
||||
this.ServerInfoTextArea.Size = new System.Drawing.Size(303, 197);
|
||||
this.ServerInfoTextArea.TabIndex = 1;
|
||||
this.ServerInfoTextArea.Text = "";
|
||||
this.timeLimit.Location = new System.Drawing.Point(109, 94);
|
||||
this.timeLimit.Minimum = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.timeLimit.Name = "timeLimit";
|
||||
this.timeLimit.Size = new System.Drawing.Size(68, 20);
|
||||
this.timeLimit.TabIndex = 11;
|
||||
this.timeLimit.ThousandsSeparator = true;
|
||||
this.timeLimit.Value = new decimal(new int[] {
|
||||
15,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// splitter1
|
||||
// gameModes
|
||||
//
|
||||
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.splitter1.Location = new System.Drawing.Point(0, 147);
|
||||
this.splitter1.Name = "splitter1";
|
||||
this.splitter1.Size = new System.Drawing.Size(303, 5);
|
||||
this.splitter1.TabIndex = 2;
|
||||
this.splitter1.TabStop = false;
|
||||
this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.gameModes.FormattingEnabled = true;
|
||||
this.gameModes.Items.AddRange(new object[] {
|
||||
"Free-for-all",
|
||||
"Team death-match"});
|
||||
this.gameModes.Location = new System.Drawing.Point(78, 66);
|
||||
this.gameModes.Name = "gameModes";
|
||||
this.gameModes.Size = new System.Drawing.Size(110, 21);
|
||||
this.gameModes.TabIndex = 10;
|
||||
//
|
||||
// clientInfoBox
|
||||
// label3
|
||||
//
|
||||
this.clientInfoBox.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.clientInfoBox.FormattingEnabled = true;
|
||||
this.clientInfoBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.clientInfoBox.Name = "clientInfoBox";
|
||||
this.clientInfoBox.Size = new System.Drawing.Size(303, 147);
|
||||
this.clientInfoBox.TabIndex = 0;
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(8, 96);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(95, 13);
|
||||
this.label3.TabIndex = 9;
|
||||
this.label3.Text = "Time limit (minutes)";
|
||||
//
|
||||
// buttonStartGame
|
||||
// forceStart
|
||||
//
|
||||
this.buttonStartGame.Location = new System.Drawing.Point(53, 195);
|
||||
this.buttonStartGame.Name = "buttonStartGame";
|
||||
this.buttonStartGame.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonStartGame.TabIndex = 6;
|
||||
this.buttonStartGame.Text = "Start game";
|
||||
this.buttonStartGame.UseVisualStyleBackColor = true;
|
||||
this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click);
|
||||
this.forceStart.AutoSize = true;
|
||||
this.forceStart.Checked = true;
|
||||
this.forceStart.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.forceStart.Location = new System.Drawing.Point(12, 120);
|
||||
this.forceStart.Name = "forceStart";
|
||||
this.forceStart.Size = new System.Drawing.Size(115, 17);
|
||||
this.forceStart.TabIndex = 1;
|
||||
this.forceStart.Text = "Ignore empty lobby";
|
||||
this.forceStart.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(8, 69);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(64, 13);
|
||||
this.label2.TabIndex = 9;
|
||||
this.label2.Text = "Game mode";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(9, 15);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(57, 13);
|
||||
this.label4.TabIndex = 8;
|
||||
this.label4.Text = "Map name";
|
||||
//
|
||||
// labelClientsConnected
|
||||
//
|
||||
this.labelClientsConnected.AutoSize = true;
|
||||
this.labelClientsConnected.Location = new System.Drawing.Point(9, 149);
|
||||
this.labelClientsConnected.Name = "labelClientsConnected";
|
||||
this.labelClientsConnected.Size = new System.Drawing.Size(104, 13);
|
||||
this.labelClientsConnected.TabIndex = 8;
|
||||
this.labelClientsConnected.Text = "Clients connected: 0";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(8, 38);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(53, 13);
|
||||
this.label1.TabIndex = 8;
|
||||
this.label1.Text = "Client limit";
|
||||
//
|
||||
// nrOfClients
|
||||
//
|
||||
|
@ -224,102 +274,93 @@
|
|||
this.nrOfClients.Size = new System.Drawing.Size(39, 20);
|
||||
this.nrOfClients.TabIndex = 7;
|
||||
this.nrOfClients.Value = new decimal(new int[] {
|
||||
2,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// label1
|
||||
// buttonStartGame
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(8, 38);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(53, 13);
|
||||
this.label1.TabIndex = 8;
|
||||
this.label1.Text = "Client limit";
|
||||
this.buttonStartGame.Location = new System.Drawing.Point(9, 176);
|
||||
this.buttonStartGame.Name = "buttonStartGame";
|
||||
this.buttonStartGame.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonStartGame.TabIndex = 6;
|
||||
this.buttonStartGame.Text = "Start game";
|
||||
this.buttonStartGame.UseVisualStyleBackColor = true;
|
||||
this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click);
|
||||
//
|
||||
// label2
|
||||
// panel_clientArea
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(8, 69);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(64, 13);
|
||||
this.label2.TabIndex = 9;
|
||||
this.label2.Text = "Game mode";
|
||||
this.panel_clientArea.Controls.Add(this.ServerInfoTextArea);
|
||||
this.panel_clientArea.Controls.Add(this.splitter1);
|
||||
this.panel_clientArea.Controls.Add(this.clientInfoBox);
|
||||
this.panel_clientArea.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel_clientArea.Location = new System.Drawing.Point(200, 0);
|
||||
this.panel_clientArea.Name = "panel_clientArea";
|
||||
this.panel_clientArea.Size = new System.Drawing.Size(535, 616);
|
||||
this.panel_clientArea.TabIndex = 8;
|
||||
//
|
||||
// gameModes
|
||||
// ServerInfoTextArea
|
||||
//
|
||||
this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.gameModes.FormattingEnabled = true;
|
||||
this.gameModes.Items.AddRange(new object[] {
|
||||
"Free-for-all",
|
||||
"Team death-match"});
|
||||
this.gameModes.Location = new System.Drawing.Point(78, 66);
|
||||
this.gameModes.Name = "gameModes";
|
||||
this.gameModes.Size = new System.Drawing.Size(99, 21);
|
||||
this.gameModes.TabIndex = 10;
|
||||
this.ServerInfoTextArea.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||
this.ServerInfoTextArea.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info;
|
||||
this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 152);
|
||||
this.ServerInfoTextArea.Name = "ServerInfoTextArea";
|
||||
this.ServerInfoTextArea.ReadOnly = true;
|
||||
this.ServerInfoTextArea.Size = new System.Drawing.Size(535, 464);
|
||||
this.ServerInfoTextArea.TabIndex = 1;
|
||||
this.ServerInfoTextArea.Text = "";
|
||||
//
|
||||
// timeLimit
|
||||
// splitter1
|
||||
//
|
||||
this.timeLimit.Location = new System.Drawing.Point(109, 94);
|
||||
this.timeLimit.Minimum = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.timeLimit.Name = "timeLimit";
|
||||
this.timeLimit.Size = new System.Drawing.Size(68, 20);
|
||||
this.timeLimit.TabIndex = 11;
|
||||
this.timeLimit.ThousandsSeparator = true;
|
||||
this.timeLimit.Value = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.splitter1.Location = new System.Drawing.Point(0, 147);
|
||||
this.splitter1.Name = "splitter1";
|
||||
this.splitter1.Size = new System.Drawing.Size(535, 5);
|
||||
this.splitter1.TabIndex = 2;
|
||||
this.splitter1.TabStop = false;
|
||||
//
|
||||
// label3
|
||||
// clientInfoBox
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(8, 96);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(95, 13);
|
||||
this.label3.TabIndex = 9;
|
||||
this.label3.Text = "Time limit (minutes)";
|
||||
this.clientInfoBox.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.clientInfoBox.FormattingEnabled = true;
|
||||
this.clientInfoBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.clientInfoBox.Name = "clientInfoBox";
|
||||
this.clientInfoBox.Size = new System.Drawing.Size(535, 147);
|
||||
this.clientInfoBox.TabIndex = 0;
|
||||
//
|
||||
// label4
|
||||
// panel_CommanArea
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(9, 15);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(57, 13);
|
||||
this.label4.TabIndex = 8;
|
||||
this.label4.Text = "Map name";
|
||||
//
|
||||
// mapName
|
||||
//
|
||||
this.mapName.Location = new System.Drawing.Point(78, 7);
|
||||
this.mapName.Name = "mapName";
|
||||
this.mapName.Size = new System.Drawing.Size(98, 20);
|
||||
this.mapName.TabIndex = 12;
|
||||
this.panel_CommanArea.Controls.Add(this.panel_commands);
|
||||
this.panel_CommanArea.Controls.Add(this.panel_serverOptions);
|
||||
this.panel_CommanArea.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.panel_CommanArea.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel_CommanArea.Name = "panel_CommanArea";
|
||||
this.panel_CommanArea.Size = new System.Drawing.Size(200, 616);
|
||||
this.panel_CommanArea.TabIndex = 9;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(517, 373);
|
||||
this.ClientSize = new System.Drawing.Size(735, 616);
|
||||
this.Controls.Add(this.panel_clientArea);
|
||||
this.Controls.Add(this.panel_commands);
|
||||
this.Controls.Add(this.panel_serverOptions);
|
||||
this.Controls.Add(this.panel_CommanArea);
|
||||
this.Name = "Form1";
|
||||
this.Text = "Form1";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClosingEvent);
|
||||
((System.ComponentModel.ISupportInitialize)(this.listenPort)).EndInit();
|
||||
this.panel_serverOptions.ResumeLayout(false);
|
||||
this.panel_serverOptions.PerformLayout();
|
||||
this.panel_commands.ResumeLayout(false);
|
||||
this.panel_commands.PerformLayout();
|
||||
this.panel_clientArea.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.timeLimit)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit();
|
||||
this.panel_clientArea.ResumeLayout(false);
|
||||
this.panel_CommanArea.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
@ -347,6 +388,9 @@
|
|||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.TextBox mapName;
|
||||
private System.Windows.Forms.CheckBox forceStart;
|
||||
private System.Windows.Forms.Label labelClientsConnected;
|
||||
private System.Windows.Forms.Panel panel_CommanArea;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ using System.Threading.Tasks;
|
|||
using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Timers;
|
||||
|
||||
namespace StandAloneLauncher
|
||||
{
|
||||
|
@ -20,7 +22,7 @@ namespace StandAloneLauncher
|
|||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.gameModes.SelectedIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,14 +32,14 @@ namespace StandAloneLauncher
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
while (this.Created)
|
||||
{
|
||||
Application.DoEvents();
|
||||
|
||||
//Do some stuff
|
||||
this.gameServer.ServerUpdate();
|
||||
this.labelClientsConnected.Text = "Clients connected: " + this.gameServer.GetClientsConnectedCount().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +89,10 @@ namespace StandAloneLauncher
|
|||
{
|
||||
//this.gameServer.GameSetGameMode(this.gameModes.SelectedText);
|
||||
this.gameServer.GameSetGameTime((int)this.timeLimit.Value);
|
||||
//this.gameServer.GameSetMapId(0);
|
||||
this.gameServer.GameSetMapName(this.mapName.Text);
|
||||
this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value);
|
||||
if (!this.gameServer.GameStart())
|
||||
|
||||
if (!this.gameServer.GameStart( this.forceStart.Checked ))
|
||||
{
|
||||
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n");
|
||||
}
|
||||
|
@ -98,5 +101,13 @@ namespace StandAloneLauncher
|
|||
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n");
|
||||
}
|
||||
}
|
||||
|
||||
private void FormClosingEvent(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (serverIsRunning)
|
||||
{
|
||||
this.gameServer.ServerStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace LinearAlgebra
|
|||
const ScalarType & operator [] ( int i ) const;
|
||||
|
||||
Quaternion<ScalarType> & operator = ( const Quaternion<ScalarType> &quaternion );
|
||||
Quaternion<ScalarType> & operator *= ( const Quaternion<ScalarType> &quaternion );
|
||||
Quaternion<ScalarType> & operator *= ( const ScalarType &scalar );
|
||||
Quaternion<ScalarType> & operator /= ( const ScalarType &scalar );
|
||||
Quaternion<ScalarType> & operator += ( const Quaternion<ScalarType> &quaternion );
|
||||
|
@ -112,6 +113,12 @@ namespace LinearAlgebra
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const Quaternion<ScalarType> &quaternion )
|
||||
{
|
||||
return *this = *this * quaternion;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
{
|
||||
|
|
|
@ -52,6 +52,8 @@ OHRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType ty
|
|||
}
|
||||
}
|
||||
|
||||
if(!resourceData) return 0;
|
||||
|
||||
return resourceData->GetResourceHandle();
|
||||
}
|
||||
OHRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force)
|
||||
|
|
|
@ -337,7 +337,11 @@ namespace Utility
|
|||
|
||||
template<typename ValueType>
|
||||
inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
|
||||
{ return value < min ? Max( value, max ) : min; }
|
||||
{
|
||||
if( value < min ) return min;
|
||||
if( value > max ) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
|
||||
|
|
|
@ -40,12 +40,13 @@ CustomNetProtocol::CustomNetProtocol()
|
|||
{
|
||||
this->privateData = new PrivateData();
|
||||
}
|
||||
CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o)
|
||||
CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o)
|
||||
{
|
||||
this->privateData = new PrivateData();
|
||||
this->privateData->attributes = o.privateData->attributes;
|
||||
}
|
||||
const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o)
|
||||
|
||||
CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o)
|
||||
{
|
||||
if(this->privateData)
|
||||
{
|
||||
|
@ -56,11 +57,29 @@ const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o)
|
|||
this->privateData->attributes = o.privateData->attributes;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CustomNetProtocol::~CustomNetProtocol()
|
||||
{
|
||||
delete this->privateData;
|
||||
this->privateData = 0;
|
||||
}
|
||||
|
||||
const NetAttributeContainer& CustomNetProtocol::operator[](int ID) const
|
||||
{
|
||||
//if(!this->privateData) this->privateData = new PrivateData();
|
||||
if((unsigned int)ID >= this->privateData->attributes.Size())
|
||||
{
|
||||
NetAttributeContainer temp;
|
||||
|
||||
temp.type = NetAttributeType_UNKNOWN;
|
||||
memset(&temp.value, 0, sizeof(NetAttributeValue));
|
||||
|
||||
this->privateData->attributes.Push(ID, temp);
|
||||
}
|
||||
|
||||
return this->privateData->attributes[ID];
|
||||
}
|
||||
|
||||
NetAttributeContainer& CustomNetProtocol::operator[](int ID)
|
||||
{
|
||||
//if(!this->privateData) this->privateData = new PrivateData();
|
||||
|
|
|
@ -130,10 +130,12 @@ namespace Oyster
|
|||
public:
|
||||
CustomNetProtocol();
|
||||
~CustomNetProtocol();
|
||||
CustomNetProtocol(CustomNetProtocol& o);
|
||||
const CustomNetProtocol& operator=(CustomNetProtocol& o);
|
||||
CustomNetProtocol( const CustomNetProtocol& o);
|
||||
CustomNetProtocol& operator=(const CustomNetProtocol& o);
|
||||
|
||||
const NetAttributeContainer& operator[](int ID) const;
|
||||
NetAttributeContainer& operator[](int ID);
|
||||
|
||||
void Set(int id, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type);
|
||||
void Set(int ID, std::string s);
|
||||
const NetAttributeContainer& Get(int id);
|
||||
|
|
|
@ -96,6 +96,10 @@ struct NetworkClient::PrivateData : public IThreadObject
|
|||
//printf("\t(%i)\n", this->sendQueue.Size());
|
||||
OysterByte temp;
|
||||
CustomNetProtocol p = this->sendQueue.Pop();
|
||||
|
||||
if(p[0].value.netShort == 304)
|
||||
int i = 0;
|
||||
|
||||
this->translator.Pack(temp, p);
|
||||
errorCode = this->connection.Send(temp);
|
||||
|
||||
|
|
|
@ -133,13 +133,7 @@ namespace Oyster
|
|||
*/
|
||||
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
||||
|
||||
/** ! Deprecate !
|
||||
* Do not use this furthermore, instead use void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
||||
* @see DataRecieved
|
||||
*/
|
||||
//virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
|
||||
|
||||
virtual std::string GetIpAddress();
|
||||
std::string GetIpAddress();
|
||||
|
||||
private:
|
||||
NetworkClient(const NetworkClient& obj);
|
||||
|
|
|
@ -98,9 +98,9 @@ namespace Oyster
|
|||
|
||||
protected:
|
||||
NetClientList clients;
|
||||
int clientCount;
|
||||
|
||||
private:
|
||||
int clientCount;
|
||||
struct PrivateSessionData;
|
||||
PrivateSessionData* data;
|
||||
};
|
||||
|
|
|
@ -61,8 +61,7 @@ namespace Oyster
|
|||
|
||||
struct PostData
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
float Amb;
|
||||
};
|
||||
|
||||
struct Text2D
|
||||
|
|
|
@ -19,11 +19,19 @@ namespace Oyster
|
|||
Math::Float4x4 Projection;
|
||||
std::vector<Definitions::Pointlight> Lights;
|
||||
float deltaTime;
|
||||
#ifdef _DEBUG
|
||||
Model::Model* cube;
|
||||
Model::Model* sphere;
|
||||
|
||||
ID3D11RasterizerState* wire;
|
||||
#endif
|
||||
}
|
||||
|
||||
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
|
||||
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, API::Option o)
|
||||
{
|
||||
Core::resolution = resulotion;
|
||||
Core::resolution = o.Resolution;
|
||||
Core::modelPath = o.modelPath;
|
||||
Core::texturePath = o.texturePath;
|
||||
|
||||
if(Core::Init::FullInit(Window, MSAA_Quality, Fullscreen) == Core::Init::Fail)
|
||||
{
|
||||
|
@ -32,7 +40,33 @@ namespace Oyster
|
|||
Render::Resources::Gui::Text::Font = (ID3D11ShaderResourceView*)API::CreateTexture(L"font_generic.png");
|
||||
Render::Resources::Init();
|
||||
|
||||
Definitions::PostData pd;
|
||||
pd.Amb = o.AmbientValue;
|
||||
|
||||
void* data = Render::Resources::Post::Data.Map();
|
||||
memcpy(data,&pd,sizeof(Definitions::PostData));
|
||||
Render::Resources::Post::Data.Unmap();
|
||||
|
||||
Render::Preparations::Basic::SetViewPort();
|
||||
#ifdef _DEBUG
|
||||
//fix load model
|
||||
cube = CreateModel(L"debug_cube.dan");
|
||||
sphere = CreateModel(L"debug_sphere.dan");
|
||||
|
||||
D3D11_RASTERIZER_DESC desc;
|
||||
desc.CullMode = D3D11_CULL_BACK;
|
||||
desc.FillMode = D3D11_FILL_WIREFRAME;
|
||||
desc.FrontCounterClockwise = false;
|
||||
desc.DepthBias = 0;
|
||||
desc.DepthBiasClamp = 0;
|
||||
desc.DepthClipEnable = true;
|
||||
desc.SlopeScaledDepthBias = 0;
|
||||
desc.ScissorEnable = false;
|
||||
desc.MultisampleEnable = false;
|
||||
desc.AntialiasedLineEnable = false;
|
||||
|
||||
Core::device->CreateRasterizerState(&desc,&wire);
|
||||
#endif
|
||||
return API::Sucsess;
|
||||
}
|
||||
|
||||
|
@ -77,6 +111,14 @@ namespace Oyster
|
|||
{
|
||||
Core::modelPath = option.modelPath;
|
||||
Core::texturePath = option.texturePath;
|
||||
|
||||
Definitions::PostData pd;
|
||||
pd.Amb = option.AmbientValue;
|
||||
|
||||
void* data = Render::Resources::Post::Data.Map();
|
||||
memcpy(data,&pd,sizeof(Definitions::PostData));
|
||||
Render::Resources::Post::Data.Unmap();
|
||||
|
||||
return API::Sucsess;
|
||||
}
|
||||
|
||||
|
@ -113,6 +155,11 @@ namespace Oyster
|
|||
|
||||
void API::Clean()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
DeleteModel(cube);
|
||||
DeleteModel(sphere);
|
||||
SAFE_RELEASE(wire);
|
||||
#endif
|
||||
DeleteTexture(Render::Resources::Gui::Text::Font);
|
||||
SAFE_DELETE(Core::viewPort);
|
||||
Core::loader.Clean();
|
||||
|
@ -127,6 +174,7 @@ namespace Oyster
|
|||
SAFE_RELEASE(Core::swapChain);
|
||||
SAFE_RELEASE(Core::deviceContext);
|
||||
SAFE_RELEASE(Core::device);
|
||||
|
||||
}
|
||||
|
||||
void API::AddLight(Definitions::Pointlight light)
|
||||
|
@ -145,6 +193,24 @@ namespace Oyster
|
|||
Render::Resources::InitShaders();
|
||||
return State::Sucsess;
|
||||
}
|
||||
|
||||
void API::StartRenderWireFrame()
|
||||
{
|
||||
Core::deviceContext->RSSetState(wire);
|
||||
Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL);
|
||||
}
|
||||
|
||||
void API::RenderDebugCube(Math::Matrix world)
|
||||
{
|
||||
cube->WorldMatrix = world;
|
||||
Render::DefaultRenderer::RenderScene(cube,1,View,Projection);
|
||||
}
|
||||
|
||||
void API::RenderDebugSphere(Math::Matrix world)
|
||||
{
|
||||
sphere->WorldMatrix = world;
|
||||
Render::DefaultRenderer::RenderScene(sphere,1,View,Projection);
|
||||
}
|
||||
#endif
|
||||
|
||||
API::Option API::GetOption()
|
||||
|
@ -153,6 +219,7 @@ namespace Oyster
|
|||
o.BytesUsed = Core::UsedMem;
|
||||
o.modelPath = Core::modelPath;
|
||||
o.texturePath = Core::texturePath;
|
||||
o.Resolution = Core::resolution;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
@ -161,7 +228,7 @@ namespace Oyster
|
|||
Render::Gui::Begin2DRender();
|
||||
}
|
||||
|
||||
void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color)
|
||||
void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float4 color)
|
||||
{
|
||||
Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color);
|
||||
}
|
||||
|
@ -196,7 +263,7 @@ namespace Oyster
|
|||
Render::Gui::Begin2DTextRender();
|
||||
}
|
||||
|
||||
void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color)
|
||||
void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float4 color)
|
||||
{
|
||||
Render::Gui::RenderText(text, Pos, Size, FontSize, color);
|
||||
}
|
||||
|
|
|
@ -27,13 +27,30 @@ namespace Oyster
|
|||
struct Option
|
||||
{
|
||||
std::wstring modelPath, texturePath;
|
||||
//between 0-1
|
||||
float AmbientValue;
|
||||
|
||||
Math::Float2 Resolution;
|
||||
|
||||
//Bytes on the GPU
|
||||
int BytesUsed;
|
||||
};
|
||||
typedef void* Texture;
|
||||
|
||||
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
|
||||
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Option options);
|
||||
#ifdef _DEBUG
|
||||
static State ReloadShaders();
|
||||
|
||||
//should be called after rendered normal models, before GUI or Text rendering
|
||||
static void StartRenderWireFrame();
|
||||
|
||||
//Render a unit cube with the presented WorldMatrix
|
||||
static void RenderDebugCube(Math::Matrix world);
|
||||
|
||||
//Render a unit Sphere with the presented WorldMatrix
|
||||
static void RenderDebugSphere(Math::Matrix world);
|
||||
|
||||
static void StartRenderFullModel();
|
||||
#endif
|
||||
|
||||
//! @todo Memory Leaks
|
||||
|
@ -57,13 +74,13 @@ namespace Oyster
|
|||
static void StartGuiRender();
|
||||
|
||||
//! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system
|
||||
static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1));
|
||||
static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float4 Color = Math::Float4(1,1,1,1));
|
||||
|
||||
//! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame()
|
||||
static void StartTextRender();
|
||||
|
||||
//! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system
|
||||
static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1));
|
||||
static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float4 Color = Math::Float4(1,1,1,1));
|
||||
|
||||
//! @brief Performs light calculations, post effects and presents the scene
|
||||
static void EndFrame();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -16,7 +16,8 @@ namespace Oyster
|
|||
|
||||
void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
||||
{
|
||||
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1));
|
||||
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0));
|
||||
Preparations::Basic::ClearDepthStencil(Resources::Gui::depth);
|
||||
Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0));
|
||||
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass);
|
||||
Lights[1];
|
||||
|
@ -38,14 +39,6 @@ namespace Oyster
|
|||
data = Resources::Light::PointLightsData.Map();
|
||||
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
|
||||
Resources::Light::PointLightsData.Unmap();
|
||||
|
||||
Definitions::PostData pd;
|
||||
pd.x = (int)lc.Pixels.x;
|
||||
pd.y = (int)lc.Pixels.y;
|
||||
|
||||
data = Resources::Post::Data.Map();
|
||||
memcpy(data, &pd, sizeof(Definitions::PostData));
|
||||
Resources::Post::Data.Unmap();
|
||||
}
|
||||
|
||||
void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime)
|
||||
|
@ -57,8 +50,8 @@ namespace Oyster
|
|||
if(models[i].Visible)
|
||||
{
|
||||
Definitions::PerModel pm;
|
||||
pm.WV = View * models[i].WorldMatrix;
|
||||
pm.WVP = Projection * pm.WV;
|
||||
pm.WV = View * models[i].WorldMatrix.GetTranspose().GetInverse();
|
||||
pm.WVP = Projection * View * models[i].WorldMatrix;
|
||||
|
||||
Model::ModelInfo* info = models[i].info;
|
||||
|
||||
|
|
|
@ -9,19 +9,19 @@ namespace Oyster
|
|||
namespace Render
|
||||
{
|
||||
const int TEXT_NR_LETTERS=95;
|
||||
const float TEXT_SPACING=1.8f;
|
||||
const float TEXT_SPACING=2.0f;
|
||||
|
||||
void Gui::Begin2DRender()
|
||||
{
|
||||
Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass);
|
||||
}
|
||||
|
||||
void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color)
|
||||
void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float4 color)
|
||||
{
|
||||
Core::deviceContext->PSSetShaderResources(0,1,&tex);
|
||||
|
||||
pos *= 2;
|
||||
pos -= 1;
|
||||
pos.xy *= 2;
|
||||
pos.xy -= 1;
|
||||
pos.y *= -1;
|
||||
|
||||
Definitions::GuiData gd;
|
||||
|
@ -37,7 +37,7 @@ namespace Oyster
|
|||
Render::Resources::Gui::Data.Unmap();
|
||||
|
||||
data = Render::Resources::Color.Map();
|
||||
memcpy(data,&color,sizeof(Math::Float3));
|
||||
memcpy(data,&color,sizeof(Math::Float4));
|
||||
Render::Resources::Color.Unmap();
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ namespace Oyster
|
|||
Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass);
|
||||
}
|
||||
|
||||
void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color)
|
||||
void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float4 color)
|
||||
{
|
||||
|
||||
//size.x = size.x / (text.length() * TEXT_SPACING /2);
|
||||
|
@ -81,7 +81,7 @@ namespace Oyster
|
|||
Definitions::Text2D tmpInst;
|
||||
|
||||
data = Render::Resources::Color.Map();
|
||||
memcpy(data,&color,sizeof(Math::Float3));
|
||||
memcpy(data,&color,sizeof(Math::Float4));
|
||||
Render::Resources::Color.Unmap();
|
||||
|
||||
void* dest = Resources::Gui::Text::Vertex.Map();
|
||||
|
|
|
@ -12,9 +12,9 @@ namespace Oyster
|
|||
{
|
||||
public:
|
||||
static void Begin2DRender();
|
||||
static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1));
|
||||
static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float4 tint = Math::Float4(1,1,1,1));
|
||||
static void Begin2DTextRender();
|
||||
static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1));
|
||||
static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float4 tint = Math::Float4(1,1,1,1));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ namespace Oyster
|
|||
ID3D11BlendState* Resources::RenderStates::bs = NULL;
|
||||
|
||||
ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL;
|
||||
ID3D11DepthStencilView* Resources::Gui::depth = NULL;
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
@ -159,7 +160,7 @@ namespace Oyster
|
|||
D3D11_RASTERIZER_DESC rdesc;
|
||||
rdesc.CullMode = D3D11_CULL_BACK;
|
||||
rdesc.FillMode = D3D11_FILL_SOLID;
|
||||
rdesc.FrontCounterClockwise = false;
|
||||
rdesc.FrontCounterClockwise = true;
|
||||
rdesc.DepthBias = 0;
|
||||
rdesc.DepthBiasClamp = 0;
|
||||
rdesc.DepthClipEnable = true;
|
||||
|
@ -304,6 +305,7 @@ namespace Oyster
|
|||
ID3D11Texture1D *pTexture1;
|
||||
|
||||
Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1 );
|
||||
Core::UsedMem += T1desc.Width * 16;
|
||||
Core::device->CreateShaderResourceView( pTexture1, 0, &Light::SSAOKernel );
|
||||
pTexture1->Release();
|
||||
|
||||
|
@ -323,8 +325,33 @@ namespace Oyster
|
|||
ID3D11Texture2D *pTexture2;
|
||||
|
||||
Core::device->CreateTexture2D( &T2desc, &rnd, &pTexture2 );
|
||||
Core::UsedMem += T2desc.Height * T2desc.Width * 16;
|
||||
Core::device->CreateShaderResourceView( (pTexture2), 0, &Light::SSAORandom );
|
||||
pTexture2->Release();
|
||||
|
||||
//create Depth Buffer
|
||||
D3D11_TEXTURE2D_DESC dTDesc;
|
||||
dTDesc.MipLevels=1;
|
||||
dTDesc.ArraySize=1;
|
||||
dTDesc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
dTDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
dTDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
dTDesc.CPUAccessFlags=0;
|
||||
dTDesc.MiscFlags=0;
|
||||
dTDesc.Height = (UINT)Core::resolution.y;
|
||||
dTDesc.Width = (UINT)Core::resolution.x;
|
||||
dTDesc.SampleDesc.Count=1;
|
||||
dTDesc.SampleDesc.Quality=0;
|
||||
|
||||
ID3D11Texture2D* depthstencil;
|
||||
Core::device->CreateTexture2D(&dTDesc,0,&depthstencil);
|
||||
Core::UsedMem += dTDesc.Height * dTDesc.Width * 4;
|
||||
Core::device->CreateDepthStencilView(depthstencil,NULL,&Gui::depth);
|
||||
depthstencil->Release();
|
||||
|
||||
|
||||
D3D11_DEPTH_STENCIL_DESC dDesc;
|
||||
|
||||
return Core::Init::Success;
|
||||
}
|
||||
|
||||
|
@ -390,10 +417,13 @@ namespace Oyster
|
|||
Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D");
|
||||
Gui::Pass.Shaders.Pixel = GetShader::Pixel(L"2D");
|
||||
Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D");
|
||||
|
||||
Gui::Pass.RTV.push_back(GBufferRTV[2]);
|
||||
Gui::Pass.CBuffers.Geometry.push_back(Gui::Data);
|
||||
Gui::Pass.CBuffers.Pixel.push_back(Color);
|
||||
|
||||
Gui::Pass.depth = Gui::depth;
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC indesc2D[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
|
@ -405,6 +435,7 @@ namespace Oyster
|
|||
Gui::Pass.RenderStates.SampleCount = 1;
|
||||
Gui::Pass.RenderStates.SampleState = RenderStates::ss;
|
||||
Gui::Pass.RenderStates.BlendState = RenderStates::bs;
|
||||
Gui::Pass.RenderStates.DepthStencil = RenderStates::dsState;
|
||||
|
||||
////---------------- Blur Pass Setup ----------------------------
|
||||
Blur::HorPass.Shaders.Compute = GetShader::Compute(L"BlurHor");
|
||||
|
@ -442,9 +473,13 @@ namespace Oyster
|
|||
Gui::Text::Pass.CBuffers.Pixel.push_back(Color);
|
||||
Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font);
|
||||
Gui::Text::Pass.RTV.push_back(GBufferRTV[2]);
|
||||
|
||||
Gui::Text::Pass.depth = Gui::depth;
|
||||
|
||||
Gui::Text::Pass.RenderStates.SampleCount = 1;
|
||||
Gui::Text::Pass.RenderStates.SampleState = RenderStates::ss;
|
||||
Gui::Text::Pass.RenderStates.BlendState = RenderStates::bs;
|
||||
Gui::Text::Pass.RenderStates.DepthStencil = RenderStates::dsState;
|
||||
|
||||
return Core::Init::Success;
|
||||
}
|
||||
|
@ -510,6 +545,8 @@ namespace Oyster
|
|||
SAFE_RELEASE(Gui::Text::Pass.RenderStates.BlendState);
|
||||
|
||||
SAFE_RELEASE(Gui::Text::Pass.IAStage.Layout);
|
||||
|
||||
SAFE_RELEASE(Gui::depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace Oyster
|
|||
{
|
||||
static Core::PipelineManager::RenderPass Pass;
|
||||
static Core::Buffer Data;
|
||||
static ID3D11DepthStencilView* depth;
|
||||
struct Text
|
||||
{
|
||||
static Core::PipelineManager::RenderPass Pass;
|
||||
|
|
|
@ -4,19 +4,19 @@
|
|||
void main(point Vertex2DIn input[1],inout TriangleStream<Pixel2DIn> Quads)
|
||||
{
|
||||
Pixel2DIn output;
|
||||
output.Pos = mul(float4(-1,-1,1,1) ,Translation);
|
||||
output.Pos = mul(float4(-1,-1,0,1) ,Translation);
|
||||
output.Uv = float2(0,1);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(-1,1,1,1), Translation);
|
||||
output.Pos = mul(float4(-1,1,0,1), Translation);
|
||||
output.Uv = float2(0,0);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(1,-1,1,1), Translation);
|
||||
output.Pos = mul(float4(1,-1,0,1), Translation);
|
||||
output.Uv = float2(1,1);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(1,1,1,1), Translation);
|
||||
output.Pos = mul(float4(1,1,0,1), Translation);
|
||||
output.Uv = float2(1,0);
|
||||
Quads.Append(output);
|
||||
}
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
float4 main(Pixel2DIn input) : SV_Target0
|
||||
{
|
||||
return Material.Sample(LinearSampler,input.Uv) * float4(Color,1);
|
||||
return Material.Sample(LinearSampler,input.Uv) * Color;
|
||||
}
|
|
@ -10,7 +10,7 @@ cbuffer EveryObject2D : register(b0)
|
|||
|
||||
cbuffer ColorData : register(b0)
|
||||
{
|
||||
float3 Color;
|
||||
float4 Color;
|
||||
};
|
||||
|
||||
struct Pixel2DIn
|
||||
|
|
|
@ -7,22 +7,22 @@ void main(point Text2DIn input[1],inout TriangleStream<Pixel2DIn> Quads)
|
|||
float endoff=startoff+input[0].coff;
|
||||
Pixel2DIn output;
|
||||
|
||||
output.Pos = mul(float4(-1,-1,1,1), Translation);
|
||||
output.Pos = mul(float4(-1,-1,0,1), Translation);
|
||||
output.Pos.x += input[0].Pos;
|
||||
output.Uv = float2(startoff,1);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(-1,1,1,1), Translation);
|
||||
output.Pos = mul(float4(-1,1,0,1), Translation);
|
||||
output.Pos.x += input[0].Pos;
|
||||
output.Uv = float2(startoff,0);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(1,-1,1,1), Translation);
|
||||
output.Pos = mul(float4(1,-1,0,1), Translation);
|
||||
output.Pos.x += input[0].Pos;
|
||||
output.Uv = float2(endoff,1);
|
||||
Quads.Append(output);
|
||||
|
||||
output.Pos = mul(float4(1,1,1,1), Translation);
|
||||
output.Pos = mul(float4(1,1,0,1), Translation);
|
||||
output.Pos.x += input[0].Pos;
|
||||
output.Uv = float2(endoff,0);
|
||||
Quads.Append(output);
|
||||
|
|
|
@ -27,7 +27,7 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
|
|||
blurCol +=Weights[i + blurRadius] * gCache[k];
|
||||
}
|
||||
|
||||
outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);
|
||||
outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);
|
||||
//outTex[ThreadID.xy + Start] = inTex[ThreadID.xy + Start];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
|
|||
}
|
||||
if(gThreadID.y >= N-blurRadius)
|
||||
{
|
||||
int y = min(ThreadID.y+blurRadius, Stop.y-1);
|
||||
int y = min(ThreadID.y +blurRadius, Stop.y-1);
|
||||
gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start];
|
||||
}
|
||||
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)];
|
||||
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)];
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
|
@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
|
|||
blurCol +=Weights[i + blurRadius] * gCache[k];
|
||||
}
|
||||
|
||||
outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);;
|
||||
outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);;
|
||||
//outTex[ThreadID.xy + Start] = inTex[ThreadID.xy+ Start];
|
||||
}
|
|
@ -8,11 +8,9 @@ SamplerState S1 : register(s0);
|
|||
|
||||
cbuffer Size : register(b0)
|
||||
{
|
||||
int2 Pixels;
|
||||
float AmbFactor;
|
||||
}
|
||||
|
||||
#define AmbFactor 0.1f;
|
||||
|
||||
float4 SuperSample(float4 Glow, uint3 DTid)
|
||||
{
|
||||
// Line X
|
||||
|
@ -20,7 +18,7 @@ float4 SuperSample(float4 Glow, uint3 DTid)
|
|||
index += float2(0,Output.Length.y/2);
|
||||
index = index / Output.Length;
|
||||
Glow = Ambient.SampleLevel(S1, index,1);
|
||||
Glow = Glow * Glow.w*10;
|
||||
Glow = Glow;
|
||||
|
||||
return Glow;
|
||||
}
|
||||
|
@ -30,13 +28,10 @@ void main( uint3 DTid : SV_DispatchThreadID )
|
|||
{
|
||||
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
|
||||
float4 Amb = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w*/, 0);
|
||||
//float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
|
||||
float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
|
||||
|
||||
Glow = SuperSample(Glow,DTid);
|
||||
|
||||
float4 GUI;
|
||||
uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0);
|
||||
uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0);
|
||||
float3 PostLight = Amb.xyz * AmbFactor;
|
||||
PostLight = PostLight + Light.xyz + Glow;
|
||||
GUI = float4(Ambient[index]);
|
||||
|
@ -44,4 +39,5 @@ void main( uint3 DTid : SV_DispatchThreadID )
|
|||
Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1);
|
||||
|
||||
//Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(0,Output.Length.y*0.5f)].xyz,1);
|
||||
//Output[DTid.xy] = Ambient[DTid.xy];
|
||||
}
|
Loading…
Reference in New Issue