diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index ddcd721956..327bd56be5 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -23,7 +23,8 @@ QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; -QMap EntityTypes::_typeToFactoryMap; +EntityTypeFactory EntityTypes::_factories[EntityTypes::LAST]; +bool EntityTypes::_factoriesInitialized = false; EntityTypeRenderer EntityTypes::_renderers[EntityTypes::LAST]; bool EntityTypes::_renderersInitialized = false; @@ -62,7 +63,11 @@ bool EntityTypes::registerEntityType(EntityType_t entityType, const char* name, _typeToNameMap[entityType] = name; _nameToTypeMap[name] = entityType; - _typeToFactoryMap[entityType] = factoryMethod; + if (!_factoriesInitialized) { + memset(&_factories,0,sizeof(_factories)); + _factoriesInitialized = true; + } + _factories[entityType] = factoryMethod; return true; } @@ -72,11 +77,8 @@ EntityItem* EntityTypes::constructEntityItem(EntityType_t entityType, const Enti qDebug() << " entityID=" << entityID; EntityItem* newEntityItem = NULL; - - QMap::iterator matchedType = _typeToFactoryMap.find(entityType); - if (matchedType != _typeToFactoryMap.end()) { - EntityTypeFactory factory = matchedType.value(); - + EntityTypeFactory factory = _factories[entityType]; + if (factory) { newEntityItem = factory(entityID, properties); } return newEntityItem; diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index e8eb903a38..08d8df2e67 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -54,7 +54,8 @@ public: private: static QMap _typeToNameMap; static QMap _nameToTypeMap; - static QMap _typeToFactoryMap; + static EntityTypeFactory _factories[LAST]; + static bool _factoriesInitialized; static EntityTypeRenderer _renderers[LAST]; static bool _renderersInitialized; }; diff --git a/libraries/entities/src/todo.txt b/libraries/entities/src/todo.txt index ccc0eca9a4..32ddc46ef8 100644 --- a/libraries/entities/src/todo.txt +++ b/libraries/entities/src/todo.txt @@ -43,8 +43,10 @@ Model properties: // TODO: -// a) crash in entity server on add entity? -// b) entities have same ID? unknown??? +// c) why does is the Box entity not drawn in it's bounds +// d) make the rotated model bounds work for other entity types? +// e) maybe make "hasGeometry" be a property of EntityItem base class?? + // 0) handle subclass properties? @@ -150,7 +152,8 @@ Model properties: // 25) consider moving the EntityTypes static Maps to be inside a singleton instance of EntityTypes to ensure initialization order -// 26) Why can't we call REGISTER_ENTITY_TYPE() in BoxEntityType.cpp +// 26) Why can't we call REGISTER_ENTITY_TYPE() in BoxEntityType.cpp or the CPP of the implementation? +// 27) Consider making properties of the entities be registered... and handle their streaming in a more automatice fashion @@ -209,4 +212,5 @@ Model properties: // SOLVED - 16) duplicate copies of entity references in the elements... this appears to be caused when "viewing" while editing... // SOLVED - 17) Handle the newer on client vs changed on server problem properly for entities // SOLVED - 20) Verified that multiple machines viewing real time edits works - fixed bugs in lastEdited. - +// SOLVED - b) entities have same ID? unknown??? - wasn't setting ID on read from buffer... +// SOLVED - a) crash in entity server on add entity?