79 Commits

Author SHA1 Message Date
Jace ae71fde88c Updated submodule remotes to something more manageable and accessible. 2017-01-04 16:00:51 +01:00
Jace 13a0d1521c Fixed filters 2014-08-18 21:41:30 +02:00
Jace 53e137f50d Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance
Conflicts:
	src/Systems/PhysicsSystem.cpp
2014-06-05 16:45:50 +02:00
Jace 428ad2bae0 Fixez 2014-06-05 16:45:15 +02:00
Jace 2f0d17a386 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 16:27:03 +02:00
Jace 09bbb5ac0b Proper entity removal. 2014-06-05 16:26:01 +02:00
Tleety e42c2c49ef Light on tank shells 2014-06-05 16:25:20 +02:00
Stiffly 2f617727a4 dead in water 2014-06-05 07:05:55 +02:00
Stiffly 9a7d0463a0 Merge remote-tracking branch 'origin/master' into Sound+Particles 2014-06-05 07:01:53 +02:00
Stiffly 7b5e0045f6 broken one deadn 2014-06-05 07:01:33 +02:00
ViktorLjung 75a19fbfe0 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:57:46 +02:00
ViktorLjung 36ecbf8b73 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:56:53 +02:00
ViktorLjung d3dca03f47 fix 2014-06-05 06:56:42 +02:00
Tleety 83e28d48f8 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:54:27 +02:00
Tleety b4cec1747e turrets now aiming as they should 2014-06-05 06:53:34 +02:00
ViktorLjung ce2e0b192c Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:46:05 +02:00
ViktorLjung 97994f9af7 Collisions 2014-06-05 06:42:19 +02:00
Tleety 4d5c4c8fc7 Added towers to the map 2014-06-05 06:25:12 +02:00
Tleety 7773580da6 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:14:00 +02:00
Tleety 3f6933da76 tower destroy debris 2014-06-05 06:13:51 +02:00
ViktorLjung a001cad9bc Merge branch 'master' into havok
Conflicts:
	src/GameWorld.cpp
	src/Systems/GameStateSystem.cpp
	src/Systems/TankSteeringSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:04:32 +02:00
ViktorLjung e4a59cec61 Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:01:49 +02:00
Jace 41ca0e832f Merge branch 'deffered_rendering' 2014-06-05 05:58:57 +02:00
Jace dcede48453 Fixed particles not rendering over skybox 2014-06-05 05:53:13 +02:00
Tleety 8f1f87512f Merge remote-tracking branch 'origin/Sound+Particles' 2014-06-05 05:22:33 +02:00
Tleety c7a37e1b9b Merge remote-tracking branch 'origin/master' into deffered_rendering 2014-06-05 05:21:28 +02:00
Tleety 85d5f209a3 Merge branch 'deffered_rendering' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance into deffered_rendering 2014-06-05 05:21:09 +02:00
Tleety fd92f37902 Skybox working, flag for averaging normals working. 2014-06-05 05:20:51 +02:00
Stiffly 16e4129d70 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/Components/Vehicle.h
	src/Systems/TankSteeringSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 05:16:57 +02:00
Stiffly ccc2c49317 Vehicle component has "CurrentRPM" 2014-06-05 05:11:04 +02:00
Jace 9ed2f04036 Fixed particles not rendering to both viewports 2014-06-05 04:50:06 +02:00
Jace 866c65514d Decorations! 2014-06-05 03:54:41 +02:00
Stiffly 09971b2d77 Publishes some bgm sounds 2014-06-05 03:14:45 +02:00
Tleety a6941c0fb6 Merge remote-tracking branch 'origin/master' into deffered_rendering
Conflicts:
	src/GameWorld.cpp
	src/GameWorld.h
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 03:03:00 +02:00
Tleety ccb3d6d84f Turret able to shoot, no collision event yet. 2014-06-05 02:54:44 +02:00
Tleety 93c4805a22 Tower not aiming towards the player. 2014-06-05 00:35:15 +02:00
Jace 56e6545f0f Direct damage and VulnerableToSplash flag on Health component 2014-06-04 23:54:52 +02:00
Jace 2d716e2998 Merge branch 'master' into havok
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 22:01:25 +02:00
Stiffly 76a9081d4b Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 18:22:16 +02:00
Stiffly 6e9eeaf991 Dust particles from tank wheels. 2014-06-04 18:15:47 +02:00
ViktorLjung 1b20204897 Player/Team specific triggers 2014-06-04 18:12:58 +02:00
Jace bf5106e5b6 Merge remote-tracking branch 'origin/deffered_rendering' 2014-06-04 17:14:34 +02:00
Jace 8b2fc86159 Main menu hidden for your debugging pleasure 2014-06-04 17:06:08 +02:00
Jace 5f1feffe0d Main menu finished 2014-06-04 16:59:30 +02:00
ViktorLjung c06c436cd1 Merge remote-tracking branch 'origin/master' into havok 2014-06-04 15:43:51 +02:00
ViktorLjung 70960c9eba Jeep working 2014-06-04 15:43:20 +02:00
Stiffly f2ae46efa5 Merge remote-tracking branch 'origin/master' into Sound+Particles 2014-06-04 15:22:00 +02:00
Stiffly 2ef5d49f7e Added Destructor. (improved StopSound and PlayBGM events) 2014-06-04 15:21:05 +02:00
Tleety 6cae09c5d8 Walls are now destroyable 2014-06-04 14:48:40 +02:00
Jace 7b90e54899 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-04 13:40:23 +02:00
Jace d3f8ef2d9c Wallz 2014-06-04 06:20:22 +02:00
Stiffly f9426745f7 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	assets
2014-06-04 06:17:05 +02:00
Stiffly 5e78fdc930 Not deleting in a "foreach"-loop 2014-06-04 06:09:59 +02:00
Tleety 5a6ae2a24e Merge remote-tracking branch 'origin/master' into deffered_rendering
Conflicts:
	assets
	src/GameWorld.cpp
2014-06-04 06:02:21 +02:00
Tleety d5dcb0b72c Fixed normals nor averaging when at a corner. 2014-06-04 05:56:38 +02:00
ViktorLjung 94178098ea Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 05:48:48 +02:00
Jace 62dd85349f A gate and better bridges. 2014-06-04 05:47:29 +02:00
ViktorLjung f9f20535ba Jeep and tank tuning 2014-06-04 05:47:17 +02:00
Tleety 74b86bc6d4 Lights working without much visable bugs. 2014-06-04 05:44:12 +02:00
Stiffly 27b735325a Improved splashes 2014-06-04 05:31:05 +02:00
Stiffly e39e1eda89 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
2014-06-04 05:30:42 +02:00
Jace 3c17ab6037 Bridges 2014-06-04 05:12:06 +02:00
Stiffly 7f017bfaed Tanks now have listeners. 2014-06-04 04:40:16 +02:00
Jace 9813e9a058 Merge remote-tracking branch 'origin/Sound+Particles'
Conflicts:
	src/GameWorld.cpp
