Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/world_entity.cc @ 3531

Last change on this file since 3531 was 3531, checked in by bensch, 19 years ago

orxonox/trunk: all WorldEntities/PWodes now destroy all date they alocate.

this is done with a virtual destructor:
if PNode is deleted it calls for the delete of the virtual destructor, and deletes the data of it.

File size: 5.8 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: Christian Meyer
16*/
17
18#include <iostream>
19
20#include "world_entity.h"
21#include "stdincl.h"
22//#include "collision.h"
23
24using namespace std;
25
26/**
27   \brief standard constructor
28   
29   Every derived contructor HAS to call the previous one supplying the isFree parameter. This is necessary to distunguish
30   between free and bound entities. The difference between them is simply the fact that the movement of a free entity is
31   not bound to the track of a world. Use this to implement projectile or effect classes that do not have to travel along the track.
32   To specify an entity to be free or bound set the default parameter in the declaration of the constructor.
33   Theoretically you should never have to call the constructor of an Entity directly, for it is called by the spawn() function of the World
34   class. So if you want to create a new entity at any time, call World::spawn(). It will handle everything that is necessary.
35*/
36WorldEntity::WorldEntity (bool isFree) : bFree(isFree)
37{
38  this->setClassName ("WorldEntity");
39  this->bDraw = true;
40  //  collisioncluster = NULL;
41}
42
43/**
44   \brief standard destructor
45*/
46WorldEntity::~WorldEntity ()
47{
48  // if( collisioncluster != NULL) delete collisioncluster;
49  this->destroy();
50}
51
52/**
53   \brief Function to call if a WorldEntity is destroyed. deletes all alocated memory.
54   */
55void WorldEntity::destroy() 
56{
57
58  // delete everything of pNode.
59  static_cast<PNode*>(this)->destroy();
60}
61
62
63/**
64   \brief get the Location of the WorldEntity
65   \return a pointer to location
66*/
67/*PN
68Location* WorldEntity::getLocation ()
69{
70  return &loc;
71}
72*/
73
74/**
75   \brief get the Placement of the WorldEntity
76   \return a pointer to placement
77*/
78 /*PN
79Placement* WorldEntity::getPlacement ()
80{
81  return &place;
82}
83 */
84/**
85   \brief query whether the WorldEntity in question is free
86   \return true if the WorldEntity is free or false if it isn't
87*/
88bool WorldEntity::isFree ()
89{
90  return bFree;
91}
92
93/**
94   \brief set the WorldEntity's collision hull
95   \param newhull: a pointer to a completely assembled CollisionCluster
96   
97   Any previously assigned collision hull will be deleted on reassignment
98*/
99/*
100void WorldEntity::setCollision (CollisionCluster* newhull)
101{
102  if( newhull == NULL) return;
103  if( collisioncluster != NULL) delete collisioncluster;
104  collisioncluster = newhull;
105}
106*/
107
108/**
109   \brief this method is called every frame
110   \param time: the time in seconds that has passed since the last tick
111   
112   Handle all stuff that should update with time inside this method (movement, animation, etc.)
113*/
114void WorldEntity::tick(float time) 
115{
116}
117
118
119/**
120    \brief process draw function
121*/
122void WorldEntity::processDraw ()
123{
124  this->draw ();
125  PNode* pn = this->children->enumerate ();
126  while( pn != NULL) 
127    { 
128      ((WorldEntity*)pn)->processDraw ();
129      pn = this->children->nextElement();
130    } 
131}
132
133/**
134   \brief sets the drawable state of this entity.
135   \param bDraw TRUE if draweable, FALSE otherwise
136*/
137void WorldEntity::setDrawable (bool bDraw)
138{
139  this->bDraw = bDraw;
140}
141
142
143/**
144   \brief the entity is drawn onto the screen with this function
145   
146   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
147*/
148void WorldEntity::draw() 
149{}
150
151/**
152   \brief this function is called, when two entities collide
153   \param other: the world entity with whom it collides
154   \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
155   \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
156
157   Implement behaviour like damage application or other miscellaneous collision stuff in this function
158*/
159void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
160
161/**
162   \brief this function is called, when the ship is hit by a waepon
163   \param weapon: the laser/rocket/shoot that hits.
164   \param loc: place where it is hit
165
166   calculate the damage depending
167*/
168void WorldEntity::hit(WorldEntity* weapon, Vector loc) {}
169
170
171
172/**
173   \brief this is called immediately after the Entity has been constructed and initialized
174   
175   Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
176   DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
177*/
178void WorldEntity::postSpawn ()
179{
180}
181
182/**
183   \brief this handles incoming command messages
184   \param cmd: a pointer to the incoming Command structure
185   
186   Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
187   to send commands from one WorldEntity to another.
188*/
189void WorldEntity::command (Command* cmd)
190{
191}
192
193/**
194   \brief this is called by the local Camera to determine the point it should look at on the WorldEntity
195   \param locbuf: a pointer to the buffer to fill with a location to look at
196       
197   You may put any Location you want into locbuf, the Camera will determine via the corresponding Track how
198   to look at the location you return with this.
199*/
200/*PN
201void WorldEntity::getLookat (Location* locbuf)
202{
203}
204*/
205
206/**
207   \brief this method is called by the world if the WorldEntity leaves valid gamespace
208   
209   For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
210   place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
211*/
212void WorldEntity::leftWorld ()
213{
214}
Note: See TracBrowser for help on using the repository browser.