/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY #include "object_manager.h" #include "class_list.h" #include "world_entity.h" #include "shell_command.h" using namespace std; SHELL_COMMAND(debug, ObjectManager, debug) ->defaultValues(2, NULL, 0); /** * standard constructor */ ObjectManager::ObjectManager () { this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); this->setName("ObjectManager"); pNodeList = NULL; } /** * the singleton reference to this class */ ObjectManager* ObjectManager::singletonRef = NULL; /** @brief standard deconstructor */ ObjectManager::~ObjectManager () { ObjectManager::singletonRef = NULL; } /** * @brief moves an Entity from an old list to a new One * @param entity the entity to move. * @param omList the new List to move the entity to. * * this will erase the entity from the old list */ void ObjectManager::toList (WorldEntity* entity, OM_LIST omList) { if (likely(entity->getOMListNumber() != OM_INIT)) this->objectLists[entity->getOMListNumber()].erase(entity->getEntityIterator()); if (likely(omList != OM_INIT)) { this->objectLists[omList].push_back(entity); entity->getEntityIterator() = --this->objectLists[omList].end(); entity->getOMListNumber() = omList; } } /** * @see ObjectManager::toList(WorldEntity* OM_LIST) * @param entity the entity to move. * @param omList the new List to move the entity to. * * this function also does a transformation from omList as char* to OM_LIST. */ void ObjectManager::toList (WorldEntity* entity, const char* omList) { this->toList(entity, ObjectManager::StringToOMList(omList)); } /** * returns a new List with a list of WorldEntities of distance Radius from center */ std::list* ObjectManager::distanceFromObject(const PNode& center, float radius, ClassID classID) { const std::list* objectList = ClassList::getList(classID); if (objectList != NULL) { std::list* newList = new std::list; list::const_iterator node; for (node = objectList->begin(); node != objectList->end(); node++) if ((dynamic_cast(*node)->getAbsCoor() - center.getAbsCoor()).len() < radius) newList->push_back(dynamic_cast(*node)); return newList; } return NULL; } /** * @brief print out nice debug information about Elements in the list OM_LIST * @param omList the List to debug. */ void ObjectManager::debug(OM_LIST omList) const { if (omList != OM_INIT) { PRINT(0)(" +ObjectManager-LIST: '%s'------\n", ObjectManager::OMListToString((OM_LIST) omList)); std::list::const_iterator entity; for (entity = this->objectLists[omList].begin(); entity != this->objectLists[omList].end(); entity++) { PRINT(0)(" | %s::%s\n",(*entity)->getClassName(), (*entity)->getName()); } } else PRINTF(2)("Invalid query. for OM_INIT-LIST\n"); } /** * @brief prints out very nice debug information * @param listName the Name of the list to get Debug information from */ void ObjectManager::debug(const char* listName) { PRINT(0)("=ObjectManager-DEBUG=============\n"); if (listName == NULL || listName[0] == '\0') for (unsigned int i = 0; i < OM_SIZE; ++i) debug((OM_LIST) i); else debug(ObjectManager::StringToOMList(listName)); PRINT(0)("=========================== OM ==\n"); } /** * @brief transforms an omList into a String (usefull for debugging). * @param omList the OM_LIST to be transformed into a String. * @returns the String transformed from omList. */ const char* ObjectManager::OMListToString(OM_LIST omList) { switch (omList) { case OM_DEAD: return "dead"; case OM_ENVIRON_NOTICK: return "environ-notick"; case OM_ENVIRON: return "environ"; case OM_COMMON: return "common"; case OM_GROUP_00: return "group00"; case OM_GROUP_00_PROJ: return "group00-proj"; case OM_GROUP_01: return "group01"; case OM_GROUP_01_PROJ: return "group01-proj"; case OM_GROUP_02: return "group02"; case OM_GROUP_02_PROJ: return "group02-proj"; case OM_GROUP_03: return "group03"; case OM_GROUP_03_PROJ: return "group03-proj"; case OM_GROUP_04: return "group04"; case OM_GROUP_04_PROJ: return "group04-proj"; case OM_GROUP_05: return "group05"; case OM_GROUP_05_PROJ: return "group05-proj"; case OM_GROUP_06: return "group06"; case OM_GROUP_06_PROJ: return "group06-proj"; case OM_GROUP_07: return "group07"; case OM_GROUP_07_PROJ: return "group07-proj"; case OM_GROUP_08: return "group08"; case OM_GROUP_08_PROJ: return "group08-proj"; case OM_GROUP_09: return "group09"; case OM_GROUP_09_PROJ: return "group09-proj"; case OM_GROUP_10: return "group10"; case OM_GROUP_10_PROJ: return "group10-proj"; case OM_GROUP_11: return "group11"; case OM_GROUP_11_PROJ: return "group11-proj"; case OM_GROUP_12: return "group11"; case OM_GROUP_12_PROJ: return "group12-proj"; case OM_GROUP_13: return "group03"; case OM_GROUP_13_PROJ: return "group13-proj"; case OM_GROUP_14: return "group14"; case OM_GROUP_14_PROJ: return "group14-proj"; case OM_GROUP_15: return "group15"; case OM_GROUP_15_PROJ: return "group15-proj"; default: return "null"; } } OM_LIST ObjectManager::StringToOMList(const char* listName) { if (unlikely(listName == NULL)) return OM_DEFAULT_LIST; if (!strcmp(listName, "dead")) return OM_DEAD; if (!strcmp(listName, "environ-notick")) return OM_ENVIRON_NOTICK; if (!strcmp(listName, "environ")) return OM_ENVIRON; if (!strcmp(listName, "common")) return OM_COMMON; if (!strcmp(listName, "group00")) return OM_GROUP_00; if (!strcmp(listName, "group00-proj")) return OM_GROUP_00_PROJ; if (!strcmp(listName, "group01")) return OM_GROUP_01; if (!strcmp(listName, "group01-proj")) return OM_GROUP_01_PROJ; if (!strcmp(listName, "group02")) return OM_GROUP_02; if (!strcmp(listName, "group02-proj")) return OM_GROUP_02_PROJ; if (!strcmp(listName, "group03")) return OM_GROUP_03; if (!strcmp(listName, "group03-proj")) return OM_GROUP_03_PROJ; if (!strcmp(listName, "group04")) return OM_GROUP_04; if (!strcmp(listName, "group04-proj")) return OM_GROUP_04_PROJ; if (!strcmp(listName, "group05")) return OM_GROUP_05; if (!strcmp(listName, "group05-proj")) return OM_GROUP_05_PROJ; if (!strcmp(listName, "group06")) return OM_GROUP_06; if (!strcmp(listName, "group06-proj")) return OM_GROUP_06_PROJ; if (!strcmp(listName, "group07")) return OM_GROUP_07; if (!strcmp(listName, "group07-proj")) return OM_GROUP_07_PROJ; if (!strcmp(listName, "group08")) return OM_GROUP_08; if (!strcmp(listName, "group08-proj")) return OM_GROUP_08_PROJ; if (!strcmp(listName, "group09")) return OM_GROUP_09; if (!strcmp(listName, "group09-proj")) return OM_GROUP_09_PROJ; if (!strcmp(listName, "group10")) return OM_GROUP_10; if (!strcmp(listName, "group10-proj")) return OM_GROUP_10_PROJ; if (!strcmp(listName, "group11")) return OM_GROUP_11; if (!strcmp(listName, "group11-proj")) return OM_GROUP_11_PROJ; if (!strcmp(listName, "group12")) return OM_GROUP_12; if (!strcmp(listName, "group12-proj")) return OM_GROUP_12_PROJ; if (!strcmp(listName, "group13")) return OM_GROUP_13; if (!strcmp(listName, "group13-proj")) return OM_GROUP_13_PROJ; if (!strcmp(listName, "group14")) return OM_GROUP_14; if (!strcmp(listName, "group14-proj")) return OM_GROUP_14_PROJ; if (!strcmp(listName, "group15")) return OM_GROUP_15; if (!strcmp(listName, "group15-proj")) return OM_GROUP_15_PROJ; return OM_DEFAULT_LIST; }