[3302] | 1 | |
---|
| 2 | |
---|
[4591] | 3 | /* |
---|
[3302] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[6640] | 15 | co-programmer: Benjamin Grauer |
---|
[3302] | 16 | */ |
---|
[5439] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE |
---|
[3302] | 18 | |
---|
| 19 | #include "base_object.h" |
---|
[4747] | 20 | |
---|
[7193] | 21 | #include "util/loading/load_param.h" |
---|
[4595] | 22 | #include "compiler.h" |
---|
[4747] | 23 | #include "class_list.h" |
---|
[3302] | 24 | |
---|
[6341] | 25 | #include "synchronizeable.h" |
---|
| 26 | |
---|
[3302] | 27 | using namespace std; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /** |
---|
[6280] | 31 | * @brief sets the name from a LoadXML-Element |
---|
[4836] | 32 | * @param root the element to load from |
---|
[5439] | 33 | */ |
---|
[6517] | 34 | BaseObject::BaseObject() |
---|
[3531] | 35 | { |
---|
[7221] | 36 | this->classID = CL_BASE_OBJECT; |
---|
[6276] | 37 | this->className = "BaseObject"; |
---|
[4435] | 38 | |
---|
[7221] | 39 | this->objectName = ""; |
---|
[6280] | 40 | this->classList = NULL; |
---|
[6517] | 41 | this->xmlElem = NULL; |
---|
[4436] | 42 | |
---|
[4778] | 43 | // ClassList::addToClassList(this, this->classID, "BaseObject"); |
---|
[3531] | 44 | } |
---|
[3302] | 45 | |
---|
| 46 | /** |
---|
[6280] | 47 | * @brief standard deconstructor |
---|
[3302] | 48 | */ |
---|
[4591] | 49 | BaseObject::~BaseObject () |
---|
[3531] | 50 | { |
---|
[4747] | 51 | ClassList::removeFromClassList(this); |
---|
| 52 | |
---|
[4261] | 53 | // delete []this->className; |
---|
[6517] | 54 | if (this->xmlElem != NULL) |
---|
| 55 | delete this->xmlElem; |
---|
[5447] | 56 | } |
---|
[3302] | 57 | |
---|
[4436] | 58 | /** |
---|
[6280] | 59 | * @brief loads parameters |
---|
[4836] | 60 | * @param root the element to load from |
---|
[5439] | 61 | */ |
---|
[4436] | 62 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
| 63 | { |
---|
[6517] | 64 | // all loadParams should sometime arrive here. |
---|
| 65 | assert (root != NULL); |
---|
| 66 | |
---|
| 67 | if (this->xmlElem != NULL) |
---|
| 68 | delete this->xmlElem; |
---|
| 69 | this->xmlElem = root->Clone(); |
---|
[4436] | 70 | // name setup |
---|
[5671] | 71 | LoadParam(root, "name", this, BaseObject, setName) |
---|
[5645] | 72 | .describe("the Name of the Object."); |
---|
[4436] | 73 | } |
---|
[4321] | 74 | |
---|
| 75 | /** |
---|
[6280] | 76 | * @brief sets the class identifiers |
---|
[4836] | 77 | * @param id a number for the class from class_id.h enumeration |
---|
| 78 | * @param className the class name |
---|
[4321] | 79 | */ |
---|
[7221] | 80 | void BaseObject::setClassID(ClassID classID, const std::string& className) |
---|
[4320] | 81 | { |
---|
[6282] | 82 | //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID); |
---|
| 83 | assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA )); |
---|
[6276] | 84 | |
---|
[5791] | 85 | this->classID |= (long)classID; |
---|
[4320] | 86 | this->className = className; |
---|
[4747] | 87 | |
---|
[6280] | 88 | this->classList = ClassList::addToClassList(this, classID, this->classID, className); |
---|
[4320] | 89 | } |
---|
[4318] | 90 | |
---|
[6280] | 91 | |
---|
[4435] | 92 | /** |
---|
[6280] | 93 | * @brief set the name of the Object |
---|
[4591] | 94 | */ |
---|
[7221] | 95 | void BaseObject::setName (const std::string& objectName) |
---|
[4435] | 96 | { |
---|
[7221] | 97 | this->objectName = objectName; |
---|
[4435] | 98 | } |
---|
[4592] | 99 | |
---|
[6281] | 100 | |
---|
[6280] | 101 | /** |
---|
| 102 | * @brief queries for the ClassID of the Leaf Class (the last made class of this type |
---|
| 103 | * @returns the ClassID of the Leaf Class (e.g. the ID of the Class) |
---|
| 104 | * |
---|
| 105 | * the returned ID can be used to generate new Objects of the same type through |
---|
| 106 | * Factory::fabricate(Object->getLeafClassID()); |
---|
| 107 | */ |
---|
| 108 | ClassID BaseObject::getLeafClassID() const |
---|
| 109 | { |
---|
| 110 | assert (this->classList != NULL); |
---|
| 111 | return this->classList->getLeafClassID(); |
---|
| 112 | } |
---|
[4592] | 113 | |
---|
[6280] | 114 | |
---|
| 115 | |
---|
[4592] | 116 | /** |
---|
[6280] | 117 | * @brief checks if the class is a classID |
---|
[4836] | 118 | * @param classID the Identifier to check for |
---|
| 119 | * @returns true if it is, false otherwise |
---|
[4592] | 120 | */ |
---|
[6077] | 121 | bool BaseObject::isA (ClassID classID) const |
---|
[4592] | 122 | { |
---|
[4837] | 123 | // if classID is a derivable object from a SUPERCLASS |
---|
| 124 | if (classID & CL_MASK_SUPER_CLASS) |
---|
[4594] | 125 | { |
---|
[4837] | 126 | if( likely(this->classID & classID)) |
---|
[4594] | 127 | return true; |
---|
[4837] | 128 | } |
---|
| 129 | // if classID is a SubSuperClass, and |
---|
| 130 | else if (classID & CL_MASK_SUBSUPER_CLASS) |
---|
| 131 | { |
---|
[7123] | 132 | if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) && |
---|
[5915] | 133 | this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB)) |
---|
[4837] | 134 | return true; |
---|
| 135 | } |
---|
| 136 | // if classID is a LOWLEVEL-class |
---|
[4594] | 137 | else |
---|
| 138 | { |
---|
[4837] | 139 | if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)) |
---|
[4594] | 140 | return true; |
---|
| 141 | } |
---|
[4592] | 142 | return false; |
---|
| 143 | } |
---|
| 144 | |
---|
[6280] | 145 | |
---|
| 146 | |
---|
[4592] | 147 | /** |
---|
[6280] | 148 | * @brief checks if the class is a classID |
---|
[5513] | 149 | * @param classID the Identifier to check for |
---|
| 150 | * @returns true if it is, false otherwise |
---|
| 151 | */ |
---|
[7221] | 152 | bool BaseObject::isA (const std::string& className) const |
---|
[5513] | 153 | { |
---|
[6077] | 154 | ClassID classID = ClassList::StringToID(className); |
---|
[5513] | 155 | if (classID != CL_NULL) |
---|
| 156 | return this->isA(classID); |
---|
| 157 | } |
---|
| 158 | |
---|
[6280] | 159 | |
---|
[5626] | 160 | /** |
---|
[6280] | 161 | * @brief compares the ObjectName with an external name |
---|
[5626] | 162 | * @param objectName: the name to check. |
---|
| 163 | * @returns true on match, false otherwise. |
---|
| 164 | */ |
---|
[7221] | 165 | bool BaseObject::operator==(const std::string& objectName) |
---|
[5626] | 166 | { |
---|
[7221] | 167 | return (this->objectName == objectName); |
---|
[5626] | 168 | } |
---|
[5513] | 169 | |
---|
[5626] | 170 | |
---|
[5513] | 171 | /** |
---|
[6280] | 172 | * @brief displays everything this class is |
---|
[5642] | 173 | * @TODO REIMPLEMENT WITH SENSE. |
---|
[4592] | 174 | */ |
---|
[4746] | 175 | void BaseObject::whatIs() const |
---|
[4592] | 176 | { |
---|
[6280] | 177 | |
---|
[4592] | 178 | } |
---|
[6341] | 179 | |
---|
| 180 | /** |
---|
| 181 | * Writes data from network containing information about the state |
---|
| 182 | * @param data pointer to data |
---|
| 183 | * @param length length of data |
---|
| 184 | * @param sender hostID of sender |
---|
| 185 | */ |
---|
| 186 | int BaseObject::writeState( const byte * data, int length, int sender ) |
---|
| 187 | { |
---|
[7230] | 188 | SYNCHELP_READ_BEGIN(); |
---|
[6341] | 189 | |
---|
[7230] | 190 | SYNCHELP_READ_STRING( this->objectName, NWT_BO_NAME ); |
---|
[7221] | 191 | |
---|
[7230] | 192 | return SYNCHELP_READ_N; |
---|
[6341] | 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * data copied in data will bee sent to another host |
---|
| 197 | * @param data pointer to data |
---|
| 198 | * @param maxLength max length of data |
---|
| 199 | * @return the number of bytes writen |
---|
| 200 | */ |
---|
| 201 | int BaseObject::readState( byte * data, int maxLength ) |
---|
| 202 | { |
---|
[7230] | 203 | SYNCHELP_WRITE_BEGIN(); |
---|
[6341] | 204 | |
---|
[6634] | 205 | //PRINTF(0)("objectname = %s\n", this->objectName); |
---|
[6815] | 206 | SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME ); |
---|
[6341] | 207 | |
---|
[7230] | 208 | return SYNCHELP_WRITE_N; |
---|
[6341] | 209 | } |
---|