Code Search for Developers
 
 
  

tempo.cpp from FreePop at Krugle


Show tempo.cpp syntax highlighted

/***************************************************************************
                           tempo.cpp
                           -------------------
    begin                : Tue Jun 15 2004
    copyright            : (C) 2004 by Brendon Higgins
    email                : freepop-devel@lists.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tempo.h>
#include <ClanLib/core.h>
#include <iostream>

/**
 * Helper for Tempo.
 */
class Ticker: public CL_KeepAlive {
public:
    /**
     * Constructor.
     */
    Ticker(Tempo* tempo);

    /**
     * Ticks the clock in Tempo.
     */
    virtual void keep_alive();

private:
    /**
     * The Tempo I'm attached to.
     */
    Tempo* t;
};

Ticker::Ticker(Tempo* tempo): t(tempo) {
}

void Ticker::keep_alive() {
    t->tick();
}


Tempo::Tempo(): thisFrames(0), prevFrames(0), framesTime(0),
    prevTime(0), thisTime(0), delay(0) {    
}

void Tempo::start() {
    thisTime = CL_System::get_time();
    delay = 0;
    t = new Ticker(this);
}

void Tempo::tick() {
    prevTime = thisTime;
    thisTime = CL_System::get_time();
    delay = thisTime - prevTime;

    ++thisFrames;
    framesTime += delay;
    if (framesTime >= 1000) {
        do {
            framesTime -= 1000;
            prevFrames = thisFrames;
            thisFrames = 0;
        } while (framesTime >= 1000);
        // If we skip some seconds, only send the one signal.
        framesSignal(prevFrames);
    }
}

void Tempo::stop() {
    delete t;
    t = 0;
    delay = 0;
}

unsigned int Tempo::getDelay() const {
    return delay;
}

unsigned int Tempo::getFrames() const {
    return prevFrames;
}

CL_Signal_v1<int>& Tempo::getFramesSignal() {
    return framesSignal;
}

unsigned int Tempo::getStamp() const {
    return thisTime;
}

void Tempo::log(const std::string& s) const {
    std::cout << "T+" << thisTime << ": " << s << std::endl;
}




See more files for this project here

FreePop

FreePop is a multi-platform tile-based game based on the great old game Populous 2 by Bullfrog Productions Ltd., but much improved.

Project homepage: http://sourceforge.net/projects/freepop
Programming language(s): C++
License: other

  client/
    Makefile.am
    client.cpp
    client.h
    clientmisc.cpp
    clientmisc.h
    clientstate.cpp
    clientstate.h
    connectstate.cpp
    connectstate.h
    cropsclient.cpp
    cropsclient.h
    entityclient.cpp
    entityclient.h
    entityclientfactory.cpp
    entityclientfactory.h
    firecolumnclient.cpp
    firecolumnclient.h
    gamestate.cpp
    gamestate.h
    loadstate.cpp
    loadstate.h
    mapclient.cpp
    mapclient.h
    maptileclient.cpp
    maptileclient.h
    messagebox.cpp
    messagebox.h
    oversprite.cpp
    oversprite.h
    paintable.cpp
    paintable.h
    pausefader.cpp
    pausefader.h
    peepclient.cpp
    peepclient.h
    peepmagnetclient.cpp
    peepmagnetclient.h
    playerclient.cpp
    playerclient.h
    playeroptionsdialog.cpp
    playeroptionsdialog.h
    rockclient.cpp
    rockclient.h
    swampclient.cpp
    swampclient.h
    townclient.cpp
    townclient.h
    treeclient.cpp
    treeclient.h
    worldclient.cpp
    worldclient.h
  server/
    Makefile.am
    contagion.cpp
    contagion.h
  Makefile.am
  common.cpp
  common.h
  corner.cpp
  corner.h
  crops.cpp
  crops.h
  entity.cpp
  entity.h
  entityfactory.cpp
  entityfactory.h
  firecolumn.cpp
  firecolumn.h
  gridmap.h
  identity.cpp
  identity.h
  map.cpp
  map.h
  mappos.cpp
  mappos.h
  maptile.cpp
  maptile.h
  maptilepos.cpp
  maptilepos.h
  misc.h
  peep.cpp
  peep.h
  peepmagnet.cpp
  peepmagnet.h
  player.cpp
  player.h
  rock.cpp
  rock.h
  rotation.cpp
  rotation.h
  rules.cpp
  rules.h
  slope.cpp
  slope.h
  swamp.cpp
  swamp.h
  tempo.cpp
  tempo.h
  town.cpp
  town.h
  tree.cpp
  tree.h
  worldpos.cpp
  worldpos.h