Compare commits

..

2 Commits

Author SHA1 Message Date
Jocke b547938928 timestep logic added, but is not used. 2016-02-19 13:24:06 +01:00
Jocke d1832c1741 WIP Timestamps 2016-02-17 17:07:17 +01:00
34 changed files with 139 additions and 5670 deletions
+2
View File
@@ -16,6 +16,8 @@ struct InputCommand : Event
std::string Command;
/** The value of the command. */
float Value = 0;
/** Timestamp of the command. */
double TimeStamp = 0;
};
}
@@ -28,7 +28,6 @@ public:
virtual void Reset();
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer);
bool SniperSprintingCheck();
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
@@ -203,7 +202,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
}
//dashing with shift
if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f) {
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;
@@ -228,7 +227,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
}
m_ValidDoubleTap = false;
if (!(m_AssaultDashCoolDownTimer <= 0.0f)) {
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;
@@ -242,12 +241,4 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
m_EventBroker->Publish(e);
}
template <typename EventContext>
bool FirstPersonInputController<EventContext>::SniperSprintingCheck() {
if (m_SpecialAbilityKeyDown) {
return true;
} else {
return false;
}
}
#endif
+7 -8
View File
@@ -33,8 +33,8 @@ public:
~Client();
void Connect(std::string address, int port);
void Update() override;
void Update(double dt) override;
private:
std::vector<Events::PlayerSpawned> m_PlayerSpawnEvents;
void parseSpawnEvents();
// Save for children
@@ -56,13 +56,13 @@ public:
bool m_IsConnected = false;
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
// Server Client Lookup map
// Assumes that root node for client and server is EntityID 0.
// Don't Add items to these two maps with insert, use insertIntoServerClientMaps(EntityID, EntityID)!!!!
std::unordered_map<EntityID, EntityID> m_ServerIDToClientID;
std::unordered_map<EntityID, EntityID> m_ClientIDToServerID;
// Network logic
UDPClient m_Unreliable;
TCPClient m_Reliable;
PlayerDefinition m_PlayerDefinitions[8];
SnapshotDefinitions m_NextSnapshot;
double m_DurationOfPingTime;
@@ -70,9 +70,9 @@ public:
std::clock_t m_TimeSinceSentInputs;
unsigned int m_SendInputIntervalMs;
std::vector<Events::InputCommand> m_InputCommandBuffer;
std::vector<Events::InputCommand> m_ReceivedInputCommands;
// Private member functions
size_t receive(char* data);
void disconnect();
void parseMessageType(Packet& packet);
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID);
@@ -88,6 +88,8 @@ public:
void parseComponentDeletion(Packet& packet);
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
void parseSnapshot(Packet& packet);
void parseOnInputCommand(Packet& packet);
void publishInputCommands();
void identifyPacketLoss();
void hasServerTimedOut();
EntityID createPlayer();
@@ -110,9 +112,6 @@ public:
EventRelay<Client, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(const Events::PlayerSpawned& e);
void parsePlayerDamage(Packet& packet);
private:
UDPClient m_Unreliable;
TCPClient m_Reliable;
};
#endif
+3 -1
View File
@@ -22,11 +22,13 @@ public:
Network(World* world, EventBroker* eventBroker);
virtual ~Network() { };
virtual void Update() = 0;
virtual void Update(double dt) = 0;
protected:
World* m_World;
EventBroker* m_EventBroker;
// for network
double m_TimeStamp = 0;
// For Debug
bool isReadingData = false;
+3 -1
View File
@@ -26,7 +26,7 @@ public:
Server(World* world, EventBroker* eventBroker, int port);
~Server();
void Update() override;
void Update(double dt) override;
private:
// Network channels
@@ -52,6 +52,7 @@ private:
int checkTimeOutInterval = 100;
int m_NextPlayerID = 0;
std::vector<Events::InputCommand> m_InputCommandsToBroadcast;
std::vector<Events::InputCommand> m_InputCommandsToPublish;
//Timers
std::clock_t m_StartPingTime;
@@ -82,6 +83,7 @@ private:
void parseTCPConnect(Packet & packet);
void parseDisconnect();
bool shouldSendToClient(EntityWrapper childEntity);
void publishInputCommands();
// Debug event
EventRelay<Server, Events::InputCommand> m_EInputCommand;
-21
View File
@@ -1,21 +0,0 @@
#ifndef BoostSystem_h__
#define BoostSystem_h__
#include "Core/System.h"
#include "Core/ResourceManager.h"
#include "Core/EntityFileParser.h"
#include "Core/EPlayerDamage.h"
#include "Common.h"
class BoostSystem : public System
{
public:
BoostSystem(SystemParams params);
private:
EventRelay<BoostSystem, Events::PlayerDamage> m_EPlayerDamage;
bool OnPlayerDamage(Events::PlayerDamage& e);
std::string DetermineClass(EntityWrapper player);
};
#endif
+1 -1
View File
@@ -39,5 +39,5 @@ private:
bool OnPlayerSpawned(Events::PlayerSpawned& e);
void updateMovementControllers(double dt);
void updateVelocity(double dt);
void updateVelocity(EntityWrapper player, double dt);
};
-5
View File
@@ -35,12 +35,7 @@
<xs:include schemaLocation="Components/AmmoPickup.xsd"/>
<xs:include schemaLocation="Components/AnimationOffset.xsd"/>
<xs:include schemaLocation="Components/DashAbility.xsd"/>
<xs:include schemaLocation="Components/ShieldAbility.xsd"/>
<xs:include schemaLocation="Components/SprintAbility.xsd"/>
<xs:include schemaLocation="Components/AssaultWeapon.xsd"/>
<xs:include schemaLocation="Components/BoostAssault.xsd"/>
<xs:include schemaLocation="Components/BoostDefender.xsd"/>
<xs:include schemaLocation="Components/BoostSniper.xsd"/>
<xs:include schemaLocation="Components/Shield.xsd"/>
<xs:include schemaLocation="Components/Sprite.xsd"/>
<xs:include schemaLocation="Components/Shielded.xsd"/>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<BoostAssault xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BoostAssault.xsd">
<StrengthOfEffect>2</StrengthOfEffect>
</BoostAssault>
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="BoostAssault">
<xs:annotation>
<xs:documentation>This is the assault's class boost component</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="StrengthOfEffect" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the strength of the boost effect</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<BoostDefender xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BoostDefender.xsd">
<StrengthOfEffect>10</StrengthOfEffect>
</BoostDefender>
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="BoostDefender">
<xs:annotation>
<xs:documentation>This is the defender's class boost component</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="StrengthOfEffect" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the strength of the boost effect</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<BoostSniper xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BoostSniper.xsd">
<StrengthOfEffect>10</StrengthOfEffect>
</BoostSniper>
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="BoostSniper">
<xs:annotation>
<xs:documentation>This is the sniper's class boost component</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="StrengthOfEffect" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the strength of the boost effect</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ShieldAbility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ShieldAbility.xsd">
<CoolDownMaxTimer>2.0</CoolDownMaxTimer>
</ShieldAbility>
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="ShieldAbility">
<xs:annotation>
<xs:documentation>A shield 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 shield</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SprintAbility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SprintAbility.xsd">
<StrengthOfEffect>2.0</StrengthOfEffect>
</SprintAbility>
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="SprintAbility">
<xs:annotation>
<xs:documentation>A sprint component for one of the classes</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="StrengthOfEffect" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the strength of the sprint effect</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1 -6
View File
@@ -5,15 +5,10 @@
<c:AABB/>
<c:AmmoPickup/>
<c:Model>
<Resource>Models/Props/PickUps/AmmoPickUp.mesh</Resource>
<Resource>Models/Core/UnitSphere.mesh</Resource>
</c:Model>
<c:RaptorCopter>
<Speed>0.1</Speed>
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Position X="0" Y="1" Z="0"/>
<Scale X="0.3" Y="0.3" Z="0.3"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:BoostAssault/>
<c:Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:Transform/>
</Components>
<Children/>
</Entity>
File diff suppressed because it is too large Load Diff
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:BoostDefender/>
<c:Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:Transform/>
</Components>
<Children/>
</Entity>
-14
View File
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:BoostSniper/>
<c:Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:Transform/>
</Components>
<Children/>
</Entity>
+1 -6
View File
@@ -5,15 +5,10 @@
<c:AABB/>
<c:HealthPickup/>
<c:Model>
<Resource>Models/Props/PickUps/HealthPickUp.mesh</Resource>
<Resource>Models/Core/UnitSphere.mesh</Resource>
</c:Model>
<c:RaptorCopter>
<Speed>0.1</Speed>
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Position X="0" Y="1" Z="0"/>
<Scale X="0.3" Y="0.3" Z="0.3"/>
</c:Transform>
<c:Trigger/>
</Components>
+10 -10
View File
@@ -5019,7 +5019,7 @@
</Team>
</c:Team>
<c:Transform>
<Position X="-60.3695679" Y="5.14500046" Z="-79.3789597"/>
<Position X="-60.3695679" Y="2.14482641" Z="-79.3789597"/>
</c:Transform>
</Components>
<Children>
@@ -5089,7 +5089,7 @@
</Team>
</c:Team>
<c:Transform>
<Position X="60.0169258" Y="6.0800004" Z="76.2893906"/>
<Position X="60.0169258" Y="2.37972379" Z="76.2893906"/>
</c:Transform>
</Components>
<Children>
@@ -5165,7 +5165,7 @@
<c:Transform>
<Position X="48.9189453" Y="7.06223536" Z="-78.9347992"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="74.6042328" Z="0"/>
<Orientation X="0" Y="71.4059677" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5184,7 +5184,7 @@
<c:Transform>
<Position X="-59.3499641" Y="7.46932745" Z="-20.6276321"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="71.2585754" Z="0"/>
<Orientation X="0" Y="68.0603104" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5203,7 +5203,7 @@
<c:Transform>
<Position X="-1.13644195" Y="1.38919806" Z="38.9768829"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="68.8666077" Z="0"/>
<Orientation X="0" Y="65.6683426" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5222,7 +5222,7 @@
<c:Transform>
<Position X="54.7225227" Y="6.51863909" Z="29.0052128"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="69.180542" Z="0"/>
<Orientation X="0" Y="65.9822693" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5241,7 +5241,7 @@
<c:Transform>
<Position X="-51.6792374" Y="8.44526482" Z="32.5153465"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="68.6292572" Z="0"/>
<Orientation X="0" Y="65.4309921" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5260,7 +5260,7 @@
<c:Transform>
<Position X="-42.3974304" Y="7.28327894" Z="81.9305344"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="66.7584839" Z="0"/>
<Orientation X="0" Y="63.560215" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5279,7 +5279,7 @@
<c:Transform>
<Position X="-9.85184956" Y="8.25567532" Z="39.6119232"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="65.8073425" Z="0"/>
<Orientation X="0" Y="62.6090584" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -5298,7 +5298,7 @@
<c:Transform>
<Position X="49.2257118" Y="7.39368248" Z="-31.1810112"/>
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
<Orientation X="0" Y="63.0184822" Z="0"/>
<Orientation X="0" Y="59.8201942" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
-2
View File
@@ -43,8 +43,6 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
m_Enabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get<bool>("Debug.EditorEnabled", false);
if (m_Enabled) {
Enable();
} else {
Disable();
}
}
+69 -20
View File
@@ -41,9 +41,11 @@ void Client::Connect(std::string address, int port)
}
}
void Client::Update()
void Client::Update(double dt)
{
m_EventBroker->Process<Client>();
//m_TimeStamp += dt;
publishInputCommands();
while (m_Unreliable.IsSocketAvailable()) {
// Packet will get real data in receive
Packet packet(MessageType::Invalid);
@@ -72,7 +74,8 @@ void Client::Update()
sendInputCommands();
m_TimeSinceSentInputs = std::clock();
}
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages.
// Reliable messages and timestamps did not fix it.
sendLocalPlayerTransform();
hasServerTimedOut();
@@ -122,6 +125,9 @@ void Client::parseMessageType(Packet& packet)
case MessageType::OnPlayerDamage:
parsePlayerDamage(packet);
break;
case MessageType::OnInputCommand:
//parsePlayerDamage(packet);
break;
default:
break;
}
@@ -284,21 +290,30 @@ void Client::ignoreFields(Packet& packet, const ComponentInfo& componentInfo)
void Client::parseSnapshot(Packet& packet)
{
// Read input commands
std::size_t numInputCommands = packet.ReadPrimitive<std::size_t>();
for (std::size_t i = 0; i < numInputCommands; ++i) {
Events::InputCommand e;
e.PlayerID = packet.ReadPrimitive<EntityID>();
EntityID player = packet.ReadPrimitive<EntityID>();
std::string command = packet.ReadString();
float value = packet.ReadPrimitive<float>();
if (m_ServerIDToClientID.find(player) != m_ServerIDToClientID.end()) {
e.Player = EntityWrapper(m_World, m_ServerIDToClientID.at(player));
e.Command = command;
e.Value = value;
m_EventBroker->Publish(e);
}
}
//// Read input commands
//std::size_t numInputCommands = packet.ReadPrimitive<std::size_t>();
//for (std::size_t i = 0; i < numInputCommands; ++i) {
// Events::InputCommand e;
// e.PlayerID = packet.ReadPrimitive<EntityID>();
// EntityID player = packet.ReadPrimitive<EntityID>();
// std::string command = packet.ReadString();
// float value = packet.ReadPrimitive<float>();
// double timestamp = packet.ReadPrimitive<double>();
// if (m_ServerIDToClientID.find(player) != m_ServerIDToClientID.end()) {
// e.Player = EntityWrapper(m_World, m_ServerIDToClientID.at(player));
// e.Command = command;
// e.Value = value;
// e.TimeStamp = timestamp;
// m_EventBroker->Publish(e);
// }
//}
// Read timestamp
double remoteTimestamp = packet.ReadPrimitive<double>();
//if (abs(remoteTimestamp - m_TimeStamp) > 0.100) {
// m_TimeStamp = remoteTimestamp;
// LOG_INFO("Resynced remote and local timestamp");
//}
// Read world state
while (packet.DataReadSize() < packet.Size()) {
@@ -359,6 +374,36 @@ void Client::parseSnapshot(Packet& packet)
parseSpawnEvents();
}
void Client::parseOnInputCommand(Packet & packet)
{
while (packet.DataReadSize() < packet.Size()) {
Events::InputCommand e;
e.PlayerID = packet.ReadPrimitive<int>();
e.Player = EntityWrapper(m_World, packet.ReadPrimitive<int>());
e.Command = packet.ReadString();
e.Value = packet.ReadPrimitive<float>();
e.TimeStamp = packet.ReadPrimitive<double>();
m_EventBroker->Publish(e);
m_ReceivedInputCommands.push_back(e);
//LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
}
}
void Client::publishInputCommands()
{
std::vector<Events::InputCommand> notPublishedEvents;
for (int i = 0; i < m_ReceivedInputCommands.size(); i++) {
if (m_ReceivedInputCommands.at(i).TimeStamp < m_TimeStamp) {
m_EventBroker->Publish(m_ReceivedInputCommands.at(i));
}
else {
notPublishedEvents.push_back(m_ReceivedInputCommands.at(i));
}
}
m_ReceivedInputCommands = notPublishedEvents;
}
void Client::disconnect()
{
m_IsConnected = false;
@@ -402,7 +447,9 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
}
} else {
if (m_IsConnected) {
m_InputCommandBuffer.push_back(e);
Events::InputCommand setTimestamp = e;
setTimestamp.TimeStamp = m_TimeStamp;
m_InputCommandBuffer.push_back(setTimestamp);
}
//LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
return true;
@@ -437,11 +484,12 @@ void Client::parsePlayerDamage(Packet& packet)
{
Events::PlayerDamage e;
PlayerID victimID = packet.ReadPrimitive<EntityID>();
if(serverClientMapsHasEntity(victimID)){
PlayerID inflictorID = packet.ReadPrimitive<EntityID>();
if(!serverClientMapsHasEntity(victimID) || !serverClientMapsHasEntity(inflictorID)){
return;
}
e.Inflictor = EntityWrapper(m_World, m_ServerIDToClientID.at(victimID));
e.Victim = EntityWrapper(m_World, m_ServerIDToClientID.at(packet.ReadPrimitive<EntityID>()));
e.Victim = EntityWrapper(m_World, m_ServerIDToClientID.at(inflictorID));
e.Damage = packet.ReadPrimitive<double>();
// Don't rebroadcast our own player damage events or we'll have an infinite loop!
if (e.Inflictor != m_LocalPlayer) {
@@ -515,6 +563,7 @@ void Client::sendInputCommands()
for (int i = 0; i < m_InputCommandBuffer.size(); i++) {
packet.WriteString(m_InputCommandBuffer[i].Command);
packet.WritePrimitive(m_InputCommandBuffer[i].Value);
packet.WritePrimitive(m_InputCommandBuffer[i].TimeStamp);
}
m_Reliable.Send(packet);
m_InputCommandBuffer.clear();
+1 -1
View File
@@ -9,7 +9,7 @@ Network::Network(World* world, EventBroker* eventBroker)
m_TimeoutMs = config->Get<int>("Networking.TimeoutMs", 20000);
}
void Network::Update()
void Network::Update(double dt)
{
updateNetworkData();
}
+29 -11
View File
@@ -1,6 +1,6 @@
#include "Network/Server.h"
Server::Server(World* world, EventBroker* eventBroker, int port)
Server::Server(World* world, EventBroker* eventBroker, int port)
: Network(world, eventBroker)
{
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
@@ -26,10 +26,12 @@ Server::~Server()
}
void Server::Update()
void Server::Update(double dt)
{
m_EventBroker->Process<Server>();
m_TimeStamp += dt;
publishInputCommands();
PlayerDefinition pd;
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
for (auto& kv : m_ConnectedPlayers) {
while (kv.second.TCPSocket->available()) {
@@ -80,11 +82,9 @@ void Server::Update()
checkForTimeOuts();
timOutTimer = currentTime;
}
m_EventBroker->Process<Server>();
if (isReadingData) {
Network::Update();
Network::Update(dt);
}
}
void Server::parseMessageType(Packet& packet)
@@ -146,7 +146,8 @@ void Server::unreliableBroadcast(Packet& packet)
void Server::sendSnapshot()
{
Packet packet(MessageType::Snapshot);
addInputCommandsToPacket(packet);
//addInputCommandsToPacket(packet);
packet.WritePrimitive(m_TimeStamp/*+ somePingvalue + offset*/);
addChildrenToPacket(packet, EntityID_Invalid);
unreliableBroadcast(packet);
}
@@ -160,6 +161,7 @@ void Server::addInputCommandsToPacket(Packet& packet)
packet.WritePrimitive(m_ConnectedPlayers.at(command.PlayerID).EntityID);
packet.WriteString(command.Command);
packet.WritePrimitive(command.Value);
packet.WritePrimitive(command.TimeStamp);
}
m_InputCommandsToBroadcast.clear();
}
@@ -280,7 +282,7 @@ void Server::parseTCPConnect(Packet & packet)
// Read packet ID
m_PreviousPacketID = m_PacketID; // Set previous packet id
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
LOG_INFO("Parsing connections");
// Check if player is already connected
// Ska vara till lagd i TCPServer receive
@@ -333,6 +335,7 @@ void Server::disconnect(PlayerID playerID)
e.PlayerID = playerID;
m_EventBroker->Publish(e);
//m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
// TODO Kolla Anders crashade efter timeout med break point
m_ConnectedPlayers[playerID].TCPSocket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
m_ConnectedPlayers[playerID].TCPSocket->close();
m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
@@ -375,8 +378,7 @@ bool Server::OnInputCommand(const Events::InputCommand & e)
}
isReadingData = !isReadingData;
m_SaveDataTimer = std::clock();
}
if (e.Command == "KickPlayer" && e.Value > 0) {
} else if (e.Command == "KickPlayer" && e.Value > 0) {
kick(0);
}
@@ -466,7 +468,9 @@ void Server::parseOnInputCommand(Packet& packet)
e.PlayerID = player; // Set correct player id
e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID);
e.Value = packet.ReadPrimitive<float>();
m_EventBroker->Publish(e);
e.TimeStamp = packet.ReadPrimitive<double>();
/* m_EventBroker->Publish(e);*/
m_InputCommandsToPublish.push_back(e);
if (e.Command == "PrimaryFire" || e.Command == "Reload") {
m_InputCommandsToBroadcast.push_back(e);
}
@@ -516,6 +520,20 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid();
}
void Server::publishInputCommands()
{
std::vector<Events::InputCommand> notPublishedEvents;
for (int i = 0; i < m_InputCommandsToPublish.size(); i++) {
if (m_InputCommandsToPublish.at(i).TimeStamp < m_TimeStamp) {
m_EventBroker->Publish(m_InputCommandsToPublish.at(i));
} else {
LOG_INFO("Did not instantly publish command");
notPublishedEvents.push_back(m_InputCommandsToPublish.at(i));
}
}
m_InputCommandsToPublish = notPublishedEvents;
}
PlayerID Server::GetPlayerIDFromEndpoint()
{
// check both tcp and udp connection
+2 -4
View File
@@ -26,7 +26,6 @@
#include "Network/MultiplayerSnapshotFilter.h"
#include "Game/Systems/AmmunitionHUDSystem.h"
#include "Game/Systems/KillFeedSystem.h"
#include "Game/Systems/BoostSystem.h"
Game::Game(int argc, char* argv[])
@@ -133,7 +132,6 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<BoostSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
@@ -201,10 +199,10 @@ void Game::Tick()
// Update network
m_EventBroker->Process<MultiplayerSnapshotFilter>();
if (m_NetworkClient != nullptr) {
m_NetworkClient->Update();
m_NetworkClient->Update(dt);
}
if (m_NetworkServer != nullptr) {
m_NetworkServer->Update();
m_NetworkServer->Update(dt);
}
//m_SoundManager->Update(dt);
-63
View File
@@ -1,63 +0,0 @@
#include "Systems/BoostSystem.h"
BoostSystem::BoostSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &BoostSystem::OnPlayerDamage);
}
bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e)
{
if (e.Victim.ID == e.Inflictor.ID) {
return false;
}
if (!e.Victim.Valid() && e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) {
return false;
}
if (!e.Inflictor.Valid() || !e.Victim.Valid()) {
return false;
}
//if its not friendly fire, return
if ((int)m_World->GetComponent(e.Inflictor.ID, "Team")["Team"] != (int)m_World->GetComponent(e.Victim.ID, "Team")["Team"]) {
return false;
}
//determine the inflictors class
auto className = DetermineClass(e.Inflictor);
if (className == "") {
return false;
}
//get the XML file, example: "Schema/Entities/BoostclassName.xml"
std::string classXML = "Schema/Entities/" + className + ".xml";
//check if player already has a child with the component, if so delete that child
auto playerBoostAssaultEntity = e.Victim.FirstChildByName(className);
if (playerBoostAssaultEntity.Valid()) {
m_World->DeleteEntity(playerBoostAssaultEntity.ID);
}
//load boost XML file, set it entity parented with the victim player
auto entityFile = ResourceManager::Load<EntityFile>(classXML);
EntityFileParser parser(entityFile);
EntityID boostAssaultEntity = parser.MergeEntities(m_World);
m_World->SetName(boostAssaultEntity, className);
m_World->SetParent(boostAssaultEntity, e.Victim.ID);
return true;
}
std::string BoostSystem::DetermineClass(EntityWrapper inflictorPlayer)
{
//determine the class based on what component the inflictor-player has
if (m_World->HasComponent(inflictorPlayer.ID, "DashAbility")) {
return "BoostAssault";
}
if (m_World->HasComponent(inflictorPlayer.ID, "ShieldAbility")) {
return "BoostDefender";
}
if (m_World->HasComponent(inflictorPlayer.ID, "SprintAbility")) {
return "BoostSniper";
}
return "";
}
-5
View File
@@ -30,11 +30,6 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
ComponentWrapper cHealth = e.Victim["Health"];
double& health = cHealth["Health"];
//if player has the boost from a defender, subtract the damage taken by StrengthOfEffect amount
auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender");
if (playerBoostDefenderEntity.Valid()) {
e.Damage -= (double)playerBoostDefenderEntity["BoostDefender"]["StrengthOfEffect"];
}
health -= e.Damage;
return true;
+6 -28
View File
@@ -16,7 +16,9 @@ PlayerMovementSystem::~PlayerMovementSystem()
void PlayerMovementSystem::Update(double dt)
{
updateMovementControllers(dt);
updateVelocity(dt);
if (LocalPlayer.Valid()) {
updateVelocity(LocalPlayer, dt);
}
}
void PlayerMovementSystem::updateMovementControllers(double dt)
@@ -53,19 +55,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
float playerMovementSpeed = player["Player"]["MovementSpeed"];
float playerCrouchSpeed = player["Player"]["CrouchSpeed"];
glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"];
auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault");
if (playerBoostAssaultEntity.Valid()) {
playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
playerCrouchSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
}
bool sniperSprinting = false;
if (player.HasComponent("SprintAbility")) {
if (controller->SniperSprintingCheck()) {
playerMovementSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
playerCrouchSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
sniperSprinting = true;
}
}
if (player.HasComponent("Physics")) {
ComponentWrapper cPhysics = player["Physics"];
@@ -117,13 +106,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
//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);
//if player has Boost from an Assault class, accelerate the player faster
if (playerBoostAssaultEntity.Valid()) {
accelerationSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
}
if (sniperSprinting) {
accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
}
velocity += accelerationSpeed * wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
}
@@ -241,15 +223,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
}
void PlayerMovementSystem::updateVelocity(double dt)
void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
{
// Only apply velocity to local player
if (!LocalPlayer.Valid()) {
return;
}
ComponentWrapper& cTransform = LocalPlayer["Transform"];
ComponentWrapper& cPhysics = LocalPlayer["Physics"];
ComponentWrapper& cTransform = player["Transform"];
ComponentWrapper& cPhysics = player["Physics"];
glm::vec3& velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
@@ -384,10 +384,9 @@ bool AssaultWeaponBehaviour::shoot(double damage)
return false;
}
// If friendly fire - reduce damage to 0 (needed to make Boosts, Ammosharing work)
// Check for friendly fire
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) {
damage = 0;
return false;
}
// Deal damage!