Skip to content

Commit

Permalink
FITD: Wrap the timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
somaen committed Feb 5, 2012
1 parent 6b6a3ce commit 9b63b48
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/anim.cpp
Expand Up @@ -20,6 +20,7 @@
*
*/

#include "fitd.h"
#include "common.h"

namespace Fitd {
Expand Down Expand Up @@ -65,7 +66,7 @@ int initAnimInBody(int frame, char *anim, char *body) {
body += 14;

*(char **)(body + 2) = anim;
*(uint16 *)(body + 6) = timer;
*(uint16 *)(body + 6) = g_fitd->getTimer();

body += *(int16 *)body;
body += 2;
Expand Down Expand Up @@ -193,7 +194,7 @@ void initBufferAnim(char *buffer, char *bodyPtr) {
int cx;
int i;

*(uint16 *)(source + 4) = (unsigned short int)timer;
*(uint16 *)(source + 4) = (uint16)g_fitd->getTimer();
*(char **)(source) = buffer;

source += *(int16 *)(source - 2);
Expand Down Expand Up @@ -366,7 +367,7 @@ int16 setInterAnimObjet(int frame, char *animPtr, char *bodyPtr) {

bodyPtr += 10; // skip bone 0

time = (unsigned short int)timer - timeOfKeyframeStart;
time = (uint16)g_fitd->getTimer() - timeOfKeyframeStart;

bx = keyframeLength;
bp = time;
Expand Down Expand Up @@ -471,7 +472,7 @@ int16 setInterAnimObjet(int frame, char *animPtr, char *bodyPtr) {

*(char **)animVar3 = animVar1;

*(uint16 *)(animVar3 + 4) = (unsigned short int)timer;
*(uint16 *)(animVar3 + 4) = (uint16)g_fitd->getTimer();

tempBx += 2;

Expand Down
16 changes: 14 additions & 2 deletions src/debugger.h
Expand Up @@ -20,8 +20,20 @@
*
*/

#ifndef _DEBUGGER_H_
#define _DEBUGGER_H_
#ifndef FITD_DEBUGGER_H
#define FITD_DEBUGGER_H

#ifdef _DEBUG
#define ASSERT(exp) assert(exp)
#else
#define ASSERT(exp)
#endif

#ifdef _DEBUG
#define ASSERT_PTR(exp) assert(exp)
#else
#define ASSERT_PTR(exp)
#endif

#ifdef INTERNAL_DEBUGGER
namespace Fitd {
Expand Down
1 change: 1 addition & 0 deletions src/fitd.cpp
Expand Up @@ -28,6 +28,7 @@
#include "fitd.h"
#include "resource.h"
#include "osystem.h"
#include "common.h"

namespace Fitd {

Expand Down
13 changes: 12 additions & 1 deletion src/fitd.h
Expand Up @@ -27,8 +27,15 @@

#include <cstdio>
#include <cstdlib>
#ifdef HAVE_CONFIG_H
#undef HAVE_CONFIG_H
#define UNIX
#include "common/endian.h"
#define HAVE_CONFIG_H
#else
#include "common/endian.h"
#endif
#include "cvars.h"
#include "common.h"

namespace Fitd {

Expand All @@ -50,6 +57,8 @@ class FitdEngine {

void sysInit();
void detectGame();

uint32 _timer;
public:
FitdEngine();
void run();
Expand All @@ -67,6 +76,8 @@ class FitdEngine {
int32 getCVarsIdx(enumCVars searchedType);
void delay(uint32 ms);
int32 getTicks();
uint32 getTimer() { return _timer; }
void setTimer(uint32 value) { _timer = value; }
};

extern FitdEngine *g_fitd;
Expand Down
32 changes: 22 additions & 10 deletions src/hqr.cpp
Expand Up @@ -20,10 +20,21 @@
*
*/

#include "common.h"
//#include "common.h"
#undef HAVE_CONFIG_H
#define UNIX
#include "common/endian.h"
#include "hqr.h"
#include "pak.h"
#include "debugger.h"
#include "ourtime.h"
#include "fitd.h"
#include "file_access.h"

namespace Fitd {

int32 hqrKeyGen = 0;

struct hqrSubEntryStruct {
int16 key;
int16 size;
Expand Down Expand Up @@ -123,8 +134,8 @@ char *hqrEntryStruct::get(int index) {
foundEntry = quickFindEntry(index, _numUsedEntry, _entries);

if(foundEntry) {
foundEntry->lastTimeUsed = timer;
hqrVar1 = 0;
foundEntry->lastTimeUsed = g_fitd->getTimer();
_hqrVar1 = 0;

return(foundEntry->ptr);
} else {
Expand Down Expand Up @@ -181,10 +192,9 @@ char *hqrEntryStruct::get(int index) {
unfreezeTime();*/

int size;
unsigned int time;
int32 size;
uint32 time;
char *ptr;
int i;

freezeTime();
size = getPakSize(_string, index);
Expand All @@ -193,9 +203,9 @@ char *hqrEntryStruct::get(int index) {
theEnd(1, _string);
}

time = timer;
time = g_fitd->getTimer();

for(i = 0; i < _numMaxEntry; i++) {
for(int i = 0; i < _numMaxEntry; i++) {
if(_entries[i].ptr == NULL) {
foundEntry = &_entries[i];
break;
Expand All @@ -206,10 +216,10 @@ char *hqrEntryStruct::get(int index) {

// foundEntry = hqrSubPtr;

hqrVar1 = 1;
_hqrVar1 = 1;

foundEntry->key = index;
foundEntry->lastTimeUsed = timer;
foundEntry->lastTimeUsed = g_fitd->getTimer();
//foundEntry[hqrPtr->numUsedEntry].offset = hqrPtr->maxFreeData - hqrPtr->sizeFreeData;
foundEntry->size = size;
foundEntry->ptr = (char *)malloc(size);
Expand All @@ -228,6 +238,7 @@ char *hqrEntryStruct::get(int index) {
}

hqrEntryStruct::hqrEntryStruct(const char *name, int size, int numEntries) {
_hqrVar1 = 0;
numEntries = 2000;

char temp[10];
Expand All @@ -247,6 +258,7 @@ hqrEntryStruct::hqrEntryStruct(const char *name, int size, int numEntries) {
}

hqrEntryStruct::hqrEntryStruct(int32 size, int32 numEntry) {
_hqrVar1 = 0;
ASSERT(size > 0);
ASSERT(numEntry > 0);

Expand Down
2 changes: 2 additions & 0 deletions src/hqr.h
Expand Up @@ -35,11 +35,13 @@ struct hqrEntryStruct {
uint16 _numMaxEntry;
uint16 _numUsedEntry;
hqrSubEntryStruct *_entries;
int32 _hqrVar1;
public:
hqrEntryStruct(const char *name, int size, int numEntries);
hqrEntryStruct(int size, int numEntries);
~hqrEntryStruct();
char *get(int index);
int32 getVar1() { return _hqrVar1; }
void reset();
int printTextSub1(int size);
char *printTextSub2(int index);
Expand Down
4 changes: 2 additions & 2 deletions src/life.cpp
Expand Up @@ -1608,7 +1608,7 @@ void processLife(int lifeNum) {
readKeyboard();

timeGlobal++;
timer = timeGlobal;
g_fitd->setTimer(timeGlobal);

time = evalChrono(&chrono);

Expand Down Expand Up @@ -1656,7 +1656,7 @@ void processLife(int lifeNum) {
flipScreen();

timeGlobal++;
timer = timeGlobal;
g_fitd->setTimer(timeGlobal);

time = evalChrono(&chrono);

Expand Down
14 changes: 7 additions & 7 deletions src/main.cpp
Expand Up @@ -1755,7 +1755,7 @@ void startActorRotation(int16 beta, int16 newBeta, int16 param, rotateStruct *ro
rotatePtr->oldAngle = beta;
rotatePtr->newAngle = newBeta;
rotatePtr->param = param;
rotatePtr->timeOfRotate = timer;
rotatePtr->timeOfRotate = g_fitd->getTimer();
}

int16 updateActorRotation(rotateStruct *rotatePtr) {
Expand All @@ -1765,7 +1765,7 @@ int16 updateActorRotation(rotateStruct *rotatePtr) {
if(!rotatePtr->param)
return(rotatePtr->newAngle);

timeDif = timer - rotatePtr->timeOfRotate;
timeDif = g_fitd->getTimer() - rotatePtr->timeOfRotate;

if(timeDif > rotatePtr->param) {
rotatePtr->param = 0;
Expand Down Expand Up @@ -2687,7 +2687,7 @@ void mainDraw(int mode) {
} else {
char *bodyPtr = listBody->get(actorPtr->bodyNum);

if(hqrVar1) {
if(listBody->getVar1()) {
// initAnimInBody(actorPtr->FRAME, HQR_Get(listAnim, actorPtr->ANIM), bodyPtr);
}

Expand Down Expand Up @@ -2948,7 +2948,7 @@ void foundObject(int objIdx, int param) {
}

if(objPtr->trackNumber) {
if(timer - objPtr->trackNumber < 300) // prevent from reopening the window every frame
if(g_fitd->getTimer() - objPtr->trackNumber < 300) // prevent from reopening the window every frame
return;
}

Expand Down Expand Up @@ -3045,7 +3045,7 @@ void foundObject(int objIdx, int param) {
if(var_6 == 1) {
take(objIdx);
} else {
objPtr->trackNumber = timer;
objPtr->trackNumber = g_fitd->getTimer();
}

while(input2 && input1) {
Expand Down Expand Up @@ -3245,12 +3245,12 @@ int processActor1Sub2(rotateStruct *data) {
if(!data->param)
return data->newAngle;

if(timer - data->timeOfRotate > (unsigned int)data->param) {
if(g_fitd->getTimer() - data->timeOfRotate > (unsigned int)data->param) {
data->param = 0;
return data->newAngle;
}

return ((((data->newAngle - data->oldAngle) * (timer - data->timeOfRotate)) / data->param) + data->oldAngle);
return ((((data->newAngle - data->oldAngle) * (g_fitd->getTimer() - data->timeOfRotate)) / data->param) + data->oldAngle);
}

void processActor1(void) {
Expand Down
2 changes: 1 addition & 1 deletion src/main_loop.cpp
Expand Up @@ -70,7 +70,7 @@ void mainLoop(int allowSystemMenu) {

timeGlobal++;

timer = timeGlobal;
g_fitd->setTimer(timeGlobal);

process_events();
readKeyboard();
Expand Down
11 changes: 7 additions & 4 deletions src/save.cpp
Expand Up @@ -248,8 +248,10 @@ int loadSave(int saveNumber) {
ASSERT(sizeof(shakeVar1) == 2);
fread(&shakeVar1, 2, 1, fHandle);

ASSERT(sizeof(timer) == 4);
fread(&timer, 4, 1, fHandle);
uint32 tempTimer;
ASSERT(sizeof(g_fitd->getTimer()) == 4);
fread(&tempTimer, 4, 1, fHandle);
g_fitd->setTimer(tempTimer);

ASSERT(sizeof(timerFreeze1) == 4);
fread(&timerFreeze1, 4, 1, fHandle);
Expand Down Expand Up @@ -731,8 +733,9 @@ int makeSaveFile(int entry) {
ASSERT(sizeof(shakeVar1) == 2);
fwrite(&shakeVar1, 2, 1, fHandle);

ASSERT(sizeof(timer) == 4);
fwrite(&timer, 4, 1, fHandle);
uint32 tempTimer = g_fitd->getTimer();
ASSERT(sizeof(g_fitd->getTimer()) == 4);
fwrite(&tempTimer, 4, 1, fHandle);

ASSERT(sizeof(timerFreeze1) == 4);
fwrite(&timerFreeze1, 4, 1, fHandle);
Expand Down
2 changes: 1 addition & 1 deletion src/sequence.cpp
Expand Up @@ -169,7 +169,7 @@ void playSequence(int sequenceIdx, int fadeStart, int fadeOutVar) {

timeGlobal++;

timer = timeGlobal;
g_fitd->setTimer(timeGlobal);

if(g_fitd->getGameType() == GType_AITD2) {
strcpy(buffer, sequenceListAITD2[sequenceIdx]);
Expand Down
6 changes: 3 additions & 3 deletions src/tatou.cpp
Expand Up @@ -21,7 +21,7 @@
*/

// seg 4

#include "fitd.h"
#include "osystem.h"
#include "resource.h"
#include "common.h"
Expand Down Expand Up @@ -285,11 +285,11 @@ void process_events(void) {
#endif

void startChrono(unsigned int *chrono) {
*chrono = timer;
*chrono = g_fitd->getTimer();
}

int evalChrono(unsigned int *chrono) {
return(timer - *chrono);
return(g_fitd->getTimer() - *chrono);
}

// bp = x, bx = y, cx = z
Expand Down
9 changes: 5 additions & 4 deletions src/track.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "common/textconsole.h"
#include "fitd.h"
#include "common.h"
#include "math.h"

Expand Down Expand Up @@ -288,7 +289,7 @@ void processTrack(void) {
case 1: { // manual
manualRot(60);
if(input4 & 1) { // forward
if(timer - lastTimeForward < 10 && currentProcessedActorPtr->speed != 4)
if(g_fitd->getTimer() - lastTimeForward < 10 && currentProcessedActorPtr->speed != 4)
currentProcessedActorPtr->speed = 5;
else if(currentProcessedActorPtr->speed == 0 || currentProcessedActorPtr->speed == -1)
currentProcessedActorPtr->speed = 4;
Expand All @@ -297,7 +298,7 @@ void processTrack(void) {
currentProcessedActorPtr->speed = 5; */


lastTimeForward = timer;
lastTimeForward = g_fitd->getTimer();
} else {
if(currentProcessedActorPtr->speed > 0 && currentProcessedActorPtr->speed <= 4) {
currentProcessedActorPtr->speed--;
Expand Down Expand Up @@ -709,7 +710,7 @@ void processTrack2(void) {
case 1: { // manual
manualRot(60);
if(input4 & 1) { // forward
if(timer - lastTimeForward < 10 && currentProcessedActorPtr->speed != 4)
if(g_fitd->getTimer() - lastTimeForward < 10 && currentProcessedActorPtr->speed != 4)
currentProcessedActorPtr->speed = 5;
else if(currentProcessedActorPtr->speed == 0 || currentProcessedActorPtr->speed == -1)
currentProcessedActorPtr->speed = 4;
Expand All @@ -718,7 +719,7 @@ void processTrack2(void) {
currentProcessedActorPtr->speed = 5; */


lastTimeForward = timer;
lastTimeForward = g_fitd->getTimer();
} else {
if(currentProcessedActorPtr->speed > 0 && currentProcessedActorPtr->speed <= 4) {
currentProcessedActorPtr->speed--;
Expand Down

0 comments on commit 9b63b48

Please sign in to comment.