Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/lang/base_object.cc @ 6257

Last change on this file since 6257 was 6257, checked in by rennerc, 19 years ago

class_id.h: changed CL_ENTITY_MANAGER to CL_NETWORK_GAME_MANAGER
base_object: added realClassID which can be used with factory
network_game_manager: fixed some bugs again, can now spawn entities over network :D

File size: 4.7 KB
RevLine 
[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
15   co-programmer: ...
16*/
[5439]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
[3302]18
19#include "base_object.h"
[4747]20
[4436]21#include "load_param.h"
[4595]22#include "compiler.h"
[4747]23#include "class_list.h"
[3302]24
25using namespace std;
26
27
28/**
[4836]29 *  sets the name from a LoadXML-Element
30 * @param root the element to load from
[5439]31 */
[4436]32BaseObject::BaseObject(const TiXmlElement* root)
[3531]33{
34  this->className = NULL;
[4591]35  this->classID = CL_BASE_OBJECT;
[4435]36
37  this->objectName = NULL;
[4436]38
39  if (root)
40    this->loadParams(root);
[4747]41
[4778]42//  ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]43}
[3302]44
45/**
[4836]46 *  standard deconstructor
[3302]47*/
[4591]48BaseObject::~BaseObject ()
[3531]49{
[4747]50  ClassList::removeFromClassList(this);
51
[4261]52  //  delete []this->className;
[4435]53  if (this->objectName)
[5447]54    delete[] this->objectName;
55}
[3302]56
[4436]57/**
[4836]58 *  loads parameters
59 * @param root the element to load from
[5439]60 */
[4436]61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // name setup
[5671]64  LoadParam(root, "name", this, BaseObject, setName)
[5645]65      .describe("the Name of the Object.");
[4436]66}
[4321]67
68/**
[4836]69 *  sets the class identifiers
70 * @param id a number for the class from class_id.h enumeration
71 * @param className the class name
[4321]72*/
[5791]73void BaseObject::setClassID(ClassID classID, const char* className)
[4320]74{
[5791]75  this->classID |= (long)classID;
[4320]76  this->className = className;
[6257]77  this->realClassID = classID;
[4747]78
79  ClassList::addToClassList(this, classID, className);
[4320]80}
[4318]81
[4435]82/**
[4591]83  \brief set the name of the Object
84 */
[4742]85void BaseObject::setName (const char* objectName)
[4435]86{
87  if (this->objectName)
[5113]88    delete[] this->objectName;
[5645]89  if (objectName != NULL)
[4592]90  {
91    this->objectName = new char[strlen(objectName)+1];
92    strcpy(this->objectName, objectName);
93  }
[4591]94  else
[4435]95    this->objectName = NULL;
96}
[4592]97
98
99/**
[4836]100 *  checks if the class is a classID
101 * @param classID the Identifier to check for
102 * @returns true if it is, false otherwise
[4592]103*/
[6077]104bool BaseObject::isA (ClassID classID) const
[4592]105{
[4837]106  // if classID is a derivable object from a SUPERCLASS
107  if (classID & CL_MASK_SUPER_CLASS)
[4594]108  {
[4837]109    if( likely(this->classID & classID))
[4594]110      return true;
[4837]111  }
112  // if classID is a SubSuperClass, and
113  else if (classID & CL_MASK_SUBSUPER_CLASS)
114  {
[5915]115    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (this->classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
116        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
[4837]117      return true;
118  }
119  // if classID is a LOWLEVEL-class
[4594]120  else
121  {
[4837]122    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
[4594]123      return true;
124  }
[4592]125  return false;
126}
127
128/**
[5513]129 *  checks if the class is a classID
130 * @param classID the Identifier to check for
131 * @returns true if it is, false otherwise
132 */
133bool BaseObject::isA (const char* className) const
134{
[6077]135  ClassID classID = ClassList::StringToID(className);
[5513]136  if (classID != CL_NULL)
137    return this->isA(classID);
138}
139
[5626]140/**
141 * compares the ObjectName with an external name
142 * @param objectName: the name to check.
143 * @returns true on match, false otherwise.
144 */
[5791]145bool BaseObject::operator==(const char* objectName)
[5626]146{
147  if (likely(this->objectName != NULL && objectName != NULL))
148    return (strcmp(this->objectName, objectName)) ? false : true;
149}
[5513]150
[5626]151
[5513]152/**
[4836]153 *  displays everything this class is
[5642]154 * @TODO REIMPLEMENT WITH SENSE.
[4592]155 */
[4746]156void BaseObject::whatIs() const
[4592]157{
[4595]158  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
[4596]159  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
160    PRINT(0)("is a Singleton-Class ");
[4594]161  if (this->classID & CL_MASK_SUPER_CLASS)
[4592]162  {
[4596]163    PRINT(0)(" ->is a derived from the following superclasses:");
[4595]164    if (this->isA(CL_BASE_OBJECT))
165      PRINT(0)(" =BaseObject=");
166    if (this->isA(CL_PARENT_NODE))
167      PRINT(0)(" =PNode=");
168    if (this->isA(CL_WORLD_ENTITY))
169      PRINT(0)(" =WorldEntity=");
170    if (this->isA(CL_PHYSICS_INTERFACE))
171      PRINT(0)(" =PhysicsInterface=");
172    if (this->isA(CL_EVENT_LISTENER))
173      PRINT(0)(" =EventListener=");
174    if (this->isA(CL_STORY_ENTITY))
175      PRINT(0)(" =StoryEntity=");
[4874]176    if (this->isA(CL_ELEMENT_2D))
177      PRINT(0)(" =Element2D=");
[4595]178    PRINT(0)("\n");
[4592]179  }
[4595]180  // subsuper-classes
181  if (this->classID & CL_MASK_SUBSUPER_CLASS)
182  {
183    PRINT(0)(" ->further derivations: ");
184    if (this->isA(CL_PLAYER))
185      PRINT(0)(" -Player-");
186    if (this->isA(CL_NPC))
187      PRINT(0)(" -NPC-");
188    if (this->isA(CL_POWER_UP))
189      PRINT(0)(" -PowerUp-");
190    if (this->isA(CL_FIELD))
191      PRINT(0)(" -Field-");
192    if (this->isA(CL_PROJECTILE))
193      PRINT(0)(" -Projectile-");
194    if (this->isA(CL_WEAPON))
195      PRINT(0)(" -Weapon-");
196    PRINT(0)("\n");
[4592]197}
[5642]198}
Note: See TracBrowser for help on using the repository browser.