17#ifndef _FGE_C_NETWORKTYPE_HPP_INCLUDED
18#define _FGE_C_NETWORKTYPE_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "C_identity.hpp"
22#include "C_packet.hpp"
23#include "FastEngine/C_callback.hpp"
24#include "FastEngine/C_dataAccessor.hpp"
25#include "FastEngine/C_propertyList.hpp"
28#include <unordered_map>
31#define FGE_NET_WAITING_UPDATE_DELAY std::chrono::milliseconds(800)
42enum PerClientConfigs : uint8_t
44 CLIENTCONFIG_MODIFIED_FLAG = 1 << 0,
45 CLIENTCONFIG_REQUIRE_EXPLICIT_UPDATE_FLAG = 1 << 1
50 std::underlying_type_t<PerClientConfigs> _config{0};
51 void* _customData{
nullptr};
54using NetworkPerClientModificationTable =
55 std::unordered_map<fge::net::Identity, fge::net::PerClientConfig, fge::net::IdentityHash>;
168 void clearExplicitUpdateFlag();
173 bool isNeedingExplicitUpdate()
const;
175 void clearWaitingUpdateFlag();
187 bool isWaitingUpdate()
const;
189 [[nodiscard]] std::chrono::microseconds getLastUpdateTime()
const;
190 void setLastUpdateTime();
198 virtual void createClientCustomData([[maybe_unused]]
void*& ptr)
const {}
199 virtual void destroyClientCustomData([[maybe_unused]]
void*& ptr)
const {}
200 virtual void applyClientCustomData([[maybe_unused]]
void*& ptr)
const {}
202 fge::net::NetworkPerClientModificationTable _g_tableId;
203 bool _g_needExplicitUpdate{
false};
204 bool _g_waitingUpdate{
false};
205 bool _g_force{
false};
206 std::chrono::microseconds _g_lastUpdateTime{0};
229 bool check()
const override;
317 fge::Vector2f
const& getCache()
const;
318 void setErrorRange(
float range);
319 float getErrorRange()
const;
322 fge::Vector2f g_typeCopy;
347 float getCache()
const;
348 void setErrorRange(
float range);
349 float getErrorRange()
const;
377 bool check()
const override;
405 bool check()
const override;
409 std::string
const& getValueName()
const;
436 bool check()
const override;
455enum class RecordedEventTypes : uint8_t
464 RecordedEventTypes _type;
475 using const_iterator =
typename std::vector<T>::const_iterator;
476 using iterator =
typename std::vector<T>::iterator;
477 using const_reverse_iterator =
typename std::vector<T>::const_reverse_iterator;
478 using const_reference =
typename std::vector<T>::const_reference;
479 using reference =
typename std::vector<T>::reference;
481 using EventQueue = std::vector<RecordedEvent>;
486 [[nodiscard]] const_reference at(SizeType index)
const;
487 [[nodiscard]] const_reference operator[](SizeType index)
const;
488 [[nodiscard]] const_reference front()
const;
489 [[nodiscard]] const_reference back()
const;
490 [[nodiscard]] T
const* data()
const;
492 [[nodiscard]] const_iterator begin()
const;
493 [[nodiscard]] const_iterator end()
const;
494 [[nodiscard]] const_iterator cbegin()
const;
495 [[nodiscard]] const_iterator cend()
const;
496 [[nodiscard]] const_reverse_iterator rbegin()
const;
497 [[nodiscard]] const_reverse_iterator rend()
const;
498 [[nodiscard]] const_reverse_iterator crbegin()
const;
499 [[nodiscard]] const_reverse_iterator crend()
const;
501 [[nodiscard]] SizeType size()
const;
502 [[nodiscard]]
bool empty()
const;
504 void reserve(SizeType n);
507 iterator insert(const_iterator pos, T
const& value);
508 iterator insert(const_iterator pos, T&& value);
509 template<
class... TArgs>
510 iterator emplace(const_iterator pos, TArgs&&... value);
512 void push_back(TArg&& arg);
513 template<
class... TArgs>
514 reference emplace_back(TArgs&&... arg);
515 const_iterator erase(const_iterator pos);
518 [[nodiscard]] reference modify(SizeType index);
519 [[nodiscard]] reference modify(const_iterator pos);
522 [[nodiscard]] SizeType eventsSize()
const;
523 [[nodiscard]] EventQueue
const& getEventQueue()
const;
524 [[nodiscard]]
bool isRegisteringEvents()
const;
525 void registerEvents(
bool enable);
530 std::vector<T> g_container;
533 bool g_registerEvents{
true};
535 bool g_registerEvents{
false};
563 bool check()
const override;
568 void createClientCustomData(
void*& ptr)
const override;
569 void destroyClientCustomData(
void*& ptr)
const override;
570 void applyClientCustomData(
void*& ptr)
const override;
572 enum class PackTypes : uint8_t
606 template<
class T,
class... TArgs>
607 T* push(TArgs&&... args)
609 static_assert(std::is_base_of_v<fge::net::NetworkTypeBase, T>,
"T must inherit from fge::net::NetworkTypeBase");
610 return static_cast<T*
>(this->push(std::make_unique<T>(std::forward<TArgs>(args)...)));
612 template<
class T,
class... TArgs>
622 [[nodiscard]]
inline std::size_t size()
const {
return this->g_data.size(); }
625 [[nodiscard]]
inline T* get(std::size_t index)
const
627 static_assert(std::is_base_of_v<fge::net::NetworkTypeBase, T>,
"T must inherit from fge::net::NetworkTypeBase");
628 return static_cast<T*
>(this->g_data[index].get());
632 return this->g_data[index].get();
636 std::vector<std::unique_ptr<fge::net::NetworkTypeBase>> g_data;
642#include "C_networkType.inl"
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
A class that map a string to a Property.
Definition C_propertyList.hpp:35
A class that can store any type of data.
Definition C_property.hpp:54
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
Definition C_tagList.hpp:28
A list of clients used by a server.
Definition C_clientList.hpp:57
Base class for a network type.
Definition C_networkType.hpp:70
void waitingUpdate()
Tell that this network type is waiting for an update.
virtual bool check() const =0
Check if the value have been modified.
virtual bool clientsCheckup(fge::net::ClientList const &clients, bool force)
Do a clients checkup with the specified client list.
virtual void requireExplicitUpdateClient(fge::net::Identity const &id)
Ask for an explicit update of the value for the specified client identity.
virtual void forceCheckClient(fge::net::Identity const &id)
Force the modification flag to be set for the specified client identity.
virtual bool checkClient(fge::net::Identity const &id) const
Check if the modification flag is set for the specified client identity.
virtual void forceUncheck()=0
Remove the forced modification of the value.
virtual void packData(fge::net::Packet &pck)=0
Pack the data without any client identity.
bool isForced() const
Check if the value is forced to be modified.
virtual void const * getSource() const =0
Get the source pointer that have been used to create this network type.
virtual void packData(fge::net::Packet &pck, fge::net::Identity const &id)=0
Pack the data into a packet and reset the modification flag of the identity.
virtual void forceUncheckClient(fge::net::Identity const &id)
Reset the modification flag for the specified client identity.
void needExplicitUpdate()
Tell that this network type need an explicit update from the server.
fge::CallbackHandler _onApplied
Callback called when the value have been applied.
Definition C_networkType.hpp:195
virtual void forceCheck()=0
Force the value to be modified (even if it is not)
virtual bool applyData(fge::net::Packet const &pck)=0
Apply the data packed by the same network type from a server.
A regroupment of network types.
Definition C_networkType.hpp:590
The network type for a trivial type but triggered manually.
Definition C_networkType.hpp:425
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:215
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:254
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:233
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:259
NetworkTypeManual(T *source)
NetworkTypeManual.
Definition C_networkType.inl:209
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:221
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:249
The network type for a property inside a list.
Definition C_networkType.hpp:394
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:147
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:186
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:196
NetworkTypePropertyList(fge::PropertyList *source, std::string const &vname)
NetworkTypePropertyList.
Definition C_networkType.inl:138
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:153
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:191
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:165
The network type for a property.
Definition C_networkType.hpp:366
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:131
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:126
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:94
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:104
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:88
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:121
NetworkTypeProperty(fge::Property *source)
NetworkTypeProperty.
Definition C_networkType.inl:81
The network type for a scene.
Definition C_networkType.hpp:244
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
void const * getSource() const override
Get the source pointer that have been used to create this network type.
void packData(fge::net::Packet &pck) override
Pack the data without any client identity.
bool check() const override
Check if the value have been modified.
void forceCheck() override
Force the value to be modified (even if it is not)
void forceCheckClient(fge::net::Identity const &id) override
Force the modification flag to be set for the specified client identity.
void forceUncheckClient(fge::net::Identity const &id) override
Reset the modification flag for the specified client identity.
bool checkClient(fge::net::Identity const &id) const override
Check if the modification flag is set for the specified client identity.
bool clientsCheckup(fge::net::ClientList const &clients, bool force) override
Do a clients checkup with the specified client list.
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
void forceUncheck() override
Remove the forced modification of the value.
The network type for a float that wait for the error threshold in order to set the value.
Definition C_networkType.hpp:332
void forceUncheck() override
Remove the forced modification of the value.
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
bool check() const override
Check if the value have been modified.
void forceCheck() override
Force the value to be modified (even if it is not)
void packData(fge::net::Packet &pck) override
Pack the data without any client identity.
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
void const * getSource() const override
Get the source pointer that have been used to create this network type.
The network type for a vector2 float that wait for the error threshold in order to set the value (use...
Definition C_networkType.hpp:302
bool check() const override
Check if the value have been modified.
void const * getSource() const override
Get the source pointer that have been used to create this network type.
void forceCheck() override
Force the value to be modified (even if it is not)
void forceUncheck() override
Remove the forced modification of the value.
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
void packData(fge::net::Packet &pck) override
Pack the data without any client identity.
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
The network type for a tag.
Definition C_networkType.hpp:275
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
void const * getSource() const override
Get the source pointer that have been used to create this network type.
void forceUncheck() override
Remove the forced modification of the value.
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
void packData(fge::net::Packet &pck) override
Pack the data without any client identity.
void forceCheck() override
Force the value to be modified (even if it is not)
bool check() const override
Check if the value have been modified.
The network type for a vector.
Definition C_networkType.hpp:549
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:654
void forceUncheckClient(fge::net::Identity const &id) override
Reset the modification flag for the specified client identity.
Definition C_networkType.inl:633
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:659
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:499
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:505
NetworkTypeVector(RecordedVector< T > *source)
NetworkTypeVector.
Definition C_networkType.inl:486
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:571
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:645
void forceCheckClient(fge::net::Identity const &id) override
Force the modification flag to be set for the specified client identity.
Definition C_networkType.inl:622
The default network type for most trivial types.
Definition C_networkType.hpp:218
NetworkType(fge::DataAccessor< T > source)
NetworkType.
Definition C_networkType.inl:23
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:67
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:47
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:72
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:34
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:29
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:62
Definition C_packet.hpp:70
Definition C_networkType.hpp:473
Definition C_dataAccessor.hpp:27
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31
Definition C_networkType.hpp:49
Definition C_networkType.hpp:463