GL - working with new models and server

This commit is contained in:
lindaandersson 2014-01-31 09:39:44 +01:00
commit 4df6b849a6
15 changed files with 357 additions and 32 deletions

View File

@ -204,6 +204,7 @@
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameClientState\GameClientState.cpp" />
<ClCompile Include="GameClientState\GameState.cpp" />
<ClCompile Include="GameClientState\LanMenuState.cpp" />
<ClCompile Include="GameClientState\LobbyState.cpp" />
<ClCompile Include="GameClientState\C_Object.cpp" />
<ClCompile Include="GameClientState\LoginState.cpp" />
@ -217,6 +218,7 @@
<ClInclude Include="GameClientState\C_obj\C_UIobject.h" />
<ClInclude Include="GameClientState\GameClientState.h" />
<ClInclude Include="GameClientState\GameState.h" />
<ClInclude Include="GameClientState\LanMenuState.h" />
<ClInclude Include="GameClientState\LoginState.h" />
<ClInclude Include="Include\DanBiasGame.h" />
<ClInclude Include="GameClientState\LobbyState.h" />

View File

@ -6,6 +6,7 @@
#include "GameClientState\GameState.h"
#include "GameClientState\LobbyState.h"
#include "GameClientState\LoginState.h"
#include "GameClientState\LanMenuState.h"
#include <Protocols.h>
#include "NetworkClient.h"
#include <GameServerAPI.h>

View File

@ -81,12 +81,8 @@ bool GameState::LoadModels(std::wstring mapFile)
Oyster::Math3D::Float4x4 translate;
C_Object* obj;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
scale.v[0].x = 8;
scale.v[1].y = 8;
scale.v[2].z = 8;
modelData.world = scale; //modelData.world * translate
modelData.modelPath = L"..\\Content\\Models\\ball.dan";
modelData.world = translate ;//modelData.world * translate
modelData.modelPath = L"world_earth.dan";
modelData.id = 0;
obj = new C_Player();
@ -95,7 +91,7 @@ bool GameState::LoadModels(std::wstring mapFile)
// add box model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-5,15,0));
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\Models\\box.dan";
modelData.id = 1;
@ -107,7 +103,7 @@ bool GameState::LoadModels(std::wstring mapFile)
// add player model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 15, 0));
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
@ -124,14 +120,14 @@ bool GameState::LoadModels(std::wstring mapFile)
}
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
{
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,1);
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 20);
camera->LookAt(pos, dir, up);
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
camera->UpdateViewMatrix();
@ -350,7 +346,7 @@ void GameState::Protocol( ObjPos* pos )
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
if(i == 2) // playerobj
{
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
camera->SetPosition(Oyster::Math::Float3(world[12], world[13]+2.2f, world[14]-1));
camera->UpdateViewMatrix();
}
}

View File

