From 39935c4ecdfead8ecc3f4fee82022e207e0a316f Mon Sep 17 00:00:00 2001 From: Andrew nuark G Date: Wed, 16 Dec 2020 00:22:33 +0700 Subject: [PATCH] Updated interactions with objects subsystem --- system/object_system.cpp | 74 ++++++++++++++++++++++++++++++++++++++++ system/object_system.h | 4 +-- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/system/object_system.cpp b/system/object_system.cpp index 9266313..cba284f 100644 --- a/system/object_system.cpp +++ b/system/object_system.cpp @@ -1,7 +1,81 @@ #include "object_system.h" +const dpoint_entity& object_system::get_dpoint(entity_id oid, bool &success) { + dpoint_entity *out; + success = false; + for (dpoint_entity &item : this->_dpoints) { + if (item.id() == oid) { + success = true; + out = &item; + break; + } + } + + return *out; +} + +bool object_system::remove_dpoint(entity_id oid) { + auto vit = this->_dpoints.begin(); + for (; vit != this->_dpoints.end(); vit++) { + if ((*vit).id() == oid) { + this->_dpoints.erase(vit); + return true; + } + } + + return false; +} + +bool object_system::add_dpoint(dpoint_entity dpoint) { + bool exists = false; + this->get_dpoint(dpoint.id(), exists); + if (!exists) { + this->_dpoints.push_back(dpoint); + return true; + } + + return false; +} + +const vessel_entity& object_system::get_vessel(entity_id oid, bool &success) { + vessel_entity *out; + + success = false; + for (vessel_entity &item : this->_vessels) { + if (item.id() == oid) { + success = true; + out = &item; + break; + } + } + + return *out; +} + +bool object_system::remove_vessel(entity_id oid) { + auto vit = this->_vessels.begin(); + for (; vit != this->_vessels.end(); vit++) { + if ((*vit).id() == oid) { + this->_vessels.erase(vit); + return true; + } + } + + return false; +} + +bool object_system::add_vessel(vessel_entity dpoint) { + bool exists = false; + this->get_dpoint(dpoint.id(), exists); + if (!exists) { + this->_vessels.push_back(dpoint); + return true; + } + + return false; +} void object_system::init(QDataStream &stream) { int dicnt; diff --git a/system/object_system.h b/system/object_system.h index 3d362b2..d69d32a 100644 --- a/system/object_system.h +++ b/system/object_system.h @@ -18,11 +18,11 @@ public: const dpoint_entity& get_dpoint(entity_id oid, bool &success); bool remove_dpoint(entity_id oid); - bool add_dpoint(const dpoint_entity &dpoint); + bool add_dpoint(dpoint_entity dpoint); const vessel_entity& get_vessel(entity_id oid, bool &success); bool remove_vessel(entity_id oid); - bool add_vessel(const vessel_entity &dpoint); + bool add_vessel(vessel_entity dpoint); void init(QDataStream &stream);