//! Returns total number of microseconds truncating any sub microsecond values tick_type total_microseconds() const { if (ticks_per_second() < 1000000) { return ticks() * (static_cast<tick_type>(1000000) / ticks_per_second()); } return ticks() / (ticks_per_second() / static_cast<tick_type>(1000000)) ; }
void sntp_process( void ) { switch( state ) { case SNTP_NOT_READY: return; // host configuration not finished. case SNTP_IDLE: if (ticks() > next_sync_time) { sntp_send_request(); next_sync_time = ticks() + TIMEOUT; state = SNTP_WAITING_FOR_RESPONSE; } break; case SNTP_WAITING_FOR_RESPONSE: if (ticks() > next_sync_time) { next_sync_time = ticks() + interval; interval *= 2; if (interval > MAX_INTERVAL) interval = MAX_INTERVAL; state = SNTP_IDLE; } } }
namespace antares { const ticks kSlowScrollInterval = ticks(4); const ticks kFastScrollInterval = ticks(2); class ScrollTextScreen : public Card { public: ScrollTextScreen(pn::string_view text, int width, ticks interval); ScrollTextScreen(pn::string_view text, int width, ticks interval, pn::string_view song); virtual void become_front(); virtual void resign_front(); virtual void mouse_down(const MouseDownEvent& event); virtual void key_down(const KeyDownEvent& event); virtual void gamepad_button_down(const GamepadButtonDownEvent& event); virtual bool next_timer(wall_time& time); virtual void fire_timer(); virtual void draw() const; private: BuildPix _build_pix; const ticks _interval; const bool _play_song; const pn::string _song; wall_time _start; wall_time _next_shift; int32_t _position; }; } // namespace antares
// sleep(int milliseconds) -- // -- sleeps during the specified time (in milliseconds) void GOS::sleep(int milliseconds) { #if defined(UNIX) struct timeval tv; tv.tv_sec = milliseconds / 1000; tv.tv_usec = (milliseconds - (tv.tv_sec * 1000)) * 1000; # if defined(THREADMODEL) && (THREADMODEL==COTHREADS) GThread::select(0, NULL, NULL, NULL, &tv); # else select(0, NULL, NULL, NULL, &tv); # endif #elif defined(WIN32) Sleep(milliseconds); #elif defined(OS2) DosSleep(milliseconds); #elif defined(macintosh) unsigned long tick = ticks(), now; while (1) { now = ticks(); if ((tick+milliseconds) < now) break; GThread::yield(); } #endif }
void TIME_STEPPER::time_loop() { if (first_step) { REAL OmRMax = 0.0, MaxRadius = 0.0; if (globalSystem->useBodies) { for (int i = 0; i < BODY::AllBodyFaces.size(); ++i) { Vect3 Pos = BODY::AllBodyFaces[i]->CollocationPoint - BODY::AllBodyFaces[i]->Owner->CG; // Get point kinematic velocity - rotational part first Vect3 Vrot = BODY::AllBodyFaces[i]->Owner->BodyRates.Cross(Pos); // Add to translational velocity.... Vect3 Vkin = BODY::AllBodyFaces[i]->Owner->Velocity + Vrot; OmRMax = max(Vkin.Mag(), OmRMax); MaxRadius = max(MaxRadius, Pos.Mag()); } } dt = globalSystem->dtInit;// = cfl_lim/OmRMax; dt_prev = cfl_lim/OmRMax; if (globalSystem->useBodies) { BODY::BodySubStep(globalSystem->dtInit, globalSystem->NumSubSteps); globalSystem->PutWakesInTree(); } globalOctree->Reset(); globalOctree->GetVels(); // if (globalSystem->useFMM) { //#pragma omp parallel for // for (int i = 0; i < FVMCell::AllCells.size(); ++i) // for (int j = 0; j < FVMCell::AllCells.size(); ++j) // FVMCell::AllCells[i]->Velocity += UTIL::globalDirectVel(FVMCell::AllCells[j]->Position - FVMCell::AllCells[i]->Position, FVMCell::AllCells[j]->Omega); // } first_step = false; } else { #ifdef TIME_STEPS long unsigned int t1 = ticks(); #endif TimeAdvance(); // Produce Output if (globalTimeStepper->dump_next) { globalSystem->WriteData(); } #ifdef TIME_STEPS long unsigned int t13 = ticks(); stringstream tmp; tmp << "Total....................: " << double(t13 - t1) / 1000.0 << endl; globalIO->step_data += tmp.str(); #endif // Display Status globalIO->stat_step(); } }
void play_controller::init_managers() { LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl; preferences::set_preference_display_settings(); tooltips_manager_.reset(new tooltips::manager(gui_->video())); soundsources_manager_.reset(new soundsource::manager(*gui_)); resources::soundsources = soundsources_manager_.get(); LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl; }
int main () { int n = 100, i, ic; double fpi = 3.1415926 / 180.0, step, x; float xray[100], y1ray[100], y2ray[100]; step = 360. / (n - 1); for (i = 0; i < n; i++) { xray[i] = (float) (i * step); x = xray[i] * fpi; y1ray[i] = (float) sin (x); y2ray[i] = (float) cos (x); } metafl ("cons"); scrmod ("revers"); disini (); pagera (); complx (); axspos (450, 1800); axslen (2200, 1200); name ("X-axis", "x"); name ("Y-axis", "y"); labdig (-1, "x"); ticks (9, "x"); ticks (10, "y"); titlin ("Demonstration of CURVE", 1); titlin ("SIN(X), COS(X)", 3); ic = intrgb (0.95,0.95,0.95); axsbgd (ic); graf (0.0, 360.0, 0.0, 90.0, -1.0, 1.0, -1.0, 0.5); setrgb (0.7, 0.7, 0.7); grid (1, 1); color ("fore"); height (50); title (); color ("red"); curve (xray, y1ray, n); color ("green"); curve (xray, y2ray, n); disfin (); return 0; }
int64_t duration_cast() const { const int64_t num = period_type::num * Den; const int64_t den = period_type::den * Num; if (num == 1 && den == 1) return ticks(); else if (num != 1 && den == 1) return ticks() * num; else if (num == 1 && period_type::den != 1) return ticks() / den; else return ticks() * num / den; }
/** Sends messages to all clients or to all clients not in a game. */ void broadCast(bool global){ verbose && cout << ticks() << ": server broadcasts: .:" << buffer.str() <<":." << endl; for (Clients::iterator it = clients.begin(); it != clients.end(); it++) if (it->second != 0){ if (it->second && ((global) || (it->second->game == 0))) it->second->cast(); } buffer.str(""); }
/** Checks whether no OOS occurs. */ bool Game::syncCheck(int clid, int timestamp, int plid, double coordx, double coordy){ synced++; double record = coordx + coordy; int i = 0; for (map<int, Client*>::iterator it = clients.begin(); it != clients.end(); it++){ if (it->second->id == clid){ sync->at(i) += record; break; } i++; } if (synced == clients.size() * players.WrapMap<Player*>::size()){ record = sync->at(0); int i = 0; for (map<int, Client*>::iterator it = clients.begin(); it != clients.end(); it++){ if (record != sync->at(i)){ return false; } sync->at(i) = 0; i++; } synced = 0; verbose && cout << ticks() << ": game #" << id << " sync ok" << endl; } return true; }
void playsingle_controller::init_gui(){ LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n"; play_controller::init_gui(); // Scroll to the starting position of the first team. If there is a // human team, use that team; otherwise use team 1. If the map defines // a starting position for the selected team, scroll to that tile. Note // this often does not matter since many scenario start with messages, // which will usually scroll to the speaker. Also note that the map // does not necessarily define the starting positions. While usually // best to use the map, the scenarion may explicitly set the positions, // overriding those found in the map (if any). { int scroll_team = gamestate().first_human_team_ + 1; if (scroll_team == 0) { scroll_team = 1; } map_location loc(gamestate().board_.map().starting_position(scroll_team)); if ((loc.x >= 0) && (loc.y >= 0)) { gui_->scroll_to_tile(loc, game_display::WARP); } } update_locker lock_display(gui_->video(), is_skipping_replay()); gui_->draw(); get_hotkey_command_executor()->set_button_state(); events::raise_draw_event(); }
void dot_t::extend_duration( int extra_ticks, bool cap ) { if ( ! ticking ) return; // Make sure this DoT is still ticking...... assert( tick_event ); if ( sim -> log ) log_t::output( sim, "%s extends duration of %s on %s, adding %d tick(s), totalling %d ticks", action -> player -> name(), name(), player -> name(), extra_ticks, num_ticks + extra_ticks ); if ( cap ) { // Can't extend beyond initial duration. // Assuming this limit is based on current haste, not haste at previous application/extension/refresh. int max_extra_ticks = std::max( action -> hasted_num_ticks() - ticks(), 0 ); extra_ticks = std::min( extra_ticks, max_extra_ticks ); } action -> player_buff(); added_ticks += extra_ticks; num_ticks += extra_ticks; recalculate_ready(); }
jlong elapsedTimer::active_ticks() const { if (!_active) { return ticks(); } jlong counter = _counter + os::elapsed_counter() - _start_counter; return counter; }
int main(int argc, char** argv) { uint64_t t1, t2; t1 = ticks(); for (int i = 0; i < 10000000; i++) xorshift128plus(); t2 = ticks(); printf("%ld ms\n", t2 - t1); #ifdef WIN64 printf("state0 = %llu\n", state0); printf("state1 = %llu\n", state1); #else printf("state0 = %lu\n", state0); printf("state1 = %lu\n", state1); #endif }
void playsingle_controller::play_scenario_main_loop() { LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks()) << "\n"; // Avoid autosaving after loading, but still // allow the first turn to have an autosave. ai_testing::log_game_start(); if(gamestate().board_.teams().empty()) { ERR_NG << "Playing game with 0 teams." << std::endl; } while(true) { try { play_turn(); if (is_regular_game_end()) { turn_data_.send_data(); return; } gamestate_->player_number_ = 1; } catch(const reset_gamestate_exception& ex) { // // TODO: // // The MP replay feature still doesn't work properly (causes OOS) // because: // // 1) The undo stack is not reset along with the gamestate (fixed). // 2) The server_request_number_ is not reset along with the // gamestate (fixed). // 3) chat and other unsynced actions are inserted in the middle of // the replay bringing the replay_pos in unorder (fixed). // 4) untracked changes in side controllers are lost when resetting // gamestate (fixed). // 5) The game should have a stricter check for whether the loaded // game is actually a parent of this game. // 6) If an action was undone after a game was saved it can cause // OOS if the undone action is in the snapshot of the saved // game (luckily this is never the case for autosaves). // boost::dynamic_bitset<> local_players; local_players.resize(gamestate().board_.teams().size(), true); //Preserve side controllers, becasue we won't get the side controoller updates again when replaying. for(size_t i = 0; i < local_players.size(); ++i) { local_players[i] = gamestate().board_.teams()[i].is_local(); } reset_gamestate(*ex.level, (*ex.level)["replay_pos"]); for(size_t i = 0; i < local_players.size(); ++i) { resources::gameboard->teams()[i].set_local(local_players[i]); } play_scenario_init(); replay_.reset(new replay_controller(*this, false, ex.level)); if(ex.start_replay) { replay_->play_replay(); } } } //end for loop }
/** Sends a message to the client. */ void Client::cast(){ int msglen; string outdata = buffer.str() + "\n"; verbose && cout << ticks() << ": server sends to #" << id << ": .:" << outdata << ":." << endl; msglen = outdata.length()+1; if (SDLNet_TCP_Send(sd, (void *)(outdata.c_str()), msglen) < msglen) cerr << "SDLNet_TCP_Send: " << SDLNet_GetError() << endl; }
/** Sends a message to clients in the same game. */ void Client::broadCast(bool except){ verbose && cout << ticks() << ": server broadcasts: .:" << buffer.str() << ":." << endl; Client* cl; for (Clients::iterator it = clients.begin(); it != clients.end(); it++) if (it->second != 0){ cl = it->second; if ((cl->game == game) && ((!except) || (cl != this))) cl->cast(); } buffer.str(""); }
/** Adds a game to the list. */ Game* Games::add(){ Game* newG = new Game(); if (WrapMap<Game*>::add(newG) != 0){ mute || cout << ticks() << ": game #" << newG->id << " created" << endl; return(newG); }else{ free(newG); return 0; } }
void randominit(void) { #ifdef USE_RANDOM srandom(getpid()+fastticks(nil)+ticks()); #else if((randfd = open("/dev/urandom", OREAD)) < 0) if((randfd = open("/dev/random", OREAD)) < 0) panic("open /dev/random: %r"); #endif }
inline clock_t times(struct tms *t){ struct timespec ts; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); clock_t ticks(static_cast<clock_t>(static_cast<double>(ts.tv_sec) * CLOCKS_PER_SEC + static_cast<double>(ts.tv_nsec) * CLOCKS_PER_SEC / 1000000.0)); t->tms_utime = ticks/2U; t->tms_stime = ticks/2U; t->tms_cutime = 0; // vxWorks is lacking the concept of a child process! t->tms_cstime = 0; // -> Set the wait times for childs to 0 return ticks; }
int64_t duration_cast() const { const int64_t num1 = period_type::num / gcd<period_type::num, Num>::value; const int64_t num2 = Num / gcd<period_type::num, Num>::value; const int64_t den1 = period_type::den / gcd<period_type::den, Den>::value; const int64_t den2 = Den / gcd<period_type::den, Den>::value; const int64_t num = num1 * den2; const int64_t den = num2 * den1; if (num == 1 && den == 1) return ticks(); else if (num != 1 && den == 1) return ticks() * num; else if (num == 1 && period_type::den != 1) return ticks() / den; else return ticks() * num / den; }
void minimizeNumberOfRests( std::multimap<ReducedFraction, MidiChord> &chords, const TimeSigMap *sigmap, const std::multimap<ReducedFraction, MidiTuplet::TupletData> &tuplets) { for (auto it = chords.begin(); it != chords.end(); ++it) { for (MidiNote ¬e: it->second.notes) { const auto barStart = MidiBar::findBarStart(note.offTime, sigmap); const auto barFraction = ReducedFraction( sigmap->timesig(barStart.ticks()).timesig()); auto durationStart = (it->first > barStart) ? it->first : barStart; if (it->second.isInTuplet) { const auto &tuplet = it->second.tuplet->second; if (note.offTime >= tuplet.onTime + tuplet.len) durationStart = tuplet.onTime + tuplet.len; } auto endTime = (barStart == note.offTime) ? barStart : barStart + barFraction; if (note.isInTuplet) { const auto &tuplet = note.tuplet->second; if (note.offTime == tuplet.onTime + tuplet.len) continue; endTime = barStart + Quantize::quantizeToLarge( note.offTime - barStart, tuplet.len / tuplet.tupletNumber); } const auto beatLen = Meter::beatLength(barFraction); const auto beatTime = barStart + Quantize::quantizeToLarge( note.offTime - barStart, beatLen); if (endTime > beatTime) endTime = beatTime; auto next = std::next(it); while (next != chords.end() && (next->second.voice != it->second.voice || next->first < note.offTime)) { ++next; } if (next != chords.end()) { if (next->first < endTime) endTime = next->first; if (next->second.isInTuplet && !note.isInTuplet) { const auto &tuplet = next->second.tuplet->second; if (tuplet.onTime < endTime) endTime = tuplet.onTime; } } lengthenNote(note, it->second.voice, it->first, durationStart, endTime, barStart, barFraction, tuplets); } } }
bool Timer::stepCount() { Uint32 temp = ticks(); if ( temp < elapsedCount ) { step++; } else { countStep = step; step = 0; start(); return true; } return false; }
TIME_STEPPER::TIME_STEPPER() { dt_prev = 0.0; dx = dy = dz = 1.0; ChangeOver = last_step = PruneNow = false; n = -1; RKStep = 0; t = substep_time = sim_time = 0.0; cfl_lim = 0.4; t_out = TIME_STEPPER::dt_out; lambda = mu = nu = 0.0; cpu_t = ticks(); dump_next = show_rundata = false; first_step = dump_next = true; }
void playsingle_controller::init_gui(){ LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n"; play_controller::init_gui(); if(gamestate().first_human_team_ != -1) { gui_->scroll_to_tile(gamestate().board_.map().starting_position(gamestate().first_human_team_ + 1), game_display::WARP); } gui_->scroll_to_tile(gamestate().board_.map().starting_position(1), game_display::WARP); update_locker lock_display(gui_->video(), is_skipping_replay()); gui_->draw(); get_hotkey_command_executor()->set_button_state(); events::raise_draw_event(); }
/** Adds a client to the list. */ bool Clients::add(TCPsocket newsd){ int newid = newID(); if (newid != 0){ //modified = true; Client* cl = new Client(newsd); operator[](newid) = cl; cl->id = newid; cl->state = cl->CHOOSE; mute || cout << ticks() << ": client #" << newid << " joined" << endl; }; return newid; }
void PhysicsSim::updatePhysics() { u32 TDeltaTime = ticks(); if(paused) TDeltaTime = 0; //if(!paused) //{ dynamicsWorld->stepSimulation(TDeltaTime * 0.001f, 60); for(unsigned int i = 0; i < objects_list.size(); i++) objects_list[i]->Update(); //} }
Time::Time(ptime t) { auto datePart = t.date(); auto timePart = t.time_of_day(); TimeScale timeScale = TimeScale::Master(); // consider date part only auto d = datePart - date(1970, 1, 1); int offsetFromEpochDays = d.days(); this->ticks_ = timeScale.TicksPerDay() * offsetFromEpochDays; // add ticks for time of day if(time_duration::ticks_per_second() > timeScale.TicksPerSecond()) // since the following computations are integer calculcations, we distinguish here { int64 conversionRate = time_duration::ticks_per_second() / timeScale.TicksPerSecond(); this->ticks_ += timePart.ticks() / conversionRate; } else { int64 conversionRate = timeScale.TicksPerSecond() / time_duration::ticks_per_second(); this->ticks_ += timePart.ticks() * conversionRate; } }
void trace(uint16_t level, const char *msg, ...) { va_list args; va_start(args, msg); if (trace_stream != 0 && trace_level <= level) { // send the timestamp stream_printf(trace_stream, "%ld %s ", ticks(), levels[level]); // send the level stream_vprintf(trace_stream, msg, args); stream_puts(trace_stream, "\r\n"); } platform_trace(level, msg, args); }
int main(int argc, char *argv[]) { std::cout << "Styled text inset demo" << std::endl; QApplication a(argc, argv); WPlot::CartesianPlot2D* plot2D(new WPlot::CartesianPlot2D); WPlot::Ticks2D::Ptr ticks(new WPlot::Ticks2D); WPlot::Axes2D::Ptr axes(new WPlot::Axes2D); ticks->setOrigin(150.0, 200.0); ticks->setPrimaryTickLength(20); ticks->setEnableLabels(true); axes->setTicks(ticks); plot2D->setPadding(25, WPlot::Padding::PIXELS); plot2D->setPlotLimits(-3.3, 7.5, -2, 4.3); plot2D->addAxes(axes); plot2D->show(); return a.exec(); }