Compare commits
494 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 73b8bff1f3 | |||
| 1deb506fb2 | |||
| 7ea26d10ee | |||
| 28e9ba1208 | |||
| f0c2fdead1 | |||
| e1ca104fc9 | |||
| 2cb4a307eb | |||
| 6507efc0db | |||
| 96a3e68bf4 | |||
| 2d438060dd | |||
| a339c61f5b | |||
| 8b81ba9019 | |||
| 9a668ed7d7 | |||
| 7624c6ee0a | |||
| 3ef15dcb81 | |||
| 5923d2d7a7 | |||
| 069583e09f | |||
| 44b4a597d4 | |||
| 618e96da90 | |||
| fb9914d08a | |||
| 0c0f2d7e50 | |||
| 26d6546d79 | |||
| 62c8196ad4 | |||
| 7af17049e9 | |||
| 76117cb3ce | |||
| e6b3bbeb54 | |||
| 01def459a1 | |||
| 3094dd301b | |||
| 76ab746a22 | |||
| e56f203f7c | |||
| 267c007291 | |||
| 8b66d29adc | |||
| 7d15313209 | |||
| a9a19193ad | |||
| 53c520123a | |||
| 92d5ec70ba | |||
| 233a1d0990 | |||
| 4ef76f6c45 | |||
| f8f4b4d939 | |||
| a5c086e389 | |||
| 91dbbb9c11 | |||
| 78835f95d8 | |||
| dc10661e6b | |||
| 8a66b1e5c8 | |||
| 3c8df35be9 | |||
| f761416e20 | |||
| 9161c11764 | |||
| cdbc348cfa | |||
| 95078b6a4b | |||
| 502a290d36 | |||
| 1217b25d02 | |||
| a2b938d8f6 | |||
| ab7fd89546 | |||
| 06d60f9884 | |||
| 629ebb871f | |||
| 6968e71e07 | |||
| 2fb3bb2a39 | |||
| 6540848392 | |||
| de9657700b | |||
| 4652cd7861 | |||
| 5a6374f013 | |||
| 03a35d0f5e | |||
| e4e9af5d9c | |||
| 96768e66de | |||
| ef66f3ebe5 | |||
| 799990f44d | |||
| 39369aa3e5 | |||
| 6eb0b83d6b | |||
| ab40fa715b | |||
| a38c18fd3a | |||
| 9747a201b7 | |||
| 6281e20000 | |||
| 1ae2f3f5f3 | |||
| f147929aa9 | |||
| aadfdfdd90 | |||
| 5a8261453e | |||
| bba002dea9 | |||
| 15195964da | |||
| a9762f44ca | |||
| 3d4427dd20 | |||
| b0a66f9e83 | |||
| 5c6a652316 | |||
| 7ba5e01560 | |||
| 6d68486c05 | |||
| c60e1ba7e4 | |||
| 63d205f56a | |||
| 36f6ade87a | |||
| 1961c16fe2 | |||
| d32a483bb4 | |||
| e23ea78aeb | |||
| 724d7b1586 | |||
| 8cda614de4 | |||
| 77eaa45702 | |||
| dfa224b4dd | |||
| 86df8f14f4 | |||
| eaea645068 | |||
| 21bf7f4df3 | |||
| e2b7e5400d | |||
| 4153a31e3a | |||
| 0908be1e02 | |||
| 2ed5fad699 | |||
| 70374fa10e | |||
| 658eace093 | |||
| 20468cba1b | |||
| c106768939 | |||
| c7dad79e72 | |||
| d37f8cc350 | |||
| 3c35c0a956 | |||
| d47a806c64 | |||
| 8e21c5a5e4 | |||
| df7ace6626 | |||
| bef79d116b | |||
| db5170c699 | |||
| bb76c9d248 | |||
| 7749fc5474 | |||
| 6dd7f1a657 | |||
| 144e548b7a | |||
| 9cbc6f7755 | |||
| d3a245606a | |||
| 14b0a64720 | |||
| 8647267cad | |||
| ecab5de056 | |||
| 38d8cdded2 | |||
| b320d8d1e4 | |||
| 22c391df54 | |||
| afddd276a4 | |||
| a48e1b567a | |||
| 62e22d3821 | |||
| 0805375483 | |||
| 0c60b637c3 | |||
| d411de894f | |||
| f56705d921 | |||
| 18450ff4f3 | |||
| 22b473a0b6 | |||
| f220d8088c | |||
| df2e4abb52 | |||
| 8867e7ac3c | |||
| f161fce719 | |||
| 0343683678 | |||
| 9e6c67596d | |||
| 89d0d5753f | |||
| 748a178801 | |||
| eac9a9daf6 | |||
| 059fe5c6c0 | |||
| fb465ede81 | |||
| f66fa7a183 | |||
| 508d8a6f00 | |||
| cd315bbaa0 | |||
| 8ce6308649 | |||
| f10958c268 | |||
| da1c7b3093 | |||
| ef87102d1f | |||
| 9a41bda4cf | |||
| fc18932068 | |||
| b874ea8641 | |||
| 2609a0253d | |||
| de309d3b9d | |||
| f7ef6707a7 | |||
| feeff5b164 | |||
| 7394436e7a | |||
| f41e0b29be | |||
| 607e83134d | |||
| 5af4f9d8e7 | |||
| af68236e71 | |||
| 6f9ce8a0c1 | |||
| 6465fe6ed6 | |||
| fa13c1d065 | |||
| e2831c5593 | |||
| 8d23c531af | |||
| 91b0ac5fbd | |||
| d77119bb2d | |||
| 27669b7383 | |||
| fc7d62a5ad | |||
| c42e1e0967 | |||
| fe9dbf0b0f | |||
| 4ffb03fdd5 | |||
| fe3e0bac5b | |||
| fa4f007604 | |||
| e5ff88d3c9 | |||
| 845a30ed0f | |||
| 34a71b0767 | |||
| 833006744a | |||
| b2d8cddfb7 | |||
| 6fab971734 | |||
| 2c18068059 | |||
| 09aec08d0e | |||
| ed9149fe63 | |||
| 4cf8c3d8d7 | |||
| 37414ce124 | |||
| adceccf402 | |||
| 4c1a284636 | |||
| 23dc8e07b2 | |||
| c7d31cac2d | |||
| a1e932d261 | |||
| 070f1bd394 | |||
| 993d804cef | |||
| 201480b17f | |||
| bac23f6e8c | |||
| 68f2d5327d | |||
| 2263fd2ad6 | |||
| 2f259c3773 | |||
| 8cc928b5f4 | |||
| 881ce7b02f | |||
| c130fdda5e | |||
| 97fcdb342d | |||
| 4c87ca10b9 | |||
| 22664848dc | |||
| d135ea2da6 | |||
| 949ee76f55 | |||
| 844825813b | |||
| 722b795d37 | |||
| cf2bf4e14d | |||
| 2ac584bafb | |||
| 6e5335a266 | |||
| fc5d054cb2 | |||
| 8c9f4bb84b | |||
| 73a4336206 | |||
| f2ab02d860 | |||
| bf376f54b6 | |||
| e15a7b9485 | |||
| a141da3d8c | |||
| ca907b912e | |||
| b2304a95f8 | |||
| 8c92b7ceb6 | |||
| 97499f1c28 | |||
| 64610e3c03 | |||
| 7f489b3569 | |||
| 5dd85d2748 | |||
| 261c2e021e | |||
| 581a7b470c | |||
| 178402e964 | |||
| c3ed429377 | |||
| c4d3c515e4 | |||
| 7cc58dc94c | |||
| 5e3af7ac5d | |||
| 3e7936ef00 | |||
| 46987beefb | |||
| 8845054965 | |||
| 7dfd68467e | |||
| 4fd0108443 | |||
| 56bc1fee3d | |||
| 52355a63e2 | |||
| 72db672dbf | |||
| 1c9a1a9904 | |||
| 950ecba1c0 | |||
| fdc8f753cb | |||
| e8aff02c4e | |||
| 0d665c10fe | |||
| 23bb1a6405 | |||
| b8222c7b2e | |||
| 43bbc063cf | |||
| f7303ad787 | |||
| 3e4b87da7c | |||
| ac9ce8ea83 | |||
| 99643fd748 | |||
| a6c30100af | |||
| 833015f45e | |||
| 657125b469 | |||
| 456cd35a12 | |||
| 8f28c760dd | |||
| b13362360a | |||
| 0af9edc6e5 | |||
| ec10ef3ffc | |||
| 4432891437 | |||
| b2a437731e | |||
| 42b49f9dba | |||
| 4b8f1d95a3 | |||
| 8f84a5ddd6 | |||
| a006db9e63 | |||
| 17da9a8036 | |||
| 6bc7131290 | |||
| 4214bf10a1 | |||
| 717af2c4a4 | |||
| 969e7cb0d5 | |||
| 47a365a8fc | |||
| 71c03326aa | |||
| ba69c79821 | |||
| 0a31fa3dfd | |||
| ca457d9c00 | |||
| a08e54a147 | |||
| 2c3122bbdb | |||
| 10846be820 | |||
| 9df7b32ca1 | |||
| 3d4a7de59d | |||
| 1cdcbf9b32 | |||
| 9e8d2b99df | |||
| ba4877c3f7 | |||
| af39b892cd | |||
| 1ed5107d9b | |||
| 2ce7179d19 | |||
| eb7b22c757 | |||
| b48d491ad7 | |||
| 7d732c75ca | |||
| 47f4711b85 | |||
| 78e318c032 | |||
| bb66f95d43 | |||
| cc422cf73a | |||
| 2e5ee633ce | |||
| 1e04244590 | |||
| f146971db0 | |||
| 60b2c9bc9b | |||
| d357e365cb | |||
| a8a3366e8a | |||
| 7de76376cf | |||
| 422bedb844 | |||
| 1da432ba23 | |||
| 787eecce26 | |||
| 215b1b1aa4 | |||
| f49cacf167 | |||
| a15e01596a | |||
| a5168bd1c2 | |||
| 784e1eb69b | |||
| b5e372896f | |||
| a54156fab3 | |||
| a20707739e | |||
| 4f7a17ff62 | |||
| 987dafb44a | |||
| 47053285c8 | |||
| bee0630a26 | |||
| 1dc3756533 | |||
| 196469299f | |||
| e1196204eb | |||
| b9ea314232 | |||
| 71533b52ae | |||
| 6442254575 | |||
| 9f8b0f7aa9 | |||
| 021c4e36d7 | |||
| 02253ea6e1 | |||
| 2417175914 | |||
| fb5164221f | |||
| 88c7c57671 | |||
| 5295133311 | |||
| baff8301b3 | |||
| 3e42c067ab | |||
| 3b42f5dbf4 | |||
| 40ae2b8cbb | |||
| f1c2413cf9 | |||
| 11af6a3078 | |||
| 0370775820 | |||
| a36ed76a4e | |||
| af30e51564 | |||
| e24a84c52d | |||
| 04f77da6f1 | |||
| 30f454e6a4 | |||
| 648d864d6e | |||
| e473194671 | |||
| b761439c84 | |||
| 44a73ef883 | |||
| c1860ae383 | |||
| c4c53944d9 | |||
| bdec4f9d16 | |||
| 7cae84d4ee | |||
| 4964e732ca | |||
| 1bb1a1445e | |||
| d1213f9f59 | |||
| dd131e7652 | |||
| 70f4002d70 | |||
| b66e3d3630 | |||
| 06f614b3bb | |||
| 4a17e3c8f3 | |||
| 22e35489d7 | |||
| 055f6517a1 | |||
| afd9e24df6 | |||
| 851418b1de | |||
| fee50ba3b6 | |||
| 5bcadd5b1a | |||
| 42d810b198 | |||
| 3a15550b57 | |||
| 8f500965d4 | |||
| bd385a0d59 | |||
| 5e05e51309 | |||
| fee1ed6d6d | |||
| f79649cf9a | |||
| 2096779eb6 | |||
| 99747c518e | |||
| f088aa1d85 | |||
| 0af337bf39 | |||
| 6caa7e94a4 | |||
| e2a8605101 | |||
| c8c4879554 | |||
| 14054ad898 | |||
| e47201ff61 | |||
| 1d14094e90 | |||
| 3301f66ad1 | |||
| 49d4a45ef8 | |||
| e0c3a32e66 | |||
| 97b915f130 | |||
| c9f815fd42 | |||
| 8eea0c8395 | |||
| 38a3e88999 | |||
| 4e23e7bf30 | |||
| 89cbc70177 | |||
| 51e0b852d2 | |||
| 7ccaf5b040 | |||
| 66e20c3fd9 | |||
| 6ba1e95da7 | |||
| a8ab49f202 | |||
| bef50ef96a | |||
| 9f657ada4e | |||
| f0ae365401 | |||
| 7d4a4ed7cf | |||
| bbbab7b287 | |||
| fa2e556ab2 | |||
| 97de31be65 | |||
| 95289f47d6 | |||
| ccf4cae74b | |||
| 2f640d224c | |||
| f11bd24d53 | |||
| 81943516a9 | |||
| e350074cb5 | |||
| 350effd8eb | |||
| 607150189c | |||
| ecc473d520 | |||
| 35e4935497 | |||
| 0394eacb6b | |||
| 73f59b89cc | |||
| 9d9c6bdf1e | |||
| 92e7d3ecf7 | |||
| 4b8f4981a3 | |||
| 447f41dbff | |||
| 9c08c351b8 | |||
| eb244f87c4 | |||
| dded296cde | |||
| c3cc5ae70b | |||
| 64a2354b24 | |||
| 675a80e905 | |||
| f05d0a1b0c | |||
| ec54b1298d | |||
| f5de267f25 | |||
| 36043010af | |||
| 6396925b68 | |||
| a53ab7f745 | |||
| 224e95f34a | |||
| 95fa1f4bbd | |||
| 2cae4e3fb2 | |||
| 0825b10c75 | |||
| ed06eacf6f | |||
| 3c3149b13e | |||
| 53265bbc90 | |||
| 7cbdc33f84 | |||
| 8520192805 | |||
| 1ba9d97ab7 | |||
| fa781d5c88 | |||
| 97780395cf | |||
| b0bdca5cdd | |||
| 9645169797 | |||
| 02cd822cf1 | |||
| 2c0f66d9c7 | |||
| f7756ff60f | |||
| 2d5f71e442 | |||
| 4f2ad3ad00 | |||
| cb77c1ff97 | |||
| 646806b50e | |||
| 69db32337d | |||
| 04c23be136 | |||
| d931660c56 | |||
| 2f53ed140f | |||
| b6b96c5f11 | |||
| 6af167675d | |||
| 2ec30fd2b2 | |||
| 5cea3bed3a | |||
| d83190290f | |||
| d5647ce89c | |||
| d2ed293183 | |||
| e9f5a3d263 | |||
| 8bdf87da12 | |||
| ecd823cb9f | |||
| e69864680d | |||
| c69a80f5ba | |||
| 971fee4a0c | |||
| 847c539373 | |||
| cb7f06573f | |||
| d3bc48f5f7 | |||
| fccd8c64e7 | |||
| 0e9fb16399 | |||
| db5301ff2c | |||
| ba9419b342 | |||
| 2b4e00e4b0 | |||
| 503613907e | |||
| 4bf91ba56a | |||
| 88d7b79cd3 | |||
| 6542d1b444 | |||
| 8034b42c87 | |||
| bbf6058c17 | |||
| 0e51ae7dc9 | |||
| c912cd7a42 | |||
| 7f1016476b | |||
| 047e71a4e1 | |||
| 9232b24a7b | |||
| 3a2b124cae | |||
| 02b69a86e7 | |||
| 774e17ffc9 | |||
| 7bf4f5c30e | |||
| e133791369 |
+1
-1
Submodule assets updated: 7531e441fe...72530423ad
+1
-1
Submodule deps updated: bf83f099ba...ed45883a44
@@ -20,6 +20,9 @@
|
||||
class World;
|
||||
struct ComponentWrapper;
|
||||
|
||||
template<typename T>
|
||||
class Octree;
|
||||
|
||||
namespace Collision
|
||||
{
|
||||
//Return true if the ray hits the box.
|
||||
@@ -44,21 +47,24 @@ bool RayVsTriangle(const Ray& ray,
|
||||
float& outVCoord,
|
||||
bool trueOnNegativeDistance = false);
|
||||
//Return true if the ray hits any of the triangles in the model. Stops checking when a hit is detected.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const std::vector<RawModel::Vertex>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices);
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix);
|
||||
//Return true if the ray hits any of the triangles in the model.
|
||||
//Also returns the position of the intersection point. Will loop through all the whole model indices.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const std::vector<RawModel::Vertex>& modelVertices,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& outHitPosition);
|
||||
//Return true if the ray hits any of the triangles in the model.
|
||||
//Also returns the distance from the ray origin to the closest
|
||||
//intersection point, and the barycentric u,v-coordinates. Will loop through all the whole model indices.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const std::vector<RawModel::Vertex>& modelVertices,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
float& outDistance,
|
||||
float& outUCoord,
|
||||
float& outVCoord);
|
||||
@@ -72,15 +78,30 @@ bool AABBvsTriangles(const AABB& box,
|
||||
bool& isOnGround,
|
||||
glm::vec3& outResolutionVector);
|
||||
|
||||
//Detects collision, but does not resolve.
|
||||
bool AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix);
|
||||
|
||||
//Return true if the boxes are intersecting.
|
||||
bool AABBVsAABB(const AABB& a, const AABB& b);
|
||||
//Return true if the boxes are intersecting.
|
||||
//Also outputs the minimum translation that box [a] would need in order to resolve collision.
|
||||
bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation);
|
||||
|
||||
// Calculates an absolute AABB from an entity AABB component
|
||||
// Calculates an absolute AABB from an entity AABB component or Model component.
|
||||
// if takeModelBox is true, the AABB component will be ignored and box is calculated from Model.
|
||||
// if takeModelBox is false, the AABB component will be prefered, if it exists.
|
||||
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox = false);
|
||||
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);
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,17 +13,18 @@
|
||||
class CollisionSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
CollisionSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree)
|
||||
: System(world, eventBroker)
|
||||
, PureSystem("Collidable")
|
||||
CollisionSystem(SystemParams params, Octree<EntityAABB>* octree)
|
||||
: System(params)
|
||||
, PureSystem("Physics")
|
||||
, m_Octree(octree)
|
||||
{ }
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override;
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPhysics, double dt) override;
|
||||
|
||||
private:
|
||||
Octree<EntityAABB>* m_Octree;
|
||||
std::vector<EntityAABB> m_OctreeResult;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> m_PrevPositions;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,8 @@
|
||||
class FillFrustumOctreeSystem : public ImpureSystem, public PureSystem
|
||||
{
|
||||
public:
|
||||
FillFrustumOctreeSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree)
|
||||
: System(world, eventBroker)
|
||||
FillFrustumOctreeSystem(SystemParams params, Octree<EntityAABB>* octree)
|
||||
: System(params)
|
||||
, PureSystem("Model")
|
||||
, m_Octree(octree)
|
||||
{ }
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
class FillOctreeSystem : public ImpureSystem, public PureSystem
|
||||
{
|
||||
public:
|
||||
FillOctreeSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree, const std::string& fillComponentType)
|
||||
: System(world, eventBroker)
|
||||
FillOctreeSystem(SystemParams params, Octree<EntityAABB>* octree, const std::string& fillComponentType)
|
||||
: System(params)
|
||||
, PureSystem(fillComponentType)
|
||||
, m_Octree(octree)
|
||||
{ }
|
||||
|
||||
@@ -15,8 +15,8 @@ class AABB;
|
||||
class TriggerSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
TriggerSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree)
|
||||
: System(world, eventBroker)
|
||||
TriggerSystem(SystemParams params, Octree<EntityAABB>* octree)
|
||||
: System(params)
|
||||
, PureSystem("Trigger")
|
||||
, m_Octree(octree)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define ComponentInfo_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
struct ComponentInfo
|
||||
{
|
||||
@@ -13,6 +14,7 @@ struct ComponentInfo
|
||||
unsigned int Allocation = 0;
|
||||
std::map<std::string, std::string> FieldAnnotations;
|
||||
std::map<std::string, std::map<std::string, EnumType>> FieldEnumDefinitions;
|
||||
bool NetworkReplicated = true;
|
||||
};
|
||||
|
||||
struct Field_t
|
||||
@@ -26,8 +28,9 @@ struct ComponentInfo
|
||||
std::string Name;
|
||||
std::unordered_map<std::string, Field_t> Fields;
|
||||
std::vector<std::string> FieldsInOrder;
|
||||
std::vector<std::string> StringFields;
|
||||
unsigned int Stride = 0;
|
||||
std::shared_ptr<char> Defaults = nullptr;
|
||||
boost::shared_array<char> Defaults = nullptr;
|
||||
std::shared_ptr<Meta_t> Meta = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef ComponentPool_h__
|
||||
#define ComponentPool_h__
|
||||
|
||||
#include <set>
|
||||
#include "MemoryPool.h"
|
||||
#include "ComponentInfo.h"
|
||||
#include "ComponentWrapper.h"
|
||||
@@ -45,7 +46,8 @@ public:
|
||||
: m_ComponentInfo(ci)
|
||||
, m_Pool(ci.Meta->Allocation, sizeof(EntityID) + ci.Stride)
|
||||
{ }
|
||||
ComponentPool(const ComponentPool& other) = delete;
|
||||
~ComponentPool();
|
||||
ComponentPool(const ComponentPool& other);
|
||||
ComponentPool(const ComponentPool&& other) = delete;
|
||||
|
||||
const ::ComponentInfo& ComponentInfo() const { return m_ComponentInfo; }
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
#ifndef ComponentWrapper_h__
|
||||
#define ComponentWrapper_h__
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include "../Common.h"
|
||||
#include "Entity.h"
|
||||
#include "ComponentInfo.h"
|
||||
#include "Util/Any.h"
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct ComponentField { };
|
||||
|
||||
template <typename T>
|
||||
struct ComponentField<T, typename std::enable_if<std::is_trivially_copyable<T>::value>::type>
|
||||
{
|
||||
static T& Get(const ComponentInfo::Field_t& info, char* data) { return *reinterpret_cast<T*>(data); }
|
||||
static void Set(const ComponentInfo::Field_t& info, char* data, const T& value) { Get(data) = value; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ComponentField<std::string, void>
|
||||
{
|
||||
static std::string& Get(const ComponentInfo::Field_t& info, char* data) { return **reinterpret_cast<std::string**>(data); }
|
||||
static void Set(const ComponentInfo::Field_t& info, char* data, const std::string& value) { Get(info, data) = value; }
|
||||
};
|
||||
|
||||
struct ComponentWrapper
|
||||
{
|
||||
ComponentWrapper(const ComponentInfo& componentInfo, char* data)
|
||||
@@ -46,7 +65,31 @@ struct ComponentWrapper
|
||||
|
||||
void Copy(ComponentWrapper& destination)
|
||||
{
|
||||
memcpy(destination.Data, this->Data, Info.Stride);
|
||||
// Copy trivial data
|
||||
memcpy(destination.Data, Data, Info.Stride);
|
||||
// Duplicate strings
|
||||
SolidifyStrings(destination);
|
||||
}
|
||||
|
||||
// When component data has been copied, strings need to be reconstructed or they'll refer to the same data!
|
||||
static void SolidifyStrings(ComponentWrapper& component)
|
||||
{
|
||||
for (auto& name : component.Info.StringFields) {
|
||||
std::size_t offset = component.Info.Fields.at(name).Offset;
|
||||
std::string value = *reinterpret_cast<const std::string*>(component.Data + offset);
|
||||
new (component.Data + offset) std::string(value);
|
||||
}
|
||||
}
|
||||
|
||||
// This needs to be called to properly free component data, because strings.
|
||||
static void Destroy(ComponentInfo info, char* data)
|
||||
{
|
||||
// Call std::string destructors
|
||||
for (auto& name : info.StringFields) {
|
||||
std::size_t offset = info.Fields.at(name).Offset;
|
||||
auto field = reinterpret_cast<std::string*>(data + offset);
|
||||
field->~basic_string();
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptProxy
|
||||
@@ -81,6 +124,18 @@ struct ComponentWrapper
|
||||
SubscriptProxy operator[](std::string propertyName) { return SubscriptProxy(this, propertyName); }
|
||||
};
|
||||
|
||||
// A component wrapper that "owns" its data through a shared pointer
|
||||
struct SharedComponentWrapper : ComponentWrapper
|
||||
{
|
||||
SharedComponentWrapper(const ComponentInfo& componentInfo, boost::shared_array<char> data)
|
||||
: ComponentWrapper(componentInfo, data.get())
|
||||
, m_DataReference(data)
|
||||
{ }
|
||||
|
||||
private:
|
||||
boost::shared_array<char> m_DataReference;
|
||||
};
|
||||
|
||||
// TODO: Move this to Tests once entity importing is finished
|
||||
class ComponentWrapperFactory
|
||||
{
|
||||
@@ -89,26 +144,38 @@ public:
|
||||
ComponentWrapperFactory(std::string componentTypeName, unsigned int allocation = 0)
|
||||
{
|
||||
m_ComponentInfo.Name = componentTypeName;
|
||||
m_ComponentInfo.Meta = std::make_shared<ComponentInfo::Meta_t>();
|
||||
m_ComponentInfo.Meta->Allocation = allocation;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AddProperty(std::string fieldName, T defaultValue)
|
||||
{
|
||||
m_DefaultValues.push_back(defaultValue);
|
||||
m_ComponentInfo.Fields[fieldName].Type = typeid(T).name();
|
||||
m_ComponentInfo.Fields[fieldName].Offset = m_ComponentInfo.Stride;
|
||||
m_ComponentInfo.Fields[fieldName].Stride = sizeof(T);
|
||||
auto& field = m_ComponentInfo.Fields[fieldName];
|
||||
field.Name = fieldName;
|
||||
field.Type = typeid(T).name();
|
||||
field.Offset = m_ComponentInfo.Stride;
|
||||
field.Stride = sizeof(T);
|
||||
m_ComponentInfo.FieldsInOrder.push_back(field.Name);
|
||||
if (field.Type == typeid(std::string).name()) {
|
||||
field.Type = "string";
|
||||
m_ComponentInfo.StringFields.push_back(field.Name);
|
||||
}
|
||||
m_ComponentInfo.Stride += sizeof(T);
|
||||
m_DefaultValues.push_back(std::make_pair(field, defaultValue));
|
||||
}
|
||||
|
||||
|
||||
ComponentInfo& Finalize()
|
||||
{
|
||||
m_ComponentInfo.Defaults = std::shared_ptr<char>(new char[m_ComponentInfo.Stride]);
|
||||
m_ComponentInfo.Defaults = boost::shared_array<char>(new char[m_ComponentInfo.Stride]);
|
||||
std::size_t offset = 0;
|
||||
for (auto& val : m_DefaultValues) {
|
||||
memcpy(m_ComponentInfo.Defaults.get() + offset, val.Data.get(), val.Size);
|
||||
offset += val.Size;
|
||||
for (auto& pair : m_DefaultValues) {
|
||||
if (pair.first.Type == "string") {
|
||||
new (m_ComponentInfo.Defaults.get() + offset) std::string(*reinterpret_cast<std::string*>(pair.second.Data.get()));
|
||||
} else {
|
||||
memcpy(m_ComponentInfo.Defaults.get() + offset, pair.second.Data.get(), pair.second.Size);
|
||||
}
|
||||
offset += pair.second.Size;
|
||||
}
|
||||
|
||||
return m_ComponentInfo;
|
||||
@@ -118,7 +185,7 @@ public:
|
||||
|
||||
private:
|
||||
ComponentInfo m_ComponentInfo;
|
||||
std::vector<Any> m_DefaultValues;
|
||||
std::vector<std::pair<ComponentInfo::Field_t, Any>> m_DefaultValues;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef EAmmoPickup_h__
|
||||
#define EAmmoPickup_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
#include "../Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct AmmoPickup : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
int AmmoGain;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,9 @@ namespace Events
|
||||
struct Captured : Event
|
||||
{
|
||||
int TeamNumberThatCapturedCapturePoint;
|
||||
EntityID CapturePointID;
|
||||
EntityID CapturePointTakenID;
|
||||
EntityWrapper BlueTeamNextCapturePoint;
|
||||
EntityWrapper RedTeamNextCapturePoint;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Events
|
||||
|
||||
struct PlayerDamage : Event
|
||||
{
|
||||
//NOTE: this struct is missing information on what the damageSource is
|
||||
EntityWrapper Player;
|
||||
EntityWrapper Inflictor;
|
||||
EntityWrapper Victim;
|
||||
double Damage;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Events
|
||||
|
||||
struct Shoot : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
EntityWrapper Inflictor;
|
||||
double Damage;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,164 +1,21 @@
|
||||
#ifndef EntityFile_h__
|
||||
#define EntityFile_h__
|
||||
|
||||
#include <stack>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/XMLChar.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/framework/XMLDocumentHandler.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/framework/psvi/XSValue.hpp>
|
||||
#include <xercesc/framework/XMLGrammarPoolImpl.hpp>
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
#include <xercesc/dom/DOMLSInput.hpp>
|
||||
#include <xercesc/dom/DOMElement.hpp>
|
||||
#include "World.h"
|
||||
#include "EntityXMLFile.h"
|
||||
#include "EntityXMLFilePreprocessor.h"
|
||||
#include "EntityXMLFileParser.h"
|
||||
#include "EntityWrapper.h"
|
||||
|
||||
#include "../GLM.h"
|
||||
#include "Util/XercesString.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "Entity.h"
|
||||
#include "ComponentInfo.h"
|
||||
|
||||
class EntityFileHandler
|
||||
{
|
||||
friend class EntityFileSAXHandler;
|
||||
public:
|
||||
// @param EntityID The entity found
|
||||
// @param EntityID The parent of the entity
|
||||
typedef std::function<void(EntityID, EntityID, const std::string&)> OnStartEntityCallback;
|
||||
void SetStartEntityCallback(OnStartEntityCallback c) { m_OnStartEntityCallback = c; }
|
||||
// @param EntityID The entity the component corresponds to
|
||||
// @param std::string Type name of the component
|
||||
typedef std::function<void(EntityID, const std::string&)> OnStartComponentCallback;
|
||||
void SetStartComponentCallback(OnStartComponentCallback c) { m_OnStartComponentCallback = c; }
|
||||
// @param EntityID Entity
|
||||
// @param std::string Component name
|
||||
// @param std::string Field name
|
||||
// @param std::map<std::string, std::string> Field attribute names and values
|
||||
typedef std::function<void(EntityID, const std::string&, const std::string&, const std::map<std::string, std::string>&)> OnStartFieldCallback;
|
||||
void SetStartFieldCallback(OnStartFieldCallback c) { m_OnStartFieldCallback = c; }
|
||||
// @param EntityID Entity
|
||||
// @param std::string Component name
|
||||
// @param std::string Field name
|
||||
// @param char* Field data
|
||||
typedef std::function<void(EntityID, const std::string&, const std::string&, const char*)> OnStartFieldDataCallback;
|
||||
void SetStartFieldDataCallback(OnStartFieldDataCallback c) { m_OnStartFieldDataCallback = c; }
|
||||
|
||||
private:
|
||||
OnStartEntityCallback m_OnStartEntityCallback = nullptr;
|
||||
OnStartComponentCallback m_OnStartComponentCallback = nullptr;
|
||||
OnStartFieldCallback m_OnStartFieldCallback = nullptr;
|
||||
OnStartFieldDataCallback m_OnStartFieldDataCallback = nullptr;
|
||||
};
|
||||
|
||||
class EntityFileSAXHandler : public xercesc::DefaultHandler
|
||||
class EntityFile : private World, public Resource
|
||||
{
|
||||
public:
|
||||
enum class State
|
||||
{
|
||||
Unknown,
|
||||
Entity,
|
||||
Component,
|
||||
ComponentField
|
||||
};
|
||||
EntityFile(std::string path);
|
||||
|
||||
EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader);
|
||||
|
||||
void startElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname, const xercesc::Attributes& attrs) override;
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length) override;
|
||||
void endElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname) override;
|
||||
|
||||
void warning(const xercesc::SAXParseException& e);
|
||||
void error(const xercesc::SAXParseException& e);
|
||||
void fatalError(const xercesc::SAXParseException& e);
|
||||
EntityWrapper MergeInto(World* other);
|
||||
|
||||
private:
|
||||
const EntityFileHandler* m_Handler;
|
||||
xercesc::XMLGrammarPool* m_GrammarPool;
|
||||
xercesc::SAX2XMLReader* m_Reader;
|
||||
//State m_CurrentScope = State::Unknown;
|
||||
std::stack<State> m_StateStack;
|
||||
unsigned int m_NextEntityID = 0;
|
||||
std::stack<EntityID> m_EntityStack;
|
||||
std::string m_CurrentComponent;
|
||||
std::string m_CurrentField;
|
||||
std::map<std::string, std::string> m_CurrentAttributes;
|
||||
|
||||
void onStartEntity(const xercesc::Attributes& attrs);
|
||||
void onEndEntity();
|
||||
void onStartEntityRef(const xercesc::Attributes& attrs);
|
||||
void onStartComponent(const std::string& name);
|
||||
void onEndComponent(const std::string& name);
|
||||
void onStartComponentField(const std::string& field, const xercesc::Attributes& attrs);
|
||||
void onEndComponentField(const std::string& field);
|
||||
void onFieldData(char* data);
|
||||
};
|
||||
|
||||
class EntityFileXMLErrorHandler : public xercesc::ErrorHandler
|
||||
{
|
||||
public:
|
||||
void warning(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("Warning", e);
|
||||
}
|
||||
void error(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("Error", e);
|
||||
}
|
||||
void fatalError(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("FATAL ERROR", e);
|
||||
}
|
||||
void resetErrors() override { }
|
||||
|
||||
private:
|
||||
void reportParseException(std::string type, const xercesc::SAXParseException& e)
|
||||
{
|
||||
char* message = xercesc::XMLString::transcode(e.getMessage());
|
||||
char* systemID = xercesc::XMLString::transcode(e.getSystemId());
|
||||
std::cerr << systemID << ":" << e.getLineNumber() << ":" << e.getColumnNumber() << std::endl;
|
||||
std::cerr << type << ": " << message << std::endl;
|
||||
xercesc::XMLString::release(&systemID);
|
||||
xercesc::XMLString::release(&message);
|
||||
}
|
||||
};
|
||||
|
||||
class EntityFile : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
friend class EntityFileSAXHandler;
|
||||
private:
|
||||
EntityFile(boost::filesystem::path path);
|
||||
~EntityFile();
|
||||
|
||||
public:
|
||||
static unsigned int GetTypeStride(std::string typeName);
|
||||
static void WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map<std::string, std::string>& attributes);
|
||||
static void WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData);
|
||||
|
||||
xercesc::XMLGrammarPool* GrammarPool() const { return m_GrammarPool; }
|
||||
|
||||
void Parse(const EntityFileHandler* handler) const;
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_FilePath;
|
||||
xercesc::XMLGrammarPool* m_GrammarPool;
|
||||
xercesc::SAX2XMLReader* m_SAX2XMLReader;
|
||||
//std::map<std::string, ::ComponentInfo> m_ComponentInfo;
|
||||
//std::vector<std::string> m_EntityReferences;
|
||||
|
||||
static void setReaderFeatures(xercesc::SAX2XMLReader* reader);
|
||||
EntityID m_RootEntity = EntityID_Invalid;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -29,16 +29,22 @@ struct EntityWrapper
|
||||
EntityWrapper Parent();
|
||||
EntityWrapper FirstChildByName(const std::string& name);
|
||||
EntityWrapper FirstParentWithComponent(const std::string& componentType);
|
||||
EntityWrapper Clone(EntityWrapper parent = EntityWrapper::Invalid);
|
||||
std::vector<EntityWrapper> ChildrenWithComponent(const std::string& componentType);
|
||||
void DeleteChildren();
|
||||
bool IsChildOf(EntityWrapper potentialParent);
|
||||
bool Valid();
|
||||
bool Valid() const;
|
||||
|
||||
ComponentWrapper operator[](const char* componentName);
|
||||
ComponentWrapper operator[](const std::string& componentName);
|
||||
bool operator==(const EntityWrapper& e) const;
|
||||
bool operator!=(const EntityWrapper& e) const;
|
||||
explicit operator EntityID() const;
|
||||
|
||||
private:
|
||||
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
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
#ifndef EntityXMLFile_h__
|
||||
#define EntityXMLFile_h__
|
||||
|
||||
#include <stack>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/XMLChar.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/framework/XMLDocumentHandler.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/framework/psvi/XSValue.hpp>
|
||||
#include <xercesc/framework/XMLGrammarPoolImpl.hpp>
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
#include <xercesc/dom/DOMLSInput.hpp>
|
||||
#include <xercesc/dom/DOMElement.hpp>
|
||||
|
||||
#include "../GLM.h"
|
||||
#include "Util/XercesString.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "Entity.h"
|
||||
#include "ComponentInfo.h"
|
||||
|
||||
class EntityFileHandler
|
||||
{
|
||||
friend class EntityFileSAXHandler;
|
||||
public:
|
||||
// @param EntityID The entity found
|
||||
// @param EntityID The parent of the entity
|
||||
typedef std::function<void(EntityID, EntityID, const std::string&)> OnStartEntityCallback;
|
||||
void SetStartEntityCallback(OnStartEntityCallback c) { m_OnStartEntityCallback = c; }
|
||||
// @param EntityID The entity the component corresponds to
|
||||
// @param std::string Type name of the component
|
||||
typedef std::function<void(EntityID, const std::string&)> OnStartComponentCallback;
|
||||
void SetStartComponentCallback(OnStartComponentCallback c) { m_OnStartComponentCallback = c; }
|
||||
// @param EntityID Entity
|
||||
// @param std::string Component name
|
||||
// @param std::string Field name
|
||||
// @param std::map<std::string, std::string> Field attribute names and values
|
||||
typedef std::function<void(EntityID, const std::string&, const std::string&, const std::map<std::string, std::string>&)> OnStartFieldCallback;
|
||||
void SetStartFieldCallback(OnStartFieldCallback c) { m_OnStartFieldCallback = c; }
|
||||
// @param EntityID Entity
|
||||
// @param std::string Component name
|
||||
// @param std::string Field name
|
||||
// @param char* Field data
|
||||
typedef std::function<void(EntityID, const std::string&, const std::string&, const char*)> OnStartFieldDataCallback;
|
||||
void SetStartFieldDataCallback(OnStartFieldDataCallback c) { m_OnStartFieldDataCallback = c; }
|
||||
|
||||
private:
|
||||
OnStartEntityCallback m_OnStartEntityCallback = nullptr;
|
||||
OnStartComponentCallback m_OnStartComponentCallback = nullptr;
|
||||
OnStartFieldCallback m_OnStartFieldCallback = nullptr;
|
||||
OnStartFieldDataCallback m_OnStartFieldDataCallback = nullptr;
|
||||
};
|
||||
|
||||
class EntityFileSAXHandler : public xercesc::DefaultHandler
|
||||
{
|
||||
public:
|
||||
enum class State
|
||||
{
|
||||
Unknown,
|
||||
Entity,
|
||||
Component,
|
||||
ComponentField
|
||||
};
|
||||
|
||||
EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader);
|
||||
|
||||
void startElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname, const xercesc::Attributes& attrs) override;
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length) override;
|
||||
void endElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname) override;
|
||||
|
||||
void warning(const xercesc::SAXParseException& e);
|
||||
void error(const xercesc::SAXParseException& e);
|
||||
void fatalError(const xercesc::SAXParseException& e);
|
||||
|
||||
private:
|
||||
const EntityFileHandler* m_Handler;
|
||||
xercesc::XMLGrammarPool* m_GrammarPool;
|
||||
xercesc::SAX2XMLReader* m_Reader;
|
||||
//State m_CurrentScope = State::Unknown;
|
||||
std::stack<State> m_StateStack;
|
||||
unsigned int m_NextEntityID = 0;
|
||||
std::stack<EntityID> m_EntityStack;
|
||||
std::string m_CurrentComponent;
|
||||
std::string m_CurrentField;
|
||||
std::map<std::string, std::string> m_CurrentAttributes;
|
||||
|
||||
void onStartEntity(const xercesc::Attributes& attrs);
|
||||
void onEndEntity();
|
||||
void onStartEntityRef(const xercesc::Attributes& attrs);
|
||||
void onStartComponent(const std::string& name);
|
||||
void onEndComponent(const std::string& name);
|
||||
void onStartComponentField(const std::string& field, const xercesc::Attributes& attrs);
|
||||
void onEndComponentField(const std::string& field);
|
||||
void onFieldData(char* data);
|
||||
};
|
||||
|
||||
class EntityFileXMLErrorHandler : public xercesc::ErrorHandler
|
||||
{
|
||||
public:
|
||||
void warning(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("Warning", e);
|
||||
}
|
||||
void error(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("Error", e);
|
||||
}
|
||||
void fatalError(const xercesc::SAXParseException& e) override
|
||||
{
|
||||
reportParseException("FATAL ERROR", e);
|
||||
}
|
||||
void resetErrors() override { }
|
||||
|
||||
private:
|
||||
void reportParseException(std::string type, const xercesc::SAXParseException& e)
|
||||
{
|
||||
char* message = xercesc::XMLString::transcode(e.getMessage());
|
||||
char* systemID = xercesc::XMLString::transcode(e.getSystemId());
|
||||
std::cerr << systemID << ":" << e.getLineNumber() << ":" << e.getColumnNumber() << std::endl;
|
||||
std::cerr << type << ": " << message << std::endl;
|
||||
xercesc::XMLString::release(&systemID);
|
||||
xercesc::XMLString::release(&message);
|
||||
}
|
||||
};
|
||||
|
||||
class EntityXMLFile : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
friend class EntityFileSAXHandler;
|
||||
private:
|
||||
EntityXMLFile(boost::filesystem::path path);
|
||||
~EntityXMLFile();
|
||||
|
||||
public:
|
||||
static unsigned int GetTypeStride(std::string typeName);
|
||||
static void WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map<std::string, std::string>& attributes);
|
||||
static void WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData);
|
||||
|
||||
xercesc::XMLGrammarPool* GrammarPool() const { return m_GrammarPool; }
|
||||
|
||||
void Parse(const EntityFileHandler* handler) const;
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_FilePath;
|
||||
xercesc::XMLGrammarPool* m_GrammarPool;
|
||||
xercesc::SAX2XMLReader* m_SAX2XMLReader;
|
||||
//std::map<std::string, ::ComponentInfo> m_ComponentInfo;
|
||||
//std::vector<std::string> m_EntityReferences;
|
||||
|
||||
static void setReaderFeatures(xercesc::SAX2XMLReader* reader);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,18 +1,19 @@
|
||||
#ifndef EntityFileParser_h__
|
||||
#define EntityFileParser_h__
|
||||
#ifndef EntityXMLFileParser_h__
|
||||
#define EntityXMLFileParser_h__
|
||||
|
||||
#include "EntityFile.h"
|
||||
#include "EntityXMLFile.h"
|
||||
#include "World.h"
|
||||
|
||||
class EntityFileParser
|
||||
class EntityXMLFileParser
|
||||
{
|
||||
friend class EntityFile;
|
||||
public:
|
||||
EntityFileParser(const EntityFile* entityFile);
|
||||
|
||||
EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid);
|
||||
EntityXMLFileParser(const EntityXMLFile* entityFile);
|
||||
|
||||
private:
|
||||
const EntityFile* m_EntityFile;
|
||||
EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid);
|
||||
|
||||
const EntityXMLFile* m_EntityFile;
|
||||
EntityFileHandler m_Handler;
|
||||
World* m_World = nullptr;
|
||||
EntityID m_FirstEntity = EntityID_Invalid;
|
||||
+11
-8
@@ -1,8 +1,10 @@
|
||||
#ifndef EntityFilePreprocessor_h__
|
||||
#define EntityFilePreprocessor_h__
|
||||
#ifndef EntityXMLFilePreprocessor_h__
|
||||
#define EntityXMLFilePreprocessor_h__
|
||||
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeUse.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
|
||||
@@ -15,17 +17,18 @@
|
||||
#include "Util/XercesString.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "World.h"
|
||||
#include "EntityFile.h"
|
||||
#include "EntityXMLFile.h"
|
||||
|
||||
class EntityFilePreprocessor
|
||||
class EntityXMLFilePreprocessor
|
||||
{
|
||||
friend class EntityFile;
|
||||
public:
|
||||
EntityFilePreprocessor(const EntityFile* entityFile);
|
||||
|
||||
void RegisterComponents(World* world);
|
||||
EntityXMLFilePreprocessor(const EntityXMLFile* entityFile);
|
||||
|
||||
private:
|
||||
const EntityFile* m_EntityFile;
|
||||
void RegisterComponents(World* world);
|
||||
|
||||
const EntityXMLFile* m_EntityFile;
|
||||
std::map<std::string, unsigned int> m_ComponentCounts;
|
||||
std::map<std::string, ComponentInfo> m_ComponentInfo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef EntityFileWriter_h__
|
||||
#define EntityFileWriter_h__
|
||||
#ifndef EntityXMLFileWriter_h__
|
||||
#define EntityXMLFileWriter_h__
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
@@ -8,13 +8,13 @@
|
||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||
|
||||
#include "Util/XercesString.h"
|
||||
#include "EntityFile.h"
|
||||
#include "EntityXMLFile.h"
|
||||
#include "World.h"
|
||||
|
||||
class EntityFileWriter
|
||||
class EntityXMLFileWriter
|
||||
{
|
||||
public:
|
||||
EntityFileWriter(boost::filesystem::path file)
|
||||
EntityXMLFileWriter(boost::filesystem::path file)
|
||||
: m_FilePath(file)
|
||||
{
|
||||
using namespace xercesc;
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <set>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "Event.h"
|
||||
@@ -107,7 +108,7 @@ private:
|
||||
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
||||
ContextRelays_t m_ContextRelays;
|
||||
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
||||
std::vector<std::tuple<EventID, ContextTypeName_t, EventTypeName_t>> m_RelaysToUnsubscribe;
|
||||
std::unordered_map<BaseEventRelay*, std::tuple<EventID, ContextTypeName_t, EventTypeName_t>> m_RelaysToUnsubscribe;
|
||||
|
||||
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueRead;
|
||||
|
||||
@@ -66,9 +66,25 @@ public:
|
||||
, m_LowestAllocatedSlot(m_NumSlots)
|
||||
{ }
|
||||
|
||||
//We may get problems with memory being released
|
||||
//prematurely, etc. if we allow copies.
|
||||
MemoryPool(const MemoryPool<T>& other) = delete;
|
||||
MemoryPool(const MemoryPool<T>& other)
|
||||
: m_StartAddress(new char[other.m_NumSlots*other.m_Stride])
|
||||
, m_SlotIsAllocated(other.m_SlotIsAllocated)
|
||||
, m_ExtraMemory()
|
||||
, m_NumSlots(other.m_NumSlots)
|
||||
, m_LowestAllocatedSlot(other.m_LowestAllocatedSlot)
|
||||
, m_NumAllocatedSlots(other.m_NumAllocatedSlots)
|
||||
, m_Stride(other.m_Stride)
|
||||
, m_CurrentAllocSlot(other.m_CurrentAllocSlot)
|
||||
{
|
||||
// Copy statically allocated pool
|
||||
memcpy(m_StartAddress, other.m_StartAddress, m_NumSlots*m_Stride);
|
||||
// Copy dynamically allocated memory
|
||||
for (char* otherAddr : other.m_ExtraMemory) {
|
||||
char* addr = (char*)malloc(m_Stride);
|
||||
memcpy(addr, otherAddr, m_Stride);
|
||||
m_ExtraMemory.push_back(addr);
|
||||
}
|
||||
}
|
||||
MemoryPool(const MemoryPool<T>&& other) = delete;
|
||||
|
||||
//Free all memory that has been allocated.
|
||||
@@ -78,8 +94,9 @@ public:
|
||||
delete[] m_StartAddress;
|
||||
m_StartAddress = nullptr;
|
||||
}
|
||||
for (char* addr : m_ExtraMemory)
|
||||
free(addr);
|
||||
for (char* addr : m_ExtraMemory) {
|
||||
free(addr);
|
||||
}
|
||||
m_ExtraMemory.clear();
|
||||
}
|
||||
|
||||
@@ -101,9 +118,6 @@ public:
|
||||
else {
|
||||
m_ExtraMemory.push_back((char*)malloc(m_Stride));
|
||||
//We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead.
|
||||
if (!DisableMemoryPool::Value) {
|
||||
LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size());
|
||||
}
|
||||
return m_ExtraMemory.back();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
#include "../Common.h"
|
||||
#include "AABB.h"
|
||||
#include "Frustum.h"
|
||||
|
||||
//Fwd declarations.
|
||||
class Ray;
|
||||
#include "Ray.h"
|
||||
|
||||
namespace OctSpace
|
||||
{
|
||||
@@ -43,6 +41,8 @@ public:
|
||||
void ObjectsInSameRegion(const Box& box, std::vector<T>& outObjects);
|
||||
//Get the objects that are inside the frustum, the objects are put in outObjects.
|
||||
void ObjectsInFrustum(const Frustum& frustum, std::vector<T>& outObjects);
|
||||
//Get objects, which AABB the input ray intersects, the objects are put in outObjects.
|
||||
void ObjectsPossiblyHitByRay(const Ray& ray, std::vector<T>& outObjects);
|
||||
//Empty the tree of all objects, static and dynamic.
|
||||
void ClearObjects();
|
||||
//Empty the tree of all dynamic objects. Static objects remain in the tree.
|
||||
@@ -102,6 +102,8 @@ struct Child
|
||||
void ObjectsInSameRegion(const Box& box, std::vector<T>& outObjects) const;
|
||||
template<typename T>
|
||||
void ObjectsInFrustum(const Frustum& frustum, std::vector<T>& outObjects, bool takeAllDontTest) const;
|
||||
template<typename T>
|
||||
void ObjectsPossiblyHitByRay(const Ray& ray, std::vector<T>& outObjects) const;
|
||||
void ClearObjects();
|
||||
void ClearDynamicObjects();
|
||||
bool RayCollides(const Ray& ray, Output& data) const;
|
||||
@@ -121,6 +123,15 @@ struct Child
|
||||
std::vector<int> childIndicesContainingBox(const AABB& box) const;
|
||||
};
|
||||
|
||||
//To be able to sort child nodes and contained objects based on distance to ray origin.
|
||||
struct RaySorterInfo
|
||||
{
|
||||
int Index;
|
||||
float Distance;
|
||||
};
|
||||
|
||||
bool isFirstLower(const RaySorterInfo& first, const RaySorterInfo& second);
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -166,6 +177,13 @@ void Octree<T>::ObjectsInFrustum(const Frustum& frustum, std::vector<T>& outObje
|
||||
m_Root->ObjectsInFrustum(frustum, outObjects, false);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Octree<T>::ObjectsPossiblyHitByRay(const Ray& ray, std::vector<T>& outObjects)
|
||||
{
|
||||
falsifyObjectChecks();
|
||||
m_Root->ObjectsPossiblyHitByRay(ray, outObjects);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Octree<T>::ClearObjects()
|
||||
{
|
||||
@@ -284,4 +302,59 @@ void OctSpace::Child::ObjectsInFrustum(const Frustum& frustum, std::vector<T>& o
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void OctSpace::Child::ObjectsPossiblyHitByRay(const Ray& ray, std::vector<T>& outObjects) const
|
||||
{
|
||||
//If the node AABB is missed, everything it contains is missed.
|
||||
if (Collision::RayAABBIntr(ray, m_Box)) {
|
||||
//If the ray shoots the tree, and it is a parent.
|
||||
if (hasChildren()) {
|
||||
//Sort children according to their distance from the ray origin.
|
||||
std::vector<RaySorterInfo> childInfos;
|
||||
childInfos.resize(8);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
childInfos[i] = { i, glm::distance(ray.Origin(), m_Children[i]->m_Box.Origin()) };
|
||||
}
|
||||
std::sort(childInfos.begin(), childInfos.end(), isFirstLower);
|
||||
//Loop through the children, starting with the one closest to the ray origin. I.e the first to be hit.
|
||||
for (const RaySorterInfo& info : childInfos) {
|
||||
m_Children[info.Index]->ObjectsPossiblyHitByRay(ray, outObjects);
|
||||
}
|
||||
} else {
|
||||
//Check against boxes in the node.
|
||||
bool intersected = false;
|
||||
float dist;
|
||||
//Sort all contained objects according to the distance from the ray origin to
|
||||
//the intersection, if they are intersecting.
|
||||
std::vector<RaySorterInfo> objectHitInfos;
|
||||
objectHitInfos.reserve(m_StaticObjIndices.size() + m_DynamicObjIndices.size());
|
||||
for (int i : m_StaticObjIndices) {
|
||||
//If we haven't tested against this object before, and the ray hits.
|
||||
if (!m_StaticObjectsRef[i].Checked &&
|
||||
Collision::RayVsAABB(ray, *m_StaticObjectsRef[i].Box, dist)) {
|
||||
objectHitInfos.push_back({ i, dist });
|
||||
}
|
||||
m_StaticObjectsRef[i].Checked = true;
|
||||
}
|
||||
for (int i : m_DynamicObjIndices) {
|
||||
//If we haven't tested against this object before, and the ray hits.
|
||||
if (!m_DynamicObjectsRef[i].Checked &&
|
||||
Collision::RayVsAABB(ray, *m_DynamicObjectsRef[i].Box, dist)) {
|
||||
objectHitInfos.push_back({ i + (int)m_StaticObjIndices.size(), dist });
|
||||
}
|
||||
m_DynamicObjectsRef[i].Checked = true;
|
||||
}
|
||||
std::sort(objectHitInfos.begin(), objectHitInfos.end(), isFirstLower);
|
||||
int startSize = (int)outObjects.size();
|
||||
outObjects.resize(startSize + objectHitInfos.size());
|
||||
for (int i = 0; i < objectHitInfos.size(); ++i) {
|
||||
outObjects[startSize + i] = (objectHitInfos[i].Index < m_StaticObjIndices.size()) ?
|
||||
*static_cast<T*>(m_StaticObjectsRef[objectHitInfos[i].Index].Box.get()) :
|
||||
*static_cast<T*>(m_DynamicObjectsRef[objectHitInfos[i].Index - m_StaticObjIndices.size()].Box.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef PerformanceTimer_h__
|
||||
#define PerformanceTimer_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include <boost/timer/timer.hpp>
|
||||
using boost::timer::cpu_timer;
|
||||
|
||||
class PerformanceTimer
|
||||
{
|
||||
public:
|
||||
static void StartTimer(std::string nameOfTimer);
|
||||
static void StartTimerAndStopPrevious(std::string nameOfTimer);
|
||||
static void StopTimer(std::string nameOfTimer);
|
||||
static void SetFrameNumber(int frameNumber);
|
||||
|
||||
static void ResetAllTimers();
|
||||
static void CreateExcelData();
|
||||
|
||||
private:
|
||||
static std::map<std::string, cpu_timer> timers;
|
||||
static cpu_timer m_Timer;
|
||||
static std::string currentTimerRunning;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,21 +5,55 @@
|
||||
#include "World.h"
|
||||
#include "EntityWrapper.h"
|
||||
#include "ComponentWrapper.h"
|
||||
#include "EPlayerSpawned.h"
|
||||
|
||||
struct SystemParams
|
||||
{
|
||||
SystemParams(::World* World, ::EventBroker* EventBroker, bool IsClient, bool IsServer)
|
||||
: World(World)
|
||||
, EventBroker(EventBroker)
|
||||
, IsClient(IsClient)
|
||||
, IsServer(IsServer)
|
||||
{ }
|
||||
|
||||
::World* World;
|
||||
::EventBroker* EventBroker;
|
||||
bool IsClient = false;
|
||||
bool IsServer = false;
|
||||
};
|
||||
|
||||
class System
|
||||
{
|
||||
friend class SystemPipeline;
|
||||
|
||||
protected:
|
||||
System(World* world, EventBroker) { }
|
||||
System(World* world, EventBroker* eventBroker)
|
||||
: m_World(world)
|
||||
, m_EventBroker(eventBroker)
|
||||
{ }
|
||||
System(SystemParams params)
|
||||
: m_World(params.World)
|
||||
, m_EventBroker(params.EventBroker)
|
||||
, IsClient(params.IsClient)
|
||||
, IsServer(params.IsServer)
|
||||
{
|
||||
if (IsClient) {
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &System::setLocalPlayer);
|
||||
}
|
||||
}
|
||||
virtual ~System() = default;
|
||||
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
bool IsClient = false;
|
||||
bool IsServer = false;
|
||||
EntityWrapper LocalPlayer = EntityWrapper::Invalid;
|
||||
|
||||
private:
|
||||
EventRelay<System, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
virtual bool setLocalPlayer(Events::PlayerSpawned& e)
|
||||
{
|
||||
if (e.PlayerID == -1) {
|
||||
LocalPlayer = e.Player;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class PureSystem : public virtual System
|
||||
@@ -34,7 +68,7 @@ protected:
|
||||
|
||||
const std::string m_ComponentType;
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) = 0;
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) = 0;
|
||||
};
|
||||
|
||||
class ImpureSystem : public virtual System
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
#include "System.h"
|
||||
#include "World.h"
|
||||
#include "EPause.h"
|
||||
#include "PerformanceTimer.h"
|
||||
|
||||
class SystemPipeline
|
||||
{
|
||||
public:
|
||||
SystemPipeline(World* world, EventBroker* eventBroker)
|
||||
SystemPipeline(World* world, EventBroker* eventBroker, bool isClient, bool isServer)
|
||||
: m_World(world)
|
||||
, m_EventBroker(eventBroker)
|
||||
, m_IsClient(isClient)
|
||||
, m_IsServer(isServer)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SystemPipeline::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SystemPipeline::OnResume);
|
||||
@@ -35,7 +38,7 @@ public:
|
||||
m_OrderedSystemGroups.resize(updateOrderLevel + 1);
|
||||
}
|
||||
UnorderedSystems& group = m_OrderedSystemGroups[updateOrderLevel];
|
||||
System* system = new T(m_World, m_EventBroker, args...);
|
||||
System* system = new T(SystemParams(m_World, m_EventBroker, m_IsClient, m_IsServer), args...);
|
||||
group.Systems[typeid(T).name()] = system;
|
||||
|
||||
PureSystem* pureSystem = dynamic_cast<PureSystem*>(system);
|
||||
@@ -59,6 +62,9 @@ public:
|
||||
dt = 0.0;
|
||||
}
|
||||
|
||||
// Process utility events for the System base class
|
||||
m_EventBroker->Process<System>();
|
||||
|
||||
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
||||
// Process events
|
||||
for (auto& pair : group.Systems) {
|
||||
@@ -67,7 +73,10 @@ public:
|
||||
|
||||
// Update
|
||||
for (auto& system : group.ImpureSystems) {
|
||||
auto className = (std::string)typeid(*system).name();
|
||||
PerformanceTimer::StartTimer(className);
|
||||
system->Update(dt);
|
||||
PerformanceTimer::StopTimer(className);
|
||||
}
|
||||
for (auto& pair : group.PureSystems) {
|
||||
const std::string& componentName = pair.first;
|
||||
@@ -78,7 +87,10 @@ public:
|
||||
}
|
||||
for (auto& component : *pool) {
|
||||
for (auto& system : systems) {
|
||||
auto className = (std::string)typeid(*system).name();
|
||||
PerformanceTimer::StartTimer(className);
|
||||
system->UpdateComponent(EntityWrapper(m_World, component.EntityID), component, dt);
|
||||
PerformanceTimer::StopTimer(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +100,8 @@ public:
|
||||
private:
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
bool m_IsClient = false;
|
||||
bool m_IsServer = false;
|
||||
bool m_Paused = false;
|
||||
|
||||
struct UnorderedSystems
|
||||
@@ -99,9 +113,9 @@ private:
|
||||
std::vector<UnorderedSystems> m_OrderedSystemGroups;
|
||||
|
||||
EventRelay<SystemPipeline, Events::Pause> m_EPause;
|
||||
bool OnPause(const Events::Pause& e) {
|
||||
if (e.World == m_World) {
|
||||
m_Paused = true;
|
||||
bool OnPause(const Events::Pause& e) {
|
||||
if (e.World == m_World) {
|
||||
m_Paused = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
class UniformScaleSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
UniformScaleSystem(World* world, EventBroker* eventBroker);
|
||||
UniformScaleSystem(SystemParams params);
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cUniformScale, double dt) override;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define Util_Any_h__
|
||||
|
||||
#include <memory>
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
struct Any
|
||||
{
|
||||
@@ -10,7 +11,7 @@ struct Any
|
||||
template <typename T>
|
||||
Any(const T& value)
|
||||
{
|
||||
Data = std::shared_ptr<char>(new char[sizeof(T)]);
|
||||
Data = boost::shared_array<char>(new char[sizeof(T)]);
|
||||
Size = sizeof(T);
|
||||
memcpy(Data.get(), &value, Size);
|
||||
}
|
||||
@@ -18,7 +19,7 @@ struct Any
|
||||
template <typename T>
|
||||
Any(T&& value)
|
||||
{
|
||||
Data = std::shared_ptr<char>(new char[sizeof(T)]);
|
||||
Data = boost::shared_array<char>(new char[sizeof(T)]);
|
||||
Size = sizeof(T);
|
||||
memcpy(Data.get(), &value, Size);
|
||||
}
|
||||
@@ -35,7 +36,7 @@ struct Any
|
||||
return Any(value);
|
||||
}
|
||||
|
||||
std::shared_ptr<char> Data = nullptr;
|
||||
boost::shared_array<char> Data = nullptr;
|
||||
std::size_t Size = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ObjectPool.h"
|
||||
#include "ComponentPool.h"
|
||||
#include "EventBroker.h"
|
||||
struct EntityWrapper;
|
||||
|
||||
class World
|
||||
{
|
||||
@@ -15,15 +16,16 @@ public:
|
||||
: m_EventBroker(eventBroker)
|
||||
{ }
|
||||
~World();
|
||||
World(const World& other);
|
||||
|
||||
// Create empty entity
|
||||
EntityID CreateEntity(EntityID parent = 0);
|
||||
EntityID CreateEntity(EntityID parent = EntityID_Invalid);
|
||||
// Delete entity and all components within
|
||||
void DeleteEntity(EntityID entity);
|
||||
// Check if an entity exists
|
||||
bool ValidEntity(EntityID entity) const;
|
||||
// Register a component type and allocate space for it
|
||||
void RegisterComponent(ComponentInfo& ci);
|
||||
void RegisterComponent(const ComponentInfo& ci);
|
||||
// Attach a component to an entity and fill it with default values
|
||||
ComponentWrapper AttachComponent(EntityID entity, const std::string& componentType);
|
||||
// Check if an entity has a component
|
||||
@@ -39,7 +41,7 @@ public:
|
||||
// Change the parent of an entity
|
||||
void SetParent(EntityID entity, EntityID parent);
|
||||
// Get children of an entity
|
||||
const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> GetChildren(EntityID entity);
|
||||
const std::pair<std::unordered_multimap<EntityID, EntityID>::const_iterator, std::unordered_multimap<EntityID, EntityID>::const_iterator> GetDirectChildren(EntityID entity);
|
||||
// Get all component pools
|
||||
const std::unordered_map<std::string, ComponentPool*>& GetComponentPools() const { return m_ComponentPools; }
|
||||
// Get the entity children map
|
||||
@@ -48,6 +50,12 @@ public:
|
||||
void SetName(EntityID entity, const std::string& name);
|
||||
// Get the textual name of an entity
|
||||
std::string GetName(EntityID entity) const;
|
||||
// Get the first entity in the world with the name.
|
||||
EntityWrapper GetFirstEntityByName(const std::string& name);
|
||||
|
||||
// Merge another world into this one
|
||||
// Returns a map that maps entities from the other world to their copies in this one
|
||||
std::unordered_map<EntityID, EntityID> Merge(const World* other);
|
||||
|
||||
private:
|
||||
EventBroker* m_EventBroker = nullptr;
|
||||
|
||||
@@ -104,6 +104,11 @@ protected:
|
||||
if (!m_Enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.WantCaptureMouse || io.WantCaptureKeyboard) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_SpeedMultiplier += e.DeltaY * (0.1 * m_SpeedMultiplier);
|
||||
m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier);
|
||||
|
||||
@@ -73,6 +73,12 @@ public:
|
||||
// Called when the user means to rename an entity.
|
||||
typedef std::function<void(EntityWrapper, const std::string&)> OnEntityChangeName_t;
|
||||
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.
|
||||
typedef std::function<void(EntityWrapper, const std::string&)> OnComponentAttach_t;
|
||||
void SetComponentAttachCallback(OnComponentAttach_t f) { m_OnComponentAttach = f; }
|
||||
@@ -111,6 +117,7 @@ private:
|
||||
std::string m_DroppedFile = "";
|
||||
bool m_Paused = false;
|
||||
bool m_MouseLocked = false;
|
||||
EntityWrapper m_CopyTarget = EntityWrapper::Invalid;
|
||||
|
||||
// Callbacks
|
||||
OnEntitySelectedCallback_t m_OnEntitySelected = nullptr;
|
||||
@@ -124,6 +131,7 @@ private:
|
||||
OnComponentDelete_t m_OnComponentDelete = nullptr;
|
||||
OnWidgetMode_t m_OnWidgetMode = nullptr;
|
||||
OnWidgetSpace_t m_OnWidgetSpace = nullptr;
|
||||
OnEntityPaste_t m_OnEntityPaste = nullptr;
|
||||
|
||||
// Events
|
||||
EventRelay<EditorGUI, Events::KeyDown> m_EKeyDown;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
class EditorRenderSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
EditorRenderSystem(World* world, EventBroker* eventBroker, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
EditorRenderSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
#include "../Core/World.h"
|
||||
#include "../Core/SystemPipeline.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Core/EntityFilePreprocessor.h"
|
||||
#include "../Core/EntityFileParser.h"
|
||||
#include "../Core/EntityFileWriter.h"
|
||||
#include "../Core/EntityFile.h"
|
||||
#include "../Core/EntityXMLFileWriter.h"
|
||||
#include "../Core/EMousePress.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
#include "EditorGUI.h"
|
||||
@@ -17,7 +16,7 @@
|
||||
class EditorSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
EditorSystem(World* world, EventBroker* eventBroker, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
~EditorSystem();
|
||||
|
||||
void Update(double dt);
|
||||
@@ -56,6 +55,7 @@ private:
|
||||
void OnEntityDelete(EntityWrapper entity);
|
||||
void OnEntityChangeParent(EntityWrapper entity, EntityWrapper parent);
|
||||
void OnEntityChangeName(EntityWrapper entity, const std::string& name);
|
||||
EntityWrapper OnEntityPaste(EntityWrapper entityToCopy, EntityWrapper parent);
|
||||
void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
|
||||
void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
|
||||
void OnWidgetSpace(EditorGUI::WidgetSpace widgetSpace);
|
||||
|
||||
@@ -25,7 +25,7 @@ struct WidgetDelta : Event
|
||||
class EditorWidgetSystem : public ImpureSystem, PureSystem
|
||||
{
|
||||
public:
|
||||
EditorWidgetSystem(World* world, EventBroker* eventBroker, IRenderer* renderer);
|
||||
EditorWidgetSystem(SystemParams params, IRenderer* renderer);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cEditorWidget, double dt) override;
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
#ifndef GUI_BUTTON_H__
|
||||
#define GUI_BUTTON_H__
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "GUI/EButtonEnter.h"
|
||||
#include "GUI/EButtonLeave.h"
|
||||
#include "GUI/EButtonPress.h"
|
||||
#include "GUI/EButtonRelease.h"
|
||||
#include "Core/EMouseMove.h"
|
||||
#include "Core/EMousePress.h"
|
||||
#include "Core/EMouseRelease.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class Button : public TextureFrame
|
||||
{
|
||||
public:
|
||||
Button(Frame* parent, std::string name)
|
||||
: TextureFrame(parent, name)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Button::OnMouseMove);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Button::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease);
|
||||
}
|
||||
|
||||
void SetTextureHover(std::string resourceName)
|
||||
{
|
||||
m_TextureHover = resourceName;
|
||||
}
|
||||
void SetTextureReleased(std::string resourceName)
|
||||
{
|
||||
m_TextureReleased = resourceName;
|
||||
SetTexture(resourceName);
|
||||
}
|
||||
void SetTexturePressed(std::string resourceName)
|
||||
{
|
||||
m_TexturePressed = resourceName;
|
||||
}
|
||||
|
||||
void Draw(RenderScene& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr && !m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
|
||||
TextureFrame::Draw(rq);
|
||||
}
|
||||
|
||||
virtual void OnEnter() { }
|
||||
virtual void OnLeave() { }
|
||||
virtual void OnPress() { }
|
||||
virtual void OnRelease() { }
|
||||
|
||||
protected:
|
||||
bool m_MouseIsOver = false;
|
||||
bool m_IsDown = false;
|
||||
|
||||
virtual bool OnMouseMove(const Events::MouseMove& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (isOver && !m_MouseIsOver) { // Enter
|
||||
if (!m_IsDown) {
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
}
|
||||
OnEnter();
|
||||
Events::ButtonEnter e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
Events::PlaySound soundEvent;
|
||||
soundEvent.FilePath = "Sounds/GUI/hover-n.wav";
|
||||
EventBroker->Publish(soundEvent);
|
||||
|
||||
} else if (!isOver && m_MouseIsOver) { // Leave
|
||||
if (!m_IsDown) {
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
OnLeave();
|
||||
Events::ButtonLeave e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
m_MouseIsOver = isOver;
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool OnMousePress(const Events::MousePress& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
//LOG_DEBUG("Pressed hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_TexturePressed.empty()) {
|
||||
SetTexture(m_TexturePressed);
|
||||
}
|
||||
|
||||
m_IsDown = true;
|
||||
OnPress();
|
||||
Events::ButtonPress e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool OnMouseRelease(const Events::MouseRelease& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
//LOG_DEBUG("Released hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (!isOver && !m_IsDown) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_MouseIsOver) {
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
} else {
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
|
||||
m_IsDown = false;
|
||||
OnRelease();
|
||||
Events::ButtonRelease e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
|
||||
EventRelay<Frame, Events::MousePress> m_EMousePress;
|
||||
EventRelay<Frame, Events::MouseRelease> m_EMouseRelease;
|
||||
|
||||
std::string m_TextureHover;
|
||||
std::string m_TexturePressed;
|
||||
std::string m_TextureReleased;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef ButtonSystem_h__
|
||||
#define ButtonSystem_h__
|
||||
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
#include "../Rendering/PickingPass.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Core/System.h"
|
||||
#include "../Core/Event.h"
|
||||
#include "../Core/EMousePress.h"
|
||||
#include "../Core/EMouseRelease.h"
|
||||
#include "../Core/ELockMouse.h"
|
||||
|
||||
#include "EButtonPressed.h"
|
||||
#include "EButtonReleased.h"
|
||||
#include "EButtonClicked.h"
|
||||
|
||||
|
||||
class ButtonSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
ButtonSystem(SystemParams params, IRenderer* renderer);
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override;
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
bool m_MouseIsLocked = false;
|
||||
|
||||
EntityWrapper m_PickEntity = EntityWrapper::Invalid;
|
||||
PickData m_PickData;
|
||||
|
||||
EventRelay<ButtonSystem, Events::LockMouse> m_EMouseLock;
|
||||
bool OnMouseLock(const Events::LockMouse& e);
|
||||
EventRelay<ButtonSystem, Events::UnlockMouse> m_EMouseUnlock;
|
||||
bool OnMouseUnlock(const Events::UnlockMouse& e);
|
||||
|
||||
EventRelay<ButtonSystem, Events::MousePress> m_EMousePress;
|
||||
bool OnMousePress(const Events::MousePress& e);
|
||||
EventRelay<ButtonSystem, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease& e);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_ButtonClicked_h__
|
||||
#define Events_ButtonClicked_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ButtonClicked : public Event {
|
||||
std::string EntityName;
|
||||
EntityWrapper Entity;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef Events_ButtonEnter_h__
|
||||
#define Events_ButtonEnter_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonEnter : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef Events_ButtonLeave_h__
|
||||
#define Events_ButtonLeave_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonLeave : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef Events_ButtonPress_h__
|
||||
#define Events_ButtonPress_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button press. */
|
||||
struct ButtonPress : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_ButtonPressed_h__
|
||||
#define Events_ButtonPressed_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ButtonPressed : public Event {
|
||||
std::string EntityName;
|
||||
EntityWrapper Entity;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef Events_ButtonRelease_h__
|
||||
#define Events_ButtonRelease_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button release. */
|
||||
struct ButtonRelease : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_ButtonReleased_h__
|
||||
#define Events_ButtonReleased_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ButtonReleased : public Event {
|
||||
std::string EntityName;
|
||||
EntityWrapper Entity;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,261 +0,0 @@
|
||||
#ifndef GUI_Frame_h__
|
||||
#define GUI_Frame_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/EKeyDown.h"
|
||||
#include "../Core/EKeyUp.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Rendering/RenderQueue.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class Frame : public Rectangle
|
||||
{
|
||||
public:
|
||||
enum class Anchor
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
};
|
||||
|
||||
static const int BaseWidth = 1280;
|
||||
static const int BaseHeight = 720;
|
||||
|
||||
// Set up a base frame with an event broker
|
||||
Frame(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
, BaseFrame(this)
|
||||
, m_Name("UIParent")
|
||||
, Rectangle() { }
|
||||
|
||||
// Create a frame as a child
|
||||
Frame(Frame* parent, std::string name)
|
||||
: m_Name(name)
|
||||
{
|
||||
SetParent(parent);
|
||||
Width = parent->Width;
|
||||
Height = parent->Height;
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||
}
|
||||
|
||||
~Frame()
|
||||
{
|
||||
/*for (auto layer : m_Children)
|
||||
{
|
||||
for (auto child : layer.second)
|
||||
{
|
||||
delete child.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Parent)
|
||||
{
|
||||
m_Parent->RemoveChild(this);
|
||||
}*/
|
||||
}
|
||||
|
||||
Frame* Parent() const { return m_Parent; }
|
||||
|
||||
void SetParent(Frame* parent)
|
||||
{
|
||||
if (parent == nullptr) {
|
||||
LOG_ERROR("Failed to parent frame \"%s\": Invalid parent", m_Name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_Layer = parent->Layer() + 1;
|
||||
parent->AddChild(this);
|
||||
m_Parent = parent;
|
||||
m_EventBroker = parent->m_EventBroker;
|
||||
BaseFrame = parent->BaseFrame;
|
||||
}
|
||||
|
||||
void AddChild(Frame* child)
|
||||
{
|
||||
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
|
||||
if (m_Parent) {
|
||||
m_Parent->AddChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveChild(Frame* child)
|
||||
{
|
||||
auto it = m_Children.find(child->m_Layer);
|
||||
if (it != m_Children.end()) {
|
||||
m_Children.erase(it);
|
||||
}
|
||||
|
||||
if (m_Parent) {
|
||||
m_Parent->RemoveChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Name() const { return m_Name; }
|
||||
void SetName(std::string val) { m_Name = val; }
|
||||
|
||||
int Layer() const { return m_Layer; }
|
||||
|
||||
bool Hidden() const
|
||||
{
|
||||
if (m_Parent)
|
||||
return m_Parent->Hidden() || m_Hidden;
|
||||
else
|
||||
return m_Hidden;
|
||||
}
|
||||
bool Visible() const
|
||||
{
|
||||
return !Hidden();
|
||||
}
|
||||
|
||||
virtual void Hide() { m_Hidden = true; }
|
||||
virtual void Show() { m_Hidden = false; }
|
||||
|
||||
int Left() const override
|
||||
{
|
||||
if (m_Parent)
|
||||
return m_Parent->Left() + X;
|
||||
else
|
||||
return X;
|
||||
}
|
||||
void SetLeft(int absLeft) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absLeft - m_Parent->Left();
|
||||
} else {
|
||||
X = absLeft;
|
||||
}
|
||||
}
|
||||
int Right() const override
|
||||
{
|
||||
return Left() + Width;
|
||||
}
|
||||
void SetRight(int absRight) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absRight - Width - m_Parent->Left();
|
||||
} else {
|
||||
X = absRight - Width;
|
||||
}
|
||||
}
|
||||
int Top() const override
|
||||
{
|
||||
if (m_Parent)
|
||||
return m_Parent->Top() + Y;
|
||||
else
|
||||
return Y;
|
||||
}
|
||||
void SetTop(int absTop) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absTop - m_Parent->Top();
|
||||
} else {
|
||||
Y = absTop;
|
||||
}
|
||||
}
|
||||
int Bottom() const override
|
||||
{
|
||||
return Top() + Height;
|
||||
}
|
||||
void SetBottom(int absBottom) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absBottom - Height - m_Parent->Top();
|
||||
} else {
|
||||
Y = absBottom - Height;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 Scale()
|
||||
{
|
||||
if (m_Parent)
|
||||
return m_Parent->Scale();
|
||||
else
|
||||
return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight);
|
||||
}
|
||||
|
||||
Rectangle AbsoluteRectangle()
|
||||
{
|
||||
int left = Left();
|
||||
if (m_Parent)
|
||||
left = std::max(left, m_Parent->Left());
|
||||
int top = Top();
|
||||
if (m_Parent)
|
||||
top = std::max(top, m_Parent->Top());
|
||||
int width = Right() - left;
|
||||
int height = Bottom() - top;
|
||||
return Rectangle(left, top, width, height);
|
||||
}
|
||||
|
||||
void UpdateLayered(double dt)
|
||||
{
|
||||
// Update ourselves
|
||||
this->Update(dt);
|
||||
|
||||
// Update children
|
||||
for (auto& pairLayer : m_Children) {
|
||||
auto children = pairLayer.second;
|
||||
for (auto& pairChild : children) {
|
||||
auto child = pairChild.second;
|
||||
child->Update(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Update(double dt) { }
|
||||
|
||||
void DrawLayered(RenderScene& rq)
|
||||
{
|
||||
if (this->Hidden())
|
||||
return;
|
||||
|
||||
// Draw ourselves
|
||||
this->Draw(rq);
|
||||
|
||||
// Draw children
|
||||
for (auto& pairLayer : m_Children) {
|
||||
auto children = pairLayer.second;
|
||||
for (auto& pairChild : children) {
|
||||
auto child = pairChild.second;
|
||||
if (child->Hidden())
|
||||
continue;
|
||||
child->Draw(rq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Draw(RenderScene& rq) { }
|
||||
|
||||
protected:
|
||||
::EventBroker* m_EventBroker;
|
||||
Frame* BaseFrame = nullptr;
|
||||
|
||||
std::string m_Name = "Unnamed";
|
||||
int m_Layer = 0;
|
||||
bool m_Hidden = false;
|
||||
|
||||
Frame* m_Parent = nullptr;
|
||||
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
|
||||
std::map<int, Children_t> m_Children; // layer -> Children_t
|
||||
|
||||
virtual bool OnKeyDown(const Events::KeyDown& event) { return false; }
|
||||
virtual bool OnKeyUp(const Events::KeyUp& event) { return false; }
|
||||
virtual bool OnCommand(const Events::InputCommand& event) { return false; }
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
|
||||
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
||||
EventRelay<Frame, Events::InputCommand> m_EInputCommand;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef MainMenuSystem_h__
|
||||
#define MainMenuSystem_h__
|
||||
|
||||
#include "../Core/System.h"
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Core/Event.h"
|
||||
|
||||
|
||||
#include "EButtonClicked.h"
|
||||
#include "EButtonPressed.h"
|
||||
#include "EButtonReleased.h"
|
||||
|
||||
|
||||
class MainMenuSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
MainMenuSystem(SystemParams params, IRenderer* renderer);
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
|
||||
EventRelay<MainMenuSystem, Events::ButtonClicked> m_EClicked;
|
||||
bool OnButtonClick(const Events::ButtonClicked& e);
|
||||
EventRelay<MainMenuSystem, Events::ButtonReleased> m_EReleased;
|
||||
bool OnButtonRelease(const Events::ButtonReleased& e);
|
||||
EventRelay<MainMenuSystem, Events::ButtonPressed> m_EPressed;
|
||||
bool OnButtonPress(const Events::ButtonPressed& e);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,111 +0,0 @@
|
||||
#ifndef GUI_TextureFrame_h__
|
||||
#define GUI_TextureFrame_h__
|
||||
|
||||
#include "Frame.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class TextureFrame : public Frame
|
||||
{
|
||||
public:
|
||||
TextureFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name) { }
|
||||
|
||||
void EnableScissor() { m_ScissorEnabled = true; }
|
||||
void DisableScissor() { m_ScissorEnabled = false; }
|
||||
|
||||
void Draw(RenderScene& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr)
|
||||
return;
|
||||
|
||||
// Texture while fading
|
||||
if (m_FadeTexture && m_CurrentFade < 1) {
|
||||
FrameJob job;
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_FadeTexture->ResourceID;
|
||||
job.DiffuseTexture = m_FadeTexture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
|
||||
// Main texture
|
||||
{
|
||||
FrameJob job;
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_Texture->ResourceID;
|
||||
job.DiffuseTexture = m_Texture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Texture() const { return m_TextureName; }
|
||||
|
||||
void SetTexture(std::string resourceName)
|
||||
{
|
||||
if (resourceName.empty()) {
|
||||
m_Texture = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
m_Texture = ResourceManager::Load<Texture>(resourceName);
|
||||
m_TextureName = resourceName;
|
||||
if (m_Texture == nullptr) {
|
||||
m_Texture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
}
|
||||
|
||||
SizeToTexture();
|
||||
}
|
||||
|
||||
void SizeToTexture()
|
||||
{
|
||||
if (m_Texture != nullptr) {
|
||||
this->Width = m_Texture->Width;
|
||||
this->Height = m_Texture->Height;
|
||||
}
|
||||
}
|
||||
|
||||
void FadeToTexture(std::string resourceName, double duration)
|
||||
{
|
||||
m_FadeTexture = m_Texture;
|
||||
SetTexture(resourceName);
|
||||
m_FadeDuration = duration;
|
||||
m_CurrentFade = 0.f;
|
||||
}
|
||||
|
||||
void Update(double dt) override
|
||||
{
|
||||
if (m_CurrentFade < 1) {
|
||||
m_CurrentFade += dt / m_FadeDuration;
|
||||
if (m_CurrentFade > 1) {
|
||||
m_FadeTexture = nullptr;
|
||||
m_CurrentFade = 1;
|
||||
m_FadeDuration = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec4 Color() const { return m_Color; }
|
||||
void SetColor(glm::vec4 val) { m_Color = val; }
|
||||
|
||||
protected:
|
||||
bool m_ScissorEnabled = true;
|
||||
Texture* m_Texture = nullptr;
|
||||
std::string m_TextureName;
|
||||
Texture* m_FadeTexture = nullptr;
|
||||
glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
float m_FadeDuration = 0.f;
|
||||
float m_CurrentFade = 1.f;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
virtual bool OnCommand(const Events::InputCommand& e) override;
|
||||
virtual void Reset();
|
||||
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer);
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID);
|
||||
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
|
||||
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
|
||||
|
||||
@@ -41,7 +41,7 @@ protected:
|
||||
bool m_Crouching = false;
|
||||
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||
double m_AssaultDashCoolDownTimer = 0.0;
|
||||
double m_DashEffectResetTimer = 0.0;
|
||||
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||
//and its very unlikely that someone wants to change that value
|
||||
const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f;
|
||||
@@ -52,9 +52,10 @@ protected:
|
||||
bool m_ShiftDashing = false;
|
||||
bool m_ValidDoubleTap = false;
|
||||
|
||||
//specialabilitys
|
||||
//specialabilities
|
||||
bool m_MovementKeyDown = false;
|
||||
bool m_SpecialAbilityKeyDown = false;
|
||||
int m_NumberOfMovementKeysDown = 0;
|
||||
|
||||
EventRelay<EventContext, Events::LockMouse> m_ELockMouse;
|
||||
bool OnLockMouse(const Events::LockMouse& e);
|
||||
@@ -132,6 +133,7 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
|
||||
}
|
||||
//if value = 0 then you have just released this key
|
||||
if (e.Value != 0) {
|
||||
m_NumberOfMovementKeysDown++;
|
||||
m_MovementKeyDown = true;
|
||||
//if you pressed the same key within m_AssaultDashDoubleTapSensitivityTimer then you have doubletapped it
|
||||
if (m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer && m_AssaultDashTapDirection == m_CurrentDirectionVector) {
|
||||
@@ -139,10 +141,14 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
|
||||
}
|
||||
} else {
|
||||
//== 0
|
||||
m_MovementKeyDown = false;
|
||||
//you have just released the key, store what key it was and reset the doubletap-sensitivity-timer
|
||||
m_AssaultDashTapDirection = m_CurrentDirectionVector;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_NumberOfMovementKeysDown--;
|
||||
if (m_NumberOfMovementKeysDown == 0) {
|
||||
m_MovementKeyDown = false;
|
||||
}
|
||||
//you have just released the key, store what key it was and reset the doubletap-sensitivity-timer
|
||||
m_AssaultDashTapDirection = m_CurrentDirectionVector;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,29 +191,33 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
|
||||
}
|
||||
|
||||
template <typename EventContext>
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) {
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID) {
|
||||
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||
m_AssaultDashCoolDownTimer -= dt;
|
||||
m_DashEffectResetTimer += dt;
|
||||
assaultDashCoolDownTimer -= dt;
|
||||
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||
if (m_AssaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
|
||||
if (assaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
|
||||
m_PlayerIsDashing = true;
|
||||
if (m_DashEffectResetTimer > 0.05) {
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
m_DashEffectResetTimer = 0.0;
|
||||
}
|
||||
} else {
|
||||
m_PlayerIsDashing = false;
|
||||
}
|
||||
|
||||
//dashing with shift
|
||||
if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) {
|
||||
if (m_ShiftDashing && assaultDashCoolDownTimer <= 0.0f) {
|
||||
//player is dashing with shift
|
||||
//the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in!
|
||||
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
//moving to the side has priority
|
||||
return;
|
||||
}
|
||||
|
||||
//dashing with doubletap - check if doubletap to dash enabled
|
||||
if (ResourceManager::Load<ConfigFile>("Input.ini")->Get<bool>("Keyboard.DoubleTapToDash", false)) {
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,13 +226,18 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
m_AssaultDashDoubleTapped = false;
|
||||
}
|
||||
|
||||
//dashing with doubletap - check if doubletap to dash enabled
|
||||
if (!ResourceManager::Load<ConfigFile>("Input.ini")->Get<bool>("Keyboard.DoubleTapToDash", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//check if we have received a valid doubletap
|
||||
if (!m_ValidDoubleTap) {
|
||||
return;
|
||||
}
|
||||
m_ValidDoubleTap = false;
|
||||
|
||||
if (!(m_AssaultDashCoolDownTimer <= 0.0f && !isJumping)) {
|
||||
if (!(assaultDashCoolDownTimer <= 0.0f)) {
|
||||
//if we cant dash at the moment, then just reset the tap-sensitivity-timer
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
return;
|
||||
@@ -230,9 +245,10 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
//ok, we have a valid tap, lets do it
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,31 +13,56 @@
|
||||
#include "Network/Network.h"
|
||||
#include "Network/MessageType.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
#include "Network/UDPClient.h"
|
||||
#include "Network/TCPClient.h"
|
||||
#include "Network/SnapshotDefinitions.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Core/EPlayerDeath.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "../Game/Events/EDoubleJump.h"
|
||||
#include "Network/EInterpolate.h"
|
||||
#include "Network/SnapshotFilter.h"
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Network/ESearchForServers.h"
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
|
||||
struct ServerInfo
|
||||
{
|
||||
ServerInfo(std::string a, int b, std::string c, int d)
|
||||
{
|
||||
Address = a; Port = b; Name = c; PlayersConnected = d;
|
||||
}
|
||||
std::string Address = "";
|
||||
int Port = 0;
|
||||
std::string Name = "";
|
||||
int PlayersConnected = 0;
|
||||
};
|
||||
|
||||
class Client : public Network
|
||||
{
|
||||
public:
|
||||
Client(ConfigFile* config);
|
||||
Client(World* world, EventBroker* eventBroker);
|
||||
Client(World* world, EventBroker* eventBroker, std::unique_ptr<SnapshotFilter> snapshotFilter);
|
||||
~Client();
|
||||
void Start(World* world, EventBroker* eventBroker) override;
|
||||
|
||||
void Connect(std::string address, int port);
|
||||
void Update() override;
|
||||
private:
|
||||
// Assio UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
UDPClient m_Unreliable;
|
||||
TCPClient m_Reliable;
|
||||
std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents;
|
||||
void parseSpawnEvents();
|
||||
// Save for children
|
||||
std::unique_ptr<SnapshotFilter> m_SnapshotFilter = nullptr;
|
||||
|
||||
std::string m_Address;
|
||||
int m_Port = 0;
|
||||
// Sending message to server logic
|
||||
size_t bytesRead = 0;
|
||||
char readBuf[INPUTSIZE] = { 0 };
|
||||
|
||||
// Packet loss logic
|
||||
PacketID m_PacketID = 0;
|
||||
@@ -45,10 +70,8 @@ private:
|
||||
PacketID m_SendPacketID = 0;
|
||||
|
||||
// Game logic
|
||||
World* m_World;
|
||||
std::string m_PlayerName;
|
||||
PlayerID m_PlayerID = -1;
|
||||
EntityID m_ServerEntityID = std::numeric_limits<EntityID>::max();
|
||||
bool m_IsConnected = false;
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
|
||||
// Server Client Lookup map
|
||||
@@ -68,28 +91,34 @@ private:
|
||||
std::vector<Events::InputCommand> m_InputCommandBuffer;
|
||||
|
||||
// Private member functions
|
||||
void readFromServer();
|
||||
size_t receive(char* data);
|
||||
void send(Packet& packet);
|
||||
void connect();
|
||||
void disconnect();
|
||||
void parseMessageType(Packet& packet);
|
||||
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType);
|
||||
void parseConnect(Packet& packet);
|
||||
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID);
|
||||
SharedComponentWrapper createSharedComponent(Packet& packet, EntityID entityID, const ComponentInfo& componentInfo);
|
||||
void ignoreFields(Packet& packet, const ComponentInfo& componentInfo);
|
||||
void parseUDPConnect(Packet& packet);
|
||||
void parseTCPConnect(Packet& packet);
|
||||
void parsePlayerConnected(Packet& packet);
|
||||
void parsePing();
|
||||
void parseServerlist(Packet& packet);
|
||||
void parseKick();
|
||||
void parsePlayersSpawned(Packet& packet);
|
||||
void parseEntityDeletion(Packet& packet);
|
||||
void parsePlayerDamage(Packet& packet);
|
||||
void parseComponentDeletion(Packet& packet);
|
||||
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||
void parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseAmmoPickup(Packet& packet);
|
||||
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||
void parseSnapshot(Packet& packet);
|
||||
void identifyPacketLoss();
|
||||
bool hasServerTimedOut();
|
||||
void hasServerTimedOut();
|
||||
EntityID createPlayer();
|
||||
void sendInputCommands();
|
||||
void sendLocalPlayerTransform();
|
||||
void becomePlayer();
|
||||
void displayServerlist();
|
||||
// Mapping Logic
|
||||
// Returns if local EntityID exist in map
|
||||
bool clientServerMapsHasEntity(EntityID clientEntityID);
|
||||
@@ -99,13 +128,24 @@ private:
|
||||
void deleteFromServerClientMaps(EntityID serverEntityID, EntityID clientEntityID);
|
||||
|
||||
// Events
|
||||
EventBroker* m_EventBroker;
|
||||
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
EventRelay<Client, Events::PlayerDamage> m_EPlayerDamage;
|
||||
bool OnPlayerDamage(const Events::PlayerDamage& e);
|
||||
EventRelay<Client, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned& e);
|
||||
EventRelay< Client, Events::SearchForServers> m_ESearchForServers;
|
||||
EventRelay<Client, Events::DoubleJump> m_EDoubleJump;
|
||||
bool OnDoubleJump(Events::DoubleJump & e);
|
||||
EventRelay<Client, Events::DashAbility> m_EDashAbility;
|
||||
bool OnDashAbility(const Events::DashAbility& e);
|
||||
|
||||
bool OnSearchForServers(const Events::SearchForServers& e);
|
||||
UDPClient m_ServerlistRequest;
|
||||
std::vector<ServerInfo> m_Serverlist;
|
||||
bool m_SearchingForServers = false;
|
||||
std::clock_t m_StartSearchTime;
|
||||
double m_SearchingTime = 2000; // Config I guess
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,8 +11,13 @@ namespace Events
|
||||
|
||||
struct Interpolate : Event
|
||||
{
|
||||
EntityID Entity;
|
||||
boost::shared_array<char> DataArray;
|
||||
Interpolate(EntityWrapper Entity, SharedComponentWrapper Component)
|
||||
: Entity(Entity)
|
||||
, Component(Component)
|
||||
{ }
|
||||
|
||||
EntityWrapper Entity;
|
||||
SharedComponentWrapper Component;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef Events_SearchForServers_h__
|
||||
#define Events_SearchForServers_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct SearchForServers : public Event { };
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -18,7 +18,12 @@ enum class MessageType
|
||||
OnPlayerSpawned,
|
||||
EntityDeleted,
|
||||
ComponentDeleted,
|
||||
PlayerTransform
|
||||
PlayerTransform,
|
||||
OnDoubleJump,
|
||||
OnDashEffect,
|
||||
ServerlistRequest,
|
||||
AmmoPickup,
|
||||
Invalid
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,17 +12,22 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#define INPUTSIZE 32000
|
||||
#define BUFFERSIZE 32000
|
||||
typedef unsigned int PlayerID;
|
||||
typedef unsigned int PacketID;
|
||||
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
Network(World* world, EventBroker* eventBroker);
|
||||
virtual ~Network() { };
|
||||
virtual void Start(World* m_world, EventBroker *eventBroker) = 0;
|
||||
|
||||
virtual void Update() = 0;
|
||||
|
||||
protected:
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
// For Debug
|
||||
bool isReadingData = false;
|
||||
NetworkData m_NetworkData;
|
||||
@@ -30,9 +35,10 @@ protected:
|
||||
std::clock_t m_SaveDataTimer;
|
||||
unsigned int m_MaxConnections;
|
||||
double m_TimeoutMs;
|
||||
void logSentData(int bytesSent);
|
||||
void logReceivedData(int bytesReceived);
|
||||
void saveToFile();
|
||||
void updateNetworkData();
|
||||
void initialize();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef NetworkClient_h__
|
||||
#define NetworkClient_h__
|
||||
|
||||
#include "Network/Packet.h"
|
||||
#define BUFFERSIZE 64000
|
||||
typedef unsigned int PlayerID;
|
||||
typedef unsigned int PacketID;
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
NetworkClient();
|
||||
virtual ~NetworkClient();
|
||||
virtual void Connect(std::string playerName, std::string address, int port) = 0;
|
||||
virtual void Disconnect() = 0;
|
||||
virtual void Receive(Packet& packet) = 0;
|
||||
virtual void Send(Packet & packet) = 0;
|
||||
virtual bool IsSocketAvailable() = 0;
|
||||
protected:
|
||||
char* m_ReadBuffer;
|
||||
unsigned int m_BufferSize = BUFFERSIZE;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef NetworkServer_h__
|
||||
#define NetworkServer_h__
|
||||
#include <boost/asio.hpp>
|
||||
#include "Network/Packet.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
#define BUFFERSIZE 64000
|
||||
typedef unsigned int PlayerID;
|
||||
typedef unsigned int PacketID;
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
public:
|
||||
NetworkServer();
|
||||
virtual ~NetworkServer();
|
||||
virtual void AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers) = 0;
|
||||
virtual void Receive(Packet & packet, PlayerDefinition & playerDefinition) = 0;
|
||||
virtual void Send(Packet & packet, PlayerDefinition & playerDefinition) = 0;
|
||||
virtual void Send(Packet & packet) = 0;
|
||||
protected:
|
||||
char* m_ReadBuffer;
|
||||
unsigned int m_BufferSize = BUFFERSIZE;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -49,10 +49,15 @@ public:
|
||||
void WriteData(char* data, int sizeOfData);
|
||||
// Pops the first element as if it was a string.
|
||||
std::string ReadString();
|
||||
// Construct a packet
|
||||
void ReconstructFromData(char* data, size_t SizeOfData);
|
||||
// Update size of packet variable in header
|
||||
void UpdateSize();
|
||||
char* ReadData(int SizeOfData);
|
||||
void ChangePacketID(unsigned int& packetID);
|
||||
size_t Size() { return m_Offset; };
|
||||
char* Data() { return m_Data; };
|
||||
MessageType GetMessageType();
|
||||
size_t DataReadSize() { return m_ReturnDataOffset; }
|
||||
size_t MaxSize() { return m_MaxPacketSize; }
|
||||
size_t HeaderSize() { return m_HeaderSize; }
|
||||
@@ -64,6 +69,7 @@ private:
|
||||
size_t m_MaxPacketSize = 512;
|
||||
size_t m_HeaderSize = 0;
|
||||
void resizeData();
|
||||
void resizeData(int size);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#define PlayerDefinition_h__
|
||||
#include <string>
|
||||
#include "../Core/Entity.h"
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
struct PlayerDefinition {
|
||||
::EntityID EntityID = EntityID_Invalid;
|
||||
@@ -9,6 +10,10 @@ struct PlayerDefinition {
|
||||
boost::asio::ip::udp::endpoint Endpoint;
|
||||
unsigned int PacketID;
|
||||
std::clock_t StopTime;
|
||||
boost::asio::ip::address TCPAddress;
|
||||
unsigned short TCPPort;
|
||||
// use for tcp connections
|
||||
boost::shared_ptr<boost::asio::ip::tcp::socket> TCPSocket;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include <ctime>
|
||||
|
||||
#include <glm/common.hpp>
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
|
||||
#include "Network/TCPServer.h"
|
||||
#include "Network/UDPServer.h"
|
||||
#include "Network/MessageType.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
#include "Core/World.h"
|
||||
@@ -16,70 +17,80 @@
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "../Game/Events/EDoubleJump.h"
|
||||
#include "Core/EEntityDeleted.h"
|
||||
#include "Core/EComponentDeleted.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
|
||||
class Server : public Network
|
||||
{
|
||||
public:
|
||||
Server();
|
||||
Server(World* world, EventBroker* eventBroker, int port);
|
||||
~Server();
|
||||
void Start(World* m_world, EventBroker *eventBroker) override;
|
||||
void Update() override;
|
||||
private:
|
||||
// UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
// Network channels
|
||||
TCPServer m_Reliable;
|
||||
UDPServer m_Unreliable;
|
||||
UDPServer m_ServerlistRequest;
|
||||
// dont forget to set these in the childrens receive logic
|
||||
boost::asio::ip::address m_Address;
|
||||
int m_Port = 27666;
|
||||
// Sending messages to client logic
|
||||
std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers;
|
||||
std::vector<PlayerID> m_PlayersToDisconnect;
|
||||
// HACK: Fix INPUTSIZE
|
||||
char readBuffer[INPUTSIZE] = { 0 };
|
||||
char readBuffer[BUFFERSIZE] = { 0 };
|
||||
size_t bytesRead = 0;
|
||||
// time for previouse message
|
||||
std::clock_t previousePingMessage = std::clock();
|
||||
std::clock_t previousSnapshotMessage = std::clock();
|
||||
std::clock_t timOutTimer = std::clock();
|
||||
|
||||
// How often we send messages (milliseconds)
|
||||
float pingIntervalMs;
|
||||
float snapshotInterval;
|
||||
int checkTimeOutInterval = 100;
|
||||
int m_NextPlayerID = 0;
|
||||
|
||||
std::vector<Events::InputCommand> m_InputCommandsToBroadcast;
|
||||
//Timers
|
||||
std::clock_t m_StartPingTime;
|
||||
|
||||
// Game logic
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
// Packet loss logic
|
||||
PacketID m_PacketID = 0;
|
||||
PacketID m_PreviousPacketID = 0;
|
||||
|
||||
// Private member functions
|
||||
size_t receive(char* data);
|
||||
void readFromClients();
|
||||
void send(PlayerID player, Packet& packet);
|
||||
void send(Packet& packet);
|
||||
void broadcast(Packet& packet);
|
||||
//int receive(char* data);
|
||||
void reliableBroadcast(Packet& packet);
|
||||
void unreliableBroadcast(Packet& packet);
|
||||
void sendSnapshot();
|
||||
void addPlayersToPacket(Packet& packet, EntityID entityID);
|
||||
void addChildrenToPacket(Packet& packet, EntityID entityID);
|
||||
void addInputCommandsToPacket(Packet& packet);
|
||||
void sendPing();
|
||||
void checkForTimeOuts();
|
||||
void disconnect(PlayerID playerID);
|
||||
void parseMessageType(Packet& packet);
|
||||
void parseOnInputCommand(Packet& packet);
|
||||
void parseOnPlayerDamage(Packet& packet);
|
||||
void parseConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
void identifyPacketLoss();
|
||||
void kick(PlayerID player);
|
||||
PlayerID GetPlayerIDFromEndpoint(boost::asio::ip::udp::endpoint endpoint);
|
||||
// Debug event
|
||||
PlayerID GetPlayerIDFromEndpoint();
|
||||
void parsePlayerTransform(Packet& packet);
|
||||
void parseOnInputCommand(Packet& packet);
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
bool parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseUDPConnect(Packet& packet);
|
||||
void parseTCPConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
void parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint);
|
||||
bool shouldSendToClient(EntityWrapper childEntity);
|
||||
|
||||
// Events
|
||||
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
EventRelay<Server, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
@@ -88,7 +99,10 @@ private:
|
||||
bool OnEntityDeleted(const Events::EntityDeleted& e);
|
||||
EventRelay<Server, Events::ComponentDeleted> m_EComponentDeleted;
|
||||
bool OnComponentDeleted(const Events::ComponentDeleted& e);
|
||||
void parsePlayerTransform(Packet& packet);
|
||||
EventRelay<Server, Events::PlayerDamage> m_EPlayerDamage;
|
||||
bool OnPlayerDamage(const Events::PlayerDamage& e);
|
||||
EventRelay<Server, Events::AmmoPickup> m_EAmmoPickup;
|
||||
bool OnAmmoPickup(const Events::AmmoPickup& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef SnapshotFilter_h__
|
||||
#define SnapshotFilter_h__
|
||||
|
||||
#include "../Core/EntityWrapper.h"
|
||||
#include "../Core/ComponentWrapper.h"
|
||||
|
||||
class SnapshotFilter
|
||||
{
|
||||
public:
|
||||
// Filters an incoming snapshot.
|
||||
// Modify the component and return true if the component snapshot should be applied.
|
||||
// Otherwise return false and it will be ignored.
|
||||
virtual bool FilterComponent(EntityWrapper entity, SharedComponentWrapper& component)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef TCPClient_h__
|
||||
#define TCPClient_h__
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include "NetworkClient.h"
|
||||
|
||||
class TCPClient : public NetworkClient
|
||||
{
|
||||
public:
|
||||
TCPClient();
|
||||
~TCPClient();
|
||||
|
||||
void Connect(std::string playerName, std::string address, int port);
|
||||
void Disconnect();
|
||||
void Receive(Packet& packet);
|
||||
void Send(Packet & packet);
|
||||
bool IsSocketAvailable();
|
||||
private:
|
||||
// Assio TCP logic
|
||||
boost::asio::ip::tcp::endpoint m_Endpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
std::unique_ptr<boost::asio::ip::tcp::socket> m_Socket;
|
||||
size_t readBuffer();
|
||||
PacketID m_SendPacketID = 0;
|
||||
bool m_IsConnected = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef TCPServer_h__
|
||||
#define TCPServer_h__
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <map>
|
||||
#include "NetworkServer.h"
|
||||
|
||||
class TCPServer : public NetworkServer
|
||||
{
|
||||
public:
|
||||
TCPServer();
|
||||
~TCPServer();
|
||||
void AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers);
|
||||
void Receive(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet);
|
||||
void Disconnect();
|
||||
int Port() { return m_Port; }
|
||||
std::string Address() { return m_Address; }
|
||||
|
||||
private:
|
||||
// TCP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
|
||||
boost::shared_ptr<boost::asio::ip::tcp::socket> lastReceivedSocket;
|
||||
|
||||
int readBuffer(PlayerDefinition& playerDefinition);
|
||||
PlayerID getPlayerIDFromEndpoint(const std::map<PlayerID, PlayerDefinition>& connectedPlayers,
|
||||
boost::asio::ip::address address, unsigned short port);
|
||||
int GetPort();
|
||||
std::string GetAddress();
|
||||
int m_Port = 0;
|
||||
std::string m_Address = "";
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef UDPClient_h__
|
||||
#define UDPClient_h__
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include "Network/NetworkClient.h"
|
||||
|
||||
class UDPClient : public NetworkClient
|
||||
{
|
||||
public:
|
||||
UDPClient();
|
||||
~UDPClient();
|
||||
|
||||
void Connect(std::string playerName, std::string address, int port);
|
||||
void Disconnect();
|
||||
void Receive(Packet& packet);
|
||||
void Send(Packet & packet);
|
||||
void Broadcast(Packet& packet, int port);
|
||||
bool IsSocketAvailable();
|
||||
private:
|
||||
// Assio UDP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::shared_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||
int readBuffer();
|
||||
PacketID m_SendPacketID = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef UDPServer_h__
|
||||
#define UDPServer_h__
|
||||
|
||||
#include "NetworkServer.h"
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
|
||||
class UDPServer : public NetworkServer
|
||||
{
|
||||
public:
|
||||
UDPServer();
|
||||
UDPServer(int port);
|
||||
~UDPServer();
|
||||
void AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers);
|
||||
void Receive(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet);
|
||||
void Send(Packet & packet, boost::asio::ip::udp::endpoint endpoint);
|
||||
void Broadcast(Packet & packet, int port);
|
||||
bool IsSocketAvailable();
|
||||
private:
|
||||
// UDP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
std::unique_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||
int readBuffer();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,8 +14,8 @@
|
||||
class AnimationSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
AnimationSystem(World* world, EventBroker* eventBroker)
|
||||
: System(world, eventBroker)
|
||||
AnimationSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("Animation")
|
||||
{
|
||||
|
||||
@@ -23,9 +23,7 @@ public:
|
||||
~AnimationSystem() { }
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) override;
|
||||
private:
|
||||
float angle = 0.f;
|
||||
bool b_forward = false;
|
||||
char bone[100];
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -13,8 +13,8 @@
|
||||
class BoneAttachmentSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
BoneAttachmentSystem(World* world, EventBroker* eventBroker)
|
||||
: System(world, eventBroker)
|
||||
BoneAttachmentSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("BoneAttachment")
|
||||
{
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ public:
|
||||
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||
void SetViewMatrix(glm::mat4 val);
|
||||
|
||||
glm::mat4 BillboardMatrix();
|
||||
|
||||
float AspectRatio() const { return m_AspectRatio; }
|
||||
void SetAspectRatio(float val);
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef CubeMapPass_h__
|
||||
#define CubeMapPass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
class CubeMapPass
|
||||
{
|
||||
public:
|
||||
CubeMapPass(IRenderer* renderer);
|
||||
~CubeMapPass() { }
|
||||
|
||||
void LoadTextures(std::string input);
|
||||
void FillCubeMap(glm::vec3 originPosition);
|
||||
void GenerateCubeMapTexture();
|
||||
|
||||
//GLuint CubeMapTexture() const { return m_CubeMapTexture; }
|
||||
GLuint m_CubeMapTexture = -1;
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
std::string m_PreviusCubeMapTexture;
|
||||
|
||||
std::vector<Texture*> m_CubeMapTextures;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,7 @@
|
||||
class DrawBloomPass
|
||||
{
|
||||
public:
|
||||
DrawBloomPass(IRenderer* renderer /* ,Texture or finalpass*/ );
|
||||
DrawBloomPass(IRenderer* renderer, ConfigFile* config);
|
||||
~DrawBloomPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
@@ -23,24 +23,33 @@ public:
|
||||
void FillGaussianBuffer(FrameBuffer* fb);
|
||||
|
||||
void Draw(GLuint texture);
|
||||
void ChangeQuality(int quality);
|
||||
|
||||
void OnWindowResize();
|
||||
|
||||
//Getters
|
||||
//Return the blurred result of the texture that was sent into draw
|
||||
GLuint GaussianTexture() const { return m_GaussianTexture_vert; }
|
||||
GLuint GaussianTexture() const {
|
||||
if (m_Quality == 0) {
|
||||
return m_BlackTexture->m_Texture;
|
||||
} else {
|
||||
return m_GaussianTexture_vert;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
Texture* m_WhiteTexture;
|
||||
Texture* m_BlackTexture;
|
||||
Model* m_ScreenQuad;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
ConfigFile* m_Config;
|
||||
//const LightCullingPass* m_LightCullingPass
|
||||
GLuint m_iterations = 9;
|
||||
int m_Iterations;
|
||||
int m_Quality = 0;
|
||||
|
||||
GLuint m_GaussianTexture_horiz;
|
||||
GLuint m_GaussianTexture_vert;
|
||||
GLuint m_GaussianTexture_horiz = 0;
|
||||
GLuint m_GaussianTexture_vert = 0;
|
||||
|
||||
FrameBuffer m_GaussianFrameBuffer_horiz;
|
||||
FrameBuffer m_GaussianFrameBuffer_vert;
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(GLuint sceneTexture, GLuint bloomTexture, GLuint sceneTextureLowRes, GLuint bloomTextureLowRes, GLfloat gamma, GLfloat exposure);
|
||||
void Draw(GLuint sceneTexture, GLuint bloomTexture, GLfloat gamma, GLfloat exposure);
|
||||
private:
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
|
||||
@@ -4,41 +4,39 @@
|
||||
#include "IRenderer.h"
|
||||
#include "DrawFinalPassState.h"
|
||||
#include "LightCullingPass.h"
|
||||
#include "CubeMapPass.h"
|
||||
#include "SSAOPass.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
#include "Texture.h"
|
||||
|
||||
class DrawFinalPass
|
||||
{
|
||||
public:
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass);
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass);
|
||||
~DrawFinalPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
void Draw(RenderScene& scene);
|
||||
void ClearBuffer();
|
||||
void OnWindowResize();
|
||||
|
||||
//Return the texture that is used in later stages to apply the bloom effect
|
||||
GLuint BloomTexture() const { return m_BloomTexture; }
|
||||
GLuint BloomTextureLowRes() const { return m_BloomTextureLowRes; }
|
||||
//Return the texture with diffuse and lighting of the scene.
|
||||
GLuint SceneTexture() const { return m_SceneTexture; }
|
||||
GLuint SceneTextureLowRes() const { return m_SceneTextureLowRes; }
|
||||
//Return the framebuffer used in the scene rendering stage.
|
||||
FrameBuffer* FinalPassFrameBuffer() { return &m_FinalPassFrameBuffer; }
|
||||
FrameBuffer* FinalPassFrameBufferLowRes() { return &m_FinalPassFrameBufferLowRes; }
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const;
|
||||
|
||||
void DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, RenderScene& scene);
|
||||
void DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawShieldToStencilBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawShieldedModelRenderQueue(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawToDepthBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
|
||||
void BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene);
|
||||
void BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene);
|
||||
@@ -50,36 +48,50 @@ private:
|
||||
Texture* m_BlackTexture;
|
||||
Texture* m_NeutralNormalTexture;
|
||||
Texture* m_GreyTexture;
|
||||
Texture* m_ErrorTexture;
|
||||
|
||||
FrameBuffer m_FinalPassFrameBuffer;
|
||||
FrameBuffer m_FinalPassFrameBufferLowRes;
|
||||
FrameBuffer m_ShieldDepthFrameBuffer;
|
||||
GLuint m_BloomTexture;
|
||||
GLuint m_SceneTexture;
|
||||
GLuint m_BloomTextureLowRes;
|
||||
GLuint m_SceneTextureLowRes;
|
||||
GLuint m_DepthBuffer;
|
||||
GLuint m_DepthBufferLowRes;
|
||||
GLuint m_ShieldBuffer;
|
||||
GLuint m_CubeMapTexture;
|
||||
|
||||
//maqke this component based i guess?
|
||||
GLuint m_ShieldPixelRate = 16;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
const CubeMapPass* m_CubeMapPass;
|
||||
const SSAOPass* m_SSAOPass;
|
||||
|
||||
ShaderProgram* m_ForwardPlusProgram;
|
||||
ShaderProgram* m_ExplosionEffectProgram;
|
||||
ShaderProgram* m_ExplosionEffectSplatMapProgram;
|
||||
ShaderProgram* m_SpriteProgram;
|
||||
ShaderProgram* m_ForwardPlusSplatMapProgram;
|
||||
ShaderProgram* m_ShieldToStencilProgram;
|
||||
ShaderProgram* m_FillDepthBufferProgram;
|
||||
ShaderProgram* m_FillDepthStencilBufferProgram;
|
||||
|
||||
ShaderProgram* m_ForwardPlusShieldCheckProgram;
|
||||
ShaderProgram* m_ExplosionEffectShieldCheckProgram;
|
||||
ShaderProgram* m_ExplosionEffectSplatMapShieldCheckProgram;
|
||||
ShaderProgram* m_SpriteShieldCheckProgram;
|
||||
ShaderProgram* m_ForwardPlusSplatMapShieldCheckProgram;
|
||||
|
||||
|
||||
|
||||
ShaderProgram* m_ForwardPlusSkinnedProgram;
|
||||
ShaderProgram* m_ExplosionEffectSkinnedProgram;
|
||||
ShaderProgram* m_ExplosionEffectSplatMapSkinnedProgram;
|
||||
ShaderProgram* m_ForwardPlusSplatMapSkinnedProgram;
|
||||
ShaderProgram* m_ShieldToStencilSkinnedProgram;
|
||||
ShaderProgram* m_FillDepthBufferSkinnedProgram;
|
||||
ShaderProgram* m_FillDepthStencilBufferSkinnedProgram;
|
||||
|
||||
ShaderProgram* m_ForwardPlusSkinnedShieldCheckProgram;
|
||||
ShaderProgram* m_ExplosionEffectSkinnedShieldCheckProgram;
|
||||
ShaderProgram* m_ExplosionEffectSplatMapSkinnedShieldCheckProgram;
|
||||
ShaderProgram* m_ForwardPlusSplatMapSkinnedShieldCheckProgram;
|
||||
ShaderProgram* m_FillDepthBufferSkinnedShieldCheckProgram;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
struct ExplosionEffectJob : ModelJob
|
||||
{
|
||||
ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage)
|
||||
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage)
|
||||
ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded)
|
||||
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage, isShielded)
|
||||
{
|
||||
ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"];
|
||||
TimeSinceDeath = (double)explosionEffectComponent["TimeSinceDeath"];
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
#include "../OpenGL.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
#include "Util/ScreenCoords.h"
|
||||
#include "Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Model.h"
|
||||
#include "../Core/World.h" //So temp
|
||||
#include "Util/CommonFunctions.h"
|
||||
|
||||
|
||||
struct PickData
|
||||
@@ -32,6 +34,8 @@ public:
|
||||
virtual void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||
bool VSYNC() const { return m_VSYNC; }
|
||||
virtual void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||
std::string WindowTitle() const { return m_WindowTitle; }
|
||||
virtual void SetWindowTitle(const std::string& title) { glfwSetWindowTitle(m_Window, title.c_str()); m_WindowTitle = title; }
|
||||
//Returns screen size excluding window border and header
|
||||
Rectangle GetViewportSize() const { return m_ViewportSize; }
|
||||
virtual void Initialize() = 0;
|
||||
@@ -47,6 +51,7 @@ protected:
|
||||
int m_GLVersion[2];
|
||||
std::string m_GLVendor;
|
||||
GLFWwindow* m_Window = nullptr;
|
||||
std::string m_WindowTitle;
|
||||
};
|
||||
|
||||
#endif // Renderer_h__
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void SetSSBOSizes();
|
||||
void CullLights(RenderScene& scene);
|
||||
void FillLightList(RenderScene& scene);
|
||||
void OnWindowResize();
|
||||
|
||||
GLuint FrustumSSBO() const { return m_FrustumSSBO; }
|
||||
GLuint LightSSBO() const { return m_LightSSBO; }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define Model_h__
|
||||
|
||||
#include "Rendering/RawModelCustom.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
//#include "Rendering/RawModelAssimp.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "Core/AABB.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
struct ModelJob : RenderJob
|
||||
{
|
||||
ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matProp, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage)
|
||||
ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matProp, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded)
|
||||
: RenderJob()
|
||||
{
|
||||
Model = model;
|
||||
@@ -108,6 +108,7 @@ struct ModelJob : RenderJob
|
||||
EndIndex = matGroup->EndIndex;
|
||||
Matrix = matrix;
|
||||
Color = modelComponent["Color"];
|
||||
GlowIntensity = ((double)modelComponent["GlowIntensity"]);
|
||||
Entity = modelComponent.EntityID;
|
||||
glm::vec3 abspos = Transform::AbsolutePosition(world, modelComponent.EntityID);
|
||||
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
|
||||
@@ -116,34 +117,38 @@ struct ModelJob : RenderJob
|
||||
|
||||
FillColor = fillColor;
|
||||
FillPercentage = fillPercentage;
|
||||
IsShielded = isShielded;
|
||||
|
||||
Skeleton = Model->m_RawModel->m_Skeleton;
|
||||
if (model->IsSkinned()) {
|
||||
Skeleton = Model->m_RawModel->m_Skeleton;
|
||||
|
||||
if (Skeleton != nullptr) {
|
||||
if (world->HasComponent(Entity, "Animation")) {
|
||||
auto animationComponent = world->GetComponent(Entity, "Animation");
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
unsigned int TextureID;
|
||||
@@ -162,13 +167,11 @@ 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;
|
||||
|
||||
|
||||
float AnimationTime = 0.f;
|
||||
|
||||
float GlowIntensity = 8.0;
|
||||
glm::vec4 DiffuseColor;
|
||||
glm::vec4 SpecularColor;
|
||||
glm::vec4 IncandescenceColor;
|
||||
@@ -178,10 +181,10 @@ struct ModelJob : RenderJob
|
||||
|
||||
glm::vec4 FillColor = glm::vec4(0);
|
||||
float FillPercentage = 0.0;
|
||||
|
||||
bool IsShielded;
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID + ModelID << 10 + ShaderID << 20;
|
||||
Hash = ShaderID << 20 + ModelID << 10 + TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
#include <png.h>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Image.h"
|
||||
|
||||
class PNG : public Image
|
||||
class PNG : public Image, public Resource
|
||||
{
|
||||
public:
|
||||
PNG(std::string path);
|
||||
|
||||
@@ -22,25 +22,25 @@ public:
|
||||
void Draw(RenderScene& scene);
|
||||
void ClearPicking();
|
||||
|
||||
void OnWindowResize();
|
||||
|
||||
//Getters
|
||||
const ShaderProgram& PickingProgram() const { return *m_PickingProgram; }
|
||||
//const std::unordered_map<glm::ivec2, EntityID>& PickingColorsToEntity() const { return m_PickingColorsToEntity; }
|
||||
GLuint PickingTexture() const { return m_PickingTexture; }
|
||||
GLuint DepthBuffer() const { return m_DepthBuffer; }
|
||||
GLuint* DepthBuffer() { return &m_DepthBuffer; }
|
||||
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
|
||||
|
||||
|
||||
PickData Pick(glm::vec2 screenCoord);
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
ShaderProgram* m_PickingProgram;
|
||||
ShaderProgram* m_PickingSkinnedProgram;
|
||||
ShaderProgram* m_PickingSkinnedProgram;
|
||||
Camera* m_Camera;
|
||||
|
||||
struct PickingInfo
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
struct TextureProperties {
|
||||
std::string TexturePath;
|
||||
glm::vec2 UVRepeat;
|
||||
std::shared_ptr<::Texture> Texture;
|
||||
Texture* Texture;
|
||||
};
|
||||
|
||||
struct MaterialBasic
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "PointLightJob.h"
|
||||
#include "DirectionalLightJob.h"
|
||||
#include "ExplosionEffectJob.h"
|
||||
#include "SpriteJob.h"
|
||||
|
||||
struct RenderScene
|
||||
{
|
||||
@@ -23,8 +24,8 @@ struct RenderScene
|
||||
std::list<std::shared_ptr<RenderJob>> OpaqueObjects;
|
||||
std::list<std::shared_ptr<RenderJob>> TransparentObjects;
|
||||
std::list<std::shared_ptr<RenderJob>> OpaqueShieldedObjects;
|
||||
std::list<std::shared_ptr<RenderJob>> TransparentShieldedObjects;
|
||||
std::list<std::shared_ptr<RenderJob>> ShieldObjects;
|
||||
std::list<std::shared_ptr<RenderJob>> SpriteJob;
|
||||
std::list<std::shared_ptr<RenderJob>> PointLight;
|
||||
std::list<std::shared_ptr<RenderJob>> Text;
|
||||
std::list<std::shared_ptr<RenderJob>> DirectionalLight;
|
||||
@@ -39,9 +40,8 @@ struct RenderScene
|
||||
Jobs.OpaqueObjects.clear();
|
||||
Jobs.TransparentObjects.clear();
|
||||
Jobs.OpaqueShieldedObjects.clear();
|
||||
Jobs.TransparentShieldedObjects.clear();
|
||||
Jobs.ShieldObjects.clear();
|
||||
Jobs.Text.clear();
|
||||
Jobs.SpriteJob.clear();
|
||||
Jobs.DirectionalLight.clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
bool StencilFunc(GLenum func, GLint ref, GLuint mask);
|
||||
bool StencilMask(GLuint mask);
|
||||
bool DepthMask(GLboolean flag);
|
||||
bool DepthFunc(GLenum func);
|
||||
bool AlphaFunc(GLenum func, GLclampf thresholder);
|
||||
|
||||
private:
|
||||
std::vector<std::function<void(void)>> m_ResetFunctions;
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
#include "../Core/EPlayerSpawned.h"
|
||||
#include "../Core/Octree.h"
|
||||
#include "../Collision/EntityAABB.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
|
||||
class RenderSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame, Octree<EntityAABB>* frustumCullOctree);
|
||||
RenderSystem(SystemParams params, const IRenderer* renderer, RenderFrame* renderFrame, Octree<EntityAABB>* frustumCullOctree);
|
||||
~RenderSystem();
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
@@ -31,7 +32,6 @@ private:
|
||||
const IRenderer* m_Renderer;
|
||||
RenderFrame* m_RenderFrame;
|
||||
Camera* m_Camera;
|
||||
World* m_World;
|
||||
EntityWrapper m_CurrentCamera = EntityWrapper::Invalid;
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
|
||||
Octree<EntityAABB>* m_Octree;
|
||||
@@ -48,6 +48,10 @@ private:
|
||||
void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -16,18 +16,25 @@
|
||||
#include "DrawScreenQuadPass.h"
|
||||
#include "DrawBloomPass.h"
|
||||
#include "DrawColorCorrectionPass.h"
|
||||
#include "SSAOPass.h"
|
||||
#include "CubeMapPass.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "ImGuiRenderPass.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "TextPass.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
#include "Core/PerformanceTimer.h"
|
||||
|
||||
class Renderer : public IRenderer
|
||||
{
|
||||
static void glfwFrameBufferCallback(GLFWwindow* window, int width, int height);
|
||||
|
||||
public:
|
||||
Renderer(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
Renderer(EventBroker* eventBroker, ConfigFile* config)
|
||||
: m_EventBroker(eventBroker)
|
||||
, m_Config(config)
|
||||
{ }
|
||||
|
||||
virtual void Initialize() override;
|
||||
@@ -36,8 +43,13 @@ public:
|
||||
|
||||
virtual PickData Pick(glm::vec2 screenCoord) override;
|
||||
|
||||
|
||||
private:
|
||||
//----------------------Variables----------------------//
|
||||
|
||||
static std::unordered_map <GLFWwindow*, Renderer*> m_WindowToRenderer;
|
||||
ConfigFile* m_Config;
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
TextPass* m_TextPass;
|
||||
|
||||
@@ -49,6 +61,10 @@ private:
|
||||
Model* m_UnitSphere;
|
||||
|
||||
int m_DebugTextureToDraw = 0;
|
||||
int m_CubeMapTexture = 0;
|
||||
bool m_ResizeWindow = false;
|
||||
int m_SSAO_Quality = 0;
|
||||
int m_GLOW_Quality = 2;
|
||||
|
||||
PickingPass* m_PickingPass;
|
||||
LightCullingPass* m_LightCullingPass;
|
||||
@@ -57,6 +73,8 @@ private:
|
||||
DrawScreenQuadPass* m_DrawScreenQuadPass;
|
||||
DrawBloomPass* m_DrawBloomPass;
|
||||
DrawColorCorrectionPass* m_DrawColorCorrectionPass;
|
||||
SSAOPass* m_SSAOPass;
|
||||
CubeMapPass* m_CubeMapPass;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef SSAOPass_h__
|
||||
#define SSAOPass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "SSAOPassState.h"
|
||||
//#include "LightCullingPass.h" Finalpass om den skall skickas in
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "DrawBloomPass.h"
|
||||
//#include "Util/UnorderedMapVec2.h"
|
||||
#include "Texture.h"
|
||||
|
||||
class SSAOPass
|
||||
{
|
||||
public:
|
||||
SSAOPass(IRenderer* renderer, ConfigFile* config);
|
||||
~SSAOPass() { };
|
||||
|
||||
void ChangeQuality(int quality);
|
||||
|
||||
void Draw(GLuint depthBuffer, Camera* camera);
|
||||
void Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int numOfTurns, int iterations, int quality);
|
||||
void ClearBuffer();
|
||||
void OnWindowResize();
|
||||
|
||||
//Return the SSAO of the texture sent to Draw
|
||||
GLuint SSAOTexture() const {
|
||||
if (m_Quality == 0) {
|
||||
return m_WhiteTexture->m_Texture;
|
||||
} else {
|
||||
return m_Gaussian_vert;
|
||||
}
|
||||
}
|
||||
|
||||
int TextureQuality() const {
|
||||
if (m_Quality == 0) {
|
||||
return 13;
|
||||
} else {
|
||||
return m_TextureQuality;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void InitializeTexture();
|
||||
void InitializeFrameBuffer();
|
||||
void InitializeShaderProgram();
|
||||
void InitializeBuffer();
|
||||
|
||||
//void blurHorizontal(GLuint depthBuffer);
|
||||
//void blurVertical(GLuint depthBuffer);
|
||||
|
||||
Model* m_ScreenQuad;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
ConfigFile* m_Config;
|
||||
|
||||
float m_Radius;
|
||||
float m_Bias;
|
||||
float m_Contrast;
|
||||
float m_IntensityScale;
|
||||
int m_NumOfSamples;
|
||||
int m_NumOfTurns;
|
||||
int m_Iterations;
|
||||
int m_TextureQuality;
|
||||
int m_Quality = 0;
|
||||
|
||||
Texture* m_WhiteTexture;
|
||||
|
||||
GLuint m_SSAOTexture = 0;
|
||||
FrameBuffer m_SSAOFramBuffer;
|
||||
|
||||
GLuint m_SSAOViewSpaceZTexture = 0;
|
||||
FrameBuffer m_SSAOViewSpaceZFramBuffer;
|
||||
|
||||
GLuint m_Gaussian_horiz = 0;
|
||||
GLuint m_Gaussian_vert = 0;
|
||||
|
||||
FrameBuffer m_GaussianFrameBuffer_horiz;
|
||||
FrameBuffer m_GaussianFrameBuffer_vert;
|
||||
|
||||
ShaderProgram* m_SSAOProgram;
|
||||
ShaderProgram* m_SSAOViewSpaceZProgram;
|
||||
ShaderProgram* m_GaussianProgram_horiz;
|
||||
ShaderProgram* m_GaussianProgram_vert;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef SSAOPassState_h__
|
||||
#define SSAOPassState_h__
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class SSAOPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
SSAOPassState();
|
||||
~SSAOPassState();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -100,19 +100,21 @@ public:
|
||||
|
||||
int GetBoneID(std::string name);
|
||||
|
||||
const Animation* GetAnimation(std::string name);
|
||||
std::vector<glm::mat4> GetFrameBones(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, AnimationOffset animationOffset, bool noRootMotion = false);
|
||||
std::vector<glm::mat4> GetFrameBones(std::vector<AnimationData> animations, bool noRootMotion = false);
|
||||
|
||||
//void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, float time, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, AnimationOffset animationOffset, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
const Animation* GetAnimation(std::string name);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
@@ -120,7 +122,7 @@ private:
|
||||
glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset);
|
||||
|
||||
std::map<std::string, Bone*> m_BonesByName;
|
||||
float aim = 0.f;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef SpriteJob_h__
|
||||
#define SpriteJob_h__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ComponentWrapper.h"
|
||||
#include "Texture.h"
|
||||
#include "Model.h"
|
||||
#include "RenderJob.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/World.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "Skeleton.h"
|
||||
|
||||
struct SpriteJob : RenderJob
|
||||
{
|
||||
SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage, bool depthSorted, bool isIndicator)
|
||||
: RenderJob()
|
||||
{
|
||||
Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh");
|
||||
::RawModel::MaterialProperties matProp = Model->MaterialGroups().front();
|
||||
TextureID = 0;
|
||||
|
||||
DiffuseTexture = CommonFunctions::LoadTexture(cSprite["DiffuseTexture"], true);
|
||||
|
||||
IncandescenceTexture = CommonFunctions::LoadTexture(cSprite["GlowMap"], true);
|
||||
|
||||
StartIndex = matProp.material->StartIndex;
|
||||
EndIndex = matProp.material->EndIndex;
|
||||
Matrix = matrix;
|
||||
Color = cSprite["Color"];
|
||||
Entity = cSprite.EntityID;
|
||||
Position = Transform::AbsolutePosition(world, cSprite.EntityID);
|
||||
Depth = 0;
|
||||
if (depthSorted) {
|
||||
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
|
||||
Depth = viewpos.z;
|
||||
}
|
||||
World = world;
|
||||
Pickable = world->HasComponent(cSprite.EntityID, "Button");
|
||||
IsIndicator = isIndicator;
|
||||
|
||||
FillColor = fillColor;
|
||||
FillPercentage = fillPercentage;
|
||||
};
|
||||
|
||||
unsigned int TextureID;
|
||||
|
||||
EntityID Entity;
|
||||
glm::mat4 Matrix;
|
||||
const Texture* DiffuseTexture;
|
||||
const Texture* NormalTexture;
|
||||
const Texture* SpecularTexture;
|
||||
const Texture* IncandescenceTexture;
|
||||
float Shininess = 0.f;
|
||||
glm::vec4 Color;
|
||||
glm::vec3 Position;
|
||||
const ::Model* Model = nullptr;
|
||||
unsigned int StartIndex = 0;
|
||||
unsigned int EndIndex = 0;
|
||||
World* World;
|
||||
|
||||
bool Pickable;
|
||||
bool IsIndicator = false;
|
||||
|
||||
glm::vec4 FillColor = glm::vec4(0);
|
||||
float FillPercentage = 0.0;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
unsigned char* Data = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
#include "../../Common.h"
|
||||
#include "../../OpenGL.h"
|
||||
#include "../../GLM.h"
|
||||
#include "../Texture.h"
|
||||
|
||||
class CommonFuntions
|
||||
{
|
||||
public:
|
||||
CommonFuntions() = delete;
|
||||
|
||||
private:
|
||||
|
||||
namespace CommonFunctions
|
||||
{
|
||||
Texture* LoadTexture(std::string path, bool threaded);
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||
void GenerateMultiSampleTexture(GLuint* texture, int numSamples, glm::vec2 dimensions, GLint internalFormat);
|
||||
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps);
|
||||
void DeleteTexture(GLuint* texture);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,11 +2,15 @@
|
||||
#define Events_DashAbility_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct DashAbility : public Event { };
|
||||
struct DashAbility : public Event
|
||||
{
|
||||
EntityID Player;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Events
|
||||
|
||||
struct DoubleJump : public Event
|
||||
{
|
||||
|
||||
EntityID entityID;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
class ExplosionEffectSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
ExplosionEffectSystem(World* world, EventBroker* eventBroker)
|
||||
: System(world, eventBroker)
|
||||
, PureSystem("ExplosionEffect")
|
||||
{ }
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override
|
||||
{
|
||||
|
||||
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) {
|
||||
(double)component["TimeSinceDeath"] = 0.f;
|
||||
}
|
||||
(double&)component["TimeSinceDeath"] += dt;
|
||||
|
||||
//if ((bool)Component["Gravity"] == true) {
|
||||
// (bool)Component["ExponentialAccelaration"] = false;
|
||||
//}
|
||||
}
|
||||
};
|
||||
+18
-22
@@ -1,24 +1,25 @@
|
||||
#ifndef Game_h__
|
||||
#define Game_h__
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Rendering/Renderer.h"
|
||||
#include "Core/InputManager.h"
|
||||
#include "GUI/Frame.h"
|
||||
#include "Core/World.h"
|
||||
#include "Input/InputProxy.h"
|
||||
#include "Input/KeyboardInputHandler.h"
|
||||
#include "Input/MouseInputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EntityFilePreprocessor.h"
|
||||
#include "Core/EntityXMLFilePreprocessor.h"
|
||||
#include "Core/SystemPipeline.h"
|
||||
#include "ExplosionEffectSystem.h"
|
||||
#include "Systems/ExplosionEffectSystem.h"
|
||||
#include "Editor/EditorSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EntityXMLFile.h"
|
||||
#include "Rendering/RenderSystem.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Core/EntityXMLFileParser.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Rendering/Font.h"
|
||||
#include "Systems/InterpolationSystem.h"
|
||||
@@ -33,6 +34,9 @@
|
||||
#include "Sound/SoundManager.h"
|
||||
#include "Systems/SoundSystem.h"
|
||||
|
||||
//Performance
|
||||
#include "Core/PerformanceTimer.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
@@ -43,37 +47,29 @@ public:
|
||||
void Tick();
|
||||
|
||||
private:
|
||||
double m_LastTime;
|
||||
std::string m_NetworkAddress;
|
||||
int m_NetworkPort = 0;
|
||||
|
||||
ConfigFile* m_Config = nullptr;
|
||||
EventBroker* m_EventBroker;
|
||||
IRenderer* m_Renderer;
|
||||
InputManager* m_InputManager;
|
||||
InputProxy* m_InputProxy;
|
||||
GUI::Frame* m_FrameStack;
|
||||
World* m_World;
|
||||
Octree<EntityAABB>* m_OctreeCollision;
|
||||
Octree<EntityAABB>* m_OctreeTrigger;
|
||||
Octree<EntityAABB>* m_OctreeFrustrumCulling;
|
||||
SystemPipeline* m_SystemPipeline;
|
||||
RenderFrame* m_RenderFrame;
|
||||
// Network variables
|
||||
boost::thread m_NetworkThread;
|
||||
|
||||
// Network methods
|
||||
void networkFunction();
|
||||
Network* m_ClientOrServer;
|
||||
bool m_IsClientOrServer = false;
|
||||
|
||||
// Sound
|
||||
Client* m_NetworkClient = nullptr;
|
||||
Server* m_NetworkServer = nullptr;
|
||||
SoundManager* m_SoundManager;
|
||||
double m_LastTime;
|
||||
|
||||
//EventRelay<Game, Events::InputCommand> m_EInputCommand;
|
||||
//bool debugOnInputCommand(const Events::InputCommand& e);
|
||||
|
||||
void debugInitialize();
|
||||
void debugTick(double dt);
|
||||
EventRelay<Client, Events::KeyDown> m_EKeyDown;
|
||||
bool m_IsClient = false;
|
||||
bool m_IsServer = false;
|
||||
|
||||
int parseArgs(int argc, char* argv[]);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef MiniDump_h__
|
||||
#define MiniDump_h__
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
void WINAPI Create_Dump(PEXCEPTION_POINTERS pException, BOOL File_Flag, BOOL Show_Flag);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef MultiplayerSnapshotFilter_h__
|
||||
#define MultiplayerSnapshotFilter_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Network/SnapshotFilter.h"
|
||||
#include "Network/EInterpolate.h"
|
||||
|
||||
class MultiplayerSnapshotFilter : public SnapshotFilter
|
||||
{
|
||||
public:
|
||||
MultiplayerSnapshotFilter(EventBroker* eventBroker);
|
||||
|
||||
virtual bool FilterComponent(EntityWrapper entity, SharedComponentWrapper& component) override;
|
||||
|
||||
private:
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
|
||||
|
||||
EventRelay<MultiplayerSnapshotFilter, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned ePlayerSpawned);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef AbilityCooldownHUDSystem_h__
|
||||
#define AbilityCooldownHUDSystem_h__
|
||||
|
||||
#include "../../Engine/Core/System.h"
|
||||
#include "../../Engine/GLM.h"
|
||||
|
||||
class AbilityCooldownHUDSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
AbilityCooldownHUDSystem(SystemParams params)
|
||||
: System(params)
|
||||
{ }
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef AmmoPickupSystem_h__
|
||||
#define AmmoPickupSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EPickupSpawned.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Engine/Collision/ETrigger.h"
|
||||
#include "Common.h"
|
||||
|
||||
class AmmoPickupSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
AmmoPickupSystem(SystemParams params);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
EventRelay<AmmoPickupSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||
bool OnTriggerTouch(Events::TriggerTouch& e);
|
||||
EventRelay<AmmoPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
|
||||
bool OnTriggerLeave(Events::TriggerLeave& e);
|
||||
|
||||
EventRelay<AmmoPickupSystem, Events::AmmoPickup> m_EAmmoPickup;
|
||||
bool OnAmmoPickup(Events::AmmoPickup& e);
|
||||
|
||||
struct NewAmmoPickup {
|
||||
glm::vec3 Pos;
|
||||
double AmmoGain;
|
||||
double RespawnTimer;
|
||||
double DecreaseThisRespawnTimer;
|
||||
EntityID parentID;
|
||||
};
|
||||
std::vector<NewAmmoPickup> m_ETriggerTouchVector;
|
||||
struct EntityAtMaxValuePickupStruct {
|
||||
EntityWrapper player;
|
||||
EntityWrapper trigger;
|
||||
};
|
||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef AmmunitionHUDSystem_h__
|
||||
#define AmmunitionHUDSystem_h__
|
||||
|
||||
#include "../../Engine/Core/System.h"
|
||||
#include "../../Engine/GLM.h"
|
||||
|
||||
class AmmunitionHUDSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
AmmunitionHUDSystem(SystemParams params)
|
||||
: System(params)
|
||||
{ }
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef BoostIconsHUDSystem_h__
|
||||
#define BoostIconsHUDSystem_h__
|
||||
|
||||
#include "../../Engine/Core/System.h"
|
||||
#include "../../Engine/GLM.h"
|
||||
|
||||
class BoostIconsHUDSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
BoostIconsHUDSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("BoostIconsHUD")
|
||||
{ }
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef BoostSystem_h__
|
||||
#define BoostSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Common.h"
|
||||
|
||||
class BoostSystem : public System
|
||||
{
|
||||
public:
|
||||
BoostSystem(SystemParams params);
|
||||
|
||||
private:
|
||||
EventRelay<BoostSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||
bool OnPlayerDamage(Events::PlayerDamage& e);
|
||||
|
||||
std::string DetermineClass(EntityWrapper player);
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef CapturePointArrowHUDSystem_h__
|
||||
#define CapturePointArrowHUDSystem_h__
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/ECaptured.h"
|
||||
|
||||
|
||||
class CapturePointArrowHUDSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
CapturePointArrowHUDSystem(SystemParams params);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
EventRelay<CapturePointArrowHUDSystem, Events::Captured> m_ECapturedEvent;
|
||||
bool OnCapturePointCaptured(Events::Captured& e);
|
||||
|
||||
bool m_InitialtargetsSet = false;
|
||||
glm::vec3 m_RedTeamCurrentTarget;
|
||||
glm::vec3 m_BlueTeamCurrentTarget;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef CapturePointHUDSystem_h__
|
||||
#define CapturePointHUDSystem_h__
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Collision/ETrigger.h"
|
||||
|
||||
class CapturePointHUDSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
CapturePointHUDSystem(SystemParams params);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user