Merge remote-tracking branch 'origin/master' into Menu
# Conflicts: # resources/Schema/Entities/Player.xml
This commit is contained in:
@@ -90,10 +90,10 @@ boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity);
|
||||
//Returns the first entity hit by the input ray. entitiesPotentiallyHitSorted needs to be sorted
|
||||
//by their distance to the ray, e.g. result from Octree<EntityAABB>::ObjectsPossiblyHitByRay.
|
||||
//Returns boost::none if none was hit. outDistance will be the distance to the intersection point if the ray intersects.
|
||||
boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<EntityAABB> entitiesPotentiallyHitSorted, float outDistance, glm::vec3& outIntersectPos);
|
||||
boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<EntityAABB> entitiesPotentiallyHitSorted, float& outDistance, glm::vec3& outIntersectPos);
|
||||
//Returns the first entity hit by the input ray that exists in the octree.
|
||||
//outDistance will be the distance to the intersection point if the ray intersects.
|
||||
boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, Octree<EntityAABB>* octree, float outDistance, glm::vec3& outIntersectPos);
|
||||
boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, Octree<EntityAABB>* octree, float& outDistance, glm::vec3& outIntersectPos);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,8 @@ namespace Events
|
||||
|
||||
struct PlayerDamage : Event
|
||||
{
|
||||
//NOTE: this struct is missing information on what the damageSource is
|
||||
EntityWrapper Player;
|
||||
EntityWrapper PlayerShooter;
|
||||
EntityWrapper Inflictor;
|
||||
EntityWrapper Victim;
|
||||
double Damage;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Events
|
||||
|
||||
struct Shoot : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
EntityWrapper Inflictor;
|
||||
double Damage;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +120,32 @@ struct ModelJob : RenderJob
|
||||
|
||||
if (model->IsSkinned()) {
|
||||
Skeleton = Model->m_RawModel->m_Skeleton;
|
||||
|
||||
if (Skeleton != nullptr) {
|
||||
if (world->HasComponent(Entity, "Animation")) {
|
||||
auto animationComponent = world->GetComponent(Entity, "Animation");
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
::Skeleton::AnimationData animationData;
|
||||
animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(animationComponent["AnimationName" + std::to_string(i)]);
|
||||
if (animationData.animation == nullptr) {
|
||||
continue;
|
||||
}
|
||||
animationData.time = (double)animationComponent["Time" + std::to_string(i)];
|
||||
animationData.weight = (double)animationComponent["Weight" + std::to_string(i)];
|
||||
|
||||
Animations.push_back(animationData);
|
||||
}
|
||||
}
|
||||
|
||||
if (world->HasComponent(Entity, "AnimationOffset")) {
|
||||
auto animationOffsetComponent = world->GetComponent(Entity, "AnimationOffset");
|
||||
AnimationOffset.animation = model->m_RawModel->m_Skeleton->GetAnimation(animationOffsetComponent["AnimationName"]);
|
||||
AnimationOffset.time = (double)animationOffsetComponent["Time"];
|
||||
} else {
|
||||
AnimationOffset.animation = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -140,8 +166,8 @@ struct ModelJob : RenderJob
|
||||
glm::vec4 Color;
|
||||
const ::Model* Model = nullptr;
|
||||
::Skeleton* Skeleton = nullptr;
|
||||
// const ::Skeleton::Animation* Animation = nullptr;
|
||||
|
||||
std::vector<::Skeleton::AnimationData> Animations;
|
||||
::Skeleton::AnimationOffset AnimationOffset;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "../Core/EPlayerSpawned.h"
|
||||
#include "../Core/Octree.h"
|
||||
#include "../Collision/EntityAABB.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
|
||||
class RenderSystem : public ImpureSystem
|
||||
{
|
||||
@@ -48,6 +49,9 @@ private:
|
||||
void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs);
|
||||
void fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||
|
||||
bool isEntityVisible(EntityWrapper& entity);
|
||||
|
||||
bool isChildOfACamera(EntityWrapper entity);
|
||||
bool isChildOfCurrentCamera(EntityWrapper entity);
|
||||
};
|
||||
|
||||
@@ -100,50 +100,29 @@ public:
|
||||
|
||||
int GetBoneID(std::string name);
|
||||
|
||||
void CalculateFrameBones(std::vector<AnimationData> animations, AnimationOffset animationOffset, bool noRootMotion = false);
|
||||
void CalculateFrameBones(std::vector<AnimationData> animations, bool noRootMotion = false);
|
||||
std::vector<glm::mat4> GetFrameBones(std::vector<AnimationData> animations, AnimationOffset animationOffset, bool noRootMotion = false);
|
||||
std::vector<glm::mat4> GetFrameBones(std::vector<AnimationData> animations, bool noRootMotion = false);
|
||||
|
||||
const Animation* GetAnimation(std::string name);
|
||||
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, AnimationOffset animationOffset, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, std::map<int, glm::mat4>& frameBones, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, AnimationOffset animationOffset, std::map<int, glm::mat4>& frameBones, const Bone* bone, glm::mat4 parentMatrix);
|
||||
|
||||
void PrintSkeleton();
|
||||
void PrintSkeleton(const Bone* parent, int depthCount);
|
||||
std::map<std::string, Animation> Animations;
|
||||
|
||||
glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix);
|
||||
glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, AnimationOffset animationOffset, glm::mat4 childMatrix);
|
||||
glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, glm::mat4 childMatrix);
|
||||
int GetKeyframe(const Animation& animation, double time);
|
||||
|
||||
|
||||
std::vector<glm::mat4> GetBones()
|
||||
{
|
||||
std::vector<glm::mat4> finalMatrices;
|
||||
for (auto &kv : m_BoneLocalTransforms) {
|
||||
finalMatrices.push_back(kv.second);
|
||||
}
|
||||
return finalMatrices;;
|
||||
}
|
||||
|
||||
glm::mat4 GetBoneTransformSuper(int boneID)
|
||||
{
|
||||
if(m_BoneTransforms.find(boneID) != m_BoneTransforms.end()) {
|
||||
return m_BoneTransforms.at(boneID);
|
||||
} else {
|
||||
return glm::mat4(1);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset);
|
||||
|
||||
std::map<std::string, Bone*> m_BonesByName;
|
||||
float aim = 0.f;
|
||||
|
||||
|
||||
std::map<int, glm::mat4> m_BoneLocalTransforms;
|
||||
std::map<int, glm::mat4> m_BoneTransforms;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,8 +21,8 @@ public:
|
||||
DamageIndicatorSystem(SystemParams params);
|
||||
|
||||
private:
|
||||
EventRelay<DamageIndicatorSystem, Events::PlayerDamage> m_DamageTakenFromPlayer;
|
||||
bool OnPlayerDamageTaken(Events::PlayerDamage& e);
|
||||
EventRelay<DamageIndicatorSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||
bool OnPlayerDamage(Events::PlayerDamage& e);
|
||||
|
||||
EventRelay<DamageIndicatorSystem, Events::SetCamera> m_ESetCamera;
|
||||
bool OnSetCamera(const Events::SetCamera& e);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "Collision/Collision.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
#include "WeaponBehaviour.h"
|
||||
#include "../SpawnerSystem.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Core/EShoot.h"
|
||||
|
||||
class AssaultWeaponBehaviour : public WeaponBehaviour
|
||||
{
|
||||
public:
|
||||
AssaultWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity);
|
||||
|
||||
virtual void Fire() override;
|
||||
virtual void CeaseFire() override;
|
||||
virtual void Reload() override;
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
EntityWrapper m_FirstPersonModel;
|
||||
// State
|
||||
bool m_Firing = false;
|
||||
bool m_Reloading = false;
|
||||
double m_ReloadTimer = 0.0;
|
||||
EntityWrapper m_ReloadImpersonator;
|
||||
double m_TimeSinceLastFire = 0.0;
|
||||
|
||||
EventRelay<WeaponBehaviour, Events::AnimationComplete> m_EAnimationComplete;
|
||||
bool OnAnimationComplete(Events::AnimationComplete& e);
|
||||
|
||||
bool hasAmmo();
|
||||
void fireRound();
|
||||
void spawnTracer();
|
||||
float traceRayDistance(glm::vec3 origin, glm::vec3 direction);
|
||||
void playSound();
|
||||
void viewPunch();
|
||||
void finishReload();
|
||||
void playShootAnimation();
|
||||
void playIdleAnimation();
|
||||
void playReloadAnimation();
|
||||
bool shoot(double damage);
|
||||
void showHitMarker();
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef WeaponBehaviour_h__
|
||||
#define WeaponBehaviour_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Rendering/IRenderer.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
|
||||
class WeaponBehaviour : public System
|
||||
{
|
||||
public:
|
||||
WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player)
|
||||
: System(systemParams)
|
||||
, m_Renderer(renderer)
|
||||
, m_CollisionOctree(collisionOctree)
|
||||
, m_Player(player)
|
||||
{ }
|
||||
virtual ~WeaponBehaviour() = default;
|
||||
|
||||
WeaponBehaviour(const WeaponBehaviour&) = delete;
|
||||
WeaponBehaviour& operator=(const WeaponBehaviour &) = delete;
|
||||
|
||||
virtual void Fire() = 0;
|
||||
virtual void CeaseFire() { }
|
||||
virtual void Reload() { }
|
||||
virtual void Update(double dt) { }
|
||||
|
||||
protected:
|
||||
IRenderer* m_Renderer;
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
EntityWrapper m_Player;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef WeaponSystem_h__
|
||||
#define WeaponSystem_h__
|
||||
|
||||
#include "Rendering/IRenderer.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Core/EShoot.h"
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
#include "Systems/SpawnerSystem.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "AssaultWeaponBehaviour.h"
|
||||
|
||||
class WeaponSystem : public PureSystem, ImpureSystem
|
||||
{
|
||||
public:
|
||||
WeaponSystem(SystemParams params, IRenderer* renderer, Octree<EntityAABB>* collisionOctree);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) override;
|
||||
|
||||
private:
|
||||
SystemParams m_SystemParams;
|
||||
IRenderer* m_Renderer;
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
|
||||
std::unordered_map<EntityWrapper, std::shared_ptr<WeaponBehaviour>> m_ActiveWeapons;
|
||||
|
||||
// Events
|
||||
EventRelay<WeaponSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||
EventRelay<WeaponSystem, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(Events::InputCommand& e);
|
||||
|
||||
void selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,192 +0,0 @@
|
||||
#ifndef WeaponSystem_h__
|
||||
#define WeaponSystem_h__
|
||||
|
||||
//#include <GLFW/glfw3.h>
|
||||
//#include <glm/common.hpp>
|
||||
#include "Rendering/IRenderer.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Core/EShoot.h"
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
#include "Systems/SpawnerSystem.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
|
||||
class WeaponBehaviour;
|
||||
|
||||
class WeaponSystem : public PureSystem, ImpureSystem
|
||||
{
|
||||
public:
|
||||
WeaponSystem(SystemParams params, IRenderer* renderer, Octree<EntityAABB>* collisionOctree);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) override;
|
||||
|
||||
private:
|
||||
SystemParams m_SystemParams;
|
||||
IRenderer* m_Renderer;
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
|
||||
std::unordered_map<EntityWrapper, std::shared_ptr<WeaponBehaviour>> m_ActiveWeapons;
|
||||
|
||||
// Events
|
||||
EventRelay<WeaponSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||
EventRelay<WeaponSystem, Events::Shoot> m_EShoot;
|
||||
bool OnShoot(Events::Shoot& e);
|
||||
EventRelay<WeaponSystem, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(Events::InputCommand& e);
|
||||
|
||||
void selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot);
|
||||
};
|
||||
|
||||
class WeaponBehaviour : public System
|
||||
{
|
||||
public:
|
||||
WeaponBehaviour(SystemParams systemParams, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
|
||||
: System(systemParams)
|
||||
, m_CollisionOctree(collisionOctree)
|
||||
, m_Entity(weaponEntity)
|
||||
{ }
|
||||
virtual ~WeaponBehaviour() = default;
|
||||
|
||||
WeaponBehaviour(const WeaponBehaviour&) = delete;
|
||||
WeaponBehaviour& operator=(const WeaponBehaviour &) = delete;
|
||||
|
||||
virtual void Fire() = 0;
|
||||
virtual void CeaseFire() { }
|
||||
virtual void Reload() { }
|
||||
virtual void Update(double dt) { }
|
||||
|
||||
protected:
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
EntityWrapper m_Entity;
|
||||
};
|
||||
|
||||
class AssaultWeaponBehaviour : public WeaponBehaviour
|
||||
{
|
||||
public:
|
||||
AssaultWeaponBehaviour(SystemParams systemParams, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
|
||||
: WeaponBehaviour(systemParams, collisionOctree, weaponEntity)
|
||||
{ }
|
||||
|
||||
virtual void Fire() override
|
||||
{
|
||||
m_TimeSinceLastFire = 0.0;
|
||||
m_Firing = true;
|
||||
fireRound();
|
||||
}
|
||||
|
||||
virtual void CeaseFire() override
|
||||
{
|
||||
m_Firing = false;
|
||||
}
|
||||
|
||||
virtual void Reload() override
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
int magSize = cAssaultWeapon["MagazineSize"];
|
||||
int& ammo = cAssaultWeapon["Ammo"];
|
||||
|
||||
// Don't reload if we're already fully loaded
|
||||
if (magAmmo == magSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Throw away rounds in magazine to incentivise ammo sharing
|
||||
int toLoad = glm::min(magSize, ammo);
|
||||
magAmmo = toLoad;
|
||||
ammo -= toLoad;
|
||||
}
|
||||
|
||||
virtual void Update(double dt) override
|
||||
{
|
||||
if (!m_Firing) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_TimeSinceLastFire += dt;
|
||||
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
if (m_TimeSinceLastFire >= 1.0 / ((double)cAssaultWeapon["RPM"] / 60.0)) {
|
||||
fireRound();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_Firing = false;
|
||||
double m_TimeSinceLastFire = 0.0;
|
||||
EntityFile* m_RayRed = nullptr;
|
||||
EntityFile* m_RayBlue = nullptr;
|
||||
|
||||
void fireRound()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
int ammo = cAssaultWeapon["Ammo"];
|
||||
|
||||
// Reload if our magazine is empty
|
||||
if (magAmmo <= 0) {
|
||||
Reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fire
|
||||
magAmmo -= 1;
|
||||
spawnTracer();
|
||||
playSound();
|
||||
|
||||
m_TimeSinceLastFire = 0.0;
|
||||
}
|
||||
|
||||
void spawnTracer()
|
||||
{
|
||||
if (!IsClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityWrapper spawner;
|
||||
if (m_Entity == LocalPlayer) {
|
||||
spawner = m_Entity.FirstChildByName("WeaponMuzzle");
|
||||
} else {
|
||||
spawner = m_Entity.FirstChildByName("ThirdPersonWeaponMuzzle");
|
||||
}
|
||||
|
||||
if (!spawner.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Events::SpawnerSpawn e;
|
||||
e.Spawner = spawner;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
float traceRayDistance(glm::vec3 origin, glm::vec3 direction)
|
||||
{
|
||||
// TODO: Cast a ray and size tracer appropriately
|
||||
return 100.f;
|
||||
}
|
||||
|
||||
void playSound()
|
||||
{
|
||||
if (!IsClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = m_Entity.ID;
|
||||
e.FilePath = "Audio/laser/laser1.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user