Weapon RayZ

Weapon RayZ
This commit is contained in:
2016-01-25 10:25:44 +01:00
parent b95c1fdfa4
commit 4245264029
20 changed files with 300 additions and 20 deletions
+1 -1
Submodule assets updated: 7577819337...e4dc9529f2
+3
View File
@@ -35,6 +35,9 @@ struct EntityWrapper
bool operator!=(const EntityWrapper& e) const;
explicit operator EntityID() const;
operator bool();
private:
EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent);
};
namespace std
+2
View File
@@ -8,8 +8,10 @@
namespace Transform
{
glm::mat4 AbsoluteTransformation(EntityWrapper entity);
glm::vec3 AbsolutePosition(EntityWrapper entity);
glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::vec3 AbsoluteOrientationEuler(EntityWrapper entity);
glm::quat AbsoluteOrientation(EntityWrapper entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(EntityWrapper entity);
+21
View File
@@ -0,0 +1,21 @@
#ifndef LifetimeSystem_h__
#define LifetimeSystem_h__
#include "Core/System.h"
class LifetimeSystem : public ImpureSystem, PureSystem
{
public:
LifetimeSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker)
, PureSystem("Lifetime")
{ }
virtual void Update(double dt) override;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cLifetime, double dt) override;
private:
std::vector<EntityWrapper> m_Deletions;
};
#endif
+3 -1
View File
@@ -11,6 +11,8 @@
#include "Core/EShoot.h"
#include "Core/EPlayerSpawned.h"
#include "Input/EInputCommand.h"
#include "Core/EntityFile.h"
#include "Core/EntityFileParser.h"
#include <tuple>
#include <vector>
@@ -33,7 +35,7 @@ private:
EventRelay<WeaponSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool WeaponSystem::OnPlayerSpawned(const Events::PlayerSpawned& e);
EventRelay<WeaponSystem, Events::Shoot> m_EShoot;
bool WeaponSystem::OnShoot(const Events::Shoot& e);
bool WeaponSystem::OnShoot(Events::Shoot& e);
EventRelay<WeaponSystem, Events::InputCommand> m_EInputCommand;
bool WeaponSystem::OnInputCommand(const Events::InputCommand& e);
};
+1
View File
@@ -26,4 +26,5 @@
<xs:include schemaLocation="Components/HealthHUD.xsd"/>
<xs:include schemaLocation="Components/Animation.xsd"/>
<xs:include schemaLocation="Components/Fill.xsd"/>
<xs:include schemaLocation="Components/Lifetime.xsd"/>
</xs:schema>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Lifetime xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Animation.xsd">
<Lifetime>0</Lifetime>
</Animation>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Lifetime">
<xs:complexType>
<xs:all>
<xs:element name="Lifetime" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+57 -4
View File
@@ -8,7 +8,9 @@
<Size X="1" Y="1.60000002" Z="1"/>
</c:AABB>
<c:Collidable/>
<c:Physics/>
<c:Physics>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
</c:Physics>
<c:Player>
<MovementSpeed>5</MovementSpeed>
</c:Player>
@@ -17,8 +19,10 @@
<Red/>
</Team>
</c:Team>
<c:Transform/>
<Position X="-0.246963501" Y="0.0264999941" Z="3.01600003"/>
<c:Transform>
<Position X="-7.12165165" Y="0.0265000015" Z="6.04289007"/>
<Orientation X="0" Y="2.24449515" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -27,6 +31,7 @@
<c:Camera/>
<c:Transform>
<Position X="0" Y="1.37700009" Z="0"/>
<Orientation X="0.122173041" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -67,11 +72,11 @@
<Children>
<Entity name="HealthBar">
<Components>
<c:HealthHUD/>
<c:Fill>
<Percentage>1</Percentage>
<Color A="0" B="1" G="0" R="0"/>
</c:Fill>
<c:HealthHUD/>
<c:Model>
<Resource>Models/Core/UnitHexagon.mesh</Resource>
<Color A="1" B="0.70588237" G="0.70588237" R="0.70588237"/>
@@ -84,6 +89,52 @@
</Components>
<Children/>
</Entity>
<Entity name="Crosshair">
<Components>
<c:Model>
<Resource>Models/CrosshairQuad.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0" Y="0" Z="0.200000003"/>
<Scale X="0.00600000005" Y="1" Z="0.00600000005"/>
<Orientation X="1.57000005" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Weapon">
<Components>
<c:Model>
<Resource>Models/AssaultWeapon.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.180000007" Y="-0.183000013" Z="0"/>
<Orientation X="0" Y="4.64700031" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="WeaponMuzzle">
<Components>
<c:Transform>
<Position X="0.215000004" Y="-0.153000012" Z="-0.266000003"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>Models/CylinderBullet.mesh</Resource>
<Color A="1" B="0" G="0.525490224" R="39.2156868"/>
</c:Model>
<c:Transform>
<Scale X="0.0110000009" Y="0.029000001" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
@@ -106,11 +157,13 @@
<Components>
<c:Animation>
<Name>Hold Pos</Name>
<Time>0.86791076003269829</Time>
<Speed>1</Speed>
</c:Animation>
<c:Model>
<Resource>Models/AssaultAnimated.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/>
<Visible>false</Visible>
</c:Model>
<c:Transform/>
</Components>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Model>
<Resource>Models/Core/UnitCylinder.mesh</Resource>
<Color A="0" B="0" G="0" R="39.2156868"/>
</c:Model>
<c:Transform>
<Scale X="0.0400000028" Y="26.2000008" Z="0.0400000028"/>
<Orientation X="1.57070005" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Lifetime>
<Lifetime>0.25</Lifetime>
</c:Lifetime>
<c:Model>
<Resource>Models/CylinderBullet.mesh</Resource>
<Color A="1" B="39.2156868" G="7.84313726" R="0"/>
</c:Model>
<c:Transform>
<Scale X="0.0109999999" Y="0.0289999992" Z="100"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Model>
<Resource>Models/Core/UnitCylinder.mesh</Resource>
<Color A="0" B="0" G="0" R="39.2156868"/>
</c:Model>
<c:Transform>
<Scale X="0.0400000028" Y="26.2000008" Z="0.0400000028"/>
<Orientation X="1.57070005" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Lifetime>
<Lifetime>0.25</Lifetime>
</c:Lifetime>
<c:Model>
<Resource>Models/CylinderBullet.mesh</Resource>
<Color A="1" B="0" G="0.525490224" R="39.2156868"/>
</c:Model>
<c:Transform>
<Scale X="0.0110000009" Y="0.029000001" Z="100"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+1
View File
@@ -32,6 +32,7 @@
<xs:element ref="c:DirectionalLight" minOccurs="0"/>
<xs:element ref="c:UniformScale" minOccurs="0"/>
<xs:element ref="c:EditorWidget" minOccurs="0"/>
<xs:element ref="c:Lifetime" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
+23 -12
View File
@@ -22,18 +22,7 @@ EntityWrapper EntityWrapper::Parent()
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
{
auto itPair = this->World->GetChildren(this->ID);
if (itPair.first == itPair.second) {
return EntityWrapper::Invalid;
}
for (auto it = itPair.first; it != itPair.second; ++it) {
if (this->World->GetName(it->second) == name) {
return EntityWrapper(this->World, it->second);
}
}
return EntityWrapper::Invalid;
return firstChildByNameRecursive(name, this->ID);
}
EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType)
@@ -108,3 +97,25 @@ EntityWrapper::operator bool()
return this->Valid();
}
EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name, EntityID parent)
{
auto itPair = this->World->GetChildren(parent);
if (itPair.first == itPair.second) {
return EntityWrapper::Invalid;
}
for (auto it = itPair.first; it != itPair.second; ++it) {
std::string itName = this->World->GetName(it->second);
if (itName == name) {
return EntityWrapper(this->World, it->second);
} else if (it->second != EntityID_Invalid) {
EntityWrapper result = firstChildByNameRecursive(name, it->second);
if (result != EntityWrapper::Invalid) {
return result;
}
}
}
return EntityWrapper::Invalid;
}
+27
View File
@@ -1,5 +1,17 @@
#include "Core/Transform.h"
glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
{
glm::mat4 t = glm::mat4(1.f);
while (entity.Valid()) {
t = glm::translate((glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((glm::vec3&)entity["Transform"]["Scale"]) * t;
entity = entity.Parent();
}
return t;
}
glm::vec3 Transform::AbsolutePosition(EntityWrapper entity)
{
return AbsolutePosition(entity.World, entity.ID);
@@ -19,6 +31,19 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
return position;
}
glm::vec3 Transform::AbsoluteOrientationEuler(EntityWrapper entity)
{
glm::vec3 orientation;
while (entity.Valid()) {
ComponentWrapper transform = entity["Transform"];
orientation += (glm::vec3)transform["Orientation"];
entity = entity.Parent();
}
return orientation;
}
glm::quat Transform::AbsoluteOrientation(EntityWrapper entity)
{
return AbsoluteOrientation(entity.World, entity.ID);
@@ -62,6 +87,8 @@ glm::mat4 Transform::ModelMatrix(EntityWrapper entity)
glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
{
return AbsoluteTransformation(EntityWrapper(world, entity));
glm::vec3 position = Transform::AbsolutePosition(world, entity);
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
+1 -1
View File
@@ -53,7 +53,7 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
// Don't render the local player
if (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer)) {
if (!entity.HasComponent("HealthHUD")) { //Should work but needs to be fixed. Should only render the things "childed" to the local player camera
continue;
//continue;
}
}
+2
View File
@@ -11,6 +11,7 @@
#include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h"
#include "Game/Systems/PlayerHUD.h"
#include "Game/Systems/LifetimeSystem.h"
#include "../Engine/Rendering/AnimationSystem.h"
Game::Game(int argc, char* argv[])
@@ -85,6 +86,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
+27
View File
@@ -0,0 +1,27 @@
#include "Systems/LifetimeSystem.h"
void LifetimeSystem::Update(double dt)
{
for (auto& e : m_Deletions) {
m_World->DeleteEntity(e.ID);
}
m_Deletions.clear();
}
void LifetimeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cLifetime, double dt)
{
if (dt == 0.0) {
return;
}
if (!entity.Valid()) {
return;
}
double& lifetime = cLifetime["Lifetime"];
lifetime -= dt;
if (lifetime <= 0.0) {
m_Deletions.push_back(entity);
}
}
+42 -1
View File
@@ -39,10 +39,51 @@ bool WeaponSystem::OnInputCommand(const Events::InputCommand& e)
return true;
}
bool WeaponSystem::OnShoot(const Events::Shoot& eShoot)
bool WeaponSystem::OnShoot(Events::Shoot& eShoot)
{
// TODO: Weapon firing effects here
auto rayRed = ResourceManager::Load<EntityFile>("Schema/Entities/RayRed.xml");
auto rayBlue = ResourceManager::Load<EntityFile>("Schema/Entities/RayBlue.xml");
EntityWrapper weapon = eShoot.Player.FirstChildByName("WeaponMuzzle");
if (weapon.Valid()) {
EntityWrapper ray;
if ((ComponentInfo::EnumType)eShoot.Player["Team"]["Team"] == eShoot.Player["Team"]["Team"].Enum("Red")) {
EntityFileParser parser(rayRed);
EntityID rayID = parser.MergeEntities(m_World);
ray = EntityWrapper(m_World, rayID);
} else {
EntityFileParser parser(rayBlue);
EntityID rayID = parser.MergeEntities(m_World);
ray = EntityWrapper(m_World, rayID);
}
glm::mat4 transformation = Transform::AbsoluteTransformation(weapon);
glm::vec3 scale;
glm::vec3 translation;
glm::quat orientation;
glm::vec3 skew;
glm::vec4 perspective;
glm::decompose(transformation, scale, orientation, translation, skew, perspective);
// Matrix to euler angles
glm::vec3 euler;
euler.y = glm::asin(-transformation[0][2]);
if (cos(euler.y) != 0) {
euler.x = atan2(transformation[1][2], transformation[2][2]);
euler.z = atan2(transformation[0][1], transformation[0][0]);
} else {
euler.x = atan2(-transformation[2][0], transformation[1][1]);
euler.z = 0;
}
//LOG_DEBUG("rotation: %f %f %f", euler.x, euler.y, euler.z);
(glm::vec3&)ray["Transform"]["Position"] = translation;
(glm::vec3&)ray["Transform"]["Orientation"] = euler;
//(glm::vec3&)ray["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(weapon);
}
// Only run further picking code client-side!
if (eShoot.Player != m_LocalPlayer) {
return false;