24 g_typeCopy(source._getter()),
25 g_typeSource(std::move(source))
31 return &this->g_typeSource;
36 if (pck >> this->g_typeCopy)
38 this->g_typeSource._setter(this->g_typeCopy);
39 this->setLastUpdateTime();
40 this->clearWaitingUpdateFlag();
49 if (this->clearModificationFlag(
id))
51 pck << this->g_typeSource._getter();
57 pck << this->g_typeSource._getter();
62 return (this->g_typeSource._getter() != this->g_typeCopy) || this->_g_force;
67 this->_g_force =
true;
72 this->_g_force =
false;
73 this->g_typeCopy = this->g_typeSource._getter();
88 return this->g_typeSource;
94 pck >> this->g_typeSource->template setType<T>();
96 this->setLastUpdateTime();
97 this->clearWaitingUpdateFlag();
104 if (this->clearModificationFlag(
id))
106 pck << this->g_typeSource->template setType<T>();
112 pck << this->g_typeSource->template setType<T>();
118 return this->g_typeSource->isModified();
123 this->g_typeSource->setModifiedFlag(
true);
128 this->g_typeSource->setModifiedFlag(
false);
134 g_typeSource(source),
138 property.setType<T>();
144 return this->g_typeSource;
150 fge::Property&
property = this->g_typeSource->getProperty(this->g_vname);
152 pck >>
property.setType<T>();
154 this->setLastUpdateTime();
155 this->clearWaitingUpdateFlag();
162 if (this->clearModificationFlag(
id))
164 fge::Property&
property = this->g_typeSource->getProperty(this->g_vname);
165 pck <<
property.setType<T>();
171 fge::Property&
property = this->g_typeSource->getProperty(this->g_vname);
173 pck <<
property.setType<T>();
179 return this->g_typeSource->getProperty(this->g_vname).isModified();
184 this->g_typeSource->getProperty(this->g_vname).setModifiedFlag(
true);
189 this->g_typeSource->getProperty(this->g_vname).setModifiedFlag(
false);
193std::string
const& NetworkTypePropertyList<T>::getValueName()
const
195 return this->g_vname;
201 g_typeSource(source),
208 return this->g_typeSource;
214 if (pck >> *this->g_typeSource)
216 this->setLastUpdateTime();
217 this->clearWaitingUpdateFlag();
226 if (this->clearModificationFlag(
id))
228 pck << *this->g_typeSource;
234 pck << *this->g_typeSource;
240 return this->g_trigger;
245 this->g_trigger =
true;
250 this->g_trigger =
false;
254void NetworkTypeManual<T>::trigger()
256 this->g_trigger =
true;
262typename RecordedVector<T>::const_reference RecordedVector<T>::at(SizeType index)
const
264 return this->g_container.at(index);
267typename RecordedVector<T>::const_reference RecordedVector<T>::operator[](SizeType index)
const
269 return this->g_container[index];
272typename RecordedVector<T>::const_reference RecordedVector<T>::front()
const
274 return this->g_container.front();
277typename RecordedVector<T>::const_reference RecordedVector<T>::back()
const
279 return this->g_container.back();
282T
const* RecordedVector<T>::data()
const
284 return this->g_container.data();
288typename RecordedVector<T>::const_iterator RecordedVector<T>::begin()
const
290 return this->g_container.begin();
293typename RecordedVector<T>::const_iterator RecordedVector<T>::end()
const
295 return this->g_container.end();
298typename RecordedVector<T>::const_iterator RecordedVector<T>::cbegin()
const
300 return this->g_container.cbegin();
303typename RecordedVector<T>::const_iterator RecordedVector<T>::cend()
const
305 return this->g_container.cend();
308typename RecordedVector<T>::const_reverse_iterator RecordedVector<T>::rbegin()
const
310 return this->g_container.rbegin();
313typename RecordedVector<T>::const_reverse_iterator RecordedVector<T>::rend()
const
315 return this->g_container.rend();
318typename RecordedVector<T>::const_reverse_iterator RecordedVector<T>::crbegin()
const
320 return this->g_container.crbegin();
323typename RecordedVector<T>::const_reverse_iterator RecordedVector<T>::crend()
const
325 return this->g_container.crend();
329SizeType RecordedVector<T>::size()
const
331 return static_cast<SizeType
>(this->g_container.size());
334bool RecordedVector<T>::empty()
const
336 return this->g_container.empty();
340void RecordedVector<T>::reserve(SizeType n)
342 this->g_container.reserve(n);
346void RecordedVector<T>::clear()
348 this->g_container.clear();
350 this->pushEvent({RecordedEventTypes::REMOVE_ALL, 0});
353typename RecordedVector<T>::iterator RecordedVector<T>::insert(const_iterator pos, T
const& value)
355 SizeType index = pos - this->g_container.begin();
356 this->pushEvent({RecordedEventTypes::ADD, index});
357 return this->g_container.insert(pos, value);
360typename RecordedVector<T>::iterator RecordedVector<T>::insert(const_iterator pos, T&& value)
362 SizeType index = pos - this->g_container.begin();
363 this->pushEvent({RecordedEventTypes::ADD, index});
364 return this->g_container.insert(pos, std::move(value));
367template<
class... TArgs>
368typename RecordedVector<T>::iterator RecordedVector<T>::emplace(const_iterator pos, TArgs&&... value)
370 SizeType index = pos - this->g_container.begin();
371 this->pushEvent({RecordedEventTypes::ADD, index});
372 return this->g_container.emplace(pos, std::forward<TArgs>(value)...);
376void RecordedVector<T>::push_back(TArg&& arg)
378 this->pushEvent({RecordedEventTypes::ADD, this->g_container.size()});
379 this->g_container.push_back(std::forward<TArg>(arg));
382template<
class... TArgs>
383typename RecordedVector<T>::reference RecordedVector<T>::emplace_back(TArgs&&... arg)
385 this->pushEvent({RecordedEventTypes::ADD, this->g_container.size()});
386 return this->g_container.emplace_back(std::forward<TArgs>(arg)...);
389typename RecordedVector<T>::const_iterator RecordedVector<T>::erase(const_iterator pos)
391 SizeType index = pos - this->g_container.begin();
392 this->pushEvent({RecordedEventTypes::REMOVE, index});
393 return this->g_container.erase(pos);
396void RecordedVector<T>::pop_back()
398 this->pushEvent({RecordedEventTypes::REMOVE, this->g_container.size() - 1});
399 this->g_container.pop_back();
403typename RecordedVector<T>::reference RecordedVector<T>::modify(SizeType index)
405 this->pushEvent({RecordedEventTypes::MODIFY, index});
406 return this->g_container[index];
409typename RecordedVector<T>::reference RecordedVector<T>::modify(const_iterator pos)
411 SizeType index = pos - this->g_container.begin();
412 this->pushEvent({RecordedEventTypes::MODIFY, index});
413 return this->g_container[index];
417void RecordedVector<T>::clearEvents()
419 this->g_events.clear();
422SizeType RecordedVector<T>::eventsSize()
const
424 return static_cast<SizeType
>(this->g_events.size());
427typename RecordedVector<T>::EventQueue
const& RecordedVector<T>::getEventQueue()
const
429 return this->g_events;
433bool RecordedVector<T>::isRegisteringEvents()
const
435 return this->g_registerEvents;
438void RecordedVector<T>::registerEvents(
bool enable)
441 this->g_registerEvents = enable;
447 if (this->g_registerEvents)
449 this->g_events.emplace_back(event);
456 return pck << vec.g_container;
461 return pck >> vec.g_container;
465 return pck <<
event._type <<
event._index;
469 return pck >>
event._type >>
event._index;
482 return this->g_typeSource;
491 if (packType == PackTypes::FULL)
493 pck >> *this->g_typeSource;
497 SizeType eventCount{0};
499 for (SizeType i = 0; i < eventCount; ++i)
505 case RecordedEventTypes::ADD:
506 if (event._index >= this->g_typeSource->size())
510 this->g_typeSource->emplace_back(std::move(value));
516 this->g_typeSource->emplace(this->g_typeSource->begin() + event._index, std::move(value));
519 case RecordedEventTypes::REMOVE:
520 if (event._index < this->g_typeSource->size())
522 this->g_typeSource->erase(this->g_typeSource->begin() + event._index);
529 case RecordedEventTypes::REMOVE_ALL:
530 this->g_typeSource->clear();
532 case RecordedEventTypes::MODIFY:
533 if (event._index < this->g_typeSource->size())
535 pck >> this->g_typeSource->modify(event._index);
546 this->setLastUpdateTime();
547 this->clearWaitingUpdateFlag();
554 auto* clientData = this->getClientData(
id);
556 if (clientData ==
nullptr)
561 auto* events =
static_cast<typename RecordedVector<T>::EventQueue*
>(clientData->_data.get());
565 pck << PackTypes::FULL;
566 pck << *this->g_typeSource;
570 pck << PackTypes::PARTIAL;
571 pck << static_cast<SizeType>(events->size());
572 for (
auto itEvent = events->begin(); itEvent != events->end(); ++itEvent)
575 if (itEvent->_type == RecordedEventTypes::ADD || itEvent->_type == RecordedEventTypes::MODIFY)
579 auto finalIndex = itEvent->_index;
580 for (
auto itReverse = events->rbegin(); &(*itReverse) != &(*itEvent); ++itReverse)
582 if (itReverse->_type == RecordedEventTypes::ADD && itReverse->_index <= finalIndex)
586 else if (itReverse->_type == RecordedEventTypes::REMOVE && itReverse->_index < finalIndex)
591 pck << this->g_typeSource->at(finalIndex);
597 clientData->_config.unset(CLIENTCONFIG_MODIFIED_FLAG);
602 pck << PackTypes::FULL << *this->g_typeSource;
608 auto* clientData = this->getClientData(
id);
609 if (clientData !=
nullptr)
611 clientData->_config.set(CLIENTCONFIG_MODIFIED_FLAG);
612 auto* events =
static_cast<typename RecordedVector<T>::EventQueue*
>(clientData->_data);
619 auto* clientData = this->getClientData(
id);
620 if (clientData !=
nullptr)
622 clientData->_config.unset(CLIENTCONFIG_MODIFIED_FLAG);
623 auto* events =
static_cast<typename RecordedVector<T>::EventQueue*
>(clientData->_data);
633 this->g_typeSource->clearEvents();
635 return this->g_typeSource->eventsSize() != 0 || this->_g_force;
640 this->_g_force =
true;
645 this->_g_force =
false;
646 this->g_typeSource->clearEvents();
650void NetworkTypeVector<T>::createClientData(std::shared_ptr<void>& ptr)
const
652 ptr = std::shared_ptr<void>(
new typename RecordedVector<T>::EventQueue(),
656void NetworkTypeVector<T>::applyClientData(std::shared_ptr<void>& ptr)
const
658 auto* events =
static_cast<typename RecordedVector<T>::EventQueue*
>(ptr);
660 bool const clearFirst = this->g_typeSource->getEventQueue().front()._type == RecordedEventTypes::REMOVE_ALL;
666 for (
auto const& event: this->g_typeSource->getEventQueue())
668 events->push_back(event);
674template<
class TEnum,
class TData>
680template<
class TEnum,
class TData>
683 SizeType eventCount{0};
691 for (SizeType i = 0; i < eventCount; ++i)
695 if constexpr (std::is_void_v<TData>)
703 this->
_onEvent.call(std::make_pair(eventType, std::move(eventData)));
707 this->setLastUpdateTime();
708 this->clearWaitingUpdateFlag();
712template<
class TEnum,
class TData>
715 auto* clientData = this->getClientData(
id);
717 if (clientData ==
nullptr)
722 auto* events =
static_cast<EventQueue*
>(clientData->_data.get());
724 pck << static_cast<SizeType>(events->size());
726 for (
auto const& event: *events)
728 if constexpr (std::is_void_v<TData>)
734 pck <<
event.first <<
event.second;
739 clientData->_config.unset(CLIENTCONFIG_MODIFIED_FLAG);
741template<
class TEnum,
class TData>
748template<
class TEnum,
class TData>
751 auto* clientData = this->getClientData(
id);
752 if (clientData !=
nullptr)
754 clientData->_config.set(CLIENTCONFIG_MODIFIED_FLAG);
757template<
class TEnum,
class TData>
760 auto* clientData = this->getClientData(
id);
761 if (clientData !=
nullptr)
763 clientData->_config.unset(CLIENTCONFIG_MODIFIED_FLAG);
764 auto* events =
static_cast<EventQueue*
>(clientData->_data.get());
769template<
class TEnum,
class TData>
772 return this->g_modified || this->_g_force;
774template<
class TEnum,
class TData>
777 this->_g_force =
true;
779template<
class TEnum,
class TData>
782 this->_g_force =
false;
783 this->g_modified =
false;
786template<
class TEnum,
class TData>
787void NetworkTypeEvents<TEnum, TData>::pushEvent(
Event const& event)
789 this->g_modified =
true;
790 for (
auto& client: *
this)
792 auto* events =
static_cast<EventQueue*
>(client.second._data.get());
793 events->push_back(event);
794 client.second._config.set(CLIENTCONFIG_MODIFIED_FLAG);
797template<
class TEnum,
class TData>
798void NetworkTypeEvents<TEnum, TData>::pushEventIgnore(Event
const& event, Identity
const& ignoreId)
800 this->g_modified =
true;
801 for (
auto& client: *
this)
803 if (client.first == ignoreId)
808 auto* events =
static_cast<EventQueue*
>(client.second._data.get());
809 events->push_back(event);
810 client.second._config.set(CLIENTCONFIG_MODIFIED_FLAG);
814template<
class TEnum,
class TData>
815void NetworkTypeEvents<TEnum, TData>::createClientData(std::shared_ptr<void>& ptr)
const
817 ptr = std::shared_ptr<void>(
new EventQueue(), NetworkTypeEvents::DataDeleter());
819template<
class TEnum,
class TData>
820void NetworkTypeEvents<TEnum, TData>::applyClientData([[maybe_unused]] std::shared_ptr<void>& ptr)
const
This class is a wrapper for SDL events.
Definition C_event.hpp:59
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
fge::CallbackHandler _onApplied
Callback called when the value have been applied.
Definition C_networkType.hpp:250
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:713
bool applyData(Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:681
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:775
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:770
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:675
void forceUncheckClient(Identity const &id) override
Reset the modification flag for the specified client identity.
Definition C_networkType.inl:758
void forceCheckClient(Identity const &id) override
Force the modification flag to be set for the specified client identity.
Definition C_networkType.inl:749
fge::CallbackHandler< Event > _onEvent
Callback called when an event is received.
Definition C_networkType.hpp:665
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:780
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:206
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:243
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:248
NetworkTypeManual(T *source)
NetworkTypeManual.
Definition C_networkType.inl:200
bool applyData(Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:212
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:224
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:238
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:142
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:177
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:187
NetworkTypePropertyList(fge::PropertyList *source, std::string const &vname)
NetworkTypePropertyList.
Definition C_networkType.inl:133
bool applyData(Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:148
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:182
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:160
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:102
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:126
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:121
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:86
bool applyData(Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:92
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:116
NetworkTypeProperty(fge::Property *source)
NetworkTypeProperty.
Definition C_networkType.inl:79
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:638
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:552
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:643
void const * getSource() const override
Get the source pointer that have been used to create this network type.
Definition C_networkType.inl:480
bool applyData(Packet const &pck) override
Apply the data packed by the same network type from a server.
Definition C_networkType.inl:486
void forceCheckClient(Identity const &id) override
Force the modification flag to be set for the specified client identity.
Definition C_networkType.inl:606
bool check() const override
Check if the value have been modified.
Definition C_networkType.inl:629
void forceUncheckClient(Identity const &id) override
Reset the modification flag for the specified client identity.
Definition C_networkType.inl:617
NetworkType(fge::DataAccessor< T > source)
NetworkType.
Definition C_networkType.inl:23
void packData(Packet &pck, Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
Definition C_networkType.inl:47
void forceCheck() override
Force the value to be modified (even if it is not)
Definition C_networkType.inl:65
void forceUncheck() override
Remove the forced modification of the value.
Definition C_networkType.inl:70
bool applyData(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:60
Definition C_packet.hpp:52
Definition C_networkType.hpp:523
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:513