Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/lang/base_object.cc @ 4815

Last change on this file since 4815 was 4815, checked in by patrick, 19 years ago

orxonox/trunk: now some other singletons get deleted at the end of the game. there is some classid problem with the collision detection framework: the stuff gets deleted, but the names remain in the list. bensch: you will have to adjust the class ids of the cd so it works, no idea how i could do this :)

File size: 3.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*/
17
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/**
[4436]29   \brief sets the name from a LoadXML-Element
30   \param root the element to load from
[3302]31*/
[4436]32BaseObject::BaseObject(const TiXmlElement* root)
[3531]33{
34  this->className = NULL;
[4591]35  this->classID = CL_BASE_OBJECT;
[3646]36  this->finalized = false;
[4435]37
38  this->objectName = NULL;
[4436]39
40  if (root)
41    this->loadParams(root);
[4747]42
[4778]43//  ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]44}
[3302]45
46/**
47   \brief standard deconstructor
48*/
[4591]49BaseObject::~BaseObject ()
[3531]50{
[4747]51  ClassList::removeFromClassList(this);
52
[4261]53  //  delete []this->className;
[4435]54  if (this->objectName)
[4747]55    delete []this->objectName;}
[3302]56
[4436]57/**
58   \brief loads parameters
59   \param root the element to load from
60*/
61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // name setup
64  LoadParam<BaseObject>(root, "name", this, &BaseObject::setName)
[4591]65  .describe("the name of the Object at hand");
[4436]66}
[4321]67
68/**
69   \brief sets the class identifiers
[4744]70   \param id a number for the class from class_id.h enumeration
[4470]71   \param className the class name
[4321]72*/
[4591]73void BaseObject::setClassID(long classID, const char* className)
[4320]74{
[4592]75  this->classID |= classID;
[4320]76  this->className = className;
[4747]77
78  ClassList::addToClassList(this, classID, className);
[4320]79}
[4318]80
[4435]81/**
[4591]82  \brief set the name of the Object
83 */
[4742]84void BaseObject::setName (const char* objectName)
[4435]85{
86  if (this->objectName)
87    delete []this->objectName;
[4591]88  if (objectName)
[4592]89  {
90    this->objectName = new char[strlen(objectName)+1];
91    strcpy(this->objectName, objectName);
92  }
[4591]93  else
[4435]94    this->objectName = NULL;
95}
[4592]96
97
98/**
99   \brief checks if the class is a classID
100   \param classID the Identifier to check for
101   \returns true if it is, false otherwise
102*/
[4747]103bool BaseObject::isA (long classID) const
[4592]104{
[4594]105  // if classID is a derivable object
[4815]106  if ( likely(classID & CL_MASK_SUPER_CLASS || classID & CL_MASK_SUBSUPER_CLASS))
[4594]107  {
108    if( this->classID & classID)
109      return true;
[4815]110  } // if classID is a LOWLEVEL-class
[4594]111  else
112  {
[4815]113    if( (this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)
[4594]114      return true;
115  }
[4592]116  return false;
117}
118
119/**
120 * @brief displays everything this class is
121 */
[4746]122void BaseObject::whatIs() const
[4592]123{
[4595]124  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
[4596]125  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
126    PRINT(0)("is a Singleton-Class ");
[4594]127  if (this->classID & CL_MASK_SUPER_CLASS)
[4592]128  {
[4596]129    PRINT(0)(" ->is a derived from the following superclasses:");
[4595]130    if (this->isA(CL_BASE_OBJECT))
131      PRINT(0)(" =BaseObject=");
132    if (this->isA(CL_PARENT_NODE))
133      PRINT(0)(" =PNode=");
134    if (this->isA(CL_WORLD_ENTITY))
135      PRINT(0)(" =WorldEntity=");
136    if (this->isA(CL_PHYSICS_INTERFACE))
137      PRINT(0)(" =PhysicsInterface=");
138    if (this->isA(CL_EVENT_LISTENER))
139      PRINT(0)(" =EventListener=");
140    if (this->isA(CL_STORY_ENTITY))
141      PRINT(0)(" =StoryEntity=");
142    PRINT(0)("\n");
[4592]143  }
[4595]144  // subsuper-classes
145  if (this->classID & CL_MASK_SUBSUPER_CLASS)
146  {
147    PRINT(0)(" ->further derivations: ");
148    if (this->isA(CL_PLAYER))
149      PRINT(0)(" -Player-");
150    if (this->isA(CL_NPC))
151      PRINT(0)(" -NPC-");
152    if (this->isA(CL_POWER_UP))
153      PRINT(0)(" -PowerUp-");
154    if (this->isA(CL_FIELD))
155      PRINT(0)(" -Field-");
156    if (this->isA(CL_PROJECTILE))
157      PRINT(0)(" -Projectile-");
158    if (this->isA(CL_WEAPON))
159      PRINT(0)(" -Weapon-");
160    PRINT(0)("\n");
161  }
[4592]162}
Note: See TracBrowser for help on using the repository browser.