diff --git a/ControlCore/CoreThing.cpp b/ControlCore/CoreThing.cpp index 40c7fa6..c33602e 100644 --- a/ControlCore/CoreThing.cpp +++ b/ControlCore/CoreThing.cpp @@ -8,31 +8,31 @@ CoreThing::CoreThing( this->type = thingType; this->networkId = networkId; this->Init(); - // CoreThings::Add(this); + CoreThing::Add(this); } void CoreThing::Init() {} -// CoreThing *CoreThings::allThings[256] = {nullptr}; +CoreThing *CoreThing::allThings[256] = {nullptr}; -// CoreThing *CoreThings::Get(unsigned char networkId, unsigned char thingId) { -// for (unsigned char ix = 0; ix < 256; ix++) { -// CoreThing *thing = allThings[ix]; -// if (thing == nullptr) -// continue; -// if (thing->networkId == networkId && thing->id == thingId) -// return thing; -// } -// return nullptr; -// } +CoreThing *CoreThing::Get(unsigned char networkId, unsigned char thingId) { + for (unsigned char ix = 0; ix < 256; ix++) { + CoreThing *thing = allThings[ix]; + if (thing == nullptr) + continue; + if (thing->networkId == networkId && thing->id == thingId) + return thing; + } + return nullptr; +} -// bool CoreThings::Add(CoreThing *newThing) { -// for (unsigned char ix = 0; ix < 256; ix++) { -// CoreThing *thing = allThings[ix]; -// if (thing == nullptr) { -// allThings[ix] = newThing; -// return true; -// } -// } -// return false; -// } \ No newline at end of file +bool CoreThing::Add(CoreThing *newThing) { + for (unsigned char ix = 0; ix < 256; ix++) { + CoreThing *thing = allThings[ix]; + if (thing == nullptr) { + allThings[ix] = newThing; + return true; + } + } + return false; +} \ No newline at end of file diff --git a/ControlCore/CoreThing.h b/ControlCore/CoreThing.h index 8937455..8b36634 100644 --- a/ControlCore/CoreThing.h +++ b/ControlCore/CoreThing.h @@ -15,27 +15,19 @@ public: const char *modelUrl; // protected Sensor sensor; + static CoreThing *allThings[]; + public: CoreThing( // Participant *client, unsigned char networkId, unsigned char thingId, unsigned char thingType = 0); + static CoreThing *Get(unsigned char networkId, unsigned char thingId); + static bool Add(CoreThing *thing); + protected: virtual void Init(); - - // Things }; -// class CoreThings { -// friend class CoreThing; - -// public: -// static CoreThing *allThings[]; - -// public: -// static CoreThing *Get(unsigned char networkId, unsigned char thingId); -// static bool Add(CoreThing *thing); -// }; - } // namespace Passer::Control diff --git a/Thing.cpp b/Thing.cpp index 377a048..515a5cc 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -6,8 +6,8 @@ using namespace Passer::RoboidControl; int Thing::lastThingId = 1; -Thing::Thing() { - //: CoreThing(0, lastThingId++, (unsigned char)Type::Undetermined) { +Thing::Thing() + : CoreThing(0, lastThingId++, (unsigned char)Type::Undetermined) { this->id = lastThingId++; this->type = (unsigned int)Type::Undetermined; this->childCount = 0; @@ -15,14 +15,14 @@ Thing::Thing() { this->children = nullptr; } -Thing::Thing(unsigned char id) { - //: CoreThing(0, id, (unsigned char)Type::Undetermined) { +Thing::Thing(unsigned char id) + : CoreThing(0, id, (unsigned char)Type::Undetermined) { this->id = id; - // this->position = SphericalOf::zero; this->type = (unsigned int)Type::Undetermined; this->childCount = 0; this->parent = nullptr; this->children = nullptr; + // this->position = SphericalOf::zero; } void Thing::SetName(const char *name) { this->name = name; } diff --git a/Thing.h b/Thing.h index bd27e63..9989789 100644 --- a/Thing.h +++ b/Thing.h @@ -10,7 +10,7 @@ namespace Passer { namespace RoboidControl { /// @brief A thing is a functional component on a robot -class Thing { //: public CoreThing { +class Thing : public CoreThing { public: Thing(); /// @brief Default constructor for a Thing