This commit is contained in:
Dander7BD 2014-02-12 17:20:42 +01:00
parent 63bc360645
commit 5d4d66cf06
6 changed files with 75 additions and 79 deletions

View File

@ -19,8 +19,8 @@
#include "../Misc/EventHandler/EventHandler.h" #include "../Misc/EventHandler/EventHandler.h"
using namespace ::Oyster; using namespace ::Oyster;
using namespace Event; using namespace ::Oyster::Event;
using namespace Network; using namespace ::Oyster::Network;
using namespace ::Utility::DynamicMemory; using namespace ::Utility::DynamicMemory;
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e ); void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
@ -46,6 +46,7 @@ namespace DanBias
this->capFrame = 0; this->capFrame = 0;
} }
} data; } data;
#pragma endregion #pragma endregion
@ -77,7 +78,7 @@ namespace DanBias
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
data.timer.reset(); data.timer.reset();
return DanBiasClientReturn_Sucess; return DanBiasClientReturn_Success;
} }
DanBiasClientReturn DanBiasGame::Run() DanBiasClientReturn DanBiasGame::Run()
@ -89,7 +90,6 @@ namespace DanBias
data.timer.reset(); data.timer.reset();
Graphics::API::Update( dt ); Graphics::API::Update( dt );
EventHandler::Instance().Update( nullptr );
if(data.networkClient.IsConnected()) if(data.networkClient.IsConnected())
data.networkClient.Update(); data.networkClient.Update();
@ -97,15 +97,20 @@ namespace DanBias
data.capFrame += dt; data.capFrame += dt;
if(data.capFrame > 0.03) if(data.capFrame > 0.03)
{ {
if(Update(dt) != S_OK) switch( Update(dt) )
return DanBiasClientReturn_Error; {
case Result_continue: break;
case Result_quit: return DanBiasClientReturn_Success;
case Result_error: return DanBiasClientReturn_Error;
default: break;
}
if(Render() != S_OK) if(Render() != S_OK)
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
data.capFrame = 0; data.capFrame = 0;
} }
} }
return DanBiasClientReturn_Sucess; return DanBiasClientReturn_Success;
} }
void DanBiasGame::Release() void DanBiasGame::Release()
@ -143,7 +148,7 @@ namespace DanBias
return S_OK; return S_OK;
} }
HRESULT DanBiasGame::Update(float deltaTime) DanBiasGame::Result DanBiasGame::Update(float deltaTime)
{ {
data.inputObj->Update(); data.inputObj->Update();
@ -158,37 +163,48 @@ namespace DanBias
if( state != Client::GameClientState::ClientState_Same ) if( state != Client::GameClientState::ClientState_Same )
{ {
bool stateVal = false; bool stateChanged = false;
data.state->Release(); data.state->Release();
switch (state) switch (state)
{ {
case Client::GameClientState::ClientState_LobbyCreate: case Client::GameClientState::ClientState_LobbyCreate:
data.serverOwner = true; {
stateVal = true; //DanBias::GameServerAPI::ServerInitiate( .. );
//DanBias::GameServerAPI::ServerStart();
//data.serverOwner = true;
//if( data.networkClient.Connect(15151, "127.0.0.1") )
//{
// data.state = new Client::LobbyState();
// stateChanged = true;
//}
}
case Client::GameClientState::ClientState_Lan:
data.state = new Client::LanMenuState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_Lobby: case Client::GameClientState::ClientState_Lobby:
data.state = new Client::LobbyState(); data.state = new Client::LobbyState();
stateVal = true; stateChanged = true;
break; break;
case Client::GameClientState::ClientState_Game: case Client::GameClientState::ClientState_Game:
data.state = new Client::GameState();
stateChanged = true;
break; break;
case Client::GameClientState::ClientState_Quit:
data.state->Release();
return Result_quit;
default: default:
return E_FAIL; data.state->Release();
break; return Result_error;
} }
if(stateVal) if( stateChanged )
{ {
data.state->Init( &data.networkClient ); // send game client data.state->Init( &data.networkClient ); // send game client
} }
else
{
} }
return Result_continue;
}
return S_OK;
} }
HRESULT DanBiasGame::Render( ) HRESULT DanBiasGame::Render( )
@ -200,7 +216,9 @@ namespace DanBias
HRESULT DanBiasGame::CleanUp() HRESULT DanBiasGame::CleanUp()
{ {
if( data.networkClient.IsConnected() )
data.networkClient.Disconnect(); data.networkClient.Disconnect();
delete data.inputObj; delete data.inputObj;
Oyster::Event::EventHandler::Instance().Clean(); Oyster::Event::EventHandler::Instance().Clean();

View File

@ -50,7 +50,15 @@ bool MainState::Init( NetworkClient* nwClient )
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
// create buttons // create buttons
ButtonRectangle<GameClientState*> *button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract_Quit, this, 0.5f, 0.5f, 0.1f, 0.1f, true ); ButtonRectangle<GameClientState*> *button;
button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract_Create, this, 0.5f, 0.2f, 0.1f, 0.3f, true );
this->privData->button.AddButton( button );
button = new ButtonRectangle<GameClientState*>( L"skysphere_md.png", OnButtonInteract_Join, this, 0.5f, 0.4f, 0.1f, 0.3f, true );
this->privData->button.AddButton( button );
button = new ButtonRectangle<GameClientState*>( L"plane_texture_md.png", OnButtonInteract_Quit, this, 0.5f, 0.8f, 0.1f, 0.3f, true );
this->privData->button.AddButton( button ); this->privData->button.AddButton( button );
// bind button collection to the singleton eventhandler // bind button collection to the singleton eventhandler
@ -61,45 +69,7 @@ bool MainState::Init( NetworkClient* nwClient )
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput) GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
{ {
//// picking EventHandler::Instance().Update( KeyInput );
//// mouse events
//// different menus
//// play sounds
//// update animation
//// send data to server
//// check data from server
//// create game
//if( KeyInput->IsKeyPressed(DIK_C))
//{
// DanBias::GameServerAPI::ServerInitDesc desc;
// DanBias::GameServerAPI::ServerInitiate(desc);
// DanBias::GameServerAPI::ServerStart();
// // my ip
// this->privData->nwClient->Connect(15152, "127.0.0.1");
// if (!this->privData->nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_LobbyCreated;
//}
//// join game
//if( KeyInput->IsKeyPressed(DIK_J))
//{
// // game ip
// this->privData->nwClient->Connect(15152, "127.0.0.1");
// //nwClient->Connect(15152, "83.254.217.248");
// if (!this->privData->nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_Lobby;
//}
return this->privData->nextState; return this->privData->nextState;
} }
@ -117,12 +87,14 @@ bool MainState::Render()
} }
bool MainState::Release() bool MainState::Release()
{
if( privData )
{ {
Graphics::API::DeleteTexture( this->privData->background ); Graphics::API::DeleteTexture( this->privData->background );
privData = NULL; privData = NULL;
// button collection will be autoreleased from EventHandler // button collection will be autoreleased from EventHandler
}
return true; return true;
} }

