view timeController.h @ 44:d810aa9ca03a

times. cosmetic stuff
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 15 Dec 2014 17:33:41 +0000
parents a223551fdc1f
children
line wrap: on
line source
    //
//  timeController.h
//  tweakathlon
//
//  Created by Robert Tubb on 10/02/2014.
//
//

#ifndef __tweakathlon__timeController__
#define __tweakathlon__timeController__
#include "ofMain.h"
#include <iostream>
#include "boost/function.hpp"
#include <boost/bind.hpp>
#import "TimedCallController.h"

typedef boost::function<void(void)> TimerCallbackFunction;
typedef map<unsigned long long, TimerCallbackFunction> TimesAndCallsMap;
typedef std::pair<unsigned long long, TimerCallbackFunction> TimeAndCallPair;

typedef unsigned long long TimerID; // the id is just the time it's set to fire, microsecs(?)
typedef unsigned long long TimerMicrosec; //microsecs(?)
typedef unsigned long long TimerMillisec;

class TimeController{
    
public:
    

    //----------------
    //----------------
    void init(){
        iosTimer = [[TimedCallController alloc] init];
        [iosTimer setAppRef:(id)this];
    };

    //----------------
    // called from testApp.update()
    void tick(){
        TimerID timeNow = getMicrosecTimeNow();
        callAndEraseAllExpired(timeNow);

    };

    //----------------
    void cancelEvent(TimerID which);
    //----------------
    TimerID scheduleEvent(TimerCallbackFunction cbfunc, int howLongMillisec);
    //----------------
    void startStopwatch();
    TimerMicrosec stopStopwatch();
    TimerMicrosec getStopwatchElapsedTime();
    
    void startCountDown(){
        
    };
    void countdownFinished(){
        
    };
    //----------------

private:
    TimesAndCallsMap timesAndCalls;
    TimerMillisec stopWatchStartTime; // millisec
    bool stopWatchRunning;
    //----------------
    void callAndEraseAllExpired(TimerMicrosec timeNow);

    TimedCallController* iosTimer;
    
    TimerMicrosec getMicrosecTimeNow(){
        double time_sec = [NSDate timeIntervalSinceReferenceDate];
        return TimerMicrosec(time_sec*1000000);
    }
    
};



#endif /* defined(__tweakathlon__timeController__) */