Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

groundturret now scales correctly on client

File size: 5.5 KB
Line 
1
2
3/*
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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
18
19#include "base_object.h"
20
21#include "load_param.h"
22#include "compiler.h"
23#include "class_list.h"
24
25#include "synchronizeable.h"
26
27using namespace std;
28
29
30/**
31 *  sets the name from a LoadXML-Element
32 * @param root the element to load from
33 */
34BaseObject::BaseObject(const TiXmlElement* root)
35{
36  this->className = NULL;
37  this->classID = CL_BASE_OBJECT;
38
39  this->objectName = NULL;
40
41  if (root)
42    this->loadParams(root);
43
44//  ClassList::addToClassList(this, this->classID, "BaseObject");
45}
46
47/**
48 *  standard deconstructor
49*/
50BaseObject::~BaseObject ()
51{
52  ClassList::removeFromClassList(this);
53
54  //  delete []this->className;
55  if (this->objectName)
56    delete[] this->objectName;
57}
58
59/**
60 *  loads parameters
61 * @param root the element to load from
62 */
63void BaseObject::loadParams(const TiXmlElement* root)
64{
65  // name setup
66  LoadParam(root, "name", this, BaseObject, setName)
67      .describe("the Name of the Object.");
68}
69
70/**
71 *  sets the class identifiers
72 * @param id a number for the class from class_id.h enumeration
73 * @param className the class name
74*/
75void BaseObject::setClassID(ClassID classID, const char* className)
76{
77  this->classID |= (long)classID;
78  this->className = className;
79
80  ClassList::addToClassList(this, classID, className);
81}
82
83/**
84  \brief set the name of the Object
85 */
86void BaseObject::setName (const char* objectName)
87{
88  if (this->objectName)
89    delete[] this->objectName;
90  if (objectName != NULL)
91  {
92    this->objectName = new char[strlen(objectName)+1];
93    strcpy(this->objectName, objectName);
94  }
95  else
96    this->objectName = NULL;
97}
98
99
100/**
101 *  checks if the class is a classID
102 * @param classID the Identifier to check for
103 * @returns true if it is, false otherwise
104*/
105bool BaseObject::isA (ClassID classID) const
106{
107  // if classID is a derivable object from a SUPERCLASS
108  if (classID & CL_MASK_SUPER_CLASS)
109  {
110    if( likely(this->classID & classID))
111      return true;
112  }
113  // if classID is a SubSuperClass, and
114  else if (classID & CL_MASK_SUBSUPER_CLASS)
115  {
116    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (this->classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
117        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
118      return true;
119  }
120  // if classID is a LOWLEVEL-class
121  else
122  {
123    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
124      return true;
125  }
126  return false;
127}
128
129/**
130 *  checks if the class is a classID
131 * @param classID the Identifier to check for
132 * @returns true if it is, false otherwise
133 */
134bool BaseObject::isA (const char* className) const
135{
136  ClassID classID = ClassList::StringToID(className);
137  if (classID != CL_NULL)
138    return this->isA(classID);
139}
140
141/**
142 * compares the ObjectName with an external name
143 * @param objectName: the name to check.
144 * @returns true on match, false otherwise.
145 */
146bool BaseObject::operator==(const char* objectName)
147{
148  if (likely(this->objectName != NULL && objectName != NULL))
149    return (strcmp(this->objectName, objectName)) ? false : true;
150}
151
152
153/**
154 *  displays everything this class is
155 * @TODO REIMPLEMENT WITH SENSE.
156 */
157void BaseObject::whatIs() const
158{
159  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
160  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
161    PRINT(0)("is a Singleton-Class ");
162  if (this->classID & CL_MASK_SUPER_CLASS)
163  {
164    PRINT(0)(" ->is a derived from the following superclasses:");
165    if (this->isA(CL_BASE_OBJECT))
166      PRINT(0)(" =BaseObject=");
167    if (this->isA(CL_PARENT_NODE))
168      PRINT(0)(" =PNode=");
169    if (this->isA(CL_WORLD_ENTITY))
170      PRINT(0)(" =WorldEntity=");
171    if (this->isA(CL_PHYSICS_INTERFACE))
172      PRINT(0)(" =PhysicsInterface=");
173    if (this->isA(CL_EVENT_LISTENER))
174      PRINT(0)(" =EventListener=");
175    if (this->isA(CL_STORY_ENTITY))
176      PRINT(0)(" =StoryEntity=");
177    if (this->isA(CL_ELEMENT_2D))
178      PRINT(0)(" =Element2D=");
179    PRINT(0)("\n");
180  }
181  // subsuper-classes
182  if (this->classID & CL_MASK_SUBSUPER_CLASS)
183  {
184    PRINT(0)(" ->further derivations: ");
185    if (this->isA(CL_PLAYER))
186      PRINT(0)(" -Player-");
187    if (this->isA(CL_NPC))
188      PRINT(0)(" -NPC-");
189    if (this->isA(CL_POWER_UP))
190      PRINT(0)(" -PowerUp-");
191    if (this->isA(CL_FIELD))
192      PRINT(0)(" -Field-");
193    if (this->isA(CL_PROJECTILE))
194      PRINT(0)(" -Projectile-");
195    if (this->isA(CL_WEAPON))
196      PRINT(0)(" -Weapon-");
197    PRINT(0)("\n");
198  }
199}
200
201/**
202 * Writes data from network containing information about the state
203 * @param data pointer to data
204 * @param length length of data
205 * @param sender hostID of sender
206 */
207int BaseObject::writeState( const byte * data, int length, int sender )
208{
209  SYNCHELP_READ_BEGIN();
210
211  if ( objectName )
212  {
213    delete[] objectName;
214    objectName = NULL;
215  }
216  SYNCHELP_READ_STRINGM( this->objectName );
217
218  return SYNCHELP_READ_N;
219}
220
221/**
222 * data copied in data will bee sent to another host
223 * @param data pointer to data
224 * @param maxLength max length of data
225 * @return the number of bytes writen
226 */
227int BaseObject::readState( byte * data, int maxLength )
228{
229  SYNCHELP_WRITE_BEGIN();
230
231  SYNCHELP_WRITE_STRING( this->objectName );
232
233  return SYNCHELP_WRITE_N;
234}
Note: See TracBrowser for help on using the repository browser.