Changeset 3304
- Timestamp:
- Jul 18, 2009, 6:23:31 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 39 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/netp6 (added) merged: 3215,3226-3227,3229-3231,3240,3242,3251-3252,3256,3258-3259,3263-3264,3267-3268,3277,3283-3284,3289,3298-3299,3302
- Property svn:mergeinfo changed
-
code/trunk/cmake/LibraryConfig.cmake
r3196 r3304 153 153 # Expand the next statement if newer boost versions than 1.36.1 are released 154 154 SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0) 155 # MSVC seems to be the only compiler requiring date_time 156 IF(MSVC) 157 FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem date_time) 158 ELSE(MSVC) 159 FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem) 160 ENDIF(MSVC) 161 # Boost 1.35 and newer also need the 'System' library 162 IF(NOT Boost_VERSION LESS 103500) 163 FIND_PACKAGE(Boost 1.35 REQUIRED system) 164 ENDIF() 155 FIND_PACKAGE(Boost 1.35 REQUIRED thread filesystem system date_time) 165 156 # No auto linking, so this option is useless anyway 166 157 MARK_AS_ADVANCED(Boost_LIB_DIAGNOSTIC_DEFINITIONS) 158 167 159 168 160 ####### Static/Dynamic linking options ########## -
code/trunk/src/core/CMakeLists.txt
r3280 r3304 61 61 TclBind.cc 62 62 TclThreadManager.cc 63 64 # multithreading 65 Thread.cc 66 ThreadPool.cc 63 67 ) 64 68 ADD_SUBDIRECTORY(input) -
code/trunk/src/core/Clock.cc
r3196 r3304 59 59 tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f; 60 60 61 if (timersTime > 0x 7FFFFFF0)61 if (timersTime > 0xFFFFFFFF/4) 62 62 { 63 63 // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit … … 74 74 unsigned long long Clock::getRealMicroseconds() const 75 75 { 76 return this->timer_->getMicroseconds() ;76 return this->timer_->getMicroseconds() + this->storedTime_; 77 77 } 78 78 } -
code/trunk/src/core/ConsoleCommand.h
r3280 r3304 32 32 #include "CorePrereqs.h" 33 33 34 #include <boost/preprocessor/cat.hpp> 35 34 36 #include "ArgumentCompletionFunctions.h" 35 37 #include "CommandExecutor.h" … … 39 41 40 42 #define SetConsoleCommand(classname, function, bCreateShortcut) \ 41 SetConsoleCommand AliasMulti(classname, function, #function, 0, bCreateShortcut)43 SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut) 42 44 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \ 43 SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut) 44 #define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \ 45 SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut) 45 SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) 46 46 47 #define SetConsoleCommandGeneric( fakevariable, classname, command, bCreateShortcut) \48 orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)47 #define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \ 48 orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut) 49 49 50 50 51 51 #define SetConsoleCommandShortcut(classname, function) \ 52 SetConsoleCommandShortcutAlias Multi(classname, function, #function, 0)52 SetConsoleCommandShortcutAliasGeneric(classname, function, #function) 53 53 #define SetConsoleCommandShortcutAlias(classname, function, name) \ 54 SetConsoleCommandShortcutAlias Multi(classname, function, name, 0)55 #define SetConsoleCommandShortcutAlias Multi(classname, function, name, number) \56 SetConsoleCommandShortcutGeneric( function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))54 SetConsoleCommandShortcutAliasGeneric(classname, function, name) 55 #define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \ 56 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name)) 57 57 58 58 #define SetConsoleCommandShortcutExtern(function) \ 59 SetConsoleCommandShortcutExternAlias Multi(function, #function, 0)59 SetConsoleCommandShortcutExternAliasGeneric(function, #function) 60 60 #define SetConsoleCommandShortcutExternAlias(function, name) \ 61 SetConsoleCommandShortcutExternAlias Multi(function, name, 0)62 #define SetConsoleCommandShortcutExternAlias Multi(function, name, number) \63 SetConsoleCommandShortcutGeneric( function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))61 SetConsoleCommandShortcutExternAliasGeneric(function, name) 62 #define SetConsoleCommandShortcutExternAliasGeneric(function, name) \ 63 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name)) 64 64 65 65 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ -
code/trunk/src/core/CorePrecompiledHeaders.h
r3214 r3304 60 60 #include <boost/shared_ptr.hpp> // 12 61 61 #include <boost/preprocessor/cat.hpp> // 12 62 // Included by both filesystem and thread but still relatively small63 #include <boost/iterator/iterator_facade.hpp> // 1064 62 65 63 // Just in case some header included windows.h -
code/trunk/src/core/CorePrereqs.h
r3280 r3304 150 150 class SubclassIdentifier; 151 151 class TclBind; 152 struct TclInterpreterBundle;153 152 class TclThreadManager; 154 153 class Template; … … 187 186 class SimpleCommand; 188 187 class SimpleInputState; 188 189 // multithreading 190 class Thread; 191 class ThreadPool; 189 192 } 190 193 … … 197 200 198 201 // Boost 199 namespace boost { namespace filesystem 200 { 201 struct path_traits; 202 template <class String, class Traits> class basic_path; 203 typedef basic_path<std::string, path_traits> path; 204 } } 202 namespace boost 203 { 204 namespace filesystem 205 { 206 struct path_traits; 207 template <class String, class Traits> class basic_path; 208 typedef basic_path<std::string, path_traits> path; 209 } 210 class thread; 211 class mutex; 212 } 205 213 206 214 // TinyXML and TinyXML++ -
code/trunk/src/core/Executor.h
r3301 r3304 246 246 virtual ~ExecutorMember() {} 247 247 248 using Executor::operator(); 249 248 250 inline void operator()(T* object) const 249 251 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } … … 278 280 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 279 281 282 using Executor::parse; 283 280 284 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 281 285 { -
code/trunk/src/core/Game.cc
r3300 r3304 40 40 #include "util/Debug.h" 41 41 #include "util/Exception.h" 42 #include "util/Sleep.h" 42 43 #include "util/SubString.h" 43 44 #include "Clock.h" … … 95 96 SetConfigValue(statisticsAvgLength_, 1000000) 96 97 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 98 SetConfigValue(fpsLimit_, 50) 99 .description("Sets the desired framerate (0 for no limit)."); 97 100 } 98 101 99 102 unsigned int statisticsRefreshCycle_; 100 103 unsigned int statisticsAvgLength_; 104 unsigned int fpsLimit_; 101 105 }; 102 106 … … 192 196 193 197 // START GAME 194 this->gameClock_->capture(); // first delta time should be about 0 seconds 198 // first delta time should be about 0 seconds 199 this->gameClock_->capture(); 200 // A first item is required for the fps limiter 201 StatisticsTickInfo tickInfo = {0, 0}; 202 statisticsTickTimes_.push_back(tickInfo); 195 203 while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0)) 196 204 { 205 uint64_t currentTime = this->gameClock_->getRealMicroseconds(); 206 207 uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_); 208 if (currentTime < nextTickTime) 209 { 210 usleep(nextTickTime - currentTime); 211 continue; 212 } 197 213 this->gameClock_->capture(); 198 uint64_t currentTime = this->gameClock_->getMicroseconds();199 214 200 215 // STATISTICS -
code/trunk/src/core/IRC.cc
r3301 r3304 47 47 { 48 48 RegisterRootObject(IRC); 49 this-> bundle_ = 0;49 this->interpreter_ = 0; 50 50 } 51 51 … … 54 54 unsigned int threadID = IRC_TCL_THREADID; 55 55 TclThreadManager::createID(threadID); 56 this-> bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);56 this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID); 57 57 58 58 try 59 59 { 60 this-> bundle_->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());61 this-> bundle_->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());62 this-> bundle_->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());63 this-> bundle_->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());60 this->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic()); 61 this->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic()); 62 this->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic()); 63 this->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic()); 64 64 } 65 65 catch (Tcl::tcl_error const &e) … … 81 81 bool IRC::eval(const std::string& command) 82 82 { 83 if (!IRC::getInstance(). bundle_)83 if (!IRC::getInstance().interpreter_) 84 84 { 85 85 IRC::getInstance().initialize(); … … 90 90 try 91 91 { 92 IRC::getInstance(). bundle_->interpreter_->eval(command);92 IRC::getInstance().interpreter_->eval(command); 93 93 return true; 94 94 } -
code/trunk/src/core/IRC.h
r3196 r3304 59 59 ~IRC() {} 60 60 61 Tcl InterpreterBundle* bundle_;61 Tcl::interpreter* interpreter_; 62 62 std::string nickname_; 63 63 }; -
code/trunk/src/core/TclThreadManager.cc
r3301 r3304 30 30 31 31 #include <boost/bind.hpp> 32 #include <boost/thread/condition.hpp> 33 #include <boost/thread/mutex.hpp> 34 #include <boost/thread/thread.hpp> 32 35 #include <OgreTimer.h> 33 36 #include <cpptcl/cpptcl.h> … … 56 59 SetConsoleCommand(TclThreadManager, flush, false).argumentCompleter(0, autocompletion::tclthreads()); 57 60 61 struct TclInterpreterBundle 62 { 63 unsigned int id_; 64 65 std::list<std::string> queue_; 66 boost::mutex queueMutex_; 67 68 Tcl::interpreter* interpreter_; 69 std::string interpreterName_; 70 boost::try_mutex interpreterMutex_; 71 72 std::list<unsigned int> queriers_; 73 boost::mutex queriersMutex_; 74 75 bool running_; 76 boost::mutex runningMutex_; 77 78 bool finished_; 79 boost::mutex finishedMutex_; 80 boost::condition finishedCondition_; 81 }; 82 83 84 static boost::thread::id threadID_g; 85 static boost::mutex bundlesMutex_g; 86 static boost::condition fullQueueCondition_g; 87 static boost::condition orxonoxEvalCondition_g; 88 58 89 TclThreadManager* TclThreadManager::singletonRef_s = 0; 59 90 60 91 TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter) 92 : orxonoxInterpreterBundle_(new TclInterpreterBundle()) 61 93 { 62 94 RegisterRootObject(TclThreadManager); … … 66 98 67 99 this->threadCounter_ = 0; 68 this->orxonoxInterpreterBundle_.id_ = 0; 69 this->orxonoxInterpreterBundle_.interpreter_ = interpreter; 70 #if (BOOST_VERSION >= 103500) 71 this->threadID_ = boost::this_thread::get_id(); 72 #else 73 // 74 #endif 100 this->orxonoxInterpreterBundle_->id_ = 0; 101 this->orxonoxInterpreterBundle_->interpreter_ = interpreter; 102 threadID_g = boost::this_thread::get_id(); 75 103 } 76 104 … … 79 107 unsigned int threadID; 80 108 { 81 boost::mutex::scoped_lock bundles_lock( this->bundlesMutex_);109 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 82 110 if (this->interpreterBundles_.begin() == this->interpreterBundles_.end()) 83 111 return; … … 87 115 this->destroy(threadID); 88 116 117 delete this->orxonoxInterpreterBundle_; 118 89 119 singletonRef_s = 0; 90 120 } … … 92 122 unsigned int TclThreadManager::create() 93 123 { 94 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);124 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 95 125 TclThreadManager::getInstance().threadCounter_++; 96 126 std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_); … … 132 162 if (bundle->finished_) 133 163 { 134 boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_); 135 #if (BOOST_VERSION >= 103500) 164 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 136 165 boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_); 137 #else138 boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);139 #endif140 166 try 141 167 { 142 168 while (!interpreter_lock.try_lock()) 143 169 { 144 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one(); 145 #if (BOOST_VERSION >= 103500) 170 orxonoxEvalCondition_g.notify_one(); 146 171 boost::this_thread::yield(); 147 #else148 boost::thread::yield();149 #endif150 172 } 151 173 } catch (...) {} … … 157 179 } 158 180 159 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one(); 160 #if (BOOST_VERSION >= 103500) 181 orxonoxEvalCondition_g.notify_one(); 161 182 boost::this_thread::yield(); 162 #else163 boost::thread::yield();164 #endif165 183 } 166 184 … … 181 199 std::string TclThreadManager::query(unsigned int threadID, const std::string& command) 182 200 { 183 return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .id_, threadID, command);201 return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command); 184 202 } 185 203 … … 191 209 output += "\t\t"; 192 210 { 193 boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .queueMutex_);194 output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .queue_.size());211 boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_); 212 output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size()); 195 213 } 196 214 output += "\t\t"; … … 198 216 COUT(0) << output << std::endl; 199 217 200 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);218 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 201 219 for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it) 202 220 { … … 209 227 output += "\t\t"; 210 228 { 211 #if (BOOST_VERSION >= 103500)212 229 boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_); 213 #else214 boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);215 #endif216 230 if (interpreter_lock.try_lock()) 217 231 output += "ready"; … … 228 242 if (threadID == 0) 229 243 { 230 bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;244 bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_; 231 245 COUT(0) << "Queue dump of Orxonox:" << std::endl; 232 246 } … … 254 268 TclInterpreterBundle* bundle = 0; 255 269 if (threadID == 0) 256 bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;270 bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_; 257 271 else 258 272 if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID))) … … 334 348 TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID) 335 349 { 336 boost::mutex::scoped_lock bundles_lock( this->bundlesMutex_);350 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 337 351 std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID); 338 352 if (it != this->interpreterBundles_.end()) … … 347 361 } 348 362 363 Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID) 364 { 365 return this->getInterpreterBundle(threadID)->interpreter_; 366 } 367 349 368 std::string TclThreadManager::dumpList(const std::list<unsigned int>& list) 350 369 { … … 362 381 void TclThreadManager::error(const std::string& error) 363 382 { 364 #if (BOOST_VERSION >= 103500) 365 if (boost::this_thread::get_id() != this->threadID_) 366 #else 367 if (boost::thread() != this->threadID_) 368 #endif 369 { 370 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_); 371 if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 372 { 373 #if (BOOST_VERSION >= 103500) 383 if (boost::this_thread::get_id() != threadID_g) 384 { 385 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 386 if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 387 { 374 388 boost::this_thread::yield(); 375 #else376 boost::thread::yield();377 #endif378 389 return; 379 390 } … … 385 396 void TclThreadManager::debug(const std::string& error) 386 397 { 387 #if (BOOST_VERSION >= 103500) 388 if (boost::this_thread::get_id() != this->threadID_) 389 #else 390 if (boost::thread() != this->threadID_) 391 #endif 392 { 393 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_); 394 if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 395 { 396 #if (BOOST_VERSION >= 103500) 398 if (boost::this_thread::get_id() != threadID_g) 399 { 400 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 401 if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 402 { 397 403 boost::this_thread::yield(); 398 #else399 boost::thread::yield();400 #endif401 404 return; 402 405 } … … 408 411 void TclThreadManager::pushCommandToQueue(const std::string& command) 409 412 { 410 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);411 while (this->orxonoxInterpreterBundle_ .queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)412 this->fullQueueCondition_.wait(queue_lock);413 414 this->orxonoxInterpreterBundle_ .queue_.push_back(command);413 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 414 while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 415 fullQueueCondition_g.wait(queue_lock); 416 417 this->orxonoxInterpreterBundle_->queue_.push_back(command); 415 418 } 416 419 417 420 void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command) 418 421 { 419 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);420 this->orxonoxInterpreterBundle_ .queue_.push_front(command);422 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 423 this->orxonoxInterpreterBundle_->queue_.push_front(command); 421 424 } 422 425 423 426 std::string TclThreadManager::popCommandFromQueue() 424 427 { 425 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);426 std::string temp = this->orxonoxInterpreterBundle_ .queue_.front();427 this->orxonoxInterpreterBundle_ .queue_.pop_front();428 this->fullQueueCondition_.notify_one();428 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 429 std::string temp = this->orxonoxInterpreterBundle_->queue_.front(); 430 this->orxonoxInterpreterBundle_->queue_.pop_front(); 431 fullQueueCondition_g.notify_one(); 429 432 return temp; 430 433 } … … 432 435 bool TclThreadManager::queueIsEmpty() 433 436 { 434 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);435 return this->orxonoxInterpreterBundle_ .queue_.empty();437 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 438 return this->orxonoxInterpreterBundle_->queue_.empty(); 436 439 } 437 440 … … 505 508 if (querier) 506 509 { 507 if (this->updateQueriersList(querier, &this->orxonoxInterpreterBundle_)) 508 { 509 #if (BOOST_VERSION >= 103500) 510 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 511 #else 512 boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 513 #endif 514 this->orxonoxEvalCondition_.wait(interpreter_lock); 510 if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_)) 511 { 512 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_); 513 orxonoxEvalCondition_g.wait(interpreter_lock); 515 514 516 515 if (!CommandExecutor::execute(command, false)) … … 521 520 } 522 521 523 boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_ .queriersMutex_);524 this->orxonoxInterpreterBundle_ .queriers_.clear();522 boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_); 523 this->orxonoxInterpreterBundle_->queriers_.clear(); 525 524 } 526 525 return output; … … 533 532 target = this->getInterpreterBundle(threadID); 534 533 else 535 target = &this->orxonoxInterpreterBundle_;534 target = this->orxonoxInterpreterBundle_; 536 535 537 536 std::string output = ""; … … 542 541 querier = this->getInterpreterBundle(querierID); 543 542 else 544 querier = &this->orxonoxInterpreterBundle_;543 querier = this->orxonoxInterpreterBundle_; 545 544 546 545 if (querier) … … 548 547 if (this->updateQueriersList(querier, target)) 549 548 { 550 #if (BOOST_VERSION >= 103500)551 549 boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_); 552 #else553 boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);554 #endif555 550 bool successfullyLocked = false; 556 551 try … … 562 557 while (!interpreter_lock.try_lock()) 563 558 { 564 #if (BOOST_VERSION >= 103500)565 559 boost::this_thread::yield(); 566 #else567 boost::thread::yield();568 #endif569 560 } 570 561 … … 599 590 { 600 591 { 601 this->orxonoxEvalCondition_.notify_one(); 602 #if (BOOST_VERSION >= 103500) 592 orxonoxEvalCondition_g.notify_one(); 603 593 boost::this_thread::yield(); 604 #else 605 boost::thread::yield(); 606 #endif 607 } 608 609 { 610 boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_); 594 } 595 596 { 597 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 611 598 for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it) 612 599 { … … 626 613 627 614 { 628 #if (BOOST_VERSION >= 103500) 629 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 630 #else 631 boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 632 #endif 615 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_); 633 616 unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE); 634 617 Ogre::Timer timer; … … 644 627 std::list<unsigned int> TclThreadManager::getThreadList() const 645 628 { 646 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);629 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 647 630 std::list<unsigned int> threads; 648 631 for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it) … … 654 637 { 655 638 TclThreadManager::getInstance().debug("TclThread_execute: " + command); 656 #if (BOOST_VERSION >= 103500)657 639 boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_); 658 #else659 boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);660 #endif661 640 try 662 641 { -
code/trunk/src/core/TclThreadManager.h
r3196 r3304 32 32 #include "CorePrereqs.h" 33 33 34 #include <cassert> 34 35 #include <list> 35 36 #include <map> 36 37 #include <string> 37 #include <boost/thread/condition.hpp>38 #include <boost/thread/mutex.hpp>39 #include <boost/thread/thread.hpp>40 41 38 #include "core/OrxonoxClass.h" 42 39 43 40 namespace orxonox 44 41 { 45 struct _CoreExport TclInterpreterBundle 46 { 47 unsigned int id_; 48 49 std::list<std::string> queue_; 50 boost::mutex queueMutex_; 51 52 Tcl::interpreter* interpreter_; 53 std::string interpreterName_; 54 boost::try_mutex interpreterMutex_; 55 56 std::list<unsigned int> queriers_; 57 boost::mutex queriersMutex_; 58 59 bool running_; 60 boost::mutex runningMutex_; 61 62 bool finished_; 63 boost::mutex finishedMutex_; 64 boost::condition finishedCondition_; 65 }; 42 // Internal struct 43 struct TclInterpreterBundle; 66 44 67 45 class _CoreExport TclThreadManager : public OrxonoxClass … … 101 79 102 80 Tcl::interpreter* createNewTclInterpreter(const std::string& threadID); 81 Tcl::interpreter* getTclInterpreter(unsigned int threadID); 103 82 TclInterpreterBundle* getInterpreterBundle(unsigned int threadID); 104 83 std::string dumpList(const std::list<unsigned int>& list); … … 119 98 120 99 unsigned int threadCounter_; 121 TclInterpreterBundle orxonoxInterpreterBundle_;100 TclInterpreterBundle* orxonoxInterpreterBundle_; 122 101 std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_; 123 boost::mutex bundlesMutex_;124 boost::condition fullQueueCondition_;125 boost::condition orxonoxEvalCondition_;126 #if (BOOST_VERSION >= 103500)127 boost::thread::id threadID_;128 #else129 boost::thread threadID_;130 #endif131 102 132 103 static TclThreadManager* singletonRef_s; -
code/trunk/src/network/CMakeLists.txt
r3214 r3304 31 31 NetworkFunction.cc 32 32 Host.cc 33 PacketBuffer.cc34 33 Server.cc 35 34 ServerConnection.cc -
code/trunk/src/network/ClientInformation.h
r3198 r3304 87 87 static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false); 88 88 static ClientInformation *getBegin(){return head_;} 89 static bool hasClients(){ return ClientInformation::head_!=0; } 89 90 90 91 bool setSynched(bool s); -
code/trunk/src/network/Connection.cc
r3214 r3304 31 31 #include <cassert> 32 32 #include <enet/enet.h> 33 #include <OgreTimer.h>34 33 #include "packet/Packet.h" 35 34 … … 77 76 78 77 assert(this->host_); 79 Ogre::Timer timer;80 78 81 while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME &&enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )79 while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 82 80 { 83 81 switch(event.type){ -
code/trunk/src/network/GamestateClient.cc
r3214 r3304 52 52 53 53 GamestateClient::~GamestateClient() { 54 std::map<unsigned int, packet::Gamestate *>::iterator it; 55 for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it ) 56 delete (*it).second; 57 if( this->tempGamestate_ ) 58 delete this->tempGamestate_; 54 59 } 55 60 -
code/trunk/src/network/GamestateClient.h
r3301 r3304 73 73 std::map<unsigned int, packet::Gamestate *> gamestateMap_; 74 74 packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue 75 unsigned char *shipCache_;76 75 77 76 }; -
code/trunk/src/network/GamestateManager.cc
r3301 r3304 42 42 43 43 #include <cassert> 44 #include <queue> 45 // #include <boost/thread/mutex.hpp> 44 46 45 47 #include "util/Debug.h" 48 #include "core/Executor.h" 49 #include "core/ThreadPool.h" 46 50 #include "ClientInformation.h" 47 51 #include "packet/Acknowledgement.h" … … 56 60 { 57 61 trafficControl_ = new TrafficControl(); 62 // threadMutex_ = new boost::mutex(); 63 // threadPool_ = new ThreadPool(); 58 64 } 59 65 … … 61 67 { 62 68 if( this->reference ) 63 delete this->reference;64 for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++)69 delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it; 70 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 65 71 delete (*it).second; 66 delete trafficControl_; 72 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1; 73 std::map<unsigned int, packet::Gamestate*>::iterator it2; 74 for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 ) 75 { 76 for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 ) 77 delete (*it2).second; 78 } 79 delete this->trafficControl_; 80 // delete this->threadMutex_; 81 // delete this->threadPool_; 67 82 } 68 83 … … 84 99 85 100 bool GamestateManager::processGamestates(){ 101 if( this->gamestateQueue.empty() ) 102 return true; 86 103 std::map<unsigned int, packet::Gamestate*>::iterator it; 87 104 // now push only the most recent gamestates we received (ignore obsolete ones) … … 109 126 return true; 110 127 } 111 112 113 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 128 129 void GamestateManager::sendGamestates() 130 { 131 ClientInformation *temp = ClientInformation::getBegin(); 132 std::queue<packet::Gamestate*> clientGamestates; 133 while(temp != NULL){ 134 if( !(temp->getSynched()) ){ 135 COUT(5) << "Server: not sending gamestate" << std::endl; 136 temp=temp->next(); 137 if(!temp) 138 break; 139 continue; 140 } 141 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 142 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 143 int cid = temp->getID(); //get client id 144 145 unsigned int gID = temp->getGamestateID(); 146 if(!reference) 147 return; 148 149 packet::Gamestate *client=0; 150 if(gID != GAMESTATEID_INITIAL){ 151 assert(gamestateMap_.find(cid)!=gamestateMap_.end()); 152 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID); 153 if(it!=gamestateMap_[cid].end()) 154 { 155 client = it->second; 156 } 157 } 158 159 clientGamestates.push(0); 160 finishGamestate( cid, &clientGamestates.back(), client, reference ); 161 //FunctorMember<GamestateManager>* functor = 162 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) ); 163 // executor->setObject(this); 164 // executor->setDefaultValues( cid, &clientGamestates.back(), client, reference ); 165 // (*static_cast<Executor*>(executor))(); 166 // this->threadPool_->passFunction( executor, true ); 167 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 168 169 temp = temp->next(); 170 } 171 172 // threadPool_->synchronise(); 173 174 while( !clientGamestates.empty() ) 175 { 176 if(clientGamestates.front()) 177 clientGamestates.front()->send(); 178 clientGamestates.pop(); 179 } 180 } 181 182 183 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 114 184 //why are we searching the same client's gamestate id as we searched in 115 185 //Server::sendGameState? 116 packet::Gamestate *gs;117 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();118 if(!reference)119 return 0;120 gs = reference->doSelection(clientID, 10000);121 186 // save the (undiffed) gamestate in the clients gamestate map 122 gamestateMap_[clientID][gs->getID()]=gs;123 187 //chose wheather the next gamestate is the first or not 124 packet::Gamestate *client=0; 125 if(gID != GAMESTATEID_INITIAL){ 126 assert(gamestateMap_.find(clientID)!=gamestateMap_.end()); 127 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID); 128 if(it!=gamestateMap_[clientID].end()) 129 { 130 client = it->second; 131 } 132 } 133 if(client){ 188 189 packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 190 // packet::Gamestate *gs = new packet::Gamestate(*gamestate); 191 // packet::Gamestate *gs = new packet::Gamestate(); 192 // gs->collectData( id_, 0x1 ); 193 // this->threadMutex_->lock(); 194 gamestateMap_[clientID][gamestate->getID()]=gs; 195 // this->threadMutex_->unlock(); 196 197 if(base) 198 { 199 134 200 // COUT(3) << "diffing" << std::endl; 135 201 // packet::Gamestate* gs1 = gs; 136 packet::Gamestate *diffed = gs->diff( client);202 packet::Gamestate *diffed = gs->diff(base); 137 203 //packet::Gamestate *gs2 = diffed->undiff(gs); 138 204 // assert(*gs == *gs2); … … 143 209 } 144 210 else{ 145 // COUT(3) << "not diffing" << std::endl;146 211 gs = new packet::Gamestate(*gs); 147 212 } 213 214 148 215 bool b = gs->compressData(); 149 216 assert(b); 150 COUT(4) << "sending gamestate with id " << gs->getID(); 151 if(gs->isDiffed()) 152 COUT(4) << " and baseid " << gs->getBaseID() << endl; 153 else 154 COUT(4) << endl; 155 return gs; 217 // COUT(4) << "sending gamestate with id " << gs->getID(); 218 // if(gamestate->isDiffed()) 219 // COUT(4) << " and baseid " << gs->getBaseID() << endl; 220 // else 221 // COUT(4) << endl; 222 gs->setClientID(clientID); 223 *destgamestate = gs; 156 224 } 157 225 … … 175 243 176 244 assert(curid==GAMESTATEID_INITIAL || curid<gamestateID); 177 COUT( 4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;245 COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 178 246 std::map<unsigned int, packet::Gamestate*>::iterator it; 179 247 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){ -
code/trunk/src/network/GamestateManager.h
r3214 r3304 45 45 #include <map> 46 46 #include "GamestateHandler.h" 47 #include "core/CorePrereqs.h" 47 48 48 49 namespace orxonox … … 73 74 bool processGamestates(); 74 75 bool update(); 75 packet::Gamestate *popGameState(unsigned int clientID); 76 void sendGamestates(); 77 // packet::Gamestate *popGameState(unsigned int clientID); 78 void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 76 79 77 80 bool getSnapshot(); … … 79 82 bool ack(unsigned int gamestateID, unsigned int clientID); 80 83 void removeClient(ClientInformation *client); 81 84 private: 82 85 bool processGamestate(packet::Gamestate *gs); 83 86 84 87 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 85 //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*86 //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate87 88 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 88 89 packet::Gamestate *reference; 89 90 TrafficControl *trafficControl_; 90 91 unsigned int id_; 92 // boost::mutex* threadMutex_; 93 ThreadPool* /*thread*/Pool_; 91 94 }; 92 95 -
code/trunk/src/network/Host.cc
r3214 r3304 74 74 } 75 75 76 77 // bool Host::chat(std::string& message){78 // if(!instance_)79 // return false;80 // packet::Chat *c = new packet::Chat(message, getPlayerID());81 // return instance_->sendChat(c);82 // }83 84 // bool Host::receiveChat(packet::Chat *message, unsigned int clientID){85 // if(instance_)86 // return instance_->processChat(message, clientID);87 // else88 // return false;89 // }90 91 76 /** 92 77 * This function returns the ID of the player -
code/trunk/src/network/NetworkFunction.cc
r3214 r3304 56 56 57 57 58 void NetworkFunctionBase::destroyAllNetworkFunctions() 59 { 60 std::map<std::string, NetworkFunctionBase*>::iterator it; 61 for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it ) 62 delete it->second; 63 } 64 58 65 59 66 NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p): -
code/trunk/src/network/NetworkFunction.h
r3214 r3304 37 37 #include <string> 38 38 #include <boost/preprocessor/cat.hpp> 39 #include <boost/static_assert.hpp> 39 40 40 41 #include "core/OrxonoxClass.h" … … 46 47 { 47 48 48 #if def ORXONOX_COMPILER_GCC49 #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32) 49 50 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8; 50 #else //ORXONOX_COMPILER_GCC51 #else 51 52 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16; 52 53 #endif //ORXONOX_COMPILER_GCC … … 57 58 bool operator<(const NetworkFunctionPointer& b) const 58 59 { 59 #if def ORXONOX_COMPILER_GCC60 #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32) 60 61 return pointer[0]<b.pointer[0] ? true : pointer[1]<b.pointer[1]; 61 62 #else //ORXONOX_COMPILER_GCC … … 80 81 81 82 static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); } 83 84 static void destroyAllNetworkFunctions(); 82 85 83 86 protected: … … 193 196 template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr) 194 197 { 195 memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T)); 198 if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0) 199 memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T)); 196 200 T p2 = ptr; 197 201 memcpy( &destptr, &p2, sizeof(T) ); … … 202 206 template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name ) 203 207 { 208 BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above 204 209 NetworkFunctionPointer destptr; 205 210 copyPtr( ptr, destptr ); … … 210 215 template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name ) 211 216 { 217 BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above 212 218 NetworkFunctionPointer destptr; 213 219 copyPtr( ptr, destptr ); -
code/trunk/src/network/NetworkPrereqs.h
r3301 r3304 102 102 template <class T> class NetworkMemeberFunction; 103 103 struct NetworkFunctionPointer; 104 class PacketBuffer;105 104 class Server; 106 105 class ServerConnection; -
code/trunk/src/network/Server.cc
r3214 r3304 48 48 #include "core/Clock.h" 49 49 #include "core/ObjectList.h" 50 #include "core/Executor.h" 50 51 #include "packet/Chat.h" 51 52 #include "packet/ClassID.h" … … 68 69 */ 69 70 Server::Server() { 70 timeSinceLastUpdate_=0; 71 gamestates_ = new GamestateManager(); 71 this->timeSinceLastUpdate_=0; 72 72 } 73 73 74 74 Server::Server(int port){ 75 75 this->setPort( port ); 76 timeSinceLastUpdate_=0; 77 gamestates_ = new GamestateManager(); 76 this->timeSinceLastUpdate_=0; 78 77 } 79 78 … … 86 85 this->setPort( port ); 87 86 this->setBindAddress( bindAddress ); 88 timeSinceLastUpdate_=0; 89 gamestates_ = new GamestateManager(); 87 this->timeSinceLastUpdate_=0; 90 88 } 91 89 … … 94 92 */ 95 93 Server::~Server(){ 96 if(gamestates_)97 delete gamestates_;98 94 } 99 95 … … 138 134 */ 139 135 void Server::update(const Clock& time) { 136 // receive incoming packets 140 137 Connection::processQueue(); 141 gamestates_->processGamestates(); 142 //this steers our network frequency 143 timeSinceLastUpdate_+=time.getDeltaTime(); 144 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 138 139 if ( ClientInformation::hasClients() ) 145 140 { 146 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 147 updateGamestate(); 141 // process incoming gamestates 142 GamestateManager::processGamestates(); 143 144 // send function calls to clients 148 145 FunctionCallManager::sendCalls(); 149 } 150 sendPackets(); // flush the enet queue 146 147 //this steers our network frequency 148 timeSinceLastUpdate_+=time.getDeltaTime(); 149 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 150 { 151 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 152 updateGamestate(); 153 } 154 sendPackets(); // flush the enet queue 155 } 151 156 } 152 157 … … 175 180 */ 176 181 void Server::updateGamestate() { 177 //if( ClientInformation::getBegin()==NULL )182 if( ClientInformation::getBegin()==NULL ) 178 183 //no client connected 179 //return;180 gamestates_->update();184 return; 185 GamestateManager::update(); 181 186 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 182 187 //std::cout << "updated gamestate, sending it" << std::endl; … … 197 202 */ 198 203 bool Server::sendGameState() { 199 COUT(5) << "Server: starting function sendGameState" << std::endl; 200 ClientInformation *temp = ClientInformation::getBegin(); 201 bool added=false; 202 while(temp != NULL){ 203 if( !(temp->getSynched()) ){ 204 COUT(5) << "Server: not sending gamestate" << std::endl; 205 temp=temp->next(); 206 if(!temp) 207 break; 208 //think this works without continue 209 continue; 210 } 211 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 212 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 213 int gid = temp->getGamestateID(); //get gamestate id 214 int cid = temp->getID(); //get client id 215 COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl; 216 packet::Gamestate *gs = gamestates_->popGameState(cid); 217 if(gs==NULL){ 218 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 219 temp = temp->next(); 220 continue; 221 } 222 //std::cout << "adding gamestate" << std::endl; 223 gs->setClientID(cid); 224 if ( !gs->send() ){ 225 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 226 temp->addFailure(); 227 }else 228 temp->resetFailures(); 229 added=true; 230 temp=temp->next(); 231 // gs gets automatically deleted by enet callback 232 } 204 // COUT(5) << "Server: starting function sendGameState" << std::endl; 205 // ClientInformation *temp = ClientInformation::getBegin(); 206 // bool added=false; 207 // while(temp != NULL){ 208 // if( !(temp->getSynched()) ){ 209 // COUT(5) << "Server: not sending gamestate" << std::endl; 210 // temp=temp->next(); 211 // if(!temp) 212 // break; 213 // continue; 214 // } 215 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 216 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 217 // int cid = temp->getID(); //get client id 218 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 219 // if(gs==NULL){ 220 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 221 // temp = temp->next(); 222 // continue; 223 // } 224 // //std::cout << "adding gamestate" << std::endl; 225 // gs->setClientID(cid); 226 // if ( !gs->send() ){ 227 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 228 // temp->addFailure(); 229 // }else 230 // temp->resetFailures(); 231 // added=true; 232 // temp=temp->next(); 233 // // gs gets automatically deleted by enet callback 234 // } 235 GamestateManager::sendGamestates(); 233 236 return true; 234 237 } … … 324 327 void Server::disconnectClient( ClientInformation *client ){ 325 328 ServerConnection::disconnectClient( client ); 326 gamestates_->removeClient(client);329 GamestateManager::removeClient(client); 327 330 // inform all the listeners 328 331 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); -
code/trunk/src/network/Server.h
r3214 r3304 34 34 #include "core/CorePrereqs.h" 35 35 #include "Host.h" 36 #include "GamestateManager.h" 36 37 #include "ServerConnection.h" 37 38 … … 43 44 * It implements all functions necessary for a Server 44 45 */ 45 class _NetworkExport Server : public Host, public ServerConnection {46 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{ 46 47 public: 47 48 Server(); … … 63 64 unsigned int shipID(){return 0;} 64 65 unsigned int playerID(){return 0;} 65 66 66 67 void addClient(ENetEvent *event); 67 68 bool createClient(int clientID); … … 75 76 void syncClassid(unsigned int clientID); 76 77 77 GamestateManager *gamestates_;78 79 80 78 float timeSinceLastUpdate_; 81 79 }; -
code/trunk/src/network/packet/ClassID.cc
r3280 r3304 142 142 classname = temp+2*sizeof(uint32_t); 143 143 id=ClassByString( std::string((const char*)classname) ); 144 COUT( 0) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;144 COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl; 145 145 if(id==NULL){ 146 146 COUT(0) << "Recieved a bad classname" << endl; -
code/trunk/src/network/packet/FunctionIDs.cc
r3280 r3304 132 132 stringsize = *(uint32_t*)(temp+sizeof(uint32_t)); 133 133 functionname = temp+2*sizeof(uint32_t); 134 COUT( 0) << "processing functionid: " << networkID << " name: " << functionname << std::endl;134 COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl; 135 135 NetworkFunctionBase::setNetworkID((const char*)functionname, networkID); 136 136 temp += 2*sizeof(uint32_t) + stringsize; -
code/trunk/src/network/synchronisable/NetworkCallbackManager.cc
r3214 r3304 44 44 if (it != callbackSet_.end()) 45 45 { 46 delete (*it);47 46 callbackSet_.erase(it); 47 delete cb; 48 48 } 49 49 } -
code/trunk/src/network/synchronisable/Synchronisable.cc
r3280 r3304 96 96 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) 97 97 deletedObjects_.push(objectID); 98 // delete all Synchronisable Variables from syncList ( which are also in stringList )99 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)100 delete (*it);101 syncList.clear();102 stringList.clear();103 }98 } 99 // delete all Synchronisable Variables from syncList ( which are also in stringList ) 100 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++) 101 delete (*it); 102 syncList.clear(); 103 stringList.clear(); 104 104 std::map<uint32_t, Synchronisable*>::iterator it; 105 105 it = objectMap_.find(objectID); … … 247 247 return 0; 248 248 uint32_t tempsize = 0; 249 #ifndef NDEBUG 249 250 if (this->classID==0) 250 251 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 252 #endif 251 253 252 254 if (this->classID == static_cast<uint32_t>(-1)) -
code/trunk/src/network/synchronisable/Synchronisable.h
r3301 r3304 43 43 #include "NetworkCallback.h" 44 44 45 /*#define REGISTERDATA(varname, ...) \46 registerVariable(static_cast<void*>(&varname), sizeof(varname), DATA, __VA_ARGS__)47 #define REGISTERSTRING(stringname, ...) \48 registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/49 45 50 46 namespace orxonox -
code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
r3214 r3304 38 38 namespace orxonox{ 39 39 40 // template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)41 // {42 // if (bidirectional)43 // syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));44 // else45 // syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));46 // stringList.push_back(syncList.back());47 // }48 49 40 template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 50 41 { 42 SynchronisableVariableBase* sv; 51 43 if (bidirectional) 52 s yncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));44 sv = new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb); 53 45 else 54 syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb)); 55 stringList.push_back(syncList.back()); 46 sv = new SynchronisableVariable<const std::string>(variable, mode, cb); 47 syncList.push_back(sv); 48 stringList.push_back(sv); 56 49 } 57 50 … … 73 66 registerVariable(variable.y, mode, cb, bidirectional); 74 67 } 75 // template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)76 // {77 // registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);78 // }79 68 80 69 template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) -
code/trunk/src/network/synchronisable/SynchronisableVariable.h
r3301 r3304 117 117 { 118 118 if (this->callback_ != 0) 119 { 119 120 NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion 121 // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback 122 } 120 123 } 121 124 -
code/trunk/src/orxonox/LevelManager.h
r3280 r3304 34 34 #include <cassert> 35 35 #include <list> 36 #include <string> 36 37 #include "core/OrxonoxClass.h" 37 38 -
code/trunk/src/orxonox/gamestates/GSDedicated.cc
r3301 r3304 42 42 #include <boost/bind.hpp> 43 43 44 #if ndef ORXONOX_PLATFORM_WINDOWS44 #ifdef ORXONOX_PLATFORM_UNIX 45 45 #include <termios.h> 46 46 #endif … … 58 58 : GameState(params) 59 59 , server_(0) 60 , timeSinceLastUpdate_(0)61 60 , closeThread_(false) 62 61 , cleanLine_(true) … … 65 64 , cursorY_(0) 66 65 { 67 this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];68 // memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );69 66 } 70 67 … … 96 93 97 94 closeThread_ = true; 98 #if ndef ORXONOX_PLATFORM_WINDOWS95 #ifdef ORXONOX_PLATFORM_UNIX 99 96 std::cout << "\033[0G\033[K"; 100 97 std::cout.flush(); … … 102 99 delete this->originalTerminalSettings_; 103 100 #endif 104 //inputThread_->join(); 101 COUT(0) << "Press enter to end the game..." << std::endl; 102 inputThread_->join(); 103 delete this->inputThread_; 105 104 106 105 GameMode::setHasServer(false); … … 109 108 void GSDedicated::update(const Clock& time) 110 109 { 111 timeSinceLastUpdate_ += time.getDeltaTime(); 112 if (timeSinceLastUpdate_ >= NETWORK_PERIOD) 113 { 114 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 115 server_->update(time); 116 } 117 else 118 { 119 msleep(static_cast<unsigned int>((NETWORK_PERIOD - timeSinceLastUpdate_)*1000)); 120 msleep(static_cast<unsigned int>(NETWORK_PERIOD*1000)); // NOTE: this is to throttle the non-network framerate 121 // COUT(0) << "sleeping for " << static_cast<int>((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl; 122 } 110 server_->update(time); 123 111 processQueue(); 124 112 printLine(); … … 127 115 void GSDedicated::inputThread() 128 116 { 117 this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH]; 118 // memset( this->commandLine_, 0, MAX_COMMAND_LENGTH ); 129 119 unsigned char c; 130 120 unsigned int escapeChar=0; … … 194 184 std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl; 195 185 strncpy(reinterpret_cast<char*>(this->commandLine_), CommandExecutor::complete( std::string(reinterpret_cast<char*>(this->commandLine_),inputIterator_) ).c_str(), MAX_COMMAND_LENGTH); 196 inputIterator_ = strlen((const char*)this->commandLine_); 186 this->inputIterator_ = strlen((const char*)this->commandLine_); 187 this->cursorX_ = this->inputIterator_; 197 188 break; 198 189 } … … 207 198 } 208 199 } 200 201 delete[] this->commandLine_; 209 202 } 210 203 211 204 void GSDedicated::printLine() 212 205 { 213 #if ndef ORXONOX_PLATFORM_WINDOWS206 #ifdef ORXONOX_PLATFORM_UNIX 214 207 // set cursor to the begining of the line and erase the line 215 208 std::cout << "\033[0G\033[K"; … … 251 244 void GSDedicated::setTerminalMode() 252 245 { 253 #if ndef ORXONOX_PLATFORM_WINDOWS246 #ifdef ORXONOX_PLATFORM_UNIX 254 247 termios new_settings; 255 248 … … 268 261 void GSDedicated::resetTerminalMode() 269 262 { 270 #if ndef ORXONOX_PLATFORM_WINDOWS263 #ifdef ORXONOX_PLATFORM_UNIX 271 264 tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_); 272 265 #endif -
code/trunk/src/orxonox/gamestates/GSDedicated.h
r3280 r3304 66 66 67 67 Server* server_; 68 float timeSinceLastUpdate_;69 68 70 69 boost::thread *inputThread_; -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r3280 r3304 34 34 #include "core/Game.h" 35 35 #include "core/GameMode.h" 36 #include "network/NetworkFunction.h" 36 37 #include "tools/Timer.h" 37 38 #include "interfaces/TimeFactorListener.h" … … 61 62 GSRoot::~GSRoot() 62 63 { 64 NetworkFunctionBase::destroyAllNetworkFunctions(); 63 65 } 64 66 -
code/trunk/src/util/Math.cc
r3196 r3304 136 136 return orxonox::Vector2(0, 1); 137 137 } 138 139 float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1)); 140 138 139 float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1); 140 float sin_value = sqrt( 1 - cos_value*cos_value ); 141 141 142 if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0) 142 return orxonox::Vector2( sin(angle), cos(angle));143 else 144 return orxonox::Vector2( -sin(angle), cos(angle));143 return orxonox::Vector2( sin_value, cos_value ); 144 else 145 return orxonox::Vector2( -sin_value, cos_value ); 145 146 } 146 147 … … 175 176 return orxonox::Vector2(0, 1); 176 177 } 177 float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1)); 178 //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1)); 179 180 float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1); 181 float sin_value = sqrt( 1 - cos_value*cos_value ); 178 182 179 183 float distancelength = distance.length(); … … 182 186 183 187 if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0) 184 return orxonox::Vector2( sin(angle) * radius, cos(angle)* radius);185 else 186 return orxonox::Vector2( -sin(angle) * radius, cos(angle)* radius);188 return orxonox::Vector2( sin_value * radius, cos_value * radius); 189 else 190 return orxonox::Vector2( -sin_value * radius, cos_value * radius); 187 191 } 188 192 -
code/trunk/src/util/Serialise.h
r3084 r3304 408 408 template <> inline void loadAndIncrease( const std::string& variable, uint8_t*& mem ) 409 409 { 410 *(std::string*)( &variable ) = std::string((const char *)mem);410 *(std::string*)( &variable ) = (const char *)mem; 411 411 mem += variable.length()+1; 412 412 } … … 414 414 template <> inline bool checkEquality( const std::string& variable, uint8_t* mem ) 415 415 { 416 return std::string((const char*)mem)==variable; 416 //return std::string((const char*)mem)==variable; 417 return (const char*)mem==variable; 417 418 } 418 419
Note: See TracChangeset
for help on using the changeset viewer.