本文整理汇总了C++中sf::Clock::restart方法的典型用法代码示例。如果您正苦于以下问题:C++ Clock::restart方法的具体用法?C++ Clock::restart怎么用?C++ Clock::restart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Clock
的用法示例。
在下文中一共展示了Clock::restart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderSceneCB
void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
static sf::Clock a_timer;
static bool a_first_time = true;
if (a_first_time) {
a_first_time = false;
a_timer.restart ();
}
float dt = a_timer.getElapsedTime ().asSeconds ();
a_timer.restart ();
// ֲ�גמה ג פאיכ פןס ט הוכ�עא ׂ
//static FILE *out = fopen ((prefix_path + "inf/out.txt").c_str (), "w");
//fprintf (out, "%4d %10g\n", int(1/dt), dt);
if (in.kb.escape.pressed_now) {
exit (0);
}
core.update (dt);
core.render ();
core.m_renderer.draw_everything ();
glutSwapBuffers();
}
示例2: display
void display(sf::RenderWindow *window)
{
if (frames==0)
sfclock.restart();
window->pushGLStates();
window->resetGLStates();
window->popGLStates();
glClearColor(1.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
v.draw();
if (frames>500)
{
sf::Time t = sfclock.getElapsedTime();
frame_rate = frames/t.asSeconds();
frames = 0;
}
else
{
frames++;
}
stringstream str;
str << "Frame rate " << frame_rate;
//drawText(window,str.str(),window->getSize().x-200,50);
window->display();
}
示例3: update
void DialogueMode::update(sf::RenderWindow &rw, sf::Clock &clock)
{
float elapsed = clock.restart().asSeconds();
rw.clear(sf::Color::White); //should this be in highest loop?
//handle all input
sf::Event event;
while (rw.pollEvent(event)) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space) {
current = current->getNext();
if (current == nullptr) {
deletionOrder = true;
return;
}
}
else current->handleInput(event);
}
current->update(elapsed);
//put into drawAll function?
rw.setView(mapView);
currentMap->drawAllObjects(rw, playerSprite);
rw.setView(HUD);
rw.draw(messageBox);
current->draw(rw);
rw.display();
}
示例4: update
//Process the player's inputs WASD and mouse buttons.
void Player::update(sf::RenderWindow &window, vector <Bullet *> &bullets, sf::Sound &laser, sf::FloatRect bounds, sf::Clock &fireRateTimer) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W) && this->getPosition().y > bounds.top) {
this->velocity.y -= this->acceleration;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) && this->getPosition().x < bounds.width) {
this->velocity.x += this->acceleration;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S) && this->getPosition().y < bounds.height) {
this->velocity.y += this->acceleration;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) && this->getPosition().x > bounds.left) {
this->velocity.x -= this->acceleration;
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if (fireRateTimer.getElapsedTime().asSeconds() >= this->rateOfFire && this->alive) {
this->shoot(window, bullets, laser);
fireRateTimer.restart();
}
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
this->activateShield(window);
}
if (this->shieldCharge >= 200) {
this->shieldCharge = 200;
}
}
示例5: broadcast_ping_data
void game_state::broadcast_ping_data()
{
static sf::Clock clk;
const float send_time_ms = 1000;
if(clk.getElapsedTime().asMicroseconds() / 1000.f < send_time_ms)
return;
clk.restart();
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::PING_DATA);
int32_t num = player_list.size();
vec.push_back<int32_t>(num);
for(int i=0; i<player_list.size(); i++)
{
///playerid int32_t
///playerping float
vec.push_back<int32_t>(player_list[i].id);
vec.push_back<float>(player_list[i].ping_ms);
}
vec.push_back(canary_end);
int none = -1;
broadcast(vec.ptr, none);
}
示例6: render
void render()
{
std::stringstream ss;
std::deque<Point> trails, vertices;
window->clear();
window->setView(camera);
window->draw(bg);
sf::Color color(sf::Color::Red);
sf::ConvexShape tail;
tail.setFillColor(sf::Color(128,0,0,128));
for(auto& creature:creatures) {
window->draw(*creature);
}
for(auto& f:food) {
fToken->setPosition(f);
window->draw(*fToken);
}
ss.str("");
ss << "Generation: " << gen;
text->setPosition(10,10);
text->setString(ss.str());
window->setView(window->getDefaultView());
window->draw(*text);
if(frameclock.getElapsedTime().asMilliseconds()>0) {
ss.str("");
ss << "FPS: " << (int)1000.f/frameclock.restart().asMilliseconds();
text->setString(ss.str());
text->move(0,text->getLocalBounds().height);
window->draw(*text);
}
window->display();
}
示例7: periodic_team_broadcast
void game_state::periodic_team_broadcast()
{
static sf::Clock clk;
///once per second
float broadcast_every_ms = 1000.f;
if(clk.getElapsedTime().asMicroseconds() / 1000.f < broadcast_every_ms)
return;
clk.restart();
for(auto& i : player_list)
{
///network
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::TEAMASSIGNMENT);
vec.push_back<int32_t>(i.id);
vec.push_back<int32_t>(i.team);
vec.push_back(canary_end);
//printf("Team ass %i team player %i\n", i.team, i.id);
int no_player = -1;
broadcast(vec.ptr, no_player);
}
}
示例8: periodic_respawn_info_update
void game_state::periodic_respawn_info_update()
{
static sf::Clock clk;
///once per second
float broadcast_every_ms = 100.f;
if(clk.getElapsedTime().asMicroseconds() / 1000.f < broadcast_every_ms)
return;
clk.restart();
for(auto& i : respawn_requests)
{
player play = get_player_from_player_id(i.player_id);
if(play.id == -1)
continue;
float time_elapsed = i.clk.getElapsedTime().asMicroseconds() / 1000.f;
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::RESPAWNINFO);
vec.push_back(time_elapsed);
vec.push_back(i.time_to_respawn_ms);
vec.push_back(canary_end);
udp_send_to(play.sock, vec.ptr, (const sockaddr*)&play.store);
}
}
示例9: init
void init()
{
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
window.create(sf::VideoMode(800, 600), "Bezier_Spline_Wireframe", sf::Style::Close, settings);
glewExperimental = true;
glewInit();
initShaders();
// Store the data for the triangles in a buffer that the gpu can use to draw
glGenVertexArrays(1, &vao0);
glBindVertexArray(vao0);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glGenBuffers(1, &ebo0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo0);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);
// Bind buffer data to shader values
posAttrib = glGetAttribLocation(shaderProgram, "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
glGenVertexArrays(1, &vao1);
glBindVertexArray(vao1);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glGenBuffers(1, &ebo1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo1);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(outlineElements), outlineElements, GL_STATIC_DRAW);
// Bind buffer data to shader values
posAttrib = glGetAttribLocation(shaderProgram, "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
timer.restart();
time_t timer;
time(&timer);
srand((unsigned int)timer);
generateTeapot();
InputManager::Init(&window);
CameraManager::Init(800.0f / 600.0f, 60.0f, 0.1f, 100.0f);
glEnable(GL_DEPTH_TEST);
}
示例10: Present
void Present() {
window_->display();
//sleep enough time
sf::Time t = tclock.restart();
if(t.asMilliseconds() < 1000.0 / 60.0)
sf::sleep(sf::milliseconds(1000.0 / 60.0) - t);
}
示例11: display
void display(sf::RenderWindow *window)
{
if (frames==0)
sfclock.restart();
// Draw using SFML
window->pushGLStates();
window->resetGLStates();
//insert SFML drawing code here (any part you are using that does not involve opengl code)
window->popGLStates();
//set up the background color of the window. This does NOT clear the window. Right now it is (0,0,0) which is black
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //this command actually clears the window.
glEnable(GL_DEPTH_TEST);
v.draw(raytrace); //simply delegate to our view class that has all the data and does all the rendering
if (frames>500)
{
sf::Time t = sfclock.getElapsedTime();
frame_rate = frames/t.asSeconds();
frames = 0;
}
else
{
frames++;
}
stringstream str;
// Finally, display the rendered frame on screen
window->display();
// cout << "Rendering" << endl;
}
示例12: gameLoop
/**
Représente un tour de boucle, ici ce trouve
toutes la gestion du jeu
@return true si pas de collision
*/
bool Game::gameLoop(sf::Clock & clock)
{
affichage();
sf::Event event;
recuperationEntree(event);
//valeur qui sera retrournée a la fin de la GameLoop
bool etat = m_map.collisionBloc(m_vaisseauJoueur, m_tirs, m_distanceParcouru);
actualisationInfoJoueur();
//actualisation du temps
m_tempsPasse = clock.getElapsedTime().asMicroseconds() / 20000.;
clock.restart().asMicroseconds();
m_tempsPasse /= m_coefRalentissement;
//calcul de la trajectoire puis la vitesse sera calculé a part
traitement(event, m_tempsPasse);
gestionScrolling(m_tempsPasse);
//deplacement des tirs
gererTirs(m_tempsPasse);
rechargeDesVaisseaux(m_tempsPasse);
actualiserAnimation(m_tempsPasse);
//comp 1
float tempsMaxComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeMax();
float tempsActuelComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeActuel();
float rapportComp1 = 1;
if (tempsActuelComp != tempsMaxComp)
rapportComp1 = ((tempsMaxComp - tempsActuelComp) / tempsMaxComp);
//comp 2
tempsMaxComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeMax();
tempsActuelComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeActuel();
float rapportComp2 = tempsActuelComp / tempsMaxComp;
//comp 3
tempsMaxComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeMax();
tempsActuelComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeActuel();
float rapportComp3 = 1;
if (m_vaisseauJoueur.getCompetence(1)->estActive())
{
rapportComp3 = tempsActuelComp / tempsMaxComp;
}
else if (tempsActuelComp != tempsMaxComp)
{
rapportComp3 = (tempsMaxComp - tempsActuelComp) / tempsMaxComp;
}
tableauDeBord.actualiserAnimationAvecCompetence(rapportComp1, rapportComp2, rapportComp3, m_vaisseauJoueur.getCompetence(1)->estActive());
return etat;
}
示例13: update
void pacman::update(){
xpos += xvel;
ypos += yvel;
sprite.setPosition(sf::Vector2f(xpos, ypos));
anspr.setPosition(sf::Vector2f(xpos, ypos));
collision_box = anspr.getGlobalBounds();
anspr.update(frame_time.restart());
}
示例14: CheckForEnemyCreate
void CheckForEnemyCreate() { if(enemy_create.getElapsedTime() > sf::milliseconds(500))
{
int willThereBeEnemy = rand()%10;
if(willThereBeEnemy >= 4)
EnemyGroup.resize(EnemyGroup.size()+1);
enemy_create.restart();
}
}
示例15: update
void update() {
delta_t = clock.getElapsedTime();
if (delta_t<max_frame_time)
sf::sleep(max_frame_time - delta_t);
delta_t = clock.restart();
currentFPS = 1 / delta_t.asSeconds();
delta_t *= time_factor;
}