Linda fixing some lvl loading stuff

This commit is contained in:
Robin Engman 2014-02-19 10:55:59 +01:00
parent 2fac21584f
commit fa95e6b821
6 changed files with 37 additions and 222 deletions

View File

@ -1,192 +0,0 @@
#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H
#define DANBIAS_CLIENTRECIEVEROBJECT_H
//WTF!? No headers included???
#include "../DanBiasGame/Include/DanBiasGame.h"
#include "../GameProtocols/GeneralProtocols.h"
#include "../GameProtocols/Protocols.h"
#include "../Network/NetworkAPI/NetworkClient.h"
#include "GameClientState\GameClientState.h"
#include "GameClientState\GameState.h"
#include <Utilities.h>
namespace DanBias
{
struct GameRecieverObject : public Oyster::Network::NetworkClient
{
Client::GameClientState* gameClientState;
// receiver function for server messages
// parsing protocols and sending it to the gameState
//void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
void GameRecieverObject::DataRecieved( Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e ) override
{
Oyster::Network::CustomNetProtocol p = e.args.data.protocol;
int pType = p[0].value.netInt;
//printf("Message(%i) arrived at client(%i)\n", pType, this->GetID());
switch (pType)
{
case protocol_General_Status:
{
GameLogic::Protocol_General_Status::States state;
state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort;
if( state == GameLogic::Protocol_General_Status::States_disconected)
{
// server disconnected
DanBiasGame::Release();
}
}
break;
case protocol_Gameplay_ObjectCreate:
{
Client::GameClientState::NewObj protocolData;// = new Client::GameClientState::NewObj;
protocolData.object_ID = p[1].value.netInt;
protocolData.path = p[2].value.netCharPtr;
for(int i = 0; i< 16; i++)
{
protocolData.worldPos[i] = p[i+3].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(&protocolData);
//delete p[2].value.netCharPtr; //delete char array
//delete protocolData;
//protocolData = NULL;
}
break;
case protocol_Gameplay_ObjectDisabled:
{
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
protocolData->object_ID = p[1].value.netInt;
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_ObjectPosition:
{
// 0: reserved
// 1: objectID
// 2,3,4: position
// 5,6,7,8: rotation quaternion
GameLogic::Protocol_ObjectPosition data(p);
Client::GameClientState::ObjPos protocolData;
protocolData.object_ID = data.object_ID;
//protocolData.object_ID = p[1].value.netInt;
for( int i = 0; i < 3; ++i )
{
protocolData.position[i] = data.position[i];
}
//for(int i = 0; i< 16; i++)
//{
// protocolData.worldPos[i] = p[i+2].value.netFloat;
//}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(&protocolData);
}
break;
case protocol_Gameplay_ObjectPositionRotation:
{
Client::GameClientState::ObjPos protocolData;
protocolData.object_ID = p[1].value.netInt;
for(int i = 0; i< 16; i++)
{
protocolData.worldPos[i] = p[i+2].value.netFloat;
}
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(&protocolData);
}
break;
case protocol_Lobby_Create:
{
if(dynamic_cast<Client::LobbyState*>(gameClientState))
{
int id = p.Get(1).value.netInt;
std::string name = p.Get(19).value.netCharPtr;
Oyster::Math::Float4x4 w;
for(int i = 0; i< 16; i++)
{
w[i] = p[i+2].value.netFloat;
}
gameClientState->Release();
delete gameClientState;
gameClientState = new Client::GameState();
gameClientState->Init(this);
std::wstring temp;
Utility::String::StringToWstring(name, temp);
((Client::GameState*)gameClientState)->InitiatePlayer(id, temp, w);
//Do some wait state?
}
}
break;
case protocol_Lobby_Start:
{
if(dynamic_cast<Client::GameState*>(gameClientState))
{
//Game state should start in n seconds
GameLogic::Protocol_LobbyStartGame p(p);
p.seconds;
//Sleep((int)(p.seconds * 1000));
}
}
break;
default:
break;
}
if(ProtocolIsLobby(p[0].value.netInt)) ParseLobbyProtocol(p);
}
void ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p)
{
switch (p[0].value.netShort)
{
case protocol_General_Status: //this->GeneralStatus (Protocol_General_Status (p), c);
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_Start: //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_LobbyLogin (p), c);
break;
case protocol_Lobby_Refresh: //this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break;
case protocol_Lobby_GameData: //this->LobbyGameData (Protocol_LobbyGameData (p), c);
{
//GameLogic::Protocol_LobbyGameData temp(p);
//printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion);
}
break;
case protocol_Lobby_ClientData: //this->LobbyMainData (Protocol_LobbyClientData (p), c);
break;
//case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
//break;
}
}
};
}
#endif

View File

@ -187,7 +187,7 @@ void GameState::ReadKeyInput()
{ {
if( this->privData->input->IsKeyPressed(DIK_W) ) if( this->privData->input->IsKeyPressed(DIK_W) )
{ {
if(!this->privData->key_forward) //if(!this->privData->key_forward)
{ {
this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); this->privData->nwClient->Send( Protocol_PlayerMovementForward() );
this->privData->key_forward = true; this->privData->key_forward = true;
@ -198,7 +198,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_S) ) if( this->privData->input->IsKeyPressed(DIK_S) )
{ {
if( !this->privData->key_backward ) //if( !this->privData->key_backward )
{ {
this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); this->privData->nwClient->Send( Protocol_PlayerMovementBackward() );
this->privData->key_backward = true; this->privData->key_backward = true;
@ -209,7 +209,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_A) ) if( this->privData->input->IsKeyPressed(DIK_A) )
{ {
if( !this->privData->key_strafeLeft ) //if( !this->privData->key_strafeLeft )
{ {
this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); this->privData->nwClient->Send( Protocol_PlayerMovementLeft() );
this->privData->key_strafeLeft = true; this->privData->key_strafeLeft = true;
@ -220,7 +220,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_D) ) if( this->privData->input->IsKeyPressed(DIK_D) )
{ {
if( !this->privData->key_strafeRight ) //if( !this->privData->key_strafeRight )
{ {
this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
this->privData->key_strafeRight = true; this->privData->key_strafeRight = true;
@ -372,7 +372,9 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
if( this->privData->myId == decoded.object_ID ) if( this->privData->myId == decoded.object_ID )
{ {
this->privData->camera.SetPosition( position ); this->privData->camera.SetPosition( position );
this->privData->camera.SetRotation( rotation ); //this->privData->camera.SetRotation( rotation );
this->privData->player.setPos( position );
//this->privData->player.setRot( rotation );
} }
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];

View File

@ -60,8 +60,8 @@ bool LanMenuState::Init( SharedStateContent &shared )
// create guiElements // create guiElements
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 = 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->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->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
this->privData->connectIP->SetFontHeight( 0.08f ); this->privData->connectIP->SetFontHeight( 0.08f );
this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetLineSpacing( 0.005f );
this->privData->connectIP->SetTopAligned(); this->privData->connectIP->SetTopAligned();

View File

@ -141,6 +141,14 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
desc.scale = oh->scale; desc.scale = oh->scale;
desc.visible = true; desc.visible = true;
// HACK: untill the world is right in lvl format
if( oh->specialTypeID == ObjectSpecialType_World)
{
desc.position = Float3(0,0,0);
desc.rotation = Quaternion::identity;
desc.scale = Float3(300,300,300);
}
C_StaticObj *staticObject = new C_StaticObj(); C_StaticObj *staticObject = new C_StaticObj();
if( staticObject->Init( desc ) ) if( staticObject->Init( desc ) )
{ {

View File

@ -7,7 +7,7 @@ Game::PlayerData::PlayerData()
{ {
//set some stats that are appropriate to a player //set some stats that are appropriate to a player
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(-50,180,0);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f);
Oyster::Math::Float mass = 60; Oyster::Math::Float mass = 60;

View File

@ -26,14 +26,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
{ {
case ObjectSpecialType_None: case ObjectSpecialType_None:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Sky: case ObjectSpecialType_Sky:
{ {
float skySize = ((SkyAttributes*)obj)->skySize; float skySize = ((SkyAttributes*)obj)->skySize;
//gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); //gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_World: case ObjectSpecialType_World:
@ -44,21 +44,21 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float worldSize = ((WorldAttributes*)obj)->worldSize; float worldSize = ((WorldAttributes*)obj)->worldSize;
float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize;
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Building: case ObjectSpecialType_Building:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
case ObjectSpecialType_Stone: case ObjectSpecialType_Stone:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_StandardBox: case ObjectSpecialType_StandardBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_RedExplosiveBox: case ObjectSpecialType_RedExplosiveBox:
@ -75,24 +75,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
// break; // break;
case ObjectSpecialType_SpikeBox: case ObjectSpecialType_SpikeBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Spike: case ObjectSpecialType_Spike:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_CrystalFormation: case ObjectSpecialType_CrystalFormation:
{ {
int dmg = 50; int dmg = 50;
//gameObj = new Crystal(rigidBody); //gameObj = new Crystal(rigidBody);
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_CrystalShard: case ObjectSpecialType_CrystalShard:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_JumpPad: case ObjectSpecialType_JumpPad:
@ -100,13 +100,13 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float power = 500; //((JumpPadAttributes*)obj)->power; float power = 500; //((JumpPadAttributes*)obj)->power;
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
Oyster::Math::Float3 pushForce = dir * power; Oyster::Math::Float3 pushForce = dir * power;
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++ , pushForce); gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce);
} }
break; break;
case ObjectSpecialType_Portal: case ObjectSpecialType_Portal:
{ {
Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination;
gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, destination); gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination);
} }
break; break;
//case ObjectSpecialType_SpawnPoint: //case ObjectSpecialType_SpawnPoint:
@ -122,12 +122,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break; break;
case ObjectSpecialType_Generic: case ObjectSpecialType_Generic:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
default: default:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
} }
@ -213,6 +213,7 @@ bool Level::InitiateLevel(std::wstring levelPath)
for (int i = 0; i < objCount; i++) for (int i = 0; i < objCount; i++)
{ {
++this->objID;
ObjectTypeHeader* obj = objects.at(i); ObjectTypeHeader* obj = objects.at(i);
switch (obj->typeID) switch (obj->typeID)
{ {
@ -229,13 +230,10 @@ bool Level::InitiateLevel(std::wstring levelPath)
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Static = NULL; ICustomBody* rigidBody_Static = NULL;
if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_Sky)
{
} // HACK: untill the world is right in lvl format
if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World) if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World)
{ {
Oyster::Math::Float3 rigidWorldPos; Oyster::Math::Float3 rigidWorldPos;
Oyster::Math::Float4 rigidWorldRotation; Oyster::Math::Float4 rigidWorldRotation;
float rigidBodyMass; float rigidBodyMass;
@ -249,9 +247,8 @@ bool Level::InitiateLevel(std::wstring levelPath)
rigidWorldRotation = Oyster::Math::Float4(0,0,0,1); rigidWorldRotation = Oyster::Math::Float4(0,0,0,1);
//mass scaled //mass scaled
rigidBodyMass = 100; rigidBodyMass = 0;
//Radius scaled //Radius scaled
rigidBodyRadius = 150; rigidBodyRadius = 150;