MULTIPLAYER

This commit is contained in:
ViktorLjung
2014-05-20 00:20:09 +02:00
parent ff58f881ae
commit 609687d6b4
15 changed files with 575 additions and 117 deletions
+1 -1
Submodule assets updated: 9d3f71bee6...6cc38589ed
+8 -10
View File
@@ -1,10 +1,6 @@
#ifndef Components_Input_h__
#define Components_Input_h__
#include <array>
#include <GLFW/glfw3.h>
#include "Component.h"
namespace Components
@@ -12,12 +8,14 @@ namespace Components
struct Input : Component
{
std::array<int, GLFW_KEY_LAST+1> KeyState;
std::array<int, GLFW_KEY_LAST+1> LastKeyState;
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> MouseState;
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> LastMouseState;
float dX, dY;
float WheelDelta;
/*Input()
: Keyboard(false)
, Mouse(false)
, GamepadID(0) { }
bool Keyboard;
bool Mouse;
int GamepadID;*/
virtual Input* Clone() const override { return new Input(*this); }
};
+21
View File
@@ -0,0 +1,21 @@
#ifndef Player_h__
#define Player_h__
#include "Component.h"
namespace Components
{
struct Player : Component
{
Player()
: ID(0) { }
int ID;
virtual Player* Clone() const override { return new Player(*this); }
};
}
#endif // Player_h__
+3
View File
@@ -7,6 +7,9 @@ namespace Components
{
struct TankSteering : Component
{
EntityID Player;
EntityID Turret;
EntityID Barrel;
TankSteering* Clone() const override { return new TankSteering(*this); }
};
}
-1
View File
@@ -10,7 +10,6 @@ struct TowerSteering : Component
{
TowerSteering()
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
float TurnSpeed;
glm::vec3 Axis;
virtual TowerSteering* Clone() const override { return new TowerSteering(*this); }
+449 -14
View File
@@ -72,15 +72,28 @@ void GameWorld::Initialize()
}
CommitEntity(viewport2);
auto player1 = CreateEntity();
{
auto player = AddComponent<Components::Player>(player1);
player->ID = 1;
}
auto player2 = CreateEntity();
{
auto player = AddComponent<Components::Player>(player2);
player->ID = 2;
}
{
auto ground = CreateEntity();
auto transform = AddComponent<Components::Transform>(ground);
transform->Position = glm::vec3(0, 0, 0);
transform->Position = glm::vec3(0, -50, 0);
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(ground);
//model->ModelFile = "Models/TestScene/testScene.obj";
model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
model->ModelFile = "Models/TestScene3/testScene.obj";
//model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
auto physics = AddComponent<Components::Physics>(ground);
physics->Mass = 10;
@@ -90,8 +103,8 @@ void GameWorld::Initialize()
auto groundshape = CreateEntity(ground);
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
//meshShape->ResourceName = "Models/TestScene/testScene.obj";
//meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
meshShape->ResourceName = "Models/TestScene3/testScene.obj";
CommitEntity(groundshape);
@@ -239,10 +252,11 @@ void GameWorld::Initialize()
physics->Mass = 63000 - 16000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 8000.f;
vehicle->MaxTorque = 36000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
AddComponent<Components::TankSteering>(tank);
auto tankSteering = AddComponent<Components::TankSteering>(tank);
tankSteering->Player = player1;
AddComponent<Components::Input>(tank);
{
@@ -264,24 +278,24 @@ void GameWorld::Initialize()
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/Fix/Chassi.obj";
model->ModelFile = "Models/Tank/tankBody.obj";
}
{
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 1.2f, 1.8f);
transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/Fix/Top.obj";
model->ModelFile = "Models/Tank/tankTop.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>()/4.f;
{
auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.018f, -0.2, -1.3f);
transform->Position = glm::vec3(-0.012f, 0.4f, -0.75);
auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
model->ModelFile = "Models/Tank/tankBarrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
@@ -312,7 +326,429 @@ void GameWorld::Initialize()
barrelSteering->ShotTemplate = shot;
}
CommitEntity(barrel);
tankSteering->Barrel = barrel;
}
CommitEntity(tower);
tankSteering->Turret = tower;
auto cameraTower = CreateEntity(tower);
{
auto transform = AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 11.f;
transform->Position.y = 4.f;
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
//auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
}
CommitEntity(cameraTower);
GetComponent<Components::Viewport>(viewport1)->Camera = cameraTower;
}
{
auto lightentity = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(lightentity);
transform->Position = glm::vec3(0, 0, 0);
auto light = AddComponent<Components::PointLight>(lightentity);
//light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f);
//light->Specular = glm::vec3(1.f);
/*light->ConstantAttenuation = 0.3f;
light->LinearAttenuation = 0.003f;
light->QuadraticAttenuation = 0.002f;*/
}
// auto wheelpair = CreateEntity(tank);
// SetProperty(wheelpair, "Name", "WheelPair");
// AddComponent(wheelpair, "WheelPairThingy");
//Create wheels
float wheelOffset = 0.4f;
float springLength = 0.3f;
float suspensionStrength = 15.f;
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
//Back
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(2,-1.7,2.0);
transformComponent->Scale = glm::vec3(3,3,3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2,-1.7,2.0);
transformComponent->Scale = glm::vec3(3,3,3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
CommitEntity(tank);
}
{
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(20, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 36000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
auto tankSteering = AddComponent<Components::TankSteering>(tank);
tankSteering->Player = player2;
AddComponent<Components::Input>(tank);
{
auto shape = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shape);
auto meshShape = AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj";
CommitEntity(shape);
// auto box = AddComponent<Components::Box>(jeep);
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
}
{
auto chassis = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/tankBody.obj";
}
{
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/tankTop.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>()/4.f;
{
auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.012f, 0.4f, -0.75);
auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/tankBarrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
barrelSteering->ShotSpeed = 70.f;
{
auto shot = CreateEntity(barrel);
auto transform = AddComponent<Components::Transform>(shot);
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
transform->Orientation = glm::angleAxis(-glm::pi<float>()/2.f, glm::vec3(1, 0, 0));
transform->Scale = glm::vec3(3.f);
AddComponent<Components::Template>(shot);
auto physics = AddComponent<Components::Physics>(shot);
physics->Mass = 25.f;
physics->Static = false;
auto modelComponent = AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
{
auto shape = CreateEntity(shot);
auto transform = AddComponent<Components::Transform>(shape);
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
CommitEntity(shape);
}
CommitEntity(shot);
barrelSteering->ShotTemplate = shot;
}
CommitEntity(barrel);
tankSteering->Barrel = barrel;
}
CommitEntity(tower);
tankSteering->Turret = tower;
auto cameraTower = CreateEntity(tower);
{
@@ -643,8 +1079,6 @@ void GameWorld::Initialize()
CommitEntity(tank);
}
/*
for(int i = 0; i < 10; i++)
{
@@ -744,6 +1178,7 @@ void GameWorld::RegisterComponents()
{
m_ComponentFactory.Register<Components::Transform>([]() { return new Components::Transform(); });
m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); });
m_ComponentFactory.Register<Components::Player>([]() { return new Components::Player(); });
}
void GameWorld::RegisterSystems()
+1
View File
@@ -40,6 +40,7 @@
#include "Components/TankSteering.h"
#include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h"
#include "Components/Player.h"
class GameWorld : public World
{
+1 -1
View File
@@ -66,7 +66,7 @@ Model::Model(ResourceManager* rm, OBJ &obj)
if (Vertices.size() > 0)
{
CreateTangents();
getSimilarVertexIndex();
//getSimilarVertexIndex();
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
}
else
+4 -4
View File
@@ -53,7 +53,7 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
float value;
std::tie(command, value) = bindingIt->second;
m_CommandKeyboardValues[command][event.KeyCode] = value;
PublishCommand(0, command, GetCommandTotalValue(command));
PublishCommand(1, command, GetCommandTotalValue(command));
}
return true;
@@ -68,7 +68,7 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
float value;
std::tie(command, value) = bindingIt->second;
m_CommandKeyboardValues[command][event.KeyCode] = 0;
PublishCommand(0, command, GetCommandTotalValue(command));;
PublishCommand(1, command, GetCommandTotalValue(command));;
}
return true;
@@ -83,7 +83,7 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
float value;
std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = value;
PublishCommand(0, command, GetCommandTotalValue(command));
PublishCommand(1, command, GetCommandTotalValue(command));
}
return true;
@@ -98,7 +98,7 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
float value;
std::tie(command, value) = bindingIt->second;
m_CommandMouseButtonValues[command][event.Button] = 0;
PublishCommand(0, command, GetCommandTotalValue(command));
PublishCommand(1, command, GetCommandTotalValue(command));
}
return true;
+1 -1
View File
@@ -75,7 +75,7 @@ void Systems::PhysicsSystem::Initialize()
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f);
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_DO_NOTHING;
// You must specify the size of the broad phase - objects should not be simulated outside this region
worldInfo.setBroadPhaseWorldSize(1000.0f);
+5 -1
View File
@@ -43,11 +43,15 @@ void Systems::RenderSystem::OnEntityCommit(EntityID entity)
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent)
return;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
// Draw models
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (transformComponent&& modelComponent)
if (transformComponent && modelComponent)
{
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
if (model)
+52 -52
View File
@@ -11,70 +11,85 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
void Systems::TankSteeringSystem::Initialize()
{
m_TankInputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker));
m_TowerInputController = std::unique_ptr<TowerSteeringInputController>(new TowerSteeringInputController(EventBroker));
for (int i = 0; i < 4; i++)
{
m_TankInputControllers[i] = std::shared_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker, i + 1));
}
}
void Systems::TankSteeringSystem::Update(double dt)
{
m_TankInputController->Update(dt);
m_TowerInputController->Update(dt);
for (int i = 0; i < 4; i++)
{
m_TankInputControllers[i]->Update(dt);
}
}
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity);
if(!tankSteeringComponent)
return;
if(tankSteeringComponent)
auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
if (!playerComponent)
return;
if (playerComponent->ID == 0)
return;
auto inputController = m_TankInputControllers[playerComponent->ID - 1];
Events::TankSteer eSteering;
eSteering.Entity = entity;
eSteering.PositionX = inputController->PositionX;
eSteering.PositionY = inputController->PositionY;
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(tankSteeringComponent->Turret);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
if(towerSteeringComponent)
{
Events::TankSteer e;
e.Entity = entity;
e.PositionX = m_TankInputController->PositionX;
e.PositionY = m_TankInputController->PositionY;
e.Handbrake = m_TankInputController->Handbrake;
EventBroker->Publish(e);
}
else if(towerSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Turret);
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * inputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
}
else if(barrelSteeringComponent)
if(barrelSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0)
if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
{
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity e;
e.Entity = clone;
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(e);
m_TimeSinceLastShot[entity] = 0;
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(eSetVelocity);
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
//1,670m/s
//25kg
EntityID baseParent = m_World->GetEntityBaseParent(entity);
Events::ApplyPointImpulse ePointImpulse ;
ePointImpulse.Entity = baseParent;
ePointImpulse.Entity = entity;
ePointImpulse.Position = absoluteTransform.Position;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
EventBroker->Publish(ePointImpulse);
}
m_TimeSinceLastShot[entity] += dt;
m_TimeSinceLastShot[tankSteeringComponent->Barrel] += dt;
}
}
@@ -82,10 +97,7 @@ void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt
{
PositionX = m_Horizontal;
PositionY = m_Vertical;
}
void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double dt )
{
TowerDirection = m_TowerDirection;
BarrelDirection = m_BarrelDirection;
Shoot = m_Shoot;
@@ -93,9 +105,12 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != this->PlayerID)
return false;
float val = event.Value;
// Tank
if (event.Command == "horizontal")
{
m_Horizontal = val;
@@ -111,12 +126,7 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
Handbrake = val > 0;
}
return true;
}
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const Events::InputCommand &event )
{
float val = event.Value;
// Turret
if(event.Command == "tower_rotation")
{
m_TowerDirection = -val;
@@ -130,19 +140,9 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
{
m_Shoot = val > 0;
}
return true;
}
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnMouseMove( const Events::MouseMove &event )
{
return false;
}
bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event )
{
return false;
}
+20 -29
View File
@@ -11,6 +11,7 @@
#include "Components/BarrelSteering.h"
#include "Components/Physics.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Systems/TransformSystem.h"
#include "InputController.h"
@@ -31,9 +32,7 @@ namespace Systems
private:
class TankSteeringInputController;
std::unique_ptr<TankSteeringInputController> m_TankInputController;
class TowerSteeringInputController;
std::unique_ptr<TowerSteeringInputController> m_TowerInputController;
std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
std::map<EntityID, double> m_TimeSinceLastShot;
};
@@ -41,35 +40,17 @@ namespace Systems
class TankSteeringSystem::TankSteeringInputController : InputController
{
public:
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker, int playerID)
: InputController(eventBroker)
{
PlayerID = playerID;
m_Horizontal = 0.f;
m_Vertical = 0.f;
PositionX = 0;
PositionY = 0;
Handbrake = false;
}
float PositionY;
float PositionX;
bool Handbrake;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
virtual bool OnMouseMove(const Events::MouseMove &event);
private:
float m_Horizontal;
float m_Vertical;
};
class TankSteeringSystem::TowerSteeringInputController : InputController
{
public:
TowerSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
: InputController(eventBroker)
{
m_TowerDirection = 0.f;
m_BarrelDirection = 0.f;
TowerDirection = 0.f;
@@ -78,18 +59,28 @@ namespace Systems
m_Shoot = false;
}
int PlayerID;
float PositionY;
float PositionX;
bool Handbrake;
float TowerDirection;
float BarrelDirection;
bool Shoot;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
virtual bool OnMouseMove(const Events::MouseMove &event);
//virtual bool OnMouseMove(const Events::MouseMove &event);
private:
float m_TowerDirection;
float m_BarrelDirection;
bool m_Shoot;
};
float m_Horizontal;
float m_Vertical;
float m_TowerDirection;
float m_BarrelDirection;
bool m_Shoot;
};
}
+1
View File
@@ -141,6 +141,7 @@
<ClInclude Include="..\..\src\Components\Particle.h" />
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
<ClInclude Include="..\..\src\Components\Physics.h" />
<ClInclude Include="..\..\src\Components\Player.h" />
<ClInclude Include="..\..\src\Components\PointLight.h" />
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
<ClInclude Include="..\..\src\Components\SphereShape.h" />
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\..\src\main.cpp" />
@@ -155,6 +155,9 @@
<Filter Include="Gameplay\Vehicles\Helicopter\Systems">
<UniqueIdentifier>{b34c0c95-a887-4cf4-af24-cf7c1f459aa8}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Components">
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\World.h" />
@@ -371,7 +374,7 @@
<Filter>Input\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Viewport.h">
<Filter>Physics\Components</Filter>
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Health.h">
<Filter>Physics\Components</Filter>
@@ -388,10 +391,12 @@
<ClInclude Include="..\..\src\Events\ApplyForce.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Util\defferedUtil.h" />
<ClInclude Include="..\..\src\Events\ApplyPointImpulse.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Player.h">
<Filter>Gameplay\Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">