Commit aa24f7d5 authored by Steven Fuller's avatar Steven Fuller

* Added functions to do simple timing (to get a general feeling of frames

per second).
parent 61c56bb1
......@@ -442,7 +442,6 @@ void AdvancePushWall(void)
void RenderView(void)
{
Word frame;
centerangle = gamestate.viewangle<<GAMEANGLETOFINE; /* 512 to 2048 */
......
......@@ -358,6 +358,10 @@ Again:
void PlayLoop(void)
{
LongWord Timer;
InitGameCounter();
InitRendCounter();
LastTicCount = ReadTick();
do {
Timer = ReadTick(); /* How much time has elapsed */
......@@ -365,13 +369,18 @@ void PlayLoop(void)
gamestate.playtime += TicCount; /* Add the physical time to the elapsed time */
LastTicCount=Timer;
if (!SlowDown) {
TicCount = 4; /* Adjust from 4 */
}
if (TicCount>=5) {
TicCount = 4;
}
IO_CheckInput(); /* Read the controls from the system */
StartGameCounter();
madenoise = FALSE; /* No noise made (Yet) */
MoveDoors(); /* Open and close all doors */
MovePWalls(); /* Move all push walls */
......@@ -381,8 +390,17 @@ void PlayLoop(void)
UpdateFace(); /* Draw BJ's face and animate it */
viewx = actors[0].x; /* Where is the camera? */
viewy = actors[0].y;
StartRendCounter();
RenderView(); /* Draw the 3D view */
EndRendCounter();
EndGameCounter();
} while (playstate==EX_STILLPLAYING);
PrintGameCounter();
PrintRendCounter();
StopSong();
}
......
......@@ -20,11 +20,67 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include "wolfdef.h"
LongWord LastTick;
TimeCounter gametime, rendtime;
void InitTimeCounter(TimeCounter *t)
{
t->frames = 0;
t->mintime = 0xFFFFFFFF;
t->maxtime = 0;
t->total = 0;
}
void StartTimeCounter(TimeCounter *t)
{
struct timeval t0;
gettimeofday(&t0, NULL);
t->secs = t0.tv_sec;
t->usecs = t0.tv_usec;
}
void EndTimeCounter(TimeCounter *t)
{
struct timeval t0;
unsigned long curtime;
long secs, usecs;
gettimeofday(&t0, NULL);
secs = t0.tv_sec - t->secs;
usecs = t0.tv_usec - t->usecs;
curtime = secs * 1000000 + usecs;
if (curtime > t->maxtime)
t->maxtime = curtime;
if (curtime < t->mintime)
t->mintime = curtime;
t->total += curtime;
t->frames++;
}
void PrintTimeCounter(TimeCounter *t, char *header)
{
double avg;
if (t->frames == 0)
return;
avg = (double)t->total / (double)t->frames;
printf("%s:\n", header);
printf("Frames: %lu, time %lu, avg %f\n", t->frames, t->total, avg);
printf("Min: %lu, max:%lu\n", t->mintime, t->maxtime);
}
unsigned short int sMSB(unsigned short int x)
{
int x1 = (x & 0x00FF) << 8;
......
......@@ -175,6 +175,7 @@ int main(int argc, char *argv[])
InitData();
SlowDown = 1;
GameViewSize = 3;
NewGameWindow(GameViewSize);
......
......@@ -36,16 +36,45 @@ typedef struct {
int bottom;
} Rect;
typedef struct {
unsigned long frames;
unsigned long mintime;
unsigned long maxtime;
unsigned long total;
long secs;
long usecs;
} TimeCounter;
extern void InitTimeCounter(TimeCounter *t);
extern void StartTimeCounter(TimeCounter *t);
extern void EndTimeCounter(TimeCounter *t);
extern void PrintTimeCounter(TimeCounter *t, char *header);
extern TimeCounter gametime, rendtime;
#define InitGameCounter() InitTimeCounter(&gametime)
#define StartGameCounter() StartTimeCounter(&gametime)
#define EndGameCounter() EndTimeCounter(&gametime)
#define PrintGameCounter() PrintTimeCounter(&gametime, "Game Loop Time")
#define InitRendCounter() InitTimeCounter(&rendtime)
#define StartRendCounter() StartTimeCounter(&rendtime)
#define EndRendCounter() EndTimeCounter(&rendtime)
#define PrintRendCounter() PrintTimeCounter(&rendtime, "Render Loop Time")
#ifdef __BIGENDIAN__
unsigned short int sLSB(unsigned short int i);
extern unsigned short int sLSB(unsigned short int i);
#define sMSB(i) i
unsigned long lLSB(unsigned long i);
extern unsigned long lLSB(unsigned long i);
#define lMSB(i) i
#else /* __BIGENDIAN__ */
unsigned short int sLSB(unsigned short int i);
unsigned short int sMSB(unsigned short int i);
unsigned long lLSB(unsigned long i);
unsigned long lMSB(unsigned long i);
#define sLSB(i) i
extern unsigned short int sMSB(unsigned short int i);
#define lLSB(i) i
extern unsigned long lMSB(unsigned long i);
#endif /* __BIGENDIAN__ */
/* an angle_t occupies an entire 16 bits so wraparound is automatically handled */
......@@ -104,10 +133,10 @@ typedef unsigned short ufixed_t; /* 8.8 unsigned fixed point number */
#define VIEWHEIGHT 160 /* Height of the viewing area */
#endif
extern int VidWidth, VidHeight, ViewHeight;
#define SCREENWIDTH VidWidth
#define SCREENHEIGHT VidHeight
#define VIEWHEIGHT ViewHeight
extern int VidWidth, VidHeight, ViewHeight;
Word ScaleX(Word x); /* Scale factor for 320 mode points projected to SCREEN */
Word ScaleY(Word y);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment