Changeset 1446 for code/branches/network/src/orxonox/Orxonox.cc
- Timestamp:
- May 28, 2008, 5:30:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/Orxonox.cc
r1443 r1446 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"77 72 78 73 // FIXME: is this really file scope? … … 83 78 namespace orxonox 84 79 { 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); 80 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 81 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 82 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 152 83 153 84 /** … … 165 96 // turn on frame smoothing by setting a value different from 0 166 97 frameSmoothingTime_(0.0f), 167 orxonoxConsole_(0),168 98 orxonoxHUD_(0), 169 99 bAbort_(false), … … 351 281 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 352 282 orxonoxHUD_ = &HUD::getSingleton(); 353 354 COUT(3) << "Orxonox: Loading Console..." << std::endl;355 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));356 /*357 Testconsole* console = new Testconsole(ib);358 ib->registerListener(console, &Testconsole::listen, true);359 ib->registerListener(console, &Testconsole::execute, '\r', false);360 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);361 ib->registerListener(console, &Testconsole::clear, '�', true);362 ib->registerListener(console, &Testconsole::removeLast, '\b', true);363 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);364 */365 orxonoxConsole_ = new InGameConsole(ib);366 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);367 ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);368 ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);369 //ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);370 ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);371 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);372 373 283 return true; 374 284 } … … 495 405 renderTime = 0.0f; 496 406 } 497 407 498 408 // Call those objects that need the real time 499 409 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) … … 502 412 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 503 413 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 504 // TODO: currently a hack. Somehow the console doesn't work with OrxonoxClass505 orxonoxConsole_->tick((float)evt.timeSinceLastFrame);506 414 507 415 // don't forget to call _fireFrameStarted in ogre to make sure … … 571 479 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 572 480 } 573 574 /**575 * Static function that shows the console in game mode.576 */577 void Orxonox::activateConsole()578 {579 // currently, the console shows itself when feeded with input.580 InputManager::setInputState(InputManager::IS_CONSOLE);581 }582 481 }
Note: See TracChangeset
for help on using the changeset viewer.