[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 | { |
---|
[6276] | 36 | this->className = "BaseObject"; |
---|
[4591] | 37 | this->classID = CL_BASE_OBJECT; |
---|
[4435] | 38 | |
---|
[7214] | 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 | */ |
---|
[5791] | 80 | void BaseObject::setClassID(ClassID classID, const char* 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 | */ |
---|
[7203] | 95 | void BaseObject::setName (const std::string& objectName) |
---|
[4435] | 96 | { |
---|
[7214] | 97 | printf("TEST\n"); |
---|
| 98 | this->objectName = objectName; |
---|
| 99 | printf("TEST2\n"); |
---|
[4435] | 100 | } |
---|
[4592] | 101 | |
---|
[6281] | 102 | |
---|
[6280] | 103 | /** |
---|
| 104 | * @brief queries for the ClassID of the Leaf Class (the last made class of this type |
---|
| 105 | * @returns the ClassID of the Leaf Class (e.g. the ID of the Class) |
---|
| 106 | * |
---|
| 107 | * the returned ID can be used to generate new Objects of the same type through |
---|
| 108 | * Factory::fabricate(Object->getLeafClassID()); |
---|
| 109 | */ |
---|
| 110 | ClassID BaseObject::getLeafClassID() const |
---|
| 111 | { |
---|
| 112 | assert (this->classList != NULL); |
---|
| 113 | return this->classList->getLeafClassID(); |
---|
| 114 | } |
---|
[4592] | 115 | |
---|
[6280] | 116 | |
---|
| 117 | |
---|
[4592] | 118 | /** |
---|
[6280] | 119 | * @brief checks if the class is a classID |
---|
[4836] | 120 | * @param classID the Identifier to check for |
---|
| 121 | * @returns true if it is, false otherwise |
---|
[4592] | 122 | */ |
---|
[6077] | 123 | bool BaseObject::isA (ClassID classID) const |
---|
[4592] | 124 | { |
---|
[4837] | 125 | // if classID is a derivable object from a SUPERCLASS |
---|
| 126 | if (classID & CL_MASK_SUPER_CLASS) |
---|
[4594] | 127 | { |
---|
[4837] | 128 | if( likely(this->classID & classID)) |
---|
[4594] | 129 | return true; |
---|
[4837] | 130 | } |
---|
| 131 | // if classID is a SubSuperClass, and |
---|
| 132 | else if (classID & CL_MASK_SUBSUPER_CLASS) |
---|
| 133 | { |
---|
[7123] | 134 | if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) && |
---|
[5915] | 135 | this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB)) |
---|
[4837] | 136 | return true; |
---|
| 137 | } |
---|
| 138 | // if classID is a LOWLEVEL-class |
---|
[4594] | 139 | else |
---|
| 140 | { |
---|
[4837] | 141 | if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)) |
---|
[4594] | 142 | return true; |
---|
| 143 | } |
---|
[4592] | 144 | return false; |
---|
| 145 | } |
---|
| 146 | |
---|
[6280] | 147 | |
---|
| 148 | |
---|
[4592] | 149 | /** |
---|
[6280] | 150 | * @brief checks if the class is a classID |
---|
[5513] | 151 | * @param classID the Identifier to check for |
---|
| 152 | * @returns true if it is, false otherwise |
---|
| 153 | */ |
---|
| 154 | bool BaseObject::isA (const char* className) const |
---|
| 155 | { |
---|
[6077] | 156 | ClassID classID = ClassList::StringToID(className); |
---|
[5513] | 157 | if (classID != CL_NULL) |
---|
| 158 | return this->isA(classID); |
---|
| 159 | } |
---|
| 160 | |
---|
[6280] | 161 | |
---|
[5626] | 162 | /** |
---|
[6280] | 163 | * @brief compares the ObjectName with an external name |
---|
[5626] | 164 | * @param objectName: the name to check. |
---|
| 165 | * @returns true on match, false otherwise. |
---|
| 166 | */ |
---|
[5791] | 167 | bool BaseObject::operator==(const char* objectName) |
---|
[5626] | 168 | { |
---|
[7214] | 169 | return (objectName != NULL && this->objectName == objectName); |
---|
[5626] | 170 | } |
---|
[5513] | 171 | |
---|
[5626] | 172 | |
---|
[5513] | 173 | /** |
---|
[6280] | 174 | * @brief displays everything this class is |
---|
[5642] | 175 | * @TODO REIMPLEMENT WITH SENSE. |
---|
[4592] | 176 | */ |
---|
[4746] | 177 | void BaseObject::whatIs() const |
---|
[4592] | 178 | { |
---|
[6280] | 179 | |
---|
[4592] | 180 | } |
---|
[6341] | 181 | |
---|
| 182 | /** |
---|
| 183 | * Writes data from network containing information about the state |
---|
| 184 | * @param data pointer to data |
---|
| 185 | * @param length length of data |
---|
| 186 | * @param sender hostID of sender |
---|
| 187 | */ |
---|
| 188 | int BaseObject::writeState( const byte * data, int length, int sender ) |
---|
| 189 | { |
---|
[7214] | 190 | /// FIXME STD |
---|
[6341] | 191 | |
---|
[7214] | 192 | /* SYNCHELP_READ_BEGIN(); |
---|
| 193 | |
---|
| 194 | if ( !objectName.empty() ) |
---|
[6341] | 195 | { |
---|
| 196 | delete[] objectName; |
---|
| 197 | objectName = NULL; |
---|
| 198 | } |
---|
[6815] | 199 | SYNCHELP_READ_STRINGM( this->objectName, NWT_BO_NAME ); |
---|
[6498] | 200 | if ( this->objectName && !strcmp(this->objectName, "") ) |
---|
| 201 | { |
---|
| 202 | delete[] this->objectName; |
---|
| 203 | this->objectName = NULL; |
---|
| 204 | } |
---|
[6341] | 205 | |
---|
[7214] | 206 | return SYNCHELP_READ_N;*/ |
---|
[6341] | 207 | } |
---|
| 208 | |
---|
| 209 | /** |
---|
| 210 | * data copied in data will bee sent to another host |
---|
| 211 | * @param data pointer to data |
---|
| 212 | * @param maxLength max length of data |
---|
| 213 | * @return the number of bytes writen |
---|
| 214 | */ |
---|
| 215 | int BaseObject::readState( byte * data, int maxLength ) |
---|
| 216 | { |
---|
[7214] | 217 | ///FIXME STD |
---|
| 218 | /* SYNCHELP_WRITE_BEGIN(); |
---|
[6341] | 219 | |
---|
[6634] | 220 | //PRINTF(0)("objectname = %s\n", this->objectName); |
---|
[6815] | 221 | SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME ); |
---|
[6341] | 222 | |
---|
[7214] | 223 | return SYNCHELP_WRITE_N;*/ |
---|
[6341] | 224 | } |
---|