diff --git a/deploy.bat b/deploy.bat index f9f1eb9..f9f05ef 100755 --- a/deploy.bat +++ b/deploy.bat @@ -15,12 +15,12 @@ MKLINK "%ConfigPath%\Sounds\" "assets\Sounds\" /J :: Shaders MKLINK "%ConfigPath%\Shaders\" "src\Shaders\" /J :: DLLs -MKLINK "%ConfigPath%\glfw3.dll" "libs\glfw-3.0.4\lib\%Configuration%\glfw3.dll" /H -MKLINK "%ConfigPath%\fmodex.dll" "libs\FMOD\lib\fmodex.dll" /H +COPY "libs\glfw-3.0.4\lib\%Configuration%\glfw3.dll" "%ConfigPath%\glfw3.dll" +COPY "libs\FMOD\lib\fmodex.dll" "%ConfigPath%\fmodex.dll" IF %~1==Debug ( - MKLINK "%ConfigPath%\glew32d.dll" "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32d.dll" /H + COPY "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32d.dll" "%ConfigPath%\glew32d.dll" ) IF %~1==Release ( - MKLINK "%ConfigPath%\glew32.dll" "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32.dll" /H + COPY "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32.dll" "%ConfigPath%\glew32.dll" ) GOTO:eof \ No newline at end of file diff --git a/src/Components/Physics.h b/src/Components/Physics.h index a99cd79..e2947ab 100644 --- a/src/Components/Physics.h +++ b/src/Components/Physics.h @@ -16,13 +16,38 @@ struct Physics : Component EXPLOSION = 4, }; + enum class MotionTypeEnum + { + Dynamic, + Fixed, + Keyframed + }; + Physics() - : Mass(1.f), Static(false), Phantom(false), CalculateCenterOfMass(true), CenterOfMass(glm::vec3(0)), InitialLinearVelocity(glm::vec3(0)), InitialAngularVelocity(glm::vec3(0)), - LinearDamping(0.f), AngularDamping(0.05f), GravityFactor(1.f), Friction(0.5f), Restitution(0.4f), MaxLinearVelocity(200.f), MaxAngularVelocity(200.f), - CollisionLayer(0), CollisionSystemGroup(0), CollisionSubSystemId(0), CollisionSubSystemDontCollideWith(0), CollisionEvent(false){} + : Mass(1.f) + //, Static(false) + , MotionType(MotionTypeEnum::Fixed) + , Phantom(false) + , CalculateCenterOfMass(true) + , CenterOfMass(glm::vec3(0)) + , InitialLinearVelocity(glm::vec3(0)) + , InitialAngularVelocity(glm::vec3(0)) + , LinearDamping(0.f) + , AngularDamping(0.05f) + , GravityFactor(1.f) + , Friction(0.5f) + , Restitution(0.4f) + , MaxLinearVelocity(200.f) + , MaxAngularVelocity(200.f) + , CollisionLayer(0) + , CollisionSystemGroup(0) + , CollisionSubSystemId(0) + , CollisionSubSystemDontCollideWith(0) + , CollisionEvent(false) + { } float Mass; - bool Static; + MotionTypeEnum MotionType; bool Phantom; bool CalculateCenterOfMass; diff --git a/src/Components/SpawnPoint.h b/src/Components/SpawnPoint.h new file mode 100644 index 0000000..c29230d --- /dev/null +++ b/src/Components/SpawnPoint.h @@ -0,0 +1,16 @@ +#ifndef Components_VehicleSpawn_h__ +#define Components_VehicleSpawn_h__ + +#include "Component.h" + +namespace Components +{ + +struct SpawnPoint : Component +{ + virtual SpawnPoint* Clone() const override { return new SpawnPoint(*this); } +}; + +} + +#endif // Components_VehicleSpawn_h__ \ No newline at end of file diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 5dfed54..9f6cfac 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -10,10 +10,9 @@ namespace Components struct Vehicle : Component { Vehicle() - : MaxTorque(1000.0f), MinRPM(0.0f), OptimalRPM(2000.0f), MaxRPM(3000.0f), MaxSteeringAngle(35), TopSpeed(70.0f), - MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(2500.0f), DownshiftRPM(500.0f), - gearsRatio0(4.5f), gearsRatio1(2.5f), gearsRatio2(1.0f), gearsRatio3(0.5f){ } - //gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f) + : MaxTorque(1000.0f), MinRPM(200.0f), OptimalRPM(3000.0f), MaxRPM(6000.0f), MaxSteeringAngle(35), TopSpeed(90.0f), + MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(5500.0f), DownshiftRPM(1000.0f), + gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f){ } float MaxTorque; float MinRPM; float OptimalRPM; diff --git a/src/Components/Wall.h b/src/Components/Wall.h new file mode 100644 index 0000000..95ee2d7 --- /dev/null +++ b/src/Components/Wall.h @@ -0,0 +1,20 @@ +#ifndef Components_Wall_h__ +#define Components_Wall_h__ + +#include "Component.h" +#include +#include + +namespace Components +{ + + struct Wall : Component + { + std::vector Walldebris; + + virtual Wall* Clone() const override { return new Wall(*this); } + }; + +} + +#endif // Components_TankShell_h__ diff --git a/src/Events/OnDead.h b/src/Events/OnDead.h new file mode 100644 index 0000000..0149ac1 --- /dev/null +++ b/src/Events/OnDead.h @@ -0,0 +1,16 @@ +#ifndef Events_OnDead_h__ +#define Events_OnDead_h__ +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct OnDead : Event + { + EntityID Entity; + }; +} + + + +#endif // Events_OnDead_h__ \ No newline at end of file diff --git a/src/Events/SpawnVehicle.h b/src/Events/SpawnVehicle.h new file mode 100644 index 0000000..21393de --- /dev/null +++ b/src/Events/SpawnVehicle.h @@ -0,0 +1,16 @@ +#ifndef Events_SpawnVehicle_h__ +#define Events_SpawnVehicle_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct SpawnVehicle : Event + { + int PlayerID; + std::string VehicleType; + }; +} + +#endif // Events_SpawnVehicle_h__ \ No newline at end of file diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index 6a649b5..25c2dd1 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -6,6 +6,9 @@ #include "Util/Rectangle.h" #include "EventBroker.h" +#include "Events/KeyDown.h" +#include "Events/KeyUp.h" +#include "Events/InputCommand.h" #include "ResourceManager.h" #include "Renderer.h" #include "RenderQueue.h" @@ -79,7 +82,13 @@ public: std::string Name() const { return m_Name; } void SetName(std::string val) { m_Name = val; } int Layer() const { return m_Layer; } - bool Hidden() const { return m_Hidden; } + bool Hidden() const + { + if (m_Parent) + return m_Parent->Hidden() || m_Hidden; + else + return m_Hidden; + } void Hide() { m_Hidden = true; } void Show() { m_Hidden = false; } @@ -129,11 +138,6 @@ public: return Rectangle(left, top, width, height); } - virtual bool OnKeyDown(const Events::KeyDown &event) { return false; } - virtual bool OnKeyUp(const Events::KeyUp &event) { return false; } - //virtual bool OnMouseDown(const Events::KeyDown &event) { } - //virtual bool OnMouseUp(const Events::KeyDown &event) { } - void UpdateLayered(double dt) { if (this->Hidden()) @@ -196,14 +200,22 @@ protected: typedef std::multimap> Children_t; // name -> frame std::map m_Children; // layer -> Children_t + virtual bool OnKeyDown(const Events::KeyDown &event) { return false; } + virtual bool OnKeyUp(const Events::KeyUp &event) { return false; } + //virtual bool OnMouseDown(const Events::KeyDown &event) { } + //virtual bool OnMouseUp(const Events::KeyDown &event) { } + virtual bool OnCommand(const Events::InputCommand &event) { return false; } + private: EventRelay m_EKeyDown; EventRelay m_EKeyUp; + EventRelay m_EInputCommand; void Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown); EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand); } }; diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index f180835..c09239f 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -25,13 +25,13 @@ public: vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1->X = 0; vp1->Width = this->Width / 2.f; - new PlayerHUD(vp1, "PlayerHUD", m_World, 1); - //new VehicleSelection(vp1, "VehicleSelection", m_World, 1); + //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); + auto vehicleSelection = new VehicleSelection(vp1, "VehicleSelection", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); vp2->Width = this->Width / 2.f; - new PlayerHUD(vp2, "PlayerHUD", m_World, 2); + //new PlayerHUD(vp2, "PlayerHUD", m_World, 2); m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); m_FreeCamViewport->Hide(); diff --git a/src/GUI/VehicleSelection.h b/src/GUI/VehicleSelection.h index fa11ceb..9a2ec18 100644 --- a/src/GUI/VehicleSelection.h +++ b/src/GUI/VehicleSelection.h @@ -3,6 +3,7 @@ #include "GUI/Frame.h" #include "GUI/HealthOverlay.h" +#include "Events/SpawnVehicle.h" namespace GUI { @@ -37,35 +38,8 @@ namespace GUI m_Background->SetTexture("Textures/GUI/VehicleSelection/1.png"); } - bool OnKeyUp(const Events::KeyUp &event) override - { - if (event.KeyCode == GLFW_KEY_LEFT) - { - m_CurrentSelection--; - } - else if (event.KeyCode == GLFW_KEY_RIGHT) - { - m_CurrentSelection++; - } - m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection); - - std::stringstream ss; - ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png"; - m_Background->FadeToTexture(ss.str(), 1.f); - - glm::vec2 scale = Scale(); - glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection]; - m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f); - glm::vec2 size = m_SelectionSizes[m_CurrentSelection]; - m_TargetSize = size * scale; - - return true; - } - void Update(double dt) override { - - glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate; m_CurrentCoordinate += posDiff * 2.f * (float)dt; @@ -94,6 +68,77 @@ namespace GUI float m_CurrentAlpha; TextureFrame* m_Background; + + bool OnCommand(const Events::InputCommand &event) override + { + if (Hidden()) + return false; + + if (event.PlayerID != m_PlayerID) + return false; + + // Menu movement + if (event.Command == "interface_horizontal" || event.Command == "interface_vertical") + { + // Horizontal scrolling + if (event.Command == "interface_horizontal") + { + if (event.Value > 0) + m_CurrentSelection++; + else if (event.Value < 0) + m_CurrentSelection--; + } + // Vertical scrolling to switch between "rows" in an intuitive way + else if (event.Command == "interface_vertical") + { + if (event.Value > 0) + { + if (m_CurrentSelection == 0) + m_CurrentSelection++; + else if (m_CurrentSelection == 3) + m_CurrentSelection--; + } + else if (event.Value < 0) + { + if (m_CurrentSelection == 1) + m_CurrentSelection--; + else if (m_CurrentSelection == 2) + m_CurrentSelection++; + } + } + + m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection); + + std::stringstream ss; + ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png"; + m_Background->FadeToTexture(ss.str(), 1.f); + + glm::vec2 scale = Scale(); + glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection]; + m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f); + glm::vec2 size = m_SelectionSizes[m_CurrentSelection]; + m_TargetSize = size * scale; + } + + // Vehicle select + if (event.Command == "interface_confirm" && event.Value > 0) + { + Events::SpawnVehicle e; + e.PlayerID = m_PlayerID; + if (m_CurrentSelection == 0) + e.VehicleType = "Tank"; // HACK: Base on selected vehicle ID + else if (m_CurrentSelection == 1) + e.VehicleType = "Helicopter"; + else if (m_CurrentSelection == 2) + e.VehicleType = "HRSV"; + else if (m_CurrentSelection == 3) + e.VehicleType = "Jeep"; + EventBroker->Publish(e); + Hide(); + } + + return true; + } }; glm::vec2 VehicleSelection::m_SelectionCoordinates[4] = { diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 57b8dc8..2708b2e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -8,6 +8,22 @@ void GameWorld::Initialize() ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj"); + // Interface + BindKey(GLFW_KEY_A, "interface_horizontal", -1.f); + BindKey(GLFW_KEY_D, "interface_horizontal", 1.f); + BindGamepadAxis(Gamepad::Axis::LeftX, "interface_horizontal", 1.f); + BindGamepadButton(Gamepad::Button::Left, "interface_horizontal", -1.f); + BindGamepadButton(Gamepad::Button::Right, "interface_horizontal", 1.f); + BindKey(GLFW_KEY_W, "interface_vertical", 1.f); + BindKey(GLFW_KEY_S, "interface_vertical", -1.f); + BindGamepadAxis(Gamepad::Axis::LeftY, "interface_vertical", 1.f); + BindGamepadButton(Gamepad::Button::Up, "interface_vertical", 1.f); + BindGamepadButton(Gamepad::Button::Down, "interface_vertical", -1.f); + BindKey(GLFW_KEY_SPACE, "interface_confirm", 1.f); + BindGamepadButton(Gamepad::Button::A, "interface_confirm", 1.f); + + + BindKey(GLFW_KEY_W, "vertical", 1.f); BindKey(GLFW_KEY_S, "vertical", -1.f); BindKey(GLFW_KEY_A, "horizontal", -1.f); @@ -28,6 +44,9 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_Z, "shoot", 1.f); BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f); + BindKey(GLFW_KEY_X, "use", 1.f); + BindGamepadButton(Gamepad::Button::X, "use", 1.f); + BindMouseButton(GLFW_MOUSE_BUTTON_1, "cam_lock", 1.f); BindKey(GLFW_KEY_Y, "cam_vertical", 1.f); BindKey(GLFW_KEY_H, "cam_vertical", -1.f); @@ -80,7 +99,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; auto physics = AddComponent(road_base); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_base); @@ -101,13 +120,15 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj"; auto physics = AddComponent(road_middle); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_middle); auto transformshape = AddComponent(groundshape); auto meshShape = AddComponent(groundshape); meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj"; + + CommitEntity(groundshape); CommitEntity(road_middle); } @@ -120,7 +141,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/SmallRoad.obj"; auto physics = AddComponent(road_small); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_small); @@ -150,8 +171,8 @@ void GameWorld::Initialize() auto physics = AddComponent(water); physics->Mass = 10; - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; { auto groundshape = CreateEntity(water); @@ -184,7 +205,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_middle); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_middle); @@ -215,7 +236,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_small); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_small); @@ -246,7 +267,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_small_mirrored); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_small_mirrored); @@ -277,7 +298,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_base); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_base); @@ -308,7 +329,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_base_mirrored); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_base_mirrored); @@ -322,43 +343,260 @@ void GameWorld::Initialize() } { - /* auto tree = CreateEntity(); + auto tree = CreateEntity(); auto transform = AddComponent(tree); transform->Position = glm::vec3(0, -10, 0); - auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/Stem/Stem.obj"; + auto physics = AddComponent(tree); physics->Mass = 100.f; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionEvent = false; + //physics->LinearDamping = 3.f; physics->CalculateCenterOfMass = true; + { - auto leafs = CreateEntity(tree); - auto transform = AddComponent(leafs); - auto model = AddComponent(leafs); - model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; - model->Transparent = true; - CommitEntity(leafs); + auto stem = CreateEntity(tree); + auto transform = AddComponent(stem); + transform->Position = glm::vec3(0, -2.40906f, 0); + auto model = AddComponent(stem); + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + } + + { + auto leafs = CreateEntity(tree); + auto transform = AddComponent(leafs); + transform->Position = glm::vec3(0, -2.45511f, 0); + auto model = AddComponent(leafs); + model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; + model->Transparent = true; + CommitEntity(leafs); } { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 0.f); + auto mesh = AddComponent(shape); + mesh->ResourceName = "Models/Tree/Collision/Collision.obj"; + + CommitEntity(shape); + } + + + /*{ auto shape = CreateEntity(tree); auto transform = AddComponent(shape); auto box = AddComponent(shape); - transform->Position = glm::vec3(0.f, 0.f, 2.29552f); + transform->Position = glm::vec3(0.f, 0, 0.f); box->Width = 0.296f; box->Height = 2.511f; box->Depth = 0.296f; - } - CommitEntity(tree);*/ + CommitEntity(shape); + } + + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto sphere = AddComponent(shape); + transform->Position = glm::vec3(0, 2.04506f, 0.f); + sphere->Radius = 1.389f; + + CommitEntity(shape); + }*/ + + CommitEntity(tree); + } + +#pragma region Wall_Debris_Template + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(3.43f, 2.287f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris1.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris1.obj"; + + m_WallDebrisTemplates.push_back(debri); + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-3.744f, 1.508f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + m_WallDebrisTemplates.push_back(debri); } - EntityID tank1 = CreateTank(1); + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-3.592f, 4.664f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-2.535f, 2.879f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris3.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris3.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.333f, 3.618f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris4.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris4.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(2.586f, 4.333f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris5.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris5.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.537f, 1.344f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris6.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris6.obj"; + + m_WallDebrisTemplates.push_back(debri); + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.f, 0.f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDestroyed.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->Mass = 200.f; + physics->Restitution = .004f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; //Lägg in ny collision modell + + m_WallDebrisTemplates.push_back(debri); + } +#pragma endregion Region for wall debris + +#pragma region Wall_Regin + + for(int i = 10; i < 0; i++) + { + EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); + } + +#pragma endregion Region for all wall creations + + /*EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); transform->Position.z = 50; - transform->Position.z = 50.f; Events::SetViewportCamera e; e.CameraEntity = GetProperty(tank1, "Camera"); @@ -366,7 +604,7 @@ void GameWorld::Initialize() EventBroker->Publish(e); } - /*EntityID tank2 = CreateTank(2); + EntityID tank2 = CreateTank(2); { auto transform = GetComponent(tank2); transform->Position.x = 10.f; @@ -378,6 +616,8 @@ void GameWorld::Initialize() EventBroker->Publish(e); }*/ + CreateGarage(glm::vec3(-3.93076, -49, 0), 1); + { auto flag = CreateEntity(); auto transform = AddComponent(flag); @@ -434,7 +674,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/Gate/Lift/Lift.obj"; auto physics = AddComponent(gateBase); - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; // Terrain-Layer { auto leftBaseShape = CreateEntity(gateBase); @@ -525,6 +765,7 @@ void GameWorld::RegisterSystems() m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::FollowSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::GarageSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::WallSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); } @@ -547,6 +788,7 @@ void GameWorld::AddSystems() AddSystem(); AddSystem(); AddSystem(); + AddSystem(); AddSystem(); } @@ -586,304 +828,160 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f EventBroker->Publish(e); } -EntityID GameWorld::CreateTank(int playerID) +void GameWorld::CreateGate(glm::vec3 Position) { - auto tank = CreateEntity(); - auto transform = AddComponent(tank); - transform->Position = glm::vec3(0, 5, 0); - //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); - auto physics = AddComponent(tank); - physics->Mass = 63000 - 16000; - physics->Static = false; - auto vehicle = AddComponent(tank); - vehicle->MaxTorque = 36000.f; - vehicle->MaxSteeringAngle = 90.f; - vehicle->MaxSpeedFullSteeringAngle = 4.f; - auto player = AddComponent(tank); - player->ID = playerID; - auto tankSteering = AddComponent(tank); - AddComponent(tank); - auto health = AddComponent(tank); - health->Amount = 100.f; + { + auto gateBase = CreateEntity(); + auto transform = AddComponent(gateBase); + transform->Position = Position; + auto model = AddComponent(gateBase); + model->ModelFile = "Models/Gate/Lift/Lift.obj"; + auto physics = AddComponent(gateBase); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - { - auto shape = CreateEntity(tank); - auto transform = AddComponent(shape); - auto meshShape = AddComponent(shape); - meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj"; - CommitEntity(shape); - } - { - auto shapeTower = CreateEntity(tank); - auto transform = AddComponent(shapeTower); - transform->Position = glm::vec3(0, 1.10633f, 1.03024f); - auto box = AddComponent(shapeTower); - box->Width = 1.298f; - box->Height = 0.502f; - box->Depth = 1.211f; - CommitEntity(shapeTower); - } - - { - auto chassis = CreateEntity(tank); - auto transform = AddComponent(chassis); - transform->Position = glm::vec3(0, 0, 0); - auto model = AddComponent(chassis); - model->ModelFile = "Models/Tank/tankBody.obj"; - } - { - auto tower = CreateEntity(tank); - SetProperty(tower, "Name", "tower"); - auto transform = AddComponent(tower); - transform->Position = glm::vec3(0.f, 0.68f, 0.9f); - auto model = AddComponent(tower); - model->ModelFile = "Models/Tank/tankTop.obj"; - auto towerSteering = AddComponent(tower); - towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); - towerSteering->TurnSpeed = glm::pi() / 4.f; { - auto barrel = CreateEntity(tower); - auto transform = AddComponent(barrel); - transform->Position = glm::vec3(-0.012f, 0.4f, -0.75); - auto model = AddComponent(barrel); - model->ModelFile = "Models/Tank/tankBarrel.obj"; - auto barrelSteering = AddComponent(barrel); - barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); - barrelSteering->TurnSpeed = glm::pi() / 4.f; - barrelSteering->ShotSpeed = 70.f; - barrelSteering->LowerRotationLimit = glm::radians(-10.f); - barrelSteering->UpperRotationLimit = glm::radians(40.f); - - { - auto shot = CreateEntity(barrel); - auto transform = AddComponent(shot); - transform->Position = glm::vec3(0.35f, 0.f, -2.f); - transform->Orientation = glm::angleAxis(-glm::pi() / 2.f, glm::vec3(1, 0, 0)); - transform->Scale = glm::vec3(3.f); - AddComponent(shot); - auto soundEmitter = AddComponent(tank); - soundEmitter->MinDistance = 1000; - soundEmitter->Gain = 1; - soundEmitter->Loop = false; - - auto physics = AddComponent(shot); - physics->Mass = 25.f; - physics->Static = false; - physics->CollisionEvent = true; - auto modelComponent = AddComponent(shot); - modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; - auto tankShellComponent = AddComponent(shot); - tankShellComponent->Damage = 20.f; - tankShellComponent->ExplosionRadius = 30.f; - tankShellComponent->ExplosionStrength = 300000.f; - { - auto shape = CreateEntity(shot); - auto transform = AddComponent(shape); - auto boxShape = AddComponent(shape); - boxShape->Width = 0.5f; - boxShape->Height = 0.5f; - boxShape->Depth = 0.5f; - CommitEntity(shape); - } - CommitEntity(shot); - barrelSteering->ShotTemplate = shot; - - - auto cameraTower = CreateEntity(barrel); - { - auto transform = AddComponent(cameraTower); - transform->Position.z = 16.f; - transform->Position.y = 4.f; - transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f)); - auto cameraComp = AddComponent(cameraTower); - cameraComp->FarClip = 2000.f; - /*auto follow = AddComponent(cameraTower); - follow->Entity = barrel; - follow->Distance = 15.f; - follow->FollowAxis = glm::vec3(1, 1, 1);*/ - } - - SetProperty(tank, "Camera", cameraTower); - } - CommitEntity(barrel); - tankSteering->Barrel = barrel; + auto leftBaseShape = CreateEntity(gateBase); + auto transform = AddComponent(leftBaseShape); + transform->Position = glm::vec3(8.5f, 3, 0); + auto box = AddComponent(leftBaseShape); + box->Width = 3.f/2; + box->Height = 6.094f/2; + box->Depth = 4.f/2; + CommitEntity(leftBaseShape); + } + { + auto RightBaseShape = CreateEntity(gateBase); + auto transform = AddComponent(RightBaseShape); + transform->Position = glm::vec3(-8.5f, 3, 0); + auto box = AddComponent(RightBaseShape); + box->Width = 3.f/2; + box->Height = 6.094f/2; + box->Depth = 4.f/2; + CommitEntity(RightBaseShape); + } + { + auto LeftTopShape = CreateEntity(gateBase); + auto transform = AddComponent(LeftTopShape); + transform->Position = glm::vec3(7.5485f, 9.385f, 0); + auto box = AddComponent(LeftTopShape); + box->Width = 1.747f/2; + box->Height = 6.851f/2; + box->Depth = 1.767f/2; + CommitEntity(LeftTopShape); } - CommitEntity(tower); - tankSteering->Turret = tower; - - + { + auto RightTopShape = CreateEntity(gateBase); + auto transform = AddComponent(RightTopShape); + transform->Position = glm::vec3(-7.5485f, 9.385f, 0); + auto box = AddComponent(RightTopShape); + box->Width = 1.747f/2; + box->Height = 6.851f/2; + box->Depth = 1.767f/2; + CommitEntity(RightTopShape); + } + { + auto RampShape = CreateEntity(gateBase); + auto transform = AddComponent(RampShape); + transform->Position = glm::vec3(0, 0.24f, 0); + auto mesh = AddComponent(RampShape); + mesh->ResourceName = "Models/Gate/Lift/RampCollision.obj"; + CommitEntity(RampShape); + } + CommitEntity(gateBase); } + { + auto gate = CreateEntity(); + auto transform = AddComponent(gate); + transform->Position = Position; + auto model = AddComponent(gate); + model->ModelFile = "Models/Gate/Gate/Gate.obj"; + auto physics = AddComponent(gate); + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto move = AddComponent(gate); + move->Speed = 5.f; + move->GoalPosition = glm::vec3(Position.x, Position.y + 9.02345f, Position.z); + move->StartPosition = glm::vec3(Position.x, Position.y, Position.z); + { + auto mainShape = CreateEntity(gate); + auto transform = AddComponent(mainShape); + transform->Position = glm::vec3(0.f, 3.09776f, 0.f); + auto box = AddComponent(mainShape); + box->Width = 6.963f; + box->Height = 2.478f; + box->Depth = 0.522f; + CommitEntity(mainShape); + } + { + auto lowerShape = CreateEntity(gate); + auto transform = AddComponent(lowerShape); + transform->Position = glm::vec3(0.f, 0.35f, 0.f); + auto box = AddComponent(lowerShape); + box->Width = 6.963f; + box->Height = 0.308f; + box->Depth = 0.222f; + CommitEntity(lowerShape); + } + CommitEntity(gate); + + { + auto gateTrigger = CreateEntity(); + auto transform = AddComponent(gateTrigger); + transform->Position = glm::vec3(Position.x, Position.y + 2.8241, Position.z); + auto trigger = AddComponent(gateTrigger); + auto triggerMove = AddComponent(gateTrigger); + triggerMove->Entity = gate; - //{ - // auto lightentity = CreateEntity(tank); - // auto transform = AddComponent(lightentity); - // transform->Position = glm::vec3(0, 0, 0); - // auto light = AddComponent(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 shape = CreateEntity(gateTrigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0.f, 2.8241f, 0.f); + auto box = AddComponent(shape); + box->Width = 6.963f; + box->Height = 3.104f; + box->Depth = 10.356f; + CommitEntity(shape); + } + CommitEntity(gateTrigger); + } - // auto wheelpair = CreateEntity(tank); - // SetProperty(wheelpair, "Name", "WheelPair"); - // AddComponent(wheelpair, "WheelPairThingy"); - -#pragma region Wheels - //Create wheels - float wheelOffset = -0.83f; - const float suspensionStrength = 15.f; - const float springLength = 0.3f; - - AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, -1.715f), 0, true); - AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, -1.715f), 0, true); - AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, 2.375), 1, false); - AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false); -#pragma endregion - - -// auto entity = CreateEntity(tank); -// auto transformComponent = AddComponent(entity); -// transformComponent->Position = glm::vec3(2, -1.7, 2.0); -// transformComponent->Scale = glm::vec3(3, 3, 3); -// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); -// auto emitterComponent = AddComponent(entity); -// emitterComponent->SpawnCount = 2; -// emitterComponent->SpawnFrequency = 0.005; -// emitterComponent->SpreadAngle = glm::pi(); -// emitterComponent->UseGoalVelocity = false; -// emitterComponent->LifeTime = 0.5; -// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); -// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); -// CommitEntity(entity); -// -// { -// auto particleEntity = CreateEntity(entity); -// auto templateComponent = AddComponent(particleEntity); -// auto TEMP = AddComponent(particleEntity); -// TEMP->Scale = glm::vec3(0); -// auto spriteComponent = AddComponent(particleEntity); -// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; -// CommitEntity(particleEntity); -// emitterComponent->ParticleTemplate = particleEntity; -// } - - CommitEntity(tank); - - return tank; + } } -void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front) +EntityID GameWorld::CreateWall(glm::vec3 pos, glm::quat orientation) { - const float separation = 1.77f; - const float suspensionStrength = 15.f; - const float springLength = 0.3f; + auto wall = CreateEntity(); + auto transform = AddComponent(wall); + transform->Position = pos; + transform->Orientation = orientation; - bool steering = front; + auto physics = AddComponent(wall); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - auto wheelFront = CreateEntity(tankEntity); - { - auto transform = AddComponent(wheelFront); - transform->Position = position - glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); - //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); -#ifdef DEBUG - auto model = AddComponent(wheelFront); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; -#endif - auto Wheel = AddComponent(wheelFront); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = axleID; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = steering; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheelFront); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheelFront); - } + auto walldebris = AddComponent(wall); + walldebris->Walldebris = m_WallDebrisTemplates; - auto wheelBack = CreateEntity(tankEntity); - { - auto transform = AddComponent(wheelBack); - transform->Position = position + glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); - //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); -#ifdef DEBUG - auto model = AddComponent(wheelBack); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; -#endif - auto Wheel = AddComponent(wheelBack); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = axleID; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = steering; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheelBack); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheelBack); - } + auto model = AddComponent(wall); + model->ModelFile = "Models/Wall/WallWhole/Wall.obj"; - auto wheelPair = CreateEntity(tankEntity); - { - { - auto transform = AddComponent(wheelPair); - transform->Position = position; - //transform->Orientation = glm::quat(glm::vec3(0, glm::pi() / 4.f, 0)); + auto health = AddComponent(wall); + health->Amount = 50.f; - auto pair = AddComponent(wheelPair); - pair->FakeWheelFront = wheelFront; - pair->FakeWheelBack = wheelBack; - } + auto shape = CreateEntity(wall); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallCollision/Collision.obj"; - auto modelEntity = CreateEntity(wheelPair); - { - auto transform = AddComponent(modelEntity); - //transform->Position = glm::vec3(0.f, 0.35f, 0.f); - if (front) - { - transform->Position = glm::vec3(0.f, 0.03f, 0.f); - transform->Orientation = glm::quat(glm::vec3(0, glm::pi(), 0)); - } - else - { - transform->Position = glm::vec3(0.f, 0.17f, 0.f); - transform->Scale = glm::vec3(1.f, 1.2f, 1.2f); - } + CommitEntity(shape); + CommitEntity(wall); + + return wall; - auto model = AddComponent(modelEntity); - model->ModelFile = "Models/Tank/tankWheel.obj"; - } - CommitEntity(modelEntity); - } - CommitEntity(wheelPair); } EntityID GameWorld::CreateJeep(int playerID) @@ -894,7 +992,7 @@ EntityID GameWorld::CreateJeep(int playerID) transform->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(0, 1, 0)); auto physics = AddComponent(jeep); physics->Mass = 1800; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; auto vehicle = AddComponent(jeep); vehicle->DownshiftRPM = 3500.f; vehicle->UpshiftRPM = 6000.f; @@ -921,16 +1019,6 @@ EntityID GameWorld::CreateJeep(int playerID) model->ModelFile = "Models/Jeep/Chassi/chassi.obj"; } - { - auto lightentity = CreateEntity(jeep); - auto transform = AddComponent(lightentity); - transform->Position = glm::vec3(0, 15, 0); - auto light = AddComponent(lightentity); - light->Diffuse = glm::vec3(128.f / 255.f, 172.f / 255.f, 242.f / 255.f); - light->Specular = glm::vec3(1.f); - } - - //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; @@ -1015,3 +1103,174 @@ EntityID GameWorld::CreateJeep(int playerID) return jeep; } + +EntityID GameWorld::CreateGarage(glm::vec3 Position, int playerID) +{ + auto garage = CreateEntity(); + auto transform = AddComponent(garage); + transform->Position = Position; + auto player = AddComponent(garage); + player->ID = playerID; + + auto ElevatorBase = CreateEntity(garage); + { + auto transform = AddComponent(ElevatorBase); + auto model = AddComponent(ElevatorBase); + model->ModelFile = "Models/SpawnRamp/Main/Main.obj"; + auto physics = AddComponent(ElevatorBase); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + + { + auto mainShape = CreateEntity(ElevatorBase); + auto transform = AddComponent(mainShape); + transform->Position = glm::vec3(0.f, 0, 0.f); + auto mesh = AddComponent(mainShape); + mesh->ResourceName = "Models/SpawnRamp/Main/CollisionShape.obj"; + CommitEntity(mainShape); + } + { + auto StairsShape = CreateEntity(ElevatorBase); + auto transform = AddComponent(StairsShape); + transform->Position = glm::vec3(-7.48639f, 0.4809f, 3.79166f); + auto box = AddComponent(StairsShape); + box->Width = 1.211f; + box->Height = 1.798f; + box->Depth = 3.229f; + CommitEntity(StairsShape); + } + } + CommitEntity(ElevatorBase); + + auto leftHatch = CreateEntity(garage); + { + auto transform = AddComponent(leftHatch); + transform->Position = glm::vec3(5.83103f, 1.3553f, -2.40268f); + auto model = AddComponent(leftHatch); + model->ModelFile = "Models/SpawnRamp/LeftHatch/LeftHatch.obj"; + auto physics = AddComponent(leftHatch); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto rotate = AddComponent(leftHatch); + rotate->StartRotation = transform->Orientation; + rotate->GoalRotation = transform->Orientation * glm::angleAxis(-glm::radians(110.f), glm::vec3(0, 0, 1)); + rotate->Time = 5.f; + { + auto shape = CreateEntity(leftHatch); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(-2.79331, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.317f; + box->Height = 0.183f; + box->Depth = 6.987f; + CommitEntity(shape); + } + CommitEntity(leftHatch); + } + + auto rightHatch = CreateEntity(garage); + { + auto transform = AddComponent(rightHatch); + transform->Position = glm::vec3(-4.52423f, 1.3553f, -2.40268f); + auto model = AddComponent(rightHatch); + model->ModelFile = "Models/SpawnRamp/RightHatch/RightHatch.obj"; + auto physics = AddComponent(rightHatch); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto rotate = AddComponent(rightHatch); + rotate->StartRotation = transform->Orientation; + rotate->GoalRotation = transform->Orientation * glm::angleAxis(glm::radians(110.f), glm::vec3(0, 0, 1)); + rotate->Time = 5.f; + { + auto shape = CreateEntity(rightHatch); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(2.79331, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.317f; + box->Height = 0.183f; + box->Depth = 6.987f; + CommitEntity(shape); + } + CommitEntity(rightHatch); + } + + auto elevator = CreateEntity(garage); + { + auto transform = AddComponent(elevator); + transform->Position = glm::vec3(0.69385f, 1.25222f, -2.39938f) + glm::vec3(0, -9.5f, 0); + auto model = AddComponent(elevator); + model->ModelFile = "Models/SpawnRamp/Elevator/Elevator.obj"; + auto physics = AddComponent(elevator); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto move = AddComponent(elevator); + move->StartPosition = transform->Position; + move->GoalPosition = transform->Position + glm::vec3(0, 9.5f, 0); + move->Speed = 1.5f; + { + auto shape = CreateEntity(elevator); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 4.754f; + box->Height = 0.141f; + box->Depth = 6.86f; + CommitEntity(shape); + } + + auto spawnPoint = CreateEntity(elevator); + { + auto transform = AddComponent(spawnPoint); + transform->Position.y = 1.f; + auto spawnPointComponent = AddComponent(spawnPoint); + } + CommitEntity(spawnPoint); + } + CommitEntity(elevator); + + auto garageComponent = AddComponent(garage); + garageComponent->DoorLeft = leftHatch; + garageComponent->DoorRight = rightHatch; + garageComponent->Elevator = elevator; + CommitEntity(garage); + + { + auto trigger = CreateEntity(garage); + SetProperty(trigger, "Name", "BoundsTrigger"); + auto transform = AddComponent(trigger); + transform->Position = glm::vec3(0, 44.87521f, 0); + auto triggerComponent = AddComponent(trigger); + { + auto shape = CreateEntity(trigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 72.98f; + box->Height = 54.53f; + box->Depth = 72.98f; + CommitEntity(shape); + } + CommitEntity(trigger); + } + + { + auto trigger = CreateEntity(garage); + SetProperty(trigger, "Name", "ElevatorShaftTrigger"); + auto transform = AddComponent(trigger); + transform->Position = glm::vec3(0.69385f, -6.7997f, -2.0f); + auto triggerComponent = AddComponent(trigger); + { + auto shape = CreateEntity(trigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.0f; + box->Height = 12.f; + box->Depth = 2.0f; + CommitEntity(shape); + } + CommitEntity(trigger); + } + + return garage; +} \ No newline at end of file diff --git a/src/GameWorld.h b/src/GameWorld.h index 1ca7de7..52bdb91 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -22,6 +22,7 @@ #include "Systems/DamageSystem.h" #include "Systems/WheelPairSystem.h" #include "Systems/FollowSystem.h" +#include "Systems/WallSystem.h" #include "Systems/GarageSystem.h" #include "Components/Camera.h" @@ -77,10 +78,12 @@ private: void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value); void BindGamepadButton(Gamepad::Button button, std::string command, float value); - EntityID CreateTank(int playerID); void CreateGate(glm::vec3 Position); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); EntityID CreateJeep(int playerID); + EntityID CreateWall(glm::vec3 pos, glm::quat orientation); + EntityID CreateGarage(glm::vec3 Position, int playerID); + std::vector m_WallDebrisTemplates; }; #endif // GameWorld_h__ diff --git a/src/Model.cpp b/src/Model.cpp index dd5757c..1186671 100755 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -93,7 +93,7 @@ Model::Model(std::shared_ptr rm, OBJ &obj) if (Vertices.size() > 0) { CreateTangents(); - getSimilarVertexIndex(); + //getSimilarVertexIndex(); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); } else diff --git a/src/Renderer.cpp b/src/Renderer.cpp index ff01e67..480e3dd 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -377,9 +377,9 @@ void Renderer::DrawWorld(RenderQueuePair &rq) for(auto job : rq.Forward) { glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); - glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + glm::mat4 cameraMatrix = m_Camera->ViewMatrix(); - glm::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); + glm::vec3 spritePos = glm::vec3((cameraMatrix * job->ModelMatrix) * glm::vec4(1, 1, 1, 1)); job->Depth = spritePos.z; } rq.Forward.Jobs.sort(Renderer::DepthSort); @@ -389,7 +389,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) /* Base pass */ - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); //glViewport(0, 0, m_Width, m_Height); @@ -475,10 +475,10 @@ void Renderer::ForwardRendering(RenderQueue &rq) glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); // Clear G-buffer - GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE , GL_NONE }; glDrawBuffers(4, attachments); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); + //glClearColor(0.f, 0.f, 0.f, 1.f); + //glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -512,23 +512,21 @@ void Renderer::ForwardRendering(RenderQueue &rq) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); - if (modelJob->NormalTexture != 0) + /*if (modelJob->NormalTexture != 0) { - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); } if (modelJob->SpecularTexture) { - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); - } + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); + }*/ glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); continue; } - - auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { @@ -559,9 +557,9 @@ void Renderer::ForwardRendering(RenderQueue &rq) glViewport(0, 0, m_Width, m_Height); glScissor(0, 0, m_Width, m_Height); + glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_BLEND); m_FinalForwardPassProgram.Bind(); //ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle(); @@ -947,7 +945,7 @@ void Renderer::FrameBufferTextures() //Generate and bind diffuse texture glGenTextures(1, &m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); diff --git a/src/Renderer.h b/src/Renderer.h index 7a1c214..2efdb57 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -219,7 +219,7 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth > j->Depth); } + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } GLuint CreateQuad(); void DrawDebugShadowMap(); diff --git a/src/Systems/DamageSystem.cpp b/src/Systems/DamageSystem.cpp index 55117dd..f894fd2 100644 --- a/src/Systems/DamageSystem.cpp +++ b/src/Systems/DamageSystem.cpp @@ -1,7 +1,6 @@ #include "PrecompiledHeader.h" #include "DamageSystem.h" #include "World.h" - void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf ) { cf->Register([]() { return new Components::Health(); }); @@ -15,8 +14,16 @@ void Systems::DamageSystem::Initialize() bool Systems::DamageSystem::OnDamage( const Events::Damage &event ) { + if(!m_World->ValidEntity(event.Entity)) + return false; auto health = m_World->GetComponent(event.Entity); health->Amount -= event.Amount; + if(health->Amount <= 0) + { + Events::OnDead e; + e.Entity = event.Entity; + EventBroker->Publish(e); + } LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount); return true; } \ No newline at end of file diff --git a/src/Systems/DamageSystem.h b/src/Systems/DamageSystem.h index 5b81f17..a77a600 100644 --- a/src/Systems/DamageSystem.h +++ b/src/Systems/DamageSystem.h @@ -5,6 +5,7 @@ #include "System.h" #include "Components/Health.h" #include "Events/Damage.h" +#include "Events/OnDead.h" namespace Systems { diff --git a/src/Systems/GarageSystem.cpp b/src/Systems/GarageSystem.cpp index 2e8cc4f..d019b27 100644 --- a/src/Systems/GarageSystem.cpp +++ b/src/Systems/GarageSystem.cpp @@ -5,12 +5,14 @@ void Systems::GarageSystem::RegisterComponents( ComponentFactory* cf ) { cf->Register([]() { return new Components::Garage(); }); + cf->Register([]() { return new Components::SpawnPoint(); }); } void Systems::GarageSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EEnterTrigger, &Systems::GarageSystem::OnEnterTrigger); EVENT_SUBSCRIBE_MEMBER(m_ELeaveTrigger, &Systems::GarageSystem::OnLeaveTrigger); + EVENT_SUBSCRIBE_MEMBER(m_ECommand, &Systems::GarageSystem::OnCommand); } void Systems::GarageSystem::Update(double dt) @@ -34,11 +36,13 @@ bool Systems::GarageSystem::OnEnterTrigger(const Events::EnterTrigger &event) std::string name = m_World->GetProperty(event.Trigger, "Name"); - if (name == "BoundsTrigger" || name == "ElevatorShaftTrigger") + if (name == "BoundsTrigger") { ToggleGarage(garageComponent); } + m_EntitiesInTrigger[event.Trigger].insert(event.Entity); + return true; } @@ -59,6 +63,40 @@ bool Systems::GarageSystem::OnLeaveTrigger(const Events::LeaveTrigger &event) ToggleGarage(garageComponent); } + m_EntitiesInTrigger[event.Trigger].erase(event.Entity); + + return true; +} + +bool Systems::GarageSystem::OnCommand(const Events::InputCommand &event) +{ + if (event.Command == "use" && event.Value > 0) + { + for (auto &pair : m_EntitiesInTrigger) + { + EntityID trigger = pair.first; + auto entities = pair.second; + + std::string name = m_World->GetProperty(trigger, "Name"); + if (name != "ElevatorShaftTrigger") + continue; + + auto triggerBaseParent = m_World->GetEntityBaseParent(trigger); + auto triggerPlayerComponent = m_World->GetComponent(triggerBaseParent); + + for (EntityID entity : entities) + { + auto entityPlayerComponent = m_World->GetComponent(triggerBaseParent); + if (triggerPlayerComponent == entityPlayerComponent) + { + EntityID garage = m_World->GetEntityParent(trigger); + auto garageComponent = m_World->GetComponent(garage); + ToggleGarage(garageComponent); + } + } + } + } + return true; } diff --git a/src/Systems/GarageSystem.h b/src/Systems/GarageSystem.h index a4078ce..aca5673 100644 --- a/src/Systems/GarageSystem.h +++ b/src/Systems/GarageSystem.h @@ -1,13 +1,17 @@ #ifndef GarageSystem_h__ #define GarageSystem_h__ +#include #include "System.h" #include "Components/Transform.h" #include "Components/Trigger.h" #include "Components/Garage.h" +#include "Components/SpawnPoint.h" #include "Events/EnterTrigger.h" #include "Events/LeaveTrigger.h" +#include "Events/SpawnVehicle.h" +#include "Events/InputCommand.h" #include "Components/Player.h" #include "Events/Move.h" @@ -30,12 +34,17 @@ namespace Systems void UpdateEntity(double dt, EntityID entity, EntityID parent) override; private: + std::map> m_EntitiesInTrigger; + EventRelay m_EEnterTrigger; bool OnEnterTrigger(const Events::EnterTrigger &event); EventRelay m_ELeaveTrigger; bool OnLeaveTrigger(const Events::LeaveTrigger &event); + EventRelay m_ECommand; + bool OnCommand(const Events::InputCommand &event); void ToggleGarage(Components::Garage* garageComponent); + }; } diff --git a/src/Systems/InputSystem.cpp b/src/Systems/InputSystem.cpp index 81a52dd..733c3bc 100755 --- a/src/Systems/InputSystem.cpp +++ b/src/Systems/InputSystem.cpp @@ -46,8 +46,8 @@ void Systems::InputSystem::Update(double dt) bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event) { - auto bindingIt = m_KeyBindings.find(event.KeyCode); - if (bindingIt != m_KeyBindings.end()) + auto range = m_KeyBindings.equal_range(event.KeyCode); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -61,8 +61,8 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event) bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event) { - auto bindingIt = m_KeyBindings.find(event.KeyCode); - if (bindingIt != m_KeyBindings.end()) + auto range = m_KeyBindings.equal_range(event.KeyCode); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -76,8 +76,8 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event) bool Systems::InputSystem::OnMousePress(const Events::MousePress &event) { - auto bindingIt = m_MouseButtonBindings.find(event.Button); - if (bindingIt != m_MouseButtonBindings.end()) + auto range = m_MouseButtonBindings.equal_range(event.Button); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -91,8 +91,8 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event) bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event) { - auto bindingIt = m_MouseButtonBindings.find(event.Button); - if (bindingIt != m_MouseButtonBindings.end()) + auto range = m_MouseButtonBindings.equal_range(event.Button); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -106,8 +106,8 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event) bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event) { - auto bindingIt = m_GamepadAxisBindings.find(event.Axis); - if (bindingIt != m_GamepadAxisBindings.end()) + auto range = m_GamepadAxisBindings.equal_range(event.Axis); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -121,8 +121,8 @@ bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event) bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event) { - auto bindingIt = m_GamepadButtonBindings.find(event.Button); - if (bindingIt != m_GamepadButtonBindings.end()) + auto range = m_GamepadButtonBindings.equal_range(event.Button); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -136,8 +136,8 @@ bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown & bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event) { - auto bindingIt = m_GamepadButtonBindings.find(event.Button); - if (bindingIt != m_GamepadButtonBindings.end()) + auto range = m_GamepadButtonBindings.equal_range(event.Button); + for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) { std::string command; float value; @@ -149,18 +149,13 @@ bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &even return true; } - bool Systems::InputSystem::OnBindKey(const Events::BindKey &event) { if (event.Command.empty()) - { - m_KeyBindings.erase(event.KeyCode); - } - else - { - m_KeyBindings[event.KeyCode] = std::make_tuple(event.Command, event.Value); - LOG_DEBUG("Input: Bound key %i:%c to %s", event.KeyCode, (char)event.KeyCode, event.Command.c_str()); - } + return false; + + m_KeyBindings.insert(std::make_pair(event.KeyCode, std::make_tuple(event.Command, event.Value))); + LOG_DEBUG("Input: Bound key %i to %s", event.KeyCode, event.Command.c_str()); return true; } @@ -168,14 +163,10 @@ bool Systems::InputSystem::OnBindKey(const Events::BindKey &event) bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &event) { if (event.Command.empty()) - { - m_MouseButtonBindings.erase(event.Button); - } - else - { - m_MouseButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value); - LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str()); - } + return false; + + m_MouseButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value))); + LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str()); return true; } @@ -183,14 +174,10 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event) { if (event.Command.empty()) - { - m_GamepadAxisBindings.erase(event.Axis); - } - else - { - m_GamepadAxisBindings[event.Axis] = std::make_tuple(event.Command, event.Value); - LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str()); - } + return false; + + m_GamepadAxisBindings.insert(std::make_pair(event.Axis, std::make_tuple(event.Command, event.Value))); + LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str()); return true; } @@ -198,14 +185,10 @@ bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &even bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event) { if (event.Command.empty()) - { - m_GamepadButtonBindings.erase(event.Button); - } - else - { - m_GamepadButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value); - LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str()); - } + return false; + + m_GamepadButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value))); + LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str()); return true; } diff --git a/src/Systems/InputSystem.h b/src/Systems/InputSystem.h index 5a193a6..7e0330b 100755 --- a/src/Systems/InputSystem.h +++ b/src/Systems/InputSystem.h @@ -40,10 +40,10 @@ private: std::unordered_map> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command std::unordered_map> m_CommandGamepadButtonValues; // command string -> gamepad button value for command // Input binding tables - std::unordered_map> m_KeyBindings; // GLFW_KEY... -> command string & value - std::unordered_map> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string - std::unordered_map> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value - std::unordered_map> m_GamepadButtonBindings; // Gamepad::Button -> command string + std::unordered_multimap> m_KeyBindings; // GLFW_KEY... -> command string & value + std::unordered_multimap> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string + std::unordered_multimap> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value + std::unordered_multimap> m_GamepadButtonBindings; // Gamepad::Button -> command string // Input events EventRelay m_EKeyDown; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index d147dcd..cba6c39 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -80,7 +80,7 @@ void Systems::PhysicsSystem::Initialize() worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // You must specify the size of the broad phase - objects should not be simulated outside this region - worldInfo.setBroadPhaseWorldSize(1500.0f); + worldInfo.setBroadPhaseWorldSize(500.0f); m_PhysicsWorld = new hkpWorld(worldInfo); // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks @@ -151,6 +151,10 @@ void Systems::PhysicsSystem::Update(double dt) EntityID entity = pair.first; EntityID parent = pair.second; + auto templateComponent = m_World->GetComponent(entity); + if(templateComponent) + continue; + if (m_RigidBodies.find(entity) == m_RigidBodies.end()) continue; @@ -218,6 +222,10 @@ void Systems::PhysicsSystem::Update(double dt) void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { + auto templateComponent = m_World->GetComponent(entity); + if(templateComponent) + return; + auto transformComponent = m_World->GetComponent(entity); if (!transformComponent) return; @@ -229,6 +237,19 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p if(m_Vehicles.find(car) != m_Vehicles.end()) { m_PhysicsWorld->markForWrite(); + + /*auto player = m_World->GetComponent(car); + if(player) + { + if(player->ID == 1) + { + LOG_INFO("Speed: %f, Gear: %i, RPM: %f", m_Vehicles[car]->calcKMPH(), m_Vehicles[car]->m_currentGear, m_Vehicles[car]->m_rpm); + + } + }*/ + + + m_Vehicles[car]->getChassis()->activate(); hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace; @@ -297,14 +318,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) auto physicsComponent = m_World->GetComponent(entity); if (physicsComponent && m_Shapes[entity].size() > 0) { - if(entityParent != 0 && !physicsComponent->Static) + if(entityParent != 0 && physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic) { LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity); return; } hkpShape* shape; - if(! physicsComponent->Static) // Not static + if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic) { hkArray shapeArray; for (auto &shapeData : m_Shapes[entity]) @@ -368,6 +389,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; if(physicsComponent->CalculateCenterOfMass) physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass); + rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass); rigidBodyInfo.m_mass = massProperties.m_mass; rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity); @@ -381,7 +403,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true;; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -400,7 +422,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } } - VehicleSetup vehicleSetup; // Create the basic vehicle. m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]); @@ -438,7 +459,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBody->removeReference(); } } - else // Static + else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed || physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed) { // Create the hkpStaticCompoundShape and add the instances. // "meshShape" should not be modified by the user in any way after adding it as an instance. @@ -490,7 +511,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) hkpRigidBodyCinfo rigidBodyInfo; { rigidBodyInfo.m_shape = shape; - rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED; + if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed) + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; + } + else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed) + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED; + } + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); @@ -513,7 +542,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -621,6 +650,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) std::vector* vertices = new std::vector; std::vector* vertexIndices = new std::vector; auto meshShape = ResourceManager->Load("OBJ", meshShapeComponent->ResourceName); + if(!meshShape) + return; for (auto &vertex : meshShape->Vertices) { @@ -732,7 +763,7 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) } else { - deviceStatus->m_positionX = steeringX; + deviceStatus->m_positionX = event.PositionX; deviceStatus->m_positionY = event.PositionY; } @@ -752,6 +783,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) { m_PhysicsWorld->markForWrite(); + m_RigidBodies[event.Entity]->activate(); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); auto transformComponent = m_World->GetComponent(event.Entity); transformComponent->Velocity = event.Velocity; @@ -795,7 +827,6 @@ void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string typ m_RigidBodies.erase(entity); m_PhysicsWorld->unmarkForWrite(); } - } diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index a14481b..a1df46a 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -23,6 +23,7 @@ #include "Components/HingeConstraint.h" #include "Components/WheelPair.h" #include "Components/TowerSteering.h" +#include "Components/Player.h" #include "Events/TankSteer.h" #include "Events/SetVelocity.h" #include "Events/ApplyForce.h" diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 2836e74..43fcc17 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -2,7 +2,7 @@ #include "TankSteeringSystem.h" #include "World.h" -void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf ) +void Systems::TankSteeringSystem::RegisterComponents(ComponentFactory* cf) { cf->Register([]() { return new Components::TankSteering(); }); cf->Register([]() { return new Components::TowerSteering(); }); @@ -12,6 +12,7 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf ) void Systems::TankSteeringSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TankSteeringSystem::OnCollision); + EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::TankSteeringSystem::OnSpawnVehicle); for (int i = 0; i < 4; i++) { @@ -124,7 +125,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit // } } -bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) +bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) { if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity2)) { @@ -152,6 +153,9 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) return false; } + if(m_World->GetComponent(shellEntity)) + return false; + auto physicsComponents = m_World->GetComponentsOfType(); auto shellTransform = m_World->GetComponent(shellEntity); //auto otherTransform = m_World->GetComponent(otherEntity); @@ -218,8 +222,6 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) EventBroker->Publish(d); } - - m_World->RemoveEntity(shellEntity); } } @@ -300,6 +302,319 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) return true; } +bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event) +{ + if (event.VehicleType != "Tank") + return false; + + auto spawnPointComponents = m_World->GetComponentsOfType(); + if (!spawnPointComponents) + { + LOG_ERROR("Found no spawn points!"); + return false; + } + + for (auto &spawnPointComponent : *spawnPointComponents) + { + auto spawnPoint = spawnPointComponent->Entity; + auto spawnPointBaseParent = m_World->GetEntityBaseParent(spawnPoint); + auto playerComponent = m_World->GetComponent(spawnPointBaseParent); + if (!playerComponent || playerComponent->ID != event.PlayerID) + continue; + + Components::Transform absoluteTransform = m_World->GetSystem()->AbsoluteTransform(spawnPoint); + + // Create a tank + EntityID tank = CreateTank(event.PlayerID); + auto tankTransform = m_World->GetComponent(tank); + tankTransform->Position = absoluteTransform.Position; + tankTransform->Orientation = absoluteTransform.Orientation; + // Set the viewport correctly + Events::SetViewportCamera e; + e.CameraEntity = m_World->GetProperty(tank, "Camera"); + if (event.PlayerID == 1) + e.ViewportFrame = "Viewport1"; + else if (event.PlayerID == 2) + e.ViewportFrame = "Viewport2"; + EventBroker->Publish(e); + } + + return true; +} + +EntityID Systems::TankSteeringSystem::CreateTank(int playerID) +{ + auto tank = m_World->CreateEntity(); + auto transform = m_World->AddComponent(tank); + transform->Position = glm::vec3(0, 5, 0); + //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); + auto physics = m_World->AddComponent(tank); + physics->Mass = 63000 - 16000; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + auto vehicle = m_World->AddComponent(tank); + vehicle->MaxTorque = 8000.f; + vehicle->MaxSteeringAngle = 90.f; + vehicle->MaxSpeedFullSteeringAngle = 4.f; + auto player = m_World->AddComponent(tank); + player->ID = playerID; + auto tankSteering = m_World->AddComponent(tank); + m_World->AddComponent(tank); + auto health = m_World->AddComponent(tank); + health->Amount = 100.f; + + { + auto shape = m_World->CreateEntity(tank); + auto transform = m_World->AddComponent(shape); + auto meshShape = m_World->AddComponent(shape); + meshShape->ResourceName = "Models/Tank/TankCollisionShape.obj"; + m_World->CommitEntity(shape); + } + { + auto shapeTower = m_World->CreateEntity(tank); + auto transform = m_World->AddComponent(shapeTower); + transform->Position = glm::vec3(0, 1.10633f, 1.03024f); + auto box = m_World->AddComponent(shapeTower); + box->Width = 1.298f; + box->Height = 0.502f; + box->Depth = 1.211f; + m_World->CommitEntity(shapeTower); + } + + { + auto chassis = m_World->CreateEntity(tank); + auto transform = m_World->AddComponent(chassis); + transform->Position = glm::vec3(0, 0, 0); + auto model = m_World->AddComponent(chassis); + model->ModelFile = "Models/Tank/tankBody.obj"; + } + { + auto tower = m_World->CreateEntity(tank); + m_World->SetProperty(tower, "Name", "tower"); + auto transform = m_World->AddComponent(tower); + transform->Position = glm::vec3(0.f, 0.68f, 0.9f); + auto model = m_World->AddComponent(tower); + model->ModelFile = "Models/Tank/tankTop.obj"; + auto towerSteering = m_World->AddComponent(tower); + towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); + towerSteering->TurnSpeed = glm::pi() / 4.f; + { + auto barrel = m_World->CreateEntity(tower); + auto transform = m_World->AddComponent(barrel); + transform->Position = glm::vec3(-0.012f, 0.3f, -0.95); + auto model = m_World->AddComponent(barrel); + model->ModelFile = "Models/Tank/tankBarrel.obj"; + auto barrelSteering = m_World->AddComponent(barrel); + barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); + barrelSteering->TurnSpeed = glm::pi() / 4.f; + barrelSteering->ShotSpeed = 70.f; + barrelSteering->LowerRotationLimit = glm::radians(-10.f); + barrelSteering->UpperRotationLimit = glm::radians(40.f); + { + auto shot = m_World->CreateEntity(barrel); + auto transform = m_World->AddComponent(shot); + transform->Position = glm::vec3(0.35f, 0.f, -2.f); + transform->Orientation = glm::angleAxis(-glm::pi() / 2.f, glm::vec3(1, 0, 0)); + transform->Scale = glm::vec3(3.f); + m_World->AddComponent(shot); + auto physics = m_World->AddComponent(shot); + physics->Mass = 25.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->CollisionEvent = true; + auto modelComponent = m_World->AddComponent(shot); + modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; + auto tankShellComponent = m_World->AddComponent(shot); + tankShellComponent->Damage = 20.f; + tankShellComponent->ExplosionRadius = 30.f; + tankShellComponent->ExplosionStrength = 300000.f; + { + auto shape = m_World->CreateEntity(shot); + auto transform = m_World->AddComponent(shape); + auto boxShape = m_World->AddComponent(shape); + boxShape->Width = 0.5f; + boxShape->Height = 0.5f; + boxShape->Depth = 0.5f; + m_World->CommitEntity(shape); + } + m_World->CommitEntity(shot); + barrelSteering->ShotTemplate = shot; + + + auto cameraTower = m_World->CreateEntity(barrel); + { + auto transform = m_World->AddComponent(cameraTower); + transform->Position.z = 16.f; + transform->Position.y = 4.f; + transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f)); + auto cameraComp = m_World->AddComponent(cameraTower); + cameraComp->FarClip = 2000.f; + /*auto follow = m_World->AddComponent(cameraTower); + follow->Entity = barrel; + follow->Distance = 15.f; + follow->FollowAxis = glm::vec3(1, 1, 1);*/ + } + + m_World->SetProperty(tank, "Camera", cameraTower); + } + m_World->CommitEntity(barrel); + tankSteering->Barrel = barrel; + } + m_World->CommitEntity(tower); + tankSteering->Turret = tower; + + + + } + + + + //{ + // auto lightentity = m_World->CreateEntity(tank); + // auto transform = m_World->AddComponent(lightentity); + // transform->Position = glm::vec3(0, 0, 0); + // auto light = m_World->AddComponent(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 = m_World->CreateEntity(tank); + // SetProperty(wheelpair, "Name", "WheelPair"); + // AddComponent(wheelpair, "WheelPairThingy"); + +#pragma region Wheels + //Create wheels + float wheelOffset = -0.83f; + const float suspensionStrength = 15.f; + const float springLength = 0.3f; + + AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, -1.715f), 0, true); + AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, -1.715f), 0, true); + AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, 2.375), 1, false); + AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false); +#pragma endregion + + { + auto entity = m_World->CreateEntity(tank); + auto transformComponent = m_World->AddComponent(entity); + transformComponent->Position = glm::vec3(-2, -1.7, 2.0); + transformComponent->Scale = glm::vec3(3, 3, 3); + transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); + auto emitterComponent = m_World->AddComponent(entity); + emitterComponent->SpawnCount = 2; + emitterComponent->SpawnFrequency = 0.005; + emitterComponent->SpreadAngle = glm::pi(); + emitterComponent->UseGoalVelocity = false; + emitterComponent->LifeTime = 0.5; + //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); + emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); + m_World->CommitEntity(entity); + + auto particleEntity = m_World->CreateEntity(entity); + auto TEMP = m_World->AddComponent(particleEntity); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = m_World->AddComponent(particleEntity); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + emitterComponent->ParticleTemplate = particleEntity; + + m_World->CommitEntity(particleEntity); + } + + m_World->CommitEntity(tank); + + return tank; +} + +void Systems::TankSteeringSystem::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front) +{ + const float separation = 1.77f; + const float suspensionStrength = 15.f; + const float springLength = 0.3f; + + bool steering = front; + + auto wheelFront = m_World->CreateEntity(tankEntity); + { + auto transform = m_World->AddComponent(wheelFront); + transform->Position = position - glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); + //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); +#ifdef DEBUG + auto model = m_World->AddComponent(wheelFront); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; +#endif + auto Wheel = m_World->AddComponent(wheelFront); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = axleID; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = steering; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + m_World->CommitEntity(wheelFront); + } + + auto wheelBack = m_World->CreateEntity(tankEntity); + { + auto transform = m_World->AddComponent(wheelBack); + transform->Position = position + glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); + //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); +#ifdef DEBUG + auto model = m_World->AddComponent(wheelBack); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; +#endif + auto Wheel = m_World->AddComponent(wheelBack); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = axleID; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = steering; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + m_World->CommitEntity(wheelBack); + } + + auto wheelPair = m_World->CreateEntity(tankEntity); + { + { + auto transform = m_World->AddComponent(wheelPair); + transform->Position = position; + //transform->Orientation = glm::quat(glm::vec3(0, glm::pi() / 4.f, 0)); + + auto pair = m_World->AddComponent(wheelPair); + pair->FakeWheelFront = wheelFront; + pair->FakeWheelBack = wheelBack; + } + + auto modelEntity = m_World->CreateEntity(wheelPair); + { + auto transform = m_World->AddComponent(modelEntity); + //transform->Position = glm::vec3(0.f, 0.35f, 0.f); + if (front) + { + transform->Position = glm::vec3(0.f, 0.03f, 0.f); + transform->Orientation = glm::quat(glm::vec3(0, glm::pi(), 0)); + } + else + { + transform->Position = glm::vec3(0.f, 0.17f, 0.f); + transform->Scale = glm::vec3(1.f, 1.2f, 1.2f); + } + + auto model = m_World->AddComponent(modelEntity); + model->ModelFile = "Models/Tank/tankWheel.obj"; + } + m_World->CommitEntity(modelEntity); + } + m_World->CommitEntity(wheelPair); +} + void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt ) { PositionX = m_Horizontal; @@ -364,5 +679,3 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E return true; } - - diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 3c2f58e..7035825 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -36,6 +36,18 @@ #include "Components/Vehicle.h" #include "Components/Player.h" +#include "Events/SpawnVehicle.h" +#include "Components/SpawnPoint.h" + +#include "Components/Wheel.h" +#include "Components/MeshShape.h" +#include "Components/Camera.h" +#include "Components/BoxShape.h" +#include "Components/WheelPair.h" +#include "Components/Input.h" + +#include "Events/SetViewportCamera.h" + namespace Systems { @@ -53,13 +65,18 @@ namespace Systems void UpdateEntity(double dt, EntityID entity, EntityID parent) override; private: + std::map m_TimeSinceLastShot; + EventRelay m_ECollision; bool OnCollision(const Events::Collision &e); + EventRelay m_ESpawnVehicle; + bool OnSpawnVehicle(const Events::SpawnVehicle &e); class TankSteeringInputController; std::array, 4> m_TankInputControllers; - std::map m_TimeSinceLastShot; + EntityID CreateTank(int playerID); + void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front); }; class TankSteeringSystem::TankSteeringInputController : InputController diff --git a/src/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp new file mode 100644 index 0000000..4f50c68 --- /dev/null +++ b/src/Systems/WallSystem.cpp @@ -0,0 +1,56 @@ +#include "PrecompiledHeader.h" +#include "WallSystem.h" +#include "World.h" + +void Systems::WallSystem::RegisterComponents( ComponentFactory* cf ) +{ + cf->Register([]() { return new Components::Wall(); }); +} + +void Systems::WallSystem::Initialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::WallSystem::Damage); +} + +bool Systems::WallSystem::Damage( const Events::Damage &event ) +{ + auto wallComponent = m_World->GetComponent(event.Entity); + if(!wallComponent) + { + return false; + } + LOG_INFO("WallSystem::Damage"); + auto wallhealthcomponent = m_World->GetComponent(event.Entity); + if(wallhealthcomponent->Amount > 0) + { + return false; + } + + + LOG_INFO("You are dead"); + auto transformComponent = m_World->GetComponent(event.Entity); + + for(auto d : wallComponent->Walldebris) + { + auto debris = m_World->CloneEntity(d); + + auto transform = m_World->GetComponent(debris); + transform->Position += transformComponent->Position; + + // DO STUFF! :D + float distance = glm::distance(transform->Position, transformComponent->Position); + float radius = 5.f; + float strength = (1.f - pow(distance / radius, 2)) * 500.f; + glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position); + + Events::ApplyPointImpulse e; + e.Entity = debris; + e.Impulse = direction * strength; + e.Position = transformComponent->Position; + EventBroker->Publish(e); + + } + + m_World->RemoveEntity(event.Entity); + return true; +} \ No newline at end of file diff --git a/src/Systems/WallSystem.h b/src/Systems/WallSystem.h new file mode 100644 index 0000000..986c7b8 --- /dev/null +++ b/src/Systems/WallSystem.h @@ -0,0 +1,42 @@ +#ifndef WallSystem_h__ +#define WallSystem_h__ + + +#include "System.h" +#include "Events/OnDead.h" +#include "Events/Damage.h" +#include "Events/ApplyPointImpulse.h" +#include "Components/Model.h" +#include "Components/Wall.h" +#include "Components/Transform.h" +#include "Components/Physics.h" +#include "Components/MeshShape.h" +#include "Components/Tankshell.h" +#include "Components/Health.h" + + + +namespace Systems +{ + class WallSystem : public System + { + public: + + WallSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + + void Initialize() override; + void RegisterComponents(ComponentFactory* cf) override; + + + + EventRelay m_eDamage; + bool Damage(const Events::Damage &event); + + private: + + }; + +} +#endif // WallSystem_h__ diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 2cbd9ab..4f89884 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -124,6 +124,7 @@ + @@ -171,7 +172,9 @@ + + @@ -184,8 +187,8 @@ - + @@ -199,12 +202,14 @@ + + @@ -247,6 +252,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index b7c5c5a..fed4ecf 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -78,6 +78,9 @@ Game\Systems + + Gameplay\Systems + Game\Systems @@ -185,10 +188,9 @@ {ddd3c442-7c2f-4690-9308-fcef62deee0b} - + {3c2ea0e5-41a1-4b11-a891-1d59ead7223c} - - + {3cbe68d9-2446-45ee-8637-ffb805997dcd} @@ -521,6 +523,12 @@ Base\Events + + Rendering\Components + + + Gameplay\Systems + Physics\Events @@ -557,6 +565,18 @@ GUI + + Gameplay\Events + + + Game\Events + + + Game\Components + + + Game\Components +