- Main Page
- Classes
- Files

- File List
- File Members

# flTimer.c

Go to the documentation of this file.

    00001 #include "flGlobal.h"
    00002 #if FL_TIMER != 0
    00003 #include <stdio.h>
    00004 #include <psprtc.h>
    00005 #include <pspkernel.h>
    00006
    00007 #if FL_INCLUDE_ALL_C == 0
    00008 #include "flTimer.h"
    00009 #include "flMemory.h"
    00010
    00011 #if FL_DEBUG != 0
    00012 #include "flDebug.h"
    00013 #endif
    00014 #endif
    00015
    00016 u64 timerPauseUntil = 0;
    00017
    00018 Timer* timerCreate() {
    00019      Timer* tempTimer = (Timer*)memAlloc(sizeof(Timer));
    00020      if(!tempTimer) {
    00021           #if FL_DEBUG_ERROR != 0
    00022           debugError("Couldn't create timer.\nOut of memory.");
    00023           #endif
    00024           return NULL;
    00025      }
    00026      tempTimer->timerTimeNow = 0;
    00027      sceRtcGetCurrentTick(&tempTimer->timerTimeLast);
    00028      tempTimer->timerTickResolution = sceRtcGetTickResolution();
    00029      return tempTimer;
    00030 }
    00031
    00032 double timerGetDeltaTime(Timer* inTimer) {
    00033      if(!inTimer) {
    00034           #if FL_DEBUG_WARNING != 0
    00035           debugWarning("Trying to get delta time from a NULL timer.");
    00036           #endif
    00037           return 0;
    00038      }
    00039      if(inTimer->timerTimeLast < timerPauseUntil)
    00040           inTimer->timerTimeLast = timerPauseUntil;
    00041      sceRtcGetCurrentTick(&inTimer->timerTimeNow);
    00042      double tempDeltaTime = (inTimer->timerTimeNow - inTimer->timerTimeLast) / ((float)inTimer->timerTickResolution);
    00043      inTimer->timerTimeLast = inTimer->timerTimeNow;
    00044
    00045      return tempDeltaTime;
    00046 }
    00047
    00048 void timerFree(Timer* inTimer) {
    00049      #if FL_MEMORY != 0
    00050      memFree(inTimer);
    00051      #else
    00052      if(inTimer)
    00053           free(inTimer);
    00054      #endif
    00055 }
    00056
    00057 void timerPauseAll() {
    00058      sceRtcGetCurrentTick(&timerPauseUntil);
    00059 }
    00060
    00061 #endif