Merge remote-tracking branch 'origin/master' into 3rdPersonDeathCam
# Conflicts: # include/Engine/Core/EPlayerHealthPickup.h
This commit is contained in:
@@ -7,11 +7,11 @@
|
|||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct PlayerHealthPickup : Event
|
struct PlayerHealthPickup : Event
|
||||||
{
|
{
|
||||||
EntityWrapper Player;
|
EntityWrapper Player;
|
||||||
double HealthAmount;
|
double HealthAmount;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,13 +200,16 @@ static T* ResourceManager::Load(const std::string& resourceName, Resource* paren
|
|||||||
}
|
}
|
||||||
|
|
||||||
//If resource has already been cached and completely loaded.
|
//If resource has already been cached and completely loaded.
|
||||||
it = m_ResourceCache.find(cacheKey);
|
{
|
||||||
if (it != m_ResourceCache.end()) {
|
boost::lock_guard<decltype(m_Mutex)> guard(m_Mutex);
|
||||||
if (it->second != nullptr) {
|
it = m_ResourceCache.find(cacheKey);
|
||||||
return static_cast<T*>(it->second);
|
if (it != m_ResourceCache.end()) {
|
||||||
} else {
|
if (it->second != nullptr) {
|
||||||
//Don't return null on failure, exception instead.
|
return static_cast<T*>(it->second);
|
||||||
throw Resource::FailedLoadingException();
|
} else {
|
||||||
|
//Don't return null on failure, exception instead.
|
||||||
|
throw Resource::FailedLoadingException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
#include "../Core/InputController.h"
|
#include "../Core/InputController.h"
|
||||||
#include "../Core/ELockMouse.h"
|
#include "../Core/ELockMouse.h"
|
||||||
|
#include "InputHandler.h"
|
||||||
|
|
||||||
template <typename EventContext>
|
template <typename EventContext>
|
||||||
class FirstPersonInputController : public InputController<EventContext>
|
class FirstPersonInputController : public InputController<EventContext>
|
||||||
@@ -25,6 +26,10 @@ public:
|
|||||||
virtual bool OnCommand(const Events::InputCommand& e) override;
|
virtual bool OnCommand(const Events::InputCommand& e) override;
|
||||||
virtual void Reset();
|
virtual void Reset();
|
||||||
|
|
||||||
|
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer);
|
||||||
|
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
|
||||||
|
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const int m_PlayerID;
|
const int m_PlayerID;
|
||||||
bool m_MouseLocked = false;
|
bool m_MouseLocked = false;
|
||||||
@@ -33,6 +38,22 @@ 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;
|
||||||
|
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||||
|
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||||
|
double m_AssaultDashCoolDownTimer = 0.0;
|
||||||
|
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||||
|
//and its very unlikely that someone wants to change that value
|
||||||
|
const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f;
|
||||||
|
std::string m_AssaultDashTapDirection = "";
|
||||||
|
std::string m_CurrentDirectionVector = "";
|
||||||
|
bool m_AssaultDashDoubleTapped = false;
|
||||||
|
bool m_PlayerIsDashing = false;
|
||||||
|
bool m_ShiftDashing = false;
|
||||||
|
bool m_ValidDoubleTap = false;
|
||||||
|
|
||||||
|
//specialabilitys
|
||||||
|
bool m_MovementKeyDown = false;
|
||||||
|
bool m_SpecialAbilityKeyDown = false;
|
||||||
|
|
||||||
EventRelay<EventContext, Events::LockMouse> m_ELockMouse;
|
EventRelay<EventContext, Events::LockMouse> m_ELockMouse;
|
||||||
bool OnLockMouse(const Events::LockMouse& e);
|
bool OnLockMouse(const Events::LockMouse& e);
|
||||||
@@ -104,6 +125,26 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.Command == "Forward" || e.Command == "Right") {
|
||||||
|
if (e.Value != 0) {
|
||||||
|
m_CurrentDirectionVector = e.Command == "Right" ? (e.Value > 0 ? "Right" : "Left") : (e.Value > 0 ? "Forward" : "Backward");
|
||||||
|
}
|
||||||
|
//if value = 0 then you have just released this key
|
||||||
|
if (e.Value != 0) {
|
||||||
|
m_MovementKeyDown = true;
|
||||||
|
//if you pressed the same key within m_AssaultDashDoubleTapSensitivityTimer then you have doubletapped it
|
||||||
|
if (m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer && m_AssaultDashTapDirection == m_CurrentDirectionVector) {
|
||||||
|
m_ValidDoubleTap = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//== 0
|
||||||
|
m_MovementKeyDown = false;
|
||||||
|
//you have just released the key, store what key it was and reset the doubletap-sensitivity-timer
|
||||||
|
m_AssaultDashTapDirection = m_CurrentDirectionVector;
|
||||||
|
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e.Command == "Jump") {
|
if (e.Command == "Jump") {
|
||||||
m_Jumping = e.Value > 0;
|
m_Jumping = e.Value > 0;
|
||||||
}
|
}
|
||||||
@@ -112,6 +153,19 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
|
|||||||
m_Crouching = e.Value > 0;
|
m_Crouching = e.Value > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.Command == "SpecialAbility") {
|
||||||
|
if (e.Value > 0) {
|
||||||
|
m_SpecialAbilityKeyDown = true;
|
||||||
|
} else {
|
||||||
|
m_SpecialAbilityKeyDown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_SpecialAbilityKeyDown && m_MovementKeyDown) {
|
||||||
|
m_ShiftDashing = true;
|
||||||
|
} else {
|
||||||
|
m_ShiftDashing = false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,4 +183,53 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename EventContext>
|
||||||
|
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) {
|
||||||
|
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||||
|
m_AssaultDashCoolDownTimer -= dt;
|
||||||
|
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||||
|
if (m_AssaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
|
||||||
|
m_PlayerIsDashing = true;
|
||||||
|
} else {
|
||||||
|
m_PlayerIsDashing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//dashing with shift
|
||||||
|
if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) {
|
||||||
|
//player is dashing with shift
|
||||||
|
//the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in!
|
||||||
|
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||||
|
m_AssaultDashDoubleTapped = true;
|
||||||
|
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||||
|
//moving to the side has priority
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//dashing with doubletap - check if doubletap to dash enabled
|
||||||
|
if (ResourceManager::Load<ConfigFile>("Input.ini")->Get<bool>("Keyboard.DoubleTapToDash", false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset the DoubleTapped state in case we recently doubleTapped (doubletap will only happen during 1 frame)
|
||||||
|
if (m_AssaultDashDoubleTapped) {
|
||||||
|
m_AssaultDashDoubleTapped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if we have received a valid doubletap
|
||||||
|
if (!m_ValidDoubleTap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_ValidDoubleTap = false;
|
||||||
|
|
||||||
|
if (!(m_AssaultDashCoolDownTimer <= 0.0f && !isJumping)) {
|
||||||
|
//if we cant dash at the moment, then just reset the tap-sensitivity-timer
|
||||||
|
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//ok, we have a valid tap, lets do it
|
||||||
|
m_AssaultDashDoubleTapped = true;
|
||||||
|
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||||
|
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -36,7 +36,7 @@ private:
|
|||||||
boost::asio::ip::udp::socket m_Socket;
|
boost::asio::ip::udp::socket m_Socket;
|
||||||
|
|
||||||
// Sending message to server logic
|
// Sending message to server logic
|
||||||
int bytesRead = -1;
|
size_t bytesRead = 0;
|
||||||
char readBuf[INPUTSIZE] = { 0 };
|
char readBuf[INPUTSIZE] = { 0 };
|
||||||
|
|
||||||
// Packet loss logic
|
// Packet loss logic
|
||||||
@@ -69,7 +69,7 @@ private:
|
|||||||
|
|
||||||
// Private member functions
|
// Private member functions
|
||||||
void readFromServer();
|
void readFromServer();
|
||||||
int receive(char* data);
|
size_t receive(char* data);
|
||||||
void send(Packet& packet);
|
void send(Packet& packet);
|
||||||
void connect();
|
void connect();
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ protected:
|
|||||||
unsigned int m_SaveDataIntervalMs = 1000;
|
unsigned int m_SaveDataIntervalMs = 1000;
|
||||||
std::clock_t m_SaveDataTimer;
|
std::clock_t m_SaveDataTimer;
|
||||||
unsigned int m_MaxConnections;
|
unsigned int m_MaxConnections;
|
||||||
unsigned int m_TimeoutMs;
|
double m_TimeoutMs;
|
||||||
void saveToFile();
|
void saveToFile();
|
||||||
void updateNetworkData();
|
void updateNetworkData();
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct NetworkData {
|
struct NetworkData {
|
||||||
unsigned int TotalTime = 0;
|
double TotalTime = 0;
|
||||||
unsigned int TotalDataReceived = 0;
|
size_t TotalDataReceived = 0;
|
||||||
unsigned int TotalDataSent = 0;
|
size_t TotalDataSent = 0;
|
||||||
unsigned int AmountOfMessagesReceived = 0;
|
size_t AmountOfMessagesReceived = 0;
|
||||||
unsigned int AmountOfMessagesSent = 0;
|
unsigned int AmountOfMessagesSent = 0;
|
||||||
// Interval based
|
// Interval based
|
||||||
unsigned int DataReceivedThisInterval = 0;
|
size_t DataReceivedThisInterval = 0;
|
||||||
unsigned int DataSentThisInterval = 0;
|
size_t DataSentThisInterval = 0;
|
||||||
// pair: first=reveived, second=send
|
// pair: first=reveived, second=send
|
||||||
std::vector<std::pair<unsigned int, unsigned int>> BandwidthBytes;
|
std::vector<std::pair<size_t, size_t>> BandwidthBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
// arg2: PacketID for identifying packet loss.
|
// arg2: PacketID for identifying packet loss.
|
||||||
Packet(MessageType type, unsigned int& packetID);
|
Packet(MessageType type, unsigned int& packetID);
|
||||||
// Used to create packet from already existing data buffer.
|
// Used to create packet from already existing data buffer.
|
||||||
Packet(char* data, const int 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);
|
||||||
@@ -51,18 +51,18 @@ public:
|
|||||||
std::string ReadString();
|
std::string ReadString();
|
||||||
char* ReadData(int SizeOfData);
|
char* ReadData(int SizeOfData);
|
||||||
void ChangePacketID(unsigned int& packetID);
|
void ChangePacketID(unsigned int& packetID);
|
||||||
int Size() { return m_Offset; };
|
size_t Size() { return m_Offset; };
|
||||||
char* Data() { return m_Data; };
|
char* Data() { return m_Data; };
|
||||||
unsigned int DataReadSize() { return m_ReturnDataOffset; }
|
size_t DataReadSize() { return m_ReturnDataOffset; }
|
||||||
unsigned int MaxSize() { return m_MaxPacketSize; }
|
size_t MaxSize() { return m_MaxPacketSize; }
|
||||||
unsigned int HeaderSize() { return m_HeaderSize; }
|
size_t HeaderSize() { return m_HeaderSize; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* m_Data;
|
char* m_Data;
|
||||||
unsigned int m_ReturnDataOffset = 0;
|
size_t m_ReturnDataOffset = 0;
|
||||||
int m_Offset = 0;
|
size_t m_Offset = 0;
|
||||||
unsigned int m_MaxPacketSize = 512;
|
size_t m_MaxPacketSize = 512;
|
||||||
unsigned int m_HeaderSize = 0;
|
size_t m_HeaderSize = 0;
|
||||||
void resizeData();
|
void resizeData();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ private:
|
|||||||
std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers;
|
std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers;
|
||||||
// HACK: Fix INPUTSIZE
|
// HACK: Fix INPUTSIZE
|
||||||
char readBuffer[INPUTSIZE] = { 0 };
|
char readBuffer[INPUTSIZE] = { 0 };
|
||||||
int bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
// time for previouse message
|
// time for previouse message
|
||||||
std::clock_t previousePingMessage = std::clock();
|
std::clock_t previousePingMessage = std::clock();
|
||||||
std::clock_t previousSnapshotMessage = std::clock();
|
std::clock_t previousSnapshotMessage = std::clock();
|
||||||
std::clock_t timOutTimer = std::clock();
|
std::clock_t timOutTimer = std::clock();
|
||||||
// How often we send messages (milliseconds)
|
// How often we send messages (milliseconds)
|
||||||
int pingIntervalMs;
|
float pingIntervalMs;
|
||||||
int snapshotInterval;
|
float snapshotInterval;
|
||||||
int checkTimeOutInterval = 100;
|
int checkTimeOutInterval = 100;
|
||||||
int m_NextPlayerID = 0;
|
int m_NextPlayerID = 0;
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ private:
|
|||||||
PacketID m_PreviousPacketID = 0;
|
PacketID m_PreviousPacketID = 0;
|
||||||
|
|
||||||
// Private member functions
|
// Private member functions
|
||||||
int receive(char* data);
|
size_t receive(char* data);
|
||||||
void readFromClients();
|
void readFromClients();
|
||||||
void send(PlayerID player, Packet& packet);
|
void send(PlayerID player, Packet& packet);
|
||||||
void send(Packet& packet);
|
void send(Packet& packet);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class InterpolationSystem : public PureSystem
|
|||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
glm::vec3 Scale;
|
glm::vec3 Scale;
|
||||||
glm::quat Orientation;
|
glm::quat Orientation;
|
||||||
double interpolationTime;
|
float interpolationTime;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
InterpolationSystem(World* world, EventBroker* eventBroker);
|
InterpolationSystem(World* world, EventBroker* eventBroker);
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ private:
|
|||||||
|
|
||||||
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -13,7 +13,8 @@ A=Right,-1
|
|||||||
R=Reload
|
R=Reload
|
||||||
Space=Jump
|
Space=Jump
|
||||||
LeftControl=Crouch
|
LeftControl=Crouch
|
||||||
LeftShift=Sprint
|
RightShift=Sprint
|
||||||
|
LeftShift=SpecialAbility
|
||||||
F1=ToggleEditor
|
F1=ToggleEditor
|
||||||
C=ConnectToServer
|
C=ConnectToServer
|
||||||
N=SwitchToServer
|
N=SwitchToServer
|
||||||
|
|||||||
@@ -30,4 +30,5 @@
|
|||||||
<xs:include schemaLocation="Components/Fill.xsd"/>
|
<xs:include schemaLocation="Components/Fill.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Lifetime.xsd"/>
|
<xs:include schemaLocation="Components/Lifetime.xsd"/>
|
||||||
<xs:include schemaLocation="Components/HiddenForLocalPlayer.xsd"/>
|
<xs:include schemaLocation="Components/HiddenForLocalPlayer.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/DashAbility.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<DashAbility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DashAbility.xsd">
|
||||||
|
<CoolDownMaxTimer>2.0</CoolDownMaxTimer>
|
||||||
|
</DashAbility>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="DashAbility">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>A dash component for one of the classes</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="CoolDownMaxTimer" type="t:double" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>This is the cooldown on dash</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<c:AABB/>
|
<c:AABB/>
|
||||||
<c:CapturePoint/>
|
<c:CapturePoint/>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
|
<Resource>Models/Core/UnitSphere.mesh</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Team/>
|
<c:Team/>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
<Origin X="0" Y="0.772000015" Z="0"/>
|
<Origin X="0" Y="0.772000015" Z="0"/>
|
||||||
<Size X="1" Y="1.60000002" Z="1"/>
|
<Size X="1" Y="1.60000002" Z="1"/>
|
||||||
</c:AABB>
|
</c:AABB>
|
||||||
|
<c:DashAbility>
|
||||||
|
<CoolDownMaxTimer>2.0</CoolDownMaxTimer>
|
||||||
|
</c:DashAbility>
|
||||||
<c:Collidable/>
|
<c:Collidable/>
|
||||||
<c:Health/>
|
<c:Health/>
|
||||||
<c:Physics>
|
<c:Physics>
|
||||||
@@ -101,13 +104,6 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
<Entity name="Weapon">
|
<Entity name="Weapon">
|
||||||
<Components>
|
<Components>
|
||||||
<c:ExplosionEffect>
|
|
||||||
<ColorByDistance>true</ColorByDistance>
|
|
||||||
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
|
|
||||||
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
|
|
||||||
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
|
|
||||||
<Randomness>true</Randomness>
|
|
||||||
</c:ExplosionEffect>
|
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/AssaultWeaponRed.mesh</Resource>
|
<Resource>Models/AssaultWeaponRed.mesh</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
|
|||||||
@@ -258,11 +258,11 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::receive(char* data)
|
size_t Client::receive(char* data)
|
||||||
{
|
{
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
|
|
||||||
int bytesReceived = m_Socket.receive_from(boost
|
size_t bytesReceived = m_Socket.receive_from(boost
|
||||||
::asio::buffer((void*)data, INPUTSIZE),
|
::asio::buffer((void*)data, INPUTSIZE),
|
||||||
m_ReceiverEndpoint,
|
m_ReceiverEndpoint,
|
||||||
0, error);
|
0, error);
|
||||||
@@ -390,7 +390,7 @@ void Client::identifyPacketLoss()
|
|||||||
bool Client::hasServerTimedOut()
|
bool Client::hasServerTimedOut()
|
||||||
{
|
{
|
||||||
// Time in ms
|
// Time in ms
|
||||||
float timeSincePing = 1000 * (std::clock() - m_StartPingTime) / static_cast<double>(CLOCKS_PER_SEC);
|
double timeSincePing = 1000 * (std::clock() - m_StartPingTime) / static_cast<double>(CLOCKS_PER_SEC);
|
||||||
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.");
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ void Network::saveToFile()
|
|||||||
outfile << "Total messages received," + std::to_string(m_NetworkData.AmountOfMessagesReceived) + "\n";
|
outfile << "Total messages received," + std::to_string(m_NetworkData.AmountOfMessagesReceived) + "\n";
|
||||||
outfile << "Total messages sent," + std::to_string(m_NetworkData.AmountOfMessagesSent) + "\n";
|
outfile << "Total messages sent," + std::to_string(m_NetworkData.AmountOfMessagesSent) + "\n";
|
||||||
|
|
||||||
float messagesReceivedPerSec = (float)m_NetworkData.AmountOfMessagesReceived / (m_NetworkData.TotalTime / 1000);
|
double messagesReceivedPerSec = m_NetworkData.AmountOfMessagesReceived / (m_NetworkData.TotalTime / 1000);
|
||||||
float messagesSentPerSec = (float)m_NetworkData.AmountOfMessagesSent / (m_NetworkData.TotalTime / 1000);
|
double messagesSentPerSec = m_NetworkData.AmountOfMessagesSent / (m_NetworkData.TotalTime / 1000);
|
||||||
float dataReceivedPerSec = (float)m_NetworkData.TotalDataReceived / (m_NetworkData.TotalTime / 1000);
|
double dataReceivedPerSec = m_NetworkData.TotalDataReceived / (m_NetworkData.TotalTime / 1000);
|
||||||
float dataSentPerSec = (float)m_NetworkData.TotalDataSent / (m_NetworkData.TotalTime / 1000);
|
double dataSentPerSec = m_NetworkData.TotalDataSent / (m_NetworkData.TotalTime / 1000);
|
||||||
outfile << "Avarage messages received / s: " + std::to_string(messagesReceivedPerSec) + "\n";
|
outfile << "Avarage messages received / s: " + std::to_string(messagesReceivedPerSec) + "\n";
|
||||||
outfile << "Avarage messages sents / s: " + std::to_string(messagesSentPerSec) + "\n";
|
outfile << "Avarage messages sents / s: " + std::to_string(messagesSentPerSec) + "\n";
|
||||||
outfile << "Avarage data received B/s: " + std::to_string(dataReceivedPerSec) + "\n";
|
outfile << "Avarage data received B/s: " + std::to_string(dataReceivedPerSec) + "\n";
|
||||||
@@ -52,7 +52,7 @@ void Network::updateNetworkData()
|
|||||||
if (m_SaveDataIntervalMs < (1000 * (currentTime - m_SaveDataTimer) / (double)CLOCKS_PER_SEC)) {
|
if (m_SaveDataIntervalMs < (1000 * (currentTime - m_SaveDataTimer) / (double)CLOCKS_PER_SEC)) {
|
||||||
// Set values
|
// Set values
|
||||||
m_NetworkData.TotalTime += (1000 * (currentTime - m_SaveDataTimer) / (double)CLOCKS_PER_SEC);
|
m_NetworkData.TotalTime += (1000 * (currentTime - m_SaveDataTimer) / (double)CLOCKS_PER_SEC);
|
||||||
m_NetworkData.BandwidthBytes.push_back(std::pair<unsigned int, unsigned int>(m_NetworkData.DataReceivedThisInterval, m_NetworkData.DataSentThisInterval));
|
m_NetworkData.BandwidthBytes.push_back(std::pair<size_t, size_t>(m_NetworkData.DataReceivedThisInterval, m_NetworkData.DataSentThisInterval));
|
||||||
// Reset interval stuff
|
// Reset interval stuff
|
||||||
m_SaveDataTimer = std::clock();
|
m_SaveDataTimer = std::clock();
|
||||||
m_NetworkData.DataSentThisInterval = 0;
|
m_NetworkData.DataSentThisInterval = 0;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Packet::Packet(MessageType type, unsigned int& packetID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create message
|
// Create message
|
||||||
Packet::Packet(char* data, const int sizeOfPacket)
|
Packet::Packet(char* data, const size_t sizeOfPacket)
|
||||||
{
|
{
|
||||||
// Resize message
|
// Resize message
|
||||||
m_MaxPacketSize = sizeOfPacket;
|
m_MaxPacketSize = sizeOfPacket;
|
||||||
@@ -45,7 +45,7 @@ void Packet::Init(MessageType type, unsigned int & packetID)
|
|||||||
void Packet::WriteString(const std::string& str)
|
void Packet::WriteString(const std::string& str)
|
||||||
{
|
{
|
||||||
// Message, add one extra byte for null terminator
|
// Message, add one extra byte for null terminator
|
||||||
int sizeOfString = str.size() + 1;
|
size_t sizeOfString = str.size() + 1;
|
||||||
if (m_Offset + sizeOfString > m_MaxPacketSize) {
|
if (m_Offset + sizeOfString > m_MaxPacketSize) {
|
||||||
//LOG_WARNING("Package::WriteString(): Data size in packet exceeded maximum package size. New size is %i bytes\n", m_MaxPacketSize*2);
|
//LOG_WARNING("Package::WriteString(): Data size in packet exceeded maximum package size. New size is %i bytes\n", m_MaxPacketSize*2);
|
||||||
resizeData();
|
resizeData();
|
||||||
@@ -82,7 +82,7 @@ char * Packet::ReadData(int SizeOfData)
|
|||||||
//LOG_WARNING("packet ReadData(): Oh no! You are trying to remove things outside my memory kingdom");
|
//LOG_WARNING("packet ReadData(): Oh no! You are trying to remove things outside my memory kingdom");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
unsigned int oldReturnDataOffset = m_ReturnDataOffset;
|
size_t oldReturnDataOffset = m_ReturnDataOffset;
|
||||||
m_ReturnDataOffset += SizeOfData;
|
m_ReturnDataOffset += SizeOfData;
|
||||||
return (m_Data + oldReturnDataOffset);
|
return (m_Data + oldReturnDataOffset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::a
|
|||||||
{
|
{
|
||||||
Network::initialize();
|
Network::initialize();
|
||||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05);
|
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
|
||||||
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
|
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ void Server::readFromClients()
|
|||||||
bytesRead = receive(readBuffer);
|
bytesRead = receive(readBuffer);
|
||||||
Packet packet(readBuffer, bytesRead);
|
Packet packet(readBuffer, bytesRead);
|
||||||
parseMessageType(packet);
|
parseMessageType(packet);
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception&) {
|
||||||
//LOG_ERROR("%i: Read from client crashed %s", m_PacketID, err.what());
|
//LOG_ERROR("%i: Read from client crashed %s", m_PacketID, err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,9 +103,9 @@ void Server::parseMessageType(Packet& packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::receive(char * data)
|
size_t Server::receive(char * data)
|
||||||
{
|
{
|
||||||
unsigned int length = m_Socket.receive_from(
|
size_t length = m_Socket.receive_from(
|
||||||
boost::asio::buffer((void*)data
|
boost::asio::buffer((void*)data
|
||||||
, INPUTSIZE)
|
, INPUTSIZE)
|
||||||
, m_ReceiverEndpoint, 0);
|
, m_ReceiverEndpoint, 0);
|
||||||
@@ -121,7 +121,7 @@ int Server::receive(char * data)
|
|||||||
void Server::send(PlayerID player, Packet& packet)
|
void Server::send(PlayerID player, Packet& packet)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
int bytesSent = m_Socket.send_to(
|
size_t bytesSent = m_Socket.send_to(
|
||||||
boost::asio::buffer(packet.Data(), packet.Size()),
|
boost::asio::buffer(packet.Data(), packet.Size()),
|
||||||
m_ConnectedPlayers[player].Endpoint,
|
m_ConnectedPlayers[player].Endpoint,
|
||||||
0);
|
0);
|
||||||
@@ -131,7 +131,7 @@ void Server::send(PlayerID player, Packet& packet)
|
|||||||
m_NetworkData.DataSentThisInterval += packet.Size();
|
m_NetworkData.DataSentThisInterval += packet.Size();
|
||||||
m_NetworkData.AmountOfMessagesSent++;
|
m_NetworkData.AmountOfMessagesSent++;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error& e) {
|
} catch (const boost::system::system_error&) {
|
||||||
// TODO: Clean up invalid endpoints out of m_ConnectedPlayers later
|
// TODO: Clean up invalid endpoints out of m_ConnectedPlayers later
|
||||||
m_ConnectedPlayers[player].Endpoint = boost::asio::ip::udp::endpoint();
|
m_ConnectedPlayers[player].Endpoint = boost::asio::ip::udp::endpoint();
|
||||||
}
|
}
|
||||||
@@ -231,12 +231,12 @@ void Server::sendPing()
|
|||||||
|
|
||||||
void Server::checkForTimeOuts()
|
void Server::checkForTimeOuts()
|
||||||
{
|
{
|
||||||
int startPing = 1000 * m_StartPingTime
|
double startPing = 1000 * m_StartPingTime
|
||||||
/ static_cast<double>(CLOCKS_PER_SEC);
|
/ static_cast<double>(CLOCKS_PER_SEC);
|
||||||
|
|
||||||
for (int i = 0; i < m_ConnectedPlayers.size(); i++) {
|
for (int i = 0; i < m_ConnectedPlayers.size(); i++) {
|
||||||
if (m_ConnectedPlayers[i].Endpoint.address() != boost::asio::ip::address()) {
|
if (m_ConnectedPlayers[i].Endpoint.address() != boost::asio::ip::address()) {
|
||||||
int stopPing = 1000 * m_ConnectedPlayers[i].StopTime /
|
double stopPing = 1000 * m_ConnectedPlayers[i].StopTime /
|
||||||
static_cast<double>(CLOCKS_PER_SEC);
|
static_cast<double>(CLOCKS_PER_SEC);
|
||||||
if (startPing > stopPing + m_TimeoutMs) {
|
if (startPing > stopPing + m_TimeoutMs) {
|
||||||
LOG_INFO("User %i timed out!", i);
|
LOG_INFO("User %i timed out!", i);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLf
|
|||||||
|
|
||||||
DrawScreenQuadPassState state = DrawScreenQuadPassState();
|
DrawScreenQuadPassState state = DrawScreenQuadPassState();
|
||||||
m_ColorCorrectionProgram->Bind();
|
m_ColorCorrectionProgram->Bind();
|
||||||
//glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), exposure);
|
glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), exposure);
|
||||||
glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Gamma"), gamma);
|
glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Gamma"), gamma);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ InterpolationSystem::InterpolationSystem(World* world, EventBroker* eventBroker)
|
|||||||
, PureSystem("Transform")
|
, PureSystem("Transform")
|
||||||
{
|
{
|
||||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
m_SnapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05);
|
m_SnapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05f);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInterpolate, &InterpolationSystem::OnInterpolate);
|
EVENT_SUBSCRIBE_MEMBER(m_EInterpolate, &InterpolationSystem::OnInterpolate);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &InterpolationSystem::OnPlayerSpawned);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &InterpolationSystem::OnPlayerSpawned);
|
||||||
}
|
}
|
||||||
@@ -18,9 +18,9 @@ void InterpolationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_NextTransform.find(transform.EntityID) != m_NextTransform.end()) { // Exists in map
|
if (m_NextTransform.find(transform.EntityID) != m_NextTransform.end()) { // Exists in map
|
||||||
m_NextTransform[transform.EntityID].interpolationTime += dt;
|
m_NextTransform[transform.EntityID].interpolationTime += static_cast<float>(dt);
|
||||||
Transform sTransform = m_NextTransform[transform.EntityID];
|
Transform sTransform = m_NextTransform[transform.EntityID];
|
||||||
double time = sTransform.interpolationTime;
|
float time = sTransform.interpolationTime;
|
||||||
if (time > m_SnapshotInterval) {
|
if (time > m_SnapshotInterval) {
|
||||||
if (m_LastReceivedTransform.find(transform.EntityID) != m_LastReceivedTransform.end()) {
|
if (m_LastReceivedTransform.find(transform.EntityID) != m_LastReceivedTransform.end()) {
|
||||||
m_NextTransform[transform.EntityID] = m_LastReceivedTransform[transform.EntityID];
|
m_NextTransform[transform.EntityID] = m_LastReceivedTransform[transform.EntityID];
|
||||||
|
|||||||
@@ -41,8 +41,15 @@ void PlayerMovementSystem::Update(double dt)
|
|||||||
|
|
||||||
if (player.HasComponent("Physics")) {
|
if (player.HasComponent("Physics")) {
|
||||||
ComponentWrapper cPhysics = player["Physics"];
|
ComponentWrapper cPhysics = player["Physics"];
|
||||||
|
//Assault Dash Check
|
||||||
|
if (player.HasComponent("DashAbility")) {
|
||||||
|
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"]);
|
||||||
|
}
|
||||||
glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
|
glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
|
||||||
|
//this makes sure you can only dash in the 4 directions: forw,backw,left,right
|
||||||
|
if (controller->AssaultDashDoubleTapped() && controller->Movement().z != 0 && controller->Movement().x != 0) {
|
||||||
|
wishDirection = glm::vec3(controller->Movement().x, 0, 0)* glm::inverse(glm::quat(ori));
|
||||||
|
}
|
||||||
float wishSpeed;
|
float wishSpeed;
|
||||||
if (controller->Crouching()) {
|
if (controller->Crouching()) {
|
||||||
wishSpeed = playerCrouchSpeed;
|
wishSpeed = playerCrouchSpeed;
|
||||||
@@ -71,16 +78,18 @@ void PlayerMovementSystem::Update(double dt)
|
|||||||
static float surfaceFriction = 5.f;
|
static float surfaceFriction = 5.f;
|
||||||
ImGui::InputFloat("surfaceFriction", &surfaceFriction);
|
ImGui::InputFloat("surfaceFriction", &surfaceFriction);
|
||||||
float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction;
|
float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction;
|
||||||
accelerationSpeed = glm::min(accelerationSpeed, addSpeed);
|
//if doubleTapped do Assault Dash - but only boost maximum 50.0f
|
||||||
|
float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f;
|
||||||
|
accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f);
|
||||||
velocity += accelerationSpeed * wishDirection;
|
velocity += accelerationSpeed * wishDirection;
|
||||||
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
|
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) {
|
//you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air
|
||||||
|
if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) {
|
||||||
if (velocity.y == 0.f) {
|
if (velocity.y == 0.f) {
|
||||||
controller->SetDoubleJumping(false);
|
controller->SetDoubleJumping(false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
controller->SetDoubleJumping(true);
|
controller->SetDoubleJumping(true);
|
||||||
}
|
}
|
||||||
velocity.y += 4.f;
|
velocity.y += 4.f;
|
||||||
@@ -101,6 +110,7 @@ void PlayerMovementSystem::Update(double dt)
|
|||||||
ComponentWrapper cAnimation = playerModel["Animation"];
|
ComponentWrapper cAnimation = playerModel["Animation"];
|
||||||
|
|
||||||
float movementLength = glm::length(groundVelocity);
|
float movementLength = glm::length(groundVelocity);
|
||||||
|
//TODO: add assault dash animation here
|
||||||
if (glm::length(controller->Movement()) > 0.f) {
|
if (glm::length(controller->Movement()) > 0.f) {
|
||||||
if (controller->Crouching()) {
|
if (controller->Crouching()) {
|
||||||
cAnimation["Name"] = "Crouch Walk";
|
cAnimation["Name"] = "Crouch Walk";
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ GameHealthSystemTest::GameHealthSystemTest()
|
|||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_World,m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
||||||
|
|
||||||
//The Test
|
//The Test
|
||||||
|
|||||||
Reference in New Issue
Block a user