2014-06-04 04:24:10 +02:00
Tleety cf2040f038 Inget funkar, broken commit, dont use. 2014-06-04 04:20:15 +02:00
Jace e11f656b3d Fixed physics relative orientations! 2014-06-04 04:18:44 +02:00
Stiffly 72a8ee9080 Water splash 2014-06-04 03:26:29 +02:00
Jace 7d9f1a7ac7 Merge remote-tracking branch 'origin/havok' 2014-06-04 02:36:59 +02:00
Stiffly 90a92d05e4 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
2014-06-04 01:27:15 +02:00
Stiffly 9f1d5206bd Muzzle Flash 2014-06-04 01:23:15 +02:00
ViktorLjung ac855f554b Fixed local physics orientation 2014-06-04 00:45:43 +02:00
Stiffly 909ee94e26 Billboarding working again 2014-06-03 23:48:13 +02:00
Stiffly df32a3b07d PlaySFX now uses Position instead of Emitter ID for playing a sound. 2014-06-03 21:02:39 +02:00
Stiffly 2833b8df36 Merge branch 'master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-03 20:39:44 +02:00
Stiffly 87b02711f4 Doppler scale ruined everything 2014-06-03 20:05:31 +02:00
Stiffly 96a608db27 Merge branch 'FMOD' into Sound+Particles 2014-06-03 19:47:01 +02:00
Stiffly 5265fb9734 assets commit 2014-06-03 19:46:48 +02:00
Stiffly a5105e5859 tank modifications 2014-06-03 19:44:33 +02:00
Stiffly e7eca74b03 Merge branch 'particles' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-02 22:59:58 +02:00
82 changed files with 3518 additions and 813 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[submodule "assets"]
path = assets
url = returngeance@shard.imon.nu:Assets
url = https://imon.nu/git/BTH/FishTanks-assets.git
branch = master
+1 -1
Submodule assets updated: 75977fd865...de87617060
+27
View File
@@ -0,0 +1,27 @@
#ifndef Components_DamageModel_h__
#define Components_DamageModel_h__
#include <string>
#include "Component.h"
namespace Components
{
struct DamageModel : Component
{
DamageModel()
: Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f))
, ShadowCaster(true)
, Transparent(false)
{ }
std::string ModelFile;
glm::vec4 Color;
bool ShadowCaster;
bool Transparent;
virtual DamageModel* Clone() const override { return new DamageModel(*this); }
};
}
#endif // !Components_DamageModel_h__
+4 -1
View File
@@ -9,9 +9,12 @@ namespace Components
struct Health : Component
{
Health()
: Amount(1.0f) { }
: Amount(1.0f)
, VulnerableToSplash(true)
{ }
float Amount;
bool VulnerableToSplash;
virtual Health* Clone() const override { return new Health(*this); }
};
+14
View File
@@ -0,0 +1,14 @@
#ifndef JeepSteering_h__
#define JeepSteering_h__
#include "Component.h"
namespace Components
{
struct JeepSteering : Component
{
JeepSteering* Clone() const override { return new JeepSteering(*this); }
};
}
#endif // JeepSteering_h__
+2 -1
View File
@@ -10,12 +10,13 @@ namespace Components
struct Model : Component
{
Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false) { }
Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false), AverageNormals(false) { }
std::string ModelFile;
glm::vec4 Color;
bool Visible;
bool ShadowCaster;
bool Transparent;
bool AverageNormals;
virtual Model* Clone() const override { return new Model(*this); }
};
+3 -1
View File
@@ -20,7 +20,8 @@ struct ParticleEmitter : Component
, SpreadAngle(0)
, LifeTime(0)
, TimeSinceLastSpawn(100)
, Color(glm::vec4(0)) { }
, Emitting(false)
, Color(glm::vec4(1)) { }
EntityID ParticleTemplate;
float SpawnFrequency;
@@ -32,6 +33,7 @@ struct ParticleEmitter : Component
double LifeTime;
bool UseGoalVelocity;
bool Fade;
bool Emitting;
glm::vec3 GoalVelocity;
std::vector<float> AngularVelocitySpectrum;
std::vector<glm::vec3> OrientationSpectrum; //Keep? noo..
+2 -1
View File
@@ -10,13 +10,14 @@ namespace Components
struct SoundEmitter : Component
{
enum class SoundType
{
SOUND_3D,
SOUND_2D
};
SoundEmitter() : Gain(1.f), MaxDistance(1.f), MinDistance(1.f), Pitch(1.f), Loop(false) {}
SoundEmitter() : Gain(1.f), MaxDistance(10000.f), MinDistance(1.f), Pitch(1.f), Loop(false) {}
float Gain;
float MaxDistance;
float MinDistance;
+18
View File
@@ -0,0 +1,18 @@
#ifndef Components_Team_h__
#define Components_Team_h__
#include "Component.h"
#include "Entity.h"
namespace Components
{
struct Team : Component
{
unsigned int TeamID;
virtual Team* Clone() const override { return new Team(*this); }
};
}
#endif // !Components_Team_h__
+24
View File
@@ -0,0 +1,24 @@
#ifndef Tower_h__
#define Tower_h__
#include "Component.h"
namespace Components
{
struct Tower : Component
{
Tower()
: ID(0) { }
int ID;
EntityID GunBase;
EntityID Gun;
virtual Tower* Clone() const override { return new Tower(*this); }
};
}
#endif // Tower_h__
+20
View File
@@ -0,0 +1,20 @@
#ifndef Components_TowerDebris_h__
#define Components_TowerDebris_h__
#include "Component.h"
#include <string>
#include <vector>
namespace Components
{
struct TowerDebris : Component
{
std::vector<EntityID> TowerDebrisIDs;
virtual TowerDebris* Clone() const override { return new TowerDebris(*this); }
};
}
#endif // Components_TowerDebris_h__
+1
View File
@@ -9,6 +9,7 @@ namespace Components
struct Trigger : Component
{
bool TriggerOnce;
int TeamID;
virtual Trigger* Clone() const override { return new Trigger(*this); }
};
+22
View File
@@ -0,0 +1,22 @@
#ifndef Components_Turret_h__
#define Components_Turret_h__
#include "Component.h"
namespace Components
{
struct Turret : Component
{
Turret()
: ShotSpeed(1.0f) { }
EntityID ShotTemplate;
float ShotSpeed;
virtual Turret* Clone() const override { return new Turret(*this); }
};
}
#endif // BarrelSteering_h__
+25
View File
@@ -0,0 +1,25 @@
#ifndef Components_TurretShot_h__
#define Components_TurretShot_h__
#include "Component.h"
namespace Components
{
struct TurretShot : Component
{
TurretShot()
: Damage(1.0f),
ExplosionRadius(1.0f),
ExplosionStrength(100.0f) { }
float Damage;
float ExplosionRadius;
float ExplosionStrength;
virtual TurretShot* Clone() const override { return new TurretShot(*this); }
};
}
#endif // Components_TurretShot_h__
+4 -3
View File
@@ -10,9 +10,9 @@ namespace Components
struct Vehicle : Component
{
Vehicle()
: 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){ }
: MaxTorque(1000.0f), MinRPM(200.0f), OptimalRPM(2500.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(90.0f),
MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(3500.0f), DownshiftRPM(1000.0f),
gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f), currentRPM(0.0f){ }
float MaxTorque;
float MinRPM;
float OptimalRPM;
@@ -29,6 +29,7 @@ struct Vehicle : Component
float gearsRatio1;
float gearsRatio2;
float gearsRatio3;
float currentRPM;
Vehicle* Clone() const override { return new Vehicle(*this); }
};
+2 -1
View File
@@ -22,7 +22,8 @@ public:
m_ResourceManager = std::make_shared<ResourceManager>();
m_ResourceManager->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
auto rm = m_ResourceManager;
m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName), false); });
m_ResourceManager->RegisterType("AveragedModel", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName), true); });
m_ResourceManager->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager);
+10 -2
View File
@@ -9,8 +9,11 @@ namespace Events
{
struct CreateExplosion : Event
{
CreateExplosion()
: Color(glm::vec4(0)) {}
CreateExplosion() :
Color(glm::vec4(0)),
usePointLight(false),
UseGoalVector(false) {}
glm::vec3 Position;
glm::vec4 Color;
double LifeTime;
@@ -19,7 +22,12 @@ namespace Events
glm::quat RelativeUpOrientation;
float Speed;
float SpreadAngle;
float usePointLight;
std::vector<float> ParticleScale;
bool UseGoalVector;
glm::vec3 GoalVelocity;
bool Emitting;
float SpawnFrequency;
};
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef Events_Dead_h__
#define Events_Dead_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct Dead : Event
{
EntityID Entity;
};
}
#endif // Events_Dead_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagCaptured_h__
#define Events_FlagCaptured_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagCaptured : Event
{
unsigned int Player;
};
}
#endif // Events_FlagCaptured_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagDropped_h__
#define Events_FlagDropped_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagDropped : Event
{
unsigned int Player;
};
}
#endif // Events_FlagDropped_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagPickup_h__
#define Events_FlagPickup_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagPickup : Event
{
unsigned int Player;
};
}
#endif // Events_FlagPickup_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagReturned_h__
#define Events_FlagReturned_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagReturned : Event
{
unsigned int Player;
};
}
#endif // Events_FlagReturned_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_GameOver_h__
#define Events_GameOver_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct GameOver : Event
{
unsigned int Player;
};
}
#endif // Events_GameOver_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_GameStart_h__
#define Events_GameStart_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct GameStart : Event
{
};
}
#endif // Events_GameStart_h__
+19
View File
@@ -0,0 +1,19 @@
#ifndef Events_JeepSteer_h__
#define Events_JeepSteer_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct JeepSteer : Event
{
EntityID Entity;
float PositionX;
float PositionY;
bool Handbrake;
};
}
#endif // Events_JeepSteer_h__
-16
View File
@@ -1,16 +0,0 @@
#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__
+10 -1
View File
@@ -9,8 +9,17 @@ namespace Events
struct PlaySFX : Event
{
EntityID Emitter;
PlaySFX() :
MinDistance(100.f),
MaxDistance(10000.f),
Volume(1.f),
Loop (false) {}
//EntityID Emitter;
glm::vec3 Position;
std::string Resource;
float MinDistance;
float MaxDistance;
float Volume;
bool Loop;
};
+45 -15
View File
@@ -36,6 +36,7 @@ public:
: EventBroker(eventBroker)
, ResourceManager(resourceManager)
, Rectangle()
, m_Parent(nullptr)
, m_Name("UIParent")
, m_Layer(0)
, m_Hidden(false)
@@ -46,12 +47,28 @@ public:
: m_Name(name)
, m_Layer(0)
, m_Hidden(false)
{ SetParent(std::shared_ptr<Frame>(parent)); Initialize(); }
{ SetParent(parent); Initialize(); }
~Frame()
{
/*for (auto layer : m_Children)
{
for (auto child : layer.second)
{
delete child.second;
}
}
if (m_Parent)
{
m_Parent->RemoveChild(this);
}*/
}
::RenderQueuePair RenderQueue;
std::shared_ptr<Frame> Parent() const { return m_Parent; }
void SetParent(std::shared_ptr<Frame> parent)
Frame* Parent() const { return m_Parent; }
void SetParent(Frame* parent)
{
if (parent == nullptr)
{
@@ -62,13 +79,13 @@ public:
Width = parent->Width;
Height = parent->Height;
m_Layer = parent->Layer() + 1;
parent->AddChild(std::shared_ptr<Frame>(this));
parent->AddChild(this);
m_Parent = parent;
EventBroker = parent->EventBroker;
ResourceManager = parent->ResourceManager;
}
void AddChild(std::shared_ptr<Frame> child)
void AddChild(Frame* child)
{
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
if (m_Parent)
@@ -77,7 +94,19 @@ public:
}
}
typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
void RemoveChild(Frame* child)
{
auto it = m_Children.find(child->m_Layer);
if (it != m_Children.end())
{
m_Children.erase(it);
}
if (m_Parent)
{
m_Parent->RemoveChild(child);
}
}
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
@@ -89,8 +118,14 @@ public:
else
return m_Hidden;
}
void Hide() { m_Hidden = true; }
void Show() { m_Hidden = false; }
bool Visible() const
{
return !Hidden();
}
virtual void Hide() { m_Hidden = true; }
virtual void Show() { m_Hidden = false; }
int Left() const override
{
@@ -144,9 +179,6 @@ public:
void UpdateLayered(double dt)
{
if (this->Hidden())
return;
// Update ourselves
this->Update(dt);
@@ -157,8 +189,6 @@ public:
for (auto &pairChild : children)
{
auto child = pairChild.second;
if (child->Hidden())
continue;
child->Update(dt);
}
}
@@ -200,8 +230,8 @@ protected:
int m_Layer;
bool m_Hidden;
std::shared_ptr<Frame> m_Parent;
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
Frame* m_Parent;
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
virtual bool OnKeyDown(const Events::KeyDown &event) { return false; }
+36 -11
View File
@@ -2,13 +2,16 @@
#define GUI_GameFrame_h__
#include "GUI/Frame.h"
#include "GUI/MainMenuFrame.h"
#include "GUI/WorldFrame.h"
#include "GUI/Viewport.h"
#include "GUI/TextureFrame.h"
#include "GUI/PlayerHUD.h"
#include "VehicleSelection.h"
#include "GameWorld.h"
#include "Events/GameStart.h"
#include "Events/GameOver.h"
#include "Events/Dead.h"
namespace GUI
{
@@ -18,37 +21,59 @@ class GameFrame : public Frame
public:
GameFrame(Frame* parent, std::string name)
: Frame(parent, name)
, m_GameOver(false)
{
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &GUI::GameFrame::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::GameFrame::OnGameOver);
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
m_WorldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
{
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1 = new Viewport(m_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);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2 = new Viewport(m_WorldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = this->Width / 2.f;
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
new VehicleSelection(vp2, "VehicleSelection", m_World, 2);
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Hide();
}
m_WorldFrame->Hide();
m_World->Initialize();
m_MainMenuFrame = new MainMenuFrame(this, "MainMenu");
}
private:
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
EventRelay<Frame, Events::GameStart> m_EGameStart;
bool OnGameStart(const Events::GameStart &event)
{
m_WorldFrame->Show();
return true;
}
EventRelay<Frame, Events::GameOver> m_EGameOver;
bool OnGameOver(const Events::GameOver &event)
{
m_GameOver = true;
return true;
}
std::shared_ptr<GameWorld> m_World;
MainMenuFrame* m_MainMenuFrame;
WorldFrame* m_WorldFrame;
Viewport* vp1;
Viewport* vp2;
Viewport* m_FreeCamViewport;
bool m_GameOver;
bool OnKeyUp(const Events::KeyUp &event) override
{
if (event.KeyCode == GLFW_KEY_1)
+41
View File
@@ -0,0 +1,41 @@
#ifndef GUI_GameOverFrame_h__
#define GUI_GameOverFrame_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
namespace GUI
{
class GameOverFrame : public Frame
{
public:
GameOverFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
//Hide();
m_Background = new TextureFrame(this, "Background");
m_Background->SetTexture("Textures/GUI/black.png");
m_Background->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.6f));
m_Text = new TextureFrame(this, "Message");
m_Text->SetTexture("Textures/GUI/GloriousVictory.png");
}
void Show(bool victory)
{
if (victory)
m_Text->SetTexture("Textures/GUI/GloriousVictory.png");
else
m_Text->SetTexture("Textures/GUI/ShamefulDefeat.png");
Frame::Show();
}
protected:
bool m_Victory;
TextureFrame* m_Background;
TextureFrame* m_Text;
};
}
#endif // GUI_GameOverFrame_h__
+1 -1
View File
@@ -37,7 +37,7 @@ namespace GUI
if (!health)
return false;
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - health->Amount / 100.f));
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - (health->Amount / 100.f / 2.f)));
return true;
}
+108
View File
@@ -0,0 +1,108 @@
#ifndef GUI_MainMenuFrame_h__
#define GUI_MainMenuFrame_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#include "Events/GameStart.h"
#include "Events/PlayBGM.h"
namespace GUI
{
class MainMenuFrame : public Frame
{
public:
MainMenuFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
m_CurrentSelection = 0;
//Hide();
m_Background = new TextureFrame(this, "Background");
m_Background->SetTexture("Textures/GUI/MainMenu/BackGround.png");
m_Buttons = new TextureFrame(this, "Message");
m_Buttons->SetTexture("Textures/GUI/MainMenu/Buttons.png");
m_CurrentCoordinate = -m_SelectionCoordinates[0] * Scale();
m_TargetCoordinate = m_CurrentCoordinate;
m_Buttons->X = m_CurrentCoordinate.x;
m_Buttons->Y = m_CurrentCoordinate.y;
Events::PlayBGM e;
e.Resource = "Sounds/BGM/DiesIrae.mp3";
EventBroker->Publish(e);
}
void Update(double dt) override
{
if (Hidden())
return;
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 4.f * (float)dt;
m_Buttons->X = m_CurrentCoordinate.x;
m_Buttons->Y = m_CurrentCoordinate.y;
}
protected:
bool m_Victory;
TextureFrame* m_Background;
TextureFrame* m_Buttons;
int m_CurrentSelection;
static glm::vec2 m_SelectionCoordinates[2];
glm::vec2 m_CurrentCoordinate;
glm::vec2 m_TargetCoordinate;
bool OnCommand(const Events::InputCommand &event) override
{
if (Hidden())
return false;
const float deadzone = 0.5f;
if (event.Command == "interface_horizontal")
{
if (event.Value > deadzone)
m_CurrentSelection++;
else if (event.Value < -deadzone)
m_CurrentSelection--;
}
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 1) ? 1 : m_CurrentSelection);
m_TargetCoordinate = -m_SelectionCoordinates[m_CurrentSelection] * Scale();
if (event.Command == "interface_confirm" && event.Value > 0)
{
// Play
if (m_CurrentSelection == 0)
{
Hide();
Events::GameStart e1;
EventBroker->Publish(e1);
Events::PlayBGM e2;
e2.Resource = "Sounds/BGM/FlightOfTheBumblebee.mp3";
EventBroker->Publish(e2);
}
// Quit
else if (m_CurrentSelection == 1)
{
exit(EXIT_SUCCESS);
}
}
return false;
}
};
glm::vec2 MainMenuFrame::m_SelectionCoordinates[2] = {
glm::vec2(0, 0),
glm::vec2(193, 0),
};
}
#endif // GUI_MainMenuFrame_h__
+56
View File
@@ -3,6 +3,12 @@
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#include "GUI/VehicleSelection.h"
#include "GUI/GameOverFrame.h"
#include "Events/GameOver.h"
#include "Events/Dead.h"
#include "Components/Player.h"
namespace GUI
{
@@ -15,7 +21,11 @@ namespace GUI
, m_World(world)
, m_PlayerID(playerID)
{
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::PlayerHUD::OnGameOver);
EVENT_SUBSCRIBE_MEMBER(m_EDead, &GUI::PlayerHUD::OnDead);
m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID);
m_Crosshair = new TextureFrame(this, "Crosshair");
m_Crosshair->Width = 45;
m_Crosshair->Height = 45;
@@ -23,6 +33,11 @@ namespace GUI
m_Crosshair->Y = this->Height / 2.f - m_Crosshair->Height / 2.f;
m_Crosshair->SetTexture("Textures/GUI/crosshair.png");
m_Crosshair->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.75f));
m_VehicleSelection = new VehicleSelection(this, "VehicleSelection", m_World, m_PlayerID);
m_GameOverFrame = new GameOverFrame(this, "GameOver");
m_GameOverFrame->Hide();
}
protected:
@@ -31,6 +46,47 @@ namespace GUI
HealthOverlay* m_HealthOverlay;
TextureFrame* m_Crosshair;
VehicleSelection* m_VehicleSelection;
GameOverFrame* m_GameOverFrame;
EventRelay<Frame, Events::GameOver> m_EGameOver;
bool OnGameOver(const Events::GameOver &event)
{
if (m_PlayerID == event.Player)
m_GameOverFrame->Show(true);
else
m_GameOverFrame->Show(false);
return true;
}
EventRelay<Frame, Events::Dead> m_EDead;
bool OnDead(const Events::Dead &event)
{
auto playerCo = m_World->GetComponent<Components::Player>(event.Entity);
if (!playerCo || m_PlayerID != playerCo->ID)
return false;
m_VehicleSelection->Show();
m_HealthOverlay->SetColor(glm::vec4(1, 1, 1, 0));
return true;
}
bool OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != m_PlayerID)
return false;
if (event.Command == "interface_confirm" && event.Value > 0)
{
/*if (m_GameOverFrame->Visible())
{
m_GameOverFrame->Hide();
}*/
}
return true;
}
};
}
+9 -4
View File
@@ -40,6 +40,9 @@ namespace GUI
void Update(double dt) override
{
if (Hidden())
return;
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 2.f * (float)dt;
@@ -77,28 +80,30 @@ namespace GUI
if (event.PlayerID != m_PlayerID)
return false;
const float deadzone = 0.5f;
// Menu movement
if (event.Command == "interface_horizontal" || event.Command == "interface_vertical")
{
// Horizontal scrolling
if (event.Command == "interface_horizontal")
{
if (event.Value > 0)
if (event.Value > deadzone)
m_CurrentSelection++;
else if (event.Value < 0)
else if (event.Value < -deadzone)
m_CurrentSelection--;
}
// Vertical scrolling to switch between "rows" in an intuitive way
else if (event.Command == "interface_vertical")
{
if (event.Value > 0)
if (event.Value > deadzone)
{
if (m_CurrentSelection == 0)
m_CurrentSelection++;
else if (m_CurrentSelection == 3)
m_CurrentSelection--;
}
else if (event.Value < 0)
else if (event.Value < -deadzone)
{
if (m_CurrentSelection == 1)
m_CurrentSelection--;
+1 -1
View File
@@ -51,7 +51,7 @@ public:
return;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
+12 -2
View File
@@ -55,7 +55,17 @@ public:
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
Model* modelAsset = nullptr;
if (modelComponent->AverageNormals)
{
modelAsset = ResourceManager->Load<Model>("AveragedModel", modelComponent->ModelFile);
}
else
{
modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
}
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
@@ -145,7 +155,7 @@ private:
auto itpair = m_Children[m_Layer + 1].equal_range(event.ViewportFrame);
for (auto it = itpair.first; it != itpair.second; ++it)
{
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
auto viewportFrame = dynamic_cast<GUI::Viewport*>(it->second);
if (!viewportFrame)
continue;
+827 -400
View File
File diff suppressed because it is too large Load Diff
+14 -4
View File
@@ -23,12 +23,17 @@
#include "Systems/WheelPairSystem.h"
#include "Systems/FollowSystem.h"
#include "Systems/WallSystem.h"
#include "Systems/TowerSystem.h"
#include "Systems/GarageSystem.h"
#include "Systems/JeepSteeringSystem.h"
#include "Systems/FlagSystem.h"
#include "Systems/GameStateSystem.h"
#include "Components/Camera.h"
#include "Components/DirectionalLight.h"
#include "Components/Input.h"
#include "Components/Model.h"
#include "Components/DamageModel.h"
#include "Components/ParticleEmitter.h"
#include "Components/Particle.h"
#include "Components/PointLight.h"
@@ -56,6 +61,7 @@
#include "Components/TriggerRotate.h"
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Team.h"
class GameWorld : public World
{
@@ -78,14 +84,18 @@ private:
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value);
void CreateGate(glm::vec3 Position);
void CreateGate(EntityID parent, glm::vec3 position, glm::quat orientation, int teamID);
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, glm::quat orientation, int playerID);
EntityID CreateWall(EntityID parent, glm::vec3 pos, glm::quat orientation);
EntityID CreateTower(EntityID parent, glm::vec3 pos, int teamID);
EntityID CreateGarage(EntityID parent, glm::vec3 Position, glm::quat orientation, int teamID);
void CreateTerrain();
void CreateBase(glm::quat orientation);
void CreateBase(glm::quat orientation, int playerID);
void CreateFlag(EntityID parent, glm::vec3 position, glm::quat orientation, int TeamID);
std::vector<EntityID> m_WallDebrisTemplates;
std::vector<EntityID> m_TowerDebrisTemplates;
EntityID m_ShotTemplate;
};
#endif // GameWorld_h__
+37 -3
View File
@@ -6,29 +6,63 @@
#include "EventBroker.h"
#include "Events/InputCommand.h"
#include "Events/MouseMove.h"
#include "Events/GameStart.h"
#include "Events/GameOver.h"
template <typename EventContext>
class InputController
{
public:
InputController(std::shared_ptr<::EventBroker> eventBroker)
: EventBroker(eventBroker) { Initialize(); }
: EventBroker(eventBroker)
, InGame(true)
{ Initialize(); }
virtual void Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand);
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::_OnCommand);
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::_OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &InputController::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &InputController::OnGameOver);
}
virtual bool OnCommand(const Events::InputCommand &event) { return false; }
virtual bool OnMouseMove(const Events::MouseMove &event) { return false; }
virtual bool OnGameStart(const Events::GameStart &event)
{
InGame = true;
return true;
}
virtual bool OnGameOver(const Events::GameOver &event)
{
InGame = false;
return true;
}
protected:
std::shared_ptr<::EventBroker> EventBroker;
bool InGame;
private:
EventRelay<EventContext, Events::InputCommand> m_EInputCommand;
EventRelay<EventContext, Events::MouseMove> m_EMouseMove;
EventRelay<EventContext, Events::GameStart> m_EGameStart;
EventRelay<EventContext, Events::GameOver> m_EGameOver;
virtual bool _OnCommand(const Events::InputCommand &event)
{
if (InGame || event.Value == 0)
return OnCommand(event);
else
return false;
}
virtual bool _OnMouseMove(const Events::MouseMove &event)
{
if (InGame)
return OnMouseMove(event);
else
return false;
}
};
#endif // InputController_h__
+22
View File
@@ -85,6 +85,28 @@ void InputManager::Update(double dt)
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_P])
{
Events::StopSound e;
e.Emitter = 1;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_L])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/WilliamTellOverture.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_O])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/DiesIrae.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
// // Lock mouse while holding LMB
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
+3
View File
@@ -13,6 +13,9 @@
#include "Events/GamepadAxis.h"
#include "Events/GamepadButton.h"
#include "Events/StopSound.h"
#include "Events/PlayBGM.h"
class InputManager
{
public:
+13 -7
View File
@@ -1,7 +1,7 @@
#include "PrecompiledHeader.h"
#include "Model.h"
Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj, bool average)
{
OBJ::MaterialInfo* currentMaterial = nullptr;
TextureGroup* currentTexGroup = nullptr;
@@ -93,7 +93,10 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
if (Vertices.size() > 0)
{
CreateTangents();
//getSimilarVertexIndex();
if (average)
{
getSimilarVertexIndex();
}
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
}
else
@@ -105,7 +108,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec3> tangents, std::vector<glm::vec3> biTangents, std::vector<glm::vec2>textureCoords)
{
LOG_INFO("Generating VertexBuffer");
//LOG_INFO("Generating VertexBuffer");
glGenBuffers(1, &VertexBuffer);
if (vertices.size() > 0)
{
@@ -118,7 +121,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty vertex buffer!");
}
LOG_INFO("Generating NormalBuffer");
//LOG_INFO("Generating NormalBuffer");
glGenBuffers(1, &NormalBuffer);
if (normals.size() > 0)
{
@@ -131,7 +134,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty normal buffer!");
}
LOG_INFO("Generating TangentNormalsBuffer");
//LOG_INFO("Generating TangentNormalsBuffer");
glGenBuffers(1, &TangentNormalsBuffer);
if (tangents.size() > 0)
{
@@ -144,7 +147,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty tangent buffer!");
}
LOG_INFO("Generating BiTangentNormalsBuffer");
//LOG_INFO("Generating BiTangentNormalsBuffer");
glGenBuffers(1, &BiTangentNormalsBuffer);
if (biTangents.size() > 0)
{
@@ -158,7 +161,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
}
LOG_INFO("Generating textureCoordBuffer");
//LOG_INFO("Generating textureCoordBuffer");
glGenBuffers(1, &TextureCoordBuffer);
if (textureCoords.size() > 0)
{
@@ -223,6 +226,8 @@ void Model::getSimilarVertexIndex()
{
glm::vec3 tempNormal, tempTangent, tempBiTangent;
if(glm::dot(Normals[i], Normals[t]) > .4f)
{
tempNormal = Normals[i] + Normals[t];
tempTangent = TangentNormals[i] + TangentNormals[t];
tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
@@ -235,6 +240,7 @@ void Model::getSimilarVertexIndex()
BiTangentNormals[i] = tempBiTangent;
BiTangentNormals[t] = tempBiTangent;
}
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@
class Model : public Resource
{
public:
Model(std::shared_ptr<ResourceManager> resourceManager, OBJ &obj);
Model(std::shared_ptr<ResourceManager> resourceManager, OBJ &obj, bool average);
struct TextureGroup
{
+3 -3
View File
@@ -13,7 +13,7 @@ bool OBJ::LoadFromFile(std::string filename)
return false;
}
LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
//LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
std::string line;
while (std::getline(file, line))
@@ -121,7 +121,7 @@ void OBJ::ParseMaterial()
return;
}
LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
//LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
std::string currentMaterialName;
MaterialInfo* currentMaterial = nullptr;
@@ -144,7 +144,7 @@ void OBJ::ParseMaterial()
{
MaterialInfo mat;
ss >> currentMaterialName;
LOG_INFO("Parsing material %s", currentMaterialName.c_str());
//LOG_INFO("Parsing material %s", currentMaterialName.c_str());
Materials[currentMaterialName] = mat;
currentMaterial = &Materials[currentMaterialName];
continue;
+1 -1
View File
@@ -114,7 +114,7 @@ void VehicleSetup::setupVehicleData(const hkpWorld* world, hkpVehicleData& data
data.m_chassisUnitInertiaYaw = 0.8f;
data.m_chassisUnitInertiaRoll = 1.0f;
data.m_chassisUnitInertiaPitch = 1.0f;
data.m_chassisUnitInertiaPitch = 2.0f;
// Adds or removes torque around the yaw axis
// based on the current steering angle. This will
+131 -91
View File
@@ -22,7 +22,7 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager)
LAtt = 0.0f;
QAtt = 3.0f;
m_ShadowMapRes = 1;
m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f);
m_SunPosition = glm::vec3(0.f, 1.0f, 0.7f);
m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection_height = glm::vec2(-40.f, 40.f);
m_SunProjection_width = glm::vec2(-40.f, 40.f);
@@ -126,6 +126,7 @@ void Renderer::LoadContent()
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SunPass.vert.glsl")));
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SunPass.frag.glsl")));
m_SunPassProgram.Compile();
glBindFragDataLocation(m_SunPassProgram.GetHandle(), 0, "frag_Light");
m_SunPassProgram.Link();
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl")));
@@ -142,7 +143,6 @@ void Renderer::LoadContent()
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
m_FirstPassProgram.Compile();
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal");
@@ -151,6 +151,7 @@ void Renderer::LoadContent()
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl")));
m_SecondPassProgram.Compile();
glBindFragDataLocation(m_SecondPassProgram.GetHandle(), 0, "frag_Light");
m_SecondPassProgram.Link();
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
@@ -161,13 +162,14 @@ void Renderer::LoadContent()
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
m_FinalPassProgram.Compile();
glBindFragDataLocation(m_FinalPassProgram.GetHandle(), 0, "frag_Diffuse");
m_FinalPassProgram.Link();
m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes);
FrameBufferTextures();
m_sphereModel = ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/sunset", "jpg");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/sky36", "jpg");
}
void Renderer::Draw(double dt)
@@ -373,6 +375,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_SCISSOR_TEST);
glDepthRange(0.0, 0.999);
//Sort forward rendering items by z value.
for(auto job : rq.Forward)
@@ -386,81 +389,77 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
rq.Forward.Jobs.sort(Renderer::DepthSort);
//DrawShadowMap(rq.Deferred);
/*
Base pass
Base pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glBindFramebuffer(GL_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);
// Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffClear);
glClearColor(115.f / 255, 192.f / 255, 255.f / 255, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffOpaque);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
DrawSkybox();
DrawFBOScene(rq.Deferred);
/*
Lighting pass
Lighting pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
//glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glCullFace(GL_FRONT);
DrawLightScene(rq.Deferred);
glCullFace(GL_BACK);
DrawSunLightScene();
/*
Final pass
Final pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
glViewport(0, 0, m_Width, m_Height);
//glScissor(0, 0, m_Width, m_Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
//glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
m_FinalPassProgram.Bind();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
//glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
/*
Transparency
@@ -470,25 +469,33 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
void Renderer::ForwardRendering(RenderQueue &rq)
{
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_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_NONE , GL_NONE , GL_NONE };
glDrawBuffers(4, attachments);
//glClearColor(0.f, 0.f, 0.f, 1.f);
//glClear(GL_COLOR_BUFFER_BIT);
/*
Skybochs
*/
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthRange(0.999, 1.0);
DrawSkybox();
glDepthRange(0.0, 0.999);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//glBindFramebuffer(GL_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);
// Clear G-buffer
//GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE, GL_NONE };
//glDrawBuffers(4, attachments);
//glClear(GL_COLOR_BUFFER_BIT);
//glClearColor(0.f, 0.f, 0.f, 0.f);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP;
@@ -497,7 +504,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle();
for (auto &job : rq)
{
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob)
{
glm::mat4 modelMatrix = modelJob->ModelMatrix;
@@ -508,12 +515,14 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "directionToSun"), 1, glm::value_ptr(glm::normalize(m_SunPosition)));
glBindVertexArray(modelJob->VAO);
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);
@@ -522,7 +531,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
{
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
}*/
}
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue;
@@ -532,8 +541,9 @@ void Renderer::ForwardRendering(RenderQueue &rq)
if (spriteJob)
{
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
glm::mat4 billboardingMatrix = glm::inverse(glm::toMat4(glm::inverse(m_Camera->Orientation())));
MVP = cameraMatrix * modelMatrix * billboardingMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4(m_Camera->ViewMatrix())));
@@ -549,14 +559,14 @@ void Renderer::ForwardRendering(RenderQueue &rq)
}
}
//glDepthMask (GL_TRUE);
//glDisable (GL_BLEND);
/*
Final pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
@@ -570,7 +580,9 @@ void Renderer::ForwardRendering(RenderQueue &rq)
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
// glActiveTexture(GL_TEXTURE1);
// glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
@@ -609,6 +621,8 @@ void Renderer::Swap()
void Renderer::DrawSkybox()
{
// glEnable(GL_CULL_FACE);
// glCullFace(GL_BACK);
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
@@ -619,8 +633,10 @@ void Renderer::DrawSkybox()
//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->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height) * glm::inverse(glm::toMat4(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraView = glm::inverse(glm::toMat4(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(cameraView));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw();
}
@@ -946,7 +962,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_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 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);
@@ -998,19 +1014,47 @@ void Renderer::FrameBufferTextures()
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fSpecularTexture, 0);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
GLenum FirstPass[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, FirstPass);
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbBasePass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
m_fbFinalPass = 0;
glGenFramebuffers(1, &m_fbFinalPass);
glGenTextures(1, &m_fFinalDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fFinalDiffuseTexture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
GLenum FinalPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, FinalPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
m_fbLightingPass = 0;
glGenFramebuffers(1, &m_fbLightingPass);
glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 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);
@@ -1019,6 +1063,9 @@ void Renderer::FrameBufferTextures()
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
@@ -1267,12 +1314,7 @@ void Renderer::DrawFBOScene(RenderQueue &rq)
void Renderer::DrawLightScene(RenderQueue &rq)
{
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1283,6 +1325,13 @@ void Renderer::DrawLightScene(RenderQueue &rq)
m_SecondPassProgram.Bind();
GLuint ShaderProgramHandle = m_SecondPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
for (auto &light : Lights)
{
MVP = cameraMatrix * light.SphereModelMatrix;
@@ -1305,21 +1354,10 @@ void Renderer::DrawLightScene(RenderQueue &rq)
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
};
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
}
void Renderer::DrawSunLightScene()
{
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
//glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1328,7 +1366,13 @@ void Renderer::DrawSunLightScene()
m_SunPassProgram.Bind();
GLuint ShaderProgramHandle = m_SunPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1, glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -1340,10 +1384,6 @@ void Renderer::DrawSunLightScene()
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
}
void Renderer::SetSphereModel( Model* _model )
+4
View File
@@ -167,6 +167,10 @@ private:
GLuint m_ShadowFrameBuffer;
GLuint m_ShadowDepthTexture;
GLuint m_fbFinalPass;
GLuint m_fFinalDiffuseTexture;
GLuint m_fbBasePass;
GLuint m_fDiffuseTexture;
GLuint m_fPositionTexture;
+1 -2
View File
@@ -1,6 +1,5 @@
#version 430
//uniform vec3 La;
layout (binding=0) uniform sampler2D DiffuseTexture;
@@ -15,11 +14,11 @@ out vec4 FragmentColor;
void main()
{
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
//vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel;
FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
}
+8 -3
View File
@@ -1,7 +1,7 @@
#version 430
//Dicksdickdickdickssssss
uniform vec3 La;
uniform float Gamma;
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D LightingTexture;
@@ -12,7 +12,7 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragmentColor;
out vec4 frag_Diffuse;
void main()
{
@@ -21,7 +21,12 @@ void main()
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel;
//frag_Diffuse = vec4(LightingTexel.rgb, 0.0);
//frag_Diffuse = DiffuseTexel * ((vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
//frag_Diffuse = LightingTexel;
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
}
+41 -1
View File
@@ -1,8 +1,23 @@
#version 430
uniform vec4 Color;
uniform vec3 La;
uniform vec3 directionToSun;
uniform mat4 V;
layout(binding=0) uniform sampler2D texture0;
layout(binding=1) uniform sampler2D PositionTexture;
layout(binding=2) uniform sampler2D NormalsTexture;
layout(binding=3) uniform sampler2D SpecularTexture;
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 100;
in VertexData {
vec3 Position;
@@ -12,9 +27,34 @@ in VertexData {
out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
//Diffuse Sunlight
vec3 directionToLight = normalize(vec3(V * vec4(directionToSun, 0.0)));
float dotProdLight = dot(directionToLight, normal);
dotProdLight = max(dotProdLight, 0.0);
vec3 sId = kd * SunDiffuseLight * dotProdLight;
//Specular Sunlight
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
}
void main() {
// Texture
vec4 texel = texture(texture0, Input.TextureCoord);
vec4 PositionTexel = texture(PositionTexture, Input.TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, Input.TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, Input.TextureCoord);
frag_Diffuse = texel * Color;
//frag_Diffuse = texel * Color * (vec4(La, 0.0) * phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel)));
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
}
+5 -2
View File
@@ -24,6 +24,7 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData
@@ -32,7 +33,7 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragColor;
out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
@@ -67,6 +68,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * vec4(1.0/La, 0.0) * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0));
//FragColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0)) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0);
//FragColor = NormalTexel;
}
+4 -2
View File
@@ -1,6 +1,7 @@
#version 430
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 P;
layout(location = 0) in vec3 Position;
@@ -11,6 +12,7 @@ out VertexData
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
vec4 pos = V * vec4(Position, 1.0);
gl_Position = P * pos;
Output.TextureCoord = Position;
}
+10 -5
View File
@@ -4,6 +4,7 @@ layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture;
layout (binding=2) uniform sampler2D SpecularTexture;
uniform vec2 ViewportSize;
uniform mat4 MVP;
uniform mat4 M;
@@ -16,10 +17,12 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(0.3, 0.3, 0.3);
const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 5;
const float specularExponent = 100;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData
@@ -28,7 +31,7 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragColor;
out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
@@ -46,7 +49,7 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
return vec4((sId + La), sIs.r);
}
void main()
@@ -56,6 +59,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(normalize(NormalTexel)), vec3(SpecularTexel));
frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0)));
//FragColor = NormalTexel;
}
+2 -2
View File
@@ -4,6 +4,7 @@
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Health>([]() { return new Components::Health(); });
cf->Register<Components::DamageModel>([]() { return new Components::DamageModel(); });
}
void Systems::DamageSystem::Initialize()
@@ -20,10 +21,9 @@ bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
health->Amount -= event.Amount;
if(health->Amount <= 0)
{
Events::OnDead e;
Events::Dead e;
e.Entity = event.Entity;
EventBroker->Publish(e);
}
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
return true;
}
+2 -1
View File
@@ -4,8 +4,9 @@
#include "System.h"
#include "Components/Health.h"
#include "Components/DamageModel.h"
#include "Events/Damage.h"
#include "Events/OnDead.h"
#include "Events/Dead.h"
namespace Systems
{
+1 -1
View File
@@ -20,7 +20,7 @@ bool Systems::DebugSystem::OnKeyDown(const Events::KeyDown &event)
if (event.KeyCode == GLFW_KEY_ENTER)
{
Events::PlaySFX e;
e.Emitter = 0;
e.Position = glm::vec3(0);
e.Resource = "Sounds/korvring.wav";
EventBroker->Publish<Events::PlaySFX>(e);
+63
View File
@@ -0,0 +1,63 @@
#include "PrecompiledHeader.h"
#include "FlagSystem.h"
#include "World.h"
void Systems::FlagSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Flag>([]() { return new Components::Flag(); });
}
void Systems::FlagSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EEnterTrigger, &Systems::FlagSystem::OnEnterTrigger);
}
void Systems::FlagSystem::Update( double dt )
{
}
void Systems::FlagSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
}
bool Systems::FlagSystem::OnEnterTrigger( const Events::EnterTrigger &event )
{
auto JeepSteeringComponent = m_World->GetComponent<Components::JeepSteering>(event.Entity);
if(!JeepSteeringComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID == playerComponent->ID)
return false;
auto flagComponent = m_World->GetComponent<Components::Flag>(event.Trigger);
if(!flagComponent)
return false;
PickUpFlag(event.Entity, event.Trigger);
return true;
}
void Systems::FlagSystem::PickUpFlag( EntityID entity, EntityID trigger )
{
m_World->RemoveComponent<Components::Trigger>(trigger);
m_World->SetEntityParent(trigger, entity);
auto triggerTransform = m_World->GetComponent<Components::Transform>(trigger);
triggerTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
auto teamComponent = m_World->GetComponent<Components::Team>(trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
Events::FlagPickup ePickup;
ePickup.Player = playerComponent->ID;
EventBroker->Publish(ePickup);
}
+44
View File
@@ -0,0 +1,44 @@
#ifndef FlagSystem_h__
#define FlagSystem_h__
#include "System.h"
#include "Components/Flag.h"
#include "Components/Player.h"
#include "Components/Team.h"
#include "Components/Trigger.h"
#include "Components/Transform.h"
#include "Components/JeepSteering.h"
#include "Events/FlagCaptured.h"
#include "Events/FlagDropped.h"
#include "Events/FlagPickup.h"
#include "Events/FlagReturned.h"
#include "Events/EnterTrigger.h"
namespace Systems
{
class FlagSystem : public System
{
public:
FlagSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
EventRelay<FlagSystem, Events::EnterTrigger> m_EEnterTrigger;
bool OnEnterTrigger(const Events::EnterTrigger &event);
void PickUpFlag(EntityID entity, EntityID trigger);
};
}
#endif // DamageSystem_h__
+22
View File
@@ -0,0 +1,22 @@
#include "PrecompiledHeader.h"
#include "GameStateSystem.h"
#include "World.h"
void Systems::GameStateSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EFlagCaptured, &Systems::GameStateSystem::OnFlagCaptured);
}
bool Systems::GameStateSystem::OnFlagCaptured(const Events::FlagCaptured &event)
{
m_InGame = false;
Events::GameOver e1;
e1.Player = event.Player;
EventBroker->Publish(e1);
Events::PlayBGM e2;
e2.Resource = "Sounds/BGM/WilliamTellOverture.mp3";
EventBroker->Publish(e2);
return true;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef GameStateSystem_h__
#define GameStateSystem_h__
#include <set>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Player.h"
#include "Events/FlagCaptured.h"
#include "Events/GameOver.h"
#include "Events/PlayBGM.h"
namespace Systems
{
class GameStateSystem : public System
{
public:
GameStateSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
, m_InGame(true)
{ }
void Initialize() override;
bool InGame() const { return m_InGame; }
private:
bool m_InGame;
EventRelay<GameStateSystem, Events::FlagCaptured> m_EFlagCaptured;
bool OnFlagCaptured(const Events::FlagCaptured &event);
};
}
#endif // GameStateSystem_h__
+49 -5
View File
@@ -34,6 +34,14 @@ bool Systems::GarageSystem::OnEnterTrigger(const Events::EnterTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -56,6 +64,15 @@ bool Systems::GarageSystem::OnLeaveTrigger(const Events::LeaveTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -76,19 +93,46 @@ bool Systems::GarageSystem::OnCommand(const Events::InputCommand &event)
{
EntityID trigger = pair.first;
auto entities = pair.second;
std::string name = m_World->GetProperty<std::string>(trigger, "Name");
if (name != "ElevatorShaftTrigger")
continue;
auto triggerBaseParent = m_World->GetEntityBaseParent(trigger);
auto triggerPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
auto triggerTeamComponent = m_World->GetComponent<Components::Team>(trigger);
if (!triggerTeamComponent)
continue;
for (EntityID entity : entities)
{
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
if (triggerPlayerComponent == entityPlayerComponent)
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(entity);
if(!entityPlayerComponent)
continue;
if (entityPlayerComponent->ID != event.PlayerID)
continue;
if (triggerTeamComponent->TeamID == entityPlayerComponent->ID)
{
auto components = m_World->GetComponentsOfType<Components::Flag>();
for (auto &component : *components)
{
auto teamComponent = m_World->GetComponent<Components::Team>(component->Entity);
if(!teamComponent)
continue;
auto parent = m_World->GetEntityParent(component->Entity);
if(parent != entity)
continue;
if(teamComponent->TeamID != entityPlayerComponent->ID)
{
Events::FlagCaptured e;
e.Player = entityPlayerComponent->ID;
EventBroker->Publish(e);
}
}
EntityID garage = m_World->GetEntityParent(trigger);
auto garageComponent = m_World->GetComponent<Components::Garage>(garage);
ToggleGarage(garageComponent);
+3
View File
@@ -18,6 +18,9 @@
#include "Events/Rotate.h"
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Team.h"
#include "Components/Flag.h"
#include "Events/FlagCaptured.h"
namespace Systems
{
+355
View File
@@ -0,0 +1,355 @@
#include "PrecompiledHeader.h"
#include "JeepSteeringSystem.h"
#include "World.h"
void Systems::JeepSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::JeepSteering>([]() { return new Components::JeepSteering(); });
}
void Systems::JeepSteeringSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::JeepSteeringSystem::OnSpawnVehicle);
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i] = std::shared_ptr<JeepSteeringInputController>(new JeepSteeringInputController(EventBroker, i + 1));
}
}
void Systems::JeepSteeringSystem::Update(double dt)
{
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i]->Update(dt);
}
}
void Systems::JeepSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto tankSteeringComponent = m_World->GetComponent<Components::JeepSteering>(entity);
if(!tankSteeringComponent)
return;
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
if (!playerComponent)
return;
if (playerComponent->ID == 0)
return;
auto inputController = m_JeepInputControllers[playerComponent->ID - 1];
Events::JeepSteer eSteering;
eSteering.Entity = entity;
eSteering.PositionX = inputController->PositionX;
eSteering.PositionY = inputController->PositionY;
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
}
bool Systems::JeepSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event)
{
if (event.VehicleType != "Jeep")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
// Create a Jeep
EntityID Jeep = CreateJeep(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(Jeep);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(Jeep, "Camera");
if (event.PlayerID == 1)
e.ViewportFrame = "Viewport1";
else if (event.PlayerID == 2)
e.ViewportFrame = "Viewport2";
EventBroker->Publish(e);
}
return true;
}
EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID)
{
auto jeep = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(jeep);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(jeep);
physics->Mass = 2000;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
physics->CenterOfMass = glm::vec3(0, 0, 0);
auto vehicle = m_World->AddComponent<Components::Vehicle>(jeep);
vehicle->MaxTorque = 500.0f;
vehicle->MaxSteeringAngle = 40.f;
vehicle->MaxSpeedFullSteeringAngle = 12.f;
vehicle->MinRPM = 1000.0f;
vehicle->OptimalRPM = 5500.0f,
vehicle->MaxRPM = 7500.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 5.f;
vehicle->UpshiftRPM = 6500.0f;
vehicle->DownshiftRPM = 3500.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(jeep);
player->ID = playerID;
auto jeepSteering = m_World->AddComponent<Components::JeepSteering>(jeep);
m_World->AddComponent<Components::Input>(jeep);
auto health = m_World->AddComponent<Components::Health>(jeep);
health->Amount = 100.f;
/*{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto meshShape = m_World->AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
m_World->CommitEntity(shape);
}*/
{
auto chassis = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = m_World->AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Jeep/Chassi/Chassi.OBJ";
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.0219f ,0.88937f, -0.48469f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.993f;
box->Height = 0.626f;
box->Depth = 1.316f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.02551f ,0.55419f, 1.78935f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.849f;
box->Height = 0.415f;
box->Depth = 1.058f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
auto cameraTower = m_World->CreateEntity(jeep);
{
auto transform = m_World->AddComponent<Components::Transform>(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<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
m_World->SetProperty(jeep, "Camera", cameraTower);
}
#pragma region Wheels
//Create wheels
float wheelOffset = 0.f;//-0.83f;
const float suspensionStrength = 15.f;
const float springLength = 0.3f;
AddJeepWheels(jeep);
#pragma endregion
{
auto entity = m_World->CreateEntity(jeep);
auto transformComponent = m_World->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 = m_World->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));
m_World->CommitEntity(entity);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(particleEntity);
}
m_World->CommitEntity(jeep);
return jeep;
}
void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity)
{
//Create wheels
float wheelOffset = 0.5f;
float springLength = 0.2f;
float suspensionStrength = 35.f;
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
}
void Systems::JeepSteeringSystem::JeepSteeringInputController::Update( double dt )
{
PositionX = m_Horizontal;
PositionY = m_Vertical;
}
bool Systems::JeepSteeringSystem::JeepSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != this->PlayerID)
return false;
float val = event.Value;
// Tank
if (event.Command == "horizontal")
{
m_Horizontal = val;
}
else if (event.Command == "jeep_vertical")
{
m_Vertical = -val;
}
else if (event.Command == "handbrake")
{
Handbrake = val > 0;
}
return true;
}
+93
View File
@@ -0,0 +1,93 @@
#include <array>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Physics.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
#include "Components/Health.h"
#include "Components/Trigger.h"
#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 "Components/JeepSteering.h"
#include "Events/JeepSteer.h"
#include "Components/Team.h"
#include "Events/SetViewportCamera.h"
namespace Systems
{
class JeepSteeringSystem : public System
{
public:
JeepSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
std::map<EntityID, double> m_TimeSinceLastShot;
EventRelay<JeepSteeringSystem, Events::SpawnVehicle> m_ESpawnVehicle;
bool OnSpawnVehicle(const Events::SpawnVehicle &e);
class JeepSteeringInputController;
std::array<std::shared_ptr<JeepSteeringInputController>, 4> m_JeepInputControllers;
EntityID CreateJeep(int playerID);
void AddJeepWheels(EntityID jeepEntity);
};
class JeepSteeringSystem::JeepSteeringInputController : InputController<JeepSteeringSystem>
{
public:
JeepSteeringInputController(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;
}
int PlayerID;
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;
};
}
+23 -6
View File
@@ -49,11 +49,15 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
{
emitterComponent->TimeSinceLastSpawn += dt;
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity);
// if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
// {
// SpawnParticles(entity);
// emitterComponent->TimeSinceLastSpawn = 0;
// }
if(emitterComponent->Emitting)
{
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{
SpawnParticles(entity);
emitterComponent->TimeSinceLastSpawn = 0;
}
}
}
auto particleComponent = m_World->GetComponent<Components::Particle>(entity);
@@ -235,17 +239,23 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect
bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e)
{
LOG_INFO("Spawning an explosion");
auto explosion = m_World->CreateEntity();
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
emitter->LifeTime = e.LifeTime;
emitter->SpawnCount = e.ParticlesToSpawn;
emitter->Speed = e.Speed;
emitter->SpreadAngle = e.SpreadAngle;
emitter->Emitting = e.Emitting;
emitter->SpawnFrequency = e.SpawnFrequency;
//emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale));
emitter->SpawnFrequency = e.LifeTime + 20; //temp
emitter->Fade = true;
emitter->Color = e.Color;
if(e.UseGoalVector)
{
emitter->UseGoalVelocity = e.UseGoalVector;
emitter->GoalVelocity = e.GoalVelocity;
}
std::vector<glm::vec3> scale;
scale.push_back(glm::vec3(e.ParticleScale[0]));
if(e.ParticleScale.size() >= 2)
@@ -258,6 +268,13 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e)
auto templateComponent = m_World->AddComponent<Components::Template>(particleEnt);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
if(e.usePointLight)
{
auto light = m_World->AddComponent<Components::PointLight>(particleEnt);
light->Diffuse = glm::vec3(231.f/255.f, 181.f/255.f, 48.f/255.f);
light->Specular = glm::vec3(0.5f, 0.5f, 0.5f);
light->Radius = 20.f;
}
spriteComponent->SpriteFile = e.spritePath;
m_World->CommitEntity(particleEnt);
emitter->ParticleTemplate = particleEnt;
+1
View File
@@ -5,6 +5,7 @@
#include "Systems/TransformSystem.h"
#include "Components/Transform.h"
#include "Components/ParticleEmitter.h"
#include "Components/PointLight.h"
#include "Components/Particle.h"
#include "Components/Sprite.h"
#include "EventBroker.h"
+140 -72
View File
@@ -33,11 +33,13 @@ void Systems::PhysicsSystem::Initialize()
// Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_EJeepSteer, &Systems::PhysicsSystem::OnJeepSteer);
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
EVENT_SUBSCRIBE_MEMBER(m_EEnableCollisions, &Systems::PhysicsSystem::OnEnableCollisions);
EVENT_SUBSCRIBE_MEMBER(m_EDisableCollisions, &Systems::PhysicsSystem::OnDisableCollisions);
EVENT_SUBSCRIBE_MEMBER(m_EDead, &Systems::PhysicsSystem::OnDead);
hkMemorySystem::FrameInfo finfo(10000 * 1024); // Allocate 10MB of Physics solver buffer
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
@@ -180,6 +182,12 @@ void Systems::PhysicsSystem::Update(double dt)
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity);
}
/*auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity);*/
m_PhysicsWorld->markForWrite();
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
@@ -247,7 +255,8 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
}
}*/
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(car);
vehicleComponent->currentRPM = m_Vehicles[car]->calcRPM();
m_Vehicles[car]->getChassis()->activate();
@@ -271,14 +280,13 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
// TODO: No support for Scale, MIGHT be possible
// HACK: WTF IS THIS?
if (transformComponentParent)
{
transformComponent->Position -= transformComponentParent->Position;
transformComponent->Position = transformComponent->Position * transformComponentParent->Orientation;
transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation);
auto absoluteTransformParent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(parent);
transformComponent->Position -= absoluteTransformParent.Position;
transformComponent->Position = transformComponent->Position * absoluteTransformParent.Orientation;
transformComponent->Orientation = glm::inverse(absoluteTransformParent.Orientation) * transformComponent->Orientation;
}
}
@@ -736,47 +744,6 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
LOG_INFO("%s", msg);
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
@@ -818,41 +785,42 @@ bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpuls
void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string type, Component* component)
{
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed Trigger of entity %i", entity);
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
}
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
{
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed rigid body of entity %i", entity);
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
if(m_ListShapes.find(entity) != m_ListShapes.end())
{
m_ListShapes[entity]->removeReference();
m_ListShapes.erase(entity);
}
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
if(m_Vehicles.find(entity) != m_Vehicles.end())
if (m_Vehicles.find(entity) != m_Vehicles.end())
{
m_PhysicsWorld->markForWrite();
m_Vehicles[entity]->removeFromWorld();
m_PhysicsWorld->unmarkForWrite();
m_Vehicles.erase(entity);
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
}
else if (m_RigidBodies.find(entity) != m_RigidBodies.end())
{
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
/*
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed rigid body of entity %i abogfusdkifbhdzfsgiudfhghdfhgdhfögödhfgödhfödhfödfjhödgfdgföuhudgf", entity);
m_PhysicsWorld->markForWrite();
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_PhysicsWorld->unmarkForWrite();
m_RigidBodies.erase(entity);
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
}*/
}
bool Systems::PhysicsSystem::OnEnableCollisions( const Events::EnableCollisions &e )
@@ -872,3 +840,103 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
m_PhysicsWorld->unmarkForWrite();
return true;
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnJeepSteer( const Events::JeepSteer &event )
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnDead( const Events::Dead &e )
{
if(m_Vehicles.find(e.Entity) != m_Vehicles.end())
{
m_World->RemoveEntity(e.Entity);
//EntityID camera = m_World->GetProperty<EntityID>(e.Entity, "Camera");
//m_World->RemoveComponent<Components::Camera>(camera);
//auto transform = m_World->GetComponent<Components::Transform>(e.Entity);
//transform->Position = glm::vec3(0, -10000.f, 0);
////m_RigidBodies[e.Entity]->setPosition(hkVector4(0, -10000, 0));
///*m_Vehicles.erase(e.Entity);
//m_RigidBodyEntities.erase(m_RigidBodies[e.Entity]);
//m_RigidBodies.erase(e.Entity);*/
//auto jeep = m_World->GetComponent<Components::JeepSteering>(e.Entity);
//if(jeep)
//{
// m_World->RemoveComponent<Components::JeepSteering>(e.Entity);
//}
//auto tank = m_World->GetComponent<Components::TankSteering>(e.Entity);
//if(tank)
//{
// m_World->RemoveComponent<Components::TankSteering>(e.Entity);
//}
auto listener = m_World->GetComponent<Components::Listener>(e.Entity);
if (listener)
{
m_World->RemoveComponent<Components::Listener>(e.Entity);
}
}
return true;
}
+10 -2
View File
@@ -86,8 +86,12 @@
#include "Events/DisableCollisions.h"
#include "Components/Trigger.h"
#include "Components/Template.h"
#include "Components/Camera.h"
#include "Components/Listener.h"
#include "Events/EnterTrigger.h"
#include "Events/JeepSteer.h"
#include "Events/Dead.h"
#include "Components/JeepSteering.h"
namespace Systems
{
@@ -110,7 +114,6 @@ public:
e.Entity1 = entity1;
e.Entity2 = entity2;
m_PhysicsSystem->EventBroker->Publish(e);
LOG_INFO("CollisionEvent!");
}
private:
@@ -178,6 +181,8 @@ private:
// Events
EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
bool OnTankSteer(const Events::TankSteer &event);
EventRelay<PhysicsSystem, Events::JeepSteer> m_EJeepSteer;
bool OnJeepSteer(const Events::JeepSteer &event);
EventRelay<PhysicsSystem, Events::SetVelocity> m_ESetVelocity;
bool OnSetVelocity(const Events::SetVelocity &event);
EventRelay<PhysicsSystem, Events::ApplyForce> m_EApplyForce;
@@ -189,6 +194,9 @@ private:
bool OnEnableCollisions(const Events::EnableCollisions &e);
EventRelay<PhysicsSystem, Events::DisableCollisions> m_EDisableCollisions;
bool OnDisableCollisions(const Events::DisableCollisions &e);
EventRelay<PhysicsSystem, Events::Dead> m_EDead;
bool OnDead(const Events::Dead &e);
void SetUpPhysicsState(EntityID entity, EntityID parent);
void TearDownPhysicsState(EntityID entity, EntityID parent);
+60 -35
View File
@@ -2,16 +2,21 @@
#include "SoundSystem.h"
#include "World.h"
Systems::SoundSystem::~SoundSystem()
{
FMOD_System_Release(m_System);
}
void Systems::SoundSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX);
EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound);
m_isPlaying = false;
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
FMOD_System_Create(&m_System);
FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED, 0);
FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_ENABLE_PROFILE, 0);
if(result != FMOD_OK)
{
LOG_ERROR("Did initialized load FMOD correctly");
@@ -20,7 +25,7 @@ void Systems::SoundSystem::Initialize()
{
LOG_INFO("FMOD initialized successfully");
}
FMOD_System_Set3DSettings(m_System, 1.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale
FMOD_System_Set3DSettings(m_System, 0.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale
}
@@ -44,20 +49,33 @@ void Systems::SoundSystem::Update(double dt)
std::map<EntityID, FMOD_CHANNEL*>::iterator it;
for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();)
{
FMOD_BOOL *isPlaying = false;
FMOD_Channel_IsPlaying(it->second, isPlaying);
if(isPlaying)
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
if(m_isPlaying)
{
it++;
}
else
{
FMOD_Sound_Release(m_DeleteSounds[it->first]);
m_DeleteSounds.erase(it->first);
// FMOD_Sound_Release(m_DeleteSounds[it->first]);
m_DeleteSounds.erase(it->first);
it = m_DeleteChannels.erase(it);
}
}
//LOG_INFO("Antal emitters i listan: %i", m_Channels.size());
for(it = m_Channels.begin(); it != m_Channels.end();)
{
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
if(!m_isPlaying)
{
it = m_Channels.erase(it);
}
else
{
it++;
}
}
}
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -119,7 +137,7 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
float maxDist = emitter->MaxDistance;
float minDist = emitter->MinDistance;
float pitch = emitter->Pitch;
//LoadSound(sound, path, maxDist, minDist);
LoadSound(sound, path, maxDist, minDist);
m_Channels.insert(std::make_pair(emitter->Entity, channel));
m_Sounds.insert(std::make_pair(emitter->Entity, sound));
}
@@ -128,47 +146,54 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
{
auto emitter = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
if(!emitter)
{
LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter];
return false;
}
auto eEntity = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(eEntity);
eTransform->Position = event.Position;
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(eEntity);
eComponent->MinDistance = event.MinDistance;
eComponent->MaxDistance= event.MaxDistance;
eComponent->Loop = event.Loop;
eComponent->Gain = event.Volume;
emitter->type = Components::SoundEmitter::SoundType::SOUND_3D;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
Sound* sound = ResourceManager->Load<Sound>("Sound3D", event.Resource);
m_Sounds[event.Emitter] = *sound;
FMOD_Sound_Set3DMinMaxDistance(*sound, emitter->MinDistance, emitter->MaxDistance);
m_Sounds[eEntity] = *sound;
FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance);
PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop);
FMOD_System_Update(m_System);
FMOD_BOOL isPlaying = false;
FMOD_Channel_IsPlaying(m_Channels[event.Emitter], &isPlaying);
if(!isPlaying)
LOG_ERROR("FMOD: File %s is not playing", event.Resource.c_str());
else
LOG_INFO("Now playing sound %s", event.Resource.c_str());
PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop);
return true;
}
bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event)
{
auto emitter = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(emitter);
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(emitter);
m_Channels[emitter] = m_BGMChannel;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
FMOD_RESULT result;
result = FMOD_Channel_Stop(m_BGMChannel);
if(result != FMOD_OK)
LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource);
m_Sounds[emitter] = *sound;
FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]);
result = FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel);
if(result != FMOD_OK)
LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
FMOD_Channel_SetMode(m_BGMChannel, FMOD_LOOP_NORMAL);
FMOD_Sound_SetLoopCount(*sound, -1);
return true;
}
bool Systems::SoundSystem::StopSound(const Events::StopSound &event)
{
FMOD_Channel_Stop(m_Channels[event.Emitter]);
auto eComp = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
if(eComp)
{
FMOD_Channel_Stop(m_Channels[event.Emitter]);
}
else
{
FMOD_Channel_Stop(m_BGMChannel);
}
return true;
}
+3 -3
View File
@@ -24,13 +24,12 @@ public:
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
{ }
~SoundSystem();
void RegisterComponents(ComponentFactory* cf) override;
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
//void OnComponentRemoved(std::string type, Component* component);
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
FMOD_SYSTEM* GetFMODSystem() const { return m_System; }
private:
@@ -48,12 +47,13 @@ private:
void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop);
FMOD_SYSTEM* m_System;
FMOD_BOOL m_isPlaying;
FMOD_CHANNEL* m_BGMChannel;
std::vector<EntityID> m_Listeners;
std::map<EntityID, FMOD_CHANNEL*> m_Channels;
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
};
+231 -36
View File
@@ -30,6 +30,45 @@ void Systems::TankSteeringSystem::Update(double dt)
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto pEmitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
if(pEmitter)
{auto tankTransform = m_World->GetComponent<Components::Transform>(parent);
if(!m_World->GetComponent<Components::TankSteering>(parent))
return;
glm::vec2 velXZ = glm::vec2(tankTransform->Velocity.x, tankTransform->Velocity.z);
float speedMPDT = glm::length(velXZ);
if(speedMPDT < 1)
{
pEmitter->Emitting = false;
return;
}
else
{
pEmitter->Emitting = true;
pEmitter->ScaleSpectrum.erase(pEmitter->ScaleSpectrum.begin());
float scale = speedMPDT / 20;
scale = glm::clamp(scale, 0.3f, 20.f);
pEmitter->ScaleSpectrum.push_back(glm::vec3(speedMPDT / 20));
float spawnFrequency = 1 / speedMPDT;
spawnFrequency = glm::clamp(spawnFrequency, 0.1f, 2.f);
pEmitter->SpawnFrequency = 1 / speedMPDT;
}
}
auto vehicleComp = m_World->GetComponent<Components::Vehicle>(entity);
if(vehicleComp)
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform->Position.y < -15 && transform->Position.y > -100)
{
Events::Dead e;
e.Entity = entity;
EventBroker->Publish(e);
}
}
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
if(!tankSteeringComponent)
return;
@@ -50,7 +89,6 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
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);
@@ -65,7 +103,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
{
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
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;
@@ -81,7 +119,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
transformComponent->Orientation = glm::quat(angles);
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
{
@@ -90,17 +128,55 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(eSetVelocity);
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
{
Events::PlaySFX e;
e.Resource = "Sounds/SFX/TankShot.mp3";
e.Position = cloneTransform->Position;
e.Loop = false;
EventBroker->Publish(e);
}
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
//1,670m/s
//25kg
Events::ApplyPointImpulse ePointImpulse ;
Events::ApplyPointImpulse ePointImpulse;
ePointImpulse.Entity = entity;
ePointImpulse.Position = absoluteTransform.Position;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f;
@@ -152,6 +228,37 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
e.ParticleScale.push_back(8);
e.ParticlesToSpawn = 20;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6, 0.6, 0.6, 1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(12);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(15);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.usePointLight = true;
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
/*Events::CreateExplosion e;
e.ParticlesToSpawn = 20;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
@@ -177,30 +284,80 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);*/
// Events::CreateExplosion e;
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180) / 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(5.f,5.f,5.f,1);
//
// EventBroker->Publish(e);
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180)/ 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(1.f,1.f,1.f,1);
// EventBroker->Publish(e);
}
{
Events::PlaySFX e;
e.MinDistance = 150.f;
e.Position = shellTransform->Position;
e.Resource = "Sounds/SFX/Explosion.wav";
EventBroker->Publish(e);
}
// Direct damage
auto health = m_World->GetComponent<Components::Health>(otherEntity);
if (health)
{
Events::Damage d;
d.Entity = otherEntity;
d.Amount = shellComponent->Damage;
EventBroker->Publish(d);
}
// Splash damage
for (auto &physComponent : *physicsComponents)
{
EntityID physicsEntity = std::dynamic_pointer_cast<Components::Physics>(physComponent)->Entity;
auto physEntityTransform = m_World->GetComponent<Components::Transform>(physicsEntity);
EntityID physicsEntity = physComponent->Entity;
// No splash damage to the direct hit target
if (physicsEntity == otherEntity)
continue;
auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(physicsEntity);
float distance = glm::distance(physEntityTransform->Position, shellTransform->Position);
float distance = glm::distance(physEntityTransform.Position, shellTransform->Position);
if (distance <= shellComponent->ExplosionRadius)
{
// DO STUFF! :D
float radius = shellComponent->ExplosionRadius;
float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength;
glm::vec3 direction = glm::normalize(physEntityTransform->Position - shellTransform->Position);
glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position);
Events::ApplyPointImpulse e;
e.Entity = physicsEntity;
e.Impulse = direction * strength;
e.Position = physEntityTransform->Position;
e.Position = physEntityTransform.Position;
EventBroker->Publish(e);
auto health = m_World->GetComponent<Components::Health>(physicsEntity);
if(health)
if (health && health->VulnerableToSplash)
{
Events::Damage d;
d.Entity = physicsEntity;
@@ -292,7 +449,7 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
{
if (event.VehicleType != "Tank")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
@@ -300,12 +457,19 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
return false;
}
for (auto &spawnPointComponent : *spawnPointComponents)
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = spawnPointComponent->Entity;
auto spawnPointBaseParent = m_World->GetEntityBaseParent(spawnPoint);
auto playerComponent = m_World->GetComponent<Components::Player>(spawnPointBaseParent);
if (!playerComponent || playerComponent->ID != event.PlayerID)
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
@@ -313,8 +477,8 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
// Create a tank
EntityID tank = CreateTank(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(tank);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(tank, "Camera");
@@ -341,13 +505,30 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
vehicle->MinRPM = 200.0f;
vehicle->OptimalRPM = 2500.0f,
vehicle->MaxRPM = 4000.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 1.f;
vehicle->UpshiftRPM = 3500.0f;
vehicle->DownshiftRPM = 1000.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = m_World->AddComponent<Components::TankSteering>(tank);
m_World->AddComponent<Components::Input>(tank);
m_World->AddComponent<Components::Listener>(tank);
auto health = m_World->AddComponent<Components::Health>(tank);
health->Amount = 100.f;
health->Amount = 200.f;
{
auto shape = m_World->CreateEntity(tank);
auto transform = m_World->AddComponent<Components::Transform>(shape);
@@ -410,14 +591,14 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto tankShellComponent = m_World->AddComponent<Components::TankShell>(shot);
tankShellComponent->Damage = 20.f;
tankShellComponent->ExplosionRadius = 30.f;
tankShellComponent->ExplosionStrength = 300000.f;
tankShellComponent->ExplosionRadius = 20.f;
tankShellComponent->ExplosionStrength = 140.f;
{
auto shape = m_World->CreateEntity(shot);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto boxShape = m_World->AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Width = 0.1f;
boxShape->Height = 0.1f;
boxShape->Depth = 0.5f;
m_World->CommitEntity(shape);
}
@@ -433,6 +614,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = m_World->AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
/*auto follow = m_World->AddComponent<Components::Follow>(cameraTower);
follow->Entity = barrel;
follow->Distance = 15.f;
@@ -481,31 +664,43 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false);
#pragma endregion
#pragma region DustParticles
std::vector<glm::vec3> ePos;
ePos.push_back(glm::vec3(-2, -1.7, 2.0));
ePos.push_back(glm::vec3(2, -1.7, 2.0));
ePos.push_back(glm::vec3(2, -1.7, -2.0));
ePos.push_back(glm::vec3(-2, -1.7, -2.0));
for (int i = 0; i < 4; i++)
{
auto entity = m_World->CreateEntity(tank);
auto transformComponent = m_World->AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
transformComponent->Position = ePos[i];
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = m_World->AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpawnCount = 1;
emitterComponent->SpawnFrequency = 0.1;
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));
m_World->CommitEntity(entity);
emitterComponent->LifeTime = 0.3;
emitterComponent->Speed = 3;
emitterComponent->Emitting = true;
emitterComponent->Fade = true;
emitterComponent->ScaleSpectrum.push_back(glm::vec3(1));
//emitterComponent->Color = glm::vec4(1);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
m_World->AddComponent<Components::Template>(particleEntity);
m_World->AddComponent<Components::Transform>(particleEntity);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
spriteComponent->SpriteFile = "Textures/Sprites/Dirt.png";
m_World->CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(entity);
}
#pragma endregion
m_World->CommitEntity(tank);
+8 -1
View File
@@ -1,5 +1,4 @@
#include <array>
#include "System.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
@@ -15,6 +14,7 @@
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Components/Team.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
@@ -22,6 +22,8 @@
#include "Components/Health.h"
#include "Components/TankShell.h"
#include "Components/SphereShape.h"
#include "Components/Listener.h"
#include "Components/SoundEmitter.h"
#include "Events/EnableCollisions.h"
#include "Events/DisableCollisions.h"
@@ -29,6 +31,10 @@
#include "Components/TriggerExplosion.h"
#include "Components/FrameTimer.h"
#include "Events/PlaySFX.h"
#include "Events/PlayBGM.h"
#include "Events/Dead.h"
#include "Events/Damage.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
@@ -44,6 +50,7 @@
#include "Components/Input.h"
#include "Events/SetViewportCamera.h"
#include "Events/GameOver.h"
namespace Systems
{
+383
View File
@@ -0,0 +1,383 @@
#include "PrecompiledHeader.h"
#include "TowerSystem.h"
#include "World.h"
void Systems::TowerSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Tower>([]() { return new Components::Tower(); });
cf->Register<Components::Turret>([]() { return new Components::Turret(); });
cf->Register<Components::TurretShot>([]() {return new Components::TurretShot(); });
cf->Register<Components::TowerDebris>([]() {return new Components::TowerDebris(); });
}
void Systems::TowerSystem::Initialize()
{
//EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage);
EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TowerSystem::OnCollision);
EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage);
Temp_m_TimeSinceLastShot = 0;
}
void Systems::TowerSystem::Update( double dt )
{
}
bool Systems::TowerSystem::Damage( const Events::Damage &event )
{
auto debrisComponent = m_World->GetComponent<Components::TowerDebris>(event.Entity);
if(!debrisComponent)
{
return false;
}
LOG_INFO("TowerSystem::Damage");
// Change to damage model
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
return false;
}
LOG_INFO("Entity %i is dead", event.Entity);
auto entitytransform = m_World->GetComponent<Components::Transform>(event.Entity);
if(!entitytransform)
return false;
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
// Spawn debris
for(auto d : debrisComponent->TowerDebrisIDs)
{
auto debris = m_World->CloneEntity(d);
auto transform = m_World->GetComponent<Components::Transform>(debris);
Components::Transform absolutetransformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(debris);
transform->Orientation = transform->Orientation * transformComponent.Orientation;
transform->Position = transform->Orientation * transform->Position + transformComponent.Position;
//DO STUFF! :D
float distance = glm::distance(transform->Position, transformComponent.Position);
float radius = 15.f;
float strength = (1.f - pow(distance / radius, 2)) * 2000.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);
}
entitytransform->Position = glm::vec3(0.f, -50000000.f, 0.f);
return true;
}
void Systems::TowerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
auto towerComponent = m_World->GetComponent<Components::Tower>(entity);
if(!towerComponent)
return;
Components::Transform absoluteTowerGunTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(towerComponent->Gun);
auto towerGunTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->Gun);
if(!towerGunTransformComponent)
return;
auto towerGunBaseTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->GunBase);
if(!towerGunBaseTransformComponent)
return;
auto turretComponent = m_World->GetComponent<Components::Turret>(entity);
if(!turretComponent)
return;
auto players = m_World->GetComponentsOfType<Components::Player>();
if (!players)
return;
for(auto player : *players)
{
auto playerComponent = std::dynamic_pointer_cast<Components::Player>(player);
if(towerComponent->ID == playerComponent->ID) //!= betyder att den bara targetar sitt eget lag, == fienden.
continue;
auto playerTransform = m_World->GetComponent<Components::Transform>(player->Entity);
if(!playerTransform)
continue;
Components::Transform absolutePlayerTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(player->Entity);
if(glm::distance(absolutePlayerTransform.Position, absoluteTowerGunTransform.Position) > 45.f)
continue;
//Rotate the turret towards the enemy player
glm::quat baseLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absoluteTowerGunTransform.Position.y, absolutePlayerTransform.Position.z), glm::vec3(0, 1, 0))));
glm::quat gunLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absolutePlayerTransform.Position.y, absolutePlayerTransform.Position.z ), glm::vec3(0, 1, 0))));
towerGunTransformComponent->Orientation = glm::inverse(baseLookAt) * gunLookAt;
towerGunBaseTransformComponent->Orientation = baseLookAt;
#pragma region GetShotDirectionAndLaunchShot
Temp_m_TimeSinceLastShot += dt;
if(Temp_m_TimeSinceLastShot > 1)
{
{
//Shoot code
EntityID clone = m_World->CloneEntity(turretComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(turretComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Orientation = templateAbsoluteTransform.Orientation;
cloneTransform->Position = templateAbsoluteTransform.Position - (cloneTransform->Orientation* glm::vec3(0.97163f, 0.f, 0.f));
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = gunLookAt * glm::vec3(0.f, 0.f, -1.f) * turretComponent->ShotSpeed;
EventBroker->Publish(eSetVelocity);
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
}
{
EntityID clone = m_World->CloneEntity(turretComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(turretComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Orientation = templateAbsoluteTransform.Orientation;
cloneTransform->Position = templateAbsoluteTransform.Position + (cloneTransform->Orientation * glm::vec3(0.97163f, 0.f, 0.f));
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = gunLookAt * glm::vec3(0.f, 0.f, -1.f) * turretComponent->ShotSpeed;
EventBroker->Publish(eSetVelocity);
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
}
Temp_m_TimeSinceLastShot = 0;
#pragma endregion
}
}
}
bool Systems::TowerSystem::OnCollision(const Events::Collision &e)
{
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity2))
{
auto tankShell1 = m_World->GetComponent<Components::TurretShot>(e.Entity1);
auto tankShell2 = m_World->GetComponent<Components::TurretShot>(e.Entity2);
EntityID shellEntity = 0;
Components::TurretShot* shellComponent;
EntityID otherEntity = 0;
if (tankShell1)
{
shellEntity = e.Entity1;
otherEntity = e.Entity2;
shellComponent = tankShell1;
}
else if (tankShell2)
{
shellEntity = e.Entity2;
otherEntity = e.Entity1;
shellComponent = tankShell2;
}
else
{
return false;
}
if(m_World->GetComponent<Components::Template>(shellEntity))
return false;
//auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>();
auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity);
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
{
Events::CreateExplosion e;
e.LifeTime = 2;
e.ParticleScale.push_back(3);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6, 0.6, 0.6, 0.1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(5);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(5);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
//{
// Events::CreateExplosion e;
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180) / 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(5.f,5.f,5.f,1);
// EventBroker->Publish(e);
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180)/ 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(1.f,1.f,1.f,1);
// EventBroker->Publish(e);
//}
//{
// Events::PlaySFX e;
// e.MinDistance = 150.f;
// e.Position = shellTransform->Position;
// e.Resource = "Sounds/SFX/Explosion.wav";
// EventBroker->Publish(e);
//}
// Direct damage
auto health = m_World->GetComponent<Components::Health>(otherEntity);
if (health)
{
Events::Damage d;
d.Entity = otherEntity;
d.Amount = shellComponent->Damage;
EventBroker->Publish(d);
}
// Splash damage
//for (auto &physComponent : *physicsComponents)
//{
// EntityID physicsEntity = physComponent->Entity;
// // No splash damage to the direct hit target
// if (physicsEntity == otherEntity)
// continue;
// auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(physicsEntity);
// float distance = glm::distance(physEntityTransform.Position, shellTransform->Position);
// if (distance <= shellComponent->ExplosionRadius)
// {
// // DO STUFF! :D
// float radius = shellComponent->ExplosionRadius;
// float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength;
// glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position);
// Events::ApplyPointImpulse e;
// e.Entity = physicsEntity;
// e.Impulse = direction * strength;
// e.Position = physEntityTransform.Position;
// EventBroker->Publish(e);
// auto health = m_World->GetComponent<Components::Health>(physicsEntity);
// if (health && health->VulnerableToSplash)
// {
// Events::Damage d;
// d.Entity = physicsEntity;
// d.Amount = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
// EventBroker->Publish(d);
// }
//
//
// }
//}
m_World->RemoveEntity(shellEntity);
}
return true;
}
+55
View File
@@ -0,0 +1,55 @@
#ifndef TowerSystem_h__
#define TowerSystem_h__
#include "System.h"
#include "Systems/TransformSystem.h"
#include "Components/Player.h"
#include "Components/Tower.h"
#include "Components/Turret.h"
#include "Components/TurretShot.h"
#include "Components/Health.h"
#include "Components/TowerDebris.h"
#include "Components/Model.h"
#include "Events/SetVelocity.h"
#include "Events/CreateExplosion.h"
#include "Events/Collision.h"
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
namespace Systems
{
class TowerSystem : public System
{
public:
TowerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
virtual void Update(double dt);
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent);
EventRelay<TowerSystem, Events::Collision> m_ECollision;
bool OnCollision(const Events::Collision &e);
EventRelay<TowerSystem, Events::Damage> m_eDamage;
bool Damage(const Events::Damage &event);
private:
std::map<EntityID, double> m_TimeSinceLastShot;
float Temp_m_TimeSinceLastShot;
};
}
#endif // TowerSystem_h__
+2 -1
View File
@@ -24,7 +24,7 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI
if(m_MoveItems.find(entity) != m_MoveItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec3 direction = glm::normalize(m_MoveItems[entity].GoalPosition - transform->Position);
glm::vec3 movement = direction * m_MoveItems[entity].Speed * (float)dt;
@@ -54,6 +54,7 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI
if(m_RotationItems.find(entity) != m_RotationItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto absolutetransform = AbsoluteTransform(entity);
float percentage = dt/m_RotationItems[entity].Time;
m_RotationItems[entity].Time -= dt;
+20 -27
View File
@@ -44,21 +44,17 @@ void Systems::TriggerSystem::OnEntityRemoved( EntityID entity )
bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
//HACK: SIMON IS DISSING AMERICA
if(flagComponent1)
{
Flag(event.Entity, event.Trigger);
}
else if (flagComponent2)
{
Flag(event.Trigger, event.Entity);
}
auto triggerMoveComponent = m_World->GetComponent<Components::TriggerMove>(event.Trigger);
if (triggerMoveComponent)
{
@@ -77,6 +73,17 @@ bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
bool Systems::TriggerSystem::OnLeaveTrigger( const Events::LeaveTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
auto triggerMoveComponent = m_World->GetComponent<Components::TriggerMove>(event.Trigger);
if (triggerMoveComponent)
{
@@ -129,20 +136,6 @@ void Systems::TriggerSystem::Move(EntityID entity, bool queue, bool swap)
}
}
void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity )
{
auto tankSteering = m_World->GetComponent<Components::TankSteering>(entity);
if (!tankSteering)
return;
m_World->RemoveComponent<Components::Trigger>(phantomEntity);
m_World->SetEntityParent(phantomEntity, entity);
auto phantomTransform = m_World->GetComponent<Components::Transform>(phantomEntity);
phantomTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
}
void Systems::TriggerSystem::Explosion( EntityID entity, EntityID phantomEntity )
{
/*auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
+1 -1
View File
@@ -21,6 +21,7 @@
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Player.h"
#include "Components/Team.h"
#include "Events/Move.h"
#include "Events/Rotate.h"
#include <math.h>
@@ -47,7 +48,6 @@ namespace Systems
EventRelay<TriggerSystem, Events::LeaveTrigger> m_ELeaveTrigger;
bool OnLeaveTrigger(const Events::LeaveTrigger &event);
private:
void Flag(EntityID entity, EntityID phantomEntity);
void Explosion(EntityID entity, EntityID phantomEntity);
void Move(EntityID entity, bool queue, bool swap);
void Rotate(EntityID entity, bool queue, bool swap);
+29 -17
View File
@@ -20,35 +20,47 @@ bool Systems::WallSystem::Damage( const Events::Damage &event )
return false;
}
LOG_INFO("WallSystem::Damage");
// Change to damage model
auto modelComponent = m_World->GetComponent<Components::Model>(event.Entity);
auto damageModel = m_World->GetComponent<Components::DamageModel>(event.Entity);
if (modelComponent)
{
modelComponent->ModelFile = damageModel->ModelFile;
modelComponent->Color = damageModel->Color;
modelComponent->ShadowCaster = damageModel->ShadowCaster;
modelComponent->Transparent = damageModel->Transparent;
}
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
return false;
}
LOG_INFO("Entity %i is dead", event.Entity);
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
LOG_INFO("You are dead");
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
// Spawn debris
for(auto d : wallComponent->Walldebris)
{
auto debris = m_World->CloneEntity(d);
auto transform = m_World->GetComponent<Components::Transform>(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);
transform->Orientation = transform->Orientation * transformComponent.Orientation;
transform->Position = transform->Orientation * 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)) * 20.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);
+3 -1
View File
@@ -3,10 +3,12 @@
#include "System.h"
#include "Events/OnDead.h"
#include "Systems/TransformSystem.h"
#include "Events/Dead.h"
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
#include "Components/Model.h"
#include "Components/DamageModel.h"
#include "Components/Wall.h"
#include "Components/Transform.h"
#include "Components/Physics.h"
+5 -3
View File
@@ -79,11 +79,13 @@ bool World::ValidEntity(EntityID entity)
void World::RemoveEntity(EntityID entity)
{
m_EntitiesToRemove.insert(entity);
for (auto pair : m_EntityParents)
auto it = m_EntityChildren.find(entity);
if (it != m_EntityChildren.end())
{
if (pair.second == entity)
for (auto entity : it->second)
{
m_EntitiesToRemove.insert(pair.first);
RemoveEntity(entity);
}
}
}
+25 -1
View File
@@ -109,10 +109,13 @@
<ClCompile Include="..\..\src\ShaderProgram.cpp" />
<ClCompile Include="..\..\src\Skybox.cpp" />
<ClCompile Include="..\..\src\Sound.cpp" />
<ClCompile Include="..\..\src\Systems\FlagSystem.cpp" />
<ClCompile Include="..\..\src\Systems\JeepSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp" />
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp" />
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp" />
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
@@ -122,6 +125,7 @@
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TimerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
@@ -137,13 +141,18 @@
<ClInclude Include="..\..\src\Components\BlendMap.h" />
<ClInclude Include="..\..\src\Components\BoxShape.h" />
<ClInclude Include="..\..\src\Components\Camera.h" />
<ClInclude Include="..\..\src\Components\DamageModel.h" />
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
<ClInclude Include="..\..\src\Components\Flag.h" />
<ClInclude Include="..\..\src\Components\Follow.h" />
<ClInclude Include="..\..\src\Components\FrameTimer.h" />
<ClInclude Include="..\..\src\Components\Garage.h" />
<ClInclude Include="..\..\src\Components\JeepSteering.h" />
<ClInclude Include="..\..\src\Components\Move.h" />
<ClInclude Include="..\..\src\Components\Rotate.h" />
<ClInclude Include="..\..\src\Components\Tower.h" />
<ClInclude Include="..\..\src\Components\Team.h" />
<ClInclude Include="..\..\src\Components\TowerDebris.h" />
<ClInclude Include="..\..\src\Components\TriggerMove.h" />
<ClInclude Include="..\..\src\Components\Timer.h" />
<ClInclude Include="..\..\src\Components\TriggerExplosion.h" />
@@ -171,6 +180,8 @@
<ClInclude Include="..\..\src\Components\Transform.h" />
<ClInclude Include="..\..\src\Components\Trigger.h" />
<ClInclude Include="..\..\src\Components\TriggerRotate.h" />
<ClInclude Include="..\..\src\Components\Turret.h" />
<ClInclude Include="..\..\src\Components\TurretShot.h" />
<ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\SpawnPoint.h" />
<ClInclude Include="..\..\src\Components\Viewport.h" />
@@ -192,9 +203,16 @@
<ClInclude Include="..\..\src\Events\Damage.h" />
<ClInclude Include="..\..\src\Events\DisableCollisions.h" />
<ClInclude Include="..\..\src\Events\EnableCollisions.h" />
<ClInclude Include="..\..\src\Events\FlagCaptured.h" />
<ClInclude Include="..\..\src\Events\FlagDropped.h" />
<ClInclude Include="..\..\src\Events\FlagPickup.h" />
<ClInclude Include="..\..\src\Events\FlagReturned.h" />
<ClInclude Include="..\..\src\Events\GameOver.h" />
<ClInclude Include="..\..\src\Events\GamepadAxis.h" />
<ClInclude Include="..\..\src\Events\GamepadButton.h" />
<ClInclude Include="..\..\src\Events\GameStart.h" />
<ClInclude Include="..\..\src\Events\InputCommand.h" />
<ClInclude Include="..\..\src\Events\JeepSteer.h" />
<ClInclude Include="..\..\src\Events\KeyDown.h" />
<ClInclude Include="..\..\src\Events\KeyUp.h" />
<ClInclude Include="..\..\src\Events\LeaveTrigger.h" />
@@ -202,7 +220,7 @@
<ClInclude Include="..\..\src\Events\MouseMove.h" />
<ClInclude Include="..\..\src\Events\MousePress.h" />
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Events\Dead.h" />
<ClInclude Include="..\..\src\Events\Move.h" />
<ClInclude Include="..\..\src\Events\PlayBGM.h" />
<ClInclude Include="..\..\src\Events\PlaySFX.h" />
@@ -218,7 +236,9 @@
<ClInclude Include="..\..\src\GUI\Frame.h" />
<ClInclude Include="..\..\src\EventBroker.h" />
<ClInclude Include="..\..\src\GUI\GameFrame.h" />
<ClInclude Include="..\..\src\GUI\GameOverFrame.h" />
<ClInclude Include="..\..\src\GUI\HealthOverlay.h" />
<ClInclude Include="..\..\src\GUI\MainMenuFrame.h" />
<ClInclude Include="..\..\src\GUI\PlayerHUD.h" />
<ClInclude Include="..\..\src\GUI\VehicleSelection.h" />
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
@@ -237,10 +257,13 @@
<ClInclude Include="..\..\src\Skybox.h" />
<ClInclude Include="..\..\src\Sound.h" />
<ClInclude Include="..\..\src\System.h" />
<ClInclude Include="..\..\src\Systems\FlagSystem.h" />
<ClInclude Include="..\..\src\Systems\JeepSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\DamageSystem.h" />
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
<ClInclude Include="..\..\src\Systems\FollowSystem.h" />
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\GameStateSystem.h" />
<ClInclude Include="..\..\src\Systems\GarageSystem.h" />
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\InputSystem.h" />
@@ -250,6 +273,7 @@
<ClInclude Include="..\..\src\Systems\SoundSystem.h" />
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\TimerSystem.h" />
<ClInclude Include="..\..\src\Systems\TowerSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Systems\TriggerSystem.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
+98 -10
View File
@@ -74,19 +74,36 @@
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Gameplay\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Sound.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\JeepSteeringSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\FlagSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -194,6 +211,9 @@
<Filter Include="Base\Events">
<UniqueIdentifier>{3cbe68d9-2446-45ee-8637-ffb805997dcd}</UniqueIdentifier>
</Filter>
<Filter Include="Rendering\Events">
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
</Filter>
<Filter Include="Game\Events">
<UniqueIdentifier>{9702064a-02a2-4b3c-a2ab-47c23a9cf49c}</UniqueIdentifier>
</Filter>
@@ -523,9 +543,6 @@
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Gameplay\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LeaveTrigger.h">
<Filter>Physics\Events</Filter>
</ClInclude>
@@ -556,12 +573,12 @@
<ClInclude Include="..\..\src\Components\Rotate.h">
<Filter>Base\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Gameplay\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter>
</ClInclude>
@@ -571,6 +588,77 @@
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\TowerSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Tower.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Turret.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\TurretShot.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Team.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\JeepSteeringSystem.h">
<Filter>Physics\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\GUI\GameOverFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\GameStateSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagPickup.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagCaptured.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagDropped.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagReturned.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\GameOver.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\MainMenuFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\GameStart.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\JeepSteer.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\JeepSteering.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\DamageModel.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\FlagSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\Events\Dead.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">