diff options
author | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-22 01:29:43 +0100 |
---|---|---|
committer | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-22 01:29:43 +0100 |
commit | 7170c16a463fdb1f446ab7458270205bf08e7c89 (patch) | |
tree | 58be57180690416272be1167900b74d4a56bfed2 /engine/object.cpp | |
parent | Fix typo to compile (diff) | |
download | flatland-7170c16a463fdb1f446ab7458270205bf08e7c89.tar.gz flatland-7170c16a463fdb1f446ab7458270205bf08e7c89.zip |
Signal change
Diffstat (limited to 'engine/object.cpp')
-rw-r--r-- | engine/object.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/engine/object.cpp b/engine/object.cpp new file mode 100644 index 0000000..eb74e1a --- /dev/null +++ b/engine/object.cpp @@ -0,0 +1,62 @@ +#include "flatobject.h" + +#include <stdlib.h> + +using namespace std; +using namespace flat::core; + +list<object*> object::all_objects; + +object::object() +{ + /* Collect this object */ + object::all_objects.push_back(this); +} + +object::~object() +{ + /* Eliminate this object reference */ + object::all_objects.remove(this); +} + +void object::set_id(const string& id) +{ + this->id = id; +} + +const string& object::get_id() const +{ + return id; +} + +string object::random_id(uint8_t length) { + + string out; + + for (Uint8 i = 0; i < length; ++i) + out += (char)(rand() % 93 + 33); + + return out; +} + +bool object::is_allocated(object *obj) +{ + for (object * o : object::all_objects) + { + if (o == obj) + return true; + } + + return false; +} + +vector<object*>& object::get_by_id(const string& id, vector<object*>& l) +{ + for (object * obj : object::all_objects) + { + if (id == obj->getID()) + l.push_back(obj); + } + + return l; +} |