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