View File

@ -22,7 +22,7 @@ namespace DanBias
enum DanBiasClientReturn enum DanBiasClientReturn
{ {
DanBiasClientReturn_Error, DanBiasClientReturn_Error,
DanBiasClientReturn_Sucess, DanBiasClientReturn_Success
}; };
struct DanBiasGameDesc struct DanBiasGameDesc
@ -47,11 +47,17 @@ namespace DanBias
static void Release(); static void Release();
private: private:
enum Result
{
Result_continue,
Result_quit,
Result_error
};
static HRESULT InitDirect3D(); static HRESULT InitDirect3D();
static HRESULT InitInput(); static HRESULT InitInput();
static HRESULT Update(float deltaTime); static Result Update(float deltaTime);
static HRESULT Render(); static HRESULT Render();
static HRESULT CleanUp(); static HRESULT CleanUp();
}; };

View File

@ -25,7 +25,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
gameDesc.hinst = hinst; gameDesc.hinst = hinst;
gameDesc.nCmdShow = cmdShow; gameDesc.nCmdShow = cmdShow;
if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Sucess) if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Success )
{ {
DanBias::DanBiasGame::Run(); DanBias::DanBiasGame::Run();
DanBias::DanBiasGame::Release(); DanBias::DanBiasGame::Release();

View File

@ -84,7 +84,7 @@ namespace Oyster
type = p.type; type = p.type;
if(type == NetAttributeType_CharArray && p.value.netCharPtr) if(type == NetAttributeType_CharArray && p.value.netCharPtr)
{ {
int len = 0; size_t len = 0;
if((len = strlen(p.value.netCharPtr)) == 0) return; if((len = strlen(p.value.netCharPtr)) == 0) return;
len++; len++;
value.netCharPtr = new char[len]; value.netCharPtr = new char[len];
@ -106,7 +106,7 @@ namespace Oyster
type = p.type; type = p.type;
if(type == NetAttributeType_CharArray && p.value.netCharPtr) if(type == NetAttributeType_CharArray && p.value.netCharPtr)
{ {
int len = 0; size_t len = 0;
if((len = strlen(p.value.netCharPtr)) == 0) return *this; if((len = strlen(p.value.netCharPtr)) == 0) return *this;
len++; len++;
value.netCharPtr = new char[len]; value.netCharPtr = new char[len];

View File

@ -47,7 +47,7 @@ struct Translator::PrivateData
headerString.push_back(it->type); headerString.push_back(it->type);
} }
message.PackShort(headerString.size(), bytes); message.PackShort((short)headerString.size(), bytes);
size += 2; size += 2;
for(int i = 0; i < (int)headerString.size(); i++) for(int i = 0; i < (int)headerString.size(); i++)