Changeset 1502
- Timestamp:
- Jun 1, 2008, 3:54:20 PM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 5 deleted
- 131 edited
- 31 copied
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified code/trunk/CMakeLists.txt ¶
r1293 r1502 45 45 SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O0 -Wall -g -ggdb") 46 46 SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") 47 #SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O3") 48 #SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O3") 49 47 50 SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}") 48 51 SET(CMAKE_EXE_LINKER_FLAGS " --no-undefined") … … 65 68 FIND_PACKAGE(ENet) 66 69 FIND_PACKAGE(Boost REQUIRED thread) 70 FIND_PACKAGE(Boost REQUIRED filesystem) 67 71 FIND_PACKAGE(OpenAL) 68 72 FIND_PACKAGE(ALUT) … … 71 75 FIND_PACKAGE(Lua) 72 76 FIND_PACKAGE(TCL) 77 FIND_PACKAGE(DirectX) 73 78 74 79 #Set the search paths for the linking … … 96 101 ${Lua_INCLUDE_DIR} 97 102 ${TCL_INCLUDE_PATH} 103 ${DirectX_INCLUDE_DIR} 104 ${ZLIB_INCLUDE_DIR} 98 105 ) 99 106 -
TabularUnified code/trunk/TODO ¶
r1293 r1502 1 very urgent: make sure receiver thread of connectionmanager is 2 threadsafe (event_type_receive, findclient) 1 - should we use enet_peer_ping to test if a client is still alive ? 2 - enet_host_broadcast ? (to all peers) 3 - enet_host_check_events ? instead of enet_host_service -
TabularUnified code/trunk/bin/disco.txt ¶
r1069 r1502 2 2 delay 0.2 Ambient setAmbientLightTest 0,1,0,1 3 3 delay 0.4 Ambient setAmbientLightTest 0,0,1,1 4 delay 0.6 execdisco.txt4 delay 0.6 source disco.txt -
TabularUnified code/trunk/bin/levels/sample.oxw ¶
r1407 r1502 9 9 </audio--> 10 10 11 < !--Ambient colourvalue="1,1,1" /-->12 <Skybox src="Orxonox/Star SkyBox" />11 <Ambient colourvalue="0.1, 0.1, 0.1" /> 12 <Skybox src="Orxonox/Starbox" /> 13 13 <SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" /> 14 <Model position="1500,0,100" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/> 15 <Model position="0,4200,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/> 16 <Model position="0,0,6800" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/> 14 <Model position="2000,0,0" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/> 15 <Model position="0,2000,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/> 16 <Model position="0,0,2000" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/> 17 <Model position="10000,16000,0" scale="100" mesh="DuBall1.mesh"/> 18 <Model position="11400,16000,0" scale="60" mesh="DuBall2.mesh"/> 17 19 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/> 18 20 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/> -
TabularUnified code/trunk/bin/run-script ¶
r1293 r1502 8 8 fi 9 9 10 if [[ ! -forge.cfg ]] ; then10 if [[ -ne orge.cfg ]] ; then 11 11 cp ogre.cfg-init ogre.cfg 12 12 fi -
TabularUnified code/trunk/cmake/FindBoost.cmake ¶
r1293 r1502 102 102 SET(SUFFIX_FOR_PATH 103 103 boost 104 boost-1_35_0 105 boost-1_35 104 106 boost-1_34_1 105 107 boost-1_34_0 … … 113 115 # 114 116 IF(WIN32) 115 SET(Boost_INCLUDE_DIR ../libs/boost_1_33_1) 117 SET(Boost_INCLUDE_DIR 118 # ../libs/boost_1_33_1 119 ../libs/boost_1_34_1 120 # ../libs/boost_1_35_0 121 ) 116 122 ELSE(WIN32) 117 123 FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS … … 188 194 gcc-1_33_1 189 195 gcc-mt-1_33_1 196 mgw34-mt-1_34_1 197 mgw34-mt-1_35 190 198 ) 191 199 -
TabularUnified code/trunk/cmake/FindZLIB.cmake ¶
r790 r1502 58 58 ENDIF(EXISTS "../libs/ogre/Dependencies/lib/Release") 59 59 60 FIND_PATH(ZLIB_INCLUDE_DIR zlib.h 61 ../libs/ogre/Dependencies/include 62 ) 63 60 64 FIND_LIBRARY(ZLIB_LIBRARY 61 65 NAMES zlib … … 63 67 ) 64 68 65 IF(ZLIB_LIBRARY )69 IF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) 66 70 MESSAGE(STATUS "Zlib was found.") 67 ELSE(ZLIB_LIBRARY )71 ELSE(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) 68 72 MESSAGE(FATAL_ERROR "Zlib was NOT found.") 69 ENDIF(ZLIB_LIBRARY )73 ENDIF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) 70 74 ENDIF(WIN32) -
TabularUnified code/trunk/src/audio/AudioPrereqs.h ¶
r1069 r1502 35 35 #define _AudioPrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 //----------------------------------------------------------------------- -
TabularUnified code/trunk/src/audio/AudioStream.cc ¶
r1064 r1502 117 117 118 118 for(int i = 0; i < vorbisComment->comments; i++) 119 { 119 120 COUT(3) << " " << vorbisComment->user_comments[i] << std::endl; 121 } 120 122 121 123 COUT(3) << std::endl; -
TabularUnified code/trunk/src/core/CMakeLists.txt ¶
r1224 r1502 2 2 BaseObject.cc 3 3 ClassTreeMask.cc 4 CommandExecutor.cc5 4 ConfigFileManager.cc 6 5 ConfigValueContainer.cc … … 11 10 Identifier.cc 12 11 IdentifierDistributor.cc 12 InputManager.cc 13 KeyBinder.cc 14 OutputBuffer.cc 13 15 InputBuffer.cc 14 InputHandler.cc 15 InputManager.cc 16 Shell.cc 17 CommandExecutor.cc 18 CommandEvaluation.cc 19 ConsoleCommand.cc 20 ArgumentCompletionFunctions.cc 21 ConsoleCommandCompilation.cc 16 22 Language.cc 17 23 Loader.cc … … 26 32 Tickable.cc 27 33 XMLPort.cc 34 TclThreadManager.cc 35 IRC.cc 28 36 tolua/tolua_bind.cc 29 37 ) … … 47 55 ois 48 56 util 57 ${Boost_thread_LIBRARIES} 58 ${Boost_filesystem_LIBRARIES} 49 59 ) -
TabularUnified code/trunk/src/core/ClassManager.h ¶
r1062 r1502 49 49 #include "Identifier.h" 50 50 #include "IdentifierDistributor.h" 51 #include "Debug.h" 51 52 52 53 namespace orxonox -
TabularUnified code/trunk/src/core/CommandExecutor.cc ¶
r1349 r1502 31 31 #include "util/String.h" 32 32 #include "util/Convert.h" 33 #include "util/SubString.h"34 33 #include "Identifier.h" 35 34 #include "Language.h" 36 35 #include "Debug.h" 37 #include "Executor.h"38 #include "ConfigValueContainer.h"39 36 #include "TclBind.h" 40 41 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"42 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY "tset"43 #define COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND "bind"44 37 45 38 namespace orxonox 46 39 { 47 ConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set", AccessLevel::User));48 ConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset", AccessLevel::User));49 ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));50 51 ConsoleCommandShortcutExtern(exec, AccessLevel::None);52 ConsoleCommandShortcutExtern(echo, AccessLevel::None);53 54 ConsoleCommandShortcutExtern(read, AccessLevel::None);55 ConsoleCommandShortcutExtern(append, AccessLevel::None);56 ConsoleCommandShortcutExtern(write, AccessLevel::None);57 58 void exec(const std::string& filename)59 {60 static std::set<std::string> executingFiles;61 62 std::set<std::string>::const_iterator it = executingFiles.find(filename);63 if (it != executingFiles.end())64 {65 COUT(1) << "Error: Recurring exec command in \"" << filename << "\". Stopped execution." << std::endl;66 return;67 }68 69 // Open the file70 std::ifstream file;71 file.open(filename.c_str(), std::fstream::in);72 73 if (!file.is_open())74 {75 COUT(1) << "Error: Couldn't execute file \"" << filename << "\"." << std::endl;76 return;77 }78 79 executingFiles.insert(filename);80 81 // Iterate through the file and put the lines into the CommandExecutor82 char line[1024];83 while (file.good() && !file.eof())84 {85 file.getline(line, 1024);86 CommandExecutor::execute(line);87 }88 89 executingFiles.erase(filename);90 file.close();91 }92 93 std::string echo(const std::string& text)94 {95 return text;96 }97 98 void write(const std::string& filename, const std::string& text)99 {100 std::ofstream file;101 file.open(filename.c_str(), std::fstream::out);102 103 if (!file.is_open())104 {105 COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;106 return;107 }108 109 file << text << std::endl;110 file.close();111 }112 113 void append(const std::string& filename, const std::string& text)114 {115 std::ofstream file;116 file.open(filename.c_str(), std::fstream::app);117 118 if (!file.is_open())119 {120 COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;121 return;122 }123 124 file << text << std::endl;125 file.close();126 }127 128 std::string read(const std::string& filename)129 {130 std::ifstream file;131 file.open(filename.c_str(), std::fstream::in);132 133 if (!file.is_open())134 {135 COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;136 return "";137 }138 139 std::string output = "";140 char line[1024];141 while (file.good() && !file.eof())142 {143 file.getline(line, 1024);144 output += line;145 output += "\n";146 }147 148 file.close();149 150 return output;151 }152 153 154 ///////////////////////155 // CommandEvaluation //156 ///////////////////////157 CommandEvaluation::CommandEvaluation()158 {159 this->processedCommand_ = "";160 this->additionalParameter_ = "";161 162 this->functionclass_ = 0;163 this->configvalueclass_ = 0;164 this->shortcut_ = 0;165 this->function_ = 0;166 this->configvalue_ = 0;167 this->key_ = 0;168 169 this->errorMessage_ = "";170 this->state_ = CS_Uninitialized;171 172 this->bEvaluatedParams_ = false;173 this->evaluatedExecutor_ = 0;174 }175 176 KeybindMode::Enum CommandEvaluation::getKeybindMode()177 {178 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)179 {180 // if (this->shortcut_ != 0)181 // return this->shortcut_->getKeybindMode();182 }183 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)184 {185 // if (this->function_ != 0)186 // return this->function_->getKeybindMode();187 }188 else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)189 {190 // return KeybindMode::onPress;191 }192 else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)193 {194 // return KeybindMode::onPress;195 }196 else197 {198 // return KeybindMode::onPress;199 }200 // FIXME: Had to insert a return statement201 return (KeybindMode::Enum)0;202 }203 204 bool CommandEvaluation::isValid() const205 {206 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)207 {208 return this->shortcut_;209 }210 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)211 {212 return (this->functionclass_ && this->function_);213 }214 else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)215 {216 return (this->configvalueclass_ && this->configvalue_);217 }218 else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)219 {220 return this->key_;221 }222 else223 {224 return false;225 }226 }227 228 void CommandEvaluation::evaluateParams()229 {230 this->bEvaluatedParams_ = false;231 this->evaluatedExecutor_ = 0;232 233 for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)234 this->param_[i] = MT_null;235 236 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)237 {238 if (this->shortcut_)239 {240 if (this->tokens_.size() <= 1)241 {242 if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))243 {244 this->bEvaluatedParams_ = true;245 this->evaluatedExecutor_ = this->shortcut_;246 }247 }248 else if (this->tokens_.size() > 1)249 {250 if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))251 {252 this->bEvaluatedParams_ = true;253 this->evaluatedExecutor_ = this->shortcut_;254 }255 }256 }257 }258 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)259 {260 if (this->function_)261 {262 if (this->tokens_.size() <= 2)263 {264 if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))265 {266 this->bEvaluatedParams_ = true;267 this->evaluatedExecutor_ = this->function_;268 }269 }270 else if (this->tokens_.size() > 2)271 {272 if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))273 {274 this->bEvaluatedParams_ = true;275 this->evaluatedExecutor_ = this->function_;276 }277 }278 }279 }280 }281 282 void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)283 {284 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)285 this->param_[index] = param;286 }287 288 MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const289 {290 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)291 return this->param_[index];292 293 return MT_null;294 }295 296 bool CommandEvaluation::hasReturnvalue() const297 {298 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)299 {300 if (this->shortcut_)301 return this->shortcut_->hasReturnvalue();302 }303 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)304 {305 if (this->function_)306 return this->function_->hasReturnvalue();307 }308 309 return MT_null;310 }311 312 MultiTypeMath CommandEvaluation::getReturnvalue() const313 {314 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)315 {316 if (this->shortcut_)317 return this->shortcut_->getReturnvalue();318 }319 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)320 {321 if (this->function_)322 return this->function_->getReturnvalue();323 }324 325 return MT_null;326 }327 328 329 /////////////////////330 // CommandExecutor //331 /////////////////////332 40 CommandExecutor& CommandExecutor::getInstance() 333 41 { … … 346 54 } 347 55 348 Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 349 { 350 CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor; 351 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor; 352 return (*executor); 56 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command) 57 { 58 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName()); 59 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end()) 60 { 61 COUT(2) << "Warning: Overwriting console-command shortcut with name " << command->getName() << "." << std::endl; 62 } 63 64 65 CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command; 66 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command; 67 return (*command); 353 68 } 354 69 … … 358 73 @return The executor of the requested console command shortcut 359 74 */ 360 ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)361 { 362 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);75 ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name) 76 { 77 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name); 363 78 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end()) 364 79 return (*it).second; … … 372 87 @return The executor of the requested console command shortcut 373 88 */ 374 ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)375 { 376 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);89 ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name) 90 { 91 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name); 377 92 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end()) 378 93 return (*it).second; … … 384 99 { 385 100 if (useTcl) 386 {387 101 return TclBind::eval(command); 388 } 389 else 390 { 391 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 392 CommandExecutor::parse(command); 393 394 return CommandExecutor::execute(CommandExecutor::getEvaluation()); 395 } 396 } 397 398 399 bool CommandExecutor::execute(const CommandEvaluation& evaluation) 400 { 401 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 402 403 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_) 404 { 405 std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl; 406 (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]); 407 return true; 408 } 409 410 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n"; 411 switch (evaluation.state_) 412 { 413 case CS_Uninitialized: 414 break; 415 case CS_Empty: 416 break; 417 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 418 break; 419 case CS_Shortcut_Params: 420 // not enough parameters but lets hope there are some additional parameters and go on 421 case CS_Shortcut_Finished: 422 // call the shortcut 423 if (evaluation.shortcut_) 424 { 425 if (tokens.size() >= 2) 426 return evaluation.shortcut_->parse(removeSlashes(tokens.subSet(1).join() + evaluation.getAdditionalParameter())); 427 else 428 return evaluation.shortcut_->parse(removeSlashes(evaluation.additionalParameter_)); 429 } 430 break; 431 case CS_Function: 432 break; 433 case CS_Function_Params: 434 // not enough parameters but lets hope there are some additional parameters and go on 435 case CS_Function_Finished: 436 // call the shortcut 437 if (evaluation.function_) 438 { 439 if (tokens.size() >= 3) 440 return evaluation.function_->parse(removeSlashes(tokens.subSet(2).join() + evaluation.getAdditionalParameter())); 441 else 442 return evaluation.function_->parse(removeSlashes(evaluation.additionalParameter_)); 443 } 444 break; 445 case CS_ConfigValueClass: 446 break; 447 case CS_ConfigValue: 448 break; 449 case CS_ConfigValueType: 450 // not enough parameters but lets hope there are some additional parameters and go on 451 case CS_ConfigValueFinished: 452 // set the config value 453 if (evaluation.configvalue_) 454 { 455 if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)) 456 { 457 if (tokens.size() >= 4) 458 return evaluation.configvalue_->set(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter())); 459 else 460 return evaluation.configvalue_->set(removeSlashes(evaluation.additionalParameter_)); 461 } 462 else if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 463 { 464 if (tokens.size() >= 4) 465 return evaluation.configvalue_->tset(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter())); 466 else 467 return evaluation.configvalue_->tset(removeSlashes(evaluation.additionalParameter_)); 468 } 469 } 470 break; 471 case CS_KeybindKey: 472 break; 473 case CS_KeybindCommand: 474 // not enough parameters but lets hope there are some additional parameters and go on 475 case CS_KeybindFinished: 476 // set the keybind 477 // ...todo 478 break; 479 case CS_Error: 480 break; 481 } 482 483 return false; 102 103 CommandExecutor::parseIfNeeded(command); 104 return CommandExecutor::getEvaluation().execute(); 484 105 } 485 106 486 107 std::string CommandExecutor::complete(const std::string& command) 487 108 { 488 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 489 CommandExecutor::parse(command); 490 491 return CommandExecutor::complete(CommandExecutor::getEvaluation()); 492 } 493 494 std::string CommandExecutor::complete(const CommandEvaluation& evaluation) 495 { 496 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 497 498 std::list<std::pair<const std::string*, const std::string*> > temp; 499 if (evaluation.state_ == CS_Empty) 500 { 501 temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end()); 502 temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end()); 503 } 504 505 switch (evaluation.state_) 506 { 507 case CS_Uninitialized: 508 break; 509 case CS_Empty: 510 return (CommandExecutor::getCommonBegin(temp)); 511 break; 512 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 513 break; 514 case CS_Shortcut_Params: 515 if (evaluation.shortcut_) 516 return (evaluation.shortcut_->getName() + " "); 517 break; 518 case CS_Shortcut_Finished: 519 if (evaluation.shortcut_) 520 { 521 if (evaluation.shortcut_->getParamCount() == 0) 522 return (evaluation.shortcut_->getName()); 523 else if (tokens.size() >= 2) 524 return (evaluation.shortcut_->getName() + " " + tokens.subSet(1).join()); 525 } 526 break; 527 case CS_Function: 528 if (evaluation.functionclass_) 529 return (evaluation.functionclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_)); 530 break; 531 case CS_Function_Params: 532 if (evaluation.functionclass_ && evaluation.function_) 533 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " "); 534 break; 535 case CS_Function_Finished: 536 if (evaluation.functionclass_ && evaluation.function_) 537 { 538 if (evaluation.function_->getParamCount() == 0) 539 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName()); 540 else if (tokens.size() >= 3) 541 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " " + tokens.subSet(2).join()); 542 } 543 break; 544 case CS_ConfigValueClass: 545 if (tokens.size() >= 1) 546 return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_)); 547 break; 548 case CS_ConfigValue: 549 if ((tokens.size() >= 1) && evaluation.configvalueclass_) 550 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_)); 551 break; 552 case CS_ConfigValueType: 553 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_) 554 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " "); 555 break; 556 case CS_ConfigValueFinished: 557 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_ && (tokens.size() >= 4)) 558 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " " + tokens.subSet(3).join()); 559 break; 560 case CS_KeybindKey: 561 if (tokens.size() >= 1) 562 return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_)); 563 break; 564 case CS_KeybindCommand: 565 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 566 return (evaluation.processedCommand_ + " "); 567 break; 568 case CS_KeybindFinished: 569 break; 570 case CS_Error: 571 break; 572 } 573 574 return evaluation.processedCommand_; 109 CommandExecutor::parseIfNeeded(command); 110 return CommandExecutor::getEvaluation().complete(); 575 111 } 576 112 577 113 std::string CommandExecutor::hint(const std::string& command) 578 114 { 579 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 580 CommandExecutor::parse(command); 581 582 return CommandExecutor::hint(CommandExecutor::getEvaluation()); 583 } 584 585 std::string CommandExecutor::hint(const CommandEvaluation& evaluation) 586 { 587 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 588 589 switch (evaluation.state_) 590 { 591 case CS_Uninitialized: 592 break; 593 case CS_Empty: 594 return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_)); 595 break; 596 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 597 break; 598 case CS_Shortcut_Params: 599 if (evaluation.shortcut_) 600 return CommandExecutor::dump(evaluation.shortcut_); 601 break; 602 case CS_Shortcut_Finished: 603 if (evaluation.shortcut_) 604 return CommandExecutor::dump(evaluation.shortcut_); 605 break; 606 case CS_Function: 607 return CommandExecutor::dump(evaluation.listOfPossibleFunctions_); 608 break; 609 case CS_Function_Params: 610 if (evaluation.function_) 611 return CommandExecutor::dump(evaluation.function_); 612 break; 613 case CS_Function_Finished: 614 if (evaluation.function_) 615 return CommandExecutor::dump(evaluation.function_); 616 break; 617 case CS_ConfigValueClass: 618 return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_); 619 break; 620 case CS_ConfigValue: 621 return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_); 622 break; 623 case CS_ConfigValueType: 624 if (evaluation.configvalue_) 625 return CommandExecutor::dump(evaluation.configvalue_); 626 break; 627 case CS_ConfigValueFinished: 628 if (evaluation.configvalue_) 629 return CommandExecutor::dump(evaluation.configvalue_); 630 break; 631 case CS_KeybindKey: 632 return CommandExecutor::dump(evaluation.listOfPossibleKeys_); 633 break; 634 case CS_KeybindCommand: 635 if (evaluation.key_) 636 return CommandExecutor::dump(evaluation.key_); 637 break; 638 case CS_KeybindFinished: 639 if (evaluation.key_) 640 return CommandExecutor::dump(evaluation.key_); 641 break; 642 case CS_Error: 643 return CommandExecutor::getEvaluation().errorMessage_; 644 break; 645 } 646 647 return ""; 115 CommandExecutor::parseIfNeeded(command); 116 return CommandExecutor::getEvaluation().hint(); 648 117 } 649 118 650 119 CommandEvaluation CommandExecutor::evaluate(const std::string& command) 651 120 { 652 CommandExecutor::parse(command, true); 653 654 if (CommandExecutor::getEvaluation().tokens_.size() > 0) 655 { 656 std::string lastToken; 657 lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1]; 658 lastToken = lastToken.substr(0, lastToken.size() - 1); 659 CommandExecutor::getEvaluation().tokens_.pop_back(); 660 CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0')); 661 } 662 121 CommandExecutor::parse(command); 663 122 CommandExecutor::getEvaluation().evaluateParams(); 664 123 return CommandExecutor::getEvaluation(); 665 124 } 666 125 126 void CommandExecutor::parseIfNeeded(const std::string& command) 127 { 128 if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized) 129 { 130 CommandExecutor::parse(command); 131 } 132 else if (CommandExecutor::getEvaluation().originalCommand_ != command) 133 { 134 if (CommandExecutor::getEvaluation().command_ == command) 135 { 136 CommandExecutor::parse(command); 137 CommandExecutor::getEvaluation().bNewCommand_ = false; 138 } 139 else 140 { 141 CommandExecutor::parse(command); 142 } 143 } 144 } 145 667 146 void CommandExecutor::parse(const std::string& command, bool bInitialize) 668 147 { 669 CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');670 CommandExecutor::getEvaluation().processedCommand_ = command;671 672 148 if (bInitialize) 673 CommandExecutor::initialize(command); 149 CommandExecutor::getEvaluation().initialize(command); 150 151 CommandExecutor::getEvaluation().commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 152 CommandExecutor::getEvaluation().command_ = command; 674 153 675 154 switch (CommandExecutor::getEvaluation().state_) 676 155 { 677 156 case CS_Uninitialized: 157 { 678 158 // Impossible 679 159 break; 160 } 680 161 case CS_Empty: 162 { 681 163 if (CommandExecutor::argumentsGiven() == 0) 682 164 { 683 // We want a hint for the first token 684 // Check if there is already a perfect match 685 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 686 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 687 688 if ((CommandExecutor::getEvaluation().functionclass_) || (CommandExecutor::getEvaluation().shortcut_)) 689 { 690 // Yes, there is a class or a shortcut with the searched name 691 // Add a whitespace and continue parsing 692 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 693 CommandExecutor::parse(command + " ", false); 165 CommandExecutor::createListOfPossibleFunctions(""); 166 CommandExecutor::createListOfPossibleIdentifiers(""); 167 break; 168 } 169 else 170 { 171 CommandExecutor::getEvaluation().state_ = CS_ShortcutOrIdentifier; 172 // Move on to next case 173 } 174 } 175 case CS_ShortcutOrIdentifier: 176 { 177 if (CommandExecutor::argumentsGiven() > 1) 178 { 179 // There's a finished first argument - check if it's a shortcut or a classname 180 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 181 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 182 183 if (CommandExecutor::getEvaluation().function_) 184 { 185 // It's a shortcut 186 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 187 CommandExecutor::getEvaluation().functionclass_ = 0; 188 // Move on to next case 189 } 190 else if (CommandExecutor::getEvaluation().functionclass_) 191 { 192 // It's a functionname 193 CommandExecutor::getEvaluation().state_ = CS_Function; 194 CommandExecutor::getEvaluation().function_ = 0; 195 // Move on to next case 196 } 197 else 198 { 199 // The first argument is bad 200 CommandExecutor::getEvaluation().state_ = CS_Error; 201 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 202 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."; 694 203 return; 695 204 } 696 697 // No perfect match: Create the lists of all possible classes and shortcuts and return 698 CommandExecutor::createListOfPossibleFunctionClasses(CommandExecutor::getToken(0)); 699 CommandExecutor::createListOfPossibleShortcuts(CommandExecutor::getToken(0)); 700 701 // Check if there's only one possiblility 702 if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 1) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 0)) 703 { 704 // There's only one possible class 205 } 206 else 207 { 208 // There's no finished first argument - search possible shortcuts or classnames 209 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0)); 210 CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0)); 211 212 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 213 unsigned int num_identifiers = CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.size(); 214 215 if (num_functions == 1 && num_identifiers == 0) 216 { 217 // It's a shortcut 218 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 219 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname); 220 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(0))) 221 { 222 // Unfinished shortcut 223 CommandExecutor::getEvaluation().bCommandChanged_ = true; 224 } 225 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 226 CommandExecutor::getEvaluation().functionclass_ = 0; 227 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 228 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 229 { 230 CommandExecutor::getEvaluation().command_ += " "; 231 CommandExecutor::getEvaluation().bCommandChanged_ = true; 232 } 233 // Move on to next case 234 } 235 else if (num_identifiers == 1 && num_functions == 0) 236 { 237 // It's a classname 238 std::string classname = *(*CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin()).first; 239 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(classname); 240 if (getLowercase(classname) != getLowercase(CommandExecutor::getArgument(0))) 241 { 242 // Unfinished classname 243 CommandExecutor::getEvaluation().bCommandChanged_ = true; 244 } 705 245 CommandExecutor::getEvaluation().state_ = CS_Function; 706 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first); 707 CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first + " ", false); 246 CommandExecutor::getEvaluation().function_ = 0; 247 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " "; 248 // Move on to next case 249 } 250 else if (num_identifiers == 0 && num_functions == 0) 251 { 252 // No possibilities 253 CommandExecutor::getEvaluation().state_ = CS_Error; 254 AddLanguageEntry("commandexecutorunknownfirstargumentstart", "There is no command or classname starting with"); 255 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + GetLocalisation("commandexecutorunknownfirstargumentstart") + " " + CommandExecutor::getArgument(0) + "."; 708 256 return; 709 257 } 710 else if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 0) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 1)) 711 { 712 if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) 713 && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY) 714 && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)) 715 { 716 // There's only one possible shortcut 717 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 718 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first); 719 } 720 else if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) 721 || (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 722 { 723 // It's the 'set' or 'tset' keyword 724 CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass; 725 } 726 else if (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) 727 { 728 // It's the 'bind' keyword 729 CommandExecutor::getEvaluation().state_ = CS_KeybindKey; 730 } 731 732 CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first + " ", false); 258 else 259 { 260 // There are several possiblilities 261 std::list<std::pair<const std::string*, const std::string*> > temp; 262 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.end()); 263 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.end()); 264 CommandExecutor::getEvaluation().command_ = CommandExecutor::getCommonBegin(temp); 265 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 266 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 267 CommandExecutor::getEvaluation().bCommandChanged_ = true; 733 268 return; 734 269 } 735 736 // It's ambiguous 270 } 271 } 272 case CS_Function: 273 { 274 if (CommandExecutor::getEvaluation().functionclass_) 275 { 276 // There is a classname - search for the commandname 277 if (CommandExecutor::argumentsGiven() > 2) 278 { 279 // There is a finished second argument - check if it's a commandname 280 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 281 282 if (CommandExecutor::getEvaluation().function_) 283 { 284 // It's a function 285 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 286 // Move on to next case 287 } 288 else 289 { 290 // The second argument is bad 291 CommandExecutor::getEvaluation().state_ = CS_Error; 292 AddLanguageEntry("commandexecutorunknownsecondargument", "is not a function of"); 293 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknownsecondargument") + " " + CommandExecutor::getEvaluation().functionclass_->getName() + "."; 294 return; 295 } 296 } 297 else 298 { 299 // There is no finished second argument - search for possibilities 300 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 301 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 302 303 if (num_functions == 1) 304 { 305 // It's a function 306 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 307 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname, CommandExecutor::getEvaluation().functionclass_); 308 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(1))) 309 { 310 // Unfinished function 311 CommandExecutor::getEvaluation().bCommandChanged_ = true; 312 } 313 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 314 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName(); 315 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 316 { 317 CommandExecutor::getEvaluation().command_ += " "; 318 CommandExecutor::getEvaluation().bCommandChanged_ = true; 319 } 320 // Move on to next case 321 } 322 else if (num_functions == 0) 323 { 324 // No possibilities 325 CommandExecutor::getEvaluation().state_ = CS_Error; 326 AddLanguageEntry("commandexecutorunknownsecondargumentstart", "has no function starting with"); 327 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getEvaluation().functionclass_->getName() + " " + GetLocalisation("commandexecutorunknownsecondargumentstart") + " " + CommandExecutor::getArgument(1) + "."; 328 return; 329 } 330 else 331 { 332 // There are several possibilities 333 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_); 334 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 335 CommandExecutor::getEvaluation().bCommandChanged_ = true; 336 return; 337 } 338 } 339 } 340 else 341 { 342 // There is no classname - move on to CS_ParamPreparation 343 } 344 } 345 case CS_ParamPreparation: 346 { 347 if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_)) 348 { 349 CommandExecutor::getEvaluation().state_ = CS_Finished; 737 350 return; 738 351 } 739 352 else 740 353 { 741 // There is at least one argument: Check if it's a shortcut, a classname or a special keyword 742 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 743 CommandExecutor::parse(command, false); 354 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2; 355 if (CommandExecutor::getEvaluation().functionclass_) 356 argumentNumber -= 1; 357 358 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 359 CommandExecutor::getEvaluation().state_ = CS_Params; 360 361 if (CommandExecutor::getEvaluation().bCommandChanged_) 362 { 363 // Don't do more than one change 364 return; 365 } 366 } 367 } 368 case CS_Params: 369 { 370 if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1) 371 { 372 // There is exactly one possible argument 373 CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString(); 374 CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString(); 375 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 744 376 return; 745 377 } 378 else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0) 379 { 380 // The user tries something new - we let him do 381 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 382 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument(); 383 return; 384 } 385 else 386 { 387 // There are several possibilities 388 unsigned int argumentNumber = CommandExecutor::argumentsGiven(); 389 if (argumentNumber > 0) 390 --argumentNumber; 391 if (CommandExecutor::getEvaluation().functionclass_ && argumentNumber > 0) 392 --argumentNumber; 393 394 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 395 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 396 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 397 return; 398 } 399 } 400 case CS_Finished: 401 { 402 // Nothing more to do 746 403 break; 747 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 748 if (CommandExecutor::argumentsGiven() >= 1) 749 { 750 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 751 { 752 // We want to set a config value 753 CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass; 754 CommandExecutor::parse(command, false); 755 return; 756 } 757 else if (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) 758 { 759 // We want to set a keybinding 760 CommandExecutor::getEvaluation().state_ = CS_KeybindKey; 761 CommandExecutor::parse(command, false); 762 return; 763 } 764 765 if (!CommandExecutor::getEvaluation().functionclass_) 766 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 767 if (!CommandExecutor::getEvaluation().shortcut_) 768 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 769 770 if ((!CommandExecutor::getEvaluation().functionclass_) && (!CommandExecutor::getEvaluation().shortcut_)) 771 { 772 // Argument 1 seems to be wrong 773 AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname"); 774 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName")); 775 CommandExecutor::getEvaluation().state_ = CS_Error; 776 return; 777 } 778 else if (CommandExecutor::getEvaluation().shortcut_) 779 { 780 // Argument 1 is a shortcut: Return the needed parameter types 781 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 782 CommandExecutor::parse(command, false); 783 return; 784 } 785 else 786 { 787 // Argument 1 is a classname: Return the possible functions 788 CommandExecutor::getEvaluation().state_ = CS_Function; 789 CommandExecutor::parse(command, false); 790 return; 791 } 792 } 793 else 794 { 795 CommandExecutor::getEvaluation().state_ = CS_Error; 796 return; 797 } 404 } 405 case CS_Error: 406 { 407 // Bad, very bad 798 408 break; 799 case CS_Shortcut_Params: 800 if (CommandExecutor::getEvaluation().shortcut_) 801 { 802 // Valid command 803 // Check if there are enough parameters 804 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_)) 805 { 806 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished; 807 return; 808 } 809 } 810 else 811 { 812 // Something is wrong 813 CommandExecutor::getEvaluation().state_ = CS_Error; 814 return; 815 } 816 break; 817 case CS_Function: 818 if (CommandExecutor::getEvaluation().functionclass_) 819 { 820 // We have a valid classname 821 // Check if there is a second argument 822 if (CommandExecutor::argumentsGiven() >= 2) 823 { 824 // There is a second argument: Check if it's a valid functionname 825 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 826 if (!CommandExecutor::getEvaluation().function_) 827 { 828 // Argument 2 seems to be wrong 829 AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in"); 830 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName()); 831 CommandExecutor::getEvaluation().state_ = CS_Error; 832 return; 833 } 834 else 835 { 836 // Argument 2 seems to be a valid functionname: Get the parameters 837 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 838 CommandExecutor::parse(command, false); 839 return; 840 } 841 } 842 else 843 { 844 // There is no finished second argument 845 // Check if there's already a perfect match 846 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 847 { 848 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 849 if (CommandExecutor::getEvaluation().function_) 850 { 851 // There is a perfect match: Add a whitespace and continue parsing 852 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 853 CommandExecutor::parse(command + " ", false); 854 return; 855 } 856 } 857 858 // No perfect match: Create the list of all possible functions and return 859 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 860 861 // Check if there's only one possiblility 862 if (CommandExecutor::getEvaluation().listOfPossibleFunctions_.size() == 1) 863 { 864 // There's only one possible function 865 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 866 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(*(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first, CommandExecutor::getEvaluation().functionclass_); 867 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first + " ", false); 868 return; 869 } 870 871 // It's ambiguous 872 return; 873 } 874 } 875 else 876 { 877 CommandExecutor::getEvaluation().state_ = CS_Error; 878 return; 879 } 880 break; 881 case CS_Function_Params: 882 if (CommandExecutor::getEvaluation().functionclass_ && CommandExecutor::getEvaluation().function_) 883 { 884 // Valid command 885 // Check if there are enough parameters 886 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_)) 887 { 888 CommandExecutor::getEvaluation().state_ = CS_Function_Finished; 889 return; 890 } 891 } 892 else 893 { 894 // Something is wrong 895 CommandExecutor::getEvaluation().state_ = CS_Error; 896 return; 897 } 898 break; 899 case CS_ConfigValueClass: 900 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))) 901 { 902 // We want to set a config value 903 // Check if there is a second argument 904 if (CommandExecutor::argumentsGiven() >= 2) 905 { 906 // There is a second argument: Check if it's a valid classname 907 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 908 if (!CommandExecutor::getEvaluation().configvalueclass_) 909 { 910 // Argument 2 seems to be wrong 911 AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values"); 912 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues")); 913 CommandExecutor::getEvaluation().state_ = CS_Error; 914 return; 915 } 916 else 917 { 918 // Argument 2 seems to be a valid classname: Search for possible config values 919 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 920 CommandExecutor::parse(command, false); 921 return; 922 } 923 } 924 else 925 { 926 // There's no finished second argument 927 // Check if there's already a perfect match 928 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 929 { 930 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 931 if (CommandExecutor::getEvaluation().configvalueclass_) 932 { 933 // There is a perfect match: Add a whitespace and continue parsing 934 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 935 CommandExecutor::parse(command + " ", false); 936 return; 937 } 938 } 939 940 // No perfect match: Create the list of all possible classnames and return 941 CommandExecutor::createListOfPossibleConfigValueClasses(CommandExecutor::getToken(1)); 942 943 // Check if there's only one possiblility 944 if (CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.size() == 1) 945 { 946 // There's only one possible classname 947 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 948 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first); 949 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first + " ", false); 950 return; 951 } 952 953 // It's ambiguous 954 return; 955 } 956 } 957 else 958 { 959 // Something is wrong 960 CommandExecutor::getEvaluation().state_ = CS_Error; 961 return; 962 } 963 break; 964 case CS_ConfigValue: 965 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_)) 966 { 967 // Check if there is a third argument 968 if (CommandExecutor::argumentsGiven() >= 3) 969 { 970 // There is a third argument: Check if it's a valid config value 971 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 972 if (!CommandExecutor::getEvaluation().configvalue_) 973 { 974 // Argument 3 seems to be wrong 975 AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in"); 976 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName()); 977 CommandExecutor::getEvaluation().state_ = CS_Error; 978 return; 979 } 980 else 981 { 982 // Argument 3 seems to be a valid config value: Get the type 983 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 984 CommandExecutor::parse(command, false); 985 return; 986 } 987 } 988 else 989 { 990 // There is no finished third argument 991 // Check if there's already a perfect match 992 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 993 { 994 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 995 if (CommandExecutor::getEvaluation().configvalue_) 996 { 997 // There is a perfect match: Add a whitespace and continue parsing 998 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 999 CommandExecutor::parse(command + " ", false); 1000 return; 1001 } 1002 } 1003 1004 // No perfect match: Create the list of all possible config values 1005 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 1006 1007 // Check if there's only one possiblility 1008 if (CommandExecutor::getEvaluation().listOfPossibleConfigValues_.size() == 1) 1009 { 1010 // There's only one possible config value 1011 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 1012 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first, CommandExecutor::getEvaluation().configvalueclass_); 1013 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + CommandExecutor::getToken(1) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first + " ", false); 1014 return; 1015 } 1016 1017 // It's ambiguous 1018 return; 1019 } 1020 } 1021 else 1022 { 1023 // Something is wrong 1024 CommandExecutor::getEvaluation().state_ = CS_Error; 1025 return; 1026 } 1027 break; 1028 case CS_ConfigValueType: 1029 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && CommandExecutor::getEvaluation().configvalueclass_ && CommandExecutor::getEvaluation().configvalue_) 1030 { 1031 // Valid command 1032 // Check if there are enough parameters 1033 if ((CommandExecutor::getEvaluation().tokens_.size() >= 4) && (CommandExecutor::getEvaluation().tokens_[3] != COMMAND_EXECUTOR_CURSOR)) 1034 { 1035 CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished; 1036 return; 1037 } 1038 } 1039 else 1040 { 1041 // Something is wrong 1042 CommandExecutor::getEvaluation().state_ = CS_Error; 1043 return; 1044 } 1045 break; 1046 case CS_KeybindKey: 1047 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)) 1048 { 1049 // todo 1050 } 1051 else 1052 { 1053 // Something is wrong 1054 CommandExecutor::getEvaluation().state_ = CS_Error; 1055 return; 1056 } 1057 break; 1058 case CS_KeybindCommand: 1059 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) && (false)) // todo 1060 { 1061 // Valid command 1062 // Check if there are enough parameters 1063 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 1064 { 1065 CommandExecutor::getEvaluation().state_ = CS_KeybindFinished; 1066 return; 1067 } 1068 1069 } 1070 else 1071 { 1072 // Something is wrong 1073 CommandExecutor::getEvaluation().state_ = CS_Error; 1074 return; 1075 } 1076 break; 1077 case CS_Shortcut_Finished: 1078 // Nothing to do 1079 break; 1080 case CS_Function_Finished: 1081 // Nothing to do 1082 break; 1083 case CS_ConfigValueFinished: 1084 // Nothing to do 1085 break; 1086 case CS_KeybindFinished: 1087 // Nothing to do 1088 break; 1089 case CS_Error: 1090 // This is bad 1091 break; 1092 } 1093 } 1094 1095 void CommandExecutor::initialize(const std::string& command) 1096 { 1097 CommandExecutor::getEvaluation().processedCommand_ = command; 1098 CommandExecutor::getEvaluation().additionalParameter_ = ""; 1099 1100 CommandExecutor::getEvaluation().bEvaluatedParams_ = false; 1101 CommandExecutor::getEvaluation().evaluatedExecutor_ = 0; 1102 1103 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear(); 1104 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear(); 409 } 410 } 411 } 412 413 unsigned int CommandExecutor::argumentsFinished() 414 { 415 unsigned int argumentsGiven = CommandExecutor::argumentsGiven(); 416 if (argumentsGiven > 0) 417 return argumentsGiven - 1; 418 else 419 return 0; 420 } 421 422 unsigned int CommandExecutor::argumentsGiven() 423 { 424 if (CommandExecutor::getEvaluation().command_.size() > 0 && CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] == ' ') 425 return CommandExecutor::getEvaluation().commandTokens_.size() + 1; 426 else 427 return CommandExecutor::getEvaluation().commandTokens_.size(); 428 } 429 430 bool CommandExecutor::enoughArgumentsGiven(ConsoleCommand* command) 431 { 432 if (CommandExecutor::getEvaluation().functionclass_) 433 return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount())); 434 else 435 return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount())); 436 } 437 438 std::string CommandExecutor::getArgument(unsigned int index) 439 { 440 if (index < (CommandExecutor::getEvaluation().commandTokens_.size())) 441 return CommandExecutor::getEvaluation().commandTokens_[index]; 442 else 443 return ""; 444 } 445 446 std::string CommandExecutor::getLastArgument() 447 { 448 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1); 449 } 450 451 void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment) 452 { 453 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear(); 454 std::string lowercase = getLowercase(fragment); 455 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 456 if ((*it).second->hasConsoleCommands()) 457 if ((*it).first.find(lowercase) == 0 || fragment == "") 458 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 459 } 460 461 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 462 { 1105 463 CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear(); 1106 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear(); 1107 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear(); 1108 CommandExecutor::getEvaluation().listOfPossibleKeys_.clear(); 1109 1110 CommandExecutor::getEvaluation().functionclass_ = 0; 1111 CommandExecutor::getEvaluation().configvalueclass_ = 0; 1112 CommandExecutor::getEvaluation().shortcut_ = 0; 1113 CommandExecutor::getEvaluation().function_ = 0; 1114 CommandExecutor::getEvaluation().configvalue_ = 0; 1115 CommandExecutor::getEvaluation().key_ = 0; 1116 1117 CommandExecutor::getEvaluation().errorMessage_ = ""; 1118 CommandExecutor::getEvaluation().state_ = CS_Empty; 1119 } 1120 1121 bool CommandExecutor::argumentsGiven(unsigned int num) 1122 { 1123 // Because we added a cursor we have +1 arguments 1124 // There are num arguments given if there are at least num arguments + one cursor 1125 return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1)); 1126 } 1127 1128 unsigned int CommandExecutor::argumentsGiven() 1129 { 1130 // Because we added a cursor we have +1 arguments 1131 if (CommandExecutor::getEvaluation().tokens_.size() >= 1) 1132 return (CommandExecutor::getEvaluation().tokens_.size() - 1); 1133 else 1134 return 0; 1135 } 1136 1137 std::string CommandExecutor::getToken(unsigned int index) 1138 { 1139 if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1))) 1140 return CommandExecutor::getEvaluation().tokens_[index]; 1141 else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1)) 1142 return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1); 1143 else 1144 return ""; 1145 } 1146 1147 bool CommandExecutor::enoughParametersGiven(unsigned int head, Executor* executor) 1148 { 1149 unsigned int neededParams = head + executor->getParamCount(); 1150 /* 1151 for (unsigned int i = executor->getParamCount() - 1; i >= 0; i--) 1152 { 1153 if (executor->defaultValueSet(i)) 1154 neededParams--; 464 std::string lowercase = getLowercase(fragment); 465 if (!identifier) 466 { 467 for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 468 if ((*it).first.find(lowercase) == 0 || fragment == "") 469 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 470 } 471 else 472 { 473 for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 474 if ((*it).first.find(lowercase) == 0 || fragment == "") 475 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 476 } 477 } 478 479 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param) 480 { 481 CommandExecutor::createArgumentCompletionList(command, param); 482 483 CommandExecutor::getEvaluation().listOfPossibleArguments_.clear(); 484 std::string lowercase = getLowercase(fragment); 485 for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 486 { 487 if ((*it).lowercaseComparison()) 488 { 489 if ((*it).getComparable().find(lowercase) == 0 || fragment == "") 490 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it); 491 } 1155 492 else 1156 break; 1157 } 1158 */ 1159 return ((CommandExecutor::getEvaluation().tokens_.size() >= neededParams) && (CommandExecutor::getEvaluation().tokens_[neededParams - 1] != COMMAND_EXECUTOR_CURSOR)); 1160 } 1161 1162 void CommandExecutor::createListOfPossibleFunctionClasses(const std::string& fragment) 1163 { 1164 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 1165 { 1166 if ((*it).second->hasConsoleCommands()) 1167 { 1168 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1169 { 1170 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1171 } 1172 } 1173 } 1174 1175 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList); 1176 } 1177 1178 void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment) 1179 { 1180 for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 1181 { 1182 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1183 { 1184 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1185 } 1186 } 1187 1188 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList); 1189 } 1190 1191 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 1192 { 1193 for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 1194 { 1195 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1196 { 1197 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1198 } 1199 } 1200 1201 CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList); 1202 } 1203 1204 void CommandExecutor::createListOfPossibleConfigValueClasses(const std::string& fragment) 1205 { 1206 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 1207 { 1208 if ((*it).second->hasConfigValues()) 1209 { 1210 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1211 { 1212 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1213 } 1214 } 1215 } 1216 1217 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList); 1218 } 1219 1220 void CommandExecutor::createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier) 1221 { 1222 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it) 1223 { 1224 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1225 { 1226 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1227 } 1228 } 1229 1230 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList); 1231 } 1232 1233 void CommandExecutor::createListOfPossibleKeys(const std::string& fragment) 1234 { 1235 // todo 1236 1237 CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList); 1238 } 1239 1240 bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second) 1241 { 1242 return ((*first.first) < (*second.first)); 1243 } 1244 1245 Identifier* CommandExecutor::getIdentifierOfPossibleFunctionClass(const std::string& name) 1246 { 1247 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name)); 493 { 494 if ((*it).getComparable().find(fragment) == 0 || fragment == "") 495 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it); 496 } 497 } 498 } 499 500 Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name) 501 { 502 std::string lowercase = getLowercase(name); 503 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase); 1248 504 if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands()) 1249 505 return (*it).second; … … 1252 508 } 1253 509 1254 ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name) 1255 { 1256 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name)); 1257 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 1258 return (*it).second; 1259 510 ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier) 511 { 512 std::string lowercase = getLowercase(name); 513 if (!identifier) 514 { 515 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase); 516 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 517 return (*it).second; 518 } 519 else 520 { 521 std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase); 522 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 523 return (*it).second; 524 } 1260 525 return 0; 1261 526 } 1262 527 1263 ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier) 1264 { 1265 std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name)); 1266 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 1267 return (*it).second; 1268 1269 return 0; 1270 } 1271 1272 Identifier* CommandExecutor::getIdentifierOfPossibleConfigValueClass(const std::string& name) 1273 { 1274 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name)); 1275 if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConfigValues()) 1276 return (*it).second; 1277 1278 return 0; 1279 } 1280 1281 ConfigValueContainer* CommandExecutor::getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier) 1282 { 1283 std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name)); 1284 if (it != identifier->getLowercaseConfigValueMapEnd()) 1285 { 1286 return (*it).second; 1287 } 1288 1289 return 0; 1290 } 1291 1292 ConfigValueContainer* CommandExecutor::getContainerOfPossibleKey(const std::string& name) 1293 { 1294 // todo 1295 1296 return 0; 1297 } 1298 1299 std::string CommandExecutor::dump(const std::list<std::pair<const std::string*, const std::string*> >& list) 1300 { 1301 std::string output = ""; 1302 for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it) 1303 { 1304 if (it != list.begin()) 1305 output += " "; 1306 1307 output += *(*it).second; 1308 } 1309 return output; 1310 } 1311 1312 std::string CommandExecutor::dump(const ExecutorStatic* executor) 1313 { 1314 std::string output = ""; 1315 for (unsigned int i = 0; i < executor->getParamCount(); i++) 1316 { 1317 if (i != 0) 1318 output += " "; 1319 1320 if (executor->defaultValueSet(i)) 1321 output += "["; 528 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 529 { 530 CommandExecutor::createArgumentCompletionList(command, param); 531 532 std::string lowercase = getLowercase(name); 533 for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 534 { 535 if ((*it).lowercaseComparison()) 536 { 537 if ((*it).getComparable() == lowercase) 538 return (*it).getString(); 539 } 1322 540 else 1323 output += "{"; 1324 1325 output += executor->getTypenameParam(i); 1326 1327 if (executor->defaultValueSet(i)) 1328 output += "=" + executor->getDefaultValue(i).toString() + "]"; 1329 else 1330 output += "}"; 1331 } 1332 return output; 1333 } 1334 1335 std::string CommandExecutor::dump(const ConfigValueContainer* container) 1336 { 1337 AddLanguageEntry("CommandExecutor::oldvalue", "old value"); 1338 if (!container->isVector()) 1339 return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")"); 1340 else 1341 return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")"); 541 { 542 if ((*it).getComparable() == name) 543 return (*it).getString(); 544 } 545 } 546 547 return ""; 548 } 549 550 void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param) 551 { 552 std::string params[5]; 553 554 unsigned int index = 0; 555 unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0); 556 557 for (unsigned int i = CommandExecutor::argumentsGiven() - 1; i >= lowestIndex; --i) 558 { 559 params[index] = CommandExecutor::getArgument(i); 560 ++index; 561 if (index >= 5) 562 break; 563 } 564 565 command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]); 1342 566 } 1343 567 … … 1382 606 } 1383 607 } 608 609 std::string CommandExecutor::getCommonBegin(const ArgumentCompletionList& list) 610 { 611 if (list.size() == 0) 612 { 613 return ""; 614 } 615 else if (list.size() == 1) 616 { 617 return ((*list.begin()).getComparable() + " "); 618 } 619 else 620 { 621 std::string output = ""; 622 for (unsigned int i = 0; true; i++) 623 { 624 char temp = 0; 625 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 626 { 627 std::string argument = (*it).getComparable(); 628 if (argument.size() > i) 629 { 630 if (it == list.begin()) 631 { 632 temp = argument[i]; 633 } 634 else 635 { 636 if (temp != argument[i]) 637 return output; 638 } 639 } 640 else 641 { 642 return output; 643 } 644 } 645 output += temp; 646 } 647 return output; 648 } 649 } 1384 650 } -
TabularUnified code/trunk/src/core/CommandExecutor.h ¶
r1349 r1502 32 32 #include "CorePrereqs.h" 33 33 34 #include <string>35 34 #include <map> 36 #include <list>37 35 38 #include "util/SubString.h" 39 #include "util/MultiTypeMath.h" 40 41 #define COMMAND_EXECUTOR_CURSOR "$" 36 #include "CommandEvaluation.h" 42 37 43 38 namespace orxonox 44 39 { 45 enum CommandState46 {47 CS_Uninitialized,48 CS_Empty,49 CS_FunctionClass_Or_Shortcut_Or_Keyword,50 CS_Shortcut_Params,51 CS_Shortcut_Finished,52 CS_Function,53 CS_Function_Params,54 CS_Function_Finished,55 CS_ConfigValueClass,56 CS_ConfigValue,57 CS_ConfigValueType,58 CS_ConfigValueFinished,59 CS_KeybindKey,60 CS_KeybindCommand,61 CS_KeybindFinished,62 CS_Error63 };64 65 void exec(const std::string& filename);66 std::string echo(const std::string& text);67 68 void write(const std::string& filename, const std::string& text);69 void append(const std::string& filename, const std::string& text);70 std::string read(const std::string& filename);71 72 ///////////////////////73 // CommandEvaluation //74 ///////////////////////75 class _CoreExport CommandEvaluation76 {77 friend class CommandExecutor;78 79 public:80 CommandEvaluation();81 82 KeybindMode::Enum getKeybindMode();83 bool isValid() const;84 85 inline void setAdditionalParameter(const std::string& param)86 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }87 inline std::string getAdditionalParameter() const88 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }89 inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; }90 inline std::string getCommandString() { return this->processedCommand_; }91 92 void setEvaluatedParameter(unsigned int index, MultiTypeMath param);93 MultiTypeMath getEvaluatedParameter(unsigned int index) const;94 95 void evaluateParams();96 97 bool hasReturnvalue() const;98 MultiTypeMath getReturnvalue() const;99 100 private:101 std::string processedCommand_;102 SubString tokens_;103 std::string additionalParameter_;104 105 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;106 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;107 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;108 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;109 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;110 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;111 112 Identifier* functionclass_;113 Identifier* configvalueclass_;114 ExecutorStatic* shortcut_;115 ExecutorStatic* function_;116 ConfigValueContainer* configvalue_;117 ConfigValueContainer* key_;118 119 std::string errorMessage_;120 CommandState state_;121 122 bool bEvaluatedParams_;123 MultiTypeMath param_[5];124 ExecutorStatic* evaluatedExecutor_;125 };126 127 /////////////////////128 // CommandExecutor //129 /////////////////////130 40 class _CoreExport CommandExecutor 131 41 { 132 42 public: 133 43 static bool execute(const std::string& command, bool useTcl = true); 134 static bool execute(const CommandEvaluation& evaluation);135 136 44 static std::string complete(const std::string& command); 137 static std::string complete(const CommandEvaluation& evaluation);138 139 45 static std::string hint(const std::string& command); 140 static std::string hint(const CommandEvaluation& evaluation);141 46 142 47 static CommandEvaluation evaluate(const std::string& command); 143 144 48 static const CommandEvaluation& getLastEvaluation(); 145 49 146 static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);147 static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);148 static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);50 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command); 51 static ConsoleCommand* getConsoleCommandShortcut(const std::string& name); 52 static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name); 149 53 150 54 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 151 static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }55 static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; } 152 56 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 153 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }57 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); } 154 58 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 155 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }59 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); } 156 60 157 61 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 158 static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }62 static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; } 159 63 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 160 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }64 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); } 161 65 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 162 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }66 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 163 67 164 68 private: … … 170 74 static CommandEvaluation& getEvaluation(); 171 75 76 static void parseIfNeeded(const std::string& command); 172 77 static void parse(const std::string& command, bool bInitialize = true); 173 static void initialize(const std::string& command);174 78 175 static bool argumentsGiven(unsigned int num);79 static unsigned int argumentsFinished(); 176 80 static unsigned int argumentsGiven(); 81 static bool enoughArgumentsGiven(ConsoleCommand* command); 82 static std::string getArgument(unsigned int index); 83 static std::string getLastArgument(); 177 84 178 static std::string getToken(unsigned int index); 85 static void createListOfPossibleIdentifiers(const std::string& fragment); 86 static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0); 87 static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param); 179 88 180 static bool enoughParametersGiven(unsigned int head, Executor* executor); 89 static Identifier* getPossibleIdentifier(const std::string& name); 90 static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0); 91 static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param); 181 92 182 static void createListOfPossibleShortcuts(const std::string& fragment); 183 static void createListOfPossibleFunctionClasses(const std::string& fragment); 184 static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier); 185 static void createListOfPossibleConfigValueClasses(const std::string& fragment); 186 static void createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier); 187 static void createListOfPossibleKeys(const std::string& fragment); 188 189 static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second); 190 191 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 192 static std::string dump(const ExecutorStatic* executor); 193 static std::string dump(const ConfigValueContainer* container); 194 93 static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param); 195 94 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 196 197 static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name); 198 static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name); 199 static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier); 200 static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name); 201 static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier); 202 static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name); 95 static std::string getCommonBegin(const ArgumentCompletionList& list); 203 96 204 97 CommandEvaluation evaluation_; 205 206 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_; 207 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_; 98 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_; 99 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_; 208 100 }; 209 101 } -
TabularUnified code/trunk/src/core/ConfigFileManager.cc ¶
r1056 r1502 38 38 namespace orxonox 39 39 { 40 ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None); 41 ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None); 42 ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None); 43 ConsoleCommandShortcutExtern(loadKeybindings, AccessLevel::None); 40 SetConsoleCommandShortcutExtern(config).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); 41 SetConsoleCommandShortcutExtern(tconfig).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); 42 SetConsoleCommandShortcutExtern(reloadConfig); 43 SetConsoleCommandShortcutExtern(cleanConfig); 44 SetConsoleCommandShortcutExtern(loadSettings).setArgumentCompleter(0, autocompletion::files()); 45 SetConsoleCommandShortcutExtern(loadKeybindings).setArgumentCompleter(0, autocompletion::files()); 46 47 bool config(const std::string& classname, const std::string& varname, const std::string& value) 48 { 49 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 50 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 51 { 52 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 53 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 54 return (*variable).second->set(value); 55 } 56 return false; 57 } 58 59 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value) 60 { 61 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 62 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 63 { 64 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 65 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 66 return (*variable).second->tset(value); 67 } 68 return false; 69 } 44 70 45 71 void reloadConfig() … … 336 362 337 363 COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl; 364 } 365 366 void ConfigFile::save(const std::string& filename) 367 { 368 std::string temp = this->filename_; 369 this->filename_ = filename; 370 this->save(); 371 this->filename_ = temp; 338 372 } 339 373 … … 473 507 } 474 508 509 void ConfigFileManager::save(ConfigFileType type, const std::string& filename) 510 { 511 this->getFile(type)->save(filename); 512 } 513 475 514 void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments) 476 515 { -
TabularUnified code/trunk/src/core/ConfigFileManager.h ¶
r1116 r1502 50 50 51 51 52 bool config(const std::string& classname, const std::string& varname, const std::string& value); 53 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value); 52 54 void reloadConfig(); 53 55 void saveConfig(); … … 222 224 void load(bool bCreateIfNotExisting = true); 223 225 void save() const; 226 void save(const std::string& filename); 224 227 void clean(bool bCleanComments = false); 225 228 … … 265 268 void load(ConfigFileType type, bool bCreateIfNotExisting = true); 266 269 void save(ConfigFileType type); 270 void save(ConfigFileType type, const std::string& filename); 267 271 void clean(ConfigFileType type, bool bCleanComments = false); 268 272 -
TabularUnified code/trunk/src/core/ConfigValueContainer.cc ¶
r1062 r1502 87 87 88 88 if (defvalue.size() > 0) 89 this->value_ = defvalue[0]; 90 91 for (unsigned int i = 0; i < defvalue.size(); i++) 92 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 93 94 for (unsigned int i = 0; i < defvalue.size(); i++) 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 97 this->update(); 89 { 90 this->value_ = defvalue[0]; 91 92 for (unsigned int i = 0; i < defvalue.size(); i++) 93 { 94 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 } 97 98 this->update(); 99 } 100 } 101 102 /** 103 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 104 @param input The new value 105 @return True if the new value was successfully assigned 106 */ 107 bool ConfigValueContainer::set(const MultiTypeMath& input) 108 { 109 if (this->bIsVector_) 110 { 111 return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString()); 112 } 113 else 114 { 115 if (this->tset(input)) 116 { 117 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string)); 118 return true; 119 } 120 } 121 return false; 122 } 123 124 /** 125 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 126 @param index The index in the vector 127 @param input The new value 128 @return True if the new value was successfully assigned 129 */ 130 bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input) 131 { 132 if (this->bIsVector_) 133 { 134 if (this->tset(index, input)) 135 { 136 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string)); 137 return true; 138 } 139 } 140 else 141 { 142 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 143 } 144 return false; 145 } 146 147 /** 148 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 149 @param input The new value. If bIsVector_ then write "index value" 150 @return True if the new value was successfully assigned 151 */ 152 bool ConfigValueContainer::tset(const MultiTypeMath& input) 153 { 154 if (this->bIsVector_) 155 { 156 return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString()); 157 } 158 else 159 { 160 MultiTypeMath temp = this->value_; 161 if (temp.assimilate(input)) 162 { 163 this->value_ = temp; 164 if (this->identifier_) 165 this->identifier_->updateConfigValues(); 166 167 return true; 168 } 169 } 170 return false; 171 } 172 173 /** 174 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 175 @param index The index in the vector 176 @param input The new value 177 @return True if the new value was successfully assigned 178 */ 179 bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input) 180 { 181 if (this->bIsVector_) 182 { 183 if (index > MAX_VECTOR_INDEX) 184 { 185 COUT(1) << "Error: Index " << index << " is too large." << std::endl; 186 return false; 187 } 188 189 if (index >= this->valueVector_.size()) 190 { 191 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 192 { 193 this->valueVector_.push_back(MultiTypeMath()); 194 } 195 } 196 197 MultiTypeMath temp = this->value_; 198 if (temp.assimilate(input)) 199 { 200 this->valueVector_[index] = temp; 201 202 if (this->identifier_) 203 this->identifier_->updateConfigValues(); 204 205 return true; 206 } 207 } 208 else 209 { 210 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 211 } 212 return false; 98 213 } 99 214 … … 103 218 @return True if the new entry was successfully added 104 219 */ 105 bool ConfigValueContainer::add(const std::string& input)220 bool ConfigValueContainer::add(const MultiTypeMath& input) 106 221 { 107 222 if (this->bIsVector_) … … 123 238 if (index < this->valueVector_.size()) 124 239 { 240 // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file 125 241 this->valueVector_.erase(this->valueVector_.begin() + index); 126 242 for (unsigned int i = index; i < this->valueVector_.size(); i++) … … 131 247 } 132 248 COUT(1) << "Error: Invalid vector-index." << std::endl; 133 }134 135 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;136 return false;137 }138 139 /**140 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.141 @param input The new value142 @return True if the new value was successfully assigned143 */144 bool ConfigValueContainer::set(const std::string& input)145 {146 if (this->bIsVector_)147 {148 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');149 int index = -1;150 bool success = false;151 152 if (token.size() > 0)153 success = ConvertValue(&index, token[0]);154 155 if (!success || index < 0 || index > MAX_VECTOR_INDEX)156 {157 if (!success)158 {159 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;160 }161 else162 {163 COUT(1) << "Error: Invalid vector-index." << std::endl;164 }165 return false;166 }167 168 if (token.size() >= 2)169 return this->set(index, token.subSet(1).join());170 else171 return this->set(index, "");172 }173 174 bool success = this->tset(input);175 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string));176 return success;177 }178 179 /**180 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.181 @param index The index in the vector182 @param input The new value183 @return True if the new value was successfully assigned184 */185 bool ConfigValueContainer::set(unsigned int index, const std::string& input)186 {187 if (this->bIsVector_)188 {189 bool success = this->tset(index, input);190 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string));191 return success;192 }193 194 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;195 return false;196 }197 198 /**199 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).200 @param input The new value201 @return True if the new value was successfully assigned202 */203 bool ConfigValueContainer::tset(const std::string& input)204 {205 bool success = this->parse(input);206 if (this->identifier_)207 this->identifier_->updateConfigValues();208 return success;209 }210 211 /**212 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).213 @param index The index in the vector214 @param input The new value215 @return True if the new value was successfully assigned216 */217 bool ConfigValueContainer::tset(unsigned int index, const std::string& input)218 {219 if (this->bIsVector_)220 {221 bool success = this->parse(index, input);222 if (this->identifier_)223 this->identifier_->updateConfigValues();224 return success;225 249 } 226 250 … … 259 283 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 260 284 { 261 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 262 this->valueVector_.push_back(this->value_); 263 } 264 } 265 } 266 267 /** 268 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 269 @param input The string to convert 270 @return True if the string was successfully parsed 271 */ 272 bool ConfigValueContainer::parse(const std::string& input) 273 { 274 if (this->bIsVector_) 275 { 276 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 277 int index = -1; 278 bool success = false; 279 280 if (token.size() > 0) 281 success = ConvertValue(&index, token[0]); 282 283 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 284 { 285 if (!success) 285 if (i < this->defvalueStringVector_.size()) 286 286 { 287 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;287 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 288 288 } 289 289 else 290 290 { 291 COUT(1) << "Error: Invalid vector-index." << std::endl;291 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string))); 292 292 } 293 return false; 294 } 295 296 if (token.size() >= 2) 297 return this->parse(index, token.subSet(1).join()); 293 294 this->valueVector_.push_back(this->value_); 295 } 296 } 297 } 298 299 /** 300 @brief Calls the given function with parsed index and the parsed argument from the input string. 301 @param function The function to call 302 @param input The input string 303 @return The returnvalue of the functioncall 304 */ 305 bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input) 306 { 307 SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0'); 308 int index = -1; 309 bool success = false; 310 311 if (token.size() > 0) 312 success = ConvertValue(&index, token[0]); 313 314 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 315 { 316 if (!success) 317 { 318 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 319 } 298 320 else 299 return this->parse(index, ""); 300 } 301 302 MultiTypeMath temp = this->value_; 303 if (temp.fromString(input)) 304 { 305 this->value_ = temp; 306 return true; 307 } 308 return false; 309 } 310 311 /** 312 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 313 @param index The index in the vector 314 @param input The string to convert 315 @return True if the string was successfully parsed 316 */ 317 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 318 { 319 if (this->bIsVector_) 320 { 321 if (index >= this->valueVector_.size()) 322 { 323 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 324 { 325 this->valueVector_.push_back(MultiTypeMath()); 326 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 327 } 328 } 329 330 MultiTypeMath temp = this->value_; 331 if (temp.fromString(input)) 332 { 333 this->valueVector_[index] = temp; 334 return true; 321 { 322 COUT(1) << "Error: Invalid vector-index." << std::endl; 335 323 } 336 324 return false; 337 325 } 338 326 339 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 340 return false; 341 } 342 343 /** 344 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 345 @param input The string to convert 346 @param defvalue The default value to assign if the parsing fails 347 @return True if the string was successfully parsed 348 */ 349 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 350 { 351 if (this->parse(input)) 352 return true; 353 354 this->value_ = defvalue; 355 return false; 356 } 357 358 /** 359 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 360 @param index The index in the vector 361 @param input The string to convert 362 @param defvalue The default value to assign if the parsing fails 363 @return True if the string was successfully parsed 364 */ 365 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 366 { 367 if (this->bIsVector_) 368 { 369 if (this->parse(index, input)) 370 return true; 371 372 this->valueVector_[index] = defvalue; 373 return false; 374 } 375 376 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 377 return false; 327 if (token.size() >= 2) 328 return (this->*function)(index, token.subSet(1).join()); 329 else 330 return (this->*function)(index, ""); 378 331 } 379 332 -
TabularUnified code/trunk/src/core/ConfigValueContainer.h ¶
r1062 r1502 90 90 } 91 91 92 template <typename T> 93 inline void setVectorType(const std::vector<T>& value) 94 { 95 this->value_ = T(); 96 this->update(); 97 } 98 92 99 inline const std::string& getName() const 93 100 { return this->varname_; } … … 100 107 const std::string& getDescription() const; 101 108 102 bool add(const std::string& input); 109 bool set(const MultiTypeMath& input); 110 bool tset(const MultiTypeMath& input); 111 112 bool set(unsigned int index, const MultiTypeMath& input); 113 bool tset(unsigned int index, const MultiTypeMath& input); 114 bool add(const MultiTypeMath& input); 103 115 bool remove(unsigned int index); 104 bool set(const std::string& input); 105 bool tset(const std::string& input); 116 106 117 bool reset(); 107 118 void update(); … … 115 126 116 127 private: 117 bool parse(const std::string& input); 118 bool parse(const std::string& input, const MultiTypeMath& defvalue); 119 120 bool set(unsigned int index, const std::string& input); 121 bool tset(unsigned int index, const std::string& input); 122 bool parse(unsigned int index, const std::string& input); 123 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 128 bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input); 124 129 125 130 bool bIsVector_; //!< True if the container contains a std::vector -
TabularUnified code/trunk/src/core/ConfigValueIncludes.h ¶
r1062 r1502 57 57 58 58 /** 59 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). 60 @param classname name in which the config value should be stored 61 @param varname The name of the variable 62 @param defvalue The default-value of the variable 63 */ 64 #define SetConfigValueGeneric(classname, varname, defvalue) \ 65 orxonox::ConfigValueContainer* container##varname = ClassManager<classname>::getIdentifier()->getConfigValueContainer(#varname); \ 66 if (!container##varname) \ 67 { \ 68 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassManager<classname>::getIdentifier(), #varname, varname = defvalue); \ 69 ClassManager<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 70 } \ 71 container##varname->getValue(&varname) 72 73 /** 59 74 @brief Assigns the vector-values, defined in the config-file, to the vector (or the default-value, if there are no entries in the file). 60 75 @param varname The name of the std::vector … … 69 84 temp.push_back(MultiTypeMath(defvalue[i])); \ 70 85 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \ 86 container##varname->setVectorType(varname); \ 71 87 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 72 88 } \ … … 106 122 } 107 123 108 /**109 @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).110 @param varname The name of the key-variable111 */112 #define SetKeybind(keyname) \113 orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \114 if (!container##keyname) \115 { \116 container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \117 this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \118 } \119 container##keyname->getValue(&varname)120 121 124 #endif /* _ConfigValueIncludes_H__ */ -
TabularUnified code/trunk/src/core/ConsoleCommand.h ¶
r1062 r1502 34 34 #include "Executor.h" 35 35 #include "ClassManager.h" 36 #include "Identifier.h"37 36 #include "CommandExecutor.h" 37 #include "ArgumentCompletionFunctions.h" 38 38 39 39 40 #define SetConsoleCommand(classname, function, bCreateShortcut) \ 41 SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut) 40 42 41 #define ConsoleCommand(classname, function, accesslevel, bCreateShortcut) \ 42 ConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel), bCreateShortcut) 43 44 #define ConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \ 45 Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ExecutorStatic*)executor, bCreateShortcut) 43 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ 44 ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut) 46 45 47 46 48 #define ConsoleCommandShortcut(classname, function, accesslevel) \49 ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel))47 #define SetConsoleCommandShortcut(classname, function) \ 48 SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function)) 50 49 51 #define ConsoleCommandShortcutExtern(function, accesslevel) \52 ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&function), #function, accesslevel))50 #define SetConsoleCommandShortcutExtern(function) \ 51 SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function)) 53 52 54 #define ConsoleCommandShortcutGeneric(fakevariable, executor) \55 Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)53 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 54 ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command) 56 55 57 56 57 namespace orxonox 58 { 59 namespace AccessLevel 60 { 61 enum Level 62 { 63 None, 64 User, 65 Admin, 66 Offline, 67 Debug, 68 Disabled 69 }; 70 } 71 72 class _CoreExport ConsoleCommand : public ExecutorStatic 73 { 74 public: 75 ConsoleCommand(FunctorStatic* functor, const std::string& name = ""); 76 77 inline ConsoleCommand& setDescription(const std::string& description) 78 { this->ExecutorStatic::setDescription(description); return (*this); } 79 inline ConsoleCommand& setDescriptionParam(int param, const std::string& description) 80 { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); } 81 inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description) 82 { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); } 83 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1) 84 { this->ExecutorStatic::setDefaultValues(param1); return (*this); } 85 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 86 { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); } 87 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 88 { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); } 89 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 90 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); } 91 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 92 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); } 93 inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param) 94 { this->ExecutorStatic::setDefaultValue(index, param); return (*this); } 95 96 inline ConsoleCommand& setAccessLevel(AccessLevel::Level level) 97 { this->accessLevel_ = level; return (*this); } 98 inline AccessLevel::Level getAccessLevel() const 99 { return this->accessLevel_; } 100 101 ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer); 102 ArgumentCompleter* getArgumentCompleter(unsigned int param) const; 103 104 void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = ""); 105 const ArgumentCompletionList& getArgumentCompletionList() const 106 { return this->argumentList_; } 107 ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const 108 { return this->argumentList_.begin(); } 109 ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const 110 { return this->argumentList_.end(); } 111 112 inline ConsoleCommand& setKeybindMode(KeybindMode::Enum mode) 113 { this->keybindMode_ = mode; return *this; } 114 inline KeybindMode::Enum getKeybindMode() const 115 { return this->keybindMode_; } 116 117 inline ConsoleCommand& setAxisParamIndex(int index) 118 { this->axisParamIndex_ = index; return *this; } 119 inline int getAxisParamIndex() const 120 { return this->axisParamIndex_; } 121 122 inline ConsoleCommand& setIsAxisRelative(bool val) 123 { this->bAxisRelative_ = val; return *this; } 124 inline int getIsAxisRelative() const 125 { return this->bAxisRelative_; } 126 127 private: 128 AccessLevel::Level accessLevel_; 129 ArgumentCompleter* argumentCompleter_[5]; 130 ArgumentCompletionList argumentList_; 131 132 KeybindMode::Enum keybindMode_; 133 int axisParamIndex_; 134 bool bAxisRelative_; 135 }; 136 137 inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "") 138 { 139 return new ConsoleCommand(functor, name); 140 } 141 } 142 58 143 #endif /* _ConsoleCommand_H__ */ -
TabularUnified code/trunk/src/core/CorePrereqs.h ¶
r1349 r1502 35 35 #define _CorePrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 #include <string> … … 66 66 namespace orxonox 67 67 { 68 #ifndef _XMLPort_Mode__69 #define _XMLPort_Mode__70 68 namespace XMLPort 71 69 { … … 76 74 }; 77 75 } 78 #endif79 76 80 77 namespace KeybindMode … … 91 88 typedef std::string LanguageEntryLabel; 92 89 90 class ArgumentCompleter; 91 class ArgumentCompletionListElement; 93 92 class BaseFactory; 94 93 class BaseMetaObjectListElement; … … 112 111 class ConfigFileSection; 113 112 class ConfigValueContainer; 113 class ConsoleCommand; 114 114 class CoreSettings; 115 115 class Error; … … 125 125 class Identifier; 126 126 class IdentifierDistributor; 127 class IRC; 127 128 template <class T> 128 129 class Iterator; … … 141 142 class ObjectListElement; 142 143 class OrxonoxClass; 144 class OutputBuffer; 145 class OutputBufferListener; 143 146 class OutputHandler; 144 147 class Shell; 148 class ShellListener; 145 149 template <class T> 146 150 class SubclassIdentifier; 147 151 class TclBind; 152 struct TclInterpreterBundle; 153 class TclThreadManager; 148 154 class Tickable; 149 155 template <class T, class O> … … 156 162 // input 157 163 //class GUIInputHandler; 164 class Calibrator; 165 class CalibratorCallback; 158 166 class InputBuffer; 159 167 class InputBufferListener; … … 161 169 class JoyStickHandler; 162 170 class KeyBinder; 163 class Key Handler;171 class KeyDetector; 164 172 class MouseHandler; 165 173 -
TabularUnified code/trunk/src/core/CoreSettings.cc ¶
r1058 r1502 117 117 118 118 /** 119 @brief Static function that holds the singleton. 119 @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). 120 @param device The device 121 @return The softDebugLevel 120 122 */ 121 123 int CoreSettings::getSoftDebugLevel(OutputHandler::OutputDevice device) … … 136 138 return 2; 137 139 } 140 141 /** 142 @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value. 143 @param device The device 144 @param level The level 145 */ 146 void CoreSettings::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 147 { 148 if (!CoreSettings::isCreatingCoreSettings()) 149 { 150 if (device == OutputHandler::LD_All) 151 CoreSettings::getInstance().softDebugLevel_ = level; 152 else if (device == OutputHandler::LD_Console) 153 CoreSettings::getInstance().softDebugLevelConsole_ = level; 154 else if (device == OutputHandler::LD_Logfile) 155 CoreSettings::getInstance().softDebugLevelLogfile_ = level; 156 else if (device == OutputHandler::LD_Shell) 157 CoreSettings::getInstance().softDebugLevelShell_ = level; 158 } 159 } 138 160 139 161 /** -
TabularUnified code/trunk/src/core/CoreSettings.h ¶
r1064 r1502 54 54 55 55 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 56 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 56 57 static const std::string& getLanguage(); 57 58 static void resetLanguage(); -
TabularUnified code/trunk/src/core/Debug.h ¶
r1293 r1502 206 206 COUT ## x 207 207 208 #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE 209 #define COUT0 \ 210 if (getSoftDebugLevel() >= ORX_NONE) \ 211 COUT_EXEC(0) 212 #else 213 #define COUT0 if (ORX_NONE)\ 214 COUT_EXEC(0) 215 #endif 216 208 217 #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR 209 218 #define COUT1 \ … … 256 265 #endif /* if ORX_PRINT_DEBUG_OUTPUT */ 257 266 258 #define COUT0 \259 COUT_EXEC(0)260 267 #endif /* ifndef COUT */ 261 268 … … 280 287 CCOUT ## x 281 288 289 #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE 290 #define CCOUT0 \ 291 if (getSoftDebugLevel() >= ORX_NONE) \ 292 CCOUT_EXEC(0) 293 #else 294 #define CCOUT0 if (ORX_NONE)\ 295 CCOUT_EXEC(0) 296 #endif 297 282 298 #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR 283 299 #define CCOUT1 \ … … 330 346 #endif /* if ORX_PRINT_DEBUG_OUTPUT */ 331 347 332 #define CCOUT0 \333 CCOUT_EXEC(0)334 348 #endif /* ifndef CCOUT */ 335 349 -
TabularUnified code/trunk/src/core/Executor.cc ¶
r1349 r1502 34 34 namespace orxonox 35 35 { 36 Executor::Executor(Functor* functor, const std::string& name , AccessLevel::Level level)36 Executor::Executor(Functor* functor, const std::string& name) 37 37 { 38 38 this->functor_ = functor; 39 39 this->name_ = name; 40 this->accessLevel_ = level;41 this->keybindMode_ = KeybindMode::OnPress;42 this->axisParamIndex_ = -1;43 this->bAxisRelative_ = false;44 40 45 41 this->bAddedDescription_ = false; -
TabularUnified code/trunk/src/core/Executor.h ¶
r1349 r1502 35 35 #include "util/SubString.h" 36 36 #include "util/String.h" 37 #include "util/Math.h" 37 38 #include "Functor.h" 38 39 #include "Debug.h" … … 100 101 COUT(5) << tokens[i]; \ 101 102 } \ 102 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \103 COUT(5) << ") and " << max((int)paramCount - (int)tokens.size(), 0) << " default values ("; \ 103 104 for (unsigned int i = tokens.size(); i < paramCount; i++) \ 104 105 { \ … … 134 135 return true 135 136 136 namespace AccessLevel137 {138 enum Level139 {140 None,141 User,142 Admin,143 Offline,144 Debug,145 Disabled146 };147 }148 149 137 namespace orxonox 150 138 { … … 152 140 { 153 141 public: 154 Executor(Functor* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None);142 Executor(Functor* functor, const std::string& name = ""); 155 143 virtual ~Executor(); 156 144 … … 181 169 const std::string& getDescriptionReturnvalue(int param) const; 182 170 171 inline Functor* getFunctor() const 172 { return this->functor_; } 183 173 inline unsigned int getParamCount() const 184 174 { return this->functor_->getParamCount(); } … … 199 189 { return this->name_; } 200 190 201 inline void setAccessLevel(AccessLevel::Level level)202 { this->accessLevel_ = level; }203 inline AccessLevel::Level getAccessLevel() const204 { return this->accessLevel_; }205 206 inline Executor& setKeybindMode(KeybindMode::Enum mode)207 { this->keybindMode_ = mode; return *this; }208 inline KeybindMode::Enum getKeybindMode() const209 { return this->keybindMode_; }210 211 inline Executor& setAxisParamIndex(int index)212 { this->axisParamIndex_ = index; return *this; }213 inline int getAxisParamIndex() const214 { return this->axisParamIndex_; }215 216 inline Executor& setIsAxisRelative(bool val)217 { this->bAxisRelative_ = val; return *this; }218 inline int getIsAxisRelative() const219 { return this->bAxisRelative_; }220 221 191 Executor& setDefaultValues(const MultiTypeMath& param1); 222 192 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2); … … 249 219 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 250 220 251 KeybindMode::Enum keybindMode_;252 int axisParamIndex_;253 bool bAxisRelative_;254 255 221 private: 256 222 LanguageEntryLabel description_; … … 261 227 bool bAddedDescriptionReturnvalue_; 262 228 bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 263 264 AccessLevel::Level accessLevel_;265 229 }; 266 230 … … 268 232 { 269 233 public: 270 ExecutorStatic(FunctorStatic* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}234 ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {} 271 235 virtual ~ExecutorStatic() {} 272 236 }; … … 276 240 { 277 241 public: 278 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}242 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {} 279 243 virtual ~ExecutorMember() {} 280 244 … … 322 286 }; 323 287 324 inline Executor* createExecutor(Functor* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)325 { 326 return new Executor(functor, name , level);288 inline Executor* createExecutor(Functor* functor, const std::string& name = "") 289 { 290 return new Executor(functor, name); 327 291 } 328 292 329 293 template <class T> 330 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)331 { 332 return new ExecutorMember<T>(functor, name , level);294 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "") 295 { 296 return new ExecutorMember<T>(functor, name); 333 297 } 334 298 335 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)336 { 337 return new ExecutorStatic(functor, name , level);299 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "") 300 { 301 return new ExecutorStatic(functor, name); 338 302 } 339 303 } -
TabularUnified code/trunk/src/core/Identifier.cc ¶
r1062 r1502 37 37 38 38 #include "Factory.h" 39 #include " Executor.h"39 #include "ConsoleCommand.h" 40 40 #include "CommandExecutor.h" 41 41 … … 231 231 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 232 232 { 233 std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname); 234 if (it != this->configValues_.end()) 235 { 236 COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl; 237 } 238 233 239 this->bHasConfigValues_ = true; 234 240 this->configValues_[varname] = container; … … 270 276 @return The executor of the command 271 277 */ 272 ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut) 273 { 278 ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut) 279 { 280 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName()); 281 if (it != this->consoleCommands_.end()) 282 { 283 COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl; 284 } 285 274 286 this->bHasConsoleCommands_ = true; 275 this->consoleCommands_[ executor->getName()] = executor;276 this->consoleCommands_LC_[getLowercase( executor->getName())] = executor;287 this->consoleCommands_[command->getName()] = command; 288 this->consoleCommands_LC_[getLowercase(command->getName())] = command; 277 289 278 290 if (bCreateShortcut) 279 CommandExecutor::addConsoleCommandShortcut( executor);280 281 return (* executor);291 CommandExecutor::addConsoleCommandShortcut(command); 292 293 return (*command); 282 294 } 283 295 … … 287 299 @return The executor of the requested console command 288 300 */ 289 ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const290 { 291 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name);301 ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); 292 304 if (it != this->consoleCommands_.end()) 293 305 return (*it).second; … … 301 313 @return The executor of the requested console command 302 314 */ 303 ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const304 { 305 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name);315 ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const 316 { 317 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); 306 318 if (it != this->consoleCommands_LC_.end()) 307 319 return (*it).second; -
TabularUnified code/trunk/src/core/Identifier.h ¶
r1064 r1502 63 63 #include "Debug.h" 64 64 #include "Iterator.h" 65 #include "MetaObjectList.h" 65 66 #include "util/String.h" 66 67 … … 175 176 176 177 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 177 inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }178 inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; } 178 179 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 179 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }180 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); } 180 181 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 181 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }182 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); } 182 183 183 184 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 184 inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }185 inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; } 185 186 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 186 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }187 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); } 187 188 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 188 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }189 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 189 190 190 191 … … 213 214 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0; 214 215 215 ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);216 ExecutorStatic* getConsoleCommand(const std::string& name) const;217 ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;216 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); 217 ConsoleCommand* getConsoleCommand(const std::string& name) const; 218 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 218 219 219 220 protected: … … 270 271 271 272 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command 272 std::map<std::string, ExecutorStatic*> consoleCommands_; //!< All console commands of this class273 std::map<std::string, ExecutorStatic*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase273 std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class 274 std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 274 275 }; 275 276 -
TabularUnified code/trunk/src/core/InputBuffer.cc ¶
r1349 r1502 37 37 namespace orxonox 38 38 { 39 InputBuffer::InputBuffer(const std::string allowedChars) : 40 buffer_(""), 41 allowedChars_(allowedChars), 42 lastKey_(KeyCode::Unassigned), 43 timeSinceKeyPressed_(0.0f), 44 timeSinceKeyRepeated_(0.0f), 45 keysToRepeat_(0) 46 { 47 RegisterObject(InputBuffer); 48 setConfigValues(); 49 } 50 51 void InputBuffer::setConfigValues() 52 { 53 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 54 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 55 if (keyRepeatDeleay_ < 0.0) 56 { 57 ResetConfigValue(keyRepeatDeleay_); 58 } 59 if (keyRepeatTime_ < 0.0) 60 { 61 ResetConfigValue(keyRepeatTime_); 62 } 63 } 64 /* 65 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 66 { 67 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 68 listeners_.insert(listeners_.end(), newListener); 69 } 70 71 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 72 { 73 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 74 listeners_.insert(listeners_.end(), newListener); 75 } 76 */ 77 void InputBuffer::set(const std::string& input) 78 { 79 buffer_ = ""; 80 append(input); 81 } 82 83 void InputBuffer::append(const std::string& input) 84 { 85 for (unsigned int i = 0; i < input.size(); i++) 86 { 87 if (charIsAllowed(input[i])) 88 buffer_ += input[i]; 89 90 updated(input[i], false); 91 } 92 updated(); 93 } 94 95 void InputBuffer::append(const char& input) 96 { 97 if (charIsAllowed(input)) 98 buffer_ += input; 99 100 updated(input, true); 101 } 102 103 void InputBuffer::clear() 104 { 105 buffer_ = ""; 106 updated(); 107 } 108 109 void InputBuffer::removeLast() 110 { 111 buffer_ = buffer_.substr(0, buffer_.size() - 1); 112 updated(); 113 } 114 115 void InputBuffer::updated() 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 118 { 119 if ((*it).bListenToAllChanges_) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 void InputBuffer::updated(const char& update, bool bSingleInput) 125 { 126 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 127 { 128 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 129 (*(*it).listener_.*(*it).function_)(); 130 } 131 } 132 133 bool InputBuffer::charIsAllowed(const char& input) 134 { 135 if (allowedChars_ == "") 136 return true; 137 else 138 return (allowedChars_.find(input) != std::string::npos); 139 } 140 141 142 void InputBuffer::processKey(const KeyEvent &evt) 143 { 144 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 145 { 146 if (evt.key == KeyCode::V) 147 append(fromClipboard()); 148 else if (evt.key == KeyCode::C) 149 toClipboard(buffer_); 150 else if (evt.key == KeyCode::X) 151 { 152 toClipboard(buffer_); 153 clear(); 154 } 155 } 156 else if (evt.isModifierDown(KeyboardModifier::Shift)) 157 { 158 if (evt.key == KeyCode::Insert) 159 { 160 append(fromClipboard()); 161 } 162 else if (evt.key == KeyCode::Delete) 163 { 164 toClipboard(buffer_); 165 clear(); 166 } 167 } 168 //std::string input = keyboard_->getAsString(e.key); 169 /*if (input.size() >= 1) 170 append(input[0]);*/ 171 172 append((char)evt.text); 173 } 174 175 /** 176 * This tick() function is called by the InputManager if the InputBuffer is active. 177 * @param dt Delta time 178 */ 179 void InputBuffer::tick(float dt) 180 { 181 timeSinceKeyPressed_ += dt; 182 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 183 { 184 // initial time out has gone by, start repeating keys 185 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 186 { 187 timeSinceKeyRepeated_ += keyRepeatTime_; 188 keysToRepeat_++; 189 } 190 } 191 } 192 193 void InputBuffer::keyPressed(const KeyEvent &evt) 194 { 195 lastKey_ = evt.key; 196 timeSinceKeyPressed_ = 0.0; 197 timeSinceKeyRepeated_ = keyRepeatDeleay_; 198 keysToRepeat_ = 0; 199 200 processKey(evt); 201 } 202 203 void InputBuffer::keyHeld(const KeyEvent& evt) 204 { 205 if (evt.key == lastKey_) 206 { 207 while (keysToRepeat_) 208 { 39 InputBuffer::InputBuffer() 40 { 41 RegisterObject(InputBuffer); 42 43 this->buffer_ = ""; 44 this->cursor_ = 0; 45 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \ 46 ABCDEFGHIJKLMNOPQRSTUVWXYZ \ 47 äëïöüÄËÏÖÜáâàéêèíîìóôòúûù \ 48 0123456789 \ 49 \\\"(){}[]<>.:,;_-+*/=!?|$&%^~#"; 50 51 this->lastKey_ = KeyCode::Unassigned; 52 this->timeSinceKeyPressed_ = 0.0f; 53 this->timeSinceKeyRepeated_ = 0.0f; 54 this->keysToRepeat_ = 0; 55 56 setConfigValues(); 57 } 58 59 InputBuffer::InputBuffer(const std::string allowedChars) 60 { 61 RegisterObject(InputBuffer); 62 63 this->allowedChars_ = allowedChars; 64 this->buffer_ = ""; 65 this->cursor_ = 0; 66 67 this->lastKey_ = KeyCode::Unassigned; 68 this->timeSinceKeyPressed_ = 0.0f; 69 this->timeSinceKeyRepeated_ = 0.0f; 70 this->keysToRepeat_ = 0; 71 72 setConfigValues(); 73 } 74 75 void InputBuffer::setConfigValues() 76 { 77 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 78 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 79 80 if (keyRepeatDeleay_ < 0.0) 81 { 82 ResetConfigValue(keyRepeatDeleay_); 83 } 84 if (keyRepeatTime_ < 0.0) 85 { 86 ResetConfigValue(keyRepeatTime_); 87 } 88 } 89 90 void InputBuffer::set(const std::string& input, bool update) 91 { 92 this->clear(false); 93 this->insert(input, update); 94 } 95 96 void InputBuffer::insert(const std::string& input, bool update) 97 { 98 for (unsigned int i = 0; i < input.size(); ++i) 99 { 100 this->insert(input[i], false); 101 102 if (update) 103 this->updated(input[i], false); 104 } 105 106 if (update) 107 this->updated(); 108 } 109 110 void InputBuffer::insert(const char& input, bool update) 111 { 112 if (this->charIsAllowed(input)) 113 { 114 this->buffer_.insert(this->cursor_, 1, input); 115 ++this->cursor_; 116 } 117 118 if (update) 119 this->updated(input, true); 120 } 121 122 void InputBuffer::clear(bool update) 123 { 124 this->buffer_ = ""; 125 this->cursor_ = 0; 126 127 if (update) 128 this->updated(); 129 } 130 131 void InputBuffer::removeBehindCursor(bool update) 132 { 133 if (this->cursor_ > 0) 134 { 135 --this->cursor_; 136 this->buffer_.erase(this->cursor_, 1); 137 138 if (update) 139 this->updated(); 140 } 141 } 142 143 void InputBuffer::removeAtCursor(bool update) 144 { 145 if (this->cursor_ < this->buffer_.size()) 146 { 147 this->buffer_.erase(this->cursor_, 1); 148 149 if (update) 150 this->updated(); 151 } 152 } 153 154 void InputBuffer::updated() 155 { 156 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 157 { 158 if ((*it)->bListenToAllChanges_) 159 (*it)->callFunction(); 160 } 161 } 162 163 void InputBuffer::updated(const char& update, bool bSingleInput) 164 { 165 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 166 { 167 if ((!(*it)->trueKeyFalseChar_) && ((*it)->bListenToAllChanges_ || ((*it)->char_ == update)) && (!(*it)->bOnlySingleInput_ || bSingleInput)) 168 (*it)->callFunction(); 169 } 170 } 171 172 bool InputBuffer::charIsAllowed(const char& input) 173 { 174 if (this->allowedChars_ == "") 175 return true; 176 else 177 return (this->allowedChars_.find(input) != std::string::npos); 178 } 179 180 181 void InputBuffer::processKey(const KeyEvent &evt) 182 { 183 if (evt.isModifierDown(KeyboardModifier::Alt) && evt.key == KeyCode::Tab) 184 return; 185 186 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 187 { 188 if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.key)) 189 (*it)->callFunction(); 190 } 191 192 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 193 { 194 if (evt.key == KeyCode::V) 195 this->insert(fromClipboard()); 196 else if (evt.key == KeyCode::C) 197 toClipboard(this->buffer_); 198 else if (evt.key == KeyCode::X) 199 { 200 toClipboard(this->buffer_); 201 this->clear(); 202 } 203 } 204 else if (evt.isModifierDown(KeyboardModifier::Shift)) 205 { 206 if (evt.key == KeyCode::Insert) 207 this->insert(fromClipboard()); 208 else if (evt.key == KeyCode::Delete) 209 { 210 toClipboard(this->buffer_); 211 this->clear(); 212 } 213 } 214 215 this->insert((char)evt.text); 216 } 217 218 /** 219 @brief This tick() function is called by the InputManager if the InputBuffer is active. 220 @param dt Delta time 221 */ 222 void InputBuffer::tickInput(float dt, const HandlerState& state) 223 { 224 timeSinceKeyPressed_ += dt; 225 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 226 { 227 // initial time out has gone by, start repeating keys 228 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 229 { 230 timeSinceKeyRepeated_ += keyRepeatTime_; 231 keysToRepeat_++; 232 } 233 } 234 } 235 236 void InputBuffer::keyPressed(const KeyEvent &evt) 237 { 238 lastKey_ = evt.key; 239 timeSinceKeyPressed_ = 0.0; 240 timeSinceKeyRepeated_ = keyRepeatDeleay_; 241 keysToRepeat_ = 0; 242 209 243 processKey(evt); 210 keysToRepeat_--; 211 } 212 } 213 } 214 244 } 245 246 void InputBuffer::keyHeld(const KeyEvent& evt) 247 { 248 if (evt.key == lastKey_) 249 { 250 while (keysToRepeat_) 251 { 252 processKey(evt); 253 keysToRepeat_--; 254 } 255 } 256 } 215 257 } -
TabularUnified code/trunk/src/core/InputBuffer.h ¶
r1349 r1502 36 36 37 37 #include "InputInterfaces.h" 38 #include " Tickable.h"38 #include "OrxonoxClass.h" 39 39 40 40 namespace orxonox 41 41 { 42 class _CoreExport InputBufferListener 43 {}; 44 45 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 46 { 47 struct InputBufferListenerTuple 42 class BaseInputBufferListenerTuple 48 43 { 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 44 public: 45 BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput, 46 bool trueKeyFalseChar, char _char, KeyCode::Enum key) 47 : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput), 48 trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key) 49 { } 50 virtual ~BaseInputBufferListenerTuple() { } 51 virtual void callFunction() = 0; 52 bool bListenToAllChanges_; 53 bool bOnlySingleInput_; 54 bool trueKeyFalseChar_; 55 char char_; 56 KeyCode::Enum key_; 54 57 }; 55 58 56 public: 57 InputBuffer(const std::string allowedChars = 58 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^"); 59 template <class T> 60 class InputBufferListenerTuple : public BaseInputBufferListenerTuple 61 { 62 public: 63 InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges, 64 bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key) 65 : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key), 66 listener_(listener), function_(function) 67 { } 68 virtual ~InputBufferListenerTuple() { } 69 void callFunction() 70 { 71 (listener_->*function_)(); 72 } 73 T* listener_; 74 void (T::*function_)(); 75 }; 59 76 60 void setConfigValues(); 77 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 78 { 79 public: 80 InputBuffer(); 81 InputBuffer(const std::string allowedChars); 61 82 62 template <class T> 63 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 64 { 65 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 66 this->listeners_.insert(this->listeners_.end(), newListener); 67 } 68 template <class T> 69 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 70 { 71 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 72 this->listeners_.insert(this->listeners_.end(), newListener); 73 } 83 void setConfigValues(); 74 84 75 template <class T> 76 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput) 77 { 78 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 79 this->listeners_.insert(this->listeners_.end(), newListener); 80 } 81 template <class T> 82 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput) 83 { 84 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 85 this->listeners_.insert(this->listeners_.end(), newListener); 86 } 85 template <class T> 86 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 87 { 88 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); 89 this->listeners_.insert(this->listeners_.end(), newTuple); 90 } 91 template <class T> 92 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 93 { 94 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); 95 this->listeners_.insert(this->listeners_.end(), newTuple); 96 } 97 template <class T> 98 void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput) 99 { 100 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); 101 this->listeners_.insert(this->listeners_.end(), newTuple); 102 } 103 template <class T> 104 void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput) 105 { 106 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); 107 this->listeners_.insert(this->listeners_.end(), newTuple); 108 } 87 109 88 void set(const std::string& input); 89 void append(const std::string& input); 90 void append(const char& input); 91 void removeLast(); 92 void clear(); 110 template <class T> 111 void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key) 112 { 113 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); 114 this->listeners_.insert(this->listeners_.end(), newTuple); 115 } 116 template <class T> 117 void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key) 118 { 119 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); 120 this->listeners_.insert(this->listeners_.end(), newTuple); 121 } 93 122 94 void updated(); 95 void updated(const char& update, bool bSingleInput); 123 template <class T> 124 void unregisterListener(T* listener) 125 { 126 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 127 { 128 InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it); 129 if (refListener && refListener->listener_ == listener) 130 this->listeners_.erase(it++); 131 else 132 it++; 133 } 134 } 96 135 97 inline std::string get() const 98 { return this->buffer_; } 136 void set(const std::string& input, bool update = true); 137 void insert(const std::string& input, bool update = true); 138 void insert(const char& input, bool update = true); 139 void clear(bool update = true); 140 void removeAtCursor(bool update = true); 141 void removeBehindCursor(bool update = true); 99 142 100 private: // functions101 bool charIsAllowed(const char& input);143 void updated(); 144 void updated(const char& update, bool bSingleInput); 102 145 103 void keyPressed (const KeyEvent& evt);104 void keyReleased(const KeyEvent& evt) {}105 void keyHeld (const KeyEvent& evt);106 void processKey (const KeyEvent &e);146 inline std::string get() const 147 { return this->buffer_; } 148 inline unsigned int getSize() const 149 { return this->buffer_.size(); } 107 150 108 void tick(float dt); 151 inline unsigned int getCursorPosition() const 152 { return this->cursor_; } 153 inline void setCursorPosition(unsigned int cursor) 154 { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } } 155 inline void setCursorToEnd() 156 { this->cursor_ = this->buffer_.size(); } 157 inline void setCursorToBegin() 158 { this->cursor_ = 0; } 159 inline void increaseCursor() 160 { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } } 161 inline void decreaseCursor() 162 { if (this->cursor_ > 0) { --this->cursor_; } } 109 163 110 private: // variables 111 std::string buffer_; 112 std::list<InputBufferListenerTuple> listeners_; 113 std::string allowedChars_; 164 private: 165 bool charIsAllowed(const char& input); 114 166 115 KeyCode::Enum lastKey_;116 float timeSinceKeyPressed_;117 float timeSinceKeyRepeated_;118 int keysToRepeat_;167 void keyPressed (const KeyEvent& evt); 168 void keyReleased(const KeyEvent& evt) { } 169 void keyHeld (const KeyEvent& evt); 170 void processKey (const KeyEvent &e); 119 171 120 // configured values 121 float keyRepeatDeleay_; 122 float keyRepeatTime_; 123 }; 172 void tickInput(float dt, const HandlerState& state); 173 174 std::string buffer_; 175 std::list<BaseInputBufferListenerTuple*> listeners_; 176 std::string allowedChars_; 177 unsigned int cursor_; 178 179 KeyCode::Enum lastKey_; 180 float timeSinceKeyPressed_; 181 float timeSinceKeyRepeated_; 182 int keysToRepeat_; 183 184 float keyRepeatDeleay_; 185 float keyRepeatTime_; 186 }; 124 187 } 125 188 -
TabularUnified code/trunk/src/core/InputInterfaces.h ¶
r1349 r1502 254 254 std::vector<Vector3> mVectors; 255 255 };*/ 256 257 /** 258 * Helper struct to determine which handlers of an object (can implement 259 * multiple handlers) are active. 260 */ 261 struct HandlerState 262 { 263 HandlerState() : key(false), mouse(false), joyStick(false) { } 264 bool key; 265 bool mouse; 266 bool joyStick; 267 }; 256 268 257 269 class _CoreExport InputTickable … … 259 271 public: 260 272 virtual ~InputTickable() { } 261 virtual void tick (float dt) = 0;273 virtual void tickInput(float dt, const HandlerState& state) = 0; 262 274 }; 263 275 … … 272 284 virtual void keyReleased(const KeyEvent& evt) = 0; 273 285 virtual void keyHeld (const KeyEvent& evt) = 0; 286 //virtual void tickKey (float dt) { } 274 287 }; 275 288 … … 286 299 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 287 300 virtual void mouseScrolled (int abs, int rel) = 0; 301 //virtual void tickMouse (float dt) { } 288 302 }; 289 303 … … 299 313 virtual void joyStickButtonReleased(int joyStickID, int button) = 0; 300 314 virtual void joyStickButtonHeld (int joyStickID, int button) = 0; 301 virtual void joyStickAxisMoved (int joyStickID, int axis, int value) = 0;315 virtual void joyStickAxisMoved (int joyStickID, int axis, float value) = 0; 302 316 //virtual bool joyStickVector3Moved (int joyStickID, int index /*, fill list*/) {return true;} 317 //virtual void tickJoyStick (float dt) { } 303 318 }; 304 319 -
TabularUnified code/trunk/src/core/InputManager.cc ¶
r1349 r1502 34 34 35 35 #include "InputManager.h" 36 #include "util/Convert.h" 36 37 #include "CoreIncludes.h" 38 #include "ConfigValueIncludes.h" 37 39 #include "Debug.h" 38 40 #include "InputBuffer.h" 39 #include "InputHandler.h" 41 #include "KeyBinder.h" 42 #include "CommandExecutor.h" 43 #include "ConsoleCommand.h" 44 #include "Shell.h" 40 45 41 46 namespace orxonox 42 47 { 48 SetConsoleCommandShortcut(InputManager, keyBind); 49 SetConsoleCommandShortcut(InputManager, storeKeyStroke); 50 SetConsoleCommandShortcut(InputManager, calibrate); 51 43 52 // ############################### 44 53 // ### Internal Methods ### … … 53 62 inputSystem_(0), keyboard_(0), mouse_(0), 54 63 joySticksSize_(0), 55 state_(IS_UNINIT), stateRequest_(IS_UNINIT), 64 keyBinder_(0), keyDetector_(0), buffer_(0), calibratorCallback_(0), 65 state_(IS_UNINIT), stateRequest_(IS_UNINIT), savedState_(IS_UNINIT), 56 66 keyboardModifiers_(0) 57 67 { … … 129 139 if (mouse_) 130 140 { 131 //// hack the mouse position132 //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;133 //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;134 141 setWindowExtents(windowWidth, windowHeight); 135 142 } … … 137 144 state_ = IS_NONE; 138 145 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 146 147 // InputManager holds the input buffer --> create one and add it. 148 buffer_ = new InputBuffer(); 149 addKeyHandler(buffer_, "buffer"); 150 Shell::getInstance().setInputBuffer(buffer_); 151 152 keyBinder_ = new KeyBinder(); 153 keyBinder_->loadBindings(); 154 addKeyHandler(keyBinder_, "keybinder"); 155 addMouseHandler(keyBinder_, "keybinder"); 156 addJoyStickHandler(keyBinder_, "keybinder"); 157 158 keyDetector_ = new KeyDetector(); 159 keyDetector_->loadBindings(); 160 addKeyHandler(keyDetector_, "keydetector"); 161 addMouseHandler(keyDetector_, "keydetector"); 162 addJoyStickHandler(keyDetector_, "keydetector"); 163 164 calibratorCallback_ = new CalibratorCallback(); 165 addKeyHandler(calibratorCallback_, "calibratorcallback"); 166 167 setConfigValues(); 168 169 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; 139 170 } 140 171 else … … 142 173 CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl; 143 174 } 144 145 // InputManager holds the input buffer --> create one and add it.146 addKeyHandler(new InputBuffer(), "buffer");147 148 KeyBinder* binder = new KeyBinder();149 binder->loadBindings();150 addKeyHandler(binder, "keybinder");151 addMouseHandler(binder, "keybinder");152 addJoyStickHandler(binder, "keybinder");153 154 // Read all the key bindings and assign them155 //if (!_loadBindings())156 // return false;157 158 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;159 175 return true; 160 176 } … … 216 232 // register our listener in OIS. 217 233 mouse_->setEventCallback(this); 218 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;234 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 219 235 return true; 220 236 } … … 276 292 povStates_.resize(joySticksSize_); 277 293 sliderStates_.resize(joySticksSize_); 294 joySticksCalibration_.resize(joySticksSize_); 295 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 296 { 297 // reset the calibration with default values 298 for (unsigned int i = 0; i < 24; i++) 299 { 300 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f; 301 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f; 302 joySticksCalibration_[iJoyStick].zeroStates[i] = 0; 303 } 304 } 278 305 return success; 279 306 } 280 307 281 308 /** 309 @brief Sets the configurable values. Use keybindings.ini as file.. 310 */ 311 void InputManager::setConfigValues() 312 { 313 if (joySticksSize_) 314 { 315 std::vector<MultiTypeMath> coeffPos; 316 std::vector<MultiTypeMath> coeffNeg; 317 std::vector<MultiTypeMath> zero; 318 coeffPos.resize(24); 319 coeffNeg.resize(24); 320 zero.resize(24); 321 for (unsigned int i = 0; i < 24; i++) 322 { 323 coeffPos[i] = 1.0f/32767.0f; 324 coeffNeg[i] = 1.0f/32768.0f; 325 zero[i] = 0; 326 } 327 328 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 329 if (!cont) 330 { 331 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos); 332 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 333 } 334 cont->getValue(&coeffPos); 335 336 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 337 if (!cont) 338 { 339 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg); 340 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 341 } 342 cont->getValue(&coeffNeg); 343 344 cont = getIdentifier()->getConfigValueContainer("Zero"); 345 if (!cont) 346 { 347 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero); 348 getIdentifier()->addConfigValueContainer("Zero", cont); 349 } 350 cont->getValue(&zero); 351 352 // copy values to our own variables 353 for (unsigned int i = 0; i < 24; i++) 354 { 355 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 356 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 357 joySticksCalibration_[0].zeroStates[i] = zero[i]; 358 } 359 } 360 } 361 362 /** 282 363 @brief Destroys all the created input devices and sets the InputManager to construction state. 283 364 */ … … 288 369 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 289 370 290 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 291 delete keyHandlers_["buffer"]; 292 293 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 294 delete keyHandlers_["keybinder"]; 371 if (buffer_) 372 delete buffer_; 373 374 if (keyBinder_) 375 delete keyBinder_; 376 377 if (keyDetector_) 378 delete keyDetector_; 379 380 if (calibratorCallback_) 381 delete calibratorCallback_; 295 382 296 383 keyHandlers_.clear(); … … 301 388 _destroyMouse(); 302 389 _destroyJoySticks(); 390 391 activeHandlers_.clear(); 303 392 304 393 // inputSystem_ can never be 0, or else the code is mistaken … … 355 444 activeJoyStickHandlers_.clear(); 356 445 joyStickButtonsDown_.clear(); 446 povStates_.clear(); 447 sliderStates_.clear(); 448 joySticksCalibration_.clear(); 357 449 } 358 450 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; 359 451 } 360 452 453 void InputManager::_saveState() 454 { 455 savedHandlers_.activeHandlers_ = activeHandlers_; 456 savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_; 457 savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_; 458 savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_; 459 } 460 461 void InputManager::_restoreState() 462 { 463 activeHandlers_ = savedHandlers_.activeHandlers_; 464 activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_; 465 activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_; 466 activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_; 467 } 468 361 469 void InputManager::_updateTickables() 362 470 { 363 // we can use a setto have a list of unique pointers (an object can implement all 3 handlers)364 std:: set<InputTickable*> tempSet;471 // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) 472 std::map<InputTickable*, HandlerState> tempSet; 365 473 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 366 tempSet .insert(activeKeyHandlers_[iHandler]);474 tempSet[activeKeyHandlers_[iHandler]].joyStick = true; 367 475 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 368 tempSet .insert(activeMouseHandlers_[iHandler]);476 tempSet[activeMouseHandlers_[iHandler]].mouse = true; 369 477 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 370 478 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 371 tempSet .insert(activeJoyStickHandlers_[iJoyStick][iHandler]);372 373 // copy the content of the setback to the actual vector479 tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; 480 481 // copy the content of the map back to the actual vector 374 482 activeHandlers_.clear(); 375 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 376 activeHandlers_.push_back(*itHandler); 483 for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); 484 itHandler != tempSet.end(); itHandler++) 485 activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); 377 486 } 378 487 … … 392 501 return; 393 502 394 // reset the game if it has changed395 503 if (state_ != stateRequest_) 396 504 { 397 if (stateRequest_ != IS_CUSTOM) 398 { 505 InputState sr = stateRequest_; 506 switch (sr) 507 { 508 case IS_NORMAL: 399 509 activeKeyHandlers_.clear(); 400 510 activeMouseHandlers_.clear(); … … 402 512 activeJoyStickHandlers_[i].clear(); 403 513 404 switch (stateRequest_) 514 // normal play mode 515 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 516 enableKeyHandler("keybinder"); 517 enableMouseHandler("keybinder"); 518 enableJoyStickHandler("keybinder", 0); 519 stateRequest_ = IS_NORMAL; 520 state_ = IS_NORMAL; 521 break; 522 523 case IS_GUI: 524 state_ = IS_GUI; 525 break; 526 527 case IS_CONSOLE: 528 activeKeyHandlers_.clear(); 529 activeMouseHandlers_.clear(); 530 for (unsigned int i = 0; i < joySticksSize_; i++) 531 activeJoyStickHandlers_[i].clear(); 532 533 enableMouseHandler("keybinder"); 534 enableJoyStickHandler("keybinder", 0); 535 enableKeyHandler("buffer"); 536 stateRequest_ = IS_CONSOLE; 537 state_ = IS_CONSOLE; 538 break; 539 540 case IS_DETECT: 541 savedState_ = state_; 542 _saveState(); 543 544 activeKeyHandlers_.clear(); 545 activeMouseHandlers_.clear(); 546 for (unsigned int i = 0; i < joySticksSize_; i++) 547 activeJoyStickHandlers_[i].clear(); 548 549 enableKeyHandler("keydetector"); 550 enableMouseHandler("keydetector"); 551 enableJoyStickHandler("keydetector", 0); 552 553 stateRequest_ = IS_DETECT; 554 state_ = IS_DETECT; 555 break; 556 557 case IS_NODETECT: 558 _restoreState(); 559 keysDown_.clear(); 560 mouseButtonsDown_.clear(); 561 joyStickButtonsDown_[0].clear(); 562 state_ = IS_NODETECT; 563 stateRequest_ = savedState_; 564 break; 565 566 case IS_CALIBRATE: 567 if (joySticksSize_) 405 568 { 406 case IS_NORMAL: 407 // normal play mode 408 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 409 enableKeyHandler("keybinder"); 410 enableMouseHandler("keybinder"); 411 enableMouseHandler("SpaceShip"); 412 enableJoyStickHandler("keybinder", 0); 413 break; 414 415 case IS_GUI: 416 // TODO: do stuff 417 break; 418 419 case IS_CONSOLE: 420 enableMouseHandler("keybinder"); 421 enableMouseHandler("SpaceShip"); 422 enableJoyStickHandler("keybinder", 0); 423 enableKeyHandler("buffer"); 424 break; 425 426 default: 427 break; 569 savedState_ = _getSingleton().state_; 570 for (unsigned int i = 0; i < 24; i++) 571 { 572 marginalsMax_[i] = INT_MIN; 573 marginalsMin_[i] = INT_MAX; 574 } 575 COUT(0) << "Move all joy stick axes in all directions a few times. " 576 << "Then put all axes in zero state and hit enter." << std::endl; 577 578 savedState_ = state_; 579 _saveState(); 580 581 activeKeyHandlers_.clear(); 582 activeMouseHandlers_.clear(); 583 for (unsigned int i = 0; i < joySticksSize_; i++) 584 activeJoyStickHandlers_[i].clear(); 585 586 enableKeyHandler("calibratorcallback"); 587 stateRequest_ = IS_CALIBRATE; 588 state_ = IS_CALIBRATE; 428 589 } 429 state_ = stateRequest_; 590 else 591 { 592 COUT(3) << "Connot calibrate, no joy stick found!" << std::endl; 593 stateRequest_ = state_; 594 } 595 break; 596 597 case IS_NOCALIBRATE: 598 _completeCalibration(); 599 _restoreState(); 600 keyBinder_->resetJoyStickAxes(); 601 state_ = IS_NOCALIBRATE; 602 stateRequest_ = savedState_; 603 break; 604 605 case IS_NONE: 606 activeKeyHandlers_.clear(); 607 activeMouseHandlers_.clear(); 608 for (unsigned int i = 0; i < joySticksSize_; i++) 609 activeJoyStickHandlers_[i].clear(); 610 state_ = IS_NONE; 611 612 default: 613 break; 430 614 } 431 615 } … … 439 623 joySticks_[i]->capture(); 440 624 441 442 // call all the handlers for the held key events 443 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 444 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 445 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 446 447 // call all the handlers for the held mouse button events 448 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 449 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 450 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 451 452 // call all the handlers for the held joy stick button events 453 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 454 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 455 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 456 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 457 458 459 // call the ticks 625 if (state_ != IS_CALIBRATE) 626 { 627 // call all the handlers for the held key events 628 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 629 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 630 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 631 632 // call all the handlers for the held mouse button events 633 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 634 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 635 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 636 637 // call all the handlers for the held joy stick button events 638 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 639 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 640 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 641 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 642 } 643 644 // call the ticks for the handlers (need to be treated specially) 460 645 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 461 activeHandlers_[iHandler]->tick(dt); 646 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 647 } 648 649 void InputManager::_completeCalibration() 650 { 651 for (unsigned int i = 0; i < 24; i++) 652 { 653 // positive coefficient 654 if (marginalsMax_[i] == INT_MIN) 655 marginalsMax_[i] = 32767; 656 // coefficients 657 if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]) 658 joySticksCalibration_[0].positiveCoeff[i] = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]); 659 else 660 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 661 662 // config value 663 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 664 assert(cont); 665 cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); 666 667 // negative coefficient 668 if (marginalsMin_[i] == INT_MAX) 669 marginalsMin_[i] = -32768; 670 // coefficients 671 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 672 joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 673 else 674 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 675 // config value 676 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 677 assert(cont); 678 cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); 679 680 // zero states 681 if (i < 8) 682 { 683 if (!(i & 1)) 684 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX; 685 else 686 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY; 687 } 688 else 689 { 690 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size()) 691 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs; 692 else 693 joySticksCalibration_[0].zeroStates[i] = 0; 694 } 695 // config value 696 cont = getIdentifier()->getConfigValueContainer("Zero"); 697 assert(cont); 698 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 699 } 462 700 } 463 701 … … 594 832 // ###### Joy Stick Events ###### 595 833 596 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)834 inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg) 597 835 { 598 836 // use the device to identify which one called the method … … 600 838 unsigned int iJoyStick = 0; 601 839 while (joySticks_[iJoyStick] != joyStick) 840 { 602 841 iJoyStick++; 842 if (iJoyStick == joySticksSize_) 843 { 844 CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl; 845 abort(); 846 } 847 } 848 return iJoyStick; 849 } 850 851 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 852 { 853 unsigned int iJoyStick = _getJoystick(arg); 603 854 604 855 // check whether the button already is in the list (can happen when focus was lost) 605 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];856 std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 606 857 unsigned int iButton = 0; 607 858 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) … … 618 869 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 619 870 { 620 // use the device to identify which one called the method 621 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 622 unsigned int iJoyStick = 0; 623 while (joySticks_[iJoyStick] != joyStick) 624 iJoyStick++; 871 unsigned int iJoyStick = _getJoystick(arg); 625 872 626 873 // remove the button from the joyStickButtonsDown_ list 627 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];874 std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 628 875 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 629 876 { … … 641 888 } 642 889 890 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 891 { 892 if (state_ == IS_CALIBRATE) 893 { 894 if (value > marginalsMax_[axis]) 895 marginalsMax_[axis] = value; 896 if (value < marginalsMin_[axis]) 897 marginalsMin_[axis] = value; 898 } 899 else 900 { 901 float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis]; 902 if (fValue > 0.0f) 903 fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis]; 904 else 905 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis]; 906 907 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 908 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 909 } 910 } 911 643 912 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 644 913 { 645 //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl; 646 // use the device to identify which one called the method 647 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 648 unsigned int iJoyStick = 0; 649 while (joySticks_[iJoyStick] != joyStick) 650 iJoyStick++; 914 //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000) 915 //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;} 916 917 unsigned int iJoyStick = _getJoystick(arg); 651 918 652 919 // keep in mind that the first 8 axes are reserved for the sliders 653 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 654 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 920 _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 655 921 656 922 return true; … … 659 925 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 660 926 { 927 //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000) 928 //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;} 661 929 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 662 // use the device to identify which one called the method 663 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 664 unsigned int iJoyStick = 0; 665 while (joySticks_[iJoyStick] != joyStick) 666 iJoyStick++; 930 931 unsigned int iJoyStick = _getJoystick(arg); 667 932 668 933 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 669 { 670 // slider X axis changed 671 sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; 672 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 673 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); 674 } 934 _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX); 675 935 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 676 { 677 // slider Y axis changed 678 sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; 679 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 680 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 681 } 936 _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 682 937 683 938 return true; … … 686 941 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 687 942 { 688 // use the device to identify which one called the method 689 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 690 unsigned int iJoyStick = 0; 691 while (joySticks_[iJoyStick] != joyStick) 692 iJoyStick++; 943 unsigned int iJoyStick = _getJoystick(arg); 693 944 694 945 // translate the POV into 8 simple buttons … … 702 953 if (lastState & OIS::Pov::West) 703 954 buttonReleased(arg, 32 + id * 4 + 3); 704 955 705 956 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 957 706 958 int currentState = povStates_[iJoyStick][id]; 707 959 if (currentState & OIS::Pov::North) … … 719 971 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 720 972 { 721 // use the device to identify which one called the method 722 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 723 unsigned int iJoyStick = 0; 724 while (joySticks_[iJoyStick] != joyStick) 725 iJoyStick++; 973 unsigned int iJoyStick = _getJoystick(arg); 726 974 727 975 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) … … 737 985 // ################################ 738 986 987 std::string InputManager::bindingCommmandString_s = ""; 988 739 989 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 740 990 bool createKeyboard, bool createMouse, bool createJoySticks) … … 780 1030 } 781 1031 782 bool InputManager::isKeyDown(KeyCode::Enum key)1032 /*bool InputManager::isKeyDown(KeyCode::Enum key) 783 1033 { 784 1034 if (_getSingleton().keyboard_) … … 786 1036 else 787 1037 return false; 788 } 789 790 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)1038 }*/ 1039 1040 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 791 1041 { 792 1042 if (_getSingleton().keyboard_) … … 794 1044 else 795 1045 return false; 796 } 1046 }*/ 797 1047 798 1048 /*const MouseState InputManager::getMouseState() … … 811 1061 return JoyStickState(); 812 1062 }*/ 813 814 1063 815 1064 void InputManager::destroy() … … 870 1119 } 871 1120 1121 void InputManager::storeKeyStroke(const std::string& name) 1122 { 1123 setInputState(IS_NODETECT); 1124 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1125 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1126 } 1127 1128 void InputManager::keyBind(const std::string& command) 1129 { 1130 bindingCommmandString_s = command; 1131 setInputState(IS_DETECT); 1132 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1133 } 1134 1135 void InputManager::calibrate() 1136 { 1137 _getSingleton().setInputState(IS_CALIBRATE); 1138 } 872 1139 873 1140 // ###### KeyHandler ###### -
TabularUnified code/trunk/src/core/InputManager.h ¶
r1349 r1502 65 65 public: 66 66 IntVector2 sliderStates[4]; 67 }; 68 69 /** 70 * Struct for storing a custom input state 71 */ 72 struct StoredState 73 { 74 std::vector<KeyHandler*> activeKeyHandlers_; 75 std::vector<MouseHandler*> activeMouseHandlers_; 76 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 77 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_; 78 }; 79 80 struct JoyStickCalibration 81 { 82 int zeroStates[24]; 83 float positiveCoeff[24]; 84 float negativeCoeff[24]; 67 85 }; 68 86 … … 80 98 enum InputState 81 99 { 82 IS_UNINIT, //!< InputManager has not yet been initialised. 83 IS_NONE, //!< Input is discarded. 84 IS_NORMAL, //!< Normal play state. Key and button bindings are active. 85 IS_GUI, //!< All OIS input events are passed to CEGUI. 86 IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer. 87 IS_CUSTOM //!< Any possible configuration. 100 IS_UNINIT, //!< InputManager has not yet been initialised. 101 IS_NONE, //!< Input is discarded. 102 IS_NORMAL, //!< Normal play state. Key and button bindings are active. 103 IS_GUI, //!< All OIS input events are passed to CEGUI. 104 IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer. 105 IS_DETECT, //!< All the input additionally goes to the KeyDetector 106 IS_NODETECT, //!< remove KeyDetector 107 IS_NOCALIBRATE, 108 IS_CALIBRATE, 109 IS_CUSTOM //!< Any possible configuration. 88 110 }; 111 112 public: // member functions 113 void setConfigValues(); 89 114 90 115 public: // static functions … … 103 128 static void destroyJoySticks(); 104 129 105 static bool isModifierDown(KeyboardModifier::Enum modifier);106 static bool isKeyDown(KeyCode::Enum key);130 //static bool isModifierDown(KeyboardModifier::Enum modifier); 131 //static bool isKeyDown(KeyCode::Enum key); 107 132 //static const MouseState getMouseState(); 108 133 //static const JoyStickState getJoyStickState(unsigned int ID); … … 112 137 static void setInputState(const InputState state); 113 138 static InputState getInputState(); 139 140 static void storeKeyStroke(const std::string& name); 141 static void keyBind(const std::string& command); 142 143 static void calibrate(); 114 144 115 145 static bool addKeyHandler (KeyHandler* handler, const std::string& name); … … 152 182 153 183 void _updateTickables(); 184 185 void _saveState(); 186 void _restoreState(); 187 188 void _completeCalibration(); 189 190 void _fireAxis(unsigned int iJoyStick, int axis, int value); 191 unsigned int _getJoystick(const OIS::JoyStickEvent& arg); 154 192 155 193 void tick(float dt); … … 172 210 173 211 private: // variables 174 OIS::InputManager* inputSystem_; //!< OIS input manager175 OIS::Keyboard* keyboard_; //!< OIS mouse176 OIS::Mouse* mouse_; //!< OIS keyboard177 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks212 OIS::InputManager* inputSystem_; //!< OIS input manager 213 OIS::Keyboard* keyboard_; //!< OIS mouse 214 OIS::Mouse* mouse_; //!< OIS keyboard 215 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 178 216 unsigned int joySticksSize_; 217 218 KeyBinder* keyBinder_; //!< KeyBinder instance 219 KeyDetector* keyDetector_; //!< KeyDetector instance 220 InputBuffer* buffer_; //!< InputBuffer instance 221 CalibratorCallback* calibratorCallback_; 179 222 180 223 InputState state_; 181 224 InputState stateRequest_; 225 InputState savedState_; 182 226 unsigned int keyboardModifiers_; 227 StoredState savedHandlers_; 228 229 // joystick calibration 230 //std::vector<int> marginalsMaxConfig_; 231 //std::vector<int> marginalsMinConfig_; 232 int marginalsMax_[24]; 233 int marginalsMin_[24]; 234 bool bCalibrated_; 183 235 184 236 //! Keeps track of the joy stick POV states … … 186 238 //! Keeps track of the possibly two slider axes 187 239 std::vector<SliderStates> sliderStates_; 240 std::vector<JoyStickCalibration> joySticksCalibration_; 188 241 189 242 std::map<std::string, KeyHandler*> keyHandlers_; … … 194 247 std::vector<MouseHandler*> activeMouseHandlers_; 195 248 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 196 std::vector< InputTickable*>activeHandlers_;249 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_; 197 250 198 251 std::vector<Key> keysDown_; … … 200 253 std::vector<std::vector<int> > joyStickButtonsDown_; 201 254 255 static std::string bindingCommmandString_s; 202 256 }; 203 257 -
TabularUnified code/trunk/src/core/Iterator.h ¶
r1063 r1502 50 50 51 51 #include "ObjectList.h" 52 #include "Debug.h"53 52 54 53 namespace orxonox -
TabularUnified code/trunk/src/core/Language.cc ¶
r1062 r1502 37 37 38 38 #include "CoreSettings.h" 39 40 #include "Debug.h" 39 41 40 42 namespace orxonox -
TabularUnified code/trunk/src/core/Language.h ¶
r1064 r1502 50 50 #include <map> 51 51 #include <string> 52 53 52 54 53 #define AddLanguageEntry(label, fallbackstring) \ -
TabularUnified code/trunk/src/core/OrxonoxClass.cc ¶
r1293 r1502 33 33 34 34 #include "OrxonoxClass.h" 35 #include "MetaObjectList.h" 36 #include "Identifier.h" 35 37 36 38 namespace orxonox … … 41 43 parents_(0) 42 44 { 45 this->metaList_ = new MetaObjectList(); 46 43 47 this->setConfigValues(); 44 48 } … … 47 51 OrxonoxClass::~OrxonoxClass() 48 52 { 53 delete this->metaList_; 54 49 55 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 50 56 if (this->parents_) 51 57 delete this->parents_; 52 58 } 59 60 /** @brief Returns true if the objects class is of the given type or a derivative. */ 61 bool OrxonoxClass::isA(const Identifier* identifier) 62 { return this->getIdentifier()->isA(identifier); } 63 /** @brief Returns true if the objects class is exactly of the given type. */ 64 bool OrxonoxClass::isExactlyA(const Identifier* identifier) 65 { return this->getIdentifier()->isExactlyA(identifier); } 66 /** @brief Returns true if the objects class is a child of the given type. */ 67 bool OrxonoxClass::isChildOf(const Identifier* identifier) 68 { return this->getIdentifier()->isChildOf(identifier); } 69 /** @brief Returns true if the objects class is a direct child of the given type. */ 70 bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) 71 { return this->getIdentifier()->isDirectChildOf(identifier); } 72 /** @brief Returns true if the objects class is a parent of the given type. */ 73 bool OrxonoxClass::isParentOf(const Identifier* identifier) 74 { return this->getIdentifier()->isParentOf(identifier); } 75 /** @brief Returns true if the objects class is a direct parent of the given type. */ 76 bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) 77 { return this->getIdentifier()->isDirectParentOf(identifier); } 78 79 80 /** @brief Returns true if the objects class is of the given type or a derivative. */ 81 bool OrxonoxClass::isA(const SubclassIdentifier<class B>* identifier) 82 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 83 /** @brief Returns true if the objects class is exactly of the given type. */ 84 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B>* identifier) 85 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 86 /** @brief Returns true if the objects class is a child of the given type. */ 87 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B>* identifier) 88 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 89 /** @brief Returns true if the objects class is a direct child of the given type. */ 90 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B>* identifier) 91 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 92 /** @brief Returns true if the objects class is a parent of the given type. */ 93 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B>* identifier) 94 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 95 /** @brief Returns true if the objects class is a direct parent of the given type. */ 96 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B>* identifier) 97 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 98 99 100 /** @brief Returns true if the objects class is of the given type or a derivative. */ 101 bool OrxonoxClass::isA(const SubclassIdentifier<class B> identifier) 102 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 103 /** @brief Returns true if the objects class is exactly of the given type. */ 104 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B> identifier) 105 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 106 /** @brief Returns true if the objects class is a child of the given type. */ 107 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B> identifier) 108 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 109 /** @brief Returns true if the objects class is a direct child of the given type. */ 110 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B> identifier) 111 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 112 /** @brief Returns true if the objects class is a parent of the given type. */ 113 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B> identifier) 114 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 115 /** @brief Returns true if the objects class is a direct parent of the given type. */ 116 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B> identifier) 117 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 118 119 120 /** @brief Returns true if the objects class is of the given type or a derivative. */ 121 bool OrxonoxClass::isA(const OrxonoxClass* object) 122 { return this->getIdentifier()->isA(object->getIdentifier()); } 123 /** @brief Returns true if the objects class is exactly of the given type. */ 124 bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) 125 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 126 /** @brief Returns true if the objects class is a child of the given type. */ 127 bool OrxonoxClass::isChildOf(const OrxonoxClass* object) 128 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 129 /** @brief Returns true if the objects class is a direct child of the given type. */ 130 bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) 131 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 132 /** @brief Returns true if the objects class is a parent of the given type. */ 133 bool OrxonoxClass::isParentOf(const OrxonoxClass* object) 134 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 135 /** @brief Returns true if the objects class is a direct child of the given type. */ 136 bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) 137 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 53 138 } -
TabularUnified code/trunk/src/core/OrxonoxClass.h ¶
r1062 r1502 43 43 #include <string> 44 44 45 #include "MetaObjectList.h"46 #include "Iterator.h"47 48 45 namespace orxonox 49 46 { … … 75 72 76 73 /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ 77 inline MetaObjectList& getMetaList() { return this->metaList_; }74 inline MetaObjectList& getMetaList() { return (*this->metaList_); } 78 75 79 76 80 /** @brief Returns true if the objects class is of the given type or a derivative. */ 81 inline bool isA(const Identifier* identifier) 82 { return this->getIdentifier()->isA(identifier); } 83 /** @brief Returns true if the objects class is exactly of the given type. */ 84 inline bool isExactlyA(const Identifier* identifier) 85 { return this->getIdentifier()->isExactlyA(identifier); } 86 /** @brief Returns true if the objects class is a child of the given type. */ 87 inline bool isChildOf(const Identifier* identifier) 88 { return this->getIdentifier()->isChildOf(identifier); } 89 /** @brief Returns true if the objects class is a direct child of the given type. */ 90 inline bool isDirectChildOf(const Identifier* identifier) 91 { return this->getIdentifier()->isDirectChildOf(identifier); } 92 /** @brief Returns true if the objects class is a parent of the given type. */ 93 inline bool isParentOf(const Identifier* identifier) 94 { return this->getIdentifier()->isParentOf(identifier); } 95 /** @brief Returns true if the objects class is a direct parent of the given type. */ 96 inline bool isDirectParentOf(const Identifier* identifier) 97 { return this->getIdentifier()->isDirectParentOf(identifier); } 77 bool isA(const Identifier* identifier); 78 bool isExactlyA(const Identifier* identifier); 79 bool isChildOf(const Identifier* identifier); 80 bool isDirectChildOf(const Identifier* identifier); 81 bool isParentOf(const Identifier* identifier); 82 bool isDirectParentOf(const Identifier* identifier); 98 83 84 bool isA(const SubclassIdentifier<class B>* identifier); 85 bool isExactlyA(const SubclassIdentifier<class B>* identifier); 86 bool isChildOf(const SubclassIdentifier<class B>* identifier); 87 bool isDirectChildOf(const SubclassIdentifier<class B>* identifier); 88 bool isParentOf(const SubclassIdentifier<class B>* identifier); 89 bool isDirectParentOf(const SubclassIdentifier<class B>* identifier); 99 90 100 /** @brief Returns true if the objects class is of the given type or a derivative. */ 101 inline bool isA(const SubclassIdentifier<class B>* identifier) 102 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 103 /** @brief Returns true if the objects class is exactly of the given type. */ 104 inline bool isExactlyA(const SubclassIdentifier<class B>* identifier) 105 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 106 /** @brief Returns true if the objects class is a child of the given type. */ 107 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 108 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 109 /** @brief Returns true if the objects class is a direct child of the given type. */ 110 inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier) 111 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 112 /** @brief Returns true if the objects class is a parent of the given type. */ 113 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 114 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 115 /** @brief Returns true if the objects class is a direct parent of the given type. */ 116 inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier) 117 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 91 bool isA(const SubclassIdentifier<class B> identifier); 92 bool isExactlyA(const SubclassIdentifier<class B> identifier); 93 bool isChildOf(const SubclassIdentifier<class B> identifier); 94 bool isDirectChildOf(const SubclassIdentifier<class B> identifier); 95 bool isParentOf(const SubclassIdentifier<class B> identifier); 96 bool isDirectParentOf(const SubclassIdentifier<class B> identifier); 118 97 119 120 /** @brief Returns true if the objects class is of the given type or a derivative. */ 121 inline bool isA(const SubclassIdentifier<class B> identifier) 122 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 123 /** @brief Returns true if the objects class is exactly of the given type. */ 124 inline bool isExactlyA(const SubclassIdentifier<class B> identifier) 125 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 126 /** @brief Returns true if the objects class is a child of the given type. */ 127 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 128 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 129 /** @brief Returns true if the objects class is a direct child of the given type. */ 130 inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier) 131 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 132 /** @brief Returns true if the objects class is a parent of the given type. */ 133 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 134 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 135 /** @brief Returns true if the objects class is a direct parent of the given type. */ 136 inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier) 137 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 138 139 140 /** @brief Returns true if the objects class is of the given type or a derivative. */ 141 inline bool isA(const OrxonoxClass* object) 142 { return this->getIdentifier()->isA(object->getIdentifier()); } 143 /** @brief Returns true if the objects class is exactly of the given type. */ 144 inline bool isExactlyA(const OrxonoxClass* object) 145 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 146 /** @brief Returns true if the objects class is a child of the given type. */ 147 inline bool isChildOf(const OrxonoxClass* object) 148 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 149 /** @brief Returns true if the objects class is a direct child of the given type. */ 150 inline bool isDirectChildOf(const OrxonoxClass* object) 151 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 152 /** @brief Returns true if the objects class is a parent of the given type. */ 153 inline bool isParentOf(const OrxonoxClass* object) 154 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 155 /** @brief Returns true if the objects class is a direct child of the given type. */ 156 inline bool isDirectParentOf(const OrxonoxClass* object) 157 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 98 bool isA(const OrxonoxClass* object); 99 bool isExactlyA(const OrxonoxClass* object); 100 bool isChildOf(const OrxonoxClass* object); 101 bool isDirectChildOf(const OrxonoxClass* object); 102 bool isParentOf(const OrxonoxClass* object); 103 bool isDirectParentOf(const OrxonoxClass* object); 158 104 159 105 private: 160 Identifier* identifier_; 106 Identifier* identifier_; //!< The Identifier of the object 161 107 std::set<const Identifier*>* parents_; //!< List of all parents of the object 162 MetaObjectList metaList_;//!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in108 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 163 109 }; 164 110 } -
TabularUnified code/trunk/src/core/OutputHandler.cc ¶
r1062 r1502 35 35 #include "CoreSettings.h" 36 36 #include "ConsoleCommand.h" 37 #include "Shell.h" 37 38 38 39 namespace orxonox 39 40 { 40 ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None)); 41 SetConsoleCommandShortcutGeneric(log, createConsoleCommand(createFunctor(&OutputHandler::log), "log" )); 42 SetConsoleCommandShortcutGeneric(error, createConsoleCommand(createFunctor(&OutputHandler::error), "error" )); 43 SetConsoleCommandShortcutGeneric(warning, createConsoleCommand(createFunctor(&OutputHandler::warning), "warning")); 44 SetConsoleCommandShortcutGeneric(info, createConsoleCommand(createFunctor(&OutputHandler::info), "info" )); 45 SetConsoleCommandShortcutGeneric(debug, createConsoleCommand(createFunctor(&OutputHandler::debug), "debug" )); 41 46 42 47 /** … … 82 87 83 88 /** 89 @brief Returns the Shell's OutputBuffer. This is mere placed here to avoid 90 recompiling the entire project when Shell.h changes. 91 @return The OutputBuffer of the Shell 92 */ 93 OutputBuffer& OutputHandler::getShellOutputBuffer() 94 { 95 return Shell::getInstance().getOutputBuffer(); 96 } 97 98 /** 84 99 @brief Overloaded << operator, redirects the output to the console and the logfile. 85 100 @param sb The streambuffer that should be shown in the console … … 96 111 this->logfile_.flush(); 97 112 } 113 114 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 115 Shell::getInstance().getOutputBuffer() << sb; 98 116 99 117 return *this; … … 116 134 } 117 135 136 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 137 Shell::getInstance().getOutputBuffer() << manipulator; 138 118 139 return *this; 119 140 } … … 134 155 this->logfile_.flush(); 135 156 } 157 158 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 159 Shell::getInstance().getOutputBuffer() << manipulator; 136 160 137 161 return *this; … … 154 178 } 155 179 180 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 181 Shell::getInstance().getOutputBuffer() << manipulator; 182 156 183 return *this; 157 184 } -
TabularUnified code/trunk/src/core/OutputHandler.h ¶
r1064 r1502 44 44 #include <string> 45 45 46 #include "OutputBuffer.h" 47 46 48 namespace orxonox 47 49 { … … 64 66 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 65 67 68 /** @brief Puts an error on the outstream. @param text The text */ 69 static inline std::string error(const std::string& text) 70 { OutputHandler::getOutStream().setOutputLevel(1); OutputHandler::getOutStream().output(text + "\n"); return text; } 71 72 /** @brief Puts a warning on the outstream. @param text The text */ 73 static inline std::string warning(const std::string& text) 74 { OutputHandler::getOutStream().setOutputLevel(2); OutputHandler::getOutStream().output(text + "\n"); return text; } 75 76 /** @brief Puts an info on the outstream. @param text The text */ 77 static inline std::string info(const std::string& text) 78 { OutputHandler::getOutStream().setOutputLevel(3); OutputHandler::getOutStream().output(text + "\n"); return text; } 79 80 /** @brief Puts some debug output on the outstream. @param text The text */ 81 static inline std::string debug(const std::string& text) 82 { OutputHandler::getOutStream().setOutputLevel(4); OutputHandler::getOutStream().output(text + "\n"); return text; } 83 66 84 /** @brief Returns a reference to the logfile. @return The logfile */ 67 85 inline std::ofstream& getLogfile() … … 77 95 78 96 static int getSoftDebugLevel(OutputHandler::OutputDevice device); 97 98 OutputBuffer& getShellOutputBuffer(); 79 99 80 100 template <class T> … … 138 158 } 139 159 160 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 161 OutputHandler::getOutStream().getShellOutputBuffer() << output; 162 140 163 return *this; 141 164 } … … 159 182 } 160 183 184 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel()) 185 OutputHandler::getOutStream().getShellOutputBuffer() << output; 186 161 187 return out; 162 188 } -
TabularUnified code/trunk/src/core/Script.cc ¶
r1153 r1502 67 67 { 68 68 output_ += str; 69 COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 69 // COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 70 COUT(5) << str; 70 71 } 71 72 … … 99 100 100 101 if (luaTags) luaSource_ = replaceLuaTags(levelString); 101 COUT( 4) << "ParsedSourceCode: " << luaSource_ << std::endl;102 COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl; 102 103 } 103 104 … … 127 128 if (error == 0) 128 129 error = lua_pcall(luaState_, 0, 0, 0); 129 if (error != 0) COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl; 130 if (error != 0) 131 { 132 COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl; 133 } 130 134 } 131 135 -
TabularUnified code/trunk/src/core/TclBind.cc ¶
r1214 r1502 33 33 #include "CommandExecutor.h" 34 34 #include "Debug.h" 35 #include "TclThreadManager.h" 35 36 #include "TclBind.h" 37 #include "util/String.h" 36 38 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None)); 41 SetConsoleCommandShortcutGeneric(tcl, createConsoleCommand(createFunctor(&TclBind::tcl), "tcl")); 42 SetConsoleCommandShortcutGeneric(bgerror, createConsoleCommand(createFunctor(&TclBind::bgerror), "bgerror")); 40 43 41 44 TclBind::TclBind() … … 59 62 void TclBind::setDataPath(const std::string& datapath) 60 63 { 61 this->tclLibPath_ = datapath + "/tcl" ;64 this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/"; 62 65 this->bSetTclLibPath_ = true; 63 66 … … 70 73 { 71 74 this->interpreter_ = new Tcl::interpreter(this->tclLibPath_); 72 this->interpreter_->def("puts", TclBind::puts, Tcl::variadic()); 73 this->interpreter_->def("orxonox", TclBind::orxonox, Tcl::variadic()); 74 this->interpreter_->def("execute", TclBind::execute, Tcl::variadic()); 75 this->interpreter_->eval("proc unknown {args} { return [orxonox $args] }"); 76 this->interpreter_->eval("rename exit tclexit; proc exit {} { orxonox exit }"); 75 this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic()); 76 this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic()); 77 this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic()); 78 79 try 80 { 81 this->interpreter_->eval("proc query args { orxonox::query $args }"); 82 this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id $args }"); 83 this->interpreter_->eval("set id 0"); 84 this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }"); 85 this->interpreter_->eval("redef_puts"); 86 } 87 catch (Tcl::tcl_error const &e) 88 { COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl; } 89 catch (std::exception const &e) 90 { COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; } 77 91 } 78 92 } … … 89 103 } 90 104 91 void TclBind::puts(Tcl::object const &args)105 std::string TclBind::tcl_query(Tcl::object const &args) 92 106 { 93 COUT(0) << args.get() << std::endl; 94 } 107 COUT(4) << "Tcl_query: " << args.get() << std::endl; 95 108 96 std::string TclBind::orxonox(Tcl::object const &args) 97 { 98 std::cout << "Tcl_execute: args: " << args.get() << std::endl; 99 std::string command = args.get(); 100 101 if (command.size() >= 2 && command[0] == '{' && command[command.size() - 1] == '}') 102 command = command.substr(1, command.size() - 2); 109 std::string command = stripEnclosingBraces(args.get()); 103 110 104 111 if (!CommandExecutor::execute(command, false)) 112 { 105 113 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 114 } 106 115 107 116 if (CommandExecutor::getLastEvaluation().hasReturnvalue()) … … 111 120 } 112 121 113 void TclBind:: execute(Tcl::object const &args)122 void TclBind::tcl_execute(Tcl::object const &args) 114 123 { 124 COUT(4) << "Tcl_execute: " << args.get() << std::endl; 125 std::string command = stripEnclosingBraces(args.get()); 126 127 if (!CommandExecutor::execute(command, false)) 128 { 129 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 130 } 115 131 } 116 132 117 133 std::string TclBind::tcl(const std::string& tclcode) 118 134 { 119 try135 if (TclBind::getInstance().interpreter_) 120 136 { 121 std::string output = TclBind::getInstance().interpreter_->eval(tclcode); 122 if (output != "") 123 COUT(0) << "tcl> " << output << std::endl; 124 return output; 125 } 126 catch (Tcl::tcl_error const &e) 127 { 128 COUT(1) << "tcl> Error: " << e.what() << std::endl; 129 } 130 catch (std::exception const &e) 131 { 132 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 137 try 138 { 139 std::string output = TclBind::getInstance().interpreter_->eval(tclcode); 140 if (output != "") 141 { 142 COUT(0) << "tcl> " << output << std::endl; 143 } 144 return output; 145 } 146 catch (Tcl::tcl_error const &e) 147 { COUT(1) << "tcl> Error: " << e.what() << std::endl; } 148 catch (std::exception const &e) 149 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 133 150 } 134 151 135 152 return ""; 153 } 154 155 void TclBind::bgerror(std::string error) 156 { 157 COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl; 136 158 } 137 159 … … 144 166 } 145 167 catch (Tcl::tcl_error const &e) 146 { 147 COUT(1) << "Error: " << e.what() << std::endl; 148 } 168 { COUT(1) << "Tcl error: " << e.what() << std::endl; } 149 169 catch (std::exception const &e) 150 { 151 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 152 } 170 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 153 171 154 172 return false; -
TabularUnified code/trunk/src/core/TclBind.h ¶
r1223 r1502 41 41 static TclBind& getInstance(); 42 42 43 static std::string tcl(const std::string& tclcode); 44 static void bgerror(std::string error); 45 43 46 void setDataPath(const std::string& datapath); 47 std::string getTclLibPath() const { return this->tclLibPath_; } 44 48 void createTclInterpreter(); 45 49 void createNewTclInterpreter(); 50 Tcl::interpreter* getTclInterpreter() const { return this->interpreter_; } 46 51 47 static void puts(Tcl::object const &args); 48 static void execute(Tcl::object const &args); 49 static std::string orxonox(Tcl::object const &args); 50 static std::string tcl(const std::string& tclcode); 52 static std::string tcl_query(Tcl::object const &args); 53 static void tcl_execute(Tcl::object const &args); 54 51 55 static bool eval(const std::string& tclcode); 52 56 -
TabularUnified code/trunk/src/core/XMLPort.h ¶
r1209 r1502 78 78 namespace orxonox 79 79 { 80 81 #ifndef _XMLPort_Mode__82 #define _XMLPort_Mode__83 namespace XMLPort84 {85 enum Mode86 {87 LoadObject,88 SaveObject89 };90 }91 #endif92 93 80 // ############################### 94 81 // ### XMLPortParamContainer ### … … 166 153 } 167 154 } 168 catch (ticpp::Exception& ex)155 catch (ticpp::Exception& ex) 169 156 { 170 157 COUT(1) << std::endl; … … 344 331 } 345 332 } 346 catch (ticpp::Exception& ex)333 catch (ticpp::Exception& ex) 347 334 { 348 335 COUT(1) << std::endl; -
TabularUnified code/trunk/src/cpptcl/CppTcl.cc ¶
r1214 r1502 953 953 954 954 { 955 // TODO: why could this probably be necessary? map::find of empty map 956 // shouldn't be a problem. 957 if (callbacks.size() == 0) 958 return; 955 959 callback_map::iterator it = callbacks.find(interp); 956 960 if (it == callbacks.end()) -
TabularUnified code/trunk/src/network/Client.cc ¶
r1360 r1502 85 85 isConnected=false; 86 86 isSynched_=false; 87 gameStateFailure_=false; 87 88 } 88 89 … … 95 96 isConnected=false; 96 97 isSynched_=false; 98 gameStateFailure_=false; 97 99 } 98 100 … … 105 107 isConnected=false; 106 108 isSynched_=false; 109 gameStateFailure_=false; 107 110 } 108 111 … … 120 123 isConnected=client_connection.createConnection(); 121 124 if(isConnected){ 122 COUT(3) << "sending connectrequest" << std::endl;123 if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())124 COUT(1) << "could not create connection" << std::endl;125 // COUT(3) << "sending connectrequest" << std::endl; 126 // if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets()) 127 // COUT(1) << "could not send connection request !!!!!!!!!" << std::endl; 125 128 }else 126 COUT(1) << "could not create connection " << std::endl;129 COUT(1) << "could not create connection laber" << std::endl; 127 130 return isConnected; 128 131 } … … 137 140 } 138 141 139 /** 140 * submits a MouseAction to the server 141 * @param x x Coordinate 142 * @param y y Coordinate 143 * @return true/false 144 */ 145 bool Client::sendMouse(double x, double y){ 146 // generate packet and add it to the queue 147 if(!isConnected) 148 return false; 149 if(!client_connection.addPacket(pck_gen.mousem(x, y))) 150 return false; 151 // send packets 152 return client_connection.sendPackets(); 153 } 154 155 /** 156 * submits a Keystrike to the server 157 * @param key_code code to submit 158 * @return true/false 159 */ 160 bool Client::sendKeyboard(char key_code){ 161 // generate packet and add it to queue 162 if(!isConnected) 163 return false; 164 if(!client_connection.addPacket(pck_gen.keystrike(key_code))) 165 return false; 166 // send packets 167 return client_connection.sendPackets(); 168 } 142 143 144 169 145 170 146 /** … … 177 153 if(!isConnected) 178 154 return false; 179 if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))180 return client_connection.sendPackets();155 return client_connection.addPacket(pck_gen.chatMessage( message.c_str() )); 156 //return client_connection.sendPackets(); 181 157 // send packets 182 158 return false; 183 }184 185 /**186 * Adds a MouseAction to the PacketQueue187 * @param x x Coordinate188 * @param y y Coordinate189 * @return true/false190 */191 bool Client::addMouse(double x, double y){192 // generate packet and add it to the queue193 if(client_connection.addPacket(pck_gen.mousem(x, y)))194 return true;195 else196 return false;197 }198 199 /**200 * Adds a Keystrike to the PacketQueue201 * @param key_code202 * @return true/false203 */204 bool Client::addKeyboard(char key_code){205 // generate packet and add it to queue206 if(client_connection.addPacket(pck_gen.keystrike(key_code)))207 return true;208 else209 return false;210 }211 212 /**213 * Sends out all the packets queued by addXXX214 */215 bool Client::sendPackets(){216 if(!isConnected)217 return false;218 ENetEvent event;219 // send packets220 client_connection.sendPackets(&event);221 if(event.type==ENET_EVENT_TYPE_NONE)222 return true;223 else224 return false;225 159 } 226 160 … … 243 177 } 244 178 } 245 ENet Packet *packet;179 ENetEvent *event; 246 180 // stop if the packet queue is empty 247 181 while(!(client_connection.queueEmpty())){ 248 packet = client_connection.getPacket(); 249 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 250 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 251 } 252 if(!client_connection.sendPackets()) 253 COUT(3) << "Problem sending packets to server" << std::endl; 254 return; 255 } 256 257 void Client::processGamestate( GameStateCompressed *data, int clientID){ 258 int id = data->id; 259 COUT(5) << "received gamestate id: " << data->id << std::endl; 260 if(gamestate.pushGameState(data)){ 182 event = client_connection.getEvent(); 183 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 184 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 185 } 186 int gameStateID = gamestate.processGameState(); 187 if(gameStateID==GAMESTATEID_INITIAL) 188 if(gameStateFailure_){ 189 if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL))) 190 COUT(3) << "could not (negatively) ack gamestate" << std::endl; 191 else 192 COUT(4) << "negatively acked a gamestate" << std::endl; 193 } 194 else 195 gameStateFailure_=true; 196 else if(gameStateID!=0){ 197 // ack gamestate and set synched 261 198 if(!isSynched_) 262 199 isSynched_=true; 263 if(!client_connection.addPacket(pck_gen.acknowledgement(id))) 264 return; 265 // we do this at the end of a tick 266 if(!client_connection.sendPackets()) 267 COUT(2) << "Could not send acknowledgment" << std::endl; 268 } 200 gameStateFailure_=false; 201 if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID))) 202 COUT(3) << "could not ack gamestate" << std::endl; 203 }// otherwise we had no gamestate to load 204 gamestate.cleanup(); 205 /*if(!client_connection.sendPackets()) 206 COUT(3) << "Problem sending packets to server" << std::endl;*/ 207 return; 208 } 209 210 void Client::processGamestate( GameStateCompressed *data, int clientID){ 211 COUT(5) << "received gamestate id: " << data->id << std::endl; 212 gamestate.addGameState(data); 269 213 } 270 214 … … 275 219 id->setNetworkID(clid->clid); 276 220 COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl; 221 COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl; 277 222 delete clid; 278 223 return; -
TabularUnified code/trunk/src/network/Client.h ¶
r1293 r1502 75 75 bool closeConnection(); 76 76 77 bool sendMouse(double x, double y);78 bool sendKeyboard(char key_code);79 77 bool sendChat( std::string message ); 80 81 bool addMouse(double x, double y);82 bool addKeyboard(char key_code);83 84 bool sendPackets();85 78 86 79 int getShipID(){return shipID_;} … … 110 103 int clientID_; // this is the id the server gave to us 111 104 int shipID_; 105 bool gameStateFailure_; 112 106 }; 113 107 -
TabularUnified code/trunk/src/network/ClientConnection.cc ¶
r1293 r1502 50 50 { 51 51 //static boost::thread_group network_threads; 52 53 boost::recursive_mutex ClientConnection::enet_mutex_; 52 54 53 55 ClientConnection::ClientConnection(int port, std::string address) { … … 75 77 76 78 77 ENetPacket *ClientConnection::getPacket(ENetAddress &address) {79 /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) { 78 80 if(!buffer.isEmpty()) { 79 81 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; … … 88 90 ENetAddress address; //sems that address is not needed 89 91 return getPacket(address); 92 }*/ 93 94 ENetEvent *ClientConnection::getEvent(){ 95 if(!buffer.isEmpty()) 96 return buffer.pop(); 97 else 98 return NULL; 90 99 } 91 100 … … 98 107 //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this)); 99 108 // wait 10 seconds for the connection to be established 100 return waitEstablished( 10000);109 return waitEstablished(3000); 101 110 } 102 111 … … 117 126 return false; 118 127 } 128 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 119 129 if(enet_peer_send(server, 0, packet)<0) 120 130 return false; … … 123 133 } 124 134 125 bool ClientConnection::sendPackets( ENetEvent *event) {135 bool ClientConnection::sendPackets() { 126 136 if(server==NULL) 127 137 return false; 128 if(enet_host_service(client, event, NETWORK_SEND_WAIT)>=0){ 129 return true;} 130 else 131 return false; 132 } 133 134 bool ClientConnection::sendPackets() { 135 ENetEvent event; 136 if(server==NULL) 137 return false; 138 if(enet_host_service(client, &event, NETWORK_SEND_WAIT)>=0){ 139 return true;} 140 else 141 return false; 138 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 139 enet_host_flush(client); 140 lock.unlock(); 141 return true; 142 142 } 143 143 144 144 void ClientConnection::receiverThread() { 145 145 // what about some error-handling here ? 146 enet_initialize();147 146 atexit(enet_deinitialize); 148 ENetEvent event; 149 client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 150 if(client==NULL) 147 ENetEvent *event; 148 { 149 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 150 enet_initialize(); 151 client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 152 lock.unlock(); 153 } 154 if(client==NULL) { 155 COUT(2) << "ClientConnection: could not create client host" << std::endl; 151 156 // add some error handling here ========================== 152 157 quit=true; 158 } 153 159 //connect to the server 154 160 if(!establishConnection()){ 161 COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl; 155 162 quit=true; 156 163 return; 157 164 } 165 event = new ENetEvent; 158 166 //main loop 159 167 while(!quit){ 160 168 //std::cout << "connection loop" << std::endl; 161 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){ 162 // we should never reach this point 163 quit=true; 164 // add some error handling here ======================== 169 { 170 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 171 if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){ 172 // we should never reach this point 173 quit=true; 174 continue; 175 // add some error handling here ======================== 176 } 177 lock.unlock(); 165 178 } 166 switch(event .type){179 switch(event->type){ 167 180 // log handling ================ 168 181 case ENET_EVENT_TYPE_CONNECT: 182 break; 169 183 case ENET_EVENT_TYPE_RECEIVE: 170 184 COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl; 171 if ( !processData( &event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;185 if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl; 172 186 COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl; 187 event = new ENetEvent; 173 188 break; 174 189 case ENET_EVENT_TYPE_DISCONNECT: … … 178 193 break; 179 194 case ENET_EVENT_TYPE_NONE: 180 continue; 195 //receiverThread_->yield(); 196 usleep(1000); 197 break; 181 198 } 182 //receiverThread_->yield();183 199 } 184 200 // now disconnect … … 186 202 if(!disconnectConnection()) 187 203 // if disconnecting failed destroy conn. 204 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 188 205 enet_peer_reset(server); 189 206 return; … … 192 209 bool ClientConnection::disconnectConnection() { 193 210 ENetEvent event; 211 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 194 212 enet_peer_disconnect(server, 0); 195 213 while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){ … … 212 230 ENetEvent event; 213 231 // connect to peer (server is type ENetPeer*) 232 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 214 233 server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS); 215 if(server==NULL) 234 if(server==NULL) { 235 COUT(2) << "ClientConnection: server == NULL" << std::endl; 216 236 // error handling 217 237 return false; 238 } 218 239 // handshake 219 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)> 0 && event.type == ENET_EVENT_TYPE_CONNECT){240 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>=0 && event.type == ENET_EVENT_TYPE_CONNECT){ 220 241 established=true; 221 242 return true; 222 243 } 223 else 224 return false; 244 else { 245 COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl; 246 return false; 247 } 225 248 } 226 249 -
TabularUnified code/trunk/src/network/ClientConnection.h ¶
r1293 r1502 54 54 #define NETWORK_PORT 55556 55 55 #define NETWORK_CLIENT_MAX_CONNECTIONS 5 56 #define NETWORK_CLIENT_TIMEOUT 100 57 #define NETWORK_SEND_WAIT 5 56 #define NETWORK_CLIENT_TIMEOUT 1 58 57 #define NETWORK_CLIENT_CHANNELS 2 59 58 … … 63 62 ClientConnection(int port, std::string address); 64 63 ClientConnection(int port, const char* address); 65 ENetPacket *getPacket(ENetAddress &address); // thread1 66 ENetPacket *getPacket(); // thread1 64 //ENetPacket *getPacket(ENetAddress &address); // thread1 65 //ENetPacket *getPacket(); // thread1 66 ENetEvent *getEvent(); 67 67 // check wheter the packet queue is empty 68 68 bool queueEmpty(); … … 75 75 bool sendPackets(); 76 76 // send out all queued packets and save result in event 77 bool sendPackets(ENetEvent *event);77 //bool sendPackets(ENetEvent *event); 78 78 bool waitEstablished(int milisec); 79 79 bool isConnected(){return established;} … … 95 95 ENetPeer *server; 96 96 boost::thread *receiverThread_; 97 98 static boost::recursive_mutex enet_mutex_; 97 99 }; 98 100 -
TabularUnified code/trunk/src/network/ClientInformation.cc ¶
r1360 r1502 45 45 namespace network 46 46 { 47 boost::recursive_mutex ClientInformation::mutex_;48 47 49 48 ClientInformation::ClientInformation() { … … 84 83 85 84 ClientInformation::~ClientInformation() { 86 boost::recursive_mutex::scoped_lock lock(mutex_); 87 if(preve!=0) 88 preve->setNext(this->nexte); 89 if(nexte!=0) 90 nexte->setPrev(this->preve); 85 if(prev()!=0) 86 prev()->setNext(this->next()); 87 if(next()!=0) 88 next()->setPrev(this->prev()); 91 89 } 92 90 93 91 ClientInformation *ClientInformation::next() { 94 boost::recursive_mutex::scoped_lock lock(mutex_);95 92 if(this!=0) 96 93 return this->nexte; … … 99 96 } 100 97 ClientInformation *ClientInformation::prev() { 101 boost::recursive_mutex::scoped_lock lock(mutex_);102 98 if(this!=0) 103 99 return this->preve; … … 107 103 108 104 bool ClientInformation::setPrev(ClientInformation *prev) { 109 boost::recursive_mutex::scoped_lock lock(mutex_);110 105 if(!head_) 111 106 this->preve = prev; … … 116 111 117 112 bool ClientInformation::setNext(ClientInformation *next) { 118 boost::recursive_mutex::scoped_lock lock(mutex_);119 113 this->nexte = next; 120 114 return true; … … 122 116 123 117 ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) { 124 boost::recursive_mutex::scoped_lock lock(mutex_); 125 this->nexte->setPrev(ins); 126 ins->setNext(this->nexte); 118 this->next()->setPrev(ins); 119 ins->setNext(this->next()); 127 120 ins->setPrev(this); 128 121 this->nexte = ins; … … 131 124 132 125 ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){ 133 boost::recursive_mutex::scoped_lock lock(mutex_);134 126 if(!this) 135 127 return NULL; 136 128 this->prev()->setNext(ins); 137 ins->setPrev(this->prev e);129 ins->setPrev(this->prev()); 138 130 this->preve=ins; 139 131 ins->setNext(this); … … 142 134 143 135 void ClientInformation::setID(int clientID){ 144 boost::recursive_mutex::scoped_lock lock(mutex_); 136 if(!this) 137 return; 145 138 clientID_ = clientID; 146 139 } 147 140 148 141 bool ClientInformation::setPeer(ENetPeer *peer){ 149 boost::recursive_mutex::scoped_lock lock(mutex_);150 142 if(!this) 151 143 return false; … … 154 146 } 155 147 156 bool ClientInformation::setGamestateID(int id){ 157 boost::recursive_mutex::scoped_lock lock(mutex_); 148 bool ClientInformation::setGameStateID(int id){ 158 149 if(!this) 159 150 return false; … … 163 154 164 155 bool ClientInformation::setPartialGamestateID(int id){ 165 boost::recursive_mutex::scoped_lock lock(mutex_);166 156 if(!this) 167 157 return false; … … 171 161 172 162 int ClientInformation::getID() { 173 boost::recursive_mutex::scoped_lock lock(mutex_);174 163 if(!this) 175 164 return CLIENTID_UNKNOWN; … … 179 168 180 169 ENetPeer *ClientInformation::getPeer() { 181 boost::recursive_mutex::scoped_lock lock(mutex_);182 170 if(this) 183 171 return peer_; … … 187 175 188 176 bool ClientInformation::getHead(){ 189 boost::recursive_mutex::scoped_lock lock(mutex_);190 177 return head_; 191 178 } 192 179 193 180 void ClientInformation::setHead(bool h){ 194 boost::recursive_mutex::scoped_lock lock(mutex_);195 181 head_=h; 196 182 } 197 183 198 184 int ClientInformation::getFailures(){ 199 boost::recursive_mutex::scoped_lock lock(mutex_);200 185 return failures_; 201 186 } 202 187 void ClientInformation::addFailure(){ 203 boost::recursive_mutex::scoped_lock lock(mutex_);204 188 failures_++; 205 189 } 206 190 void ClientInformation::resetFailures(){ 207 boost::recursive_mutex::scoped_lock lock(mutex_);208 191 failures_=0; 209 192 } 210 193 211 194 int ClientInformation::getGamestateID() { 212 boost::recursive_mutex::scoped_lock lock(mutex_);213 195 if(this) 214 196 return gamestateID_; … … 218 200 219 201 int ClientInformation::getPartialGamestateID() { 220 boost::recursive_mutex::scoped_lock lock(mutex_);221 202 if(this) 222 203 return partialGamestateID_; … … 226 207 227 208 ClientInformation *ClientInformation::insertBack(ClientInformation *ins) { 228 boost::recursive_mutex::scoped_lock lock(mutex_);229 209 if(!this) 230 210 return NULL; … … 239 219 240 220 bool ClientInformation::removeClient(int clientID) { 241 boost::recursive_mutex::scoped_lock lock(mutex_);242 221 if(!this || clientID==CLIENTID_UNKNOWN) 243 222 return false; … … 252 231 253 232 bool ClientInformation::removeClient(ENetPeer *peer) { 254 boost::recursive_mutex::scoped_lock lock(mutex_);255 233 if(!this || !peer) 256 234 return false; … … 275 253 */ 276 254 ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) { 277 boost::recursive_mutex::scoped_lock lock(mutex_);278 255 ClientInformation *temp = this; 279 256 if (temp->head_) … … 293 270 */ 294 271 ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) { 295 boost::recursive_mutex::scoped_lock lock(mutex_);296 272 ClientInformation *temp = this; 297 273 while(temp!=0){ … … 309 285 310 286 bool ClientInformation::setSynched(bool s) { 311 boost::recursive_mutex::scoped_lock lock(mutex_);312 287 if(!this) 313 288 return false; … … 317 292 318 293 bool ClientInformation::getSynched() { 319 boost::recursive_mutex::scoped_lock lock(mutex_);320 294 if(this) 321 295 return synched_; -
TabularUnified code/trunk/src/network/ClientInformation.h ¶
r1360 r1502 49 49 #define CLIENTID_UNKNOWN -2 50 50 51 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE 52 51 53 namespace network 52 54 { … … 69 71 void setID(int clientID); 70 72 bool setPeer(ENetPeer *peer); 71 bool setGame stateID(int id);73 bool setGameStateID(int id); 72 74 bool setPartialGamestateID(int id); 73 75 inline void setShipID(int id){ShipID_=id;} … … 114 116 bool head_; 115 117 unsigned short failures_; 116 static boost::recursive_mutex mutex_;117 118 118 119 }; -
TabularUnified code/trunk/src/network/ConnectionManager.cc ¶
r1360 r1502 44 44 #include "core/CoreIncludes.h" 45 45 #include "core/BaseObject.h" 46 #include "objects/SpaceShip.h" 46 47 #include "util/Math.h" 47 #include " objects/SpaceShip.h"48 #include "util/Sleep.h" 48 49 #include "ClientInformation.h" 49 50 #include "ConnectionManager.h" … … 65 66 66 67 ConnectionManager::ConnectionManager():receiverThread_(0){} 68 boost::recursive_mutex ConnectionManager::enet_mutex_; 67 69 68 70 ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { … … 72 74 head_ = head; 73 75 } 76 77 ConnectionManager::ConnectionManager(ClientInformation *head, int port){ 78 quit=false; 79 bindAddress.host = ENET_HOST_ANY; 80 bindAddress.port = port; 81 head_ = head; 82 } 74 83 75 84 ConnectionManager::ConnectionManager(int port, std::string address, ClientInformation *head) :receiverThread_(0) { … … 87 96 } 88 97 89 ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {98 /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) { 90 99 if(!buffer.isEmpty()) 91 100 return buffer.pop(address); 92 101 else 93 102 return NULL; 94 } 103 }*/ 95 104 /** 96 105 This function only pops the first element in PacketBuffer (first in first out) 97 106 used by processQueue in Server.cc 98 107 */ 99 ENetPacket *ConnectionManager::getPacket(int &clientID) {108 /*ENetPacket *ConnectionManager::getPacket(int &clientID) { 100 109 ENetAddress address; 101 110 ENetPacket *packet=getPacket(address); … … 105 114 clientID=temp->getID(); 106 115 return packet; 116 }*/ 117 118 ENetEvent *ConnectionManager::getEvent(){ 119 if(!buffer.isEmpty()) 120 return buffer.pop(); 121 else 122 return NULL; 107 123 } 108 124 … … 129 145 if(!temp) 130 146 return false; 147 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 131 148 if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0) 132 149 return false; … … 136 153 bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) { 137 154 ClientInformation *temp = head_->findClient(clientID); 138 if(!temp) 139 return false; 140 if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0) 141 return false; 155 if(!temp){ 156 COUT(3) << "C.Man: addPacket findClient failed" << std::endl; 157 return false; 158 } 159 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 160 if(enet_peer_send(temp->getPeer(), 0, packet)!=0){ 161 COUT(3) << "C.Man: addPacket enet_peer_send failed" << std::endl; 162 return false; 163 } 142 164 return true; 143 165 } 144 166 145 167 bool ConnectionManager::addPacketAll(ENetPacket *packet) { 168 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 146 169 for(ClientInformation *i=head_->next(); i!=0; i=i->next()){ 147 170 if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0) … … 151 174 } 152 175 153 bool ConnectionManager::sendPackets(ENetEvent *event) { 176 // we actually dont need that function, because host_service does that for us 177 bool ConnectionManager::sendPackets() { 154 178 if(server==NULL) 155 179 return false; 156 if(enet_host_service(server, event, NETWORK_SEND_WAIT)>=0) 157 return true; 158 else 159 return false; 160 } 161 162 bool ConnectionManager::sendPackets() { 163 ENetEvent event; 164 if(server==NULL) 165 return false; 166 if(enet_host_service(server, &event, NETWORK_SEND_WAIT)>=0) 167 return true; 168 else 169 return false; 180 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 181 enet_host_flush(server); 182 lock.unlock(); 183 return true; 170 184 } 171 185 172 186 void ConnectionManager::receiverThread() { 173 187 // what about some error-handling here ? 174 enet_initialize();188 ENetEvent *event; 175 189 atexit(enet_deinitialize); 176 ENetEvent *event = new ENetEvent; 177 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 190 { //scope of the mutex 191 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 192 enet_initialize(); 193 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 194 lock.unlock(); 195 } 178 196 if(server==NULL){ 179 197 // add some error handling here ========================== … … 182 200 } 183 201 202 event = new ENetEvent; 184 203 while(!quit){ 185 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 186 // we should never reach this point 187 quit=true; 188 // add some error handling here ======================== 204 { //mutex scope 205 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 206 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 207 // we should never reach this point 208 quit=true; 209 continue; 210 // add some error handling here ======================== 211 } 212 lock.unlock(); 189 213 } 190 214 switch(event->type){ 191 215 // log handling ================ 192 216 case ENET_EVENT_TYPE_CONNECT: 193 addClient(event); 217 COUT(3) << "adding event_type_connect to queue" << std::endl; 218 case ENET_EVENT_TYPE_DISCONNECT: 219 //addClient(event); 194 220 //this is a workaround to ensure thread safety 195 COUT(5) << "Con.Man: connection event has occured" << std::endl;196 break;221 //COUT(5) << "Con.Man: connection event has occured" << std::endl; 222 //break; 197 223 case ENET_EVENT_TYPE_RECEIVE: 198 224 //std::cout << "received data" << std::endl; 199 225 COUT(5) << "Con.Man: receive event has occured" << std::endl; 200 226 // only add, if client has connected yet and not been disconnected 201 if(head_->findClient(&event->peer->address))227 //if(head_->findClient(&event->peer->address)) 202 228 processData(event); 203 else 204 COUT(3) << "received a packet from a client we don't know" << std::endl; 229 event = new ENetEvent; 230 // else 231 // COUT(3) << "received a packet from a client we don't know" << std::endl; 205 232 break; 206 case ENET_EVENT_TYPE_DISCONNECT: 207 clientDisconnect(event->peer); 233 //case ENET_EVENT_TYPE_DISCONNECT: 234 //clientDisconnect(event->peer); 235 //break; 236 case ENET_EVENT_TYPE_NONE: 237 //receiverThread_->yield(); 238 usleep(1000); 208 239 break; 209 case ENET_EVENT_TYPE_NONE:210 receiverThread_->yield();211 break;212 240 } 213 241 // usleep(100); 214 receiverThread_->yield(); //TODO: find apropriate242 //receiverThread_->yield(); //TODO: find apropriate 215 243 } 216 244 disconnectClients(); 217 245 // if we're finishied, destroy server 218 enet_host_destroy(server); 246 { 247 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 248 enet_host_destroy(server); 249 lock.unlock(); 250 } 219 251 } 220 252 … … 226 258 ClientInformation *temp = head_->next(); 227 259 while(temp!=0){ 228 enet_peer_disconnect(temp->getPeer(), 0); 260 { 261 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 262 enet_peer_disconnect(temp->getPeer(), 0); 263 lock.unlock(); 264 } 229 265 temp = temp->next(); 230 266 } 231 267 //bugfix: might be the reason why server crashes when clients disconnects 232 //temp = temp->next();233 268 temp = head_->next(); 234 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){ 269 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 270 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){ 235 271 switch (event.type) 236 272 { … … 258 294 } 259 295 260 bool ConnectionManager::clientDisconnect(ENetPeer *peer) { 261 COUT(4) << "removing client from list" << std::endl; 262 return removeClient(head_->findClient(&(peer->address))->getID()); 263 } 264 /** 265 This function adds a client that connects to the clientlist of the server 266 NOTE: if you change this, don't forget to change the test function 267 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid 268 */ 269 bool ConnectionManager::addClient(ENetEvent *event) { 270 ClientInformation *temp = head_->insertBack(new ClientInformation); 271 if(!temp){ 272 COUT(2) << "Conn.Man. could not add client" << std::endl; 273 return false; 274 } 275 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 276 temp->prev()->setID(0); //bugfix: not necessary but usefull 277 temp->setID(1); 278 } 279 else 280 temp->setID(temp->prev()->getID()+1); 281 temp->setPeer(event->peer); 282 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 283 return true; 284 } 296 285 297 286 298 int ConnectionManager::getClientID(ENetPeer peer) { … … 316 328 ++it; 317 329 } 318 sendPackets();330 //sendPackets(); 319 331 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; 320 332 } 321 333 322 bool ConnectionManager::createClient(int clientID){ 323 ClientInformation *temp = head_->findClient(clientID); 324 if(!temp){ 325 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 326 return false; 327 } 328 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 329 syncClassid(temp->getID()); 330 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 331 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 332 if(!createShip(temp)) 333 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 334 else 335 COUT(3) << "created spaceship" << std::endl; 336 temp->setSynched(true); 337 COUT(3) << "sending welcome" << std::endl; 338 sendWelcome(temp->getID(), temp->getShipID(), true); 339 return true; 340 } 341 342 bool ConnectionManager::removeClient(int clientID){ 343 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 344 ClientInformation *client = head_->findClient(clientID); 345 if(!client) 346 return false; 347 while(it){ 348 if(it->objectID!=client->getShipID()){ 349 ++it; 350 continue; 351 } 352 orxonox::Iterator<orxonox::SpaceShip> temp=it; 353 ++it; 354 delete *temp; 355 return head_->removeClient(clientID); 356 } 357 return false; 358 } 359 360 bool ConnectionManager::createShip(ClientInformation *client){ 361 if(!client) 362 return false; 363 orxonox::Identifier* id = ID("SpaceShip"); 364 if(!id){ 365 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; 366 return false; 367 } 368 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 369 no->setPosition(orxonox::Vector3(0,80,0)); 370 no->setScale(10); 371 no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0)); 372 no->setMesh("assff.mesh"); 373 no->setMaxSpeed(500); 374 no->setMaxSideAndBackSpeed(50); 375 no->setMaxRotation(1.0); 376 no->setTransAcc(200); 377 no->setRotAcc(3.0); 378 no->setTransDamp(75); 379 no->setRotDamp(1.0); 380 no->setCamera("cam_"+client->getID()); 381 no->classID = id->getNetworkID(); 382 no->create(); 383 384 client->setShipID(no->objectID); 385 return true; 386 } 334 387 335 388 336 bool ConnectionManager::removeShip(ClientInformation *client){ … … 399 347 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 400 348 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ 401 sendPackets();349 //sendPackets(); 402 350 return true; 403 351 }else … … 406 354 407 355 void ConnectionManager::disconnectClient(ClientInformation *client){ 408 enet_peer_disconnect(client->getPeer(), 0); 356 { 357 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 358 enet_peer_disconnect(client->getPeer(), 0); 359 lock.unlock(); 360 } 409 361 removeShip(client); 410 362 } … … 418 370 419 371 420 // int ConnectionManager::getNumberOfClients() { 421 // 422 // return clientsShip.size(); 423 // } 424 425 /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) { 426 COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl; 427 clientsShip.insert( std::make_pair( clientID, objectID ) ); 372 428 373 } 429 430 int ConnectionManager::getClientsShipID( int clientID ) {431 return clientsShip[clientID];432 }433 434 int ConnectionManager::getObjectsClientID( int objectID ) {435 std::map<int, int>::iterator iter;436 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {437 if( iter->second == objectID ) return iter->first;438 }439 return -99;440 }441 442 void ConnectionManager::deleteClientIDReg( int clientID ) {443 clientsShip.erase( clientID );444 }445 446 void ConnectionManager::deleteObjectIDReg( int objectID ) {447 std::map<int, int>::iterator iter = clientsShip.begin();448 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {449 if( iter->second == objectID ) break;450 }451 clientsShip.erase( iter->first );452 }*/453 } -
TabularUnified code/trunk/src/network/ConnectionManager.h ¶
r1293 r1502 48 48 #include <enet/enet.h> 49 49 #include <boost/thread/thread.hpp> 50 #include <boost/thread/recursive_mutex.hpp> 50 51 51 52 #include "PacketBuffer.h" … … 61 62 #define NETWORK_PORT 55556 62 63 #define NETWORK_MAX_CONNECTIONS 50 63 #define NETWORK_WAIT_TIMEOUT 5000 64 #define NETWORK_SEND_WAIT 5 64 #define NETWORK_WAIT_TIMEOUT 1 65 65 66 66 struct ClientList{ … … 74 74 ConnectionManager(); 75 75 ConnectionManager(ClientInformation *head); 76 ConnectionManager(ClientInformation *head, int port); 76 77 ConnectionManager(int port, const char *address, ClientInformation *head); 77 78 ConnectionManager(int port, std::string address, ClientInformation *head); 78 ENetPacket *getPacket(ENetAddress &address); // thread1 79 ENetPacket *getPacket(int &clientID); 79 //ENetPacket *getPacket(ENetAddress &address); // thread1 80 //ENetPacket *getPacket(int &clientID); 81 ENetEvent *getEvent(); 80 82 bool queueEmpty(); 81 83 void createListener(); … … 84 86 bool addPacket(ENetPacket *packet, int ID); 85 87 bool addPacketAll(ENetPacket *packet); 86 bool sendPackets(ENetEvent *event);88 // bool sendPackets(ENetEvent *event); 87 89 bool sendPackets(); 88 bool createClient(int clientID);90 //bool createClient(int clientID); 89 91 void disconnectClient(ClientInformation *client); 92 void syncClassid(int clientID); 93 bool sendWelcome(int clientID, int shipID, bool allowed); 90 94 91 95 private: 92 bool clientDisconnect(ENetPeer *peer);93 bool removeClient(int clientID);96 // bool clientDisconnect(ENetPeer *peer); 97 // bool removeClient(int clientID); 94 98 bool processData(ENetEvent *event); 95 bool addClient(ENetEvent *event);99 //bool addClient(ENetEvent *event); 96 100 void receiverThread(); 97 101 void disconnectClients(); 98 102 int getClientID(ENetPeer peer); 99 103 int getClientID(ENetAddress address); 100 void syncClassid(int clientID);101 104 ENetPeer *getClientPeer(int clientID); 102 bool createShip(ClientInformation *client);105 //bool createShip(ClientInformation *client); 103 106 bool removeShip(ClientInformation *client); 104 bool sendWelcome(int clientID, int shipID, bool allowed);105 107 bool addFakeConnectRequest(ENetEvent *ev); 106 108 PacketBuffer buffer; … … 114 116 115 117 boost::thread *receiverThread_; 118 static boost::recursive_mutex enet_mutex_; 116 119 // int getNumberOfClients(); 117 120 //functions to map what object every clients uses -
TabularUnified code/trunk/src/network/GameStateClient.cc ¶
r1360 r1502 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 35 35 #include "Synchronisable.h" 36 36 37 #define GAMESTATEID_INITIAL -138 37 39 38 namespace network … … 43 42 int id; 44 43 }; 45 44 46 45 GameStateClient::GameStateClient() { 47 46 COUT(5) << "this: " << this << std::endl; 48 47 last_diff_=0; 49 48 last_gamestate_=GAMESTATEID_INITIAL-1; 49 tempGameState_=NULL; 50 myShip_=NULL; 50 51 } 51 52 … … 95 96 return false; 96 97 } 97 98 98 99 GameStateCompressed *GameStateClient::popPartialGameState(){ 99 100 GameState *gs = getPartialSnapshot(); 101 if(!gs) 102 return NULL; 100 103 GameStateCompressed *cgs = compress_(gs); 101 104 delete[] gs->data; … … 103 106 return cgs; 104 107 } 105 108 109 void GameStateClient::addGameState(GameStateCompressed *gs){ 110 if(tempGameState_!=NULL){ 111 //delete the obsolete gamestate 112 if(tempGameState_->id>gs->id) 113 return; 114 delete[] tempGameState_->data; 115 delete tempGameState_; 116 } 117 tempGameState_=gs; 118 } 119 int GameStateClient::processGameState(){ 120 if(tempGameState_==NULL) 121 return 0; 122 int id=tempGameState_->id; 123 bool b = saveShipCache(); 124 if(pushGameState(tempGameState_)){ 125 if(b) 126 loadShipCache(); 127 return id; 128 } 129 else 130 return GAMESTATEID_INITIAL; 131 } 132 106 133 107 134 /** … … 151 178 orxonox::Identifier* id = ID((unsigned int)sync.classID); 152 179 if(!id){ 153 COUT( 4) << "We could not identify a new object; classid: " << sync.classID<< std::endl;154 return false; 180 COUT(3) << "We could not identify a new object; classid: " << sync.classID << " uint: " << (unsigned int)sync.classID << " objectID: " << sync.objectID << " size: " << sync.length << std::endl; 181 return false; // most probably the gamestate is corrupted 155 182 } 156 183 Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate()); … … 168 195 } 169 196 if( !no->create() ) 197 { 170 198 COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl; 199 } 171 200 it=orxonox::ObjectList<Synchronisable>::end(); 172 201 } … … 174 203 // we have our object 175 204 if(! it->updateData(sync)) 205 { 176 206 COUT(1) << "We couldn't update objectID: " \ 177 207 << sync.objectID << "; classID: " << sync.classID << std::endl; 208 } 178 209 } 179 210 ++it; … … 213 244 } 214 245 //retval->data = (unsigned char*)malloc(size); 246 if(size==0) 247 return NULL; 215 248 retval->data = new unsigned char[size]; 216 249 if(!retval->data){ … … 245 278 return retval; 246 279 } 247 248 280 281 249 282 GameState *GameStateClient::undiff(GameState *old, GameState *diff) { 250 283 if(!old || !diff) … … 253 286 int of=0; // pointers offset 254 287 int dest_length=0; 255 if(old->size>=diff->size)288 /*if(old->size>=diff->size) 256 289 dest_length=old->size; 257 else 290 else*/ 258 291 dest_length=diff->size; 259 292 // unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char)); 293 if(dest_length==0) 294 return NULL; 260 295 unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)]; 261 296 while(of<old->size && of<diff->size){ … … 270 305 of++; 271 306 } 272 } else{307 } /*else{ 273 308 while(of<dest_length){ 274 309 *(dp+of)=*(ap+of)^n; 275 310 of++; 276 311 } 277 } 312 }*/ 278 313 } 279 314 // should be finished now … … 297 332 298 333 uLongf buffer = (uLongf)((a->size + 12)*1.01)+1; 334 if(buffer==0) 335 return NULL; 299 336 unsigned char *dest = new unsigned char[buffer]; 300 337 int retval; … … 303 340 switch ( retval ) { 304 341 case Z_OK: COUT(5) << "G.St.Cl: compress: successfully compressed" << std::endl; break; 305 case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 342 case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 306 343 return NULL; 307 344 case Z_BUF_ERROR: COUT(2) << "G.St.Cl: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 321 358 return compressedGamestate; 322 359 } 323 324 360 361 325 362 GameState *GameStateClient::decompress(GameStateCompressed *a) { 326 363 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; … … 333 370 bufsize = normsize; 334 371 // unsigned char* dest = (unsigned char*)malloc( bufsize ); 372 if(bufsize==0) 373 return NULL; 335 374 unsigned char *dest = new unsigned char[bufsize]; 336 375 int retval; … … 376 415 return t; 377 416 } 378 417 379 418 void GameStateClient::cleanup(){ 380 419 std::map<int, GameState*>::iterator temp, it = gameStateMap.begin(); … … 388 427 gameStateMap.erase(temp); 389 428 } 429 tempGameState_=NULL; 390 430 } 391 431 … … 397 437 } 398 438 COUT(4) << std::endl; 399 400 } 401 402 439 440 } 441 442 bool GameStateClient::saveShipCache(){ 443 if(myShip_==NULL) 444 myShip_ = orxonox::SpaceShip::getLocalShip(); 445 if(myShip_){ 446 // unsigned char *data = new unsigned char[myShip_->getSize()]; 447 int size=myShip_->getSize(0x3); 448 if(size==0) 449 return false; 450 unsigned char *data = new unsigned char [size]; 451 shipCache_ = myShip_->getData(data, 0x1); 452 return true; 453 }else 454 return false; 455 } 456 457 bool GameStateClient::loadShipCache(){ 458 if(myShip_){ 459 myShip_->updateData(shipCache_, 0x2); 460 if(shipCache_.data){ 461 delete[] shipCache_.data; 462 } 463 return true; 464 }else 465 return false; 466 } 467 403 468 //##### ADDED FOR TESTING PURPOSE ##### 404 469 GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) { 405 470 return decompress( gc ); 406 471 } 407 472 408 473 GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) { 409 474 return undiff( g_old, g_diffed ); 410 475 } 411 476 //##### ADDED FOR TESTING PURPOSE ##### 412 413 477 478 414 479 } 415 480 -
TabularUnified code/trunk/src/network/GameStateClient.h ¶
r1360 r1502 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 33 33 // 34 34 // 35 // Author: <>, (C) 200735 // Author: Oliver Scheuss, (C) 2007 36 36 // 37 37 // Copyright: See COPYING file that comes with this distribution … … 46 46 #include "core/CorePrereqs.h" 47 47 #include "PacketTypes.h" 48 #include "objects/SpaceShip.h" 48 49 50 51 #define GAMESTATEID_INITIAL -1 49 52 50 53 namespace network … … 56 59 ~GameStateClient(); 57 60 61 void addGameState(GameStateCompressed *gs); 62 int processGameState(); 63 GameStateCompressed *popPartialGameState(); 64 void cleanup(); 65 private: 58 66 bool pushGameState(GameStateCompressed *compstate); 59 GameStateCompressed *popPartialGameState();60 private:61 67 bool loadSnapshot(GameState *state); 62 68 GameState *getPartialSnapshot(); 63 void cleanup();64 69 GameState *undiff(GameState *old, GameState *diff); 65 70 GameStateCompressed *compress_(GameState *a); … … 69 74 void removeObject(orxonox::Iterator<Synchronisable> &it); 70 75 void printGameStateMap(); 76 bool saveShipCache(); 77 bool loadShipCache(); 71 78 72 79 int last_diff_; 73 80 int last_gamestate_; 74 81 std::map<int, GameState *> gameStateMap; 82 GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue 83 orxonox::SpaceShip *myShip_; 84 syncData shipCache_; 75 85 76 86 -
TabularUnified code/trunk/src/network/GameStateManager.cc ¶
r1360 r1502 68 68 printGameStates(); 69 69 return; 70 } 71 72 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 73 if(!gs) 74 return; 75 std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID); 76 if(it!=gameStateQueue.end()){ 77 // delete obsolete gamestate 78 delete[] it->second->data; 79 delete it->second; 80 } 81 gameStateQueue[clientID] = gs; 82 return; 83 } 84 85 void GameStateManager::processGameStates(){ 86 std::map<int, GameStateCompressed*>::iterator it; 87 // now push only the most recent gamestates we received (ignore obsolete ones) 88 for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){ 89 pushGameState(it->second, it->first); 90 } 91 // now clear the queue 92 gameStateQueue.clear(); 70 93 } 71 94 … … 117 140 client = it->second; 118 141 GameState *server = reference; 119 COUT( 3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap<< std::endl;142 COUT(4) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl; 120 143 if(client) 121 144 return encode(client, server); … … 170 193 } 171 194 //retval->data = (unsigned char*)malloc(size); 195 if(size==0) 196 return NULL; 172 197 retval->data = new unsigned char[size]; 173 198 if(!retval->data){ … … 237 262 data+=sizeof(int); 238 263 sync.classID = *(int*)data; 264 if(sync.classID == 0) // TODO: remove this 265 COUT(3) << "received a classid 0" << std::endl; 239 266 data+=sizeof(int); 240 267 sync.data = data; … … 246 273 247 274 if(!it){ 248 // the object does not exist yet275 // the objectaber ich glaub die does not exist yet 249 276 COUT(4) << "loadsnapshot: creating new object " << std::endl; 250 277 //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; … … 314 341 } 315 342 316 GameState *GameStateManager::diff(GameState *a , GameState *b) {317 unsigned char *ap = a ->data, *bp = b->data;343 GameState *GameStateManager::diff(GameState *alt, GameState *neu) { 344 unsigned char *ap = alt->data, *bp = neu->data; 318 345 int of=0; // pointers offset 319 346 int dest_length=0; 320 if(a->size>=b->size) 321 dest_length=a->size; 322 else 323 dest_length=b->size; 347 /*if(alt->size>neu->size) 348 dest_length=alt->size; 349 else*/ 350 dest_length=neu->size; 351 if(dest_length==0) 352 return NULL; 324 353 //unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char)); 325 354 unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)]; 326 while(of<a ->size && of<b->size){355 while(of<alt->size && of<neu->size){ 327 356 *(dp+of)=*(ap+of)^*(bp+of); // do the xor 328 357 ++of; 329 358 } 330 if(a ->size!=b->size){ // do we have to fill up ?359 if(alt->size!=neu->size){ // do we have to fill up ? 331 360 unsigned char n=0; 332 if(a ->size<b->size){361 if(alt->size<neu->size){ 333 362 while(of<dest_length){ 334 363 *(dp+of)=n^*(bp+of); 335 364 of++; 336 365 } 337 } else{366 } /*else{ 338 367 while(of<dest_length){ 339 368 *(dp+of)=*(ap+of)^n; 340 369 of++; 341 370 } 342 } 371 }*/ 343 372 } 344 373 345 374 GameState *r = new GameState; 346 r->id = b->id;375 r->id = neu->id; 347 376 r->size = dest_length; 348 377 r->diffed = true; 349 r->base_id = a ->id;378 r->base_id = alt->id; 350 379 r->data = dp; 351 380 r->complete = true; … … 362 391 //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl; 363 392 //unsigned char* dest = (unsigned char*)malloc( buffer ); 393 if(buffer==0) 394 return NULL; 364 395 unsigned char *dest = new unsigned char[buffer]; 365 396 //COUT(4) << "dest: " << dest << std::endl; … … 404 435 bufsize = normsize; 405 436 // unsigned char* dest = (unsigned char*)malloc( bufsize ); 437 if(bufsize==0) 438 return NULL; 406 439 unsigned char *dest = new unsigned char[bufsize]; 407 440 int retval; … … 436 469 return; 437 470 int curid = temp->getGamestateID(); 471 472 if(gamestateID == GAMESTATEID_INITIAL){ 473 temp->setGameStateID(GAMESTATEID_INITIAL); 474 if(curid!=GAMESTATEID_INITIAL) 475 --(gameStateUsed.find(curid)->second); 476 return; 477 } 438 478 if(curid > gamestateID) 439 479 // the network packets got messed up … … 446 486 --(gameStateUsed.find(curid)->second); 447 487 ++(gameStateUsed.find(gamestateID)->second); 448 temp->setGame stateID(gamestateID);488 temp->setGameStateID(gamestateID); 449 489 /* 450 490 GameState *old = clientGameState[clientID]; -
TabularUnified code/trunk/src/network/GameStateManager.h ¶
r1293 r1502 72 72 ~GameStateManager(); 73 73 74 void addGameState(GameStateCompressed *gs, int clientID); 75 void processGameStates(); 76 74 77 void update(); 75 78 GameStateCompressed *popGameState(int clientID); 76 bool pushGameState(GameStateCompressed *gs, int clientID);77 79 void ackGameState(int clientID, int gamestateID); 78 80 void removeClient(ClientInformation *client); 79 private: 81 private: 82 bool pushGameState(GameStateCompressed *gs, int clientID); 80 83 void cleanup(); // "garbage handler" 81 84 GameState *getSnapshot(); … … 83 86 GameStateCompressed *encode(GameState *a, GameState *b); 84 87 GameStateCompressed *encode(GameState *a); 85 GameState *diff(GameState *a , GameState *b);88 GameState *diff(GameState *alt, GameState *neu); 86 89 GameStateCompressed *compress_(GameState *a); 87 90 GameState *decompress(GameStateCompressed *a); … … 91 94 std::map<int, GameState*> gameStateMap; //map gsID to gamestate* 92 95 std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate 96 std::map<int, GameStateCompressed*> gameStateQueue; 93 97 GameState *reference; 94 98 ClientInformation *head_; -
TabularUnified code/trunk/src/network/NetworkPrereqs.h ¶
r1360 r1502 35 35 #define _NetworkPrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 //----------------------------------------------------------------------- … … 54 54 #else 55 55 # define _NetworkExport 56 #endif57 58 //-----------------------------------------------------------------------59 // fixed width integers60 //-----------------------------------------------------------------------61 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC62 typedef __int8 int8_t;63 typedef __int16 int16_t;64 typedef __int32 int32_t;65 typedef __int64 int64_t;66 typedef unsigned __int8 uint8_t;67 typedef unsigned __int16 uint16_t;68 typedef unsigned __int32 uint32_t;69 typedef unsigned __int64 uint64_t;70 #else71 # include "inttypes.h"72 56 #endif 73 57 -
TabularUnified code/trunk/src/network/PacketBuffer.cc ¶
r1360 r1502 62 62 last->next=NULL; 63 63 // change this!!!!!!! ---- we are not doing stl so we won't change this 64 last->packet = ev->packet; 65 last->address = ev->peer->address; 64 last->event = ev; 66 65 //last->address = ev->peer->address; 67 66 } else { … … 72 71 last->next=NULL; 73 72 // save the packet to the new element 74 last->packet = ev->packet; 75 last->address = ev->peer->address; 73 last->event = ev; 76 74 //last->address = ev->peer->address; 77 75 } … … 82 80 //returns the first element in the list without deleting it but 83 81 //moving first pointer to next element 84 ENetPacket *PacketBuffer::pop() {82 /*ENetPacket *PacketBuffer::pop() { 85 83 ENetAddress address; 86 84 return pop(address); 87 } 88 89 ENet Packet *PacketBuffer::pop(ENetAddress &address){85 }*/ 86 87 ENetEvent *PacketBuffer::pop(){ 90 88 boost::recursive_mutex::scoped_lock lock(mutex_); 91 89 //std::cout << "packetbuffer pop(address)" << std::endl; … … 93 91 QueueItem *temp = first; 94 92 // get packet 95 ENetPacket *pck=first->packet; 96 address = first->address; 93 ENetEvent *ev=first->event; 94 //address = first->address; 95 // remove first element 96 first = first->next; 97 delete temp; 98 lock.unlock(); 99 //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl; 100 return ev; 101 } else{ 102 lock.unlock(); 103 return NULL; 104 } 105 } 106 107 /*ENetPacket *PacketBuffer::pop(ENetAddress &address) { 108 boost::recursive_mutex::scoped_lock lock(mutex_); 109 //std::cout << "packetbuffer pop(address)" << std::endl; 110 if(first!=NULL ){ 111 QueueItem *temp = first; 112 // get packet 113 ENetPacket *pck=first->event->packet; 114 address = first->event->peer->address; 97 115 // remove first element 98 116 first = first->next; … … 105 123 return NULL; 106 124 } 107 } 125 }*/ 108 126 109 127 bool PacketBuffer::isEmpty() { -
TabularUnified code/trunk/src/network/PacketBuffer.h ¶
r1360 r1502 55 55 56 56 struct QueueItem{ 57 ENet Packet *packet;58 ENetAddress address;57 ENetEvent *event; 58 //ENetAddress address; 59 59 QueueItem *next; 60 60 }; … … 68 68 void print(); 69 69 // pops a packet from the queue 70 ENetPacket *pop(); 71 ENetPacket *pop(ENetAddress &address); 70 //ENetPacket *pop(); 71 //ENetPacket *pop(ENetAddress &address); 72 ENetEvent *pop(); 72 73 // pushs a packet to the queue 73 74 bool push(ENetEvent *ev); -
TabularUnified code/trunk/src/network/PacketDecoder.cc ¶
r1360 r1502 68 68 case COMMAND: 69 69 return command( packet, clientId ); 70 case MOUSE:71 mousem( packet, clientId );72 return true;73 case KEYBOARD:74 keystrike( packet, clientId );75 return true;76 70 case CHAT: 77 71 chatMessage( packet, clientId ); … … 90 84 return false; 91 85 } 92 86 93 87 bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){ 94 88 uint32_t submittetcrc; … … 108 102 return false; 109 103 } 110 104 111 105 // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function 112 106 … … 124 118 enet_packet_destroy( packet ); 125 119 } 126 120 127 121 bool PacketDecoder::command( ENetPacket* packet, int clientId ){ 128 122 int length = *(int*)((unsigned char *)packet->data+sizeof(int)); 123 if(length<=0) 124 return false; 129 125 void *data = (void *)new unsigned char[length]; 130 126 memcpy(data, (void *)(packet->data+2*sizeof(int)), length); … … 133 129 } 134 130 135 void PacketDecoder::mousem( ENetPacket* packet, int clientId )136 {137 mouse* mouseMove = new mouse;138 //copy data of packet->data to new struct139 *mouseMove = *(mouse*)packet->data;140 141 //clean memory142 enet_packet_destroy( packet );143 printMouse( mouseMove ); //debug info144 }145 146 void PacketDecoder::keystrike( ENetPacket* packet, int clientId )147 {148 keyboard* key = new keyboard;149 *key = *(keyboard*)packet->data; //see above150 151 //clean memory152 enet_packet_destroy( packet );153 printKey( key ); //debug info154 155 }156 157 131 void PacketDecoder::chatMessage( ENetPacket* packet, int clientId ) 158 132 { 159 133 chat* chatting = new chat; 134 if(packet->dataLength==4) 135 return; 160 136 chatting->id = (int)*packet->data; //first copy id into new struct 161 137 //since the chat message is a char*, allocate the memory needed … … 185 161 return; 186 162 } 187 //since it's not alowed to use void* for pointer arithmetic188 //FIXME: variable never used189 unsigned char* data = (unsigned char *)(packet->data);190 163 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 191 164 memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) ); … … 202 175 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 203 176 if(currentState->compsize==0) 177 { 204 178 COUT(2) << "PacketDecoder: compsize is 0" << std::endl; 179 } 205 180 // currentState->data = (unsigned char*)(malloc( currentState->compsize )); 181 if(currentState->compsize==0) 182 return; 206 183 currentState->data = new unsigned char[currentState->compsize]; 207 184 if(currentState->data==NULL) 185 { 208 186 COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl; 187 } 209 188 //copy the GameStateCompressed data 210 189 memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize ); … … 221 200 cid->id = ((classid *)(packet->data))->id; 222 201 cid->clid = ((classid *)(packet->data))->clid; 202 if(cid->length==0) 203 return; 223 204 // cid->message = (const char *)malloc(cid->length); 224 205 cid->message = new char[cid->length]; … … 229 210 processClassid(cid); 230 211 } 231 232 212 213 233 214 bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){ 234 215 welcome *w = new welcome; … … 240 221 return processWelcome(w); 241 222 } 242 223 243 224 bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){ 244 225 connectRequest *con = new connectRequest; … … 279 260 return; 280 261 } 281 262 282 263 bool PacketDecoder::processWelcome( welcome *w ){ 283 264 delete w; 284 265 return true; 285 266 } 286 267 287 268 bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){ 288 269 COUT(3) << "packetdecoder: processing connectRequest" << std::endl; … … 299 280 } 300 281 301 void PacketDecoder::printMouse( mouse* data )302 {303 COUT(5) << "data id: " << data->id << std::endl;304 COUT(5) << "data: " << data->x << " " << data->y << std::endl;305 }306 307 void PacketDecoder::printKey( keyboard* data )308 {309 COUT(5) << "data id: " << data->id << std::endl;310 COUT(5) << "data: " << (char)data->press << std::endl;311 }312 282 313 283 void PacketDecoder::printChat( chat* data, int clientId ) 314 284 { 315 285 if(clientId!=CLIENTID_CLIENT) 286 { 316 287 COUT(5) << "client: " << clientId << std::endl; 288 } 317 289 COUT(5) << "data id: " << data->id << std::endl; 318 290 COUT(5) << "data: " << data->message << std::endl; -
TabularUnified code/trunk/src/network/PacketGenerator.cc ¶
r1360 r1502 78 78 { 79 79 COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl; 80 ack* ackreq = new ack; 80 81 ENetPacket *packet = enet_packet_create( NULL , sizeof( ack ), reliable ); 82 ack* ackreq = (ack *)packet->data; 81 83 ackreq->id = ACK; 82 84 ackreq->a = state; 83 84 ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable ); 85 delete ackreq; 85 //delete ackreq; 86 86 return packet; 87 87 } … … 89 89 ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE ) 90 90 { 91 if(dataLength==0) 92 return NULL; 91 93 unsigned char *stream = new unsigned char[dataLength + 2*sizeof(int)]; 92 94 if(!stream) … … 101 103 } 102 104 103 /*### mouseupdates */104 ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )105 {106 COUT(4) << "PacketGenerator: generating new mouse" << std::endl;107 mouse* mousemove = new mouse;108 mousemove->id = MOUSE;109 mousemove->x = x;110 mousemove->y = y;111 112 ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );113 delete mousemove;114 return packet;115 }116 117 /*### keystrikes updates */118 ENetPacket* PacketGenerator::keystrike( char press, int reliable )119 {120 COUT(4) << "PacketGenerator: generating new keyboard" << std::endl;121 keyboard* key = new keyboard;122 key->id = KEYBOARD;123 key->press = press;124 125 ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );126 delete key;127 return packet;128 }129 105 130 106 /*### chat messages packet */ … … 150 126 //std::cout << "totalLen " << totalLen << std::endl; 151 127 //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 152 unsigned char *data = new unsigned char[totalLen]; 128 if(totalLen==0) 129 return NULL; 130 ENetPacket *packet = enet_packet_create( NULL , totalLen+sizeof(uint32_t), reliable ); 131 //unsigned char *data = new unsigned char[totalLen]; 132 unsigned char *data = packet->data; 153 133 memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id 154 134 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id … … 163 143 //create an enet packet with the generated bytestream 164 144 COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl; 165 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 166 delete[] data; 145 //delete[] data; 167 146 if(!addCRC(packet)) 168 147 COUT(3) << "could not add crc to gamestate packet" << std::endl; … … 173 152 { 174 153 //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1); 154 if(classname.length()==0) 155 return NULL; 175 156 unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1]; 176 157 std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl; … … 206 187 bool PacketGenerator::addCRC( ENetPacket *packet){ 207 188 unsigned char *data = packet->data; 208 uint32_t crc32=calcCRC(data, packet->dataLength );189 uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t)); 209 190 // now append the crc to the packet data 210 int oldlength = packet->dataLength ;211 if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){191 int oldlength = packet->dataLength-sizeof(uint32_t); 192 //if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){ 212 193 memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t)); 213 194 return true; 214 }else{215 COUT(3) << "could not add crc to gamestate" << std::endl;216 return false;217 }195 //}else{ 196 // COUT(3) << "could not add crc to gamestate" << std::endl; 197 // return false; 198 //} 218 199 } 219 200 -
TabularUnified code/trunk/src/network/PacketManager.h ¶
r1360 r1502 59 59 ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability 60 60 ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE ); 61 ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );62 ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );63 61 ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); 64 62 ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates … … 94 92 void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 95 93 bool command( ENetPacket* packet, int clientId ); 96 void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );97 void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );98 94 void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 99 95 void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); … … 113 109 //print functions 114 110 void printAck( ack* data ); 115 void printMouse( mouse* data );116 void printKey( keyboard* data );117 111 void printChat( chat* data, int clientId ); 118 112 void printGamestate( GameStateCompressed *data ); -
TabularUnified code/trunk/src/network/PacketTypes.h ¶
r1293 r1502 48 48 enum packet_id { 49 49 ACK, 50 MOUSE,51 50 COMMAND, 52 KEYBOARD,53 51 CHAT, 54 52 GAMESTATE , … … 104 102 }; 105 103 106 struct mouse {107 int id;108 double x;109 double y;110 };111 112 struct keyboard {113 int id;114 char press;115 };116 104 //only in this class, not PacketGenerator, used as pattern to put incoming 117 105 //bytes inside -
TabularUnified code/trunk/src/network/Server.cc ¶
r1360 r1502 42 42 43 43 #include <iostream> 44 44 45 45 46 #include "ConnectionManager.h" … … 49 50 //#include "NetworkFrameListener.h" 50 51 #include "util/Sleep.h" 52 #include "objects/SpaceShip.h" 51 53 52 54 … … 56 58 57 59 #define MAX_FAILURES 20; 58 60 #define NETWORK_FREQUENCY 30 59 61 60 62 /** … … 63 65 */ 64 66 Server::Server() { 67 timeSinceLastUpdate_=0; 65 68 packet_gen = PacketGenerator(); 66 69 clients = new ClientInformation(true); … … 68 71 gamestates = new GameStateManager(clients); 69 72 } 73 74 Server::Server(int port){ 75 timeSinceLastUpdate_=0; 76 packet_gen = PacketGenerator(); 77 clients = new ClientInformation(true); 78 connection = new ConnectionManager(clients, port); 79 gamestates = new GameStateManager(clients); 80 } 70 81 71 82 /** … … 75 86 */ 76 87 Server::Server(int port, std::string bindAddress) { 88 timeSinceLastUpdate_=0; 77 89 packet_gen = PacketGenerator(); 78 90 clients = new ClientInformation(); … … 87 99 */ 88 100 Server::Server(int port, const char *bindAddress) { 101 timeSinceLastUpdate_=0; 89 102 packet_gen = PacketGenerator(); 90 103 clients = new ClientInformation(); … … 117 130 ENetPacket *packet = packet_gen.chatMessage(msg.c_str()); 118 131 //std::cout <<"adding packets" << std::endl; 119 if(connection->addPacketAll(packet)) 120 //std::cout <<"added packets" << std::endl; 121 return connection->sendPackets(); 122 else 123 return false; 132 return connection->addPacketAll(packet); 124 133 } 125 134 … … 132 141 ENetPacket *packet = packet_gen.chatMessage(msg); 133 142 COUT(4) <<"Server: adding Packets" << std::endl; 134 connection->addPacketAll(packet); 135 //std::cout <<"added packets" << std::endl; 136 if (connection->sendPackets()){ 137 COUT(4) << "Server: Sucessfully" << std::endl; 138 return true; 139 } 140 return false; 143 return connection->addPacketAll(packet); 141 144 } 142 145 … … 148 151 void Server::tick(float time) { 149 152 processQueue(); 150 updateGamestate(); 151 // usleep(500000); // TODO remove 153 //this steers our network frequency 154 timeSinceLastUpdate_+=time; 155 if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){ 156 timeSinceLastUpdate_-=(1./NETWORK_FREQUENCY); 157 gamestates->processGameStates(); 158 updateGamestate(); 159 } 160 // usleep(5000); // TODO remove 152 161 return; 153 162 } … … 157 166 */ 158 167 void Server::processQueue() { 159 ENet Packet *packet;168 ENetEvent *event; 160 169 int clientID=-1; 161 170 while(!connection->queueEmpty()){ 162 171 //std::cout << "Client " << clientID << " sent: " << std::endl; 163 172 //clientID here is a reference to grab clientID from ClientInformation 164 packet = connection->getPacket(clientID); 165 if(!packet) 166 continue; 173 event = connection->getEvent(); 174 if(!event) 175 continue; 176 assert(event->type != ENET_EVENT_TYPE_NONE); 177 switch( event->type ) { 178 case ENET_EVENT_TYPE_CONNECT: 179 COUT(3) << "processing event_Type_connect" << std::endl; 180 addClient(event); 181 break; 182 case ENET_EVENT_TYPE_DISCONNECT: 183 if(clients->findClient(&event->peer->address)) 184 disconnectClient(event); 185 break; 186 case ENET_EVENT_TYPE_RECEIVE: 187 if(clients->findClient(&event->peer->address)){ 188 clientID = clients->findClient(&event->peer->address)->getID(); 189 if( !elaborate(event->packet, clientID) ) 190 COUT(3) << "Server: could not elaborate" << std::endl; 191 } 192 break; 193 } 194 delete event; 167 195 //if statement to catch case that packetbuffer is empty 168 if( !elaborate(packet, clientID) )169 COUT(3) << "Server: could not elaborate" << std::endl;170 196 } 171 197 } … … 210 236 if(gs==NULL){ 211 237 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 212 return false;238 continue; 213 239 } 214 240 //std::cout << "adding gamestate" << std::endl; 215 if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){ 241 ENetPacket *packet = packet_gen.gstate(gs); 242 if(!packet) 243 continue; 244 if ( !(connection->addPacket(packet, cid)) ){ 216 245 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 217 246 temp->addFailure(); 218 if(temp->getFailures() > 20 )219 disconnectClient(temp); 247 /*if(temp->getFailures() > 0 ) 248 disconnectClient(temp);*/ 220 249 //std::cout << "added gamestate" << std::endl; 221 } 250 }else 251 temp->resetFailures(); 222 252 added=true; 223 253 temp=temp->next(); … … 226 256 delete gs; 227 257 } 228 if(added) {258 /*if(added) { 229 259 //std::cout << "send gamestates from server.cc in sendGameState" << std::endl; 230 260 return connection->sendPackets(); 231 } 232 COUT(5) << "Server: had no gamestates to send" << std::endl;233 return false;261 }*/ 262 //COUT(5) << "Server: had no gamestates to send" << std::endl; 263 return true; 234 264 } 235 265 236 266 void Server::processAck( ack *data, int clientID) { 237 COUT(4) << " \b\b\b\n\n\n\n\nServer: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;267 COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl; 238 268 gamestates->ackGameState(clientID, data->a); 239 269 delete data; … … 241 271 242 272 bool Server::processConnectRequest( connectRequest *con, int clientID ){ 243 COUT(3) << "processing connectRequest " << std::endl;273 //(COUT(3) << "processing connectRequest " << std::endl; 244 274 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 245 connection->createClient(clientID);275 //createClient(clientID); 246 276 delete con; 247 277 return true; … … 250 280 void Server::processGamestate( GameStateCompressed *data, int clientID){ 251 281 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; 252 if(!gamestates->pushGameState(data, clientID))253 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;282 gamestates->addGameState(data, clientID); 283 /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 254 284 else 255 285 if(clients->findClient(clientID)) 256 clients->findClient(clientID)->resetFailures(); 286 clients->findClient(clientID)->resetFailures();*/ 287 } 288 289 bool Server::addClient(ENetEvent *event){ 290 ClientInformation *temp = clients->insertBack(new ClientInformation); 291 if(!temp){ 292 COUT(2) << "Server: could not add client" << std::endl; 293 return false; 294 } 295 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 296 temp->prev()->setID(0); //bugfix: not necessary but usefull 297 temp->setID(1); 298 } 299 else 300 temp->setID(temp->prev()->getID()+1); 301 temp->setPeer(event->peer); 302 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 303 return createClient(temp->getID()); 304 } 305 306 bool Server::createClient(int clientID){ 307 ClientInformation *temp = clients->findClient(clientID); 308 if(!temp){ 309 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 310 return false; 311 } 312 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 313 connection->syncClassid(temp->getID()); 314 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 315 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 316 if(!createShip(temp)) 317 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 318 else 319 COUT(3) << "created spaceship" << std::endl; 320 temp->setSynched(true); 321 COUT(3) << "sending welcome" << std::endl; 322 connection->sendWelcome(temp->getID(), temp->getShipID(), true); 323 return true; 324 } 325 326 bool Server::createShip(ClientInformation *client){ 327 if(!client) 328 return false; 329 orxonox::Identifier* id = ID("SpaceShip"); 330 if(!id){ 331 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; 332 return false; 333 } 334 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 335 no->setPosition(orxonox::Vector3(0,0,80)); 336 no->setScale(10); 337 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0)); 338 no->setMesh("assff.mesh"); 339 no->setMaxSpeed(500); 340 no->setMaxSideAndBackSpeed(50); 341 no->setMaxRotation(1.0); 342 no->setTransAcc(200); 343 no->setRotAcc(3.0); 344 no->setTransDamp(75); 345 no->setRotDamp(1.0); 346 no->setCamera("cam_"+client->getID()); 347 no->classID = id->getNetworkID(); 348 no->create(); 349 350 client->setShipID(no->objectID); 351 return true; 352 } 353 354 bool Server::disconnectClient(ENetEvent *event){ 355 COUT(4) << "removing client from list" << std::endl; 356 //return removeClient(head_->findClient(&(peer->address))->getID()); 357 358 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 359 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 360 ClientInformation *client = clients->findClient(&event->peer->address); 361 if(!client) 362 return false; 363 while(it){ 364 if(it->objectID!=client->getShipID()){ 365 ++it; 366 continue; 367 } 368 orxonox::Iterator<orxonox::SpaceShip> temp=it; 369 ++it; 370 delete *temp; 371 return clients->removeClient(event->peer); 372 } 373 return false; 257 374 } 258 375 -
TabularUnified code/trunk/src/network/Server.h ¶
r1293 r1502 60 60 public: 61 61 Server(); 62 Server(int port); 62 63 Server(int port, std::string bindAddress); 63 64 Server(int port, const char *bindAddress); … … 71 72 void updateGamestate(); 72 73 private: 74 bool addClient(ENetEvent *event); 75 bool createClient(int clientID); 76 bool createShip(ClientInformation *client); 77 bool disconnectClient(ENetEvent *event); 73 78 void disconnectClient(int clientID); 74 79 void disconnectClient( ClientInformation *client); … … 82 87 83 88 ClientInformation *clients; 89 float timeSinceLastUpdate_; 84 90 }; 85 91 -
TabularUnified code/trunk/src/network/Synchronisable.cc ¶
r1360 r1502 66 66 67 67 Synchronisable::~Synchronisable(){ 68 } 69 70 bool Synchronisable::create(){ 71 this->classID = this->getIdentifier()->getNetworkID(); 72 COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 73 return true; 68 74 } 69 75 … … 151 157 * @return data containing all variables and their sizes 152 158 */ 153 syncData Synchronisable::getData(unsigned char *mem ){159 syncData Synchronisable::getData(unsigned char *mem, int mode){ 154 160 //std::cout << "inside getData" << std::endl; 161 if(mode==0x0) 162 mode=state_; 155 163 if(classID==0) 156 164 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; … … 167 175 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 168 176 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 169 if( ((*i)->mode & state_) == 0 ){177 if( ((*i)->mode & mode) == 0 ){ 170 178 COUT(5) << "not getting data: " << std::endl; 171 179 continue; // this variable should only be received … … 194 202 * @return true/false 195 203 */ 196 bool Synchronisable::updateData(syncData vars){ 204 bool Synchronisable::updateData(syncData vars, int mode){ 205 if(mode==0x0) 206 mode=state_; 197 207 unsigned char *data=vars.data; 198 208 std::list<synchronisableVariable *>::iterator i; … … 203 213 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl; 204 214 for(i=syncList->begin(); i!=syncList->end(); i++){ 205 if( ((*i)->mode ^ state_) == 0 ){215 if( ((*i)->mode ^ mode) == 0 ){ 206 216 COUT(5) << "synchronisable: not updating variable " << std::endl; 207 continue; // this variable should only be updated217 continue; // this variable should only be set 208 218 } 209 219 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; … … 230 240 * @return amount of bytes 231 241 */ 232 int Synchronisable::getSize( ){242 int Synchronisable::getSize(int mode){ 233 243 int tsize=0; 244 if(mode==0x0) 245 mode=state_; 234 246 std::list<synchronisableVariable *>::iterator i; 235 247 for(i=syncList->begin(); i!=syncList->end(); i++){ 236 if( ((*i)->mode & state_) == 0 )248 if( ((*i)->mode & mode) == 0 ) 237 249 continue; // this variable should only be received, so dont add its size to the send-size 238 250 switch((*i)->type){ -
TabularUnified code/trunk/src/network/Synchronisable.h ¶
r1293 r1502 83 83 void registerVar(void *var, int size, variableType t, int mode=1); 84 84 // syncData getData(); 85 syncData getData(unsigned char *mem );86 int getSize( );87 bool updateData(syncData vars );85 syncData getData(unsigned char *mem, int mode=0x0); 86 int getSize(int mode=0x0); 87 bool updateData(syncData vars, int mode=0x0); 88 88 void setBacksync(bool sync); 89 89 bool getBacksync(); 90 90 virtual void registerAllVariables()=0; 91 virtual bool create() =0;91 virtual bool create(); 92 92 static void setClient(bool b); 93 93 protected: -
TabularUnified code/trunk/src/network/diffTest.cc ¶
r1360 r1502 549 549 550 550 std::cout << "test setGamestateID" << std::endl; 551 temp->setGame stateID( 8 );551 temp->setGameStateID( 8 ); 552 552 printClientInformationBox( temp ); 553 553 … … 559 559 newInfo->setSynched( true ); 560 560 newInfo->setPeer( NULL ); 561 toool->setGame stateID( 199 );561 toool->setGameStateID( 199 ); 562 562 toool->setID( numberOfClients+1); 563 563 toool->setSynched( true ); -
TabularUnified code/trunk/src/network/dummyclient3.cc ¶
r1293 r1502 51 51 Client client( str, PORT ); 52 52 if ( client.establishConnection() ) 53 { 53 54 COUT(3) << "connection established" << std::endl; 54 else COUT(0) << "problems establishing connection" << std::endl; 55 } 56 else 57 { 58 COUT(0) << "problems establishing connection" << std::endl; 59 } 55 60 char message[10000]; 56 61 char signs[] = "abcdefghijklmnopqrstuvwxy"; -
TabularUnified code/trunk/src/ois/CMakeLists.txt ¶
r1219 r1502 37 37 38 38 ADD_LIBRARY( ois SHARED ${OIS_SRC_FILES} ) 39 40 IF(WIN32) 41 LINK_DIRECTORIES(${DirectX_LIB_DIR}) 42 TARGET_LINK_LIBRARIES( ois 43 dxguid 44 dinput8 45 ) 46 ENDIF(WIN32) 47 -
TabularUnified code/trunk/src/ois/OISException.cpp ¶
r1219 r1502 26 26 27 27 //----------------------------------------------------------------------------// 28 const char* Exception::what() const throw()28 /*const char* Exception::what() const throw() 29 29 { 30 30 return eText; 31 31 } 32 32 */ -
TabularUnified code/trunk/src/ois/OISException.h ¶
r1219 r1502 58 58 : eType(err), eLine(line), eFile(file), eText(str) {} 59 59 60 ~Exception() throw() {} 61 62 virtual const char* what() const throw(); 60 virtual const char* what() const throw() 61 { return eText; } 63 62 64 63 //! The type of exception raised -
TabularUnified code/trunk/src/orxonox/CMakeLists.txt ¶
r1407 r1502 9 9 hud/RadarOverlayElement.cc 10 10 hud/RadarObject.cc 11 hud/Navigation.cc 11 12 particle/ParticleInterface.cc 12 13 tolua/tolua_bind.cc … … 24 25 objects/NPC.cc 25 26 objects/Projectile.cc 27 objects/RotatingProjectile.cc 26 28 objects/Skybox.cc 27 29 objects/SpaceShip.cc 30 objects/SpaceShipAI.cc 28 31 objects/WorldEntity.cc 29 32 -
TabularUnified code/trunk/src/orxonox/GraphicsEngine.cc ¶
r1349 r1502 45 45 #include "core/Debug.h" 46 46 #include "core/CommandExecutor.h" 47 47 #include "core/TclBind.h" 48 #include "console/InGameConsole.h" 49 50 #include "core/ConsoleCommand.h" 51 #include <OgreSceneManager.h> 52 #include <OgreCompositorManager.h> 53 #include <OgreViewport.h> 48 54 49 55 namespace orxonox { 50 51 56 /** 52 57 @brief Returns the singleton instance and creates it the first time. … … 83 88 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 84 89 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 90 91 TclBind::getInstance().setDataPath(this->dataPath_); 85 92 } 86 93 … … 137 144 #endif 138 145 139 /* // create a logManager 146 // TODO: LogManager doesn't work on specific systems. The why is unknown yet. 147 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 148 // create a logManager 140 149 // note: If there's already a logManager, Ogre will complain by a failed assertation. 141 150 // but that shouldn't happen, since this is the first time to create a logManager.. … … 148 157 myLog = logger->createLog("ogre.log", true, false, true); 149 158 else 150 159 myLog = logger->createLog(this->ogreLogfile_, true, false, false); 151 160 CCOUT(4) << "Ogre Log created" << std::endl; 152 161 153 162 myLog->setLogDetail(Ogre::LL_BOREME); 154 myLog->addListener(this);*/ 163 myLog->addListener(this); 164 #endif 155 165 156 166 // Root will detect that we've already created a Log 157 167 CCOUT(4) << "Creating Ogre Root..." << std::endl; 158 root_ = new Ogre::Root(plugin_filename); 168 169 root_ = new Ogre::Root(plugin_filename, "ogre.cfg", this->ogreLogfile_); 170 171 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 172 // tame the ogre ouput so we don't get all the mess in the console 173 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 174 defaultLog->setDebugOutputEnabled(false); 175 defaultLog->setLogDetail(Ogre::LL_BOREME); 176 defaultLog->addListener(this); 177 #endif 178 159 179 CCOUT(4) << "Creating Ogre Root done" << std::endl; 160 180 … … 241 261 bool GraphicsEngine::createNewScene() 242 262 { 243 CCOUT(4) << "Creating new SceneManager " << std::endl;263 CCOUT(4) << "Creating new SceneManager..." << std::endl; 244 264 if (scene_) 245 265 { … … 291 311 else 292 312 return 0; 313 } 314 315 /** 316 @brief Returns the window aspect ratio height/width. 317 @return The ratio 318 */ 319 float GraphicsEngine::getWindowAspectRatio() const 320 { 321 if (this->renderWindow_) 322 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); 323 else 324 return 1.0f; 293 325 } 294 326 … … 345 377 int h = rw->getHeight(); 346 378 InputManager::setWindowExtents(w, h); 379 InGameConsole::getInstance().resize(); 347 380 } 348 381 … … 365 398 CommandExecutor::execute("exit", false); 366 399 } 400 401 //HACK!! 402 /*SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOn).setAccessLevel(AccessLevel::User); 403 SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOn).setAccessLevel(AccessLevel::User); 404 SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOff).setAccessLevel(AccessLevel::User); 405 SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOff).setAccessLevel(AccessLevel::User); 406 void GraphicsEngine::CompositorBloomOn() 407 { 408 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 409 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 410 Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom"); 411 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", true); 412 } 413 void GraphicsEngine::CompositorBloomOff() 414 { 415 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 416 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 417 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", false); 418 } 419 420 void GraphicsEngine::CompositorMotionBlurOn() 421 { 422 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 423 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 424 Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur"); 425 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", true); 426 } 427 void GraphicsEngine::CompositorMotionBlurOff() 428 { 429 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 430 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 431 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", false); 432 }*/ 367 433 } -
TabularUnified code/trunk/src/orxonox/GraphicsEngine.h ¶
r1293 r1502 72 72 int getWindowWidth() const; 73 73 int getWindowHeight() const; 74 float getWindowAspectRatio() const; 75 float getAverageFPS() const 76 { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; } 74 77 75 78 void windowMoved (Ogre::RenderWindow* rw); … … 80 83 static GraphicsEngine& getSingleton(); 81 84 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); } 85 86 //HACK!!! 87 //void static CompositorBloomOn(); 88 //void static CompositorBloomOff(); 89 //void static CompositorMotionBlurOn(); 90 //void static CompositorMotionBlurOff(); 91 82 92 83 93 private: -
TabularUnified code/trunk/src/orxonox/Main.cc ¶
r1293 r1502 36 36 #include <exception> 37 37 38 #include " OrxonoxPlatform.h"38 #include "util/OrxonoxPlatform.h" 39 39 #include "core/SignalHandler.h" 40 40 #include "Orxonox.h" -
TabularUnified code/trunk/src/orxonox/Orxonox.cc ¶
r1407 r1502 51 51 //#include "util/Sleep.h" 52 52 #include "util/ArgReader.h" 53 #include "util/ExprParser.h"54 53 55 54 // core … … 57 56 #include "core/ConsoleCommand.h" 58 57 #include "core/Debug.h" 59 #include "core/Factory.h"60 58 #include "core/Loader.h" 61 59 #include "core/Tickable.h" 62 #include "core/InputBuffer.h"63 60 #include "core/InputManager.h" 64 61 #include "core/TclBind.h" … … 72 69 73 70 // objects and tools 74 #include "tools/Timer.h"75 71 #include "hud/HUD.h" 76 #include "console/InGameConsole.h" 72 #include <Ogre.h> 73 74 #include "GraphicsEngine.h" 77 75 78 76 // FIXME: is this really file scope? … … 83 81 namespace orxonox 84 82 { 85 ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress); 86 ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0) 87 .setAxisParamIndex(0).setIsAxisRelative(false); 88 ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 89 ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None); 90 class Testconsole : public InputBufferListener 91 { 92 public: 93 Testconsole(InputBuffer* ib) : ib_(ib) {} 94 void listen() const 95 { 96 std::cout << "> " << this->ib_->get() << std::endl; 97 } 98 void execute() const 99 { 100 std::cout << ">> " << this->ib_->get() << std::endl; 101 if (!CommandExecutor::execute(this->ib_->get())) 102 std::cout << "Error" << std::endl; 103 this->ib_->clear(); 104 } 105 void hintandcomplete() const 106 { 107 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 108 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 109 } 110 void clear() const 111 { 112 this->ib_->clear(); 113 } 114 void removeLast() const 115 { 116 this->ib_->removeLast(); 117 } 118 void exit() const 119 { 120 InputManager::setInputState(InputManager::IS_NORMAL); 121 } 122 123 private: 124 InputBuffer* ib_; 125 }; 126 127 class Calculator 128 { 129 public: 130 static float calculate(const std::string& calculation) 131 { 132 ExprParser expr(calculation); 133 if (expr.getSuccess()) 134 { 135 if (expr.getResult() == 42.0) 136 std::cout << "Greetings from the restaurant at the end of the universe." << std::endl; 137 // FIXME: insert modifier to display in full precision 138 std::cout << "Result is: " << expr.getResult() << std::endl; 139 if (expr.getRemains() != "") 140 std::cout << "Warning: Expression could not be parsed to the end! Remains: '" 141 << expr.getRemains() << "'" << std::endl; 142 return expr.getResult(); 143 } 144 else 145 { 146 std::cout << "Cannot calculate expression: Parse error" << std::endl; 147 return 0; 148 } 149 } 150 }; 151 ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None); 83 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 84 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 85 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 152 86 153 87 /** … … 165 99 // turn on frame smoothing by setting a value different from 0 166 100 frameSmoothingTime_(0.0f), 167 orxonoxConsole_(0),168 101 orxonoxHUD_(0), 169 102 bAbort_(false), 170 103 timefactor_(1.0f), 171 104 mode_(STANDALONE), 172 serverIp_("") 105 serverIp_(""), 106 serverPort_(NETWORK_PORT) 173 107 { 174 108 } … … 180 114 { 181 115 // keep in mind: the order of deletion is very important! 182 if (this->orxonoxHUD_)183 delete this->orxonoxHUD_;116 // if (this->orxonoxHUD_) 117 // delete this->orxonoxHUD_; 184 118 Loader::close(); 185 119 InputManager::destroy(); … … 244 178 ar.checkArgument("data", dataPath, false); 245 179 ar.checkArgument("ip", serverIp_, false); 180 ar.checkArgument("port", serverPort_, false); 246 181 if(ar.errorHandling()) 247 182 return false; … … 251 186 else if (mode == "server") 252 187 mode_ = SERVER; 188 else if (mode == "dedicated") 189 mode_ = DEDICATED; 253 190 else 254 191 { … … 265 202 // procedure until the GUI is identical 266 203 267 TclBind::getInstance().setDataPath(dataPath);268 204 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 269 205 Factory::createClassHierarchy(); … … 281 217 bool Orxonox::start() 282 218 { 283 //if (mode == DEDICATED) 284 // do something else 285 //else 286 287 if (!ogre_->loadRenderer()) // creates the render window 288 return false; 289 290 // Calls the InputManager which sets up the input devices. 291 // The render window width and height are used to set up the mouse movement. 292 if (!InputManager::initialise(ogre_->getWindowHandle(), 293 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 294 return false; 295 296 // TODO: Spread this so that this call only initialises things needed for the GUI 297 if (!ogre_->initialiseResources()) 298 return false; 299 300 // TOOD: load the GUI here 301 // set InputManager to GUI mode 302 InputManager::setInputState(InputManager::IS_GUI); 303 // TODO: run GUI here 304 305 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 306 307 InputManager::setInputState(InputManager::IS_NONE); 308 309 if (!loadPlayground()) 310 return false; 219 if (mode_ == DEDICATED) 220 { 221 // do something else 222 } 223 else 224 { // not dedicated server 225 if (!ogre_->loadRenderer()) // creates the render window 226 return false; 227 228 // Calls the InputManager which sets up the input devices. 229 // The render window width and height are used to set up the mouse movement. 230 if (!InputManager::initialise(ogre_->getWindowHandle(), 231 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 232 return false; 233 234 // TODO: Spread this so that this call only initialises things needed for the GUI 235 if (!ogre_->initialiseResources()) 236 return false; 237 238 // TOOD: load the GUI here 239 // set InputManager to GUI mode 240 InputManager::setInputState(InputManager::IS_GUI); 241 // TODO: run GUI here 242 243 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 244 245 InputManager::setInputState(InputManager::IS_NONE); 246 247 // create Ogre SceneManager 248 ogre_->createNewScene(); 249 250 if (!loadPlayground()) 251 return false; 252 } 311 253 312 254 switch (mode_) … … 320 262 return false; 321 263 break; 264 case DEDICATED: 265 if (!serverLoad()) 266 return false; 267 break; 322 268 default: 323 269 if (!standaloneLoad()) … … 336 282 bool Orxonox::loadPlayground() 337 283 { 338 ogre_->createNewScene(); 339 340 // Init audio 284 // Init audio 341 285 //auMan_ = new audio::AudioManager(); 342 286 //auMan_->ambientAdd("a1"); … … 348 292 // Load the HUD 349 293 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 350 orxonoxHUD_ = new HUD(1); 351 352 COUT(3) << "Orxonox: Loading Console..." << std::endl; 353 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer")); 354 /* 355 Testconsole* console = new Testconsole(ib); 356 ib->registerListener(console, &Testconsole::listen, true); 357 ib->registerListener(console, &Testconsole::execute, '\r', false); 358 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true); 359 ib->registerListener(console, &Testconsole::clear, '§', true); 360 ib->registerListener(console, &Testconsole::removeLast, '\b', true); 361 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 362 */ 363 orxonoxConsole_ = new InGameConsole(ib); 364 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true); 365 ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false); 366 ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true); 367 ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true); 368 ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true); 369 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true); 370 294 orxonoxHUD_ = &HUD::getSingleton(); 371 295 return true; 372 296 } … … 379 303 COUT(2) << "Loading level in server mode" << std::endl; 380 304 381 server_g = new network::Server( );305 server_g = new network::Server(serverPort_); 382 306 383 307 if (!loadScene()) … … 399 323 client_g = network::Client::createSingleton(); 400 324 else 401 client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT); 402 403 client_g->establishConnection(); 325 326 client_g = network::Client::createSingleton(serverIp_, serverPort_); 327 328 if(!client_g->establishConnection()) 329 return false; 404 330 client_g->tick(0); 405 331 … … 427 353 Level* startlevel = new Level("levels/sample.oxw"); 428 354 Loader::open(startlevel); 429 355 356 // HACK: shader stuff for presentation 357 /*Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 358 mSceneMgr->setAmbientLight(ColourValue(0.4,0.4,0.4)); 359 Ogre::Light* dirlight = mSceneMgr->createLight("Light1"); 360 361 dirlight->setType(Ogre::Light::LT_DIRECTIONAL); 362 dirlight->setDirection(Vector3( 0, 1, 5 )); 363 dirlight->setDiffuseColour(ColourValue(0.6, 0.6, 0.4)); 364 dirlight->setSpecularColour(ColourValue(1.0, 1.0, 1.0));*/ 365 430 366 return true; 431 367 } … … 453 389 // Contains the times of recently fired events 454 390 // eventTimes[4] is the list for the times required for the fps counter 455 std::deque<unsigned long> eventTimes[ 4];391 std::deque<unsigned long> eventTimes[3]; 456 392 // Clear event times 457 for (int i = 0; i < 4; ++i)393 for (int i = 0; i < 3; ++i) 458 394 eventTimes[i].clear(); 459 // fill the fps time list with zeros460 for (int i = 0; i < 50; i++)461 eventTimes[3].push_back(0);462 395 463 396 // use the ogre timer class to measure time. … … 466 399 timer_->reset(); 467 400 401 float renderTime = 0.0f; 402 float frameTime = 0.0f; 403 clock_t time = 0; 404 405 //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 406 //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 407 408 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom"); 409 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur"); 410 468 411 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 469 while (!bAbort_) 470 { 471 // Pump messages in all registered RenderWindows 472 // This calls the WindowEventListener objects. 473 Ogre::WindowEventUtilities::messagePump(); 474 412 while (!bAbort_) 413 { 475 414 // get current time 476 415 unsigned long now = timer_->getMilliseconds(); 477 eventTimes[3].push_back(now);478 eventTimes[3].erase(eventTimes[3].begin());479 416 480 417 // create an event to pass to the frameStarted method in ogre … … 482 419 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 483 420 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 421 frameTime += evt.timeSinceLastFrame; 484 422 485 423 // show the current time in the HUD 486 // orxonoxHUD_->setTime((int)now, 0); 487 // orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber()); 488 if (eventTimes[3].back() - eventTimes[3].front() != 0) 489 // orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 490 491 // Iterate through all Tickables and call their tick(dt) function 424 // HUD::getSingleton().setTime(now); 425 if (mode_ != DEDICATED && frameTime > 0.4f) 426 { 427 HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime); 428 frameTime = 0.0f; 429 renderTime = 0.0f; 430 } 431 432 // Call those objects that need the real time 433 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 434 it->tick((float)evt.timeSinceLastFrame); 435 // Call the scene objects 492 436 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 493 437 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 494 // Iterate through all TickableReals and call their tick(dt) function495 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)496 it->tick((float)evt.timeSinceLastFrame);497 orxonoxConsole_->tick((float)evt.timeSinceLastFrame);498 438 499 439 // don't forget to call _fireFrameStarted in ogre to make sure … … 501 441 ogreRoot._fireFrameStarted(evt); 502 442 503 // server still renders at the moment504 //if (mode_ != SERVER)505 ogreRoot._updateAllRenderTargets(); // only render in non-server mode506 507 443 // get current time 508 444 now = timer_->getMilliseconds(); 445 calculateEventTime(now, eventTimes[2]); 446 447 if (mode_ != DEDICATED) 448 { 449 // Pump messages in all registered RenderWindows 450 // This calls the WindowEventListener objects. 451 Ogre::WindowEventUtilities::messagePump(); 452 453 // render 454 ogreRoot._updateAllRenderTargets(); 455 } 456 457 // get current time 458 now = timer_->getMilliseconds(); 509 459 510 460 // create an event to pass to the frameEnded method in ogre 511 461 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 512 evt.timeSinceLastFrame= calculateEventTime(now, eventTimes[2]);462 renderTime += calculateEventTime(now, eventTimes[2]); 513 463 514 464 // again, just to be sure ogre works fine 515 465 ogreRoot._fireFrameEnded(evt); 516 } 517 518 if(mode_==CLIENT) 466 //msleep(200); 467 } 468 469 if (mode_ == CLIENT) 519 470 network::Client::getSingleton()->closeConnection(); 520 else if (mode_==SERVER)471 else if (mode_ == SERVER) 521 472 server_g->close(); 473 522 474 return true; 523 475 } … … 560 512 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 561 513 } 562 563 /**564 * Static function that shows the console in game mode.565 */566 void Orxonox::activateConsole()567 {568 // currently, the console shows itself when feeded with input.569 InputManager::setInputState(InputManager::IS_CONSOLE);570 }571 514 } -
TabularUnified code/trunk/src/orxonox/Orxonox.h ¶
r1293 r1502 50 50 SERVER, 51 51 CLIENT, 52 STANDALONE 52 STANDALONE, 53 DEDICATED 53 54 }; 54 55 … … 70 71 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 71 72 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 72 static inline void activateConsole();73 73 74 74 private: … … 97 97 // TODO: make this a config-value by creating a config class for orxonox 98 98 float frameSmoothingTime_; 99 InGameConsole* orxonoxConsole_;100 99 HUD* orxonoxHUD_; 101 100 bool bAbort_; //!< aborts the render loop if true … … 105 104 gameMode mode_; 106 105 std::string serverIp_; 106 int serverPort_; 107 107 108 108 static Orxonox *singletonRef_s; -
TabularUnified code/trunk/src/orxonox/OrxonoxPrereqs.h ¶
r1214 r1502 35 35 #define _OrxonoxPrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 //----------------------------------------------------------------------- … … 74 74 class Skybox; 75 75 class SpaceShip; 76 class SpaceShipAI; 76 77 class WorldEntity; 77 78 … … 95 96 96 97 // hud 98 class BarOverlayElement; 97 99 class HUD; 100 class Navigation; 101 class RadarObject; 102 class RadarOverlayElement; 103 98 104 //console 99 105 class InGameConsole; -
TabularUnified code/trunk/src/orxonox/OrxonoxStableHeaders.h ¶
r1219 r1502 35 35 #define _OrxonoxStableHeaders_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC … … 109 109 #include "network/Synchronisable.h" 110 110 111 #include "OrxonoxPlatform.h"112 111 #include "OrxonoxPrereqs.h" 113 112 #include "tools/Timer.h" -
TabularUnified code/trunk/src/orxonox/console/InGameConsole.cc ¶
r1362 r1502 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 40 40 #include "core/Debug.h" 41 41 #include "core/CoreIncludes.h" 42 #include "core/ConfigValueIncludes.h" 42 43 #include "core/ConsoleCommand.h" 43 44 #include "core/InputManager.h" 45 #include "util/Math.h" 44 46 #include "GraphicsEngine.h" 45 47 46 #define LINES 20 48 #define LINES 30 49 #define CHAR_WIDTH1 7.78 //34 // fix this please - determine the char-width dynamically 50 #define CHAR_WIDTH2 8.28 // fix this please - determine the char-width dynamically 51 #define CHAR_WIDTH3 7.80 //78 // fix this please - determine the char-width dynamically 47 52 48 53 namespace orxonox 49 54 { 55 SetConsoleCommand(InGameConsole, openConsole, true); 56 SetConsoleCommand(InGameConsole, closeConsole, true); 57 50 58 using namespace Ogre; 51 59 52 const float REL_WIDTH = 0.8; 53 const float REL_HEIGHT = 0.4; 54 const float BLINK = 0.25; 55 56 InGameConsole::InGameConsole(InputBuffer* ib) : 57 windowW(0), windowH(0), 58 scroll(0), scrollTimer(0.0f), 59 cursor(0.0f), 60 active(false), 61 ib_(ib), 62 om(0), 63 consoleOverlay(0), 64 consoleOverlayContainer(0), 65 consoleOverlayNoise(0), 66 consoleOverlayBorder(0), 67 consoleOverlayTextAreas(0) 68 { 69 //RegisterObject(InGameConsole); 70 init(); 71 } 72 73 InGameConsole::~InGameConsole(void){ 74 for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i]; 75 delete consoleOverlayTextAreas; 76 } 77 78 void InGameConsole::listen(){ 79 if(!active) activate(); 80 print(convert2UTF(this->ib_->get())); 81 } 82 83 void InGameConsole::execute(){ 84 newline(); 85 if (!CommandExecutor::execute(this->ib_->get())){ 86 print("Error"); 87 newline(); 88 } 89 this->ib_->clear(); 90 } 91 92 void InGameConsole::hintandcomplete(){ 93 print(CommandExecutor::hint(this->ib_->get())); 94 newline(); 95 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 96 print(convert2UTF(this->ib_->get())); 97 } 98 99 void InGameConsole::clear(){ 100 this->ib_->clear(); 101 } 102 103 void InGameConsole::removeLast(){ 104 this->ib_->removeLast(); 105 } 106 107 void InGameConsole::exit(){ 108 clear(); 109 deactivate(); 110 InputManager::setInputState(InputManager::IS_NORMAL); 111 } 112 113 /** 114 @brief called once by constructor 115 */ 116 void InGameConsole::init(){ 60 float InGameConsole::REL_WIDTH = 0.8; 61 float InGameConsole::REL_HEIGHT = 0.4; 62 float InGameConsole::BLINK = 0.5; 63 64 /** 65 @brief Constructor: Creates and initializes the InGameConsole. 66 */ 67 InGameConsole::InGameConsole() : 68 om_(0), consoleOverlay_(0), consoleOverlayContainer_(0), 69 consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0) 70 { 71 RegisterObject(InGameConsole); 72 73 this->active_ = false; 74 this->cursor_ = 0.0; 75 this->cursorSymbol_ = '|'; 76 this->inputWindowStart_ = 0; 77 this->numLinesShifted_ = LINES - 1; 78 79 this->init(); 80 this->setConfigValues(); 81 82 Shell::getInstance().addOutputLevel(true); 83 } 84 85 /** 86 @brief Destructor: Destroys the TextAreas. 87 */ 88 InGameConsole::~InGameConsole(void) 89 { 90 /*for (int i = 0; i < LINES; i++) 91 if (this->consoleOverlayTextAreas_[i]) 92 om_->destroyOverlayElement(this->consoleOverlayTextAreas_[i]); 93 94 if (this->consoleOverlayTextAreas_) 95 delete[] this->consoleOverlayTextAreas_;*/ 96 } 97 98 /** 99 @brief Returns a reference to the only existing instance of InGameConsole. 100 */ 101 InGameConsole& InGameConsole::getInstance() 102 { 103 static InGameConsole instance; 104 return instance; 105 } 106 107 /** 108 @brief Sets the config values, describing the size of the console. 109 */ 110 void InGameConsole::setConfigValues() 111 { 112 SetConfigValue(REL_WIDTH, 0.8); 113 SetConfigValue(REL_HEIGHT, 0.4); 114 SetConfigValue(BLINK, 0.5); 115 } 116 117 /** 118 @brief Called if all output-lines have to be redrawn. 119 */ 120 void InGameConsole::linesChanged() 121 { 122 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 123 int max = 0; 124 for (int i = 1; i < LINES; ++i) 125 { 126 if (it != Shell::getInstance().getEndIterator()) 127 { 128 ++it; 129 max = i; 130 } 131 else 132 break; 133 } 134 135 for (int i = LINES - 1; i > max; --i) 136 this->print("", i, true); 137 138 for (int i = max; i >= 1; --i) 139 { 140 --it; 141 this->print(*it, i, true); 142 } 143 } 144 145 /** 146 @brief Called if only the last output-line has changed. 147 */ 148 void InGameConsole::onlyLastLineChanged() 149 { 150 if (LINES > 1) 151 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 152 } 153 154 /** 155 @brief Called if a new output-line was added. 156 */ 157 void InGameConsole::lineAdded() 158 { 159 this->numLinesShifted_ = 0; 160 this->shiftLines(); 161 this->onlyLastLineChanged(); 162 } 163 164 /** 165 @brief Called if the text in the input-line has changed. 166 */ 167 void InGameConsole::inputChanged() 168 { 169 if (LINES > 0) 170 this->print(Shell::getInstance().getInput(), 0); 171 172 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 173 this->inputWindowStart_ = 0; 174 } 175 176 /** 177 @brief Called if the position of the cursor in the input-line has changed. 178 */ 179 void InGameConsole::cursorChanged() 180 { 181 /*std::string input = Shell::getInstance().getInput(); 182 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 183 if (LINES > 0) 184 this->print(input, 0);*/ 185 this->setCursorPosition(Shell::getInstance().getCursorPosition() - inputWindowStart_); 186 } 187 188 /** 189 @brief Called if the console gets closed. 190 */ 191 void InGameConsole::exit() 192 { 193 this->deactivate(); 194 } 195 196 /** 197 @brief Called once by constructor, initializes the InGameConsole. 198 */ 199 void InGameConsole::init() 200 { 117 201 // for the beginning, don't scroll 118 scroll= 0;119 scrollTimer= 0;120 cursor= 0;202 this->scroll_ = 0; 203 this->scrollTimer_ = 0; 204 this->cursor_ = 0; 121 205 122 206 // create overlay and elements 123 om= &Ogre::OverlayManager::getSingleton();207 this->om_ = &Ogre::OverlayManager::getSingleton(); 124 208 125 209 // create a container 126 consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));127 consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);128 consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);129 consoleOverlayContainer->setDimensions(REL_WIDTH,REL_HEIGHT);210 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer")); 211 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 212 this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0); 213 this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT); 130 214 131 215 // create BorderPanel 132 consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));133 consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);134 consoleOverlayBorder->setMaterialName("ConsoleCenter");216 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 217 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 218 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 135 219 // set parameters for border 136 consoleOverlayBorder->setBorderSize(16, 16, 0, 16);137 consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");138 consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);139 consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);140 consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);141 consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);142 consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);220 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 221 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); 222 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 223 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 224 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 225 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 226 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 143 227 144 228 // create the text lines 145 consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES]; 146 for(int i = 0; i<LINES; i++){ 147 consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i))); 148 consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS); 149 consoleOverlayTextAreas[i]->setFontName("Console"); 150 consoleOverlayTextAreas[i]->setCharHeight(20); 151 consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21"); 152 consoleOverlayTextAreas[i]->setLeft(8); 153 consoleOverlayTextAreas[i]->setCaption(""); 229 this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES]; 230 for (int i = 0; i < LINES; i++) 231 { 232 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 233 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 234 this->consoleOverlayTextAreas_[i]->setFontName("Console"); 235 this->consoleOverlayTextAreas_[i]->setCharHeight(18); 236 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21"); 237 this->consoleOverlayTextAreas_[i]->setLeft(8); 238 this->consoleOverlayTextAreas_[i]->setCaption(""); 154 239 } 155 240 156 241 // create noise 157 consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise")); 158 consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS); 159 consoleOverlayNoise->setPosition(5,0); 160 consoleOverlayNoise->setMaterialName("ConsoleNoise"); 161 162 consoleOverlay = om->create("Console"); 163 consoleOverlay->add2D(consoleOverlayContainer); 164 consoleOverlayContainer->addChild(consoleOverlayBorder); 165 //comment following line to disable noise 166 consoleOverlayContainer->addChild(consoleOverlayNoise); 167 for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]); 168 resize(); 242 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise")); 243 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 244 this->consoleOverlayNoise_->setPosition(5,0); 245 this->consoleOverlayNoise_->setMaterialName("ConsoleNoise"); 246 247 // create cursor 248 this->consoleOverlayCursor_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleCursor")); 249 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS); 250 this->consoleOverlayCursor_->setPosition(5,219); 251 this->consoleOverlayCursor_->setDimensions(1, 14); 252 this->consoleOverlayCursor_->setMaterialName("Orxonox/GreenDot"); 253 254 this->consoleOverlay_ = this->om_->create("InGameConsoleConsole"); 255 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 256 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 257 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 258 //comment following line to disable noise 259 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 260 for (int i = 0; i < LINES; i++) 261 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 262 263 this->resize(); 169 264 170 265 // move overlay "above" the top edge of the screen 171 266 // we take -1.2 because the border mkes the panel bigger 172 consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);267 this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT); 173 268 // show overlay 174 consoleOverlay->show(); 175 176 COUT(3) << "Info: InGameConsole initialized" << std::endl; 177 } 178 179 /** 180 @brief used to control the actual scrolling and cursor 181 */ 182 void InGameConsole::tick(float dt){ 183 scrollTimer += dt; 184 if(scrollTimer >= 0.01){ 185 float top = consoleOverlayContainer->getTop(); 186 scrollTimer = 0; 187 if(scroll!=0){ 269 this->consoleOverlay_->show(); 270 271 COUT(4) << "Info: InGameConsole initialized" << std::endl; 272 } 273 274 /** 275 @brief Resizes the console elements. Call if window size changes. 276 */ 277 void InGameConsole::resize() 278 { 279 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 280 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 281 this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH); 282 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT); 283 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10); 284 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5); 285 286 // now adjust the text lines... 287 this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12; 288 289 if (LINES > 0) 290 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH3)); 291 else 292 this->maxCharsPerLine_ = 10; 293 294 for (int i = 0; i < LINES; i++) 295 { 296 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 297 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i); 298 } 299 300 this->linesChanged(); 301 } 302 303 /** 304 @brief Used to control the actual scrolling and the cursor. 305 */ 306 void InGameConsole::tick(float dt) 307 { 308 this->scrollTimer_ += dt; 309 if (this->scrollTimer_ >= 0.01) 310 { 311 float top = this->consoleOverlayContainer_->getTop(); 312 float timePassed = scrollTimer_; 313 this->scrollTimer_ = 0; 314 if (this->scroll_ != 0) 315 { 188 316 // scroll 189 top = top + 0.02*scroll;190 consoleOverlayContainer->setTop(top);317 top = top + timePassed * this->scroll_; 318 this->consoleOverlayContainer_->setTop(top); 191 319 } 192 if(top <= -1.2*REL_HEIGHT){ 320 if (top <= -1.2 * InGameConsole::REL_HEIGHT) 321 { 193 322 // window has completely scrolled up 194 scroll = 0; 195 consoleOverlay->hide(); 196 active = false; 323 this->scroll_ = 0; 324 this->consoleOverlay_->hide(); 325 this->active_ = false; 326 Shell::getInstance().unregisterListener(this); 197 327 } 198 if(top >= 0){ 328 if (top >= 0) 329 { 199 330 // window has completely scrolled down 200 scroll= 0;201 consoleOverlayContainer->setTop(0);202 active= true;331 this->scroll_ = 0; 332 this->consoleOverlayContainer_->setTop(0); 333 this->active_ = true; 203 334 } 204 335 } 205 336 206 cursor += dt; 207 if(cursor >= 2*BLINK) cursor = 0; 208 print(convert2UTF(this->ib_->get())); 209 210 // this creates a flickering effect 211 consoleOverlayNoise->setTiling(1, rand()%5+1); 212 } 213 214 /** 215 @brief resizes the console elements. call if window size changes 216 */ 217 void InGameConsole::resize(){ 218 windowW = GraphicsEngine::getSingleton().getWindowWidth(); 219 windowH = GraphicsEngine::getSingleton().getWindowHeight(); 220 consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH); 221 consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT); 222 consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10); 223 consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5); 224 // now adjust the text lines... 225 for(int i = 0; i<LINES; i++){ 226 consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH); 227 consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i); 228 } 229 } 230 231 /** 232 @brief shows console 233 */ 234 void InGameConsole::activate(){ 235 consoleOverlay->show(); 337 this->cursor_ += dt; 338 if (this->cursor_ >= InGameConsole::BLINK) 339 { 340 this->cursor_ = 0; 341 bShowCursor_ = !bShowCursor_; 342 if (bShowCursor_) 343 this->consoleOverlayCursor_->show(); 344 else 345 this->consoleOverlayCursor_->hide(); 346 } 347 348 /*if (this->cursor_ >= 2 * InGameConsole::BLINK) 349 this->cursor_ = 0; 350 351 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 352 { 353 this->cursorSymbol_ = ' '; 354 this->cursorChanged(); 355 } 356 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 357 { 358 this->cursorSymbol_ = '|'; 359 this->cursorChanged(); 360 }*/ 361 362 // this creates a flickering effect 363 this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1); 364 } 365 366 /** 367 @brief Shows the InGameConsole. 368 */ 369 void InGameConsole::activate() 370 { 371 InputManager::setInputState(InputManager::IS_CONSOLE); 372 Shell::getInstance().registerListener(this); 373 this->linesChanged(); 374 375 this->consoleOverlay_->show(); 236 376 // just in case window size has changed... 237 resize();377 this->resize(); 238 378 // scroll down 239 scroll= 1;379 this->scroll_ = 1; 240 380 // the rest is done by tick 241 381 } 242 382 243 383 /** 244 @brief hides console 245 */ 246 void InGameConsole::deactivate(){ 384 @brief Hides the InGameConsole. 385 */ 386 void InGameConsole::deactivate() 387 { 247 388 // scroll up 248 scroll= -1;389 this->scroll_ = -1; 249 390 // the rest is done by tick 250 } 251 252 /** 253 @brief prints string to bottom line 254 @param s string to be printed 255 */ 256 void InGameConsole::print(Ogre::UTFString s){ 257 if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s); 258 else consoleOverlayTextAreas[0]->setCaption(">" + s + "_"); 259 } 260 261 /** 262 @brief shifts all lines up and clears the bottom line 263 */ 264 void InGameConsole::newline(){ 265 Ogre::UTFString line; 266 for(int i = LINES-1; i>=1; i--){ 267 line = consoleOverlayTextAreas[i-1]->getCaption(); 268 // don't copy the cursor... 269 int l = line.length(); 270 if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1); 271 consoleOverlayTextAreas[i]->setCaption(line); 272 } 273 consoleOverlayTextAreas[0]->setCaption(">"); 274 } 275 276 Ogre::UTFString InGameConsole::convert2UTF(std::string s){ 391 InputManager::setInputState(InputManager::IS_NORMAL); 392 } 393 394 /** 395 @brief Activates the console. 396 */ 397 void InGameConsole::openConsole() 398 { 399 InGameConsole::getInstance().activate(); 400 } 401 402 /** 403 @brief Deactivates the console. 404 */ 405 void InGameConsole::closeConsole() 406 { 407 InGameConsole::getInstance().deactivate(); 408 } 409 410 /** 411 @brief Shifts all output lines one line up 412 */ 413 void InGameConsole::shiftLines() 414 { 415 for (unsigned int i = LINES - 1; i > 1; --i) 416 { 417 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 418 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 419 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 420 } 421 } 422 423 void InGameConsole::colourLine(int colourcode, int index) 424 { 425 if (colourcode == -1) 426 { 427 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 428 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 429 } 430 else if (colourcode == 1) 431 { 432 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 433 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 434 } 435 else if (colourcode == 2) 436 { 437 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 438 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 439 } 440 else if (colourcode == 3) 441 { 442 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 443 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 444 } 445 else if (colourcode == 4) 446 { 447 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 448 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 449 } 450 else if (colourcode == 5) 451 { 452 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 453 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 454 } 455 else 456 { 457 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 458 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 459 } 460 } 461 462 void InGameConsole::setCursorPosition(int pos) 463 { 464 static std::string char1 = "bdefgilpqtzCEGIJKNOPQT5[}äü"; 465 static std::string char2 = "Z4"; 466 467 if (pos > (int)maxCharsPerLine_) 468 pos = maxCharsPerLine_; 469 else if (pos < 0) 470 pos = 0; 471 472 float width = 0; 473 for (int i = 0; i < pos; ++i) 474 { 475 if (char1.find(displayedText_[i]) != std::string::npos) 476 width += CHAR_WIDTH1; 477 else if (char2.find(displayedText_[i]) != std::string::npos) 478 width += CHAR_WIDTH2; 479 else 480 width += CHAR_WIDTH3; 481 } 482 this->consoleOverlayCursor_->setPosition(width + 5, this->windowH_ * InGameConsole::REL_HEIGHT - 20); 483 } 484 485 /** 486 @brief Prints string to bottom line. 487 @param s String to be printed 488 */ 489 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 490 { 491 char level = 0; 492 if (text.size() > 0) 493 level = text[0]; 494 495 std::string output = text; 496 497 if (level >= -1 && level <= 5) 498 output.erase(0, 1); 499 500 if (LINES > index) 501 { 502 this->colourLine(level, index); 503 504 if (index > 0) 505 { 506 unsigned int linesUsed = 1; 507 while (output.size() > this->maxCharsPerLine_) 508 { 509 ++linesUsed; 510 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_))); 511 output.erase(0, this->maxCharsPerLine_); 512 output.insert(0, 1, ' '); 513 if (linesUsed > numLinesShifted_ || alwaysShift) 514 this->shiftLines(); 515 this->colourLine(level, index); 516 } 517 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 518 this->displayedText_ = output; 519 this->numLinesShifted_ = linesUsed; 520 } 521 else 522 { 523 if (output.size() > this->maxCharsPerLine_) 524 { 525 if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_) 526 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition(); 527 else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 528 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1; 529 530 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); 531 } 532 else 533 this->inputWindowStart_ = 0; 534 this->displayedText_ = output; 535 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 536 } 537 } 538 } 539 540 /** 541 @brief Converts a string into an Ogre::UTFString. 542 @param s The string to convert 543 @return The converted string 544 */ 545 Ogre::UTFString InGameConsole::convert2UTF(std::string s) 546 { 277 547 Ogre::UTFString utf; 278 int i;279 548 Ogre::UTFString::code_point cp; 280 for (i=0; i<(int)s.size(); ++i){ 549 for (unsigned int i = 0; i < s.size(); ++i) 550 { 281 551 cp = s[i]; 282 552 cp &= 0xFF; -
TabularUnified code/trunk/src/orxonox/console/InGameConsole.h ¶
r1214 r1502 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 37 37 38 38 #include "core/Tickable.h" 39 #include "core/ InputBuffer.h"39 #include "core/Shell.h" 40 40 41 41 42 42 namespace orxonox 43 43 { 44 class _OrxonoxExport InGameConsole : public InputBufferListener44 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener 45 45 { 46 46 public: 47 InGameConsole(InputBuffer* ib); 48 ~InGameConsole(); 49 void listen(); 50 void execute(); 51 void hintandcomplete(); 52 void clear(); 53 void removeLast(); 54 void exit(); 55 void init(); 47 static InGameConsole& getInstance(); 48 49 void setConfigValues(); 56 50 void tick(float dt); 51 57 52 void activate(); 58 53 void deactivate(); 54 void resize(); 55 56 static void openConsole(); 57 static void closeConsole(); 59 58 60 59 private: 61 void resize(); 62 void print(Ogre::UTFString s); 63 void newline(); 64 Ogre::UTFString convert2UTF(std::string s); 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other); 62 ~InGameConsole(); 65 63 66 int windowW; 67 int windowH; 68 int scroll; 69 float scrollTimer; 70 float cursor; 71 bool active; 72 InputBuffer* ib_; 73 Ogre::OverlayManager* om; 74 Ogre::Overlay* consoleOverlay; 75 Ogre::OverlayContainer* consoleOverlayContainer; 76 Ogre::PanelOverlayElement* consoleOverlayNoise; 77 Ogre::BorderPanelOverlayElement* consoleOverlayBorder; 78 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas; 64 virtual void linesChanged(); 65 virtual void onlyLastLineChanged(); 66 virtual void lineAdded(); 67 virtual void inputChanged(); 68 virtual void cursorChanged(); 69 virtual void exit(); 70 71 void init(); 72 void shiftLines(); 73 void colourLine(int colourcode, int index); 74 void setCursorPosition(int pos); 75 void print(const std::string& text, int index, bool alwaysShift = false); 76 static Ogre::UTFString convert2UTF(std::string s); 77 78 static float REL_WIDTH; 79 static float REL_HEIGHT; 80 static float BLINK; 81 82 int windowW_; 83 int windowH_; 84 int desiredTextWidth_; 85 unsigned int maxCharsPerLine_; 86 unsigned int numLinesShifted_; 87 int scroll_; 88 float scrollTimer_; 89 float cursor_; 90 unsigned int inputWindowStart_; 91 char cursorSymbol_; 92 bool active_; 93 bool bShowCursor_; 94 std::string displayedText_; 95 Ogre::OverlayManager* om_; 96 Ogre::Overlay* consoleOverlay_; 97 Ogre::OverlayContainer* consoleOverlayContainer_; 98 Ogre::PanelOverlayElement* consoleOverlayNoise_; 99 Ogre::PanelOverlayElement* consoleOverlayCursor_; 100 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 101 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 79 102 }; 80 103 } -
TabularUnified code/trunk/src/orxonox/hud/BarOverlayElement.cc ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 30 #include "BarOverlayElement.h" 28 31 #include <OgreOverlayManager.h> 29 #include <OgreOverlayElement.h>30 #include <OgrePanelOverlayElement.h>31 32 #include "GraphicsEngine.h" 32 #include "BarOverlayElement.h"33 33 34 34 namespace orxonox 35 35 { 36 using namespace Ogre;36 using namespace Ogre; 37 37 38 BarOverlayElement::BarOverlayElement(const String& name): Ogre::PanelOverlayElement(name){38 BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){ 39 39 name_ = name; 40 40 } … … 42 42 BarOverlayElement::~BarOverlayElement(){} 43 43 44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, O gre::OverlayContainer* container){44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 45 45 // init some values... 46 46 container_ = container; 47 om = &O gre::OverlayManager::getSingleton();47 om = &OverlayManager::getSingleton(); 48 48 value_ = 0; 49 49 color_ = 2; … … 53 53 topRel_ = topRel; 54 54 dimRel_ = dimRel; 55 55 56 56 // create background... 57 57 background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container")); 58 58 background_->show(); 59 59 container_->addChild(background_); 60 background_->setMetricsMode( Ogre::GMM_PIXELS);60 background_->setMetricsMode(GMM_PIXELS); 61 61 background_->setMaterialName("Orxonox/BarBackground"); 62 62 … … 65 65 66 66 show(); 67 setMetricsMode( Ogre::GMM_PIXELS);67 setMetricsMode(GMM_PIXELS); 68 68 setMaterialName("Orxonox/Green"); 69 69 background_->addChild(this); … … 126 126 } 127 127 } 128 129 -
TabularUnified code/trunk/src/orxonox/hud/BarOverlayElement.h ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #ifndef _BarOverlayElement_H__ 30 #define _BarOverlayElement_H__ 28 31 29 #ifndef _BAR_H__ 30 #define _BAR_H__ 31 32 #include <OgreOverlayManager.h> 33 #include <OgreOverlayElement.h> 34 #include <OgrePanelOverlayElement.h> 32 #include "OrxonoxPrereqs.h" 35 33 36 34 #include <OgrePrerequisites.h> 37 #include "../OrxonoxPrereqs.h" 38 39 35 #include <OgrePanelOverlayElement.h> 40 36 41 37 namespace orxonox … … 44 40 { 45 41 private: 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 42 bool autoColor_; // whether bar changes color automatically 43 float value_; // progress of bar 44 int color_; 45 int left_; 46 int top_; 47 int width_; 48 int height_; 49 int windowW_, windowH_; 50 Ogre::Real leftRel_; 51 Ogre::Real topRel_; 52 Ogre::Real dimRel_; 53 Ogre::OverlayManager* om; // our overlay manager 54 Ogre::OverlayContainer* container_; // our parent container to attach to 55 Ogre::OverlayContainer* background_; 56 Ogre::String name_; 61 57 62 58 public: 63 64 65 66 59 bool left2Right; 60 static const int RED = 0; // predefined colors 61 static const int YELLOW = 1; 62 static const int GREEN = 2; 67 63 68 69 70 71 72 73 74 75 64 BarOverlayElement(const Ogre::String& name); 65 virtual ~BarOverlayElement(); 66 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 67 void resize(); 68 void setValue(float value); 69 void setColor(int color); 70 float getValue(); 71 int getBarColor(); 76 72 }; 77 73 } 78 #endif 79 80 74 #endif /* _BarOverlayElement_H__ */ -
TabularUnified code/trunk/src/orxonox/hud/HUD.cc ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist3 * 4 *5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 27 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "HUD.h" 31 32 #include <string> 33 #include <set> 30 34 #include <OgreOverlay.h> 31 35 #include <OgreOverlayContainer.h> 32 36 #include <OgreOverlayManager.h> 33 #include <OgreSceneNode.h>34 #include <OgreEntity.h>35 37 #include <OgreStringConverter.h> 38 36 39 #include "core/Debug.h" 40 #include "core/ConsoleCommand.h" 37 41 #include "objects/SpaceShip.h" 38 #include " HUD.h"42 #include "GraphicsEngine.h" 39 43 #include "BarOverlayElement.h" 44 #include "RadarObject.h" 40 45 #include "RadarOverlayElement.h" 46 #include "Navigation.h" 41 47 #include "OverlayElementFactories.h" 42 48 43 49 namespace orxonox 44 50 { 51 SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 52 SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User); 53 SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User); 54 45 55 using namespace Ogre; 46 56 47 HUD::HUD( int zoom){57 HUD::HUD(){ 48 58 om = &Ogre::OverlayManager::getSingleton(); 49 50 // create Factories 59 sm = GraphicsEngine::getSingleton().getSceneManager(); 60 showFPS = true; 61 showRenderTime = true; 62 63 // create Factories 51 64 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 52 65 om->addOverlayElementFactory(barOverlayElementFactory); … … 56 69 orxonoxHUD = om->create("Orxonox/HUD"); 57 70 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); 58 // test 59 test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123")); 60 test->show(); 61 test->setMetricsMode(Ogre::GMM_RELATIVE); 62 test->setDimensions(0.8, 0.8); 63 test->setPosition(0.02, 0.02); 64 test->setFontName("Console"); 65 test->setCaption("init"); 71 72 // creating text to display fps 73 fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText")); 74 fpsText->show(); 75 fpsText->setMetricsMode(Ogre::GMM_PIXELS); 76 fpsText->setDimensions(0.001, 0.001); 77 fpsText->setPosition(10, 10); 78 fpsText->setFontName("Console"); 79 fpsText->setCharHeight(20); 80 fpsText->setCaption("init"); 81 82 // creating text to display render time ratio 83 rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText")); 84 rTRText->show(); 85 rTRText->setMetricsMode(Ogre::GMM_PIXELS); 86 rTRText->setDimensions(0.001, 0.001); 87 rTRText->setPosition(10, 30); 88 rTRText->setFontName("Console"); 89 rTRText->setCharHeight(20); 90 rTRText->setCaption("init"); 66 91 67 92 // create energy bar … … 75 100 radar->show(); 76 101 77 // set up screen-wide container 102 // create Navigation 103 nav = new Navigation(container); 104 105 // set up screen-wide container 78 106 container->show(); 79 107 … … 85 113 container->setHeight(1.0); 86 114 container->setMetricsMode(Ogre::GMM_RELATIVE); 87 container->addChild(test); 115 container->addChild(fpsText); 116 container->addChild(rTRText); 117 88 118 energyBar->init(0.01, 0.94, 0.4, container); 89 119 energyBar->setValue(1); 120 90 121 speedoBar->init(0.01, 0.90, 0.4, container); 122 91 123 radar->init(0.5, 0.9, 0.2, container); 92 radar->addObject(Vector3(1500.0, 0.0, 100.0)); 93 radar->addObject(Vector3(0.0, 4000.0, 0.0)); 94 radar->addObject(Vector3(0.0, 0.0, 6800.0)); 95 RadarOverlayElement::cycleFocus(); 124 SceneNode* node; 125 node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0)); 126 addRadarObject(node); 127 node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0)); 128 addRadarObject(node); 129 node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0)); 130 addRadarObject(node); 131 node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0)); 132 addRadarObject(node, 3); 133 } 134 135 HUD::~HUD(){ 136 //todo: clean up objects 96 137 } 97 138 98 139 void HUD::tick(float dt) 99 140 { 100 int d = radar->getDist2Focus()/10;101 if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));102 else test->setCaption("");103 104 141 energyBar->resize(); 105 142 106 float v = SpaceShip::instance_s->getVelocity().length(); 107 float vmax = SpaceShip::instance_s->getMaxSpeed(); 143 if(!SpaceShip::getLocalShip()) 144 return; 145 float v = SpaceShip::getLocalShip()->getVelocity().length(); 146 float vmax = SpaceShip::getLocalShip()->getMaxSpeed(); 108 147 speedoBar->setValue(v/vmax); 109 148 speedoBar->resize(); … … 111 150 radar->resize(); 112 151 radar->update(); 113 } 114 115 HUD::~HUD(void){ 152 153 nav->update(); 154 155 setFPS(); 156 } 157 158 void HUD::setRenderTimeRatio(float ratio) 159 { 160 if(showRenderTime){ 161 rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio)); 162 } 163 else{ 164 rTRText->setCaption(""); 165 return; 166 } 167 } 168 169 void HUD::setFPS(){ 170 if(showFPS){ 171 float fps = GraphicsEngine::getSingleton().getAverageFPS(); 172 fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps)); 173 } 174 else{ 175 fpsText->setCaption(""); 176 return; 177 } 178 } 179 180 void HUD::addRadarObject(SceneNode* node, int colour){ 181 RadarObject* obj = new RadarObject(container, node, colour); 182 roSet.insert(obj); 183 // // check if this is the first RadarObject to create 184 // if(firstRadarObject == NULL){ 185 // firstRadarObject = new RadarObject(container, node, colour); 186 // lastRadarObject = firstRadarObject; 187 // } 188 // else{ // if not, append to list 189 // lastRadarObject->next = new RadarObject(container, node, colour); 190 // lastRadarObject = lastRadarObject->next; 191 // } 192 } 193 194 void HUD::removeRadarObject(Ogre::SceneNode* node){ 195 COUT(3) << "blabla" << std::endl; 196 for(std::set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); it++){ 197 if((*it)->getNode() == node) { 198 delete (*it); 199 roSet.erase(it); 200 } 201 } 202 } 203 204 /*static*/ HUD& HUD::getSingleton(){ 205 static HUD theInstance; 206 return theInstance; 207 } 208 209 /*static*/ void HUD::setEnergy(float value){ 210 HUD::getSingleton().energyBar->setValue(value); 211 } 212 213 /*static*/ void HUD::cycleNavigationFocus(){ 214 HUD::getSingleton().nav->cycleFocus(); 215 } 216 217 /*static*/ void HUD::toggleFPS(){ 218 HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS; 219 } 220 221 /*static*/ void HUD::toggleRenderTime(){ 222 HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime; 116 223 } 117 224 } -
TabularUnified code/trunk/src/orxonox/hud/HUD.h ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 29 … … 30 31 #define _HUD_H__ 31 32 32 #include <string.h> 33 #include <OgreOverlayElement.h> 33 #include "OrxonoxPrereqs.h" 34 35 #include <OgrePrerequisites.h> 34 36 #include <OgreTextAreaOverlayElement.h> 35 #include <OgrePrerequisites.h> 36 37 #include "OrxonoxPrereqs.h" 37 #include <OgreSceneNode.h> 38 38 #include "core/Tickable.h" 39 #include "BarOverlayElement.h" 40 #include "RadarOverlayElement.h" 41 39 #include "util/Math.h" 42 40 43 41 namespace orxonox … … 45 43 class _OrxonoxExport HUD : public Tickable 46 44 { 47 private: 48 Ogre::OverlayManager* om; 49 Ogre::Overlay* orxonoxHUD; 50 Ogre::OverlayContainer* container; 51 Ogre::TextAreaOverlayElement* test; 52 BarOverlayElement* energyBar; 53 BarOverlayElement* speedoBar; 54 RadarOverlayElement* radar; 45 private: 46 HUD(); 47 HUD(HUD& instance); 48 ~HUD(); 49 Ogre::OverlayManager* om; 50 Ogre::SceneManager* sm; 51 Ogre::Overlay* orxonoxHUD; 52 Ogre::OverlayContainer* container; 53 Ogre::TextAreaOverlayElement* fpsText; 54 Ogre::TextAreaOverlayElement* rTRText; 55 BarOverlayElement* energyBar; 56 BarOverlayElement* speedoBar; 57 RadarOverlayElement* radar; 58 Navigation* nav; 55 59 56 public: 57 HUD(int zoom); 58 ~HUD(); 59 virtual void tick(float); 60 bool showFPS; 61 bool showRenderTime; 60 62 63 public: 64 virtual void tick(float); 65 void addRadarObject(Ogre::SceneNode* node, int colour = 0); 66 void removeRadarObject(Ogre::SceneNode* node); 67 void setRenderTimeRatio(float ratio); 68 void setFPS(); 69 70 std::set<RadarObject*> roSet; 71 72 static HUD* instance_s; 73 static HUD& getSingleton(); 74 static void setEnergy(float value); 75 static void cycleNavigationFocus(); 76 static void toggleFPS(); 77 static void toggleRenderTime(); 61 78 }; 62 79 } 63 80 64 #endif 81 #endif /* _HUD_H__ */ -
TabularUnified code/trunk/src/orxonox/hud/OverlayElementFactories.h ¶
r1362 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 #ifndef _ FACTORIES_H__29 #define _ FACTORIES_H__29 #ifndef _OverlayElementFactories_H__ 30 #define _OverlayElementFactories_H__ 30 31 32 #include "OrxonoxPrereqs.h" 33 34 #include <OgrePrerequisites.h> 31 35 #include <OgreOverlayElement.h> 32 #include <OgrePrerequisites.h>33 36 #include <OgreOverlayElementFactory.h> 34 37 35 38 #include "BarOverlayElement.h" 39 #include "RadarOverlayElement.h" 36 40 37 41 namespace orxonox{ 38 42 class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{ 39 43 public: 40 44 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 41 45 return new BarOverlayElement(instanceName); … … 48 52 49 53 class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{ 50 54 public: 51 55 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 52 56 return new RadarOverlayElement(instanceName); … … 59 63 } 60 64 61 #endif 65 #endif /* _OverlayElementFactories_H__ */ -
TabularUnified code/trunk/src/orxonox/hud/RadarObject.cc ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Felix Schulthess 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Felix Schulthess 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 28 30 #include "RadarObject.h" 31 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 34 #include "GraphicsEngine.h" 29 35 30 36 namespace orxonox … … 32 38 using namespace Ogre; 33 39 34 40 int RadarObject::count = 0; // initialize static variable 35 41 36 RadarObject::RadarObject(Ogre::OverlayContainer* container){ 37 container_ = container; 38 pos_ = Vector3(0.0, 0.0, 0.0); 39 init(); 40 } 41 42 RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){ 43 container_ = container; 44 pos_ = pos; 45 init(); 46 } 47 48 RadarObject::~RadarObject(){} 49 50 void RadarObject::init(){ 51 next = NULL; 52 om = &Ogre::OverlayManager::getSingleton(); 53 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 54 "Object"+Ogre::StringConverter::toString(count))); 55 panel_->setMaterialName("Orxonox/RedDot"); 56 panel_->setDimensions(3,3); 42 RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){ 43 container_ = container; 44 node_ = node; 45 colour_ = colour; 46 om = &OverlayManager::getSingleton(); 47 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 48 "Object"+StringConverter::toString(count))); 49 setColour(colour_); 50 panel_->setDimensions(3,3); 57 51 panel_->setMetricsMode(Ogre::GMM_PIXELS); 58 52 panel_->show(); … … 60 54 count++; 61 55 container_->addChild(panel_); 62 } 56 } 57 58 RadarObject::~RadarObject(){ 59 delete panel_; 60 } 61 62 void RadarObject::setColour(int colour){ 63 switch(colour){ 64 case RED: panel_->setMaterialName("Orxonox/RedDot"); break; 65 case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break; 66 case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break; 67 case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break; 68 case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break; 69 default: panel_->setMaterialName("Orxonox/RedDot"); break; 70 } 71 } 72 73 void RadarObject::resetColour(){ 74 setColour(colour_); 75 } 76 77 Vector3 RadarObject::getPosition(){ 78 return node_->getPosition(); 79 } 80 81 SceneNode* RadarObject::getNode(){ 82 return node_; 83 } 63 84 } 64 85 65 /* my local clipboard...66 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";67 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl;68 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";69 */ -
TabularUnified code/trunk/src/orxonox/hud/RadarObject.h ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Felix Schulthess 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 28 #ifndef _R ADAR2_H__29 #define _R ADAR2_H__29 #ifndef _RadarObject_H__ 30 #define _RadarObject_H__ 30 31 31 #include <string.h>32 32 #include <OgrePrerequisites.h> 33 #include <OgreOverlayManager.h> 34 #include <OgreOverlayElement.h> 33 #include <OgreSceneNode.h> 35 34 #include <OgrePanelOverlayElement.h> 36 #include <OgreStringConverter.h> 37 38 #include <util/Math.h> 39 #include "../OrxonoxPrereqs.h" 35 #include "OrxonoxPrereqs.h" 36 #include "util/Math.h" 40 37 41 38 namespace orxonox … … 43 40 class _OrxonoxExport RadarObject 44 41 { 45 private: 46 Ogre::OverlayManager* om; // our one and only overlay manager 47 void init(); 42 private: 43 Ogre::OverlayManager* om; // our one and only overlay manager 44 Ogre::SceneNode* node_; // node of object 45 int colour_; 48 46 49 public: 50 RadarObject(Ogre::OverlayContainer* container); 51 RadarObject(Ogre::OverlayContainer* container, Vector3 pos); 52 ~RadarObject(); 47 public: 48 RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, int colour = 0); 49 ~RadarObject(); 50 void setColour(int colour); 51 void resetColour(); 52 Vector3 getPosition(); 53 Ogre::SceneNode* getNode(); 53 54 54 bool right_; 55 int index_; // index number of object 56 Vector3 pos_; // position in space 57 Ogre::Real radius_, phi_; // position on radar 58 Ogre::OverlayContainer* container_; 59 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 60 RadarObject* next; // next pointer of linked list 55 bool right_; 56 int index_; // index number of object 57 Ogre::OverlayContainer* container_; 58 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 61 59 62 static int count; 63 }; 60 static int count; 61 static const int RED = 0; 62 static const int YELLOW = 1; 63 static const int GREEN = 2; 64 static const int BLUE = 3; 65 static const int WHITE = 99; // used if object got nav focus 66 }; 64 67 } 65 68 66 #endif 69 #endif /* _RadarObject_H__ */ -
TabularUnified code/trunk/src/orxonox/hud/RadarOverlayElement.cc ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 28 30 #include "RadarOverlayElement.h" 31 32 #include <string> 33 #include <OgreOverlayManager.h> 34 #include <OgreStringConverter.h> 35 36 #include "GraphicsEngine.h" 37 #include "core/Tickable.h" 38 #include "core/ConsoleCommand.h" 39 #include "objects/SpaceShip.h" 40 #include "RadarObject.h" 41 #include "HUD.h" 29 42 30 43 namespace orxonox 31 44 { 32 ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);33 34 45 using namespace Ogre; 35 46 36 RadarOverlayElement* RadarOverlayElement::instance_s = NULL; 37 38 RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 39 RadarOverlayElement::instance_s = this; 47 RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ 40 48 } 41 49 … … 43 51 } 44 52 45 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, O gre::OverlayContainer* container){53 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 46 54 // some initial data 47 om = &Ogre::OverlayManager::getSingleton();55 om = &OverlayManager::getSingleton(); 48 56 dimRel_ = dimRel; 49 57 leftRel_ = leftRel; 50 58 topRel_ = topRel; 51 59 container_ = container; 52 firstRadarObject_ = NULL;53 lastRadarObject_ = NULL;54 focus_ = NULL;55 60 56 // create nav marker ... 57 navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker")); 58 navMarker_->setMetricsMode(Ogre::GMM_PIXELS); 59 navMarker_->setMaterialName("Orxonox/NavMarker"); 60 navMarker_->setDimensions(16,16); 61 navMarker_->setPosition(0,386); 62 navMarker_->hide(); 63 container_->addChild(navMarker_); 64 65 // these have to fit the data in the level 66 shipPos_ = Vector3(0.0, 0.0, 0.0); 67 initialDir_ = Vector3(1.0, 0.0, 0.0); 68 currentDir_ = initialDir_; 69 initialOrth_ = Vector3(0.0, 0.0, 1.0); 70 currentOrth_ = initialOrth_; 71 plane = Plane(currentDir_, shipPos_); 72 73 setMetricsMode(Ogre::GMM_PIXELS); 61 setMetricsMode(GMM_PIXELS); 74 62 setMaterialName("Orxonox/Radar"); 75 63 resize(); … … 90 78 91 79 void RadarOverlayElement::update() { 92 shipPos_ = SpaceShip::instance_s->getPosition(); 93 currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... 94 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 95 plane = Plane(currentDir_, shipPos_); 96 97 RadarObject* ro = firstRadarObject_; 80 shipPos_ = SpaceShip::getLocalShip()->getPosition(); 81 currentDir_ = SpaceShip::getLocalShip()->getDir(); 82 currentOrth_ = SpaceShip::getLocalShip()->getOrth(); 98 83 // iterate through all RadarObjects 99 while(ro != NULL){100 101 ro->radius_ = calcRadius(ro);102 ro->phi_ = calcPhi(ro);103 ro->right_ = calcRight(ro);84 for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){ 85 // calc position on radar... 86 float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it)); 87 float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it)); 88 bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it)); 104 89 105 90 // set size to fit distance... 106 float d = (ro->pos_-shipPos_).length(); 107 if(d<4000) ro->panel_->setDimensions(4,4); 108 else if(d<8000) ro->panel_->setDimensions(3,3); 109 else if(d<16000) ro->panel_->setDimensions(2,2); 110 else ro->panel_->setDimensions(1,1); 91 float d = ((*it)->getPosition()-shipPos_).length(); 92 if(d<10000) (*it)->panel_->setDimensions(4,4); 93 else if(d<20000) (*it)->panel_->setDimensions(3,3); 94 else (*it)->panel_->setDimensions(2,2); 111 95 112 if (r o->right_){113 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/114 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);96 if (right){ 97 (*it)->panel_->setPosition(sin(phi)*radius/ 98 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 115 99 } 116 100 else { 117 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/ 118 3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2); 119 } 120 ro = ro->next; 121 } 122 updateNavMarker(); 123 } 124 125 void RadarOverlayElement::updateNavMarker(){ 126 if(focus_ == NULL) return; 127 // from the angle we find out where to draw the marker 128 // and which of the four arrows to take 129 float r1 = atan((float)(windowW_)/(float)(windowH_)); 130 float phi = focus_->phi_; 131 if(focus_->right_){ 132 if(phi<r1){ 133 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0); 134 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 135 } 136 else if(phi>3.14-r1){ 137 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16); 138 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 139 } 140 else { 141 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2); 142 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 143 } 144 } 145 else{ 146 if(phi<r1) { 147 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0); 148 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 149 } 150 else if(phi>3.14-r1) { 151 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16); 152 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 153 } 154 else { 155 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2); 156 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 101 (*it)->panel_->setPosition(-sin(phi)*radius/ 102 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 157 103 } 158 104 } 159 105 } 160 106 161 void RadarOverlayElement::addObject(Vector3 pos){ 162 if(firstRadarObject_ == NULL){ 163 firstRadarObject_ = new RadarObject(container_, pos); 164 lastRadarObject_ = firstRadarObject_; 107 void RadarOverlayElement::listObjects(){ 108 int i = 0; 109 COUT(3) << "List of RadarObjects:\n"; 110 // iterate through all Radar Objects 111 for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){ 112 COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; 165 113 } 166 else{ 167 lastRadarObject_->next = new RadarObject(container_, pos); 168 lastRadarObject_ = lastRadarObject_->next; 169 } 170 } 114 } 171 115 172 void RadarOverlayElement::listObjects(){ 173 int i = 0; 174 RadarObject* ro = firstRadarObject_; 175 COUT(3) << "List of RadarObjects:\n"; 176 // iterate through all Radar Objects 177 while(ro != NULL) { 178 COUT(3) << i++ << ": " << ro->pos_ << std::endl; 179 ro = ro->next; 180 } 181 } 116 float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 117 return(acos((dir.dotProduct(obj->getPosition() - pos))/ 118 ((obj->getPosition() - pos).length()*dir.length()))); 119 } 182 120 183 float RadarOverlayElement::getDist2Focus(){ 184 if(focus_ == NULL) return(0.0); 185 return((focus_->pos_-shipPos_).length()); 186 } 121 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 122 // project difference vector on our plane... 123 Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos); 124 // ...and find out the angle 125 return(acos((orth.dotProduct(proj))/ 126 (orth.length()*proj.length()))); 127 } 187 128 188 float RadarOverlayElement::calcRadius(RadarObject* obj){ 189 return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/ 190 ((obj->pos_ - shipPos_).length()*currentDir_.length()))); 191 } 192 193 float RadarOverlayElement::calcPhi(RadarObject* obj){ 194 // project difference vector on our plane... 195 Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_); 196 // ...and find out the angle 197 return(acos((currentOrth_.dotProduct(proj))/ 198 (currentOrth_.length()*proj.length()))); 199 } 200 201 bool RadarOverlayElement::calcRight(RadarObject* obj){ 202 if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0) 203 return true; 129 bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 130 if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0) 131 return true; 204 132 else return false; 205 } 206 207 /*static*/void RadarOverlayElement::cycleFocus(){ 208 if(RadarOverlayElement::instance_s == NULL) return; 209 210 if(RadarOverlayElement::instance_s->focus_ == NULL){ 211 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_; 212 } 213 else{ 214 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot"); 215 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next; 216 } 217 218 if(RadarOverlayElement::instance_s->focus_ == NULL){ 219 RadarOverlayElement::instance_s->navMarker_->hide(); 220 } 221 else{ 222 RadarOverlayElement::instance_s->navMarker_->show(); 223 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot"); 224 } 225 } 133 } 226 134 } 227 228 /* my local clipboard...229 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";230 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl;231 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";232 */ -
TabularUnified code/trunk/src/orxonox/hud/RadarOverlayElement.h ¶
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 #ifndef _R ADAR_H__29 #define _R ADAR_H__29 #ifndef _RadarOverlayElement_H__ 30 #define _RadarOverlayElement_H__ 30 31 31 #include <string.h> 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 34 #include <OgreOverlayElement.h> 32 #include "OrxonoxPrereqs.h" 33 34 #include <OgrePrerequisites.h> 35 35 #include <OgrePanelOverlayElement.h> 36 #include <OgrePrerequisites.h> 37 38 #include <util/Math.h> 39 #include <string.h> 40 #include "core/Tickable.h" 41 #include "core/ConsoleCommand.h" 42 #include "objects/SpaceShip.h" 43 #include "../OrxonoxPrereqs.h" 44 #include "RadarObject.h" 45 #include "GraphicsEngine.h" 36 #include "util/Math.h" 46 37 47 38 namespace orxonox … … 49 40 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 50 41 { 51 private: 52 Ogre::OverlayManager* om; // our one and only overlay manager 53 Ogre::OverlayContainer* container_; // pointer to the container we're in 54 Vector3 initialDir_; // direction of nose 55 Vector3 currentDir_; 56 Vector3 initialOrth_; // direction of normal 57 Vector3 currentOrth_; 58 Vector3 shipPos_; // position of ship 59 Ogre::Plane plane; // plane perpendicular to dir 42 private: 43 Ogre::OverlayManager* om; // our one and only overlay manager 44 Ogre::OverlayContainer* container_; // pointer to the container we're in 45 Vector3 currentDir_; 46 Vector3 currentOrth_; 47 Vector3 shipPos_; // position of ship 60 48 61 62 63 int windowW_, windowH_;// absolute window dimensions49 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 50 int left_, top_, dim_; // absolute position/dimension 51 int windowW_, windowH_; // absolute window dimensions 64 52 65 public: 66 RadarOverlayElement(const Ogre::String& name); 67 ~RadarOverlayElement(); 68 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 69 void resize(); 70 void update(); 71 void updateNavMarker(); 72 void addObject(Vector3 pos); 73 void listObjects(); 74 float getDist2Focus(); 75 float calcRadius(RadarObject* obj); 76 float calcPhi(RadarObject* obj); 77 bool calcRight(RadarObject* obj); 53 public: 54 RadarOverlayElement(const Ogre::String& name); 55 ~RadarOverlayElement(); 56 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 57 void resize(); 58 void update(); 59 void listObjects(); 78 60 79 Ogre::PanelOverlayElement* navMarker_; // marker to help navigating 80 RadarObject* firstRadarObject_; // start of linked list 81 RadarObject* lastRadarObject_; // end of linked list 82 RadarObject* focus_; // object that is focussed 83 84 static RadarOverlayElement* instance_s; 85 static void cycleFocus(); 86 }; 61 static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 62 static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 63 static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 64 }; 87 65 } 88 66 89 #endif 67 #endif /* _RadarOverlayElement_H__ */ -
TabularUnified code/trunk/src/orxonox/objects/Ambient.cc ¶
r1293 r1502 47 47 namespace orxonox 48 48 { 49 ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));49 SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline); 50 50 51 51 CreateFactory(Ambient); … … 66 66 bool Ambient::create(){ 67 67 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_); 68 return true;68 return Synchronisable::create(); 69 69 } 70 70 -
TabularUnified code/trunk/src/orxonox/objects/Ambient.h ¶
r1293 r1502 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 void setAmbientLight(const ColourValue& colour); 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 -
TabularUnified code/trunk/src/orxonox/objects/Camera.cc ¶
r1293 r1502 60 60 { 61 61 CameraHandler::getInstance()->releaseFocus(this); 62 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName()); 62 63 } 63 64 … … 75 76 void Camera::tick(float dt) 76 77 { 77 if(this->positionNode_ != NULL) { 78 if (this->positionNode_ != NULL) 79 { 78 80 // this stuff here may need some adjustments 79 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition(); 80 this->cameraNode_->translate(15*dt*offset); 81 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition(); 82 float coeff = 15.0f * dt; 83 if (coeff > 1.0f) 84 coeff = 1.0f; 81 85 82 this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 86 this->cameraNode_->translate(coeff * offset); 87 88 this->cameraNode_->setOrientation(Quaternion::Slerp(7.0f * dt, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 83 89 } 84 90 } -
TabularUnified code/trunk/src/orxonox/objects/Camera.h ¶
r1407 r1502 50 50 void setTargetNode(Ogre::SceneNode* obj); 51 51 52 Ogre::Camera* cam_; 53 52 54 void tick(float dt); 53 55 void update(); … … 63 65 Ogre::SceneNode* cameraNode_; 64 66 Ogre::Vector3 oldPos; 65 Ogre::Camera* cam_;66 67 bool bHasFocus_; 67 68 }; -
TabularUnified code/trunk/src/orxonox/objects/CameraHandler.cc ¶
r1293 r1502 26 26 * 27 27 */ 28 #include "OrxonoxStableHeaders.h" 29 #include "CameraHandler.h" 30 28 31 #include <OgreSceneManager.h> 29 32 #include <OgreRenderWindow.h> 30 33 31 #include "OrxonoxStableHeaders.h"32 34 #include "core/ObjectList.h" 33 #include "CameraHandler.h"34 35 #include "Camera.h" 35 36 #include "GraphicsEngine.h" -
TabularUnified code/trunk/src/orxonox/objects/Explosion.cc ¶
r1293 r1502 79 79 } 80 80 }; 81 82 /*bool Explosion::create(){ 83 if(!WorldEntity::create()) 84 return false; 85 classID=this->getIdentifier()->getNetworkID(); 86 }*/ 81 87 82 88 void Explosion::destroyObject() -
TabularUnified code/trunk/src/orxonox/objects/Explosion.h ¶
r1056 r1502 43 43 virtual ~Explosion(); 44 44 void destroyObject(); 45 virtual bool create(){return WorldEntity::create();} 45 46 46 47 private: -
TabularUnified code/trunk/src/orxonox/objects/Model.cc ¶
r1293 r1502 34 34 #include "GraphicsEngine.h" 35 35 #include "core/XMLPort.h" 36 37 #include <OgreEntity.h> 38 #include <OgreMesh.h> 39 #include <OgreHardwareVertexBuffer.h> 40 #include <OgreMeshManager.h> 41 36 42 37 43 namespace orxonox … … 77 83 this->mesh_.setMesh(meshSrc_); 78 84 this->attachObject(this->mesh_.getEntity()); 85 86 //HACK!! 87 /*if ((this->meshSrc_ == "assff.mesh") || (this->meshSrc_ == "ast1.mesh") || (this->meshSrc_ == "ast2.mesh") || (this->meshSrc_ == "ast3.mesh") || (this->meshSrc_ == "ast4.mesh") ||(this->meshSrc_ == "ast5.mesh") || (this->meshSrc_ == "ast6.mesh")) 88 { 89 Ogre::MeshPtr pMesh = this->mesh_.getEntity()->getMesh(); 90 //set Mesh to tangentspace 91 unsigned short src, dest; 92 if (!pMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest)) 93 { 94 pMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest); 95 } 96 if ((this->meshSrc_ == "assff.mesh")) 97 { 98 (this->mesh_.getEntity())->setMaterialName("Assff/BumpMap"); 99 } 100 else 101 { 102 (this->mesh_.getEntity())->setMaterialName("Asteroid/BumpMap"); 103 } 104 105 106 }*/ 79 107 COUT(4) << "Loader (Model.cc): Created model" << std::endl; 80 108 } -
TabularUnified code/trunk/src/orxonox/objects/Model.h ¶
r1293 r1502 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 void setMesh(const std::string& meshname); 47 bool create();47 virtual bool create(); 48 48 49 49 protected: -
TabularUnified code/trunk/src/orxonox/objects/NPC.cc ¶
r1293 r1502 67 67 } 68 68 69 bool NPC::create(){70 Model::create();71 return true;72 }73 69 74 70 /** -
TabularUnified code/trunk/src/orxonox/objects/NPC.h ¶
r1293 r1502 53 53 void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable); 54 54 void registerAllVariables(); 55 bool create();55 virtual bool create(){return Model::create();} 56 56 57 57 private: -
TabularUnified code/trunk/src/orxonox/objects/Projectile.cc ¶
r1360 r1502 30 30 #include "Projectile.h" 31 31 32 #include <OgreBillboard.h> 33 32 34 #include "core/CoreIncludes.h" 33 35 #include "core/Executor.h" … … 41 43 { 42 44 CreateFactory(Projectile); 45 46 float Projectile::speed_ = 0; 43 47 44 48 Projectile::Projectile(SpaceShip* owner) : … … 63 67 64 68 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 65 this->classID = this->getIdentifier()->getNetworkID(); // TODO: remove this hack66 69 // COUT(3) << this->classID << std::endl; 67 70 } … … 92 95 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 93 96 { 94 new Explosion(this); 97 Explosion *exp = new Explosion(this); 98 exp->create(); 95 99 delete this; 96 100 return; … … 104 108 delete this; 105 109 } 110 111 void Projectile::setColour(const ColourValue& colour) 112 { 113 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour); 114 } 106 115 } -
TabularUnified code/trunk/src/orxonox/objects/Projectile.h ¶
r1056 r1502 35 35 #include "../tools/BillboardSet.h" 36 36 #include "../tools/Timer.h" 37 #include "util/Math.h" 37 38 38 39 namespace orxonox … … 46 47 void destroyObject(); 47 48 virtual void tick(float dt); 49 virtual bool create(){return WorldEntity::create();} 50 void setColour(const ColourValue& colour); 51 52 static float getSpeed() 53 { return Projectile::speed_; } 54 55 protected: 56 SpaceShip* owner_; 48 57 49 58 private: 50 SpaceShip* owner_;51 59 BillboardSet billboard_; 52 float speed_;60 static float speed_; 53 61 float lifetime_; 54 62 Timer<Projectile> destroyTimer_; -
TabularUnified code/trunk/src/orxonox/objects/Skybox.cc ¶
r1293 r1502 90 90 bool Skybox::create(){ 91 91 this->setSkybox(skyboxSrc_); 92 return true;92 return Synchronisable::create(); 93 93 } 94 94 -
TabularUnified code/trunk/src/orxonox/objects/Skybox.h ¶
r1293 r1502 47 47 void setSkybox(const std::string& skyboxname); 48 48 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 void setSkyboxSrc(const std::string &src); -
TabularUnified code/trunk/src/orxonox/objects/SpaceShip.cc ¶
r1407 r1502 45 45 #include "particle/ParticleInterface.h" 46 46 #include "Projectile.h" 47 #include "RotatingProjectile.h" 47 48 #include "core/XMLPort.h" 48 49 #include "core/ConsoleCommand.h" 49 50 #include "network/Client.h" 51 #include "hud/HUD.h" 50 52 51 53 namespace orxonox 52 54 { 53 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); 54 ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true); 55 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); 56 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); 57 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); 55 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 56 SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); 57 SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 58 SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 59 SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 60 SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 61 SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 62 SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); 63 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 64 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 65 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 58 66 59 67 CreateFactory(SpaceShip); … … 64 72 Iterator<SpaceShip> it; 65 73 for(it = ObjectList<SpaceShip>::start(); it; ++it){ 66 if( (it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ))74 if( (it)->myShip_ ) 67 75 return *it; 68 76 } 69 77 return NULL; 70 78 } 71 79 72 80 SpaceShip::SpaceShip() : 73 81 //testvector_(0,0,0), … … 103 111 mouseY_(0.0f), 104 112 emitterRate_(0.0f), 105 server_(false) 113 myShip_(false), 114 teamNr_(0), 115 health_(100) 106 116 { 107 117 RegisterObject(SpaceShip); … … 112 122 this->setConfigValues(); 113 123 124 initialDir_ = Vector3(1.0, 0.0, 0.0); 125 currentDir_ = initialDir_; 126 initialOrth_ = Vector3(0.0, 0.0, 1.0); 127 currentOrth_ = initialOrth_; 128 129 this->camName_ = this->getName() + "CamNode"; 114 130 115 131 this->setRotationAxis(1, 0, 0); … … 127 143 if (this->cam_) 128 144 delete this->cam_; 145 if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL) 146 //remove the radar object 147 HUD::getSingleton().removeRadarObject(this->getNode()); 129 148 } 130 149 131 150 bool SpaceShip::create(){ 151 if(!myShip_){ 152 if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) 153 myShip_=true; 154 else 155 HUD::getSingleton().addRadarObject(this->getNode(), 3); 156 } 132 157 if(Model::create()) 133 158 this->init(); … … 153 178 void SpaceShip::init() 154 179 { 155 if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))156 {157 if (!setMouseEventCallback_)158 {159 InputManager::addMouseHandler(this, "SpaceShip");160 //InputManager::enableMouseHandler("SpaceShip");161 setMouseEventCallback_ = true;162 }163 }164 165 180 // START CREATING THRUSTER 166 181 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 200 215 // END CREATING BLINKING LIGHTS 201 216 202 // START of testing crosshair 203 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 204 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 205 206 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 207 this->chNearNode_->setInheritScale(false); 208 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 209 this->chFarNode_->setInheritScale(false); 210 211 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 212 this->chNearNode_->setScale(0.2, 0.2, 0.2); 213 214 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 215 this->chFarNode_->setScale(0.4, 0.4, 0.4); 217 if (this->isExactlyA(Class(SpaceShip))) 218 { 219 // START of testing crosshair 220 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 221 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 222 223 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 224 this->chNearNode_->setInheritScale(false); 225 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 226 this->chFarNode_->setInheritScale(false); 227 228 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 229 this->chNearNode_->setScale(0.2, 0.2, 0.2); 230 231 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 232 this->chFarNode_->setScale(0.4, 0.4, 0.4); 233 } 216 234 217 235 createCamera(); … … 237 255 CameraHandler::getInstance()->requestFocus(cam_); 238 256 257 } 258 259 Camera* SpaceShip::getCamera(){ 260 return cam_; 239 261 } 240 262 … … 295 317 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 296 318 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 297 server_=true; // TODO: this is only a hack 319 myShip_=true; // TODO: this is only a hack 320 298 321 SpaceShip::create(); 299 getFocus(); 322 if (this->isExactlyA(Class(SpaceShip))) 323 getFocus(); 300 324 } 301 325 … … 308 332 } 309 333 310 void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)311 {312 /*313 this->mouseX += e.state.X.rel;314 if (this->bInvertMouse_)315 this->mouseY += e.state.Y.rel;316 else317 this->mouseY -= e.state.Y.rel;318 319 // if(mouseX>maxMouseX) maxMouseX = mouseX;320 // if(mouseX<minMouseX) minMouseX = mouseX;321 // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;322 323 this->moved = true;324 */325 if (this->bRMousePressed_)326 {327 this->camNode_->roll(Degree(-rel.x * 0.10));328 this->camNode_->yaw(Degree(rel.y * 0.10));329 }330 else331 {332 float minDimension = clippingSize.y;333 if (clippingSize.x < minDimension)334 minDimension = clippingSize.x;335 336 this->mouseX_ += rel.x;337 if (this->mouseX_ < -minDimension)338 this->mouseX_ = -minDimension;339 if (this->mouseX_ > minDimension)340 this->mouseX_ = minDimension;341 342 this->mouseY_ += rel.y;343 if (this->mouseY_ < -minDimension)344 this->mouseY_ = -minDimension;345 if (this->mouseY_ > minDimension)346 this->mouseY_ = minDimension;347 348 float xRotation = this->mouseX_ / minDimension;349 xRotation = xRotation*xRotation * sgn(xRotation);350 xRotation *= -this->rotationAcceleration_;351 if (xRotation > this->maxRotation_)352 xRotation = this->maxRotation_;353 if (xRotation < -this->maxRotation_)354 xRotation = -this->maxRotation_;355 this->mouseXRotation_ = Radian(xRotation);356 357 float yRotation = this->mouseY_ / minDimension;358 yRotation = yRotation*yRotation * sgn(yRotation);359 yRotation *= this->rotationAcceleration_;360 if (yRotation > this->maxRotation_)361 yRotation = this->maxRotation_;362 if (yRotation < -this->maxRotation_)363 yRotation = -this->maxRotation_;364 this->mouseYRotation_ = Radian(yRotation);365 }366 }367 368 void SpaceShip::mouseButtonPressed(MouseButton::Enum id)369 {370 if (id == MouseButton::Left)371 this->bLMousePressed_ = true;372 else if (id == MouseButton::Right)373 this->bRMousePressed_ = true;374 }375 376 void SpaceShip::mouseButtonReleased(MouseButton::Enum id)377 {378 if (id == MouseButton::Left)379 this->bLMousePressed_ = false;380 else if (id == MouseButton::Right)381 {382 this->bRMousePressed_ = false;383 this->camNode_->resetOrientation();384 }385 }386 387 334 std::string SpaceShip::whereAmI() { 388 335 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) … … 391 338 } 392 339 393 Vector3 SpaceShip::get SPosition() {394 return SpaceShip::getLocalShip()->getPosition();395 } 396 397 Quaternion SpaceShip::getSOrientation(){398 return SpaceShip::getLocalShip()->getOrientation();340 Vector3 SpaceShip::getDir() { 341 return currentDir_; 342 } 343 344 Vector3 SpaceShip::getOrth(){ 345 return currentOrth_; 399 346 } 400 347 … … 403 350 void SpaceShip::tick(float dt) 404 351 { 352 currentDir_ = getOrientation()*initialDir_; 353 currentOrth_ = getOrientation()*initialOrth_; 354 405 355 if (this->cam_) 406 356 this->cam_->tick(dt); … … 422 372 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 423 373 { 424 425 Projectile *p = new Projectile(this); 426 374 375 Projectile *p; 376 if (this->isExactlyA(Class(SpaceShip))) 377 p = new RotatingProjectile(this); 378 else 379 p = new Projectile(this); 380 p->setColour(this->getProjectileColour()); 381 p->create(); 382 if(p->classID==0) 383 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 384 427 385 p->setBacksync(true); 428 386 this->timeToReload_ = this->reloadTime_; … … 495 453 } 496 454 497 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ )498 {499 COUT(4) << "steering our ship: " << objectID << std::endl;500 if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))501 this->acceleration_.x = this->translationAcceleration_;502 else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))503 this->acceleration_.x = -this->translationAcceleration_;504 else505 this->acceleration_.x = 0;506 507 if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))508 this->acceleration_.y = -this->translationAcceleration_;509 else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))510 this->acceleration_.y = this->translationAcceleration_;511 else512 this->acceleration_.y = 0;513 514 if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))515 this->momentum_ = Radian(-this->rotationAccelerationRadian_);516 else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))517 this->momentum_ = Radian(this->rotationAccelerationRadian_);518 else519 this->momentum_ = 0;520 }/*else521 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/522 455 523 456 WorldEntity::tick(dt); … … 533 466 else 534 467 this->tt_->setRate(0); 535 } 536 468 469 if( myShip_ ) 470 { 471 COUT(4) << "steering our ship: " << objectID << std::endl; 472 this->acceleration_.x = 0; 473 this->acceleration_.y = 0; 474 this->momentum_ = 0; 475 this->mouseXRotation_ = Radian(0); 476 this->mouseYRotation_ = Radian(0); 477 this->bLMousePressed_ = false; 478 }/*else 479 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 480 } 481 482 void SpaceShip::movePitch(float val) 483 { getLocalShip()->setMovePitch(val); } 484 void SpaceShip::moveYaw(float val) 485 { getLocalShip()->setMoveYaw(val); } 486 void SpaceShip::moveRoll(float val) 487 { getLocalShip()->setMoveRoll(val); } 488 void SpaceShip::moveLongitudinal(float val) 489 { getLocalShip()->setMoveLongitudinal(val); } 490 void SpaceShip::moveLateral(float val) 491 { getLocalShip()->setMoveLateral(val); } 492 void SpaceShip::fire() 493 { getLocalShip()->doFire(); } 494 495 void SpaceShip::setMovePitch(float val) 496 { 497 val = -val * val * sgn(val) * this->rotationAcceleration_; 498 if (val > this->maxRotation_) 499 val = this->maxRotation_; 500 if (val < -this->maxRotation_) 501 val = -this->maxRotation_; 502 this->mouseYRotation_ = Radian(val); 503 } 504 505 void SpaceShip::setMoveYaw(float val) 506 { 507 val = -val * val * sgn(val) * this->rotationAcceleration_; 508 if (val > this->maxRotation_) 509 val = this->maxRotation_; 510 if (val < -this->maxRotation_) 511 val = -this->maxRotation_; 512 this->mouseXRotation_ = Radian(val); 513 } 514 515 void SpaceShip::setMoveRoll(float val) 516 { 517 this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val); 518 //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl; 519 } 520 521 void SpaceShip::setMoveLongitudinal(float val) 522 { 523 this->acceleration_.x = this->translationAcceleration_ * val; 524 } 525 526 void SpaceShip::setMoveLateral(float val) 527 { 528 this->acceleration_.y = -this->translationAcceleration_ * val; 529 } 530 531 void SpaceShip::doFire() 532 { 533 this->bLMousePressed_ = true; 534 } 537 535 } -
TabularUnified code/trunk/src/orxonox/objects/SpaceShip.h ¶
r1407 r1502 41 41 namespace orxonox 42 42 { 43 class _OrxonoxExport SpaceShip : public Model , public MouseHandler43 class _OrxonoxExport SpaceShip : public Model 44 44 { 45 45 public: 46 46 47 47 static SpaceShip *getLocalShip(); 48 48 49 49 SpaceShip(); 50 50 ~SpaceShip(); 51 bool create();51 virtual bool create(); 52 52 void registerAllVariables(); 53 53 void init(); … … 64 64 void setTransDamp(float value); 65 65 void setRotDamp(float value); 66 void getFocus(); 66 67 67 void getFocus();68 static SpaceShip* instance_s;69 static Vector3 getSPosition();70 static Quaternion getSOrientation();71 68 static std::string whereAmI(); 72 69 static void setMaxSpeedTest(float value) 73 70 { SpaceShip::instance_s->setMaxSpeed(value); } 74 71 75 void mouseButtonPressed (MouseButton::Enum id); 76 void mouseButtonReleased(MouseButton::Enum id); 77 void mouseButtonHeld (MouseButton::Enum id) { } 78 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 79 void mouseScrolled (int abs, int rel) { } 72 static void movePitch(float value); 73 static void moveYaw(float value); 74 static void moveRoll(float value); 75 static void moveLongitudinal(float value); 76 static void moveLateral(float value); 77 static void fire(); 78 void setMovePitch(float value); 79 void setMoveYaw(float value); 80 void setMoveRoll(float value); 81 void setMoveLongitudinal(float value); 82 void setMoveLateral(float value); 83 void doFire(); 80 84 81 85 float getMaxSpeed(); 86 Vector3 getDir(); 87 Vector3 getOrth(); 88 Camera* getCamera(); 89 90 int getTeamNr() const 91 { return this->teamNr_; } 92 int getHealth() const 93 { return this->health_; } 94 95 bool getMyShip(){return myShip_;} 96 97 protected: 98 void setTeamNr(int teamNr) 99 { this->teamNr_ = teamNr; } 82 100 83 101 private: 84 102 void createCamera(); 103 virtual ColourValue getProjectileColour() const 104 { return ColourValue(1.0, 1.0, 0.5); } 85 105 86 106 Vector3 testvector_; 107 Vector3 initialDir_; 108 Vector3 currentDir_; 109 Vector3 initialOrth_; 110 Vector3 currentOrth_; 87 111 bool bInvertYAxis_; 88 112 bool setMouseEventCallback_; … … 130 154 131 155 float emitterRate_; 132 bool server_; 156 157 protected: 158 bool myShip_; 159 160 int teamNr_; 161 int health_; 162 163 static SpaceShip* instance_s; 133 164 }; 134 165 } -
TabularUnified code/trunk/src/orxonox/objects/WorldEntity.cc ¶
r1360 r1502 85 85 this->rotationRate_ += (dt * this->momentum_); 86 86 this->rotate(this->rotationAxis_, dt * this->rotationRate_); 87 //COUT(3) << "rotationrate: " << this->rotationRate_.valueDegrees() << " momentum: " << this->momentum_.valueDegrees() << std::endl; 87 88 } 88 89 } … … 153 154 registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3); 154 155 //register acceleration & momentum 155 registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);156 registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);157 registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);158 registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA); 156 // registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2); 157 // registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2); 158 // registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2); 159 // registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync 159 160 } 160 161 -
TabularUnified code/trunk/src/orxonox/objects/WorldEntity.h ¶
r1227 r1502 53 53 virtual void loadParams(TiXmlElement* xmlElem); 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 inline bool create(){ return true; }55 virtual inline bool create(){ return Synchronisable::create(); } 56 56 57 57 void attachWorldEntity(WorldEntity* entity); -
TabularUnified code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h ¶
r1056 r1502 60 60 61 61 protected: 62 inline bool create() { return true; }62 inline bool create() { return Synchronisable::create(); } 63 63 void registerAllVariables(); 64 64 -
TabularUnified code/trunk/src/orxonox/objects/weapon/BulletManager.h ¶
r1209 r1502 60 60 61 61 protected: 62 inline bool create() { return true; }62 inline bool create() { return Synchronisable::create(); } 63 63 void registerAllVariables(); 64 64 -
TabularUnified code/trunk/src/orxonox/tools/Mesh.cc ¶
r1056 r1502 40 40 unsigned int Mesh::meshCounter_s = 0; 41 41 42 Mesh::Mesh() 42 Mesh::Mesh() : 43 entity_(0) 43 44 { 44 this->entity_ = 0;45 45 } 46 46 -
TabularUnified code/trunk/src/orxonox/tools/Timer.cc ¶
r1293 r1502 27 27 */ 28 28 29 #include <set> 30 29 31 #include "OrxonoxStableHeaders.h" 30 32 #include "Timer.h" … … 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutExtern(delay, AccessLevel::None); 41 SetConsoleCommandShortcutExtern(delay); 42 SetConsoleCommandShortcutExtern(killdelays); 43 44 static std::set<StaticTimer*> delaytimerset; 40 45 41 46 /** … … 47 52 { 48 53 StaticTimer *delaytimer = new StaticTimer(); 54 delaytimerset.insert(delaytimer); 55 49 56 ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 50 57 delayexecutor->setDefaultValues(delaytimer, command); … … 61 68 CommandExecutor::execute(command); 62 69 delete timer; 70 delaytimerset.erase(timer); 71 } 72 73 /** 74 @brief Kills all delayed commands. 75 */ 76 void killdelays() 77 { 78 for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it) 79 delete (*it); 80 81 delaytimerset.clear(); 63 82 } 64 83 -
TabularUnified code/trunk/src/orxonox/tools/Timer.h ¶
r1056 r1502 69 69 class StaticTimer; 70 70 void delay(float delay, const std::string& command); 71 void killdelays(); 71 72 void executeDelayedCommand(StaticTimer* timer, const std::string& command); 72 73 -
TabularUnified code/trunk/src/util/Convert.h ¶
r1064 r1502 384 384 else if (input.getType() == MT_vector3) 385 385 return ConvertValue(output, input.getVector3()); 386 else if (input.getType() == MT_vector4) 387 return ConvertValue(output, input.getVector4()); 386 388 else if (input.getType() == MT_quaternion) 387 389 return ConvertValue(output, input.getQuaternion()); -
TabularUnified code/trunk/src/util/Math.h ¶
r1349 r1502 121 121 122 122 template <typename T> 123 inline int mod(T x, int max) 124 { 125 if (x >= 0) 126 return (x % max); 127 else 128 return ((x % max) + max); 129 } 130 131 template <typename T> 123 132 T interpolate(float time, const T& start, const T& end) 124 133 { -
TabularUnified code/trunk/src/util/MultiType.h ¶
r1056 r1502 54 54 MT_vector2, 55 55 MT_vector3, 56 MT_vector4, 56 57 MT_colourvalue, 57 58 MT_quaternion, -
TabularUnified code/trunk/src/util/MultiTypeMath.cc ¶
r1056 r1502 37 37 else if (type == MT_vector3) 38 38 this->vector3_ = orxonox::Vector3(0, 0, 0); 39 else if (type == MT_vector4) 40 this->vector4_ = orxonox::Vector4(0, 0, 0, 0); 39 41 else if (type == MT_colourvalue) 40 42 this->colourvalue_ = orxonox::ColourValue(0, 0, 0, 0); … … 55 57 else if (this->type_ == MT_vector3) 56 58 return (this->vector3_ == mtm.vector3_); 59 else if (this->type_ == MT_vector4) 60 return (this->vector4_ == mtm.vector4_); 57 61 else if (this->type_ == MT_colourvalue) 58 62 return (this->colourvalue_ == mtm.colourvalue_); … … 68 72 } 69 73 74 bool MultiTypeMath::operator==(const MultiTypeString& mts) const 75 { 76 return MultiTypeString::operator==(mts); 77 } 78 79 bool MultiTypeMath::operator==(const MultiTypePrimitive& mtp) const 80 { 81 return MultiTypePrimitive::operator==(mtp); 82 } 83 70 84 bool MultiTypeMath::operator!=(const MultiTypeMath& mtm) const 71 85 { … … 76 90 else if (this->type_ == MT_vector3) 77 91 return (this->vector3_ != mtm.vector3_); 92 else if (this->type_ == MT_vector4) 93 return (this->vector4_ != mtm.vector4_); 78 94 else if (this->type_ == MT_colourvalue) 79 95 return (this->colourvalue_ != mtm.colourvalue_); … … 87 103 88 104 return true; 105 } 106 107 bool MultiTypeMath::operator!=(const MultiTypeString& mts) const 108 { 109 return MultiTypeString::operator!=(mts); 110 } 111 112 bool MultiTypeMath::operator!=(const MultiTypePrimitive& mtp) const 113 { 114 return MultiTypePrimitive::operator!=(mtp); 89 115 } 90 116 … … 123 149 MultiTypeMath::operator orxonox::Vector3() const 124 150 { return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); } 151 MultiTypeMath::operator orxonox::Vector4() const 152 { return (this->type_ == MT_vector4) ? this->vector4_ : getConvertedValue<MultiTypeMath, orxonox::Vector4>(*this); } 125 153 MultiTypeMath::operator orxonox::Quaternion() const 126 154 { return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); } … … 137 165 this->vector2_ = mtm.vector2_; 138 166 this->vector3_ = mtm.vector3_; 167 this->vector4_ = mtm.vector4_; 139 168 this->quaternion_ = mtm.quaternion_; 140 169 this->colourvalue_ = mtm.colourvalue_; … … 143 172 } 144 173 174 void MultiTypeMath::setValue(const MultiTypeString& mts) 175 { 176 MultiTypeString::setValue(mts); 177 } 178 179 void MultiTypeMath::setValue(const MultiTypePrimitive& mtp) 180 { 181 MultiTypePrimitive::setValue(mtp); 182 } 183 145 184 std::string MultiTypeMath::getTypename() const 146 185 { … … 149 188 else if (this->type_ == MT_vector3) 150 189 return "Vector3"; 190 else if (this->type_ == MT_vector4) 191 return "Vector4"; 151 192 else if (this->type_ == MT_colourvalue) 152 193 return "ColourValue"; … … 169 210 else if (this->type_ == MT_vector3) 170 211 ConvertValue(&output, this->vector3_); 212 else if (this->type_ == MT_vector4) 213 ConvertValue(&output, this->vector4_); 171 214 else if (this->type_ == MT_colourvalue) 172 215 ConvertValue(&output, this->colourvalue_); … … 189 232 else if (this->type_ == MT_vector3) 190 233 return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0)); 234 else if (this->type_ == MT_vector4) 235 return ConvertValue(&this->vector4_, value, orxonox::Vector4(0, 0, 0, 0)); 191 236 else if (this->type_ == MT_colourvalue) 192 237 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); … … 201 246 } 202 247 248 bool MultiTypeMath::assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue) 249 { 250 if (this->type_ == MT_void) 251 return ConvertValue(&this->value_.void_, mtm, defvalue.value_.void_); 252 else if (this->type_ == MT_int) 253 return ConvertValue(&this->value_.int_, mtm, defvalue.value_.int_); 254 else if (this->type_ == MT_uint) 255 return ConvertValue(&this->value_.uint_, mtm, defvalue.value_.uint_); 256 else if (this->type_ == MT_char) 257 return ConvertValue(&this->value_.char_, mtm, defvalue.value_.char_); 258 else if (this->type_ == MT_uchar) 259 return ConvertValue(&this->value_.uchar_, mtm, defvalue.value_.uchar_); 260 else if (this->type_ == MT_short) 261 return ConvertValue(&this->value_.short_, mtm, defvalue.value_.short_); 262 else if (this->type_ == MT_ushort) 263 return ConvertValue(&this->value_.ushort_, mtm, defvalue.value_.ushort_); 264 else if (this->type_ == MT_long) 265 return ConvertValue(&this->value_.long_, mtm, defvalue.value_.long_); 266 else if (this->type_ == MT_ulong) 267 return ConvertValue(&this->value_.ulong_, mtm, defvalue.value_.ulong_); 268 else if (this->type_ == MT_float) 269 return ConvertValue(&this->value_.float_, mtm, defvalue.value_.float_); 270 else if (this->type_ == MT_double) 271 return ConvertValue(&this->value_.double_, mtm, defvalue.value_.double_); 272 else if (this->type_ == MT_longdouble) 273 return ConvertValue(&this->value_.longdouble_, mtm, defvalue.value_.longdouble_); 274 else if (this->type_ == MT_bool) 275 return ConvertValue(&this->value_.bool_, mtm, defvalue.value_.bool_); 276 else if (this->type_ == MT_constchar) 277 return ConvertValue(&this->string_, mtm, defvalue.string_); 278 else if (this->type_ == MT_string) 279 return ConvertValue(&this->string_, mtm, defvalue.string_); 280 else if (this->type_ == MT_vector2) 281 return ConvertValue(&this->vector2_, mtm, defvalue.vector2_); 282 else if (this->type_ == MT_vector3) 283 return ConvertValue(&this->vector3_, mtm, defvalue.vector3_); 284 else if (this->type_ == MT_vector4) 285 return ConvertValue(&this->vector4_, mtm, defvalue.vector4_); 286 else if (this->type_ == MT_colourvalue) 287 return ConvertValue(&this->colourvalue_, mtm, defvalue.colourvalue_); 288 else if (this->type_ == MT_quaternion) 289 return ConvertValue(&this->quaternion_, mtm, defvalue.quaternion_); 290 else if (this->type_ == MT_radian) 291 return ConvertValue(&this->radian_, mtm, defvalue.radian_); 292 else if (this->type_ == MT_degree) 293 return ConvertValue(&this->degree_, mtm, defvalue.degree_); 294 else 295 return false; 296 } 297 203 298 std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm) 204 299 { -
TabularUnified code/trunk/src/util/MultiTypeMath.h ¶
r1064 r1502 63 63 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 64 64 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } 65 inline MultiTypeMath(const orxonox::Vector4& value) { this->setValue(value); } 65 66 inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); } 66 67 inline MultiTypeMath(const orxonox::Quaternion& value) { this->setValue(value); } … … 68 69 inline MultiTypeMath(const orxonox::Degree& value) { this->setValue(value); } 69 70 inline MultiTypeMath(const MultiTypeMath& mtm) { this->setValue(mtm); } 71 inline MultiTypeMath(const MultiTypeString& mts) { this->setValue(mts); } 72 inline MultiTypeMath(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 70 73 virtual inline ~MultiTypeMath() {} 71 74 … … 73 76 inline MultiTypeMath& operator=(const orxonox::Vector2& value) { this->setValue(value); return *this; } 74 77 inline MultiTypeMath& operator=(const orxonox::Vector3& value) { this->setValue(value); return *this; } 78 inline MultiTypeMath& operator=(const orxonox::Vector4& value) { this->setValue(value); return *this; } 75 79 inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; } 76 80 inline MultiTypeMath& operator=(const orxonox::Quaternion& value) { this->setValue(value); return *this; } … … 78 82 inline MultiTypeMath& operator=(const orxonox::Degree& value) { this->setValue(value); return *this; } 79 83 inline MultiTypeMath& operator=(const MultiTypeMath& mtm) { this->setValue(mtm); return *this; } 84 inline MultiTypeMath& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 85 inline MultiTypeMath& operator=(const MultiTypePrimitive mtp) { this->setValue(mtp); return *this; } 80 86 81 87 using MultiTypeString::operator==; 82 88 inline bool operator==(const orxonox::Vector2& value) const { return (this->vector2_ == value); } 83 89 inline bool operator==(const orxonox::Vector3& value) const { return (this->vector3_ == value); } 90 inline bool operator==(const orxonox::Vector4& value) const { return (this->vector4_ == value); } 84 91 inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); } 85 92 inline bool operator==(const orxonox::Quaternion& value) const { return (this->quaternion_ == value); } … … 87 94 inline bool operator==(const orxonox::Degree& value) const { return (this->degree_ == value); } 88 95 bool operator==(const MultiTypeMath& mtm) const; 96 bool operator==(const MultiTypeString& mts) const; 97 bool operator==(const MultiTypePrimitive& mtp) const; 89 98 90 99 using MultiTypeString::operator!=; 91 100 inline bool operator!=(const orxonox::Vector2& value) const { return (this->vector2_ != value); } 92 101 inline bool operator!=(const orxonox::Vector3& value) const { return (this->vector3_ != value); } 102 inline bool operator!=(const orxonox::Vector4& value) const { return (this->vector4_ != value); } 93 103 inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); } 94 104 inline bool operator!=(const orxonox::Quaternion& value) const { return (this->quaternion_ != value); } … … 96 106 inline bool operator!=(const orxonox::Degree& value) const { return (this->degree_ != value); } 97 107 bool operator!=(const MultiTypeMath& mtm) const; 108 bool operator!=(const MultiTypeString& mts) const; 109 bool operator!=(const MultiTypePrimitive& mtp) const; 98 110 99 111 virtual operator void*() const; … … 114 126 virtual operator orxonox::Vector2() const; 115 127 virtual operator orxonox::Vector3() const; 128 virtual operator orxonox::Vector4() const; 116 129 virtual operator orxonox::ColourValue() const; 117 130 virtual operator orxonox::Quaternion() const; … … 122 135 inline void setValue(const orxonox::Vector2& value) { this->type_ = MT_vector2; this->vector2_ = value; } 123 136 inline void setValue(const orxonox::Vector3& value) { this->type_ = MT_vector3; this->vector3_ = value; } 137 inline void setValue(const orxonox::Vector4& value) { this->type_ = MT_vector4; this->vector4_ = value; } 124 138 inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; } 125 139 inline void setValue(const orxonox::Quaternion& value) { this->type_ = MT_quaternion; this->quaternion_ = value; } … … 127 141 inline void setValue(const orxonox::Degree& value) { this->type_ = MT_degree; this->degree_ = value; } 128 142 void setValue(const MultiTypeMath& mtm); 143 void setValue(const MultiTypeString& mts); 144 void setValue(const MultiTypePrimitive& mtp); 129 145 130 146 inline orxonox::Vector2 getVector2() const { return this->vector2_; } 131 147 inline orxonox::Vector3 getVector3() const { return this->vector3_; } 148 inline orxonox::Vector4 getVector4() const { return this->vector4_; } 132 149 inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; } 133 150 inline orxonox::Quaternion getQuaternion() const { return this->quaternion_; } … … 137 154 inline orxonox::Vector2& getVector2() { return this->vector2_; } 138 155 inline orxonox::Vector3& getVector3() { return this->vector3_; } 156 inline orxonox::Vector4& getVector4() { return this->vector4_; } 139 157 inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; } 140 158 inline orxonox::Quaternion& getQuaternion() { return this->quaternion_; } … … 145 163 inline void getValue(orxonox::Vector2* variable) const { (*variable) = orxonox::Vector2 (this->vector2_); } 146 164 inline void getValue(orxonox::Vector3* variable) const { (*variable) = orxonox::Vector3 (this->vector3_); } 165 inline void getValue(orxonox::Vector4* variable) const { (*variable) = orxonox::Vector4 (this->vector4_); } 147 166 inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); } 148 167 inline void getValue(orxonox::Quaternion* variable) const { (*variable) = orxonox::Quaternion (this->quaternion_); } … … 155 174 virtual bool fromString(const std::string value); 156 175 176 virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath()); 177 157 178 protected: 158 179 orxonox::Vector2 vector2_; 159 180 orxonox::Vector3 vector3_; 181 orxonox::Vector4 vector4_; 160 182 orxonox::ColourValue colourvalue_; 161 183 orxonox::Quaternion quaternion_; -
TabularUnified code/trunk/src/util/MultiTypePrimitive.cc ¶
r1056 r1502 266 266 } 267 267 268 bool MultiTypePrimitive::assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue) 269 { 270 if (this->type_ == MT_void) 271 return ConvertValue(&this->value_.void_, mtp, defvalue.value_.void_); 272 else if (this->type_ == MT_int) 273 return ConvertValue(&this->value_.int_, mtp, defvalue.value_.int_); 274 else if (this->type_ == MT_uint) 275 return ConvertValue(&this->value_.uint_, mtp, defvalue.value_.uint_); 276 else if (this->type_ == MT_char) 277 return ConvertValue(&this->value_.char_, mtp, defvalue.value_.char_); 278 else if (this->type_ == MT_uchar) 279 return ConvertValue(&this->value_.uchar_, mtp, defvalue.value_.uchar_); 280 else if (this->type_ == MT_short) 281 return ConvertValue(&this->value_.short_, mtp, defvalue.value_.short_); 282 else if (this->type_ == MT_ushort) 283 return ConvertValue(&this->value_.ushort_, mtp, defvalue.value_.ushort_); 284 else if (this->type_ == MT_long) 285 return ConvertValue(&this->value_.long_, mtp, defvalue.value_.long_); 286 else if (this->type_ == MT_ulong) 287 return ConvertValue(&this->value_.ulong_, mtp, defvalue.value_.ulong_); 288 else if (this->type_ == MT_float) 289 return ConvertValue(&this->value_.float_, mtp, defvalue.value_.float_); 290 else if (this->type_ == MT_double) 291 return ConvertValue(&this->value_.double_, mtp, defvalue.value_.double_); 292 else if (this->type_ == MT_longdouble) 293 return ConvertValue(&this->value_.longdouble_, mtp, defvalue.value_.longdouble_); 294 else if (this->type_ == MT_bool) 295 return ConvertValue(&this->value_.bool_, mtp, defvalue.value_.bool_); 296 else 297 return false; 298 299 } 300 268 301 std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp) 269 302 { -
TabularUnified code/trunk/src/util/MultiTypePrimitive.h ¶
r1062 r1502 138 138 void setValue(const MultiTypePrimitive& mtp); 139 139 140 inline void* getVoid() const { return this->value_.void_; 140 inline void* getVoid() const { return this->value_.void_; } 141 141 inline int getInt() const { return this->value_.int_; } 142 142 inline unsigned int getUnsignedInt() const { return this->value_.uint_; } … … 187 187 virtual bool fromString(const std::string value); 188 188 189 virtual bool assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue = MultiTypePrimitive()); 190 189 191 protected: 190 192 MultiTypeValue value_; -
TabularUnified code/trunk/src/util/MultiTypeString.cc ¶
r1064 r1502 33 33 MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type) 34 34 { 35 // Nothing to do for string and xml-element35 // Nothing to do for string 36 36 } 37 37 … … 49 49 } 50 50 51 bool MultiTypeString::operator==(const MultiTypePrimitive& mtp) const 52 { 53 return MultiTypePrimitive::operator==(mtp); 54 } 55 51 56 bool MultiTypeString::operator!=(const MultiTypeString& mts) const 52 57 { … … 60 65 61 66 return true; 67 } 68 69 bool MultiTypeString::operator!=(const MultiTypePrimitive& mtp) const 70 { 71 return MultiTypePrimitive::operator!=(mtp); 62 72 } 63 73 … … 99 109 } 100 110 111 void MultiTypeString::setValue(const MultiTypePrimitive& mtp) 112 { 113 MultiTypePrimitive::setValue(mtp); 114 } 115 101 116 std::string MultiTypeString::getTypename() const 102 117 { … … 136 151 } 137 152 153 bool MultiTypeString::assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue) 154 { 155 if (this->type_ == MT_void) 156 return ConvertValue(&this->value_.void_, mts, defvalue.value_.void_); 157 else if (this->type_ == MT_int) 158 return ConvertValue(&this->value_.int_, mts, defvalue.value_.int_); 159 else if (this->type_ == MT_uint) 160 return ConvertValue(&this->value_.uint_, mts, defvalue.value_.uint_); 161 else if (this->type_ == MT_char) 162 return ConvertValue(&this->value_.char_, mts, defvalue.value_.char_); 163 else if (this->type_ == MT_uchar) 164 return ConvertValue(&this->value_.uchar_, mts, defvalue.value_.uchar_); 165 else if (this->type_ == MT_short) 166 return ConvertValue(&this->value_.short_, mts, defvalue.value_.short_); 167 else if (this->type_ == MT_ushort) 168 return ConvertValue(&this->value_.ushort_, mts, defvalue.value_.ushort_); 169 else if (this->type_ == MT_long) 170 return ConvertValue(&this->value_.long_, mts, defvalue.value_.long_); 171 else if (this->type_ == MT_ulong) 172 return ConvertValue(&this->value_.ulong_, mts, defvalue.value_.ulong_); 173 else if (this->type_ == MT_float) 174 return ConvertValue(&this->value_.float_, mts, defvalue.value_.float_); 175 else if (this->type_ == MT_double) 176 return ConvertValue(&this->value_.double_, mts, defvalue.value_.double_); 177 else if (this->type_ == MT_longdouble) 178 return ConvertValue(&this->value_.longdouble_, mts, defvalue.value_.longdouble_); 179 else if (this->type_ == MT_bool) 180 return ConvertValue(&this->value_.bool_, mts, defvalue.value_.bool_); 181 else if (this->type_ == MT_constchar) 182 return ConvertValue(&this->string_, mts, defvalue.string_); 183 else if (this->type_ == MT_string) 184 return ConvertValue(&this->string_, mts, defvalue.string_); 185 else 186 return false; 187 } 188 138 189 std::ostream& operator<<(std::ostream& out, MultiTypeString& mts) 139 190 { -
TabularUnified code/trunk/src/util/MultiTypeString.h ¶
r1064 r1502 61 61 inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} 62 62 inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} 63 inline MultiTypeString(const char* value) { this->setValue(value); } 64 inline MultiTypeString(const std::string& value) { this->setValue(value); } 65 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 63 inline MultiTypeString(const char* value) { this->setValue(value); } 64 inline MultiTypeString(const std::string& value) { this->setValue(value); } 65 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 66 inline MultiTypeString(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 66 67 virtual inline ~MultiTypeString() {} 67 68 68 69 using MultiTypePrimitive::operator=; 69 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 70 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 71 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 70 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 71 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 72 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 73 inline MultiTypeString& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } 72 74 73 75 using MultiTypePrimitive::operator==; 74 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 75 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 76 bool operator==(const MultiTypeString& mts) const; 76 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 77 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 78 bool operator==(const MultiTypeString& mts) const; 79 bool operator==(const MultiTypePrimitive& mtp) const; 77 80 78 81 using MultiTypePrimitive::operator!=; 79 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 80 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 81 bool operator!=(const MultiTypeString& mts) const; 82 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 83 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 84 bool operator!=(const MultiTypeString& mts) const; 85 bool operator!=(const MultiTypePrimitive& mtp) const; 82 86 83 virtual operator void*() 84 virtual operator int() 85 virtual operator unsigned int() 86 virtual operator char() 87 virtual operator unsigned char() 88 virtual operator short() 89 virtual operator unsigned short() 90 virtual operator long() 91 virtual operator unsigned long() 92 virtual operator float () 93 virtual operator double () 94 virtual operator long double() 95 virtual operator bool() 96 virtual operator std::string() 97 virtual operator const char*() 87 virtual operator void*() const; 88 virtual operator int() const; 89 virtual operator unsigned int() const; 90 virtual operator char() const; 91 virtual operator unsigned char() const; 92 virtual operator short() const; 93 virtual operator unsigned short() const; 94 virtual operator long() const; 95 virtual operator unsigned long() const; 96 virtual operator float () const; 97 virtual operator double () const; 98 virtual operator long double() const; 99 virtual operator bool() const; 100 virtual operator std::string() const; 101 virtual operator const char*() const; 98 102 99 103 using MultiTypePrimitive::setValue; 100 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 101 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 102 void setValue(const MultiTypeString& mts); 104 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 105 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 106 void setValue(const MultiTypeString& mts); 107 void setValue(const MultiTypePrimitive& mtp); 103 108 104 inline std::string getString() 105 inline const char* getConstChar() 109 inline std::string getString() const { return this->string_; } 110 inline const char* getConstChar() const { return this->string_.c_str(); } 106 111 107 inline std::string& getString() 108 inline const char* getConstChar() 112 inline std::string& getString() { return this->string_; } 113 inline const char* getConstChar() { return this->string_.c_str(); } 109 114 110 115 using MultiTypePrimitive::getValue; 111 inline void getValue(std::string* 112 inline void getValue(const char** 116 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 117 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 113 118 114 119 virtual std::string getTypename() const; … … 116 121 virtual std::string toString() const; 117 122 virtual bool fromString(const std::string value); 123 124 virtual bool assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue = MultiTypeString()); 118 125 119 126 protected: -
TabularUnified code/trunk/src/util/String.cc ¶
r1219 r1502 108 108 109 109 unsigned int quotecount = 0; 110 unsigned int quote = 0;111 while ((quote = getNextQuote(str, quote )) < pos)110 unsigned int quote = (unsigned int)-1; 111 while ((quote = getNextQuote(str, quote + 1)) < pos) 112 112 { 113 113 quotecount++; … … 185 185 else 186 186 return str; 187 } 188 189 /** 190 @brief Removes enclosing {braces}. 191 @param str The string to strip 192 @return The striped string 193 */ 194 std::string stripEnclosingBraces(const std::string& str) 195 { 196 std::string output = str; 197 198 while (output.size() >= 2 && output[0] == '{' && output[output.size() - 1] == '}') 199 output = output.substr(1, output.size() - 2); 200 201 return output; 187 202 } 188 203 -
TabularUnified code/trunk/src/util/String.h ¶
r1062 r1502 47 47 48 48 _UtilExport std::string stripEnclosingQuotes(const std::string& str); 49 _UtilExport std::string stripEnclosingBraces(const std::string& str); 49 50 50 51 _UtilExport bool isEmpty(const std::string& str); -
TabularUnified code/trunk/src/util/UtilPrereqs.h ¶
r1062 r1502 35 35 #define _UtilPrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 //----------------------------------------------------------------------- -
TabularUnified code/trunk/visual_studio/base_properties_release.vsprops ¶
r1024 r1502 9 9 Name="VCCLCompilerTool" 10 10 Optimization="2" 11 WholeProgramOptimization=" true"11 WholeProgramOptimization="false" 12 12 PreprocessorDefinitions="NDEBUG" 13 13 RuntimeLibrary="2" -
TabularUnified code/trunk/visual_studio/vc8/core.vcproj ¶
r1293 r1502 149 149 > 150 150 <File 151 RelativePath="..\..\src\core\BaseObject.cc"152 >153 </File>154 <File155 RelativePath="..\..\src\core\ClassTreeMask.cc"156 >157 </File>158 <File159 RelativePath="..\..\src\core\CommandExecutor.cc"160 >161 </File>162 <File163 151 RelativePath="..\..\src\core\ConfigFileManager.cc" 164 152 > … … 177 165 </File> 178 166 <File 179 RelativePath="..\..\src\core\Executor.cc"180 >181 </File>182 <File183 RelativePath="..\..\src\core\Factory.cc"184 >185 </File>186 <File187 RelativePath="..\..\src\core\Identifier.cc"188 >189 </File>190 <File191 RelativePath="..\..\src\core\IdentifierDistributor.cc"192 >193 </File>194 <File195 RelativePath="..\..\src\core\InputBuffer.cc"196 >197 </File>198 <File199 RelativePath="..\..\src\core\InputHandler.cc"200 >201 </File>202 <File203 RelativePath="..\..\src\core\InputManager.cc"204 >205 </File>206 <File207 167 RelativePath="..\..\src\core\Language.cc" 208 168 > 209 169 </File> 210 170 <File 211 RelativePath="..\..\src\core\Loader.cc"212 >213 </File>214 <File215 RelativePath="..\..\src\core\MetaObjectList.cc"216 >217 </File>218 <File219 RelativePath="..\..\src\core\Namespace.cc"220 >221 </File>222 <File223 RelativePath="..\..\src\core\NamespaceNode.cc"224 >225 </File>226 <File227 171 RelativePath="..\..\src\core\OrxonoxClass.cc" 228 172 > 229 173 </File> 230 174 <File 175 RelativePath="..\..\src\core\OutputBuffer.cc" 176 > 177 </File> 178 <File 231 179 RelativePath="..\..\src\core\OutputHandler.cc" 232 180 > … … 241 189 </File> 242 190 <File 243 RelativePath="..\..\src\core\TclBind.cc"244 >245 </File>246 <File247 191 RelativePath="..\..\src\core\Tickable.cc" 248 192 > 249 193 </File> 250 <File251 RelativePath="..\..\src\core\XMLPort.cc"252 >253 </File>254 194 <Filter 255 195 Name="tolua" … … 257 197 <File 258 198 RelativePath="..\..\src\core\tolua\tolua_bind.cc" 199 > 200 </File> 201 </Filter> 202 <Filter 203 Name="command" 204 > 205 <File 206 RelativePath="..\..\src\core\ArgumentCompletionFunctions.cc" 207 > 208 </File> 209 <File 210 RelativePath="..\..\src\core\CommandEvaluation.cc" 211 > 212 </File> 213 <File 214 RelativePath="..\..\src\core\CommandExecutor.cc" 215 > 216 </File> 217 <File 218 RelativePath="..\..\src\core\ConsoleCommand.cc" 219 > 220 </File> 221 <File 222 RelativePath="..\..\src\core\ConsoleCommandCompilation.cc" 223 > 224 </File> 225 <File 226 RelativePath="..\..\src\core\Executor.cc" 227 > 228 </File> 229 </Filter> 230 <Filter 231 Name="hierarchy" 232 > 233 <File 234 RelativePath="..\..\src\core\Factory.cc" 235 > 236 </File> 237 <File 238 RelativePath="..\..\src\core\Identifier.cc" 239 > 240 </File> 241 <File 242 RelativePath="..\..\src\core\IdentifierDistributor.cc" 243 > 244 </File> 245 <File 246 RelativePath="..\..\src\core\MetaObjectList.cc" 247 > 248 </File> 249 </Filter> 250 <Filter 251 Name="level" 252 > 253 <File 254 RelativePath="..\..\src\core\BaseObject.cc" 255 > 256 </File> 257 <File 258 RelativePath="..\..\src\core\ClassTreeMask.cc" 259 > 260 </File> 261 <File 262 RelativePath="..\..\src\core\Loader.cc" 263 > 264 </File> 265 <File 266 RelativePath="..\..\src\core\Namespace.cc" 267 > 268 </File> 269 <File 270 RelativePath="..\..\src\core\NamespaceNode.cc" 271 > 272 </File> 273 <File 274 RelativePath="..\..\src\core\XMLPort.cc" 275 > 276 </File> 277 </Filter> 278 <Filter 279 Name="input" 280 > 281 <File 282 RelativePath="..\..\src\core\InputBuffer.cc" 283 > 284 </File> 285 <File 286 RelativePath="..\..\src\core\InputManager.cc" 287 > 288 </File> 289 <File 290 RelativePath="..\..\src\core\KeyBinder.cc" 291 > 292 </File> 293 </Filter> 294 <Filter 295 Name="shell" 296 > 297 <File 298 RelativePath="..\..\src\core\IRC.cc" 299 > 300 </File> 301 <File 302 RelativePath="..\..\src\core\Shell.cc" 303 > 304 </File> 305 <File 306 RelativePath="..\..\src\core\TclBind.cc" 307 > 308 </File> 309 <File 310 RelativePath="..\..\src\core\TclThreadManager.cc" 259 311 > 260 312 </File> … … 267 319 > 268 320 <File 269 RelativePath="..\..\src\core\BaseObject.h"270 >271 </File>272 <File273 RelativePath="..\..\src\core\ClassFactory.h"274 >275 </File>276 <File277 RelativePath="..\..\src\core\ClassManager.h"278 >279 </File>280 <File281 RelativePath="..\..\src\core\ClassTreeMask.h"282 >283 </File>284 <File285 RelativePath="..\..\src\core\CommandExecutor.h"286 >287 </File>288 <File289 321 RelativePath="..\..\src\core\ConfigFileManager.h" 290 322 > … … 299 331 </File> 300 332 <File 301 RelativePath="..\..\src\core\ConsoleCommand.h"302 >303 </File>304 <File305 RelativePath="..\..\src\core\CoreIncludes.h"306 >307 </File>308 <File309 333 RelativePath="..\..\src\core\CorePrereqs.h" 310 334 > … … 323 347 </File> 324 348 <File 325 RelativePath="..\..\src\core\Executor.h"326 >327 </File>328 <File329 RelativePath="..\..\src\core\Factory.h"330 >331 </File>332 <File333 RelativePath="..\..\src\core\Functor.h"334 >335 </File>336 <File337 RelativePath="..\..\src\core\Identifier.h"338 >339 </File>340 <File341 RelativePath="..\..\src\core\IdentifierDistributor.h"342 >343 </File>344 <File345 RelativePath="..\..\src\core\InputBuffer.h"346 >347 </File>348 <File349 RelativePath="..\..\src\core\InputHandler.h"350 >351 </File>352 <File353 RelativePath="..\..\src\core\InputInterfaces.h"354 >355 </File>356 <File357 RelativePath="..\..\src\core\InputManager.h"358 >359 </File>360 <File361 RelativePath="..\..\src\core\Iterator.h"362 >363 </File>364 <File365 349 RelativePath="..\..\src\core\Language.h" 366 350 > 367 351 </File> 368 352 <File 369 RelativePath="..\..\src\core\Level.h"370 >371 </File>372 <File373 RelativePath="..\..\src\core\Loader.h"374 >375 </File>376 <File377 RelativePath="..\..\src\core\MetaObjectList.h"378 >379 </File>380 <File381 RelativePath="..\..\src\core\Namespace.h"382 >383 </File>384 <File385 RelativePath="..\..\src\core\NamespaceNode.h"386 >387 </File>388 <File389 RelativePath="..\..\src\core\ObjectList.h"390 >391 </File>392 <File393 353 RelativePath="..\..\src\core\OrxonoxClass.h" 394 354 > 395 355 </File> 396 356 <File 357 RelativePath="..\..\src\core\OutputBuffer.h" 358 > 359 </File> 360 <File 397 361 RelativePath="..\..\src\core\OutputHandler.h" 398 362 > … … 403 367 </File> 404 368 <File 369 RelativePath="..\..\src\core\Script_clean.h" 370 > 371 </File> 372 <File 405 373 RelativePath="..\..\src\core\SignalHandler.h" 406 374 > 407 375 </File> 408 376 <File 409 RelativePath="..\..\src\core\TclBind.h"410 >411 </File>412 <File413 377 RelativePath="..\..\src\core\Tickable.h" 414 378 > 415 379 </File> 416 <File 417 RelativePath="..\..\src\core\XMLPort.h" 418 > 419 </File> 380 <Filter 381 Name="input" 382 > 383 <File 384 RelativePath="..\..\src\core\InputBuffer.h" 385 > 386 </File> 387 <File 388 RelativePath="..\..\src\core\InputInterfaces.h" 389 > 390 </File> 391 <File 392 RelativePath="..\..\src\core\InputManager.h" 393 > 394 </File> 395 <File 396 RelativePath="..\..\src\core\KeyBinder.h" 397 > 398 </File> 399 </Filter> 400 <Filter 401 Name="command" 402 > 403 <File 404 RelativePath="..\..\src\core\ArgumentCompleter.h" 405 > 406 </File> 407 <File 408 RelativePath="..\..\src\core\ArgumentCompletionFunctions.h" 409 > 410 </File> 411 <File 412 RelativePath="..\..\src\core\ArgumentCompletionListElement.h" 413 > 414 </File> 415 <File 416 RelativePath="..\..\src\core\CommandEvaluation.h" 417 > 418 </File> 419 <File 420 RelativePath="..\..\src\core\CommandExecutor.h" 421 > 422 </File> 423 <File 424 RelativePath="..\..\src\core\ConsoleCommand.h" 425 > 426 </File> 427 <File 428 RelativePath="..\..\src\core\ConsoleCommandCompilation.h" 429 > 430 </File> 431 <File 432 RelativePath="..\..\src\core\Executor.h" 433 > 434 </File> 435 <File 436 RelativePath="..\..\src\core\Functor.h" 437 > 438 </File> 439 </Filter> 440 <Filter 441 Name="shell" 442 > 443 <File 444 RelativePath="..\..\src\core\IRC.h" 445 > 446 </File> 447 <File 448 RelativePath="..\..\src\core\Shell.h" 449 > 450 </File> 451 <File 452 RelativePath="..\..\src\core\TclBind.h" 453 > 454 </File> 455 <File 456 RelativePath="..\..\src\core\TclThreadManager.h" 457 > 458 </File> 459 </Filter> 460 <Filter 461 Name="hierarchy" 462 > 463 <File 464 RelativePath="..\..\src\core\ClassFactory.h" 465 > 466 </File> 467 <File 468 RelativePath="..\..\src\core\ClassManager.h" 469 > 470 </File> 471 <File 472 RelativePath="..\..\src\core\CoreIncludes.h" 473 > 474 </File> 475 <File 476 RelativePath="..\..\src\core\Factory.h" 477 > 478 </File> 479 <File 480 RelativePath="..\..\src\core\Identifier.h" 481 > 482 </File> 483 <File 484 RelativePath="..\..\src\core\IdentifierDistributor.h" 485 > 486 </File> 487 <File 488 RelativePath="..\..\src\core\Iterator.h" 489 > 490 </File> 491 <File 492 RelativePath="..\..\src\core\MetaObjectList.h" 493 > 494 </File> 495 <File 496 RelativePath="..\..\src\core\ObjectList.h" 497 > 498 </File> 499 </Filter> 500 <Filter 501 Name="level" 502 > 503 <File 504 RelativePath="..\..\src\core\BaseObject.h" 505 > 506 </File> 507 <File 508 RelativePath="..\..\src\core\ClassTreeMask.h" 509 > 510 </File> 511 <File 512 RelativePath="..\..\src\core\Level.h" 513 > 514 </File> 515 <File 516 RelativePath="..\..\src\core\Loader.h" 517 > 518 </File> 519 <File 520 RelativePath="..\..\src\core\Namespace.h" 521 > 522 </File> 523 <File 524 RelativePath="..\..\src\core\NamespaceNode.h" 525 > 526 </File> 527 <File 528 RelativePath="..\..\src\core\XMLPort.h" 529 > 530 </File> 531 </Filter> 420 532 <Filter 421 533 Name="tolua" -
TabularUnified code/trunk/visual_studio/vc8/orxonox.vcproj ¶
r1293 r1502 188 188 > 189 189 <File 190 RelativePath="..\..\src\orxonox\hud\BarOverlayElement.cc" 191 > 192 </File> 193 <File 190 194 RelativePath="..\..\src\orxonox\hud\HUD.cc" 191 195 > 192 196 </File> 197 <File 198 RelativePath="..\..\src\orxonox\hud\Navigation.cc" 199 > 200 </File> 201 <File 202 RelativePath="..\..\src\orxonox\hud\RadarObject.cc" 203 > 204 </File> 205 <File 206 RelativePath="..\..\src\orxonox\hud\RadarOverlayElement.cc" 207 > 208 </File> 193 209 </Filter> 194 210 <Filter … … 224 240 </File> 225 241 <File 242 RelativePath="..\..\src\orxonox\objects\RotatingProjectile.cc" 243 > 244 </File> 245 <File 226 246 RelativePath="..\..\src\orxonox\objects\Skybox.cc" 227 247 > … … 229 249 <File 230 250 RelativePath="..\..\src\orxonox\objects\SpaceShip.cc" 251 > 252 </File> 253 <File 254 RelativePath="..\..\src\orxonox\objects\SpaceShipAI.cc" 231 255 > 232 256 </File> … … 435 459 </File> 436 460 <File 437 RelativePath="..\..\src\orxonox\OrxonoxPlatform.h"438 >439 </File>440 <File441 461 RelativePath="..\..\src\orxonox\OrxonoxPrereqs.h" 442 462 > … … 450 470 > 451 471 <File 472 RelativePath="..\..\src\orxonox\hud\BarOverlayElement.h" 473 > 474 </File> 475 <File 452 476 RelativePath="..\..\src\orxonox\hud\HUD.h" 453 477 > 454 478 </File> 479 <File 480 RelativePath="..\..\src\orxonox\hud\Navigation.h" 481 > 482 </File> 483 <File 484 RelativePath="..\..\src\orxonox\hud\OverlayElementFactories.h" 485 > 486 </File> 487 <File 488 RelativePath="..\..\src\orxonox\hud\RadarObject.h" 489 > 490 </File> 491 <File 492 RelativePath="..\..\src\orxonox\hud\RadarOverlayElement.h" 493 > 494 </File> 455 495 </Filter> 456 496 <Filter … … 486 526 </File> 487 527 <File 528 RelativePath="..\..\src\orxonox\objects\RotatingProjectile.h" 529 > 530 </File> 531 <File 488 532 RelativePath="..\..\src\orxonox\objects\Skybox.h" 489 533 > … … 491 535 <File 492 536 RelativePath="..\..\src\orxonox\objects\SpaceShip.h" 537 > 538 </File> 539 <File 540 RelativePath="..\..\src\orxonox\objects\SpaceShipAI.h" 493 541 > 494 542 </File> -
TabularUnified code/trunk/visual_studio/vc8/util.vcproj ¶
r1126 r1502 227 227 </File> 228 228 <File 229 RelativePath="..\..\src\util\OrxonoxPlatform.h" 230 > 231 </File> 232 <File 229 233 RelativePath="..\..\src\util\Sleep.h" 230 234 >
Note: See TracChangeset
for help on using the changeset viewer.