Compare commits

..

1 Commits

Author SHA1 Message Date
Jace cedcffcf97 WIP multi-weapon behaviours 2016-02-25 16:24:38 +01:00
39 changed files with 325 additions and 357 deletions
@@ -24,7 +24,6 @@ public:
private: private:
Octree<EntityAABB>* m_Octree; Octree<EntityAABB>* m_Octree;
std::vector<EntityAABB> m_OctreeResult; std::vector<EntityAABB> m_OctreeResult;
std::unordered_map<EntityWrapper, glm::vec3> m_PrevPositions;
}; };
#endif #endif
+2 -2
View File
@@ -29,7 +29,7 @@ struct EntityWrapper
EntityWrapper Parent(); EntityWrapper Parent();
EntityWrapper FirstChildByName(const std::string& name); EntityWrapper FirstChildByName(const std::string& name);
EntityWrapper FirstParentWithComponent(const std::string& componentType); EntityWrapper FirstParentWithComponent(const std::string& componentType);
EntityWrapper Clone(EntityWrapper parent = EntityWrapper::Invalid); std::vector<EntityWrapper> ChildrenWithComponent(const std::string& componentType);
bool IsChildOf(EntityWrapper potentialParent); bool IsChildOf(EntityWrapper potentialParent);
bool Valid() const; bool Valid() const;
@@ -40,7 +40,7 @@ struct EntityWrapper
private: private:
EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent); EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent);
EntityWrapper cloneRecursive(EntityWrapper entity, EntityWrapper parent); void childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent);
}; };
namespace std namespace std
+1 -1
View File
@@ -40,7 +40,7 @@ public:
// Change the parent of an entity // Change the parent of an entity
void SetParent(EntityID entity, EntityID parent); void SetParent(EntityID entity, EntityID parent);
// Get children of an entity // Get children of an entity
const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> GetDirectChildren(EntityID entity); const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> GetChildren(EntityID entity);
// Get all component pools // Get all component pools
const std::unordered_map<std::string, ComponentPool*>& GetComponentPools() const { return m_ComponentPools; } const std::unordered_map<std::string, ComponentPool*>& GetComponentPools() const { return m_ComponentPools; }
// Get the entity children map // Get the entity children map
-8
View File
@@ -73,12 +73,6 @@ public:
// Called when the user means to rename an entity. // Called when the user means to rename an entity.
typedef std::function<void(EntityWrapper, const std::string&)> OnEntityChangeName_t; typedef std::function<void(EntityWrapper, const std::string&)> OnEntityChangeName_t;
void SetEntityChangeNameCallback(OnEntityChangeName_t f) { m_OnEntityChangeName = f; } void SetEntityChangeNameCallback(OnEntityChangeName_t f) { m_OnEntityChangeName = f; }
// Called when the user pastes an entity previously "copied"
// @param EntityWrapper The entity to copy
// @param EntityWrapper The entity to parent the new copy to
// @return The new copy of the entity
typedef std::function<EntityWrapper(EntityWrapper, EntityWrapper)> OnEntityPaste_t;
void SetEntityPasteCallback(OnEntityPaste_t f) { m_OnEntityPaste = f; }
// Called when the user means to attach a new component to an entity. // Called when the user means to attach a new component to an entity.
typedef std::function<void(EntityWrapper, const std::string&)> OnComponentAttach_t; typedef std::function<void(EntityWrapper, const std::string&)> OnComponentAttach_t;
void SetComponentAttachCallback(OnComponentAttach_t f) { m_OnComponentAttach = f; } void SetComponentAttachCallback(OnComponentAttach_t f) { m_OnComponentAttach = f; }
@@ -117,7 +111,6 @@ private:
std::string m_DroppedFile = ""; std::string m_DroppedFile = "";
bool m_Paused = false; bool m_Paused = false;
bool m_MouseLocked = false; bool m_MouseLocked = false;
EntityWrapper m_CopyTarget = EntityWrapper::Invalid;
// Callbacks // Callbacks
OnEntitySelectedCallback_t m_OnEntitySelected = nullptr; OnEntitySelectedCallback_t m_OnEntitySelected = nullptr;
@@ -131,7 +124,6 @@ private:
OnComponentDelete_t m_OnComponentDelete = nullptr; OnComponentDelete_t m_OnComponentDelete = nullptr;
OnWidgetMode_t m_OnWidgetMode = nullptr; OnWidgetMode_t m_OnWidgetMode = nullptr;
OnWidgetSpace_t m_OnWidgetSpace = nullptr; OnWidgetSpace_t m_OnWidgetSpace = nullptr;
OnEntityPaste_t m_OnEntityPaste = nullptr;
// Events // Events
EventRelay<EditorGUI, Events::KeyDown> m_EKeyDown; EventRelay<EditorGUI, Events::KeyDown> m_EKeyDown;
-1
View File
@@ -56,7 +56,6 @@ private:
void OnEntityDelete(EntityWrapper entity); void OnEntityDelete(EntityWrapper entity);
void OnEntityChangeParent(EntityWrapper entity, EntityWrapper parent); void OnEntityChangeParent(EntityWrapper entity, EntityWrapper parent);
void OnEntityChangeName(EntityWrapper entity, const std::string& name); void OnEntityChangeName(EntityWrapper entity, const std::string& name);
EntityWrapper OnEntityPaste(EntityWrapper entityToCopy, EntityWrapper parent);
void OnComponentAttach(EntityWrapper entity, const std::string& componentType); void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
void OnComponentDelete(EntityWrapper entity, const std::string& componentType); void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
void OnWidgetSpace(EditorGUI::WidgetSpace widgetSpace); void OnWidgetSpace(EditorGUI::WidgetSpace widgetSpace);
+5 -8
View File
@@ -19,10 +19,8 @@
#include "Core/World.h" #include "Core/World.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/ConfigFile.h" #include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
#include "Core/EPlayerDamage.h" #include "Core/EPlayerDamage.h"
#include "../Game/Events/EDoubleJump.h"
#include "Network/EInterpolate.h" #include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h" #include "Network/SnapshotFilter.h"
#include "Core/EPlayerSpawned.h" #include "Core/EPlayerSpawned.h"
@@ -49,9 +47,7 @@ public:
void Connect(std::string address, int port); void Connect(std::string address, int port);
void Update() override; void Update() override;
private:
UDPClient m_Unreliable;
TCPClient m_Reliable;
std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents; std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents;
void parseSpawnEvents(); void parseSpawnEvents();
// Save for children // Save for children
@@ -105,9 +101,9 @@ private:
void parseEntityDeletion(Packet& packet); void parseEntityDeletion(Packet& packet);
void parsePlayerDamage(Packet& packet); void parsePlayerDamage(Packet& packet);
void parseComponentDeletion(Packet& packet); void parseComponentDeletion(Packet& packet);
void parseDoubleJump(Packet& packet);
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
void parseSnapshot(Packet& packet); void parseSnapshot(Packet& packet);
void UpdateLocalCapturePointHUD(EntityWrapper capturePointHUD);
void identifyPacketLoss(); void identifyPacketLoss();
void hasServerTimedOut(); void hasServerTimedOut();
EntityID createPlayer(); EntityID createPlayer();
@@ -131,10 +127,11 @@ private:
EventRelay<Client, Events::PlayerSpawned> m_EPlayerSpawned; EventRelay<Client, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(const Events::PlayerSpawned& e); bool OnPlayerSpawned(const Events::PlayerSpawned& e);
EventRelay< Client, Events::SearchForServers> m_ESearchForServers; EventRelay< Client, Events::SearchForServers> m_ESearchForServers;
EventRelay<Client, Events::DoubleJump> m_EDoubleJump;
bool OnDoubleJump(Events::DoubleJump & e);
bool OnSearchForServers(const Events::SearchForServers& e); bool OnSearchForServers(const Events::SearchForServers& e);
private:
UDPClient m_Unreliable;
UDPClient m_ServerlistRequest; UDPClient m_ServerlistRequest;
TCPClient m_Reliable;
std::vector<ServerInfo> m_Serverlist; std::vector<ServerInfo> m_Serverlist;
bool m_SearchingForServers = false; bool m_SearchingForServers = false;
std::clock_t m_StartSearchTime; std::clock_t m_StartSearchTime;
-1
View File
@@ -19,7 +19,6 @@ enum class MessageType
EntityDeleted, EntityDeleted,
ComponentDeleted, ComponentDeleted,
PlayerTransform, PlayerTransform,
OnDoubleJump,
ServerlistRequest, ServerlistRequest,
Invalid Invalid
}; };
+3 -4
View File
@@ -8,6 +8,7 @@
#include "Network/TCPServer.h" #include "Network/TCPServer.h"
#include "Network/UDPServer.h" #include "Network/UDPServer.h"
#include "Network/UDPClient.h" //LOL
#include "Network/MessageType.h" #include "Network/MessageType.h"
#include "Network/PlayerDefinition.h" #include "Network/PlayerDefinition.h"
#include "Core/World.h" #include "Core/World.h"
@@ -17,7 +18,6 @@
#include "Core/EPlayerDamage.h" #include "Core/EPlayerDamage.h"
#include "Network/EPlayerDisconnected.h" #include "Network/EPlayerDisconnected.h"
#include "Core/EPlayerSpawned.h" #include "Core/EPlayerSpawned.h"
#include "../Game/Events/EDoubleJump.h"
#include "Core/EEntityDeleted.h" #include "Core/EEntityDeleted.h"
#include "Core/EComponentDeleted.h" #include "Core/EComponentDeleted.h"
@@ -81,9 +81,8 @@ private:
void parseOnInputCommand(Packet& packet); void parseOnInputCommand(Packet& packet);
void parseClientPing(); void parseClientPing();
void parsePing(); void parsePing();
bool parseDoubleJump(Packet& packet); void parseUDPConnect(Packet & packet);
void parseUDPConnect(Packet& packet); void parseTCPConnect(Packet & packet);
void parseTCPConnect(Packet& packet);
void parseDisconnect(); void parseDisconnect();
void parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint); void parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint);
bool shouldSendToClient(EntityWrapper childEntity); bool shouldSendToClient(EntityWrapper childEntity);
+3 -2
View File
@@ -25,9 +25,10 @@ private:
std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor; std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
boost::shared_ptr<boost::asio::ip::tcp::socket> lastReceivedSocket; boost::shared_ptr<boost::asio::ip::tcp::socket> lastReceivedSocket;
void handle_accept(boost::shared_ptr<boost::asio::ip::tcp::socket> socket,
int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers,
const boost::system::error_code& error);
int readBuffer(PlayerDefinition& playerDefinition); int readBuffer(PlayerDefinition& playerDefinition);
PlayerID getPlayerIDFromEndpoint(const std::map<PlayerID, PlayerDefinition>& connectedPlayers,
boost::asio::ip::address address, unsigned short port);
int GetPort(); int GetPort();
std::string GetAddress(); std::string GetAddress();
int m_Port = 0; int m_Port = 0;
+1 -1
View File
@@ -8,7 +8,7 @@ namespace Events
struct DoubleJump : public Event struct DoubleJump : public Event
{ {
EntityID entityID;
}; };
} }
@@ -34,13 +34,9 @@ private:
glm::vec3 m_LastPosition = glm::vec3(); glm::vec3 m_LastPosition = glm::vec3();
// The logic for making the sound play when player is moving // The logic for making the sound play when player is moving
void playerStep(double dt); void playerStep(double dt);
// Spawn a hexagon at origin of an Entity
void spawnHexagon(EntityWrapper target);
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned; EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(Events::PlayerSpawned& e); bool OnPlayerSpawned(Events::PlayerSpawned& e);
EventRelay<PlayerMovementSystem, Events::DoubleJump> m_EDoubleJump;
bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e);
void updateMovementControllers(double dt); void updateMovementControllers(double dt);
void updateVelocity(EntityWrapper player, double dt); void updateVelocity(EntityWrapper player, double dt);
@@ -1,13 +1,14 @@
#ifndef AssaultWeaponBehaviour_h__
#define AssaultWeaponBehaviour_h__
#include "Sound/EPlaySoundOnEntity.h" #include "Sound/EPlaySoundOnEntity.h"
#include "Collision/Collision.h" #include "Collision/Collision.h"
#include "Rendering/AnimationSystem.h"
#include "Core/ConfigFile.h" #include "Core/ConfigFile.h"
#include "WeaponBehaviour.h" #include "WeaponBehaviour.h"
#include "../SpawnerSystem.h" #include "../SpawnerSystem.h"
#include "Core/EPlayerDamage.h" #include "Core/EPlayerDamage.h"
#include "Core/EShoot.h" #include "Core/EShoot.h"
class AssaultWeaponBehaviour : public WeaponBehaviour class AssaultWeaponBehaviour : public WeaponBehaviour
{ {
public: public:
@@ -22,16 +23,13 @@ public:
private: private:
EntityWrapper m_FirstPersonModel; EntityWrapper m_FirstPersonModel;
EntityWrapper m_ThirdPersonModel; EntityWrapper m_ThirdPersonModel;
// State // State
bool m_Firing = false; bool m_Firing = false;
bool m_Reloading = false; bool m_Reloading = false;
double m_ReloadTimer = 0.0; double m_ReloadTimer = 0.0;
EntityWrapper m_FirstPersonReloadImpersonator;
EntityWrapper m_ThirdPersonReloadImpersonator;
double m_TimeSinceLastFire = 0.0; double m_TimeSinceLastFire = 0.0;
EntityWrapper m_FirstPersonReloadImpostor;
EventRelay<WeaponBehaviour, Events::AnimationComplete> m_EAnimationComplete;
bool OnAnimationComplete(Events::AnimationComplete& e);
bool hasAmmo(); bool hasAmmo();
void fireRound(); void fireRound();
@@ -47,3 +45,5 @@ private:
bool shoot(double damage); bool shoot(double damage);
void showHitMarker(); void showHitMarker();
}; };
#endif
@@ -0,0 +1,16 @@
#include "WeaponBehaviour.h"
class DefenderWeaponBehaviour : public WeaponBehaviour
{
public:
DefenderWeaponBehaviour(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:
double m_TimeSinceLastFire = 0.0;
};
@@ -8,17 +8,21 @@
class WeaponBehaviour : public System class WeaponBehaviour : public System
{ {
friend class WeaponSystem;
public: public:
WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player) WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player, EntityWrapper firstPersonWeapon, EntityWrapper thirdPersonWeapon)
: System(systemParams) : System(systemParams)
, m_Renderer(renderer) , m_Renderer(renderer)
, m_CollisionOctree(collisionOctree) , m_CollisionOctree(collisionOctree)
, m_Player(player) , m_Player(player)
, m_FirstPerson(firstPersonWeapon)
, m_ThirdPerson(thirdPersonWeapon)
{ } { }
virtual ~WeaponBehaviour() = default; virtual ~WeaponBehaviour() = default;
WeaponBehaviour(const WeaponBehaviour&) = delete; WeaponBehaviour(const WeaponBehaviour&) = delete;
WeaponBehaviour& operator=(const WeaponBehaviour &) = delete; WeaponBehaviour& operator=(const WeaponBehaviour&) = delete;
virtual void Fire() = 0; virtual void Fire() = 0;
virtual void CeaseFire() { } virtual void CeaseFire() { }
@@ -29,6 +33,8 @@ protected:
IRenderer* m_Renderer; IRenderer* m_Renderer;
Octree<EntityAABB>* m_CollisionOctree; Octree<EntityAABB>* m_CollisionOctree;
EntityWrapper m_Player; EntityWrapper m_Player;
EntityWrapper m_FirstPerson;
EntityWrapper m_ThirdPerson;
}; };
#endif #endif
+1
View File
@@ -46,4 +46,5 @@
<xs:include schemaLocation="Components/Page.xsd"/> <xs:include schemaLocation="Components/Page.xsd"/>
<xs:include schemaLocation="Components/SpriteIndicator.xsd"/> <xs:include schemaLocation="Components/SpriteIndicator.xsd"/>
<xs:include schemaLocation="Components/Button.xsd"/> <xs:include schemaLocation="Components/Button.xsd"/>
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
</xs:schema> </xs:schema>
+1
View File
@@ -2,6 +2,7 @@
<Physics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Physics.xsd"> <Physics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Physics.xsd">
<Velocity X="0" Y="0" Z="0"/> <Velocity X="0" Y="0" Z="0"/>
<Gravity>true</Gravity> <Gravity>true</Gravity>
<PrevOrigin X="-9876.5" Y="-9876.5" Z="-9876.5"/>
<IsOnGround>false</IsOnGround> <IsOnGround>false</IsOnGround>
<VerticalStepHeight>0.33</VerticalStepHeight> <VerticalStepHeight>0.33</VerticalStepHeight>
</Physics> </Physics>
+1
View File
@@ -13,6 +13,7 @@
<xs:annotation><xs:documentation>m/s^2</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>m/s^2</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="Gravity" type="t:bool" minOccurs="0"/> <xs:element name="Gravity" type="t:bool" minOccurs="0"/>
<xs:element name="PrevOrigin" type="t:Vector" minOccurs="0"/>
<xs:element name="IsOnGround" type="t:bool" minOccurs="0"/> <xs:element name="IsOnGround" type="t:bool" minOccurs="0"/>
<xs:element name="VerticalStepHeight" type="t:double" minOccurs="0"> <xs:element name="VerticalStepHeight" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The largest height of a "stair-step" that can be walked over</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>The largest height of a "stair-step" that can be walked over</xs:documentation></xs:annotation>
-3
View File
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Trigger xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Trigger.xsd">
</Trigger>
-17
View File
@@ -1,17 +0,0 @@
<?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="Weapon">
<xs:complexType>
<xs:all>
<xs:element name="MagSize" type="t:int" minOccurs="0"/>
<xs:element name="MaxAmmo" type="t:int" minOccurs="0"/>
<xs:element name="CurrentAmmoInMag" type="t:int" minOccurs="0"/>
<xs:element name="CurrentAmmo" type="t:int" minOccurs="0"/>
<xs:element name="RPM" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<WeaponAttachment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WeaponAttachment.xsd">
<Person><FirstPerson/></Person>
</WeaponAttachment>
@@ -0,0 +1,37 @@
<?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:complexType name="PersonEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="FirstPerson" type="t:int" fixed="0" minOccurs="0"/>
<xs:element name="ThirdPerson" type="t:int" fixed="1" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="WeaponSlotEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Primary" type="t:int" fixed="1" minOccurs="0"/>
<xs:element name="Secondary" type="t:int" fixed="2" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="WeaponAttachment">
<xs:annotation><xs:documentation>Combine with a spawner to define a weapon attachment point</xs:documentation></xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Person" type="PersonEnum" minOccurs="0"/>
<xs:element name="Slot" type="WeaponSlotEnum" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1
View File
@@ -13,6 +13,7 @@
<c:DashAbility/> <c:DashAbility/>
<c:Health/> <c:Health/>
<c:Physics> <c:Physics>
<PrevOrigin X="0" Y="0.772000015" Z="0"/>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/> <Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
</c:Physics> </c:Physics>
<c:Player> <c:Player>
+1
View File
@@ -13,6 +13,7 @@
<c:DashAbility/> <c:DashAbility/>
<c:Health/> <c:Health/>
<c:Physics> <c:Physics>
<PrevOrigin X="0" Y="0.772000015" Z="0"/>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/> <Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
</c:Physics> </c:Physics>
<c:Player> <c:Player>
+1
View File
@@ -50,6 +50,7 @@
<xs:element ref="c:Menu" minOccurs="0"/> <xs:element ref="c:Menu" minOccurs="0"/>
<xs:element ref="c:Page" minOccurs="0"/> <xs:element ref="c:Page" minOccurs="0"/>
<xs:element ref="c:Button" minOccurs="0"/> <xs:element ref="c:Button" minOccurs="0"/>
<xs:element ref="c:WeaponAttachment" minOccurs="0"/>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
+43 -45
View File
@@ -16,51 +16,51 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
EntityAABB& boxA = *boundingBox; EntityAABB& boxA = *boundingBox;
bool everHitTheGround = false; bool everHitTheGround = false;
auto prevPosIt = m_PrevPositions.find(entity); glm::vec3 size = boxA.Size();
if (prevPosIt != m_PrevPositions.end()) { float diameter = std::min(size.x, size.z);
glm::vec3 size = boxA.Size(); glm::vec3 prevOrigin = (glm::vec3)cPhysics["PrevOrigin"];
float diameter = std::min(size.x, size.z); glm::vec3 toCurrentPos = boxA.Origin() - prevOrigin;
glm::vec3 prevOrigin = prevPosIt->second; float rayLength = glm::length(toCurrentPos) + 0.5f*diameter;
glm::vec3 toCurrentPos = boxA.Origin() - prevOrigin; //If the entity has moved farther than the size of its box, we need to handle it specially.
float rayLength = glm::length(toCurrentPos) + 0.5f*diameter; bool traceCollision = rayLength > diameter;
//If the entity has moved farther than the size of its box, we need to handle it specially. //hack solution: If prevOrigin is less than -9000 in all dimensions,
if (rayLength > diameter) { //then it means it is not set, i.e. this is the first collision check for the entity.
Ray ray(prevOrigin, toCurrentPos); if (traceCollision && glm::any(glm::greaterThan((glm::vec3)cPhysics["PrevOrigin"], glm::vec3(-9000.f)))) {
m_OctreeResult.clear(); Ray ray(prevOrigin, toCurrentPos);
m_Octree->ObjectsPossiblyHitByRay(ray, m_OctreeResult); m_OctreeResult.clear();
for (auto& boxB : m_OctreeResult) { m_Octree->ObjectsPossiblyHitByRay(ray, m_OctreeResult);
if (boxA.Entity == boxB.Entity) { for (auto& boxB : m_OctreeResult) {
if (boxA.Entity == boxB.Entity) {
continue;
}
bool hit;
float dist;
if (boxB.Entity.HasComponent("Model")) {
RawModel* model;
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
try {
model = ResourceManager::Load<RawModel, true>(res);
} catch (const std::exception&) {
continue; continue;
} }
bool hit; float u, v;
float dist; hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, Transform::ModelMatrix(boxB.Entity), dist, u, v);
if (boxB.Entity.HasComponent("Model")) { } else {
RawModel* model; hit = Collision::RayVsAABB(ray, boxB, dist);
std::string res = (std::string)boxB.Entity["Model"]["Resource"]; }
try { if (hit && dist < rayLength) {
model = ResourceManager::Load<RawModel, true>(res); //Set the entity to where it was colliding, minus the maximum box size.
} catch (const std::exception&) { //TODO: Perhaps this should be done slightly more properly.
continue; glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction();
} glm::vec3 resolve = newOriginPos - boxA.Origin();
float u, v; (glm::vec3&)cTransform["Position"] += resolve;
hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, Transform::ModelMatrix(boxB.Entity), dist, u, v); boxA = *Collision::EntityAbsoluteAABB(entity);
} else { if (resolve.y > 0) {
hit = Collision::RayVsAABB(ray, boxB, dist); everHitTheGround = true;
} (bool)cPhysics["IsOnGround"] = true;
if (hit && dist < rayLength) { ((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
//Set the entity to where it was colliding, minus the maximum box size.
//TODO: Perhaps this should be done slightly more properly.
glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction();
glm::vec3 resolve = newOriginPos - boxA.Origin();
(glm::vec3&)cTransform["Position"] += resolve;
boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolve.y > 0) {
everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true;
((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
}
break;
} }
break;
} }
} }
} }
@@ -90,7 +90,6 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
(glm::vec3&)cTransform["Position"] += resolutionVector; (glm::vec3&)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity; cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) { if (isOnGround) {
everHitTheGround = true; everHitTheGround = true;
@@ -100,7 +99,6 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
} else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) { } else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
//Enter here if boxB has no Model. //Enter here if boxB has no Model.
(glm::vec3&)cTransform["Position"] += resolutionVector; (glm::vec3&)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolutionVector.y > 0) { if (resolutionVector.y > 0) {
everHitTheGround = true; everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true; (bool)cPhysics["IsOnGround"] = true;
@@ -114,5 +112,5 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
(bool)cPhysics["IsOnGround"] = false; (bool)cPhysics["IsOnGround"] = false;
} }
m_PrevPositions[entity] = boxA.Origin(); (glm::vec3&)cPhysics["PrevOrigin"] = boxA.Origin();
} }
+14 -27
View File
@@ -51,15 +51,11 @@ EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& compone
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
EntityWrapper EntityWrapper::Clone(EntityWrapper parent /*= Invalid*/) std::vector<EntityWrapper> EntityWrapper::ChildrenWithComponent(const std::string& componentType)
{ {
if (!Valid()) { std::vector<EntityWrapper> childrenWithComponent;
return EntityWrapper::Invalid; childrenWithComponentRecursive(componentType, *this, childrenWithComponent);
} return childrenWithComponent;
EntityWrapper clone = cloneRecursive(*this, EntityWrapper::Invalid);
this->World->SetParent(clone.ID, parent.ID);
return clone;
} }
bool EntityWrapper::IsChildOf(EntityWrapper potentialParent) bool EntityWrapper::IsChildOf(EntityWrapper potentialParent)
@@ -122,7 +118,7 @@ EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name,
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
auto itPair = this->World->GetDirectChildren(parent); auto itPair = this->World->GetChildren(parent);
if (itPair.first == itPair.second) { if (itPair.first == itPair.second) {
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
@@ -142,27 +138,18 @@ EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name,
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
EntityWrapper EntityWrapper::cloneRecursive(EntityWrapper entity, EntityWrapper parent) void EntityWrapper::childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent)
{ {
EntityWrapper clone = EntityWrapper(entity.World, entity.World->CreateEntity(parent.ID)); auto itPair = this->World->GetChildren(entity.ID);
entity.World->SetName(clone.ID, entity.Name()); if (itPair.first == itPair.second) {
return;
}
// Clone components for (auto it = itPair.first; it != itPair.second; ++it) {
for (auto& kv : entity.World->GetComponentPools()) { if (entity.HasComponent(componentType)) {
if (kv.second->KnowsEntity(entity.ID)) { childrenWithComponent.push_back(entity);
ComponentWrapper c1 = kv.second->GetByEntity(entity.ID);
ComponentWrapper c2 = entity.World->AttachComponent(clone.ID, kv.first);
c1.Copy(c2);
} }
childrenWithComponentRecursive(componentType, entity, childrenWithComponent);
} }
// Clone children
auto children = entity.World->GetDirectChildren(entity.ID);
for (auto it = children.first; it != children.second; ++it) {
EntityWrapper child(entity.World, it->second);
cloneRecursive(child, clone);
}
return clone;
} }
+1 -1
View File
@@ -127,7 +127,7 @@ void World::SetParent(EntityID entity, EntityID parent)
m_EntityChildren.insert(std::make_pair(parent, entity)); m_EntityChildren.insert(std::make_pair(parent, entity));
} }
const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> World::GetDirectChildren(EntityID entity) const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> World::GetChildren(EntityID entity)
{ {
return m_EntityChildren.equal_range(entity); return m_EntityChildren.equal_range(entity);
} }
-18
View File
@@ -580,11 +580,6 @@ void EditorGUI::createWidgetToolButton(WidgetMode mode)
bool EditorGUI::OnKeyDown(const Events::KeyDown& e) bool EditorGUI::OnKeyDown(const Events::KeyDown& e)
{ {
ImGuiIO& io = ImGui::GetIO();
if (io.WantCaptureKeyboard) {
return false;
}
if (e.ModCtrl && e.KeyCode == GLFW_KEY_S) { if (e.ModCtrl && e.KeyCode == GLFW_KEY_S) {
if (m_CurrentSelection.Valid()) { if (m_CurrentSelection.Valid()) {
EntityWrapper baseParent = m_CurrentSelection; EntityWrapper baseParent = m_CurrentSelection;
@@ -603,19 +598,6 @@ bool EditorGUI::OnKeyDown(const Events::KeyDown& e)
entityImport(m_World); entityImport(m_World);
} }
if (e.ModCtrl && e.KeyCode == GLFW_KEY_C) {
m_CopyTarget = m_CurrentSelection;
}
if (e.ModCtrl && e.KeyCode == GLFW_KEY_V) {
if (m_OnEntityPaste != nullptr) {
EntityWrapper copy = m_OnEntityPaste(m_CopyTarget, m_CurrentSelection);
if (copy != EntityWrapper::Invalid) {
SelectEntity(copy);
}
}
}
if (e.KeyCode == GLFW_KEY_DELETE) { if (e.KeyCode == GLFW_KEY_DELETE) {
if (m_CurrentSelection.Valid()) { if (m_CurrentSelection.Valid()) {
entityDelete(m_CurrentSelection); entityDelete(m_CurrentSelection);
-6
View File
@@ -28,7 +28,6 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
m_EditorGUI->SetEntityDeleteCallback(std::bind(&EditorSystem::OnEntityDelete, this, std::placeholders::_1)); m_EditorGUI->SetEntityDeleteCallback(std::bind(&EditorSystem::OnEntityDelete, this, std::placeholders::_1));
m_EditorGUI->SetEntityChangeParentCallback(std::bind(&EditorSystem::OnEntityChangeParent, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetEntityChangeParentCallback(std::bind(&EditorSystem::OnEntityChangeParent, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetEntityChangeNameCallback(std::bind(&EditorSystem::OnEntityChangeName, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetEntityChangeNameCallback(std::bind(&EditorSystem::OnEntityChangeName, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetEntityPasteCallback(std::bind(&EditorSystem::OnEntityPaste, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1)); m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1));
@@ -161,11 +160,6 @@ void EditorSystem::OnEntityChangeName(EntityWrapper entity, const std::string& n
} }
} }
EntityWrapper EditorSystem::OnEntityPaste(EntityWrapper entityToCopy, EntityWrapper parent)
{
return entityToCopy.Clone(parent);
}
void EditorSystem::OnComponentAttach(EntityWrapper entity, const std::string& componentType) void EditorSystem::OnComponentAttach(EntityWrapper entity, const std::string& componentType)
{ {
if (entity.Valid()) { if (entity.Valid()) {
+21 -54
View File
@@ -32,7 +32,6 @@ void Client::Connect(std::string address, int port)
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Client::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Client::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Client::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Client::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Client::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Client::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump);
EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers); EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers);
auto config = ResourceManager::Load<ConfigFile>("Config.ini"); auto config = ResourceManager::Load<ConfigFile>("Config.ini");
m_Address = address; m_Address = address;
@@ -141,9 +140,6 @@ void Client::parseMessageType(Packet& packet)
case MessageType::OnPlayerDamage: case MessageType::OnPlayerDamage:
parsePlayerDamage(packet); parsePlayerDamage(packet);
break; break;
case MessageType::OnDoubleJump:
parseDoubleJump(packet);
break;
default: default:
break; break;
} }
@@ -261,14 +257,8 @@ void Client::parseEntityDeletion(Packet & packet)
if (m_ServerIDToClientID.find(entityToDelete) != m_ServerIDToClientID.end()) { if (m_ServerIDToClientID.find(entityToDelete) != m_ServerIDToClientID.end()) {
EntityID localEntity = m_ServerIDToClientID.at(entityToDelete); EntityID localEntity = m_ServerIDToClientID.at(entityToDelete);
if (m_World->ValidEntity(localEntity)) { if (m_World->ValidEntity(localEntity)) {
if (m_World->HasComponent(localEntity,"Player")) { m_World->DeleteEntity(localEntity);
Events::PlayerDeath e; deleteFromServerClientMaps(entityToDelete, localEntity);
e.Player = EntityWrapper(m_World, localEntity);
m_EventBroker->Publish(e);
} else {
m_World->DeleteEntity(localEntity);
deleteFromServerClientMaps(entityToDelete, localEntity);
}
} }
} }
} }
@@ -282,20 +272,6 @@ void Client::parseComponentDeletion(Packet & packet)
} }
} }
void Client::parseDoubleJump(Packet & packet)
{
EntityID serverID = packet.ReadPrimitive<EntityID>();
if (!serverClientMapsHasEntity(serverID)) {
return;
}
Events::DoubleJump e;
e.entityID = m_ServerIDToClientID.at(serverID);
// If player is local player do not publish to prevent infinite feedback loop
if (e.entityID != m_LocalPlayer.ID) {
m_EventBroker->Publish(e);
}
}
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
{ {
for (auto field : componentInfo.FieldsInOrder) { for (auto field : componentInfo.FieldsInOrder) {
@@ -372,7 +348,9 @@ void Client::parseSnapshot(Packet& packet)
EntityWrapper localEntity(m_World, localEntityID); EntityWrapper localEntity(m_World, localEntityID);
// Update entity // Update entity
if (m_World->HasComponent(localEntityID, componentType)) { if (m_World->HasComponent(localEntityID, componentType)) {
// TODO Fix memory leak here if (localEntity.Name() == "CapturePointHUD") {
UpdateLocalCapturePointHUD(localEntity);
}
SharedComponentWrapper newComponent = createSharedComponent(packet, localEntityID, componentInfo); SharedComponentWrapper newComponent = createSharedComponent(packet, localEntityID, componentInfo);
bool shouldApply = true; bool shouldApply = true;
// Apply potential filter function // Apply potential filter function
@@ -383,7 +361,6 @@ void Client::parseSnapshot(Packet& packet)
ComponentWrapper currentComponent = m_World->GetComponent(localEntityID, componentType); ComponentWrapper currentComponent = m_World->GetComponent(localEntityID, componentType);
memcpy(currentComponent.Data, newComponent.Data, componentInfo.Stride); memcpy(currentComponent.Data, newComponent.Data, componentInfo.Stride);
} }
//if (localEntity != m_LocalPlayer && !localEntity.IsChildOf(m_LocalPlayer)) { //if (localEntity != m_LocalPlayer && !localEntity.IsChildOf(m_LocalPlayer)) {
// updateFields(packet, componentInfo, localEntityID); // updateFields(packet, componentInfo, localEntityID);
//} else { //} else {
@@ -400,11 +377,7 @@ void Client::parseSnapshot(Packet& packet)
if (serverParentID == EntityID_Invalid) { if (serverParentID == EntityID_Invalid) {
newLocalEntityID = m_World->CreateEntity(EntityID_Invalid); newLocalEntityID = m_World->CreateEntity(EntityID_Invalid);
} else { } else {
if (serverClientMapsHasEntity(serverParentID)) { newLocalEntityID = m_World->CreateEntity(m_ServerIDToClientID.at(serverParentID));
newLocalEntityID = m_World->CreateEntity(m_ServerIDToClientID.at(serverParentID));
} else {
newLocalEntityID = m_World->CreateEntity(EntityID_Invalid);
}
} }
m_World->SetName(newLocalEntityID, serverEntityName); m_World->SetName(newLocalEntityID, serverEntityName);
insertIntoServerClientMaps(serverEntityID, newLocalEntityID); insertIntoServerClientMaps(serverEntityID, newLocalEntityID);
@@ -414,16 +387,26 @@ void Client::parseSnapshot(Packet& packet)
} }
// Parent logic // Parent logic
// This should be enough beacause we know that the entities arives in pre-order (there will always be a parent) // This should be enough beacause we know that the entities arives in pre-order (there will always be a parent)
if (serverParentID != EntityID_Invalid && serverClientMapsHasEntity(serverParentID)) { if (serverParentID != EntityID_Invalid) {
EntityID localEntityID = m_ServerIDToClientID.at(serverEntityID); EntityID localEntityID = m_ServerIDToClientID.at(serverEntityID);
if (m_World->GetParent(localEntityID) != m_ServerIDToClientID.at(serverParentID)) { m_World->SetParent(localEntityID, m_ServerIDToClientID.at(serverParentID));
m_World->SetParent(localEntityID, m_ServerIDToClientID.at(serverParentID));
}
} }
} }
parseSpawnEvents(); parseSpawnEvents();
} }
void Client::UpdateLocalCapturePointHUD(EntityWrapper capturePointHUD)
{
//auto children = m_World->GetChildren(capturePointHUD.ID);
//for (auto it = children.first; it != children.second; it++) {
// it->first
//}
//
//EntityWrapper& localHUD = m_LocalPlayer.FirstChildByName("HUD").FirstChildByName("CapturePointHUD");
//m_World->GetComponentPools()
}
void Client::disconnect() void Client::disconnect()
{ {
m_IsConnected = false; m_IsConnected = false;
@@ -486,11 +469,6 @@ bool Client::OnPlayerDamage(const Events::PlayerDamage & e)
if (e.Inflictor != m_LocalPlayer) { if (e.Inflictor != m_LocalPlayer) {
return false; return false;
} }
// Could this happen?
//if (!clientServerMapsHasEntity(e.Inflictor.ID)
// || !clientServerMapsHasEntity(e.Victim.ID)) {
// return;
//}
Packet packet(MessageType::OnPlayerDamage, m_SendPacketID); Packet packet(MessageType::OnPlayerDamage, m_SendPacketID);
packet.WritePrimitive(m_ClientIDToServerID.at(e.Inflictor.ID)); packet.WritePrimitive(m_ClientIDToServerID.at(e.Inflictor.ID));
@@ -525,7 +503,7 @@ void Client::parsePlayerDamage(Packet& packet)
Events::PlayerDamage e; Events::PlayerDamage e;
PlayerID victimID = packet.ReadPrimitive<EntityID>(); PlayerID victimID = packet.ReadPrimitive<EntityID>();
PlayerID inflictorID = packet.ReadPrimitive<EntityID>(); PlayerID inflictorID = packet.ReadPrimitive<EntityID>();
if (!serverClientMapsHasEntity(victimID) || !serverClientMapsHasEntity(inflictorID)) { if(!serverClientMapsHasEntity(victimID) || !serverClientMapsHasEntity(inflictorID)){
return; return;
} }
e.Inflictor = EntityWrapper(m_World, m_ServerIDToClientID.at(victimID)); e.Inflictor = EntityWrapper(m_World, m_ServerIDToClientID.at(victimID));
@@ -537,17 +515,6 @@ void Client::parsePlayerDamage(Packet& packet)
} }
} }
bool Client::OnDoubleJump(Events::DoubleJump & e)
{
if (!clientServerMapsHasEntity(e.entityID) || e.entityID != m_LocalPlayer.ID) {
return false;
}
Packet packet(MessageType::OnDoubleJump);
packet.WritePrimitive(m_ClientIDToServerID.at(e.entityID));
m_Reliable.Send(packet);
return true;
}
void Client::sendLocalPlayerTransform() void Client::sendLocalPlayerTransform()
{ {
if (!m_LocalPlayer.Valid()) { if (!m_LocalPlayer.Valid()) {
+42 -55
View File
@@ -29,8 +29,9 @@ Server::~Server()
void Server::Update() void Server::Update()
{ {
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers); PlayerDefinition pd;
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
for (auto& kv : m_ConnectedPlayers) { for (auto& kv : m_ConnectedPlayers) {
while (kv.second.TCPSocket->available()) { while (kv.second.TCPSocket->available()) {
// Packet will get real data in receive // Packet will get real data in receive
@@ -46,7 +47,6 @@ void Server::Update()
} }
} }
PlayerDefinition pd;
while (m_Unreliable.IsSocketAvailable()) { while (m_Unreliable.IsSocketAvailable()) {
// Packet will get real data in receive // Packet will get real data in receive
Packet packet(MessageType::Invalid); Packet packet(MessageType::Invalid);
@@ -65,7 +65,7 @@ void Server::Update()
PlayerDefinition localArea; PlayerDefinition localArea;
localArea.Endpoint = boost::asio::ip::udp::endpoint(); localArea.Endpoint = boost::asio::ip::udp::endpoint();
m_ServerlistRequest.Receive(packet, localArea); m_ServerlistRequest.Receive(packet, localArea);
if (packet.GetMessageType() == MessageType::ServerlistRequest) { if(packet.GetMessageType() == MessageType::ServerlistRequest) {
packet.ReadPrimitive<int>(); // Pop size packet.ReadPrimitive<int>(); // Pop size
packet.ReadPrimitive<int>(); // Pop MsgType packet.ReadPrimitive<int>(); // Pop MsgType
packet.ReadPrimitive<int>(); // Pop packet ID packet.ReadPrimitive<int>(); // Pop packet ID
@@ -76,7 +76,7 @@ void Server::Update()
} }
// Check if players have disconnected // Check if players have disconnected
for (int i = 0; i < m_PlayersToDisconnect.size(); i++) { for (int i = 0; i < m_PlayersToDisconnect.size(); i++) {
disconnect(m_PlayersToDisconnect.at(i)); disconnect(m_PlayersToDisconnect.at(i));
} }
m_PlayersToDisconnect.clear(); m_PlayersToDisconnect.clear();
@@ -136,10 +136,7 @@ void Server::parseMessageType(Packet& packet)
parseOnPlayerDamage(packet); parseOnPlayerDamage(packet);
break; break;
case MessageType::PlayerTransform: case MessageType::PlayerTransform:
parsePlayerTransform(packet); parsePlayerTransform(packet);
break;
case MessageType::OnDoubleJump:
parseDoubleJump(packet);
break; break;
default: default:
break; break;
@@ -186,7 +183,7 @@ void Server::addInputCommandsToPacket(Packet& packet)
void Server::addPlayersToPacket(Packet & packet, EntityID entityID) void Server::addPlayersToPacket(Packet & packet, EntityID entityID)
{ {
auto itPair = m_World->GetDirectChildren(entityID); auto itPair = m_World->GetChildren(entityID);
std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools(); std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools();
// Loop through every child // Loop through every child
for (auto it = itPair.first; it != itPair.second; it++) { for (auto it = itPair.first; it != itPair.second; it++) {
@@ -194,47 +191,49 @@ void Server::addPlayersToPacket(Packet & packet, EntityID entityID)
// HACK: Only sync players for now, since the map turned out to be TOO LARGE to send in one snapshot and Simon's computer shits itself // HACK: Only sync players for now, since the map turned out to be TOO LARGE to send in one snapshot and Simon's computer shits itself
// HACK: Also checked CapturePointHUD for now. (this would get out of sync); // HACK: Also checked CapturePointHUD for now. (this would get out of sync);
EntityWrapper childEntity(m_World, childEntityID); EntityWrapper childEntity(m_World, childEntityID);
if (shouldSendToClient(childEntity)) { if (!shouldSendToClient(childEntity)) {
// Write EntityID and parentsID and Entity name continue;
packet.WritePrimitive(childEntityID); }
packet.WritePrimitive(entityID);
packet.WriteString(m_World->GetName(childEntityID)); // Write EntityID and parentsID and Entity name
// Write components to child packet.WritePrimitive(childEntityID);
int numberOfComponents = 0; packet.WritePrimitive(entityID);
for (auto& i : worldComponentPools) { packet.WriteString(m_World->GetName(childEntityID));
if (i.second->KnowsEntity(childEntityID)) { // Write components to child
numberOfComponents++; int numberOfComponents = 0;
} for (auto& i : worldComponentPools) {
if (i.second->KnowsEntity(childEntityID)) {
numberOfComponents++;
} }
// Write how many components should be read }
packet.WritePrimitive(numberOfComponents); // Write how many components should be read
for (auto& i : worldComponentPools) { packet.WritePrimitive(numberOfComponents);
// If the entity exist in the pool for (auto& i : worldComponentPools) {
if (i.second->KnowsEntity(childEntityID)) { // If the entity exist in the pool
ComponentWrapper componentWrapper = i.second->GetByEntity(childEntityID); if (i.second->KnowsEntity(childEntityID)) {
// ComponentType ComponentWrapper componentWrapper = i.second->GetByEntity(childEntityID);
packet.WriteString(componentWrapper.Info.Name); // ComponentType
// Loop through fields packet.WriteString(componentWrapper.Info.Name);
for (auto& componentField : componentWrapper.Info.FieldsInOrder) { // Loop through fields
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField); for (auto& componentField : componentWrapper.Info.FieldsInOrder) {
if (fieldInfo.Type == "string") { ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
std::string& value = componentWrapper[componentField]; if (fieldInfo.Type == "string") {
packet.WriteString(value); std::string& value = componentWrapper[componentField];
} else { packet.WriteString(value);
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride); } else {
} packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
} }
} }
} }
} }
// Go to to your children // Go to to your children
addPlayersToPacket(packet, childEntityID); addChildrenToPacket(packet, childEntityID);
} }
} }
void Server::addChildrenToPacket(Packet & packet, EntityID entityID) void Server::addChildrenToPacket(Packet & packet, EntityID entityID)
{ {
auto itPair = m_World->GetDirectChildren(entityID); auto itPair = m_World->GetChildren(entityID);
std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools(); std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools();
// Loop through every child // Loop through every child
for (auto it = itPair.first; it != itPair.second; it++) { for (auto it = itPair.first; it != itPair.second; it++) {
@@ -456,7 +455,8 @@ bool Server::OnInputCommand(const Events::InputCommand & e)
} }
isReadingData = !isReadingData; isReadingData = !isReadingData;
m_SaveDataTimer = std::clock(); m_SaveDataTimer = std::clock();
} else if (e.Command == "KickPlayer" && e.Value > 0) { }
else if (e.Command == "KickPlayer" && e.Value > 0) {
kick(0); kick(0);
} }
@@ -507,7 +507,7 @@ bool Server::OnPlayerDamage(const Events::PlayerDamage& e)
packet.WritePrimitive(e.Damage); packet.WritePrimitive(e.Damage);
reliableBroadcast(packet); reliableBroadcast(packet);
return true; return false;
} }
void Server::parseClientPing() void Server::parseClientPing()
@@ -536,12 +536,6 @@ void Server::parsePing()
} }
} }
bool Server::parseDoubleJump(Packet & packet)
{
reliableBroadcast(packet);
return true;
}
void Server::parseOnInputCommand(Packet& packet) void Server::parseOnInputCommand(Packet& packet)
{ {
PlayerID player = -1; PlayerID player = -1;
@@ -601,15 +595,8 @@ void Server::parsePlayerTransform(Packet& packet)
bool Server::shouldSendToClient(EntityWrapper childEntity) bool Server::shouldSendToClient(EntityWrapper childEntity)
{ {
auto children = m_World->GetDirectChildren(childEntity.ID);
for (auto it = children.first; it != children.second; it++) {
EntityWrapper child(m_World, it->second);
if(child.HasComponent("CapturePoint")) {
return true;
}
}
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid() return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint"); || childEntity.HasComponent("CapturePoint") || childEntity.FirstParentWithComponent("CapturePoint").Valid();
} }
PlayerID Server::GetPlayerIDFromEndpoint() PlayerID Server::GetPlayerIDFromEndpoint()
+23 -17
View File
@@ -4,8 +4,6 @@ using namespace boost::asio::ip;
TCPServer::TCPServer() TCPServer::TCPServer()
{ {
acceptor = std::unique_ptr<tcp::acceptor>(new tcp::acceptor(m_IOService, tcp::endpoint(tcp::v4(), 27666))); acceptor = std::unique_ptr<tcp::acceptor>(new tcp::acceptor(m_IOService, tcp::endpoint(tcp::v4(), 27666)));
// Make the acceptor non-blocking so we wont get stuck in AcceptNewConnections().
acceptor->non_blocking(true);
m_Port = GetPort(); m_Port = GetPort();
m_Address = GetAddress(); m_Address = GetAddress();
} }
@@ -15,24 +13,14 @@ TCPServer::~TCPServer()
void TCPServer::AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers) void TCPServer::AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers)
{ {
boost::system::error_code error;
boost::shared_ptr<tcp::socket> newSocket = boost::shared_ptr<tcp::socket>(new tcp::socket(m_IOService)); boost::shared_ptr<tcp::socket> newSocket = boost::shared_ptr<tcp::socket>(new tcp::socket(m_IOService));
acceptor->accept(*newSocket, error); m_IOService.poll();
// If no error occured add new tcp connection acceptor->async_accept(*newSocket,
if (!error) { boost::bind(&TCPServer::handle_accept, this, newSocket, boost::ref(nextPlayerID), boost::ref(connectedPlayers),
// Add tcp socket to connections boost::asio::placeholders::error));
boost::asio::ip::tcp::no_delay option(true);
newSocket->set_option(option);
PlayerDefinition pd;
pd.StopTime = std::clock();
pd.TCPSocket = newSocket;
pd.TCPAddress = newSocket.get()->remote_endpoint().address();
pd.TCPPort = newSocket.get()->remote_endpoint().port();
connectedPlayers[nextPlayerID++] = pd;
}
} }
PlayerID TCPServer::getPlayerIDFromEndpoint(const std::map<PlayerID, PlayerDefinition>& connectedPlayers, PlayerID GetPlayerIDFromEndpoint(const std::map<PlayerID, PlayerDefinition>& connectedPlayers,
boost::asio::ip::address address, unsigned short port) boost::asio::ip::address address, unsigned short port)
{ {
for (auto& kv : connectedPlayers) { for (auto& kv : connectedPlayers) {
@@ -44,6 +32,24 @@ PlayerID TCPServer::getPlayerIDFromEndpoint(const std::map<PlayerID, PlayerDefin
return -1; return -1;
} }
void TCPServer::handle_accept(boost::shared_ptr<tcp::socket> socket,
int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers,
const boost::system::error_code& error)
{
if (!error && GetPlayerIDFromEndpoint(connectedPlayers, socket->remote_endpoint().address(),
socket->remote_endpoint().port()) == -1) {
// Add tcp socket to connections
boost::asio::ip::tcp::no_delay option(true);
socket->set_option(option);
PlayerDefinition pd;
pd.StopTime = std::clock();
pd.TCPSocket = socket;
pd.TCPAddress = socket.get()->remote_endpoint().address();
pd.TCPPort = socket.get()->remote_endpoint().port();
connectedPlayers[nextPlayerID++] = pd;
}
}
void TCPServer::Send(Packet & packet, PlayerDefinition & playerDefinition) void TCPServer::Send(Packet & packet, PlayerDefinition & playerDefinition)
{ {
packet.UpdateSize(); packet.UpdateSize();
-1
View File
@@ -17,7 +17,6 @@ void CubeMapPass::LoadTextures(std::string input)
m_CubeMapTextures.push_back(img); m_CubeMapTextures.push_back(img);
} }
GenerateCubeMapTexture(); GenerateCubeMapTexture();
m_PreviusCubeMapTexture = input;
} }
} }
+3 -8
View File
@@ -6,11 +6,9 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
, PureSystem("CapturePoint") , PureSystem("CapturePoint")
{ {
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
if (!IsClient) { EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
}
} }
@@ -18,9 +16,6 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt //NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt) void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
{ {
if (IsClient) {
return;
}
if (m_WinnerWasFound) { if (m_WinnerWasFound) {
return; return;
} }
+6 -28
View File
@@ -4,7 +4,6 @@ PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
: System(params) : System(params)
{ {
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump);
} }
PlayerMovementSystem::~PlayerMovementSystem() PlayerMovementSystem::~PlayerMovementSystem()
@@ -37,6 +36,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (!player.Valid()) { if (!player.Valid()) {
continue; continue;
} }
// Aim pitch // Aim pitch
EntityWrapper cameraEntity = player.FirstChildByName("Camera"); EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) { if (cameraEntity.Valid()) {
@@ -122,14 +122,15 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (isOnGround) { if (isOnGround) {
controller->SetDoubleJumping(false); controller->SetDoubleJumping(false);
} else { } else {
// If IsServer and network is off this will not work
if (IsClient) { if (IsClient) {
//put a hexagon at the players feet //put a hexagon at the players feet
spawnHexagon(player); auto hexagonEffect = ResourceManager::Load<EntityFile>("Schema/Entities/DoubleJumpHexagon.xml");
EntityFileParser parser(hexagonEffect);
EntityID hexagonEffectID = parser.MergeEntities(m_World);
EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID);
hexagonEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
controller->SetDoubleJumping(true); controller->SetDoubleJumping(true);
// Publish event for client to listen to
Events::DoubleJump e; Events::DoubleJump e;
e.entityID = player.ID;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
} }
@@ -294,26 +295,3 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
} }
return true; return true;
} }
bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e)
{
// If entity does not exist, exit
if (!EntityWrapper(m_World, e.entityID).Valid()) {
return false;
}
// If entity IsLocalPlayer, exit
if (e.entityID == m_LocalPlayer.ID) {
return false;
}
spawnHexagon(EntityWrapper(m_World, e.entityID));
}
void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
{
//put a hexagon at the entitys... feet?
auto hexagonEffect = ResourceManager::Load<EntityFile>("Schema/Entities/DoubleJumpHexagon.xml");
EntityFileParser parser(hexagonEffect);
EntityID hexagonEffectID = parser.MergeEntities(m_World);
EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID);
hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"];
}
+1 -1
View File
@@ -36,7 +36,7 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
} }
// Find any SpawnPoints existing as children of spawner // Find any SpawnPoints existing as children of spawner
auto children = spawner.World->GetDirectChildren(spawner.ID); auto children = spawner.World->GetChildren(spawner.ID);
std::vector<EntityWrapper> spawnPoints; std::vector<EntityWrapper> spawnPoints;
for (auto kv = children.first; kv != children.second; ++kv) { for (auto kv = children.first; kv != children.second; ++kv) {
const EntityID& child = kv->second; const EntityID& child = kv->second;
@@ -5,7 +5,6 @@ AssaultWeaponBehaviour::AssaultWeaponBehaviour(SystemParams systemParams, IRende
{ {
m_FirstPersonModel = m_Player.FirstChildByName("Hands"); m_FirstPersonModel = m_Player.FirstChildByName("Hands");
m_ThirdPersonModel = m_Player.FirstChildByName("PlayerModel"); m_ThirdPersonModel = m_Player.FirstChildByName("PlayerModel");
EVENT_SUBSCRIBE_MEMBER(m_EAnimationComplete, &AssaultWeaponBehaviour::OnAnimationComplete);
} }
void AssaultWeaponBehaviour::Fire() void AssaultWeaponBehaviour::Fire()
@@ -36,7 +35,7 @@ void AssaultWeaponBehaviour::Reload()
return; return;
} }
// Don't reload if we're completly out of ammo // Don't reload if we're completely out of ammo
if (ammo == 0) { if (ammo == 0) {
playEmptySound(); playEmptySound();
m_TimeSinceLastFire = -0.0f; // HACK: To make empty sound play with interval m_TimeSinceLastFire = -0.0f; // HACK: To make empty sound play with interval
@@ -56,14 +55,14 @@ void AssaultWeaponBehaviour::Update(double dt)
{ {
if (m_Reloading) { if (m_Reloading) {
m_ReloadTimer -= dt; m_ReloadTimer -= dt;
// Re-enable glow on reload impersonator half-way through the animation // Re-enable glow on reload impostor half-way through the animation
if (IsClient) { if (IsClient) {
if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) { if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) {
if (m_FirstPersonReloadImpersonator.Valid()) { if (m_FirstPersonReloadImpostor.Valid()) {
m_FirstPersonReloadImpersonator["Model"]["GlowMap"] = true; m_FirstPersonReloadImpostor["Model"]["GlowMap"] = true;
} }
if (m_ThirdPersonReloadImpersonator.Valid()) { if (m_ThirdPersonReloadImpostor.Valid()) {
m_ThirdPersonReloadImpersonator["Model"]["GlowMap"] = true; m_ThirdPersonReloadImpostor["Model"]["GlowMap"] = true;
} }
} }
} }
@@ -96,21 +95,6 @@ void AssaultWeaponBehaviour::Update(double dt)
} }
} }
bool AssaultWeaponBehaviour::OnAnimationComplete(Events::AnimationComplete& e)
{
if (e.Entity != m_FirstPersonModel) {
return false;
}
//if (e.Name == "ShootRifle") {
// if (!m_Firing) {
// playIdleAnimation();
// }
//}
return true;
}
bool AssaultWeaponBehaviour::hasAmmo() bool AssaultWeaponBehaviour::hasAmmo()
{ {
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"]; ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
@@ -215,6 +199,12 @@ void AssaultWeaponBehaviour::playEmptySound()
void AssaultWeaponBehaviour::viewPunch() void AssaultWeaponBehaviour::viewPunch()
{ {
// Since we send absolute client orientations to server, running this server side would
// cause aim desync.
if (!IsClient) {
return;
}
EntityWrapper playerCamera = m_Player.FirstChildByName("Camera"); EntityWrapper playerCamera = m_Player.FirstChildByName("Camera");
if (!playerCamera.Valid()) { if (!playerCamera.Valid()) {
return; return;
@@ -323,8 +313,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel"); EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner"); EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner");
if (IsClient) { if (IsClient) {
m_FirstPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner); m_FirstPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpersonator["Model"]); firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpostor["Model"]);
} }
firstPersonWeaponModel["Model"]["Visible"] = false; firstPersonWeaponModel["Model"]["Visible"] = false;
} }
@@ -332,8 +322,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
EntityWrapper thirdPersonWeaponModel = m_Player.FirstChildByName("ThirdPersonWeaponModel"); EntityWrapper thirdPersonWeaponModel = m_Player.FirstChildByName("ThirdPersonWeaponModel");
EntityWrapper reloadSpawner = m_Player.FirstChildByName("ThirdPersonReloadSpawner"); EntityWrapper reloadSpawner = m_Player.FirstChildByName("ThirdPersonReloadSpawner");
if (IsClient) { if (IsClient) {
m_ThirdPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner); m_ThirdPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpersonator["Model"]); thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpostor["Model"]);
} }
thirdPersonWeaponModel["Model"]["Visible"] = false; thirdPersonWeaponModel["Model"]["Visible"] = false;
} }
@@ -371,7 +361,7 @@ bool AssaultWeaponBehaviour::shoot(double damage)
return false; return false;
} }
// Don't let us shoot ourselves in the foot // Don't let us shoot ourselves in the foot somehow
if (victim == LocalPlayer) { if (victim == LocalPlayer) {
return false; return false;
} }
@@ -0,0 +1,10 @@
#include "Systems/Weapon/DefenderWeaponBehaviour.h"
DefenderWeaponBehaviour::DefenderWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
: WeaponBehaviour(systemParams, renderer, collisionOctree, weaponEntity) { }
void DefenderWeaponBehaviour::Fire()
{
}
+50 -6
View File
@@ -13,7 +13,7 @@ WeaponSystem::WeaponSystem(SystemParams params, IRenderer* renderer, Octree<Enti
void WeaponSystem::Update(double dt) void WeaponSystem::Update(double dt)
{ {
// TODO: Clear inactive weapons
} }
void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt)
@@ -72,20 +72,64 @@ bool WeaponSystem::OnInputCommand(Events::InputCommand& e)
void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot) void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot)
{ {
std::vector<EntityWrapper> weaponAttachments = player.ChildrenWithComponent("WeaponAttachment");
// Find the weapon attachments matching the slot selected
EntityWrapper firstPersonAttachment;
EntityWrapper thirdPersonAttachment;
for (auto& attachment : weaponAttachments) {
ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"];
if ((ComponentInfo::EnumType)cWeaponAttachment["Slot"] == slot) {
ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"];
if (person == person.Enum("FirstPerson")) {
firstPersonAttachment = attachment;
} else if (person == person.Enum("ThirdPerson")) {
thirdPersonAttachment = attachment;
}
}
}
if (firstPersonAttachment.Valid() && thirdPersonAttachment.Valid()) {
LOG_WARNING("No weapon attachment found for slot %i of player #%i", slot, player.ID);
return;
}
// TODO: Delete old weapons
// Spawn the weapon(s)
EntityWrapper firstPersonWeapon;
EntityWrapper thirdPersonWeapon;
if (firstPersonAttachment.Valid()) {
firstPersonWeapon = SpawnerSystem::Spawn(firstPersonAttachment, firstPersonAttachment);
}
if (thirdPersonAttachment.Valid()) {
firstPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment);
}
// Create the correct behaviour
if (firstPersonWeapon.Valid()) {
if (firstPersonWeapon.HasComponent("AssaultWeapon") {
}
}
// Primary // Primary
if (slot == 1) { if (slot == 1) {
// TODO: if class... // TODO: if class...
if (m_ActiveWeapons.count(player) == 0) { nextBehaviour = std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player);
m_ActiveWeapons.insert(std::make_pair(player, std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player)));
} else {
//m_ActiveWeapons.erase(player);
}
} }
// Secondary // Secondary
if (slot == 2) { if (slot == 2) {
//m_ActiveWeapons[player] = std::make_shared<PistolWeaponBehaviour>(); //m_ActiveWeapons[player] = std::make_shared<PistolWeaponBehaviour>();
} }
if (nextBehaviour != nullptr) {
// TODO: Destroy previous behaviour and make new
if (m_ActiveWeapons.count(player) == 0) {
m_ActiveWeapons[player] = nextBehaviour;
}
}
} }
bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e) bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e)