/* Update the current clock's tick count based on a given interval of real time and the clock's time scale and pause state. Typically, this interval will be computed using a clock that measures time in the "real" world. */ void simphys::Clock::update(float dt) { int f; //std::cout << "here" << f << std::endl; if(not paused) ticks += secondsToTicks(dt) * timeScale; }
//------------------------------------------------------------------------------------- void Archiver::tick() { int32 periodInTicks = secondsToTicks(ServerConfig::getSingleton().getBaseApp().archivePeriod, 0); if (periodInTicks == 0) return; if (archiveIndex_ >= periodInTicks) { this->createArchiveTable(); } // 算法如下: // base的数量 * idx / tick周期 = 每次在vector中移动的一个区段 // 这个区段在每个gametick进行处理, 刚好平滑的在periodInTicks中处理完任务 // 如果archiveIndex_ >= periodInTicks则重新产生一次随机序列 int size = backupEntityIDs_.size(); int startIndex = size * archiveIndex_ / periodInTicks; ++archiveIndex_; int endIndex = size * archiveIndex_ / periodInTicks; for (int i = startIndex; i < endIndex; ++i) { Base * pBase = Baseapp::getSingleton().findEntity(backupEntityIDs_[i]); if(pBase && pBase->hasDB()) { this->archive(*pBase); } } }
/* Constructor. We pass in a starting time, which may default to zero. */ simphys::Clock::Clock(float startTime = 0.0f) { freq = 1000000.f; timeScale = 1.0f; paused = false; ticks = secondsToTicks(startTime); }