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