[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" |
---|
[1853] | 17 | |
---|
[9869] | 18 | #include "debug.h" |
---|
| 19 | #include "loading/resource_manager.h" |
---|
[8087] | 20 | |
---|
[10114] | 21 | |
---|
| 22 | ObjectListDefinition(BspEntity); |
---|
[9869] | 23 | CREATE_FACTORY(BspEntity); |
---|
[8087] | 24 | |
---|
[9869] | 25 | |
---|
[3564] | 26 | /** |
---|
[8490] | 27 | * constructs and loads a BspEntity from a XML-element |
---|
[4838] | 28 | * @param root the XML-element to load from |
---|
| 29 | */ |
---|
[8490] | 30 | BspEntity::BspEntity(const TiXmlElement* root) |
---|
[4483] | 31 | { |
---|
| 32 | this->init(); |
---|
[8490] | 33 | |
---|
[4838] | 34 | if (root != NULL) |
---|
| 35 | this->loadParams(root); |
---|
[4483] | 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /** |
---|
[4838] | 40 | * standard deconstructor |
---|
| 41 | */ |
---|
[8490] | 42 | BspEntity::~BspEntity () |
---|
[3566] | 43 | { |
---|
[9003] | 44 | if( this->bspManager != NULL) |
---|
[8490] | 45 | delete this->bspManager; |
---|
[3566] | 46 | } |
---|
| 47 | |
---|
[8087] | 48 | |
---|
[9003] | 49 | |
---|
[3762] | 50 | /** |
---|
[8490] | 51 | * initializes the BspEntity |
---|
[4838] | 52 | * @todo change this to what you wish |
---|
| 53 | */ |
---|
[8490] | 54 | void BspEntity::init() |
---|
[4483] | 55 | { |
---|
[9869] | 56 | this->registerObject(this, BspEntity::_objectList); |
---|
[5509] | 57 | |
---|
[9003] | 58 | this->bspManager = NULL; |
---|
[10519] | 59 | this->sortTransparency = 1; |
---|
| 60 | this->sortTransparencyMore = 0; |
---|
[9406] | 61 | |
---|
[10519] | 62 | |
---|
[9656] | 63 | this->name_handle = registerVarId( new SynchronizeableString( &this->name, &this->name_write, "name", PERMISSION_MASTER_SERVER ) ); |
---|
[9406] | 64 | |
---|
[9059] | 65 | this->setSynchronized( true ); |
---|
[8490] | 66 | } |
---|
[5509] | 67 | |
---|
[8490] | 68 | |
---|
| 69 | void BspEntity::setName(const std::string& name) |
---|
| 70 | { |
---|
| 71 | PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str()); |
---|
[9406] | 72 | |
---|
[9059] | 73 | this->name = name; |
---|
[8490] | 74 | |
---|
[9003] | 75 | // Check wether file exists.... |
---|
[9869] | 76 | if ( File(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(name)).exists() ) { |
---|
[9003] | 77 | |
---|
| 78 | this->bspManager = new BspManager(this); |
---|
[10519] | 79 | this->bspManager->sortTransparency = this->sortTransparency; |
---|
| 80 | this->bspManager->sortTransparencyMore = this->sortTransparencyMore; |
---|
[9003] | 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 | } |
---|
[4483] | 92 | } |
---|
| 93 | |
---|
[10519] | 94 | void 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 | } |
---|
[5509] | 105 | |
---|
[4483] | 106 | /** |
---|
[8490] | 107 | * loads a BspEntity from a XML-element |
---|
[4838] | 108 | * @param root the XML-element to load from |
---|
| 109 | * @todo make the class Loadable |
---|
| 110 | */ |
---|
[8490] | 111 | void BspEntity::loadParams(const TiXmlElement* root) |
---|
[4483] | 112 | { |
---|
[4838] | 113 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[9003] | 114 | // WorldEntity::loadParam(root); |
---|
[8087] | 115 | |
---|
[8490] | 116 | LoadParam(root, "Name", this, BspEntity, setName) |
---|
[9003] | 117 | .describe("Sets the of the BSP file."); |
---|
[4483] | 118 | |
---|
[10519] | 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 | |
---|
[9003] | 123 | /* LoadParam(root, "Scale", this, BSpEntity, setScale) |
---|
| 124 | .describe("Sets the scale factore of the bsp level."); |
---|
| 125 | */ |
---|
[5509] | 126 | |
---|
| 127 | /** |
---|
| 128 | * @todo: make the class Loadable |
---|
| 129 | */ |
---|
[4483] | 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | /** |
---|
[8490] | 134 | * advances the BspEntity about time seconds |
---|
[4838] | 135 | * @param time the Time to step |
---|
| 136 | */ |
---|
[8490] | 137 | void BspEntity::tick(float time) |
---|
[3762] | 138 | { |
---|
[8490] | 139 | this->bspManager->tick(time); |
---|
[3762] | 140 | } |
---|
| 141 | |
---|
[8081] | 142 | |
---|
[3245] | 143 | /** |
---|
[4838] | 144 | * draws this worldEntity |
---|
| 145 | */ |
---|
[8490] | 146 | void BspEntity::draw () const |
---|
[4838] | 147 | { |
---|
[8081] | 148 | this->bspManager->draw(); |
---|
[3559] | 149 | } |
---|
[5509] | 150 | |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * |
---|
| 154 | * |
---|
| 155 | */ |
---|
[8490] | 156 | void BspEntity::collidesWith (WorldEntity* entity, const Vector& location) |
---|
[9003] | 157 | {} |
---|
[9059] | 158 | |
---|
| 159 | void 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 | } |
---|