@ -0,0 +1,164 @@
#include "LanMenuState.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_StaticObj.h"
#include "C_obj/C_DynamicObj.h"
#include "DllInterfaces/GFXAPI.h"
#include <GameServerAPI.h>
using namespace DanBias::Client;
struct LanMenuState::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[2];
int modelCount;
// UI object
// game client*
}privData;
LanMenuState::LanMenuState()
{
}
LanMenuState::~LanMenuState()
{
}
bool LanMenuState::Init(Oyster::Network::NetworkClient* nwClient)
{
privData = new myData();
this->nwClient = nwClient;
// load models
LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f));
return true;
}
bool LanMenuState::LoadModels(std::wstring file)
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(-2,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 10;
plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight);
// open file
// read file
// init models
privData->modelCount = 2;
ModelInitData modelData;
modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.visible = true;
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
// load models
privData->object[0] = new C_StaticObj();
privData->object[0]->Init(modelData);
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate;
privData->object[1] = new C_DynamicObj();
privData->object[1]->Init(modelData);
return true;
}
bool LanMenuState::InitCamera(Oyster::Math::Float3 startPos)
{
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
}
GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput)
{
// create game
if( KeyInput->IsKeyPressed(DIK_C))
{
DanBias::GameServerAPI::ServerInitDesc desc;
DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart();
// my ip
nwClient->Connect(15151, "127.0.0.1");
if (!nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
return ClientState_Lobby;
}
// join game
if( KeyInput->IsKeyPressed(DIK_J))
{
// game ip
nwClient->Connect(15151, "194.47.150.56");
if (!nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
return ClientState_Lobby;
}
return ClientState_Same;
}
bool LanMenuState::Render()
{
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Oyster::Graphics::API::NewFrame();
// render objects
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Render();
}
// render effects
// render lights
Oyster::Graphics::API::EndFrame();
return true;
}
bool LanMenuState::Release()
{
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
delete privData;
privData = NULL;
return true;
}
void LanMenuState::Protocol(ProtocolStruct* protocolStruct)
{
if((PlayerName*)protocolStruct)
PlayerJoinProtocol((PlayerName*)protocolStruct);
}
void LanMenuState::PlayerJoinProtocol(PlayerName* name)
{
}

View File

@ -0,0 +1,37 @@
#ifndef LAN_MENU_STATE_H
#define LAN_MENU_STATE_H
#include "GameClientState.h"
#include "OysterMath.h"
namespace DanBias
{
namespace Client
{
class LanMenuState : public GameClientState
{
public:
LanMenuState();
virtual ~LanMenuState();
virtual bool Init(Oyster::Network::NetworkClient* nwClient);
virtual ClientState Update(float deltaTime, InputClass* KeyInput);
bool LoadModels(std::wstring file);
bool InitCamera(Oyster::Math::Float3 startPos);
virtual bool Render();
virtual bool Release();
virtual void Protocol(ProtocolStruct* protocolStruct);
void PlayerJoinProtocol(PlayerName* name);
private:
Oyster::Network::NetworkClient* nwClient;
struct myData;
myData* privData;
};
}
}
#endif

View File

@ -81,8 +81,18 @@ using namespace GameLogic;
void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj, void *args)
{
Oyster::Math::Float3 pushForce = Oyster::Math::Float4(1,0,0) * (1);
Oyster::Math::Float3 pushForce = Oyster::Math::Float4(1,0,0) * (500);
Oyster::Physics::ICustomBody::State state;
Object *realObj = (Object*)obj->GetCustomTag();
if(realObj->GetObjectType() == OBJECT_TYPE_BOX)
{
state = obj->GetState();
state.SetOrientation(Oyster::Math::Float3(1,0.5,1),Oyster::Math::Float3(1,0.5,1));
obj->SetState(state);
}
if(realObj->GetObjectType() == OBJECT_TYPE_PLAYER || realObj->GetObjectType() == OBJECT_TYPE_WORLD)
return;
state = obj->GetState();
state.ApplyLinearImpulse(pushForce);
obj->SetState(state);

View File

@ -129,6 +129,7 @@ bool Game::NewFrame()
}
gameInstance.onMoveFnc(this->level);
return true;
}

View File

@ -7,9 +7,9 @@ Game::PlayerData::PlayerData()
{
//set some stats that are appropriate to a player
Oyster::Physics::API::SimpleBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float3(0,165,0);
sbDesc.centerPosition = Oyster::Math::Float3(0,320,0);
sbDesc.size = Oyster::Math::Float3(4,7,4);
sbDesc.mass = 10;
//create rigid body
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();

View File

@ -25,7 +25,7 @@ void Level::InitiateLevel(float radius)
API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
sbDesc.ignoreGravity = true;
sbDesc.radius = 150;
sbDesc.radius = 300;
sbDesc.mass = 10e12f;
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
@ -39,9 +39,9 @@ void Level::InitiateLevel(float radius)
rigidBody->SetCustomTag(levelObj);
// add box
// add box
API::SimpleBodyDescription sbDesc_TestBox;
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-5,15,0,0);
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(4,320,0,0);
sbDesc_TestBox.ignoreGravity = false;
sbDesc_TestBox.mass = 10;
sbDesc_TestBox.size = Oyster::Math::Float4(0.5f,0.5f,0.5f,0);
@ -52,14 +52,14 @@ void Level::InitiateLevel(float radius)
testBox = new DynamicObject(rigidBody_TestBox, OBJECT_TYPE::OBJECT_TYPE_BOX);
rigidBody_TestBox->SetCustomTag(testBox);
rigidBody_TestBox->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,4));
state.ApplyLinearImpulse(Oyster::Math::Float3(0,20,0));
rigidBody_TestBox->SetState(state);
// add gravitation
API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 10e16f;
gravityWell.well.mass = 1e15f;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
API::Instance().AddGravity(gravityWell);
}

