Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cleanup/src/world_entities/bsp_entity.cc @ 10586

Last change on this file since 10586 was 10519, checked in by patrick, 18 years ago

emitter fix

File size: 3.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Claudio Botta
13   co-programmer: ...
14*/
15
16#include "bsp_entity.h"
17
18#include "debug.h"
19#include "loading/resource_manager.h"
20
21
22ObjectListDefinition(BspEntity);
23CREATE_FACTORY(BspEntity);
24
25
26/**
27 * constructs and loads a BspEntity from a XML-element
28 * @param root the XML-element to load from
29 */
30BspEntity::BspEntity(const TiXmlElement* root)
31{
32  this->init();
33
34  if (root != NULL)
35    this->loadParams(root);
36}
37
38
39/**
40 * standard deconstructor
41 */
42BspEntity::~BspEntity ()
43{
44  if( this->bspManager != NULL)
45    delete this->bspManager;
46}
47
48
49
50/**
51 * initializes the BspEntity
52 * @todo change this to what you wish
53 */
54void BspEntity::init()
55{
56  this->registerObject(this, BspEntity::_objectList);
57
58  this->bspManager = NULL;
59  this->sortTransparency = 1;
60  this->sortTransparencyMore = 0;
61
62
63  this->name_handle = registerVarId( new SynchronizeableString( &this->name, &this->name_write, "name", PERMISSION_MASTER_SERVER ) );
64
65  this->setSynchronized( true );
66}
67
68
69void BspEntity::setName(const std::string& name)
70{
71  PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str());
72
73  this->name = name;
74
75  // Check wether file exists....
76  if ( File(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(name)).exists()  ) {
77
78    this->bspManager = new BspManager(this);
79    this->bspManager->sortTransparency = this->sortTransparency;
80    this->bspManager->sortTransparencyMore = this->sortTransparencyMore;
81
82    if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) {
83      this->bspManager = NULL;
84
85    } else {
86      this->toList(OM_ENVIRON); // Success!!!
87    }
88  } else {
89    this->bspManager = NULL;
90    this->toList(OM_DEAD);
91  }
92}
93
94void BspEntity::setTransparency(int sort, int sortMore)
95{
96  this->sortTransparency = sort;
97  this->sortTransparencyMore = sortMore;
98 
99  if (this->bspManager != NULL)
100  {
101    this->bspManager->sortTransparency = sort;
102    this->bspManager->sortTransparencyMore = sortMore;
103  }
104}
105
106/**
107 * loads a BspEntity from a XML-element
108 * @param root the XML-element to load from
109 * @todo make the class Loadable
110 */
111void BspEntity::loadParams(const TiXmlElement* root)
112{
113  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
114  // WorldEntity::loadParam(root);
115
116  LoadParam(root, "Name", this, BspEntity, setName)
117  .describe("Sets the of the BSP file.");
118
119  LoadParam(root, "Transparency", this, BspEntity, setTransparency)
120  .describe("1. argument: true -> sort transparent textures; 2. argument: true -> better but slower sorting")
121  .defaultValues(1, 0);
122 
123  /*  LoadParam(root, "Scale", this, BSpEntity, setScale)
124        .describe("Sets the scale factore of the bsp level.");
125  */
126
127  /**
128   * @todo: make the class Loadable
129   */
130}
131
132
133/**
134 * advances the BspEntity about time seconds
135 * @param time the Time to step
136 */
137void BspEntity::tick(float time)
138{
139  this->bspManager->tick(time);
140}
141
142
143/**
144 * draws this worldEntity
145 */
146void BspEntity::draw () const
147{
148  this->bspManager->draw();
149}
150
151
152/**
153 *
154 *
155 */
156void BspEntity::collidesWith (WorldEntity* entity, const Vector& location)
157{}
158
159void BspEntity::varChangeHandler( std::list< int > & id )
160{
161  if ( std::find( id.begin(), id.end(), this->name_handle ) != id.end() )
162  {
163    this->setName( this->name_write );
164  }
165}
Note: See TracBrowser for help on using the repository browser.