Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f89cef7a78 |
@@ -84,18 +84,6 @@ bool AABBvsTriangles(const AABB& box,
|
|||||||
const std::vector<unsigned int>& modelIndices,
|
const std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix);
|
const glm::mat4& modelMatrix);
|
||||||
|
|
||||||
enum Output
|
|
||||||
{
|
|
||||||
OutContained,
|
|
||||||
OutSeparated,
|
|
||||||
OutIntersecting
|
|
||||||
};
|
|
||||||
//Detects intersection and containment.
|
|
||||||
Output AABBvsTrianglesWContainment(const AABB& box,
|
|
||||||
const RawModel::Vertex* modelVertices,
|
|
||||||
const std::vector<unsigned int>& modelIndices,
|
|
||||||
const glm::mat4& modelMatrix);
|
|
||||||
|
|
||||||
//Return true if the boxes are intersecting.
|
//Return true if the boxes are intersecting.
|
||||||
bool AABBVsAABB(const AABB& a, const AABB& b);
|
bool AABBVsAABB(const AABB& a, const AABB& b);
|
||||||
//Return true if the boxes are intersecting.
|
//Return true if the boxes are intersecting.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ public:
|
|||||||
virtual const glm::vec3 Rotation() const { return m_Rotation; }
|
virtual const glm::vec3 Rotation() const { return m_Rotation; }
|
||||||
virtual bool Jumping() const { return m_Jumping; }
|
virtual bool Jumping() const { return m_Jumping; }
|
||||||
virtual bool Crouching() const { return m_Crouching; }
|
virtual bool Crouching() const { return m_Crouching; }
|
||||||
virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; }
|
|
||||||
virtual bool DoubleJumping() const { return m_DoubleJumping; }
|
virtual bool DoubleJumping() const { return m_DoubleJumping; }
|
||||||
virtual void SetDoubleJumping(bool isDoubleJumping) {
|
virtual void SetDoubleJumping(bool isDoubleJumping) {
|
||||||
m_DoubleJumping = isDoubleJumping;
|
m_DoubleJumping = isDoubleJumping;
|
||||||
@@ -45,7 +44,6 @@ protected:
|
|||||||
bool m_Jumping = false;
|
bool m_Jumping = false;
|
||||||
bool m_DoubleJumping = false;
|
bool m_DoubleJumping = false;
|
||||||
bool m_Crouching = false;
|
bool m_Crouching = false;
|
||||||
bool m_CrouchingLastFrame = false;
|
|
||||||
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||||
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||||
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||||
@@ -84,7 +82,6 @@ void FirstPersonInputController<EventContext>::Reset()
|
|||||||
{
|
{
|
||||||
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
|
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
|
||||||
m_Jumping = false;
|
m_Jumping = false;
|
||||||
m_CrouchingLastFrame = m_Crouching;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename EventContext>
|
template <typename EventContext>
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
void Connect(std::string address, int port);
|
void Connect(std::string address, int port);
|
||||||
void Update() override;
|
void Update() override;
|
||||||
private:
|
private:
|
||||||
UDPClient m_Unreliable;
|
//UDPClient m_Unreliable;
|
||||||
TCPClient m_Reliable;
|
TCPClient m_Reliable;
|
||||||
std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents;
|
std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents;
|
||||||
void parseSpawnEvents();
|
void parseSpawnEvents();
|
||||||
@@ -81,7 +81,7 @@ private:
|
|||||||
std::vector<Events::InputCommand> m_InputCommandBuffer;
|
std::vector<Events::InputCommand> m_InputCommandBuffer;
|
||||||
|
|
||||||
// Private member functions
|
// Private member functions
|
||||||
size_t receive(char* data);
|
size_t receive(char* data);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
void parseMessageType(Packet& packet);
|
void parseMessageType(Packet& packet);
|
||||||
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID);
|
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID);
|
||||||
@@ -139,7 +139,7 @@ private:
|
|||||||
std::vector<ServerInfo> m_Serverlist;
|
std::vector<ServerInfo> m_Serverlist;
|
||||||
bool m_SearchingForServers = false;
|
bool m_SearchingForServers = false;
|
||||||
std::clock_t m_StartSearchTime;
|
std::clock_t m_StartSearchTime;
|
||||||
double m_SearchingTime = 200; // Config I guess
|
double m_SearchingTime = 2000; // Config I guess
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ protected:
|
|||||||
void logReceivedData(int bytesReceived);
|
void logReceivedData(int bytesReceived);
|
||||||
void saveToFile();
|
void saveToFile();
|
||||||
void updateNetworkData();
|
void updateNetworkData();
|
||||||
void popNetworkSegmentOfHeader(Packet& packet);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -16,9 +16,7 @@ public:
|
|||||||
Packet(char* data, const size_t sizeOfPacket);
|
Packet(char* data, const size_t sizeOfPacket);
|
||||||
Packet(MessageType type);
|
Packet(MessageType type);
|
||||||
~Packet();
|
~Packet();
|
||||||
void Init(MessageType type, unsigned int& packetID,
|
void Init(MessageType type, unsigned int& packetID);
|
||||||
int groupIndex, int groupSize,
|
|
||||||
int packetGroup);
|
|
||||||
|
|
||||||
// Add primitive types like int, float, char...
|
// Add primitive types like int, float, char...
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -27,8 +25,7 @@ public:
|
|||||||
// Check if we are trying to add more than the package can fit.
|
// Check if we are trying to add more than the package can fit.
|
||||||
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
||||||
if (m_MaxPacketSize >= 32000) {
|
if (m_MaxPacketSize >= 32000) {
|
||||||
// This will spam couse 8 players are over 100 000 bytes
|
LOG_WARNING("Package::WritePrimitive(): New size is huge %i bytes\n", m_MaxPacketSize*2);
|
||||||
//LOG_WARNING("Package::WritePrimitive(): New size is huge %i bytes\n", m_MaxPacketSize*2);
|
|
||||||
}
|
}
|
||||||
resizeData();
|
resizeData();
|
||||||
}
|
}
|
||||||
@@ -60,19 +57,13 @@ public:
|
|||||||
void UpdateSize();
|
void UpdateSize();
|
||||||
char* ReadData(int SizeOfData);
|
char* ReadData(int SizeOfData);
|
||||||
void ChangePacketID(unsigned int& packetID);
|
void ChangePacketID(unsigned int& packetID);
|
||||||
void ChangeGroupIndex(int groupIndex);
|
|
||||||
void ChangeGroupSize(int groupSize);
|
|
||||||
void ChangeGroup(int group);
|
|
||||||
size_t Size() { return m_Offset; };
|
size_t Size() { return m_Offset; };
|
||||||
char* Data() { return m_Data; };
|
char* Data() { return m_Data; };
|
||||||
MessageType GetMessageType();
|
MessageType GetMessageType();
|
||||||
size_t Group();
|
|
||||||
size_t DataReadSize() { return m_ReturnDataOffset; }
|
size_t DataReadSize() { return m_ReturnDataOffset; }
|
||||||
size_t MaxSize() { return m_MaxPacketSize; }
|
size_t MaxSize() { return m_MaxPacketSize; }
|
||||||
size_t HeaderSize() { return m_HeaderSize; }
|
size_t HeaderSize() { return m_HeaderSize; }
|
||||||
size_t GroupIndex();
|
|
||||||
size_t GroupSize();
|
|
||||||
size_t PacketID();
|
|
||||||
private:
|
private:
|
||||||
char* m_Data;
|
char* m_Data;
|
||||||
size_t m_ReturnDataOffset = 0;
|
size_t m_ReturnDataOffset = 0;
|
||||||
@@ -81,13 +72,6 @@ private:
|
|||||||
size_t m_HeaderSize = 0;
|
size_t m_HeaderSize = 0;
|
||||||
void resizeData();
|
void resizeData();
|
||||||
void resizeData(int size);
|
void resizeData(int size);
|
||||||
|
|
||||||
size_t packetSizeOffset = 0;
|
|
||||||
size_t groupOffset = 0;
|
|
||||||
size_t groupIndexOffset = 0;
|
|
||||||
size_t groupSizeOffset = 0;
|
|
||||||
size_t messageTypeOffset = 0;
|
|
||||||
size_t packetIDOffset = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -14,7 +14,6 @@ struct PlayerDefinition {
|
|||||||
unsigned short TCPPort;
|
unsigned short TCPPort;
|
||||||
// use for tcp connections
|
// use for tcp connections
|
||||||
boost::shared_ptr<boost::asio::ip::tcp::socket> TCPSocket;
|
boost::shared_ptr<boost::asio::ip::tcp::socket> TCPSocket;
|
||||||
int PacketGroup = 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Network channels
|
// Network channels
|
||||||
TCPServer m_Reliable;
|
TCPServer m_Reliable;
|
||||||
UDPServer m_Unreliable;
|
//UDPServer m_Unreliable;
|
||||||
UDPServer m_ServerlistRequest;
|
UDPServer m_ServerlistRequest;
|
||||||
// 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;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#ifndef UDPClient_h__
|
#ifndef UDPClient_h__
|
||||||
#define UDPClient_h__
|
#define UDPClient_h__
|
||||||
#include <map>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "Network/NetworkClient.h"
|
#include "Network/NetworkClient.h"
|
||||||
@@ -15,27 +13,16 @@ public:
|
|||||||
bool Connect(std::string playerName, std::string address, int port);
|
bool Connect(std::string playerName, std::string address, int port);
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
void Receive(Packet& packet);
|
void Receive(Packet& packet);
|
||||||
void ReceivePackets();
|
void Send(Packet & packet);
|
||||||
void Send(Packet& packet);
|
|
||||||
void Broadcast(Packet& packet, int port);
|
void Broadcast(Packet& packet, int port);
|
||||||
bool IsSocketAvailable();
|
bool IsSocketAvailable();
|
||||||
// Returns false if no packets are available
|
|
||||||
bool GetNextPacket(Packet& packet);
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<unsigned int, std::vector<std::pair<int, boost::shared_ptr<char>>>> PacketMap;
|
|
||||||
// Assio UDP logic
|
// Assio UDP logic
|
||||||
boost::asio::io_service m_IOService;
|
boost::asio::io_service m_IOService;
|
||||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||||
boost::shared_ptr<boost::asio::ip::udp::socket> m_Socket;
|
boost::shared_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||||
int m_LastReceivedSnapshotGroup = 0;
|
|
||||||
int readBuffer();
|
int readBuffer();
|
||||||
void readPartOfPacket();
|
|
||||||
PacketID m_SendPacketID = 0;
|
PacketID m_SendPacketID = 0;
|
||||||
//map:(packetGroup, vector:(pair:(groupIndex, packetData)))
|
|
||||||
PacketMap m_PacketSegmentMap;
|
|
||||||
bool hasReceivedPacket(int packetGroup, int groupIndex);
|
|
||||||
// 2^19
|
|
||||||
const int m_SizeOfSocketBuffer = 524288;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "NetworkServer.h"
|
#include "NetworkServer.h"
|
||||||
#include <boost/asio/ip/udp.hpp>
|
#include <boost/asio/ip/udp.hpp>
|
||||||
#define MAXPACKETSIZE 64000
|
|
||||||
|
|
||||||
class UDPServer : public NetworkServer
|
class UDPServer : public NetworkServer
|
||||||
{
|
{
|
||||||
@@ -14,7 +13,6 @@ public:
|
|||||||
void AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers);
|
void AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers);
|
||||||
void Receive(Packet & packet, PlayerDefinition & playerDefinition);
|
void Receive(Packet & packet, PlayerDefinition & playerDefinition);
|
||||||
void Send(Packet & packet, PlayerDefinition & playerDefinition);
|
void Send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||||
void SendToConnectedPlayers(Packet & packet, std::map<PlayerID, PlayerDefinition>& playersTosendTo);
|
|
||||||
void Send(Packet & packet);
|
void Send(Packet & packet);
|
||||||
void Send(Packet & packet, boost::asio::ip::udp::endpoint endpoint);
|
void Send(Packet & packet, boost::asio::ip::udp::endpoint endpoint);
|
||||||
void Broadcast(Packet & packet, int port);
|
void Broadcast(Packet & packet, int port);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "ShadowPass.h"
|
#include "ShadowPass.h"
|
||||||
#include "BlurHUD.h"
|
#include "BlurHUD.h"
|
||||||
|
#include "TextPass.h"
|
||||||
|
|
||||||
class DrawFinalPass
|
class DrawFinalPass
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,7 @@ public:
|
|||||||
void InitializeTextures();
|
void InitializeTextures();
|
||||||
void InitializeFrameBuffers();
|
void InitializeFrameBuffers();
|
||||||
void InitializeShaderPrograms();
|
void InitializeShaderPrograms();
|
||||||
void Draw(RenderScene& scene, BlurHUD* blurHUDPass);
|
void Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass);
|
||||||
void ClearBuffer();
|
void ClearBuffer();
|
||||||
void OnWindowResize();
|
void OnWindowResize();
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Input/EInputCommand.h"
|
#include "Input/EInputCommand.h"
|
||||||
#include "Network/EPlayerDisconnected.h"
|
|
||||||
|
|
||||||
class SpectatorCameraSystem : public ImpureSystem
|
class SpectatorCameraSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
@@ -18,8 +17,6 @@ private:
|
|||||||
|
|
||||||
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;
|
|
||||||
bool OnDisconnect(const Events::PlayerDisconnected& e);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -30,5 +30,3 @@ F2=PerformanceTimingResetAllTimers
|
|||||||
F3=PerformanceTimingCreateExcelData
|
F3=PerformanceTimingCreateExcelData
|
||||||
Comma=SwapToClassPick
|
Comma=SwapToClassPick
|
||||||
Period=SwapToTeamPick
|
Period=SwapToTeamPick
|
||||||
Enter=PickClass,1
|
|
||||||
F5=DisconnectFromServer
|
|
||||||
+3571
-3571
File diff suppressed because it is too large
Load Diff
@@ -360,14 +360,7 @@ constexpr bool FaceIsGround(float faceNormalY)
|
|||||||
//An array containing 3 int pairs { 0, 2 }, { 0, 1 }, { 1, 2 }
|
//An array containing 3 int pairs { 0, 2 }, { 0, 1 }, { 1, 2 }
|
||||||
constexpr std::array<std::pair<int, int>, 3> dimensionPairs({ std::pair<int, int>(0, 2), std::pair<int, int>(0, 1), std::pair<int, int>(1, 2) });
|
constexpr std::array<std::pair<int, int>, 3> dimensionPairs({ std::pair<int, int>(0, 2), std::pair<int, int>(0, 1), std::pair<int, int>(1, 2) });
|
||||||
|
|
||||||
enum class BoxTriRes
|
bool AABBvsTriangle(const AABB& box,
|
||||||
{
|
|
||||||
Front,
|
|
||||||
Behind,
|
|
||||||
Intersect
|
|
||||||
};
|
|
||||||
|
|
||||||
BoxTriRes AABBvsTriangle(const AABB& box,
|
|
||||||
const std::array<glm::vec3, 3>& triPos,
|
const std::array<glm::vec3, 3>& triPos,
|
||||||
const glm::vec3& originalBoxVelocity,
|
const glm::vec3& originalBoxVelocity,
|
||||||
float verticalStepHeight,
|
float verticalStepHeight,
|
||||||
@@ -381,7 +374,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
//Less checks, and we should be able to walk out from models if we are trapped inside.
|
//Less checks, and we should be able to walk out from models if we are trapped inside.
|
||||||
glm::vec3 triNormal = glm::cross(triPos[1] - triPos[0], triPos[2] - triPos[0]);
|
glm::vec3 triNormal = glm::cross(triPos[1] - triPos[0], triPos[2] - triPos[0]);
|
||||||
if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) {
|
if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) {
|
||||||
return BoxTriRes::Behind;
|
return false;
|
||||||
}
|
}
|
||||||
triNormal = glm::normalize(triNormal);
|
triNormal = glm::normalize(triNormal);
|
||||||
|
|
||||||
@@ -416,9 +409,6 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
const glm::vec3& min = box.MinCorner();
|
const glm::vec3& min = box.MinCorner();
|
||||||
const glm::vec3& max = box.MaxCorner();
|
const glm::vec3& max = box.MaxCorner();
|
||||||
|
|
||||||
// If there is no intersection, whether the box center is in front of or behind the triangle.
|
|
||||||
BoxTriRes noIntersection = glm::dot(triNormal, origin - triPos[0]) > 0 ? BoxTriRes::Front : BoxTriRes::Behind;
|
|
||||||
|
|
||||||
//For each projection in xy-, xz-, and yx-planes.
|
//For each projection in xy-, xz-, and yx-planes.
|
||||||
for (std::pair<int, int> dim : dimensionPairs) {
|
for (std::pair<int, int> dim : dimensionPairs) {
|
||||||
//2D Triangle.
|
//2D Triangle.
|
||||||
@@ -436,7 +426,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
bool pushedFromTriangleLine;
|
bool pushedFromTriangleLine;
|
||||||
//if projections don't overlap, return false.
|
//if projections don't overlap, return false.
|
||||||
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
|
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
|
||||||
return noIntersection;
|
return false;
|
||||||
} else if (resolveCollision) {
|
} else if (resolveCollision) {
|
||||||
//Overwrite the smallest resolution if this is smaller.
|
//Overwrite the smallest resolution if this is smaller.
|
||||||
if (resolutionDist < resolveShortest.DistanceSq) {
|
if (resolutionDist < resolveShortest.DistanceSq) {
|
||||||
@@ -472,15 +462,14 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal);
|
float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal);
|
||||||
//If intersection point between plane and diagonal is within the box.
|
//If intersection point between plane and diagonal is within the box.
|
||||||
if (glm::abs(t) > 1) {
|
if (glm::abs(t) > 1) {
|
||||||
return noIntersection;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resolveCollision) {
|
if (!resolveCollision) {
|
||||||
return BoxTriRes::Intersect;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 cornerResolution = (1+t) * diagonal;
|
glm::vec3 cornerResolution = (1+t) * diagonal;
|
||||||
cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal;
|
|
||||||
//Overwrite the smallest resolution if cornerResolution is smaller.
|
//Overwrite the smallest resolution if cornerResolution is smaller.
|
||||||
float lenSq = glm::length2(cornerResolution);
|
float lenSq = glm::length2(cornerResolution);
|
||||||
if (lenSq < resolveShortest.DistanceSq) {
|
if (lenSq < resolveShortest.DistanceSq) {
|
||||||
@@ -509,7 +498,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
case ResolveDimZ:
|
case ResolveDimZ:
|
||||||
//If we get here, the resolution is along one coordinate axis.
|
//If we get here, the resolution is along one coordinate axis.
|
||||||
//set velocity to 0 in y if it is along y-axis.
|
//set velocity to 0 in y if it is along y-axis.
|
||||||
return BoxTriRes::Intersect;
|
return true;
|
||||||
case Line:
|
case Line:
|
||||||
projNorm = glm::normalize(outResolution);
|
projNorm = glm::normalize(outResolution);
|
||||||
break;
|
break;
|
||||||
@@ -544,10 +533,10 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm;
|
boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BoxTriRes::Intersect;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Output AABBvsTriangles(const AABB& box,
|
bool AABBvsTriangles(const AABB& box,
|
||||||
const RawModel::Vertex* modelVertices,
|
const RawModel::Vertex* modelVertices,
|
||||||
const std::vector<unsigned int>& modelIndices,
|
const std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
@@ -557,8 +546,8 @@ Output AABBvsTriangles(const AABB& box,
|
|||||||
glm::vec3& outResolutionVector,
|
glm::vec3& outResolutionVector,
|
||||||
bool resolveCollision)
|
bool resolveCollision)
|
||||||
{
|
{
|
||||||
bool intersect = false;
|
bool hit = false;
|
||||||
Output out = Output::OutContained;
|
|
||||||
bool everHitTheGround = false;
|
bool everHitTheGround = false;
|
||||||
AABB newBox = box;
|
AABB newBox = box;
|
||||||
outResolutionVector = glm::vec3(0.f);
|
outResolutionVector = glm::vec3(0.f);
|
||||||
@@ -571,27 +560,20 @@ Output AABBvsTriangles(const AABB& box,
|
|||||||
};
|
};
|
||||||
glm::vec3 outVec;
|
glm::vec3 outVec;
|
||||||
bool collideWithGround = isOnGround;
|
bool collideWithGround = isOnGround;
|
||||||
switch (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
|
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
|
||||||
case Collision::BoxTriRes::Front:
|
hit = true;
|
||||||
out = Output::OutSeparated;
|
|
||||||
break;
|
|
||||||
case Collision::BoxTriRes::Intersect:
|
|
||||||
intersect = true;
|
|
||||||
outResolutionVector += outVec;
|
outResolutionVector += outVec;
|
||||||
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
|
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
|
||||||
if (collideWithGround) {
|
if (collideWithGround) {
|
||||||
everHitTheGround = isOnGround = true;
|
everHitTheGround = isOnGround = true;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!everHitTheGround) {
|
if (!everHitTheGround) {
|
||||||
isOnGround = false;
|
isOnGround = false;
|
||||||
}
|
}
|
||||||
return intersect ? Output::OutIntersecting : out;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABBvsTriangles(const AABB& box,
|
bool AABBvsTriangles(const AABB& box,
|
||||||
@@ -611,31 +593,13 @@ bool AABBvsTriangles(const AABB& box,
|
|||||||
verticalStepHeight,
|
verticalStepHeight,
|
||||||
isOnGround,
|
isOnGround,
|
||||||
outResolutionVector,
|
outResolutionVector,
|
||||||
true) == Output::OutIntersecting;
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABBvsTriangles(const AABB& box,
|
bool AABBvsTriangles(const AABB& box,
|
||||||
const RawModel::Vertex* modelVertices,
|
const RawModel::Vertex* modelVertices,
|
||||||
const std::vector<unsigned int>& modelIndices,
|
const std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix)
|
const glm::mat4& modelMatrix)
|
||||||
{
|
|
||||||
glm::vec3 vel, outres;
|
|
||||||
bool g;
|
|
||||||
return AABBvsTriangles(box,
|
|
||||||
modelVertices,
|
|
||||||
modelIndices,
|
|
||||||
modelMatrix,
|
|
||||||
vel,
|
|
||||||
0.f,
|
|
||||||
g,
|
|
||||||
outres,
|
|
||||||
false) == Output::OutIntersecting;
|
|
||||||
}
|
|
||||||
|
|
||||||
Output AABBvsTrianglesWContainment(const AABB& box,
|
|
||||||
const RawModel::Vertex* modelVertices,
|
|
||||||
const std::vector<unsigned int>& modelIndices,
|
|
||||||
const glm::mat4& modelMatrix)
|
|
||||||
{
|
{
|
||||||
glm::vec3 vel, outres;
|
glm::vec3 vel, outres;
|
||||||
bool g;
|
bool g;
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
bool hit;
|
bool hit;
|
||||||
float dist;
|
float dist;
|
||||||
if (boxB.Entity.HasComponent("Model")) {
|
if (boxB.Entity.HasComponent("Model")) {
|
||||||
if (!((bool)boxB.Entity["Model"]["Visible"])) {
|
|
||||||
// Don't collide against invisible models.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
RawModel* model;
|
RawModel* model;
|
||||||
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
|
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
|
||||||
try {
|
try {
|
||||||
@@ -81,11 +77,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) {
|
if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) {
|
||||||
// Here we know boxB is a entity with Collideable, AABB, and Model.
|
//Here we know boxB is a entity with Collideable, AABB, and Model.
|
||||||
if (!((bool)boxB.Entity["Model"]["Visible"])) {
|
|
||||||
// Don't collide against invisible models.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
RawModel* model;
|
RawModel* model;
|
||||||
try {
|
try {
|
||||||
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
|
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
|
||||||
@@ -96,11 +88,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
||||||
|
|
||||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||||
|
bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end();
|
||||||
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->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.
|
||||||
(glm::vec3&)cTransform["Position"] += resolutionVector;
|
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
|
||||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||||
cPhysics["Velocity"] = inOutVelocity;
|
cPhysics["Velocity"] = inOutVelocity;
|
||||||
if (isOnGround) {
|
if (isOnGround) {
|
||||||
|
|||||||
@@ -10,16 +10,6 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawModel* triggerModel = nullptr;
|
|
||||||
glm::mat4 triggerModelMat;
|
|
||||||
if (triggerEntity.HasComponent("Model")) {
|
|
||||||
try {
|
|
||||||
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]);
|
|
||||||
triggerModelMat = Transform::ModelMatrix(triggerEntity);
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_OctreeOut.clear();
|
m_OctreeOut.clear();
|
||||||
m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut);
|
m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut);
|
||||||
|
|
||||||
@@ -32,17 +22,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
if (colliderFitsInTrigger) {
|
if (colliderFitsInTrigger) {
|
||||||
completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size());
|
completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size());
|
||||||
}
|
}
|
||||||
|
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox)) {
|
||||||
// We know the entity is inside the trigger box, but perhaps not the model yet.
|
|
||||||
Collision::Output out = triggerModel == nullptr
|
|
||||||
? Collision::Output::OutContained
|
|
||||||
: Collision::AABBvsTrianglesWContainment(
|
|
||||||
colliderBox,
|
|
||||||
triggerModel->Vertices(),
|
|
||||||
triggerModel->m_Indices,
|
|
||||||
triggerModelMat);
|
|
||||||
|
|
||||||
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox) && out == Collision::Output::OutContained) {
|
|
||||||
// Entity is completely inside the trigger.
|
// Entity is completely inside the trigger.
|
||||||
// If it was only touching before, it is erased.
|
// If it was only touching before, it is erased.
|
||||||
m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity);
|
m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity);
|
||||||
@@ -52,8 +32,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
completeSet.insert(colliderEntity);
|
completeSet.insert(colliderEntity);
|
||||||
publish<Events::TriggerEnter>(colliderEntity, triggerEntity);
|
publish<Events::TriggerEnter>(colliderEntity, triggerEntity);
|
||||||
}
|
}
|
||||||
continue;
|
} else {
|
||||||
} else if (out != Collision::Output::OutSeparated) {
|
|
||||||
// Entity is only touching the trigger.
|
// Entity is only touching the trigger.
|
||||||
auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity];
|
auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity];
|
||||||
auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity];
|
auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity];
|
||||||
@@ -68,17 +47,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
touchSet.insert(colliderEntity);
|
touchSet.insert(colliderEntity);
|
||||||
}
|
}
|
||||||
// Else, it was touching the trigger last frame too and nothing is done.
|
// Else, it was touching the trigger last frame too and nothing is done.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Entity is not touching the trigger,
|
||||||
|
// Throw event if it was previously.
|
||||||
|
if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// This only occurs if the entity was completely inside the trigger one frame,
|
||||||
|
// then completely outside the trigger, e.g. when dying and respawning.
|
||||||
|
throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity);
|
||||||
}
|
}
|
||||||
// Only get here if entity is not touching the trigger,
|
|
||||||
// throw event if it was touching previously.
|
|
||||||
if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// This only occurs if the entity was completely inside the trigger one frame,
|
|
||||||
// then completely outside the trigger, e.g. when dying and respawning.
|
|
||||||
throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
|
|||||||
Enable();
|
Enable();
|
||||||
} else {
|
} else {
|
||||||
Disable();
|
Disable();
|
||||||
m_EventBroker->Publish(Events::UnlockMouse());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#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)
|
||||||
@@ -51,19 +50,16 @@ void Client::Connect(std::string address, int port)
|
|||||||
void Client::Update()
|
void Client::Update()
|
||||||
{
|
{
|
||||||
m_EventBroker->Process<Client>();
|
m_EventBroker->Process<Client>();
|
||||||
while (m_Unreliable.IsSocketAvailable()) {
|
//while (m_Unreliable.IsSocketAvailable()) {
|
||||||
m_Unreliable.ReceivePackets();
|
// // Packet will get real data in receive
|
||||||
}
|
// Packet packet(MessageType::Invalid);
|
||||||
// Packet will get real data in GetNextPacket()
|
// m_Unreliable.Receive(packet);
|
||||||
Packet parsedPacket(MessageType::Invalid);
|
// if (packet.GetMessageType() == MessageType::Connect) {
|
||||||
while (m_Unreliable.GetNextPacket(parsedPacket)) {
|
// parseUDPConnect(packet);
|
||||||
if (parsedPacket.GetMessageType() == MessageType::Connect) {
|
// } else {
|
||||||
parseUDPConnect(parsedPacket);
|
// parseMessageType(packet);
|
||||||
} else {
|
// }
|
||||||
parseMessageType(parsedPacket);
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (m_Reliable.IsSocketAvailable()) {
|
while (m_Reliable.IsSocketAvailable()) {
|
||||||
// Packet will get real data in receive
|
// Packet will get real data in receive
|
||||||
Packet packet(MessageType::Invalid);
|
Packet packet(MessageType::Invalid);
|
||||||
@@ -110,9 +106,8 @@ void Client::Update()
|
|||||||
|
|
||||||
void Client::parseMessageType(Packet& packet)
|
void Client::parseMessageType(Packet& packet)
|
||||||
{
|
{
|
||||||
// Pop packetSize, sequenceNumber and packetsInSequence.
|
// Pop packetSize
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>();
|
||||||
|
|
||||||
int messageType = packet.ReadPrimitive<int>();
|
int messageType = packet.ReadPrimitive<int>();
|
||||||
if (messageType == -1)
|
if (messageType == -1)
|
||||||
return;
|
return;
|
||||||
@@ -167,29 +162,26 @@ void Client::parseMessageType(Packet& packet)
|
|||||||
void Client::parseUDPConnect(Packet& packet)
|
void Client::parseUDPConnect(Packet& packet)
|
||||||
{
|
{
|
||||||
// Map ServerEntityID and your PlayerID
|
// Map ServerEntityID and your PlayerID
|
||||||
// TODO: If this is not received send a new connect message.
|
|
||||||
LOG_INFO("I be connected PogChamp");
|
LOG_INFO("I be connected PogChamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::parseTCPConnect(Packet& packet)
|
void Client::parseTCPConnect(Packet& packet)
|
||||||
{
|
{
|
||||||
LOG_INFO("Received TCP connect from server");
|
LOG_INFO("Received TCP connect from server");
|
||||||
// Pop packetSize, group, groupIndex and groupSize.
|
// Pop size of message int
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>();
|
||||||
|
|
||||||
int messageType = packet.ReadPrimitive<int>();
|
int messageType = packet.ReadPrimitive<int>();
|
||||||
// Read packet ID
|
// Read packet ID
|
||||||
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
||||||
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
||||||
// parse player id and other stuff
|
// parse player id and other stuff
|
||||||
m_PlayerID = packet.ReadPrimitive<int>();
|
m_PlayerID = packet.ReadPrimitive<int>();
|
||||||
|
m_PlayerID = packet.ReadPrimitive<int>();
|
||||||
LOG_INFO("A Player connected");
|
LOG_INFO("A Player connected");
|
||||||
// TODO: If this is not received send a new connect message.
|
|
||||||
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
|
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
|
||||||
// Add player id and other stuff
|
// Add player id and other stuff
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,11 +208,10 @@ void Client::parsePing()
|
|||||||
|
|
||||||
void Client::parseServerlist(Packet& packet)
|
void Client::parseServerlist(Packet& packet)
|
||||||
{
|
{
|
||||||
// Pop packetSize, group, groupIndex and groupSize.
|
// Pop size, message type, and ID
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>();
|
||||||
packet.ReadPrimitive<int>();
|
packet.ReadPrimitive<int>();
|
||||||
packet.ReadPrimitive<int>();
|
packet.ReadPrimitive<int>();
|
||||||
|
|
||||||
std::string address = packet.ReadString();
|
std::string address = packet.ReadString();
|
||||||
int port = packet.ReadPrimitive<int>();
|
int port = packet.ReadPrimitive<int>();
|
||||||
std::string serverName = packet.ReadString();
|
std::string serverName = packet.ReadString();
|
||||||
@@ -233,7 +224,7 @@ void Client::parseServerlist(Packet& packet)
|
|||||||
void Client::parseKick()
|
void Client::parseKick()
|
||||||
{
|
{
|
||||||
LOG_WARNING("You have been kicked from the server.");
|
LOG_WARNING("You have been kicked from the server.");
|
||||||
disconnect();
|
m_IsConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::parseSpawnEvents()
|
void Client::parseSpawnEvents()
|
||||||
@@ -472,12 +463,7 @@ void Client::disconnect()
|
|||||||
m_PacketID = 0;
|
m_PacketID = 0;
|
||||||
Packet packet(MessageType::Disconnect, m_SendPacketID);
|
Packet packet(MessageType::Disconnect, m_SendPacketID);
|
||||||
m_Reliable.Send(packet);
|
m_Reliable.Send(packet);
|
||||||
m_Unreliable.Disconnect();
|
|
||||||
m_Reliable.Disconnect();
|
m_Reliable.Disconnect();
|
||||||
Events::PlayerDisconnected e;
|
|
||||||
e.Entity = m_LocalPlayer.ID;
|
|
||||||
e.PlayerID = -1;
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
createMainMenu();
|
createMainMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,8 +475,8 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
|
|||||||
|
|
||||||
if (e.Command == "ConnectToServer") { // Connect for now
|
if (e.Command == "ConnectToServer") { // Connect for now
|
||||||
if (e.Value > 0) {
|
if (e.Value > 0) {
|
||||||
m_Reliable.Connect(m_PlayerName, m_Address, m_Port);
|
//m_Reliable.Connect(m_PlayerName, m_Address, m_Port);
|
||||||
m_Unreliable.Connect(m_PlayerName, m_Address, m_Port);
|
// m_Unreliable.Connect(m_PlayerName, m_Address, m_Port);
|
||||||
}
|
}
|
||||||
//LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
//LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
return true;
|
return true;
|
||||||
@@ -567,7 +553,6 @@ bool Client::OnConnectRequest(const Events::ConnectRequest& e)
|
|||||||
{
|
{
|
||||||
removeWorld();
|
removeWorld();
|
||||||
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
||||||
m_Unreliable.Connect(m_PlayerName, e.IP, e.Port);
|
|
||||||
// The client sent a successful connect message
|
// The client sent a successful connect message
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -644,7 +629,7 @@ void Client::sendLocalPlayerTransform()
|
|||||||
packet.WritePrimitive((int)cAssaultWeapon["Ammo"]);
|
packet.WritePrimitive((int)cAssaultWeapon["Ammo"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Unreliable.Send(packet);
|
m_Reliable.Send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::identifyPacketLoss()
|
void Client::identifyPacketLoss()
|
||||||
@@ -706,6 +691,7 @@ void Client::displayServerlist()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Client::removeWorld()
|
void Client::removeWorld()
|
||||||
{
|
{
|
||||||
std::vector<EntityID> childrenToBeDeleted;
|
std::vector<EntityID> childrenToBeDeleted;
|
||||||
|
|||||||
@@ -83,12 +83,3 @@ void Network::updateNetworkData()
|
|||||||
m_NetworkData.DataReceivedThisInterval = 0;
|
m_NetworkData.DataReceivedThisInterval = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::popNetworkSegmentOfHeader(Packet & packet)
|
|
||||||
{
|
|
||||||
// Pop packetSize, group, groupIndex and groupSize.
|
|
||||||
packet.ReadPrimitive<int>();
|
|
||||||
packet.ReadPrimitive<int>();
|
|
||||||
packet.ReadPrimitive<int>();
|
|
||||||
packet.ReadPrimitive<int>();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,22 +3,16 @@
|
|||||||
Packet::Packet(MessageType type, unsigned int& packetID)
|
Packet::Packet(MessageType type, unsigned int& packetID)
|
||||||
{
|
{
|
||||||
m_Data = new char[m_MaxPacketSize];
|
m_Data = new char[m_MaxPacketSize];
|
||||||
Init(type, packetID, 1, 1, -1);
|
Init(type, packetID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create message
|
// Create message
|
||||||
Packet::Packet(char* data, const size_t sizeOfPacket)
|
Packet::Packet(char* data, const size_t sizeOfPacket)
|
||||||
{
|
{
|
||||||
// Create message header
|
|
||||||
// allocate memory for size of packet, sequenceNumber and totalPacketesInSequence
|
|
||||||
m_ReturnDataOffset = 0;
|
|
||||||
m_Offset = 0;
|
|
||||||
// Resize message
|
// Resize message
|
||||||
m_MaxPacketSize = sizeOfPacket;
|
m_MaxPacketSize = sizeOfPacket;
|
||||||
// Copy data newly allocated memory
|
// Copy data newly allocated memory
|
||||||
m_Data = new char[sizeOfPacket];
|
m_Data = new char[sizeOfPacket];
|
||||||
unsigned int dummy = 0;
|
|
||||||
Init(MessageType::Invalid, dummy, 0, 0, 0);
|
|
||||||
memcpy(m_Data, data, sizeOfPacket);
|
memcpy(m_Data, data, sizeOfPacket);
|
||||||
m_Offset = sizeOfPacket;
|
m_Offset = sizeOfPacket;
|
||||||
}
|
}
|
||||||
@@ -27,7 +21,7 @@ Packet::Packet(MessageType type)
|
|||||||
{
|
{
|
||||||
m_Data = new char[m_MaxPacketSize];
|
m_Data = new char[m_MaxPacketSize];
|
||||||
unsigned int dummy = 0;
|
unsigned int dummy = 0;
|
||||||
Init(type, dummy, 1, 1, -1);
|
Init(type, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet::~Packet()
|
Packet::~Packet()
|
||||||
@@ -35,30 +29,16 @@ Packet::~Packet()
|
|||||||
delete[] m_Data;
|
delete[] m_Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packet::Init(MessageType type, unsigned int & packetID,
|
void Packet::Init(MessageType type, unsigned int & packetID)
|
||||||
int groupIndex, int groupSize, int group)
|
|
||||||
{
|
{
|
||||||
m_ReturnDataOffset = 0;
|
m_ReturnDataOffset = 0;
|
||||||
m_Offset = 0;
|
m_Offset = 0;
|
||||||
// Create message header
|
// Create message header
|
||||||
// allocate memory for size of packet, sequenceNumber and totalPacketesInSequence
|
// allocate memory for size of packet(only used in tcp)
|
||||||
packetSizeOffset = m_Offset;
|
|
||||||
WritePrimitive<int>(0);
|
WritePrimitive<int>(0);
|
||||||
// packetGroup is the group the packet is in
|
|
||||||
groupOffset = m_Offset;
|
|
||||||
WritePrimitive<int>(group);
|
|
||||||
// What index the packet has in the packetGroup
|
|
||||||
groupIndexOffset = m_Offset;
|
|
||||||
WritePrimitive(groupIndex);
|
|
||||||
// The total amount of packets in a packetGroup
|
|
||||||
groupSizeOffset = m_Offset;
|
|
||||||
WritePrimitive(groupSize);
|
|
||||||
// Add message type
|
// Add message type
|
||||||
int messageType = static_cast<int>(type);
|
int messageType = static_cast<int>(type);
|
||||||
messageTypeOffset = m_Offset;
|
|
||||||
WritePrimitive<int>(messageType);
|
WritePrimitive<int>(messageType);
|
||||||
// Packet ID
|
|
||||||
packetIDOffset = m_Offset;
|
|
||||||
WritePrimitive<int>(packetID);
|
WritePrimitive<int>(packetID);
|
||||||
packetID++;
|
packetID++;
|
||||||
m_HeaderSize = m_Offset;
|
m_HeaderSize = m_Offset;
|
||||||
@@ -124,7 +104,8 @@ void Packet::ReconstructFromData(char * data, size_t sizeOfData)
|
|||||||
|
|
||||||
void Packet::UpdateSize()
|
void Packet::UpdateSize()
|
||||||
{
|
{
|
||||||
memcpy(m_Data + packetSizeOffset, &m_Offset, sizeof(int));
|
int whatisoffset = m_Offset;
|
||||||
|
memcpy(m_Data, &m_Offset, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
char * Packet::ReadData(int sizeOfData)
|
char * Packet::ReadData(int sizeOfData)
|
||||||
@@ -142,47 +123,14 @@ void Packet::ChangePacketID(unsigned int & packetID)
|
|||||||
{
|
{
|
||||||
packetID = packetID + 1;
|
packetID = packetID + 1;
|
||||||
// Overwrite old PacketID
|
// Overwrite old PacketID
|
||||||
memcpy(m_Data + packetIDOffset, &packetID, sizeof(int));
|
memcpy(m_Data + 2*sizeof(int), &packetID, sizeof(int));
|
||||||
}
|
|
||||||
|
|
||||||
void Packet::ChangeGroupIndex(int groupIndex)
|
|
||||||
{
|
|
||||||
memcpy(m_Data + groupIndexOffset, &groupIndex, sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Packet::ChangeGroupSize(int groupSize)
|
|
||||||
{
|
|
||||||
memcpy(m_Data + groupSizeOffset, &groupSize, sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Packet::ChangeGroup(int group)
|
|
||||||
{
|
|
||||||
memcpy(m_Data + groupOffset, &group, sizeof(int));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageType Packet::GetMessageType()
|
MessageType Packet::GetMessageType()
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<MessageType*>(m_Data + messageTypeOffset);
|
MessageType messagType;
|
||||||
}
|
memcpy(&messagType, m_Data + sizeof(int), sizeof(int));
|
||||||
|
return messagType;
|
||||||
size_t Packet::Group()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<size_t*>(m_Data + groupOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Packet::GroupIndex()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<size_t*>(m_Data + groupIndexOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Packet::GroupSize()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<size_t*>(m_Data + groupSizeOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Packet::PacketID()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<size_t*>(m_Data + packetIDOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packet::resizeData()
|
void Packet::resizeData()
|
||||||
|
|||||||
@@ -49,19 +49,19 @@ void Server::Update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerDefinition pd;
|
//PlayerDefinition pd;
|
||||||
while (m_Unreliable.IsSocketAvailable()) {
|
//while (m_Unreliable.IsSocketAvailable()) {
|
||||||
// Packet will get real data in receive
|
// // Packet will get real data in receive
|
||||||
Packet packet(MessageType::Invalid);
|
// Packet packet(MessageType::Invalid);
|
||||||
m_Unreliable.Receive(packet, pd);
|
// m_Unreliable.Receive(packet, pd);
|
||||||
m_Address = pd.Endpoint.address();
|
// m_Address = pd.Endpoint.address();
|
||||||
m_Port = pd.Endpoint.port();
|
// m_Port = pd.Endpoint.port();
|
||||||
if (packet.GetMessageType() == MessageType::Connect) {
|
// if (packet.GetMessageType() == MessageType::Connect) {
|
||||||
parseUDPConnect(packet);
|
// parseUDPConnect(packet);
|
||||||
} else {
|
// } else {
|
||||||
parseMessageType(packet);
|
// parseMessageType(packet);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
while (m_ServerlistRequest.IsSocketAvailable()) {
|
while (m_ServerlistRequest.IsSocketAvailable()) {
|
||||||
Packet packet(MessageType::Invalid);
|
Packet packet(MessageType::Invalid);
|
||||||
@@ -69,11 +69,9 @@ void Server::Update()
|
|||||||
localArea.Endpoint = boost::asio::ip::udp::endpoint();
|
localArea.Endpoint = boost::asio::ip::udp::endpoint();
|
||||||
m_ServerlistRequest.Receive(packet, localArea);
|
m_ServerlistRequest.Receive(packet, localArea);
|
||||||
if (packet.GetMessageType() == MessageType::ServerlistRequest) {
|
if (packet.GetMessageType() == MessageType::ServerlistRequest) {
|
||||||
// Pop header
|
packet.ReadPrimitive<int>(); // Pop size
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>(); // Pop MsgType
|
||||||
packet.ReadPrimitive<int>();
|
packet.ReadPrimitive<int>(); // Pop packet ID
|
||||||
packet.ReadPrimitive<int>();
|
|
||||||
|
|
||||||
int port = packet.ReadPrimitive<int>();
|
int port = packet.ReadPrimitive<int>();
|
||||||
std::string address = localArea.Endpoint.address().to_string();
|
std::string address = localArea.Endpoint.address().to_string();
|
||||||
parseServerlistRequest(boost::asio::ip::udp::endpoint(boost::asio::ip::address().from_string(address), port));
|
parseServerlistRequest(boost::asio::ip::udp::endpoint(boost::asio::ip::address().from_string(address), port));
|
||||||
@@ -111,9 +109,9 @@ void Server::Update()
|
|||||||
|
|
||||||
void Server::parseMessageType(Packet& packet)
|
void Server::parseMessageType(Packet& packet)
|
||||||
{
|
{
|
||||||
// Pop packetSize, sequenceNumber and packetsInSequence.
|
// Pop packetSize which is used by TCP Client to
|
||||||
// create a packet of the correct size
|
// create a packet of the correct size
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>();
|
||||||
|
|
||||||
int messageType = packet.ReadPrimitive<int>(); // Read what type off message was sent from server
|
int messageType = packet.ReadPrimitive<int>(); // Read what type off message was sent from server
|
||||||
// Read packet ID
|
// Read packet ID
|
||||||
@@ -164,7 +162,10 @@ void Server::reliableBroadcast(Packet& packet)
|
|||||||
|
|
||||||
void Server::unreliableBroadcast(Packet& packet)
|
void Server::unreliableBroadcast(Packet& packet)
|
||||||
{
|
{
|
||||||
m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers);
|
for (auto& kv : m_ConnectedPlayers) {
|
||||||
|
packet.ChangePacketID(kv.second.PacketID);
|
||||||
|
// m_Unreliable.Send(packet, kv.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send snapshot fields
|
// Send snapshot fields
|
||||||
@@ -173,8 +174,7 @@ 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);
|
reliableBroadcast(packet);
|
||||||
unreliableBroadcast(packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::addInputCommandsToPacket(Packet& packet)
|
void Server::addInputCommandsToPacket(Packet& packet)
|
||||||
@@ -299,6 +299,8 @@ void Server::sendPing()
|
|||||||
reliableBroadcast(packet);
|
reliableBroadcast(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Server::checkForTimeOuts()
|
void Server::checkForTimeOuts()
|
||||||
{
|
{
|
||||||
double startPing = 1000 * m_StartPingTime
|
double startPing = 1000 * m_StartPingTime
|
||||||
@@ -315,35 +317,38 @@ void Server::checkForTimeOuts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = playersToRemove.size() - 1; i >= 0; i--) {
|
for (size_t i = 0; i < playersToRemove.size(); i++) {
|
||||||
disconnect(playersToRemove.at(i));
|
disconnect(playersToRemove.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::parseUDPConnect(Packet & packet)
|
//void Server::parseUDPConnect(Packet & packet)
|
||||||
{
|
//{
|
||||||
//Pop packetSize, sequenceNumber and packetsInSequence.
|
// // Pop size of message int
|
||||||
popNetworkSegmentOfHeader(packet);
|
// packet.ReadPrimitive<int>();
|
||||||
int messageType = packet.ReadPrimitive<int>();
|
// int messageType = packet.ReadPrimitive<int>();
|
||||||
// Read packet ID
|
// // Read packet ID
|
||||||
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
// m_PreviousPacketID = m_PacketID; // Set previous packet id
|
||||||
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
// m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
||||||
// parse player id and other stuff
|
// // parse player id and other stuff
|
||||||
PlayerID playerID = packet.ReadPrimitive<int>();
|
// PlayerID playerID = packet.ReadPrimitive<int>();
|
||||||
boost::asio::ip::udp::endpoint endpoint(m_Address, m_Port);
|
// if (!EntityWrapper(m_World, playerID).Valid()) {
|
||||||
m_ConnectedPlayers.at(playerID).Endpoint = endpoint;
|
//
|
||||||
LOG_INFO("parseUDPConnect: Spectator \"%s\" connected on IP: %s", m_ConnectedPlayers.at(playerID).Name.c_str(), m_ConnectedPlayers.at(playerID).Endpoint.address().to_string().c_str());
|
// }
|
||||||
// Send a message to the player that connected
|
// // Do something here?
|
||||||
Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
// boost::asio::ip::udp::endpoint endpoint(m_Address, m_Port);
|
||||||
m_Unreliable.Send(connnectPacket);
|
// m_ConnectedPlayers.at(playerID).Endpoint = endpoint;
|
||||||
LOG_INFO("UDP Connect sent to client");
|
// LOG_INFO("parseUDPConnect: Spectator \"%s\" connected on IP: %s", m_ConnectedPlayers.at(playerID).Name.c_str(), m_ConnectedPlayers.at(playerID).Endpoint.address().to_string().c_str());
|
||||||
}
|
// // Send a message to the player that connected
|
||||||
|
// Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
||||||
|
// m_Unreliable.Send(connnectPacket);
|
||||||
|
// LOG_INFO("UDP Connect sent to client");
|
||||||
|
//}
|
||||||
|
|
||||||
void Server::parseTCPConnect(Packet & packet)
|
void Server::parseTCPConnect(Packet & packet)
|
||||||
{
|
{
|
||||||
// Pop packetSize, sequenceNumber and packetsInSequence.
|
// Pop size of message int
|
||||||
popNetworkSegmentOfHeader(packet);
|
packet.ReadPrimitive<int>();
|
||||||
|
|
||||||
int messageType = packet.ReadPrimitive<int>();
|
int messageType = packet.ReadPrimitive<int>();
|
||||||
// Read packet ID
|
// Read packet ID
|
||||||
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
||||||
@@ -351,9 +356,9 @@ void Server::parseTCPConnect(Packet & packet)
|
|||||||
|
|
||||||
LOG_INFO("Parsing connections");
|
LOG_INFO("Parsing connections");
|
||||||
// Check if player is already connected
|
// Check if player is already connected
|
||||||
|
// Ska vara till lagd i TCPServer receive
|
||||||
PlayerID playerID = getPlayerIDFromEndpoint();
|
PlayerID playerID = getPlayerIDFromEndpoint();
|
||||||
if (playerID == -1) {
|
if (playerID == -1) {
|
||||||
LOG_INFO("Server::parseTCPConnect: Not connected");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Create a new player
|
// Create a new player
|
||||||
@@ -376,7 +381,7 @@ void Server::parseTCPConnect(Packet & packet)
|
|||||||
Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
||||||
// Write playerID to packet
|
// Write playerID to packet
|
||||||
connnectPacket.WritePrimitive(playerID);
|
connnectPacket.WritePrimitive(playerID);
|
||||||
m_Reliable.Send(connnectPacket, m_ConnectedPlayers.at(playerID));
|
m_Reliable.Send(connnectPacket);
|
||||||
|
|
||||||
Packet firstSnapshot(MessageType::Snapshot);
|
Packet firstSnapshot(MessageType::Snapshot);
|
||||||
addInputCommandsToPacket(firstSnapshot);
|
addInputCommandsToPacket(firstSnapshot);
|
||||||
|
|||||||
@@ -3,14 +3,25 @@
|
|||||||
using namespace boost::asio::ip;
|
using namespace boost::asio::ip;
|
||||||
|
|
||||||
TCPClient::TCPClient()
|
TCPClient::TCPClient()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
TCPClient::~TCPClient()
|
TCPClient::~TCPClient()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool TCPClient::Connect(std::string playerName, std::string address, int port)
|
bool TCPClient::Connect(std::string playerName, std::string address, int port)
|
||||||
{
|
{
|
||||||
if (!m_Socket) {
|
if (m_Socket) {
|
||||||
|
if (m_IsConnected) {
|
||||||
|
Packet packet(MessageType::Connect, m_SendPacketID);
|
||||||
|
packet.WriteString(playerName);
|
||||||
|
Send(packet);
|
||||||
|
LOG_INFO("Connect message sent again!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (!m_IsConnected) {
|
||||||
boost::system::error_code error = boost::asio::error::host_not_found;
|
boost::system::error_code error = boost::asio::error::host_not_found;
|
||||||
m_Endpoint = tcp::endpoint(boost::asio::ip::address::from_string(address), port);
|
m_Endpoint = tcp::endpoint(boost::asio::ip::address::from_string(address), port);
|
||||||
m_Socket = std::unique_ptr<tcp::socket>(new tcp::socket(m_IOService));
|
m_Socket = std::unique_ptr<tcp::socket>(new tcp::socket(m_IOService));
|
||||||
@@ -25,7 +36,9 @@ bool TCPClient::Connect(std::string playerName, std::string address, int port)
|
|||||||
Send(packet);
|
Send(packet);
|
||||||
LOG_INFO("Connect message sent!");
|
LOG_INFO("Connect message sent!");
|
||||||
return true;
|
return true;
|
||||||
} else { // If error
|
}
|
||||||
|
// If error
|
||||||
|
else {
|
||||||
m_Socket->close();
|
m_Socket->close();
|
||||||
m_Socket = nullptr;
|
m_Socket = nullptr;
|
||||||
return false;
|
return false;
|
||||||
@@ -35,9 +48,13 @@ bool TCPClient::Connect(std::string playerName, std::string address, int port)
|
|||||||
|
|
||||||
void TCPClient::Disconnect()
|
void TCPClient::Disconnect()
|
||||||
{
|
{
|
||||||
|
if (!m_IsConnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||||
m_Socket->close();
|
m_Socket->close();
|
||||||
m_Socket = nullptr;
|
m_Socket = nullptr;
|
||||||
|
m_IsConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPClient::Receive(Packet& packet)
|
void TCPClient::Receive(Packet& packet)
|
||||||
@@ -75,7 +92,7 @@ size_t TCPClient::readBuffer()
|
|||||||
while (sizeOfPacket > bytesReceived) {
|
while (sizeOfPacket > bytesReceived) {
|
||||||
// Read the rest of the message
|
// Read the rest of the message
|
||||||
bytesReceived += m_Socket->read_some(boost
|
bytesReceived += m_Socket->read_some(boost
|
||||||
::asio::buffer((void*)(m_ReadBuffer + bytesReceived), sizeOfPacket - bytesReceived),
|
::asio::buffer((void*)(m_ReadBuffer), sizeOfPacket - bytesReceived),
|
||||||
error);
|
error);
|
||||||
if (error) {
|
if (error) {
|
||||||
//LOG_ERROR("receive: %s", error.message().c_str());
|
//LOG_ERROR("receive: %s", error.message().c_str());
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ void TCPServer::Send(Packet & packet, PlayerDefinition & playerDefinition)
|
|||||||
{
|
{
|
||||||
packet.UpdateSize();
|
packet.UpdateSize();
|
||||||
try {
|
try {
|
||||||
// Crashed once TCPSocket was NULL
|
|
||||||
int bytesSent = playerDefinition.TCPSocket->send(
|
int bytesSent = playerDefinition.TCPSocket->send(
|
||||||
boost::asio::buffer(packet.Data(), packet.Size()),
|
boost::asio::buffer(packet.Data(), packet.Size()),
|
||||||
0);
|
0);
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#include "Network/UDPClient.h"
|
#include "Network/UDPClient.h"
|
||||||
#include "boost/asio/basic_datagram_socket.hpp"
|
|
||||||
|
|
||||||
using namespace boost::asio::ip;
|
using namespace boost::asio::ip;
|
||||||
|
|
||||||
UDPClient::UDPClient()
|
UDPClient::UDPClient()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
UDPClient::~UDPClient()
|
UDPClient::~UDPClient()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool UDPClient::Connect(std::string playerName, std::string address, int port)
|
bool UDPClient::Connect(std::string playerName, std::string address, int port)
|
||||||
{
|
{
|
||||||
@@ -17,20 +18,12 @@ bool UDPClient::Connect(std::string playerName, std::string address, int port)
|
|||||||
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address().from_string(address), port);
|
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address().from_string(address), port);
|
||||||
m_Socket = boost::shared_ptr<boost::asio::ip::udp::socket>(new boost::asio::ip::udp::socket(m_IOService));
|
m_Socket = boost::shared_ptr<boost::asio::ip::udp::socket>(new boost::asio::ip::udp::socket(m_IOService));
|
||||||
m_Socket->open(boost::asio::ip::udp::v4());
|
m_Socket->open(boost::asio::ip::udp::v4());
|
||||||
boost::asio::socket_base::receive_buffer_size option(m_SizeOfSocketBuffer);
|
|
||||||
m_Socket->set_option(option);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPClient::Disconnect()
|
void UDPClient::Disconnect()
|
||||||
{
|
{
|
||||||
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
|
||||||
m_Socket->close();
|
|
||||||
m_Socket = nullptr;
|
|
||||||
|
|
||||||
m_LastReceivedSnapshotGroup = 0;
|
|
||||||
m_PacketSegmentMap.clear();
|
|
||||||
PacketID m_SendPacketID = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPClient::Receive(Packet& packet)
|
void UDPClient::Receive(Packet& packet)
|
||||||
@@ -41,11 +34,6 @@ void UDPClient::Receive(Packet& packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPClient::ReceivePackets()
|
|
||||||
{
|
|
||||||
readPartOfPacket();
|
|
||||||
}
|
|
||||||
|
|
||||||
int UDPClient::readBuffer()
|
int UDPClient::readBuffer()
|
||||||
{
|
{
|
||||||
if (!m_Socket) {
|
if (!m_Socket) {
|
||||||
@@ -53,9 +41,9 @@ int UDPClient::readBuffer()
|
|||||||
}
|
}
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
// Read size of packet
|
// Read size of packet
|
||||||
m_Socket->receive(boost
|
m_Socket->receive(boost
|
||||||
::asio::buffer((void*)m_ReadBuffer, sizeof(int)),
|
::asio::buffer((void*)m_ReadBuffer, sizeof(int)),
|
||||||
boost::asio::ip::udp::socket::message_peek, error);
|
boost::asio::ip::udp::socket::message_peek, error);
|
||||||
int sizeOfPacket = 0;
|
int sizeOfPacket = 0;
|
||||||
memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int));
|
memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int));
|
||||||
if (sizeOfPacket > m_Socket->available()) {
|
if (sizeOfPacket > m_Socket->available()) {
|
||||||
@@ -84,72 +72,6 @@ int UDPClient::readBuffer()
|
|||||||
return bytesReceived;
|
return bytesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPClient::readPartOfPacket()
|
|
||||||
{
|
|
||||||
if (!m_Socket) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boost::system::error_code error;
|
|
||||||
// Peek header
|
|
||||||
m_Socket->receive(boost
|
|
||||||
::asio::buffer((void*)m_ReadBuffer, 5 * sizeof(int)),
|
|
||||||
boost::asio::ip::udp::socket::message_peek, error);
|
|
||||||
|
|
||||||
int sizeOfPacket = 0;
|
|
||||||
memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int));
|
|
||||||
if (sizeOfPacket == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int packetGroup = *reinterpret_cast<int*>(m_ReadBuffer + sizeof(int));
|
|
||||||
int packetGroupIndex = *reinterpret_cast<int*>(m_ReadBuffer + 2 * sizeof(int));
|
|
||||||
int packetGroupSize = *reinterpret_cast<int*>(m_ReadBuffer + 3 * sizeof(int));
|
|
||||||
//LOG_INFO("Packet group: %i. Group index: %i. Group size: %i. Packet size: %i.", packetGroup, packetGroupIndex, packetGroupSize, sizeOfPacket);
|
|
||||||
if (sizeOfPacket > m_Socket->available()) {
|
|
||||||
LOG_WARNING("UDPClient::readBuffer(): We haven't got the whole packet yet.");
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
// if the buffer is to small increase the size of it
|
|
||||||
boost::shared_ptr<char> packetData(new char[sizeOfPacket]);
|
|
||||||
|
|
||||||
// Read the message
|
|
||||||
size_t bytesReceived = m_Socket->receive_from(boost
|
|
||||||
::asio::buffer((void*)(packetData.get()),
|
|
||||||
sizeOfPacket),
|
|
||||||
m_ReceiverEndpoint, 0, error);
|
|
||||||
if (error) {
|
|
||||||
LOG_ERROR("UDPClient::readPartOfPacket: %s", error.message().c_str());
|
|
||||||
}
|
|
||||||
// Might want to do this earlier when i figure out a good way to
|
|
||||||
// remove data from network buffer.
|
|
||||||
if (hasReceivedPacket(packetGroup, packetGroupIndex)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// If group exists
|
|
||||||
PacketMap::iterator it;
|
|
||||||
it = m_PacketSegmentMap.find(packetGroup);
|
|
||||||
if (it != m_PacketSegmentMap.end()) {
|
|
||||||
it->second.push_back(std::make_pair(packetGroupIndex, std::move(packetData)));
|
|
||||||
} else { // Create group and add element
|
|
||||||
m_PacketSegmentMap[packetGroup].push_back(std::make_pair(packetGroupIndex, std::move(packetData)));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UDPClient::hasReceivedPacket(int packetGroup, int groupIndex)
|
|
||||||
{
|
|
||||||
PacketMap::iterator it;
|
|
||||||
it = m_PacketSegmentMap.find(packetGroup);
|
|
||||||
if (it != m_PacketSegmentMap.end()) {
|
|
||||||
const std::vector<std::pair<int, boost::shared_ptr<char>>>& loopPacketGroup = it->second;
|
|
||||||
for (size_t i = 0; i < loopPacketGroup.size(); i++) {
|
|
||||||
if (loopPacketGroup.at(i).first == groupIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UDPClient::Send(Packet& packet)
|
void UDPClient::Send(Packet& packet)
|
||||||
{
|
{
|
||||||
packet.UpdateSize();
|
packet.UpdateSize();
|
||||||
@@ -178,50 +100,3 @@ bool UDPClient::IsSocketAvailable()
|
|||||||
}
|
}
|
||||||
return m_Socket->available();
|
return m_Socket->available();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UDPClient::GetNextPacket(Packet & packet)
|
|
||||||
{
|
|
||||||
// A duplicate packet should not be present in the vector!
|
|
||||||
// Soo we will assume that this is true and only look if size
|
|
||||||
// of vector is correct.
|
|
||||||
PacketMap::iterator it = m_PacketSegmentMap.begin();
|
|
||||||
while (it != m_PacketSegmentMap.end()) {
|
|
||||||
// pair(Group index, packetData)
|
|
||||||
std::vector<std::pair<int, boost::shared_ptr<char>>>& currentVector = it->second;
|
|
||||||
Packet headerInfoPacket(currentVector.at(0).second.get(), packet.HeaderSize());
|
|
||||||
int groupSize = headerInfoPacket.GroupSize();
|
|
||||||
//LOG_INFO("UDPClient::GetNextPacket: Packet group : %i.Group index : %i.Group size : %i. lastReceivedSnapshotGroup: %i. MessageType(Ples 4): %i", headerInfoPacket.Group(), headerInfoPacket.GroupIndex(), groupSize, lastReceivedSnapshotGroup, headerInfoPacket.GetMessageType());
|
|
||||||
//LOG_INFO("UDPClient::GetNextPacket: Packet group : %i.lastReceivedSnapshotGroup: %i. MessageType(Ples 4): %i", headerInfoPacket.Group(), lastReceivedSnapshotGroup, headerInfoPacket.GetMessageType());
|
|
||||||
int mapSize = m_PacketSegmentMap.size();
|
|
||||||
if (mapSize > 5) {
|
|
||||||
it = m_PacketSegmentMap.erase(it);
|
|
||||||
LOG_INFO("The map is increasing in size, size is %i", mapSize);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (headerInfoPacket.GetMessageType() == MessageType::Snapshot && m_LastReceivedSnapshotGroup > headerInfoPacket.Group()) {
|
|
||||||
it = m_PacketSegmentMap.erase(it);
|
|
||||||
continue;
|
|
||||||
//LOG_INFO("Deleted old entry");
|
|
||||||
}
|
|
||||||
if (currentVector.size() == groupSize) {
|
|
||||||
std::sort(currentVector.begin(), currentVector.end());
|
|
||||||
// Add the first packet in vector
|
|
||||||
packet.ReconstructFromData(currentVector.at(0).second.get(), packet.HeaderSize());
|
|
||||||
// Add the rest of the packets.
|
|
||||||
int sizeOfData = 0;
|
|
||||||
for (auto& packetSegment : currentVector) {
|
|
||||||
memcpy(&sizeOfData, packetSegment.second.get(), sizeof(int));
|
|
||||||
packet.WriteData(packetSegment.second.get() + packet.HeaderSize(), sizeOfData - packet.HeaderSize());
|
|
||||||
}
|
|
||||||
if (headerInfoPacket.GetMessageType() == MessageType::Snapshot) {
|
|
||||||
m_LastReceivedSnapshotGroup = packet.Group();
|
|
||||||
}
|
|
||||||
// No need to get next it as we are returning.
|
|
||||||
m_PacketSegmentMap.erase(it);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,110 +12,34 @@ UDPServer::UDPServer(int port)
|
|||||||
|
|
||||||
UDPServer::~UDPServer()
|
UDPServer::~UDPServer()
|
||||||
{ }
|
{ }
|
||||||
// TODO: Fix correct groups
|
|
||||||
void UDPServer::Send(Packet& packet, PlayerDefinition& playerDefinition)
|
void UDPServer::Send(Packet& packet, PlayerDefinition & playerDefinition)
|
||||||
{
|
{
|
||||||
packet.UpdateSize();
|
packet.UpdateSize();
|
||||||
try {
|
try {
|
||||||
// Remove header from packet.
|
int bytesSent = m_Socket->send_to(
|
||||||
packet.ReadData(packet.HeaderSize());
|
boost::asio::buffer(packet.Data(), packet.Size()),
|
||||||
int totalBytesSent = 0;
|
playerDefinition.Endpoint,
|
||||||
int groupIndex = 1;
|
0);
|
||||||
int groupSize = std::ceil((float)packet.Size() / MAXPACKETSIZE);
|
LOG_INFO("Size of packet is %i", bytesSent);
|
||||||
int packetDataSent = 0;
|
|
||||||
int packetDataSize = packet.Size() - packet.HeaderSize();
|
|
||||||
|
|
||||||
while (packetDataSize > packetDataSent) {
|
|
||||||
Packet splitPacket(packet.GetMessageType(), playerDefinition.PacketID);
|
|
||||||
splitPacket.ChangeGroupIndex(groupIndex);
|
|
||||||
splitPacket.ChangeGroupSize(groupSize);
|
|
||||||
splitPacket.ChangeGroup(playerDefinition.PacketGroup);
|
|
||||||
int amountToSend = packetDataSize - packetDataSent;
|
|
||||||
if (amountToSend > MAXPACKETSIZE) {
|
|
||||||
amountToSend = MAXPACKETSIZE;
|
|
||||||
}
|
|
||||||
splitPacket.WriteData(packet.ReadData(amountToSend), amountToSend);
|
|
||||||
splitPacket.UpdateSize();
|
|
||||||
// Remove header size from bytes sent soo that we only
|
|
||||||
// count data in the packet
|
|
||||||
int bytesSent = 0;
|
|
||||||
bytesSent = m_Socket->send_to(
|
|
||||||
boost::asio::buffer(splitPacket.Data(), splitPacket.Size()),
|
|
||||||
playerDefinition.Endpoint,
|
|
||||||
0);
|
|
||||||
packetDataSent += bytesSent - splitPacket.HeaderSize();
|
|
||||||
totalBytesSent += bytesSent;
|
|
||||||
//LOG_INFO("bytesSent size %i, groupIndex: %i. Number of packets: %i", bytesSent, sequenceNumber, totalMessages);
|
|
||||||
++groupIndex;
|
|
||||||
}
|
|
||||||
playerDefinition.PacketGroup++;
|
|
||||||
} catch (const boost::system::system_error& e) {
|
} catch (const boost::system::system_error& e) {
|
||||||
LOG_INFO(e.what());
|
LOG_INFO(e.what());
|
||||||
// TODO: Clean up invalid endpoints out of m_ConnectedPlayers later
|
// TODO: Clean up invalid endpoints out of m_ConnectedPlayers later
|
||||||
playerDefinition.Endpoint = boost::asio::ip::udp::endpoint();
|
playerDefinition.Endpoint = boost::asio::ip::udp::endpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPServer::SendToConnectedPlayers(Packet& packet, std::map<PlayerID, PlayerDefinition>& playersTosendTo)
|
|
||||||
{
|
|
||||||
packet.UpdateSize();
|
|
||||||
// Remove header from packet.
|
|
||||||
packet.ReadData(packet.HeaderSize());
|
|
||||||
int totalBytesSent = 0;
|
|
||||||
int groupIndex = 1;
|
|
||||||
int groupSize = std::ceil((float)packet.Size() / MAXPACKETSIZE);
|
|
||||||
int packetDataSent = 0;
|
|
||||||
int packetDataSize = packet.Size() - packet.HeaderSize();
|
|
||||||
|
|
||||||
while (packetDataSize > packetDataSent) {
|
|
||||||
Packet splitPacket(packet.GetMessageType());
|
|
||||||
splitPacket.ChangeGroupIndex(groupIndex);
|
|
||||||
splitPacket.ChangeGroupSize(groupSize);
|
|
||||||
int amountToSend = packetDataSize - packetDataSent;
|
|
||||||
if (amountToSend > MAXPACKETSIZE) {
|
|
||||||
amountToSend = MAXPACKETSIZE;
|
|
||||||
}
|
|
||||||
splitPacket.WriteData(packet.ReadData(amountToSend), amountToSend);
|
|
||||||
splitPacket.UpdateSize();
|
|
||||||
// Remove header size from bytes sent soo that we only
|
|
||||||
// count data in the packet
|
|
||||||
int bytesSent = 0;
|
|
||||||
for (auto& kv : playersTosendTo) {
|
|
||||||
try {
|
|
||||||
splitPacket.ChangeGroup(kv.second.PacketGroup);
|
|
||||||
bytesSent = m_Socket->send_to(
|
|
||||||
boost::asio::buffer(splitPacket.Data(), splitPacket.Size()),
|
|
||||||
kv.second.Endpoint,
|
|
||||||
0);
|
|
||||||
// LOG_INFO("bytesSent: %i", bytesSent);
|
|
||||||
} catch (const boost::system::system_error& e) {
|
|
||||||
LOG_INFO("UDPServer::SendToConnectedPlayers: Disconnected client. %s", e.what());
|
|
||||||
// TODO: Clean up invalid endpoints out of m_ConnectedPlayers later
|
|
||||||
kv.second.Endpoint = boost::asio::ip::udp::endpoint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
packetDataSent += splitPacket.Size() - splitPacket.HeaderSize();
|
|
||||||
totalBytesSent += splitPacket.Size();
|
|
||||||
|
|
||||||
//LOG_INFO("bytesSent size %i, groupIndex: %i. Number of packets: %i", bytesSent, sequenceNumber, totalMessages);
|
|
||||||
++groupIndex;
|
|
||||||
}
|
|
||||||
for (auto& kv : playersTosendTo) {
|
|
||||||
kv.second.PacketGroup++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send back to endpoint of received packet
|
// Send back to endpoint of received packet
|
||||||
void UDPServer::Send(Packet & packet)
|
void UDPServer::Send(Packet & packet)
|
||||||
{
|
{
|
||||||
packet.UpdateSize();
|
packet.UpdateSize();
|
||||||
size_t bytesSent = m_Socket->send_to(
|
size_t bytesSent = m_Socket->send_to(
|
||||||
boost::asio::buffer(
|
boost::asio::buffer(
|
||||||
packet.Data(),
|
packet.Data(),
|
||||||
packet.Size()),
|
packet.Size()),
|
||||||
m_ReceiverEndpoint,
|
m_ReceiverEndpoint,
|
||||||
0);
|
0);
|
||||||
//LOG_INFO("Size of packet is %i", bytesSent);
|
LOG_INFO("Size of packet is %i", bytesSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcasting respond specific logic
|
// Broadcasting respond specific logic
|
||||||
@@ -128,7 +52,7 @@ void UDPServer::Send(Packet & packet, boost::asio::ip::udp::endpoint endpoint)
|
|||||||
packet.Size()),
|
packet.Size()),
|
||||||
endpoint,
|
endpoint,
|
||||||
0);
|
0);
|
||||||
//LOG_INFO("Size of packet is %i", bytesSent);
|
LOG_INFO("Size of packet is %i", bytesSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcasting
|
// Broadcasting
|
||||||
@@ -140,7 +64,7 @@ void UDPServer::Broadcast(Packet & packet, int port)
|
|||||||
boost::asio::buffer(
|
boost::asio::buffer(
|
||||||
packet.Data(),
|
packet.Data(),
|
||||||
packet.Size()),
|
packet.Size()),
|
||||||
boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4().broadcast(), port),
|
boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4().broadcast(),port),
|
||||||
0);
|
0);
|
||||||
m_Socket->set_option(boost::asio::socket_base::broadcast(false));
|
m_Socket->set_option(boost::asio::socket_base::broadcast(false));
|
||||||
}
|
}
|
||||||
@@ -167,7 +91,7 @@ int UDPServer::readBuffer()
|
|||||||
int addasdasd = m_Socket->available();
|
int addasdasd = m_Socket->available();
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
// Read size of packet
|
// Read size of packet
|
||||||
m_Socket->receive_from(boost
|
m_Socket->receive_from(boost
|
||||||
::asio::buffer((void*)m_ReadBuffer, sizeof(int)),
|
::asio::buffer((void*)m_ReadBuffer, sizeof(int)),
|
||||||
m_ReceiverEndpoint, boost::asio::ip::udp::socket::message_peek, error);
|
m_ReceiverEndpoint, boost::asio::ip::udp::socket::message_peek, error);
|
||||||
unsigned int sizeOfPacket = 0;
|
unsigned int sizeOfPacket = 0;
|
||||||
@@ -190,13 +114,13 @@ int UDPServer::readBuffer()
|
|||||||
::asio::buffer((void*)(m_ReadBuffer),
|
::asio::buffer((void*)(m_ReadBuffer),
|
||||||
sizeOfPacket),
|
sizeOfPacket),
|
||||||
m_ReceiverEndpoint, 0, error);
|
m_ReceiverEndpoint, 0, error);
|
||||||
if (error) {
|
if (error) {
|
||||||
//LOG_ERROR("receive: %s", error.message().c_str());
|
//LOG_ERROR("receive: %s", error.message().c_str());
|
||||||
}
|
}
|
||||||
if (sizeOfPacket > 1000000)
|
if (sizeOfPacket > 1000000)
|
||||||
LOG_WARNING("The packets received are bigger than 1MB");
|
LOG_WARNING("The packets received are bigger than 1MB");
|
||||||
|
|
||||||
return bytesReceived;
|
return bytesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPServer::AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers)
|
void UDPServer::AcceptNewConnections(int& nextPlayerID, std::map<PlayerID, PlayerDefinition>& connectedPlayers)
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ void DrawFinalPass::InitializeShaderPrograms()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass)
|
||||||
{
|
{
|
||||||
GLERROR("Pre");
|
GLERROR("Pre");
|
||||||
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
|
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
|
||||||
@@ -282,10 +282,36 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
|||||||
//state->StencilMask(0x00);
|
//state->StencilMask(0x00);
|
||||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
|
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
|
||||||
GLERROR("OpaqueObjects");
|
GLERROR("OpaqueObjects");
|
||||||
|
delete state;
|
||||||
|
|
||||||
|
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||||
|
if (scene.ShouldBlur) {
|
||||||
|
//Combine nonblur and blur texture
|
||||||
|
stateSprite->Disable(GL_DEPTH_TEST);
|
||||||
|
stateSprite->Disable(GL_STENCIL_TEST);
|
||||||
|
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
|
||||||
|
|
||||||
|
}
|
||||||
|
//Draw Transparen objects
|
||||||
|
//state->BlendFunc(GL_ONE, GL_ONE);
|
||||||
|
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
|
||||||
|
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
|
||||||
|
GLERROR("TransparentObjects");
|
||||||
|
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
stateSprite->Enable(GL_DEPTH_TEST);
|
||||||
|
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
|
||||||
|
//stateSprite->Enable(GL_ALPHA_TEST);
|
||||||
|
DrawSprites(scene.Jobs.SpriteJob, scene);
|
||||||
|
GLERROR("SpriteJobs");
|
||||||
|
|
||||||
|
delete stateSprite;
|
||||||
|
|
||||||
|
state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||||
|
|
||||||
//state->Disable(GL_STENCIL_TEST);
|
//state->Disable(GL_STENCIL_TEST);
|
||||||
//Draw Transparen Shielded objects
|
//Draw Transparen Shielded objects
|
||||||
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
textPass->Draw(scene, m_FinalPassFrameBuffer);
|
||||||
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
|
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
|
||||||
GLERROR("Shielded Transparent objects");
|
GLERROR("Shielded Transparent objects");
|
||||||
|
|
||||||
@@ -296,27 +322,7 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
|||||||
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
|
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
|
||||||
if(scene.ShouldBlur) {
|
|
||||||
//Combine nonblur and blur texture
|
|
||||||
stateSprite->Disable(GL_DEPTH_TEST);
|
|
||||||
stateSprite->Disable(GL_STENCIL_TEST);
|
|
||||||
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
|
|
||||||
|
|
||||||
}
|
|
||||||
//Draw Transparen objects
|
|
||||||
//state->BlendFunc(GL_ONE, GL_ONE);
|
|
||||||
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
|
|
||||||
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
|
|
||||||
GLERROR("TransparentObjects");
|
|
||||||
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
stateSprite->Enable(GL_DEPTH_TEST);
|
|
||||||
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
|
|
||||||
//stateSprite->Enable(GL_ALPHA_TEST);
|
|
||||||
DrawSprites(scene.Jobs.SpriteJob, scene);
|
|
||||||
GLERROR("SpriteJobs");
|
|
||||||
|
|
||||||
delete stateSprite;
|
|
||||||
GLERROR("END");
|
GLERROR("END");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,14 +210,15 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
|
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
|
||||||
m_LightCullingPass->CullLights(*scene);
|
m_LightCullingPass->CullLights(*scene);
|
||||||
GLERROR("LightCulling");
|
GLERROR("LightCulling");
|
||||||
|
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
|
||||||
|
//m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
|
||||||
|
GLERROR("Draw Text");
|
||||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
|
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
|
||||||
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
|
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass, m_TextPass);
|
||||||
GLERROR("Draw Geometry+Light");
|
GLERROR("Draw Geometry+Light");
|
||||||
//m_DrawScenePass->Draw(*scene);
|
//m_DrawScenePass->Draw(*scene);
|
||||||
|
|
||||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
|
|
||||||
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
|
|
||||||
GLERROR("Draw Text");
|
|
||||||
PerformanceTimer::StopTimer("Renderer-Draw Text");
|
PerformanceTimer::StopTimer("Renderer-Draw Text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void TextPass::Update()
|
|||||||
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
|
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
|
||||||
{
|
{
|
||||||
GLERROR("Derp1");
|
GLERROR("Derp1");
|
||||||
TextPassState* state = new TextPassState(frameBuffer.GetHandle());
|
//TextPassState* state = new TextPassState(frameBuffer.GetHandle());
|
||||||
for (auto &job : scene.Jobs.Text) {
|
for (auto &job : scene.Jobs.Text) {
|
||||||
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
||||||
if (textJob) {
|
if (textJob) {
|
||||||
@@ -43,7 +43,7 @@ void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GLERROR("Derp2");
|
GLERROR("Derp2");
|
||||||
delete state;
|
// delete state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
TextPassState::TextPassState(GLuint frameBuffer)
|
TextPassState::TextPassState(GLuint frameBuffer)
|
||||||
{
|
{
|
||||||
BindFramebuffer(frameBuffer);
|
BindFramebuffer(frameBuffer);
|
||||||
glEnable(GL_BLEND);
|
Enable(GL_BLEND);
|
||||||
glDisable(GL_CULL_FACE);
|
Disable(GL_CULL_FACE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
Enable(GL_DEPTH_TEST);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
Enable(GL_ALPHA_TEST);
|
||||||
|
AlphaFunc(GL_GEQUAL, 0.05f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextPassState::~TextPassState()
|
TextPassState::~TextPassState()
|
||||||
|
|||||||
@@ -264,11 +264,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
|||||||
size = glm::vec3(1.f, 1.f, 1.f);
|
size = glm::vec3(1.f, 1.f, 1.f);
|
||||||
} else {
|
} else {
|
||||||
size = glm::vec3(1.f, 1.6f, 1.f);
|
size = glm::vec3(1.f, 1.6f, 1.f);
|
||||||
if (controller->CrouchingLastFrame() && isOnGround) {
|
|
||||||
// The collision should resolve this anyway, but
|
|
||||||
// this is more reliable, since the box gets larger.
|
|
||||||
((glm::vec3&)cTransform["Position"]).y += 0.3f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
|
|||||||
, m_PickedTeam(-1)
|
, m_PickedTeam(-1)
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectatorCameraSystem::Update(double dt)
|
void SpectatorCameraSystem::Update(double dt)
|
||||||
@@ -89,16 +88,3 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e)
|
|
||||||
{
|
|
||||||
// If local player gets disconnected, they should be set to
|
|
||||||
// the spectator camera next time a map loads that has one.
|
|
||||||
if (e.Entity == LocalPlayer.ID) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user