From a9a9af96f5cb7f027d4e184fc934dba294b6fade Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 20 Dec 2000 22:46:12 +0000 Subject: [PATCH] --- data/Scripts/test.scr | 14 ++++++++++++-- source/gfx/animtex.cpp | 4 ++-- source/gfx/bubicles.cpp | 2 +- source/system/clickcount.cpp | 7 ++++--- source/system/gstate.cpp | 37 ++++++++++++++++++++++++------------ source/system/gstate.h | 6 +++--- source/system/vid.cpp | 6 ++++++ source/system/vid.h | 1 + 8 files changed, 54 insertions(+), 23 deletions(-) diff --git a/data/Scripts/test.scr b/data/Scripts/test.scr index 9d8f53cc3..898f3d9cb 100644 --- a/data/Scripts/test.scr +++ b/data/Scripts/test.scr @@ -37,10 +37,20 @@ vx=velocity; vy=velocity; while(1==1) { - _drawSprite(0,x,y,100); +// readout for fps :) +$tmp0=_getFrameTime(); +//print($tmp0); +$tmp5=50; +do{ + _drawSprite(4,$tmp5,50,10); + $tmp5=$tmp5+15; + $tmp0=$tmp0-1; +}while($tmp0>0); + + + _drawSprite(0,x,y,100); $tmp0=_getFrameTime(); - print($tmp0); do { x=x+vx; diff --git a/source/gfx/animtex.cpp b/source/gfx/animtex.cpp index ac27ce5b5..6418fec92 100644 --- a/source/gfx/animtex.cpp +++ b/source/gfx/animtex.cpp @@ -117,7 +117,7 @@ CAnimTex *ThisTex=AnimTexList; RECT Rect; int Count,CountComp; int H,W; -int Time = GameState::getTimeSinceLast(); +int Time = GameState::getFramesSinceLast(); while (ThisTex) { @@ -141,7 +141,7 @@ int Time = GameState::getTimeSinceLast(); Rect.h=CountComp; LoadImage(&Rect,ThisTex->TexData); } - ThisTex->Count+=(ThisTex->Speed * Time)>> 12; + ThisTex->Count+=(ThisTex->Speed * Time); ThisTex->Count%=(ThisTex->Rect.h<<2); ThisTex=ThisTex->NextTex; } diff --git a/source/gfx/bubicles.cpp b/source/gfx/bubicles.cpp index 47e66f8c4..dc81ad3e6 100644 --- a/source/gfx/bubicles.cpp +++ b/source/gfx/bubicles.cpp @@ -563,7 +563,7 @@ CBubicle *CBubicleFactory::spawnParticle(BubicleEmitterData *_init) } } - SYSTEM_DBGMSG("Out of CBubicles!"); +// SYSTEM_DBGMSG("Out of CBubicles!"); return NULL; } diff --git a/source/system/clickcount.cpp b/source/system/clickcount.cpp index 260183a0a..7e1e4493b 100644 --- a/source/system/clickcount.cpp +++ b/source/system/clickcount.cpp @@ -15,10 +15,11 @@ u32 CClickCount::s_currentTime=0; bool CClickCount::s_initialised=false; bool CClickCount::s_paused=false; -static const int COUNT_DOWN_VAL = 17200;//2150; -static const int COUNTS_PER_FRAME_INTERNAL = 4; +static const int COUNT_DOWN_VAL = 17200; +static const int COUNTS_PER_FRAME_INTERNAL = 2; static const int COUNTS_PER_FRAME_EXTERNAL = 4096; + /*****************************************************************************/ void clockTicker() { @@ -48,8 +49,8 @@ u32 CClickCount::timeSinceLast() timeSince=currentTime-m_lastTime; m_lastTime=currentTime; + return((timeSince*COUNTS_PER_FRAME_EXTERNAL)/COUNTS_PER_FRAME_INTERNAL); - return(currentTime*4096); } /*****************************************************************************/ diff --git a/source/system/gstate.cpp b/source/system/gstate.cpp index 316f572a0..57f223de2 100644 --- a/source/system/gstate.cpp +++ b/source/system/gstate.cpp @@ -15,12 +15,26 @@ #include "system\global.h" #include "system\gstate.h" +#ifndef __MEMORY_HEADER__ +#include "mem\memory.h" +#endif + +#ifndef __VID_HEADER_ +#include "system\vid.h" +#endif + + + +/*****************************************************************************/ + + +// Use click counter or vbl counter +#define USE_CLICK_COUNTER + +#ifdef USE_CLICK_COUNTER #ifndef __SYSTEM_CLICKCOUNT_H__ #include "system\clickcount.h" #endif - -#ifndef __MEMORY_HEADER__ -#include "mem\memory.h" #endif @@ -28,8 +42,10 @@ static CScene *s_currentScene; static CScene *s_pendingScene; -int GameState::s_timeSinceLast; +#ifdef USE_CLICK_COUNTER static CClickCount s_clickCounter; +#endif +int GameState::s_framesSinceLast=1; #ifdef __VERSION_DEBUG__ static int s_baseMemory=0; @@ -145,16 +161,13 @@ CScene * GameState::getPendingScene() } /*****************************************************************************/ -static int s_timeSpeed = ONE; void GameState::updateTimer() { - s_timeSinceLast = (s_clickCounter.timeSinceLast() * s_timeSpeed) >> 12; - - if (s_timeSinceLast > 4 * 4096) - { - s_timeSinceLast = 4 * 4096; - SYSTEM_DBGMSG("updateTimer loosing frames!"); - } +#ifdef USE_CLICK_COUNTER + s_framesSinceLast=(s_clickCounter.timeSinceLast()>>12)/4+1; +#else + s_framesSinceLast=VidGetVblsThisFrame(); +#endif } diff --git a/source/system/gstate.h b/source/system/gstate.h index ea0c8a048..f933cacf2 100644 --- a/source/system/gstate.h +++ b/source/system/gstate.h @@ -20,6 +20,7 @@ + /*****************************************************************************/ class CScene { @@ -48,8 +49,7 @@ public: static void setNextScene( CScene *_nextScene ); - inline static long int getTimeSinceLast() {return s_timeSinceLast;} - inline static long int getFramesSinceLast() {return (s_timeSinceLast>>12)+1;} + inline static long int getFramesSinceLast() {return s_framesSinceLast;} static void setTimeSpeed( int speed ); @@ -67,7 +67,7 @@ private: GameState(); static void updateTimer(); - static int s_timeSinceLast; + static int s_framesSinceLast; }; diff --git a/source/system/vid.cpp b/source/system/vid.cpp index f41ca6a5b..82a814c35 100644 --- a/source/system/vid.cpp +++ b/source/system/vid.cpp @@ -19,6 +19,7 @@ static void (*VbFunc)(void); static VbFuncType VbFuncList[MaxVBFuncs]; static u32 FrameCounter=0,TickCount=0,TickBuffer[2]; +static u32 s_lastFrameCounter=0,s_vblsThisFrame=0; static sVidScreen Screen[2]; static int ScreenXOfs=0,ScreenYOfs=0; static int ScreenW, ScreenH; @@ -194,6 +195,7 @@ sVidScreen *VidGetDispScreen() {return (VidGetScreen());} sVidScreen *VidGetDrawScreen() {return &Screen[FrameFlipFlag^1];} u32 VidGetFrameCount() {return(FrameCounter);} u32 VidGetTickCount() {return(TickBuffer[FrameFlipFlag^1]);} +int VidGetVblsThisFrame() {return s_vblsThisFrame;} void SetScreenImage(u8 *Ptr) {ScreenImage=Ptr;} u8 *GetScreenImage() {return ScreenImage;} @@ -396,6 +398,10 @@ if(ScreenClipBox==2) AddPrimToList(f4,0); } + // How many frames since we last flipped the display? + int fc=FrameCounter; + s_vblsThisFrame=fc-s_lastFrameCounter; + s_lastFrameCounter=fc; } diff --git a/source/system/vid.h b/source/system/vid.h index 1d4304c8f..dd83e2d77 100644 --- a/source/system/vid.h +++ b/source/system/vid.h @@ -42,6 +42,7 @@ sVidScreen *VidGetDispScreen(); sVidScreen *VidGetDrawScreen(); u32 VidGetFrameCount(); u32 VidGetTickCount(); +int VidGetVblsThisFrame(); void VidSwapDraw();