Compare commits

..

1 Commits

Author SHA1 Message Date
Jace 0516794db6 Separating RawModel from Model 2016-03-13 14:47:11 +01:00
38 changed files with 4905 additions and 5067 deletions
+1 -1
Submodule assets updated: 504752c949...bc6e7df04c
+6 -6
View File
@@ -48,13 +48,13 @@ bool RayVsTriangle(const Ray& ray,
bool trueOnNegativeDistance = false); bool trueOnNegativeDistance = false);
//Return true if the ray hits any of the triangles in the model. Stops checking when a hit is detected. //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, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix); const glm::mat4& modelMatrix);
//Return true if the ray hits any of the triangles in the model. //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. //Also returns the position of the intersection point. Will loop through all the whole model indices.
bool RayVsModel(const Ray& ray, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
glm::vec3& outHitPosition); glm::vec3& outHitPosition);
@@ -62,7 +62,7 @@ bool RayVsModel(const Ray& ray,
//Also returns the distance from the ray origin to the closest //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. //intersection point, and the barycentric u,v-coordinates. Will loop through all the whole model indices.
bool RayVsModel(const Ray& ray, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
float& outDistance, float& outDistance,
@@ -70,7 +70,7 @@ bool RayVsModel(const Ray& ray,
float& outVCoord); float& outVCoord);
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
glm::vec3& boxVelocity, glm::vec3& boxVelocity,
@@ -80,7 +80,7 @@ bool AABBvsTriangles(const AABB& box,
//Detects collision, but does not resolve. //Detects collision, but does not resolve.
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix); const glm::mat4& modelMatrix);
@@ -92,7 +92,7 @@ enum Output
}; };
//Detects intersection and containment. //Detects intersection and containment.
Output AABBvsTrianglesWContainment(const AABB& box, Output AABBvsTrianglesWContainment(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix); const glm::mat4& modelMatrix);
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef Events_Captured_h__ #ifndef ECaptured_h__
#define Events_Captured_h__ #define ECaptured_h__
#include "EventBroker.h" #include "EventBroker.h"
#include "../Core/Entity.h" #include "../Core/Entity.h"
+22 -26
View File
@@ -10,32 +10,28 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
#include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h"
#include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Core/EPlayerDamage.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Game/Events/EDoubleJump.h"
#include "Game/Events/EDashAbility.h"
#include "Game/Events/EReset.h"
#include "Input/EInputCommand.h"
#include "imgui/imgui.h"
#include "Network/Network.h" #include "Network/Network.h"
#include "Network/MessageType.h" #include "Network/MessageType.h"
#include "Network/PlayerDefinition.h" #include "Network/PlayerDefinition.h"
#include "Network/UDPClient.h" #include "Network/UDPClient.h"
#include "Network/TCPClient.h" #include "Network/TCPClient.h"
#include "Network/SnapshotDefinitions.h" #include "Network/SnapshotDefinitions.h"
#include "Network/EDisplayServerlist.h" #include "Core/World.h"
#include "Network/EConnectRequest.h" #include "Core/EntityFile.h"
#include "Network/EPlayerDisconnected.h" #include "Core/EventBroker.h"
#include "Network/ESearchForServers.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/EInterpolate.h"
#include "Network/SnapshotFilter.h" #include "Network/SnapshotFilter.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Network/ESearchForServers.h"
#include "../Game/Events/EDashAbility.h"
#include "Network/EDisplayServerlist.h"
#include "Network/EConnectRequest.h"
class Client : public Network class Client : public Network
{ {
public: public:
@@ -44,7 +40,7 @@ public:
~Client(); ~Client();
void Connect(std::string address, int port); void Connect(std::string address, int port);
void Update(double dt) override; void Update() override;
private: private:
UDPClient m_Unreliable; UDPClient m_Unreliable;
TCPClient m_Reliable; TCPClient m_Reliable;
@@ -78,10 +74,10 @@ private:
// Network logic // Network logic
PlayerDefinition m_PlayerDefinitions[8]; PlayerDefinition m_PlayerDefinitions[8];
SnapshotDefinitions m_NextSnapshot; SnapshotDefinitions m_NextSnapshot;
double m_DurationOfPingTime = 0; double m_DurationOfPingTime;
double m_StartPingTime = 0; std::clock_t m_StartPingTime;
double m_TimeSinceSentInputs = 0; std::clock_t m_TimeSinceSentInputs;
double m_SendInputInterval = 0.033; unsigned int m_SendInputIntervalMs;
std::vector<Events::InputCommand> m_InputCommandBuffer; std::vector<Events::InputCommand> m_InputCommandBuffer;
// Private member functions // Private member functions
@@ -104,7 +100,6 @@ private:
void parseDoubleJump(Packet& packet); void parseDoubleJump(Packet& packet);
void parseDashEffect(Packet& packet); void parseDashEffect(Packet& packet);
void parseAmmoPickup(Packet& packet); void parseAmmoPickup(Packet& packet);
void parseRemoveWorld(Packet& packet);
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
void parseSnapshot(Packet& packet); void parseSnapshot(Packet& packet);
void identifyPacketLoss(); void identifyPacketLoss();
@@ -114,6 +109,7 @@ private:
void sendLocalPlayerTransform(); void sendLocalPlayerTransform();
void becomePlayer(); void becomePlayer();
void displayServerlist(); void displayServerlist();
void removeWorld();
void createMainMenu(); void createMainMenu();
// Mapping Logic // Mapping Logic
// Returns if local EntityID exist in map // Returns if local EntityID exist in map
@@ -142,8 +138,8 @@ private:
UDPClient m_ServerlistRequest; UDPClient m_ServerlistRequest;
std::vector<ServerInfo> m_Serverlist; std::vector<ServerInfo> m_Serverlist;
bool m_SearchingForServers = false; bool m_SearchingForServers = false;
double m_TimeSearched = 0; std::clock_t m_StartSearchTime;
double m_SearchingTime = 0.2; // Config I guess double m_SearchingTime = 200; // Config I guess
}; };
#endif #endif
-1
View File
@@ -23,7 +23,6 @@ enum class MessageType
OnDashEffect, OnDashEffect,
ServerlistRequest, ServerlistRequest,
AmmoPickup, AmmoPickup,
RemoveWorld,
Invalid Invalid
}; };
+1 -2
View File
@@ -22,7 +22,7 @@ public:
Network(World* world, EventBroker* eventBroker); Network(World* world, EventBroker* eventBroker);
virtual ~Network() { }; virtual ~Network() { };
virtual void Update(double dt) = 0; virtual void Update() = 0;
protected: protected:
World* m_World; World* m_World;
@@ -40,7 +40,6 @@ protected:
void saveToFile(); void saveToFile();
void updateNetworkData(); void updateNetworkData();
void popNetworkSegmentOfHeader(Packet& packet); void popNetworkSegmentOfHeader(Packet& packet);
void removeWorld();
}; };
#endif #endif
+8 -16
View File
@@ -11,7 +11,6 @@
#include "Network/MessageType.h" #include "Network/MessageType.h"
#include "Network/PlayerDefinition.h" #include "Network/PlayerDefinition.h"
#include "Core/World.h" #include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "../Network/Network.h" #include "../Network/Network.h"
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
@@ -25,8 +24,6 @@
#include "Core/EPlayerDeath.h" #include "Core/EPlayerDeath.h"
#include "Network/EPlayerConnected.h" #include "Network/EPlayerConnected.h"
#include "Network/EKillDeath.h" #include "Network/EKillDeath.h"
#include "Core/EWin.h"
#include "Game/Events/EReset.h"
class Server : public Network class Server : public Network
{ {
@@ -34,7 +31,7 @@ public:
Server(World* world, EventBroker* eventBroker, int port); Server(World* world, EventBroker* eventBroker, int port);
~Server(); ~Server();
void Update(double dt) override; void Update() override;
private: private:
// Network channels // Network channels
@@ -44,7 +41,6 @@ private:
// dont forget to set these in the childrens receive logic // dont forget to set these in the childrens receive logic
boost::asio::ip::address m_Address; boost::asio::ip::address m_Address;
int m_Port = 27666; int m_Port = 27666;
bool m_GameIsOver = false;
// Sending messages to client logic // Sending messages to client logic
std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers; std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers;
std::vector<PlayerID> m_PlayersToDisconnect; std::vector<PlayerID> m_PlayersToDisconnect;
@@ -52,14 +48,14 @@ private:
char readBuffer[BUFFERSIZE] = { 0 }; char readBuffer[BUFFERSIZE] = { 0 };
size_t bytesRead = 0; size_t bytesRead = 0;
// time for previouse message // time for previouse message
double previousPingMessage = 0; std::clock_t previousePingMessage = std::clock();
double previousSnapshotMessage = 0; std::clock_t previousSnapshotMessage = std::clock();
double timeOutTimer = 0; std::clock_t timOutTimer = std::clock();
// How often we send messages (seconds) // How often we send messages (milliseconds)
double pingInterval = 1; float pingIntervalMs;
double snapshotInterval = 0.05; float snapshotInterval;
double checkTimeOutInterval = 0.1; int checkTimeOutInterval = 100;
int m_NextPlayerID = 0; int m_NextPlayerID = 0;
std::vector<Events::InputCommand> m_InputCommandsToBroadcast; std::vector<Events::InputCommand> m_InputCommandsToBroadcast;
//Timers //Timers
@@ -75,7 +71,6 @@ private:
void reliableBroadcast(Packet& packet); void reliableBroadcast(Packet& packet);
void unreliableBroadcast(Packet& packet); void unreliableBroadcast(Packet& packet);
void sendSnapshot(); void sendSnapshot();
void createWorldSnapshot(Packet& packet);
void addPlayersToPacket(Packet& packet, EntityID entityID); void addPlayersToPacket(Packet& packet, EntityID entityID);
void addChildrenToPacket(Packet& packet, EntityID entityID); void addChildrenToPacket(Packet& packet, EntityID entityID);
void addInputCommandsToPacket(Packet& packet); void addInputCommandsToPacket(Packet& packet);
@@ -88,7 +83,6 @@ private:
void kick(PlayerID player); void kick(PlayerID player);
PlayerID getPlayerIDFromEndpoint(); PlayerID getPlayerIDFromEndpoint();
PlayerID getPlayerIDFromEntityID(EntityID entityID); PlayerID getPlayerIDFromEntityID(EntityID entityID);
void resetMap();
void parsePlayerTransform(Packet& packet); void parsePlayerTransform(Packet& packet);
void parseOnInputCommand(Packet& packet); void parseOnInputCommand(Packet& packet);
void parseClientPing(); void parseClientPing();
@@ -116,8 +110,6 @@ private:
bool OnAmmoPickup(const Events::AmmoPickup& e); bool OnAmmoPickup(const Events::AmmoPickup& e);
EventRelay<Server, Events::PlayerDeath> m_EPlayerDeath; EventRelay<Server, Events::PlayerDeath> m_EPlayerDeath;
bool OnPlayerDeath(const Events::PlayerDeath& e); bool OnPlayerDeath(const Events::PlayerDeath& e);
EventRelay<Server, Events::Win> m_EWin;
bool OnWin(const Events::Win& e);
}; };
#endif #endif
+12 -6
View File
@@ -16,15 +16,18 @@ private:
public: public:
~Model(); ~Model();
const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_RawModel->m_Materials; } const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_Materials; }
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; } //const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); } unsigned int NumberOfVertices() const { return m_Vertices.size(); }
unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); }
const AABB& Box() const { return m_Box; } const AABB& Box() const { return m_Box; }
bool IsSkinned() const { return m_RawModel->IsSkinned(); } bool IsSkinned() const { return m_IsSkinned; }
GLuint VAO; GLuint VAO;
GLuint ElementBuffer; GLuint ElementBuffer;
RawModel* m_RawModel; //RawModel* m_RawModel;
Skeleton* m_Skeleton = nullptr;
std::vector<glm::vec3> m_Vertices;
std::vector<unsigned int> m_Indices;
private: private:
AABB m_Box; AABB m_Box;
@@ -34,6 +37,9 @@ private:
GLuint TangentNormalsBuffer; GLuint TangentNormalsBuffer;
GLuint BiTangentNormalsBuffer; GLuint BiTangentNormalsBuffer;
GLuint TextureCoordBuffer; GLuint TextureCoordBuffer;
std::vector<RawModel::MaterialProperties> m_Materials;
bool m_IsSkinned;
}; };
#endif #endif
+1 -1
View File
@@ -105,7 +105,7 @@ struct ModelJob : RenderJob
IsShielded = isShielded; IsShielded = isShielded;
if (model->IsSkinned()) { if (model->IsSkinned()) {
Skeleton = Model->m_RawModel->m_Skeleton; Skeleton = Model->m_Skeleton;
if (Skeleton != nullptr) { if (Skeleton != nullptr) {
+2 -5
View File
@@ -13,6 +13,7 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/endian/buffers.hpp>
#include "../Common.h" #include "../Common.h"
#include "../GLM.h" #include "../GLM.h"
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
@@ -20,14 +21,10 @@
#include "Skeleton.h" #include "Skeleton.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "boost\endian\buffers.hpp"
class RawModelCustom : public Resource class RawModelCustom : public Resource
{ {
friend class ResourceManager; friend class ResourceManager;
friend class Model;
protected: protected:
RawModelCustom(std::string fileName); RawModelCustom(std::string fileName);
-16
View File
@@ -1,16 +0,0 @@
#ifndef Events_Reset_h__
#define Events_Reset_h__
#include "Core/EventBroker.h"
#include "Core/EntityWrapper.h"
namespace Events
{
struct Reset : Event
{
};
}
#endif
@@ -9,7 +9,6 @@
#include "Engine/Collision/ETrigger.h" #include "Engine/Collision/ETrigger.h"
#include "Core/ECaptured.h" #include "Core/ECaptured.h"
#include "Core/EWin.h" #include "Core/EWin.h"
#include "Game/Events/EReset.h"
#include <tuple> #include <tuple>
#include <vector> #include <vector>
@@ -24,7 +23,6 @@ public:
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override;
private: private:
void Init();
//methods which will take care of specific events //methods which will take care of specific events
EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch; EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch;
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e);
@@ -32,8 +30,6 @@ private:
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured; EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e); bool CapturePointSystem::OnCaptured(const Events::Captured& e);
EventRelay<CapturePointSystem, Events::Reset> m_EReset;
bool CapturePointSystem::OnReset(const Events::Reset& e);
void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner); void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner);
bool m_WinnerWasFound = false; bool m_WinnerWasFound = false;
-6
View File
@@ -8,8 +8,6 @@
#include "Core/EPlayerSpawned.h" #include "Core/EPlayerSpawned.h"
#include "Network/EPlayerConnected.h" #include "Network/EPlayerConnected.h"
#include "Network/EPlayerDisconnected.h" #include "Network/EPlayerDisconnected.h"
#include "Game/Events/EReset.h"
#include "Engine/Input/EInputCommand.h"
#include "GLM.h" #include "GLM.h"
class ScoreScreenSystem : public PureSystem class ScoreScreenSystem : public PureSystem
@@ -27,10 +25,6 @@ public:
bool OnPlayerConnected(const Events::PlayerConnected& e); bool OnPlayerConnected(const Events::PlayerConnected& e);
EventRelay<ScoreScreenSystem, Events::PlayerDisconnected> m_EPlayerDisconnected; EventRelay<ScoreScreenSystem, Events::PlayerDisconnected> m_EPlayerDisconnected;
bool OnPlayerDisconnected(const Events::PlayerDisconnected& e); bool OnPlayerDisconnected(const Events::PlayerDisconnected& e);
EventRelay<ScoreScreenSystem, Events::Reset> m_EReset;
bool OnReset(const Events::Reset& e);
EventRelay<ScoreScreenSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
private: private:
struct PlayerData { struct PlayerData {
+1
View File
@@ -8,6 +8,7 @@
#include "Events/ESpawnerSpawn.h" #include "Events/ESpawnerSpawn.h"
#include "Core/TransformSystem.h" #include "Core/TransformSystem.h"
#include "Core/EntityFile.h" #include "Core/EntityFile.h"
#include "Rendering/Model.h"
class SpawnerSystem : public System class SpawnerSystem : public System
{ {
@@ -4,7 +4,6 @@
#include "Core/System.h" #include "Core/System.h"
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
#include "Network/EPlayerDisconnected.h" #include "Network/EPlayerDisconnected.h"
#include "Game/Events/EReset.h"
class SpectatorCameraSystem : public ImpureSystem class SpectatorCameraSystem : public ImpureSystem
{ {
@@ -16,14 +15,11 @@ public:
private: private:
int m_PickedTeam; int m_PickedTeam;
bool m_CamSetToTeamPick; bool m_CamSetToTeamPick;
void reset();
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand; EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e); bool OnInputCommand(const Events::InputCommand& e);
EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect; EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect;
bool OnDisconnect(const Events::PlayerDisconnected& e); bool OnDisconnect(const Events::PlayerDisconnected& e);
EventRelay<SpectatorCameraSystem, Events::Reset> m_EReset;
bool OnReset(const Events::Reset& e);
}; };
#endif #endif
@@ -2,5 +2,4 @@
<CapturePointGameMode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePointGameMode.xsd"> <CapturePointGameMode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePointGameMode.xsd">
<RespawnTime>0.0</RespawnTime> <RespawnTime>0.0</RespawnTime>
<MaxRespawnTime>8.0</MaxRespawnTime> <MaxRespawnTime>8.0</MaxRespawnTime>
<ResetCountdown>10.0</ResetCountdown>
</CapturePointGameMode> </CapturePointGameMode>
@@ -12,9 +12,6 @@
<xs:element name="MaxRespawnTime" type="t:double" minOccurs="0"> <xs:element name="MaxRespawnTime" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Players will be spawned when RespawnTime reaches this.</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>Players will be spawned when RespawnTime reaches this.</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="ResetCountdown" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The map will be reset when time reaches 0.</xs:documentation></xs:annotation>
</xs:element>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
File diff suppressed because it is too large Load Diff
+17 -17
View File
@@ -146,14 +146,14 @@ bool RayVsTriangle(const Ray& ray,
} }
bool RayVsModel(const Ray& ray, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix) const glm::mat4& modelMatrix)
{ {
for (int i = 0; i < modelIndices.size();) { for (int i = 0; i < modelIndices.size();) {
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
if (RayVsTriangle(ray, v0, v1, v2)) { if (RayVsTriangle(ray, v0, v1, v2)) {
return true; return true;
} }
@@ -194,7 +194,7 @@ bool RayVsTriangle(const Ray& ray,
} }
bool RayVsModel(const Ray& ray, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
float& outDistance, float& outDistance,
@@ -204,9 +204,9 @@ bool RayVsModel(const Ray& ray,
outDistance = INFINITY; outDistance = INFINITY;
bool hit = false; bool hit = false;
for (int i = 0; i < modelIndices.size();) { for (int i = 0; i < modelIndices.size();) {
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
float dist = outDistance; float dist = outDistance;
float u; float u;
float v; float v;
@@ -221,7 +221,7 @@ bool RayVsModel(const Ray& ray,
} }
bool RayVsModel(const Ray& ray, bool RayVsModel(const Ray& ray,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
glm::vec3& outHitPosition) glm::vec3& outHitPosition)
@@ -548,7 +548,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
} }
Output AABBvsTriangles(const AABB& box, Output AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
glm::vec3& boxVelocity, glm::vec3& boxVelocity,
@@ -565,9 +565,9 @@ Output AABBvsTriangles(const AABB& box,
glm::vec3 originalBoxVelocity(boxVelocity); glm::vec3 originalBoxVelocity(boxVelocity);
for (int i = 0; i < modelIndices.size(); ) { for (int i = 0; i < modelIndices.size(); ) {
std::array<glm::vec3, 3> triVertices = { std::array<glm::vec3, 3> triVertices = {
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix), TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix), TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix) TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix)
}; };
glm::vec3 outVec; glm::vec3 outVec;
bool collideWithGround = isOnGround; bool collideWithGround = isOnGround;
@@ -595,7 +595,7 @@ Output AABBvsTriangles(const AABB& box,
} }
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
glm::vec3& boxVelocity, glm::vec3& boxVelocity,
@@ -615,7 +615,7 @@ bool AABBvsTriangles(const AABB& box,
} }
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix) const glm::mat4& modelMatrix)
{ {
@@ -633,7 +633,7 @@ bool AABBvsTriangles(const AABB& box,
} }
Output AABBvsTrianglesWContainment(const AABB& box, Output AABBvsTrianglesWContainment(const AABB& box,
const RawModel::Vertex* modelVertices, const std::vector<glm::vec3>& modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix) const glm::mat4& modelMatrix)
{ {
@@ -741,7 +741,7 @@ boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<Enti
continue; continue;
} }
float u, v; float u, v;
if (RayVsModel(ray, model->Vertices(), model->m_RawModel->m_Indices, TransformSystem::ModelMatrix(entityBox.Entity), outDistance, u, v)) { if (RayVsModel(ray, model->m_Vertices, model->m_Indices, TransformSystem::ModelMatrix(entityBox.Entity), outDistance, u, v)) {
outIntersectPos = ray.Origin() + outDistance * ray.Direction(); outIntersectPos = ray.Origin() + outDistance * ray.Direction();
return entityBox; return entityBox;
} }
+6 -6
View File
@@ -41,15 +41,15 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
// Don't collide against invisible models. // Don't collide against invisible models.
continue; continue;
} }
RawModel* model; Model* model;
std::string res = (std::string)boxB.Entity["Model"]["Resource"]; std::string res = (std::string)boxB.Entity["Model"]["Resource"];
try { try {
model = ResourceManager::Load<RawModel, true>(res); model = ResourceManager::Load<Model, true>(res);
} catch (const std::exception&) { } catch (const std::exception&) {
continue; continue;
} }
float u, v; float u, v;
hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, TransformSystem::ModelMatrix(boxB.Entity), dist, u, v); hit = Collision::RayVsModel(ray, model->m_Vertices, model->m_Indices, TransformSystem::ModelMatrix(boxB.Entity), dist, u, v);
} else { } else {
hit = Collision::RayVsAABB(ray, boxB, dist); hit = Collision::RayVsAABB(ray, boxB, dist);
} }
@@ -86,9 +86,9 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
// Don't collide against invisible models. // Don't collide against invisible models.
continue; continue;
} }
RawModel* model; Model* model;
try { try {
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]); model = ResourceManager::Load<Model, true>(boxB.Entity["Model"]["Resource"]);
} catch (const std::exception&) { } catch (const std::exception&) {
continue; continue;
} }
@@ -98,7 +98,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"]; glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"]; bool isOnGround = (bool)cPhysics["IsOnGround"];
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
(Field<glm::vec3>)cTransform["Position"] += resolutionVector; (Field<glm::vec3>)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
+3 -3
View File
@@ -10,11 +10,11 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
return; return;
} }
RawModel* triggerModel = nullptr; Model* triggerModel = nullptr;
glm::mat4 triggerModelMat; glm::mat4 triggerModelMat;
if (triggerEntity.HasComponent("Model")) { if (triggerEntity.HasComponent("Model")) {
try { try {
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]); triggerModel = ResourceManager::Load<Model, true>(triggerEntity["Model"]["Resource"]);
triggerModelMat = TransformSystem::ModelMatrix(triggerEntity); triggerModelMat = TransformSystem::ModelMatrix(triggerEntity);
} catch (const std::exception&) { } catch (const std::exception&) {
} }
@@ -38,7 +38,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
? Collision::Output::OutContained ? Collision::Output::OutContained
: Collision::AABBvsTrianglesWContainment( : Collision::AABBvsTrianglesWContainment(
colliderBox, colliderBox,
triggerModel->Vertices(), triggerModel->m_Vertices,
triggerModel->m_Indices, triggerModel->m_Indices,
triggerModelMat); triggerModelMat);
+22 -31
View File
@@ -1,5 +1,5 @@
#include "Network/Client.h" #include "Network/Client.h"
#include "Network/EPlayerDisconnected.h"
using namespace boost::asio::ip; using namespace boost::asio::ip;
Client::Client(World* world, EventBroker* eventBroker) Client::Client(World* world, EventBroker* eventBroker)
@@ -12,7 +12,7 @@ Client::Client(World* world, EventBroker* eventBroker)
auto config = ResourceManager::Load<ConfigFile>("Config.ini"); auto config = ResourceManager::Load<ConfigFile>("Config.ini");
m_PlayerName = config->Get<std::string>("Networking.Name", "Raptorcopter"); m_PlayerName = config->Get<std::string>("Networking.Name", "Raptorcopter");
m_SendInputInterval = config->Get<int>("Networking.SendInputIntervalMs", 33) / 1000.0; m_SendInputIntervalMs = config->Get<int>("Networking.SendInputIntervalMs", 33);
LOG_INFO("Client initialized"); LOG_INFO("Client initialized");
m_ServerlistRequest.Connect(m_PlayerName, "192.168.1.255", 32554); m_ServerlistRequest.Connect(m_PlayerName, "192.168.1.255", 32554);
@@ -48,7 +48,7 @@ void Client::Connect(std::string address, int port)
} }
} }
void Client::Update(double dt) void Client::Update()
{ {
m_EventBroker->Process<Client>(); m_EventBroker->Process<Client>();
while (m_Unreliable.IsSocketAvailable()) { while (m_Unreliable.IsSocketAvailable()) {
@@ -85,9 +85,7 @@ void Client::Update(double dt)
} }
if (m_SearchingForServers) { if (m_SearchingForServers) {
m_TimeSearched += dt; if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
if (m_SearchingTime < m_TimeSearched) {
m_TimeSearched = 0;
m_SearchingForServers = false; m_SearchingForServers = false;
//displayServerlist(); //displayServerlist();
Events::DisplayServerlist e; Events::DisplayServerlist e;
@@ -98,25 +96,16 @@ void Client::Update(double dt)
if (m_IsConnected) { if (m_IsConnected) {
// Don't send 1 input in 1 packet, bunch em up. // Don't send 1 input in 1 packet, bunch em up.
m_TimeSinceSentInputs += dt; if (m_SendInputIntervalMs < (1000 * (std::clock() - m_TimeSinceSentInputs) / (double)CLOCKS_PER_SEC)) {
if (m_SendInputInterval < m_TimeSinceSentInputs) {
sendInputCommands(); sendInputCommands();
m_TimeSinceSentInputs = 0; m_TimeSinceSentInputs = std::clock();
} }
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages // HACK: Send absolute player positions for now to avoid desync until we have reliable messages
sendLocalPlayerTransform(); sendLocalPlayerTransform();
hasServerTimedOut(); hasServerTimedOut();
} }
//Network::Update();
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("You have been disconnected from server.\n\n");
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
if (ImGui::Button("OK", ImVec2(120, 0))) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
} }
void Client::parseMessageType(Packet& packet) void Client::parseMessageType(Packet& packet)
@@ -170,9 +159,6 @@ void Client::parseMessageType(Packet& packet)
case MessageType::AmmoPickup: case MessageType::AmmoPickup:
parseAmmoPickup(packet); parseAmmoPickup(packet);
break; break;
case MessageType::RemoveWorld:
parseRemoveWorld(packet);
break;
default: default:
break; break;
} }
@@ -204,7 +190,7 @@ void Client::parseTCPConnect(Packet& packet)
packet.WritePrimitive(m_PlayerID); packet.WritePrimitive(m_PlayerID);
m_Unreliable.Send(packet); m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server"); // LOG_INFO("Sent UDP Connect Server");
} }
void Client::parsePlayerConnected(Packet & packet) void Client::parsePlayerConnected(Packet & packet)
@@ -350,13 +336,6 @@ void Client::parseAmmoPickup(Packet & packet)
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
void Client::parseRemoveWorld(Packet & packet)
{
removeWorld();
Events::Reset e;
m_EventBroker->Publish(e);
}
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
{ {
for (auto field : componentInfo.FieldsInOrder) { for (auto field : componentInfo.FieldsInOrder) {
@@ -604,7 +583,7 @@ bool Client::OnConnectRequest(const Events::ConnectRequest& e)
bool Client::OnSearchForServers(const Events::SearchForServers& e) bool Client::OnSearchForServers(const Events::SearchForServers& e)
{ {
m_SearchingForServers = true; m_SearchingForServers = true;
m_TimeSearched = 0; m_StartSearchTime = std::clock();
m_Serverlist.clear(); m_Serverlist.clear();
Packet packet(MessageType::ServerlistRequest); Packet packet(MessageType::ServerlistRequest);
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
@@ -684,7 +663,6 @@ void Client::hasServerTimedOut()
if (timeSincePing > m_TimeoutMs) { if (timeSincePing > m_TimeoutMs) {
// Clear everything and go to menu. // Clear everything and go to menu.
LOG_INFO("Server has timed out, returning to menu, Beep Boop."); LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
ImGui::OpenPopup("Disconnected");
disconnect(); disconnect();
} }
} }
@@ -728,6 +706,19 @@ void Client::displayServerlist()
} }
} }
void Client::removeWorld()
{
std::vector<EntityID> childrenToBeDeleted;
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
childrenToBeDeleted.push_back(it->second);
}
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
m_World->DeleteEntity(childrenToBeDeleted[i]);
}
}
void Client::createMainMenu() void Client::createMainMenu()
{ {
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/StartMenu.xml"); auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/StartMenu.xml");
+1 -13
View File
@@ -9,7 +9,7 @@ Network::Network(World* world, EventBroker* eventBroker)
m_TimeoutMs = config->Get<int>("Networking.TimeoutMs", 20000); m_TimeoutMs = config->Get<int>("Networking.TimeoutMs", 20000);
} }
void Network::Update(double dt) void Network::Update()
{ {
updateNetworkData(); updateNetworkData();
} }
@@ -92,15 +92,3 @@ void Network::popNetworkSegmentOfHeader(Packet & packet)
packet.ReadPrimitive<int>(); packet.ReadPrimitive<int>();
packet.ReadPrimitive<int>(); packet.ReadPrimitive<int>();
} }
void Network::removeWorld()
{
std::vector<EntityID> childrenToBeDeleted;
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
childrenToBeDeleted.push_back(it->second);
}
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
m_World->DeleteEntity(childrenToBeDeleted[i]);
}
}
+15 -62
View File
@@ -5,8 +5,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
, m_ServerlistRequest(13) , m_ServerlistRequest(13)
{ {
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini"); ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
snapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05); snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
pingInterval = config->Get<float>("Networking.PingIntervalMs", 1000) / 1000.0; pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
m_ServerName = config->Get<std::string>("Networking.Name", "Unnamed"); m_ServerName = config->Get<std::string>("Networking.Name", "Unnamed");
// Subscribe to events // Subscribe to events
@@ -17,7 +17,6 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup); EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath);
EVENT_SUBSCRIBE_MEMBER(m_EWin, &Server::OnWin);
// BindWW // BindWW
if (port == 0) { if (port == 0) {
port = config->Get<float>("Networking.Port", 27666); port = config->Get<float>("Networking.Port", 27666);
@@ -31,7 +30,7 @@ Server::~Server()
} }
void Server::Update(double dt) void Server::Update()
{ {
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers); m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
@@ -87,44 +86,26 @@ void Server::Update(double dt)
} }
m_PlayersToDisconnect.clear(); m_PlayersToDisconnect.clear();
std::clock_t currentTime = std::clock();
// Send snapshot // Send snapshot
previousSnapshotMessage += dt; if (snapshotInterval < (1000 * (currentTime - previousSnapshotMessage) / (double)CLOCKS_PER_SEC)) {
if (snapshotInterval < previousSnapshotMessage) {
sendSnapshot(); sendSnapshot();
previousSnapshotMessage = 0; previousSnapshotMessage = currentTime;
} }
// Send pings each // Send pings each
previousPingMessage += dt; if (pingIntervalMs < (1000 * (currentTime - previousePingMessage) / (double)CLOCKS_PER_SEC)) {
if (pingInterval < previousPingMessage) {
sendPing(); sendPing();
previousPingMessage = 0; previousePingMessage = currentTime;
} }
// Time out logic // Time out logic
timeOutTimer += dt; if (checkTimeOutInterval < (1000 * (currentTime - timOutTimer) / (double)CLOCKS_PER_SEC)) {
if (checkTimeOutInterval < timeOutTimer) {
checkForTimeOuts(); checkForTimeOuts();
timeOutTimer = 0; timOutTimer = currentTime;
} }
m_EventBroker->Process<Server>(); m_EventBroker->Process<Server>();
if (isReadingData) { if (isReadingData) {
Network::Update(dt); Network::Update();
}
if (m_GameIsOver) {
auto pool = m_World->GetComponents("CapturePointGameMode");
if (pool != nullptr && pool->size() > 0) {
// Take the first CapturePointGameMode component found.
ComponentWrapper& modeComponent = *pool->begin();
// Decrease timer.
Field<double> timer = modeComponent["ResetCountdown"];
timer -= dt;
if (timer < 0) {
resetMap();
}
} else {
resetMap();
}
} }
} }
@@ -183,7 +164,7 @@ void Server::reliableBroadcast(Packet& packet)
void Server::unreliableBroadcast(Packet& packet) void Server::unreliableBroadcast(Packet& packet)
{ {
m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers); m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers);
} }
// Send snapshot fields // Send snapshot fields
@@ -192,16 +173,10 @@ void Server::sendSnapshot()
Packet packet(MessageType::Snapshot); Packet packet(MessageType::Snapshot);
addInputCommandsToPacket(packet); addInputCommandsToPacket(packet);
addPlayersToPacket(packet, EntityID_Invalid); addPlayersToPacket(packet, EntityID_Invalid);
//addChildrenToPacket(packet, EntityID_Invalid);
unreliableBroadcast(packet); unreliableBroadcast(packet);
} }
// Send snapshot fields
void Server::createWorldSnapshot(Packet& packet)
{
addInputCommandsToPacket(packet);
addChildrenToPacket(packet, EntityID_Invalid);
}
void Server::addInputCommandsToPacket(Packet& packet) void Server::addInputCommandsToPacket(Packet& packet)
{ {
// Number of input commands // Number of input commands
@@ -404,7 +379,8 @@ void Server::parseTCPConnect(Packet & packet)
m_Reliable.Send(connnectPacket, m_ConnectedPlayers.at(playerID)); m_Reliable.Send(connnectPacket, m_ConnectedPlayers.at(playerID));
Packet firstSnapshot(MessageType::Snapshot); Packet firstSnapshot(MessageType::Snapshot);
createWorldSnapshot(firstSnapshot); addInputCommandsToPacket(firstSnapshot);
addChildrenToPacket(firstSnapshot, EntityID_Invalid);
m_Reliable.Send(firstSnapshot); m_Reliable.Send(firstSnapshot);
// Send notification that a player has connected // Send notification that a player has connected
@@ -566,13 +542,6 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
return false; return false;
} }
bool Server::OnWin(const Events::Win & e)
{
// Postpone the gameover reset
m_GameIsOver = true;
return true;
}
void Server::parseClientPing() void Server::parseClientPing()
{ {
LOG_INFO("%i: Parsing ping", m_PacketID); LOG_INFO("%i: Parsing ping", m_PacketID);
@@ -694,20 +663,4 @@ PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
} }
} }
return -1; return -1;
}
void Server::resetMap()
{
m_GameIsOver = false;
Events::Reset reset;
m_EventBroker->Publish(reset);
Packet removeMap(MessageType::RemoveWorld);
reliableBroadcast(removeMap);
removeWorld();
// Hardcoded for now.
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/CP_Rocky2.xml");
entityFile->MergeInto(m_World);
Packet newWorld(MessageType::Snapshot);
createWorldSnapshot(newWorld);
reliableBroadcast(newWorld);
} }
+5 -5
View File
@@ -37,7 +37,7 @@ void AnimationSystem::CreateBlendTrees()
continue;; continue;;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
continue; continue;
} }
@@ -79,7 +79,7 @@ void AnimationSystem::UpdateAnimations(double dt)
return; return;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return; return;
} }
@@ -175,7 +175,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
return false; return false;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return false; return false;
} }
@@ -294,7 +294,7 @@ bool AnimationSystem::OnEntityDeleted(Events::EntityDeleted& e)
return false; return false;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return false; return false;
} }
@@ -325,7 +325,7 @@ bool AnimationSystem::OnSetBlendWeight(Events::SetBlendWeight& e)
return false; return false;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return false; return false;
} }
+3 -3
View File
@@ -22,7 +22,7 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
return; return;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return; return;
} }
@@ -130,7 +130,7 @@ bool AutoBlendQueue::HasActiveBlendJob()
return HasActiveBlendJob(); return HasActiveBlendJob();
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
m_BlendQueue.pop_front(); m_BlendQueue.pop_front();
return HasActiveBlendJob(); return HasActiveBlendJob();
@@ -173,7 +173,7 @@ std::shared_ptr<BlendTree> AutoBlendQueue::GetBlendTree()
return nullptr; return nullptr;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
return nullptr; return nullptr;
} }
@@ -26,7 +26,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
return; return;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if(skeleton == nullptr) { if(skeleton == nullptr) {
return; return;
+1 -1
View File
@@ -530,7 +530,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
std::vector<glm::mat4> frameBones; std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) { if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose(); frameBones = modelJob->BlendTree->GetFinalPose();
} else { } else if (modelJob->Skeleton != nullptr) {
frameBones = modelJob->Skeleton->GetTPose(); frameBones = modelJob->Skeleton->GetTPose();
} }
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
+15 -3
View File
@@ -2,8 +2,10 @@
Model::Model(std::string fileName) Model::Model(std::string fileName)
{ {
//fileName = "Models/Core/ScreenQuad.mesh";
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller. //Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
m_RawModel = ResourceManager::Load<RawModel, true>(fileName); auto m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
//throw FailedLoadingException("Test");
for (auto& materialProperty : m_RawModel->m_Materials) { for (auto& materialProperty : m_RawModel->m_Materials) {
switch (materialProperty.type) { switch (materialProperty.type) {
@@ -99,14 +101,24 @@ Model::Model(std::string fileName)
glm::vec3 mini(INFINITY); glm::vec3 mini(INFINITY);
glm::vec3 maxi(-INFINITY); glm::vec3 maxi(-INFINITY);
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) { for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
const auto& v = m_RawModel->Vertices()[i]; const auto& v = m_RawModel->Vertices()[i];
mini = glm::min(mini, v.Position); mini = glm::min(mini, v.Position);
maxi = glm::max(maxi, v.Position); maxi = glm::max(maxi, v.Position);
} }
m_Box = AABB(mini, maxi); m_Box = AABB(mini, maxi);
//m_Skeleton = m_RawModel->m_Skeleton;
delete m_RawModel->m_Skeleton;
m_Materials = m_RawModel->m_Materials;
//m_Indices = m_RawModel->m_Indices;
m_IsSkinned = m_RawModel->IsSkinned();
// Copy vertex positions for collisions later
for (auto& v : m_RawModel->m_Vertices) {
//m_Vertices.push_back(v.Position);
}
ResourceManager::Release("RawModel", fileName);
} }
Model::~Model() Model::~Model()
+1 -1
View File
@@ -110,7 +110,7 @@ void PickingPass::Draw(RenderScene& scene)
std::vector<glm::mat4> frameBones; std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) { if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose(); frameBones = modelJob->BlendTree->GetFinalPose();
} else { } else if (modelJob->Skeleton != nullptr) {
frameBones = modelJob->Skeleton->GetTPose(); frameBones = modelJob->Skeleton->GetTPose();
} }
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
+7 -6
View File
@@ -493,12 +493,13 @@ void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData,
RawModelCustom::~RawModelCustom() RawModelCustom::~RawModelCustom()
{ {
if (m_Skeleton != nullptr) { // Ownership of skeleton and materials get transferred to Model
delete m_Skeleton; // if (m_Skeleton != nullptr) {
} // delete m_Skeleton;
for (auto material : m_Materials) { // }
delete material.material; //for (auto material : m_Materials) {
} // delete material.material;
//}
} }
#endif #endif
+1 -1
View File
@@ -270,7 +270,7 @@ void ShadowPass::Draw(RenderScene & scene)
std::vector<glm::mat4> frameBones; std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) { if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose(); frameBones = modelJob->BlendTree->GetFinalPose();
} else { } else if (modelJob->Skeleton != nullptr) {
frameBones = modelJob->Skeleton->GetTPose(); frameBones = modelJob->Skeleton->GetTPose();
} }
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
+2 -2
View File
@@ -232,10 +232,10 @@ void Game::Tick()
PerformanceTimer::StartTimerAndStopPrevious("Network"); PerformanceTimer::StartTimerAndStopPrevious("Network");
m_EventBroker->Process<MultiplayerSnapshotFilter>(); m_EventBroker->Process<MultiplayerSnapshotFilter>();
if (m_NetworkClient != nullptr) { if (m_NetworkClient != nullptr) {
m_NetworkClient->Update(dt); m_NetworkClient->Update();
} }
if (m_NetworkServer != nullptr) { if (m_NetworkServer != nullptr) {
m_NetworkServer->Update(dt); m_NetworkServer->Update();
} }
//m_SoundManager->Update(dt); //m_SoundManager->Update(dt);
+4 -31
View File
@@ -10,26 +10,8 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
EVENT_SUBSCRIBE_MEMBER(m_EReset, &CapturePointSystem::OnReset);
Init();
} }
}
void CapturePointSystem::Init()
{
m_WinnerWasFound = false;
//need to track these variables for the captureSystem to work as per design!
m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint;
m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint;
m_RedTeamHomeCapturePoint = m_NotACapturePoint;
m_BlueTeamHomeCapturePoint = m_NotACapturePoint;
m_NumberOfCapturePoints = 0;
m_ResetTimers = false;
m_RecentlyCapturedNeedNextCapturePointNow = false;
m_CapturePointNumberToEntityMap.clear();
//vectors which will keep track of enter/leave changes
m_ETriggerTouchVector.clear();
m_ETriggerLeaveVector.clear();
} }
//here all capturepoints will update their component //here all capturepoints will update their component
@@ -42,9 +24,6 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
if (m_WinnerWasFound) { if (m_WinnerWasFound) {
return; return;
} }
if (!capturePointEntity.Valid()) {
return;
}
const int capturePointNumber = cCapturePoint["CapturePointNumber"]; const int capturePointNumber = cCapturePoint["CapturePointNumber"];
const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); const bool hasTeamComponent = capturePointEntity.HasComponent("Team");
@@ -81,7 +60,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
} }
//if we havent received all capturepoints yet, just return //if we havent received all capturepoints yet, just return
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints > m_CapturePointNumberToEntityMap.size()) { if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) {
m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity));
return; return;
} }
@@ -253,10 +232,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
} }
void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) {
{
(Field<bool>)capturePointModels["Model"]["Visible"] = isOwner; (Field<bool>)capturePointModels["Model"]["Visible"] = isOwner;
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) { for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform"))
{
if (capModel.HasComponent("Model")) { if (capModel.HasComponent("Model")) {
(Field<bool>)capModel["Model"]["Visible"] = isOwner; (Field<bool>)capModel["Model"]["Visible"] = isOwner;
} }
@@ -290,9 +269,3 @@ bool CapturePointSystem::OnCaptured(const Events::Captured& e)
m_ResetTimers = true; m_ResetTimers = true;
return true; return true;
} }
bool CapturePointSystem::OnReset(const Events::Reset& e)
{
Init();
return true;
}
-24
View File
@@ -9,8 +9,6 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &ScoreScreenSystem::OnPlayerSpawn); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &ScoreScreenSystem::OnPlayerSpawn);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerConnected, &ScoreScreenSystem::OnPlayerConnected); EVENT_SUBSCRIBE_MEMBER(m_EPlayerConnected, &ScoreScreenSystem::OnPlayerConnected);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDisconnected, &ScoreScreenSystem::OnPlayerDisconnected); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDisconnected, &ScoreScreenSystem::OnPlayerDisconnected);
EVENT_SUBSCRIBE_MEMBER(m_EReset, &ScoreScreenSystem::OnReset);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &ScoreScreenSystem::OnInputCommand);
} }
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt) void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt)
@@ -158,25 +156,3 @@ bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e
m_DisconnectedIdentities.push_back(e.PlayerID); m_DisconnectedIdentities.push_back(e.PlayerID);
return 0; return 0;
} }
bool ScoreScreenSystem::OnReset(const Events::Reset & e)
{
for (auto& it : m_PlayerIdentities) {
it.second.Deaths = 0;
it.second.Kills = 0;
it.second.Team = 1;
it.second.Player = EntityWrapper::Invalid;
}
return true;
}
bool ScoreScreenSystem::OnInputCommand(const Events::InputCommand & e)
{
if (e.Command != "PickTeam" || e.PlayerID == -1 || e.Value == 0) {
return false;
}
m_PlayerIdentities.at(e.PlayerID).Team = e.Value;
return true;
}
+3 -3
View File
@@ -103,15 +103,15 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
if (!spawnedBox.Entity.HasComponent("Model")) { if (!spawnedBox.Entity.HasComponent("Model")) {
return true; return true;
} }
RawModel* model = nullptr; Model* model = nullptr;
try { try {
model = ResourceManager::Load<RawModel, true>(otherEntity["Model"]["Resource"]); model = ResourceManager::Load<Model, true>(otherEntity["Model"]["Resource"]);
} catch (const std::exception&) { } catch (const std::exception&) {
} }
if (model != nullptr && Collision::AABBvsTriangles( if (model != nullptr && Collision::AABBvsTriangles(
spawnedBox, spawnedBox,
model->Vertices(), model->m_Vertices,
model->m_Indices, model->m_Indices,
TransformSystem::ModelMatrix(otherEntity))) { TransformSystem::ModelMatrix(otherEntity))) {
return true; return true;
+4 -16
View File
@@ -9,7 +9,6 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
{ {
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect); EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
EVENT_SUBSCRIBE_MEMBER(m_EReset, &SpectatorCameraSystem::OnReset);
} }
void SpectatorCameraSystem::Update(double dt) void SpectatorCameraSystem::Update(double dt)
@@ -28,14 +27,6 @@ void SpectatorCameraSystem::Update(double dt)
} }
} }
void SpectatorCameraSystem::reset()
{
m_CamSetToTeamPick = false;
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
{ {
// Only the client should do this, and only if player is not spawned. // Only the client should do this, and only if player is not spawned.
@@ -104,13 +95,10 @@ bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e)
// If local player gets disconnected, they should be set to // If local player gets disconnected, they should be set to
// the spectator camera next time a map loads that has one. // the spectator camera next time a map loads that has one.
if (e.Entity == LocalPlayer.ID) { if (e.Entity == LocalPlayer.ID) {
reset(); m_CamSetToTeamPick = false;
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
} }
return true; return true;
} }
bool SpectatorCameraSystem::OnReset(const Events::Reset & e)
{
reset();
return true;
}
+6 -6
View File
@@ -108,7 +108,7 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode&
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) { } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "found color splat map"); MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.ColorMaps, MFnDependencyNode(AllConnections[i].node())); return findSplatTextures(material_node, material_node.ColorMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
@@ -162,9 +162,9 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode&
material_node.NormalMaps.push_back(newTexture); material_node.NormalMaps.push_back(newTexture);
return true; return true;
} else if (AllBumpConnections[j].node().hasFn(MFn::kLayeredTexture)) { } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "found normal splat map"); MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.NormalMaps, MFnDependencyNode(AllBumpConnections[j].node())); return findSplatTextures(material_node, material_node.NormalMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
} }
@@ -218,7 +218,7 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod
material_node.type = MaterialNode::MaterialType::SingleTextures; material_node.type = MaterialNode::MaterialType::SingleTextures;
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) { } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "found specular splat map"); MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.SpecularMaps, MFnDependencyNode(AllConnections[i].node())); return findSplatTextures(material_node, material_node.SpecularMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }
@@ -270,7 +270,7 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen
return true; return true;
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) { } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
MGlobal::displayInfo(MString() + "found incandescens splat map"); MGlobal::displayInfo(MString() + "find splat map");
return findSplatTextures(material_node, material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node())); return findSplatTextures(material_node, material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node()));
} }
} }