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"
using namespace ::Oyster;
using namespace Event;
using namespace Network;
using namespace ::Oyster::Event;
using namespace ::Oyster::Network;
using namespace ::Utility::DynamicMemory;
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
@ -46,6 +46,7 @@ namespace DanBias
this->capFrame = 0;
}
} data;
#pragma endregion
@ -77,7 +78,7 @@ namespace DanBias
return DanBiasClientReturn_Error;
data.timer.reset();
return DanBiasClientReturn_Sucess;
return DanBiasClientReturn_Success;
}
DanBiasClientReturn DanBiasGame::Run()
@ -89,7 +90,6 @@ namespace DanBias
data.timer.reset();
Graphics::API::Update( dt );
EventHandler::Instance().Update( nullptr );
if(data.networkClient.IsConnected())
data.networkClient.Update();
@ -97,15 +97,20 @@ namespace DanBias
data.capFrame += dt;
if(data.capFrame > 0.03)
{
if(Update(dt) != S_OK)
return DanBiasClientReturn_Error;
switch( Update(dt) )
{
case Result_continue: break;
case Result_quit: return DanBiasClientReturn_Success;
case Result_error: return DanBiasClientReturn_Error;
default: break;
}
if(Render() != S_OK)
return DanBiasClientReturn_Error;
data.capFrame = 0;
}
}
return DanBiasClientReturn_Sucess;
return DanBiasClientReturn_Success;
}
void DanBiasGame::Release()
@ -143,11 +148,11 @@ namespace DanBias
return S_OK;
}
HRESULT DanBiasGame::Update(float deltaTime)
DanBiasGame::Result DanBiasGame::Update(float deltaTime)
{
data.inputObj->Update();
if(data.serverOwner)
if( data.serverOwner )
{
DanBias::GameServerAPI::ServerUpdate();
}
@ -156,39 +161,50 @@ namespace DanBias
state = data.state->Update( deltaTime, data.inputObj );
if(state != Client::GameClientState::ClientState_Same)
if( state != Client::GameClientState::ClientState_Same )
{
bool stateVal = false;
bool stateChanged = false;
data.state->Release();
switch (state)
{
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:
data.state = new Client::LobbyState();
stateVal = true;
stateChanged = true;
break;
case Client::GameClientState::ClientState_Game:
data.state = new Client::GameState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_Quit:
data.state->Release();
return Result_quit;
default:
return E_FAIL;
break;
data.state->Release();
return Result_error;
}
if(stateVal)
if( stateChanged )
{
data.state->Init( &data.networkClient ); // send game client
}
else
{
}
}
}
return S_OK;
return Result_continue;
}
HRESULT DanBiasGame::Render( )
@ -200,7 +216,9 @@ namespace DanBias
HRESULT DanBiasGame::CleanUp()
{
data.networkClient.Disconnect();
if( data.networkClient.IsConnected() )
data.networkClient.Disconnect();
delete data.inputObj;
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" );
// 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 );
// bind button collection to the singleton eventhandler
@ -61,45 +69,7 @@ bool MainState::Init( NetworkClient* nwClient )
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
{
//// picking
//// 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;
//}
EventHandler::Instance().Update( KeyInput );
return this->privData->nextState;
}
@ -118,11 +88,13 @@ bool MainState::Render()
bool MainState::Release()
{
Graphics::API::DeleteTexture( this->privData->background );
privData = NULL;
// button collection will be autoreleased from EventHandler
if( privData )
{
Graphics::API::DeleteTexture( this->privData->background );
privData = NULL;
// button collection will be autoreleased from EventHandler
}
return true;
}

View File

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

View File

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

View File

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

View File

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