|
Problems with HookTimer() in v2.7 Displaying 1-6 of 6 total.
1
dante-1
|
Since I wanted to see how the different .dlls perform I decided to make some fps-counter as my first v2.7 "project". Well, after reading through the Python tutorial, Python reference manual, Python library reference and the Verge 2.7 python reference I came up with this code:
fps=0
frames=0
def ShowFps():
global fps,frames
GetScreenImage().Rect( 10, 10, 70, 32, RGB(0,0,255,100), 1)
fnt.Print(12,12,"Fps:"+string.rjust(`fps`,4))
fnt.Print(12,21,"Frm:"+string.rjust(`frames`,4))
frames=frames+1
def CountFps():
global fps,frames
Log("Count called");
if GetTime()%100==0:
fps=frames
frames=0
HookRetrace(ShowFps)
HookTimer(CountFps)
Now, everything worked fine except for CountFps() not being called at all (I added the Log() to be sure).
Well, looks like I'll have to find another way of doing this...
Posted on 2001-08-19 12:13:53
|
dante-1
|
Well, here's the code again: (ignore _)
fps=0
frames=0
def ShowFps():
____global fps,frames
____GetScreenImage().Rect( 10, 10, 70, 32, RGB(0,0,255,100), 1)
____fnt.Print(12,12,"Fps:"+string.rjust(`fps`,4))
____fnt.Print(12,21,"Frm:"+string.rjust(`frames`,4))
____frames=frames+1
def CountFps():
____global fps,frames
____Log("Count called");
____if GetTime()%100==0:
________fps=frames
________frames=0
HookRetrace(ShowFps)
HookTimer(CountFps)
Is there a better way of keeping the indenting?
Posted on 2001-08-19 12:17:30
|
andy
|
is the only way to space with the boards at their present state. Maybe SoulBain or loretian could fix that. :)
Anyhow, HookTimer is only called when the map engine is active. I intend to improve this situation.
"Ignorance is its own reward" -- Proverb
Posted on 2001-08-19 15:13:39
|
Kut
|
Remove ';' from the line 'Log("Count called");'
I made that mistake many, many times!!
And also, I believe GetScreenImage is not an object; it returns an object!
try this:
rectangle = GetScreenImage()
def afunction():
_____global rectangle
_____rectangle.Rect(x,y,x2,y2,c,[true or false])
Failure is not an option,
Windows is built with it!
Posted on 2001-08-19 15:27:48
|
dante-1
|
I removed that ; already, and I think that in Python it is possible to treat a function that returns an object like the object itself (and the rectangle drawing works just fine).
BTW, i actually got a working version now, but it's veeeery ugly:
def ShowFps():
global fps,frames
GetScreenImage().Rect( 10, 10, 70, 32, RGB(0,0,255,100), 1)
fnt.Print(12,12,"Fps:"+string.rjust(`fps`,4))
fnt.Print(12,21,"Frm:"+string.rjust(`frames`,4))
frames=frames+1
if GetTime()%100=0 and GetTime()%1002:
fps=frames
frames=0
HookRetrace(ShowFps)
As I said, very ugly and not 100% reliable, but it gets the job done.
Posted on 2001-08-19 16:00:12
|
ShadowDrak
|
You could put this in a hook retrace
def FPS()
-global frames,time,timelast,fps
-time+=getTime()-timelast
-timelast=GetTime()
-frames++
-if time100:
--fps=frames/(time/100)
--time=0
--frames=0
of course youd have to initialize the global variables first but it cleans up the if statement a bit.
I don't see why every fps couter ive seen checks the point when it exactly hits one second(sometimes it will miss it). you do want it over one second for accuracy. but if i remember my math correctly:
workdone/timetaken= workdone per time.
I've seen similar code that worked in other people's c++ code.
Posted on 2001-08-21 17:54:27
|
Displaying 1-6 of 6 total.
1
|
|