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,9 +442,8 @@ void AdvancePushWall(void) ...@@ -442,9 +442,8 @@ void AdvancePushWall(void)
void RenderView(void) void RenderView(void)
{ {
Word frame; Word frame;
centerangle = gamestate.viewangle<<GAMEANGLETOFINE; /* 512 to 2048 */ centerangle = gamestate.viewangle<<GAMEANGLETOFINE; /* 512 to 2048 */
centershort = centerangle<<ANGLETOFINESHIFT; /* 2048 to 64k */ centershort = centerangle<<ANGLETOFINESHIFT; /* 2048 to 64k */
viewsin = sintable[gamestate.viewangle]; /* Get the basic sine */ viewsin = sintable[gamestate.viewangle]; /* Get the basic sine */
...@@ -472,5 +471,5 @@ void RenderView(void) ...@@ -472,5 +471,5 @@ void RenderView(void)
} }
IO_AttackShape(gamestate.weapon*4 + frame); /* Draw the gun shape */ IO_AttackShape(gamestate.weapon*4 + frame); /* Draw the gun shape */
} }
IO_DisplayViewBuffer(); /* blit to screen */ IO_DisplayViewBuffer(); /* blit to screen */
} }
...@@ -358,20 +358,29 @@ Again: ...@@ -358,20 +358,29 @@ Again:
void PlayLoop(void) void PlayLoop(void)
{ {
LongWord Timer; LongWord Timer;
LastTicCount = ReadTick();
InitGameCounter();
InitRendCounter();
LastTicCount = ReadTick();
do { do {
Timer = ReadTick(); /* How much time has elapsed */ Timer = ReadTick(); /* How much time has elapsed */
TicCount = (Timer-LastTicCount); TicCount = (Timer-LastTicCount);
gamestate.playtime += TicCount; /* Add the physical time to the elapsed time */ gamestate.playtime += TicCount; /* Add the physical time to the elapsed time */
LastTicCount=Timer; LastTicCount=Timer;
if (!SlowDown) { if (!SlowDown) {
TicCount = 4; /* Adjust from 4 */ TicCount = 4; /* Adjust from 4 */
} }
if (TicCount>=5) { if (TicCount>=5) {
TicCount = 4; TicCount = 4;
} }
IO_CheckInput(); /* Read the controls from the system */ IO_CheckInput(); /* Read the controls from the system */
StartGameCounter();
madenoise = FALSE; /* No noise made (Yet) */ madenoise = FALSE; /* No noise made (Yet) */
MoveDoors(); /* Open and close all doors */ MoveDoors(); /* Open and close all doors */
MovePWalls(); /* Move all push walls */ MovePWalls(); /* Move all push walls */
...@@ -381,8 +390,17 @@ void PlayLoop(void) ...@@ -381,8 +390,17 @@ void PlayLoop(void)
UpdateFace(); /* Draw BJ's face and animate it */ UpdateFace(); /* Draw BJ's face and animate it */
viewx = actors[0].x; /* Where is the camera? */ viewx = actors[0].x; /* Where is the camera? */
viewy = actors[0].y; viewy = actors[0].y;
StartRendCounter();
RenderView(); /* Draw the 3D view */ RenderView(); /* Draw the 3D view */
EndRendCounter();
EndGameCounter();
} while (playstate==EX_STILLPLAYING); } while (playstate==EX_STILLPLAYING);
PrintGameCounter();
PrintRendCounter();
StopSong(); StopSong();
} }
......
...@@ -20,11 +20,67 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -20,11 +20,67 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h>
#include "wolfdef.h" #include "wolfdef.h"
LongWord LastTick; 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) unsigned short int sMSB(unsigned short int x)
{ {
int x1 = (x & 0x00FF) << 8; int x1 = (x & 0x00FF) << 8;
......
...@@ -175,6 +175,7 @@ int main(int argc, char *argv[]) ...@@ -175,6 +175,7 @@ int main(int argc, char *argv[])
InitData(); InitData();
SlowDown = 1;
GameViewSize = 3; GameViewSize = 3;
NewGameWindow(GameViewSize); NewGameWindow(GameViewSize);
......
...@@ -36,16 +36,45 @@ typedef struct { ...@@ -36,16 +36,45 @@ typedef struct {
int bottom; int bottom;
} Rect; } 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__ #ifdef __BIGENDIAN__
unsigned short int sLSB(unsigned short int i); extern unsigned short int sLSB(unsigned short int i);
#define sMSB(i) i #define sMSB(i) i
unsigned long lLSB(unsigned long i); extern unsigned long lLSB(unsigned long i);
#define lMSB(i) i #define lMSB(i) i
#else /* __BIGENDIAN__ */ #else /* __BIGENDIAN__ */
unsigned short int sLSB(unsigned short int i); #define sLSB(i) i
unsigned short int sMSB(unsigned short int i); extern unsigned short int sMSB(unsigned short int i);
unsigned long lLSB(unsigned long i); #define lLSB(i) i
unsigned long lMSB(unsigned long i); extern unsigned long lMSB(unsigned long i);
#endif /* __BIGENDIAN__ */ #endif /* __BIGENDIAN__ */
/* an angle_t occupies an entire 16 bits so wraparound is automatically handled */ /* 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 */ ...@@ -104,10 +133,10 @@ typedef unsigned short ufixed_t; /* 8.8 unsigned fixed point number */
#define VIEWHEIGHT 160 /* Height of the viewing area */ #define VIEWHEIGHT 160 /* Height of the viewing area */
#endif #endif
extern int VidWidth, VidHeight, ViewHeight;
#define SCREENWIDTH VidWidth #define SCREENWIDTH VidWidth
#define SCREENHEIGHT VidHeight #define SCREENHEIGHT VidHeight
#define VIEWHEIGHT ViewHeight #define VIEWHEIGHT ViewHeight
extern int VidWidth, VidHeight, ViewHeight;
Word ScaleX(Word x); /* Scale factor for 320 mode points projected to SCREEN */ Word ScaleX(Word x); /* Scale factor for 320 mode points projected to SCREEN */
Word ScaleY(Word y); 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