View File

@ -86,24 +86,24 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward()
{
setState.ApplyLinearImpulse(this->lookDir * (20 * this->gameInstance->GetFrameTime()));
setState.ApplyLinearImpulse(this->lookDir * (2000 * this->gameInstance->GetFrameTime()));
}
void Player::MoveBackwards()
{
setState.ApplyLinearImpulse(-this->lookDir * 20 * this->gameInstance->GetFrameTime());
setState.ApplyLinearImpulse(-this->lookDir * 2000 * this->gameInstance->GetFrameTime());
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime());
setState.ApplyLinearImpulse(r * 2000 * this->gameInstance->GetFrameTime());
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero
setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime());
setState.ApplyLinearImpulse(-r * 2000 * this->gameInstance->GetFrameTime());
}
void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -123,7 +123,7 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir)
{
this->lookDir = lookDir;
Oyster::Math::Float4 up(0,1,0,0);//-setState.GetGravityNormal();
Oyster::Math::Float4 up = -setState.GetGravityNormal();
Oyster::Math::Float4 pos = setState.GetCenterPosition();
Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz);
// cant set rotation

View File

@ -16,11 +16,15 @@
#include "../../Misc/Utilities.h"
#include "../../Misc/Thread/IThreadObject.h"
#include "../../Misc/Thread/OysterThread.h"
#include "../../Misc/Packing/Packing.h"
#include <queue>
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace Utility::DynamicMemory;
using namespace Utility::Container;
using namespace std;
/*************************************
PrivateData
@ -35,11 +39,12 @@ struct NetworkClient::PrivateData : public IThreadObject
Translator translator;
OysterThread thread;
OysterByte recieveBuffer;
//Message queue for sending and recieving
ThreadSafeQueue<CustomNetProtocol> sendQueue;
ThreadSafeQueue<NetEvent<NetworkClient*, NetworkClient::ClientEventArgs>> recieveQueue;
//ID
static unsigned int currID;
const unsigned int ID;
@ -66,7 +71,7 @@ struct NetworkClient::PrivateData : public IThreadObject
bool DoWork() override
{
if(!this->connection.IsConnected()) return false;
Send();
Recv();
@ -82,6 +87,7 @@ struct NetworkClient::PrivateData : public IThreadObject
CustomNetProtocol p = this->sendQueue.Pop();
this->translator.Pack(temp, p);
errorCode = this->connection.Send(temp);
if(errorCode != 0)
{
CEA parg;
@ -103,9 +109,13 @@ struct NetworkClient::PrivateData : public IThreadObject
if(errorCode == 0 && temp.GetSize())
{
HandleRecievedData(temp);
/* Replaced with EmptyOutbufferedQueue() and HandleRecievedData(OysterByte)
CustomNetProtocol protocol;
bool ok = this->translator.Unpack(protocol, temp);
//Check if the protocol was unpacked correctly
if(ok)
{
@ -114,7 +124,8 @@ struct NetworkClient::PrivateData : public IThreadObject
parg.data.protocol = protocol;
NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e = { this->parent, parg };
this->recieveQueue.Push(e);
}
}*/
}
//else
//{
@ -127,6 +138,76 @@ struct NetworkClient::PrivateData : public IThreadObject
return errorCode;
}
void HandleRecievedData(OysterByte& data)
{
//Loop through all packages that was recieved and add them to the queue.
unsigned int size = 0;
Oyster::Network::OysterByte msg;
//If there is part of a message in the buffer.
if(recieveBuffer.GetSize() > 0)
{
//cout << "the buffer size: " << recvBuffer.GetSize() <<endl;
unsigned int temp = recieveBuffer.GetSize();
size = Oyster::Packing::Unpacki(recieveBuffer);
if(temp + data.GetSize() > size)
{
msg = recieveBuffer;
recieveBuffer.Clear();
size -= msg.GetSize();
msg.AppendPartOfArray(data, 0, size);
UnpackMessageAndAddToQueue(msg);
}
else if(temp + data.GetSize() == size)
{
msg = recieveBuffer;
recieveBuffer.Clear();
size -= msg.GetSize();
msg += data;
UnpackMessageAndAddToQueue(msg);
return;
}
else
{
recieveBuffer += data;
size = data.GetSize();
return;
}
}
for(unsigned int i = size; i < data.GetSize(); i += size)
{
size = Oyster::Packing::Unpacki(&data.GetByteArray()[i]);
if(i+size > data.GetSize())
{
//Add it to the recvBuffer instead.
recieveBuffer.AppendPartOfArray(data, i, data.GetSize());
break;
}
msg.Clear();
msg.AppendPartOfArray(data, i, i+size);
UnpackMessageAndAddToQueue(msg);
}
}
void UnpackMessageAndAddToQueue(OysterByte& msg)
{
CustomNetProtocol protocol;
bool ok = this->translator.Unpack(protocol, msg);
//Check if the protocol was unpacked correctly
if(ok)
{
CEA parg;
parg.type = CEA::EventType_ProtocolRecieved;
parg.data.protocol = protocol;
NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e = { this->parent, parg };
this->recieveQueue.Push(e);
}
}
};
unsigned int NetworkClient::PrivateData::currID = 0;

View File

@ -48,7 +48,7 @@ void OysterByte::Resize(unsigned int cap)
}
}
int OysterByte::GetSize()
unsigned int OysterByte::GetSize()
{
return size;
}
@ -60,7 +60,7 @@ unsigned char* OysterByte::GetByteArray()
void OysterByte::AddSize(unsigned int size)
{
int newCapacity = this->size + size;
unsigned int newCapacity = this->size + size;
if(newCapacity >= capacity)
{
@ -81,6 +81,32 @@ void OysterByte::SetSize(unsigned int size)
this->size = size;
}
void OysterByte::AppendPartOfArray(OysterByte& source, unsigned int startIndex, unsigned int endIndex)
{
if(startIndex < 0 && startIndex >= endIndex)
return;
if(endIndex > source.size)
return;
unsigned int totalSize = endIndex - startIndex;
totalSize += size;
//Make sure the new data can fit in the array.
if(totalSize > capacity)
{
IncreaseCapacity(totalSize);
}
//Copy over new data.
for(unsigned int i = size; i < totalSize; i++)
{
byteArray[i] = source.byteArray[startIndex++];
}
//Set the new size
size = totalSize;
}
OysterByte& OysterByte::operator =(const OysterByte& obj)
{
delete[] this->byteArray;

View File

@ -25,7 +25,7 @@ namespace Oyster
//Resizes the array with, it does not keep anything in it.
void Resize(unsigned int cap);
int GetSize();
unsigned int GetSize();
unsigned char* GetByteArray();
void AddSize(unsigned int size);
@ -34,6 +34,9 @@ namespace Oyster
//Only sets the private variable 'size'
void SetSize(unsigned int size);
//Copies over a part of the addFrom array and adds it to the end of this array.
void AppendPartOfArray(OysterByte& source, unsigned int startIndex, unsigned int endIndex);
OysterByte& operator =(const OysterByte& obj);
operator char*();

View File

@ -27,7 +27,9 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
Shaded.Specular += light.Specular;
}
Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,1);
//Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,1);
Diffuse[DTid.xy] = float4(DiffuseGlow[DTid.xy].xyz,1);
Specular[DTid.xy] = float4(Shaded.Specular, 1);

View File

@ -8,5 +8,7 @@ RWTexture2D<float4> Output;
void main( uint3 DTid : SV_DispatchThreadID )
{
Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
//Output[DTid.xy] = Diffuse[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
//Output[DTid.xy] = Diffuse[DTid.xy];
}