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 | #include "util/loading/resource_manager.h" |
---|
18 | #include "util/loading/resource_manager.h" |
---|
19 | |
---|
20 | CREATE_FACTORY(BspEntity, CL_BSP_ENTITY); |
---|
21 | |
---|
22 | |
---|
23 | /** |
---|
24 | * constructs and loads a BspEntity from a XML-element |
---|
25 | * @param root the XML-element to load from |
---|
26 | */ |
---|
27 | BspEntity::BspEntity(const TiXmlElement* root) |
---|
28 | { |
---|
29 | this->init(); |
---|
30 | |
---|
31 | if (root != NULL) |
---|
32 | this->loadParams(root); |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | /** |
---|
37 | * standard deconstructor |
---|
38 | */ |
---|
39 | BspEntity::~BspEntity () |
---|
40 | { |
---|
41 | if( this->bspManager != NULL) |
---|
42 | delete this->bspManager; |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * initializes the BspEntity |
---|
49 | * @todo change this to what you wish |
---|
50 | */ |
---|
51 | void BspEntity::init() |
---|
52 | { |
---|
53 | |
---|
54 | this->bspManager = NULL; |
---|
55 | |
---|
56 | this->name_handle = registerVarId( new SynchronizeableString( &this->name, &this->name_write, "name" ) ); |
---|
57 | |
---|
58 | this->setSynchronized( true ); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void BspEntity::setName(const std::string& name) |
---|
63 | { |
---|
64 | PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str()); |
---|
65 | |
---|
66 | this->name = name; |
---|
67 | |
---|
68 | // Check wether file exists.... |
---|
69 | if ( File(ResourceManager::getFullName(name)).exists() ) { |
---|
70 | |
---|
71 | this->setClassID(CL_BSP_ENTITY, "BspEntity"); |
---|
72 | this->bspManager = new BspManager(this); |
---|
73 | |
---|
74 | if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) { |
---|
75 | this->bspManager = NULL; |
---|
76 | |
---|
77 | } else { |
---|
78 | this->toList(OM_ENVIRON); // Success!!! |
---|
79 | } |
---|
80 | } else { |
---|
81 | this->bspManager = NULL; |
---|
82 | this->toList(OM_DEAD); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | * loads a BspEntity from a XML-element |
---|
89 | * @param root the XML-element to load from |
---|
90 | * @todo make the class Loadable |
---|
91 | */ |
---|
92 | void BspEntity::loadParams(const TiXmlElement* root) |
---|
93 | { |
---|
94 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
95 | // WorldEntity::loadParam(root); |
---|
96 | |
---|
97 | LoadParam(root, "Name", this, BspEntity, setName) |
---|
98 | .describe("Sets the of the BSP file."); |
---|
99 | |
---|
100 | /* LoadParam(root, "Scale", this, BSpEntity, setScale) |
---|
101 | .describe("Sets the scale factore of the bsp level."); |
---|
102 | */ |
---|
103 | |
---|
104 | /** |
---|
105 | * @todo: make the class Loadable |
---|
106 | */ |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * advances the BspEntity about time seconds |
---|
112 | * @param time the Time to step |
---|
113 | */ |
---|
114 | void BspEntity::tick(float time) |
---|
115 | { |
---|
116 | this->bspManager->tick(time); |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | /** |
---|
121 | * draws this worldEntity |
---|
122 | */ |
---|
123 | void BspEntity::draw () const |
---|
124 | { |
---|
125 | this->bspManager->draw(); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | /** |
---|
130 | * |
---|
131 | * |
---|
132 | */ |
---|
133 | void BspEntity::collidesWith (WorldEntity* entity, const Vector& location) |
---|
134 | {} |
---|
135 | |
---|
136 | void BspEntity::varChangeHandler( std::list< int > & id ) |
---|
137 | { |
---|
138 | if ( std::find( id.begin(), id.end(), this->name_handle ) != id.end() ) |
---|
139 | { |
---|
140 | this->setName( this->name_write ); |
---|
141 | } |
---|
142 | } |
---|