Getting a negative readout from millisecs  


πŸ‘‰ BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member πŸ‘ˆ

 

Tweet
fox95871

I never solved this years ago, if someone can help...

https://archive.blitzcoder.org/forums/b3d-beginners/106608.html

I'm sure they explained it fine, but I do a lot better with mods of code I posted.


; IFPS

; I found out years ago that if you make a "copy" of one of the variables of the holy Render tween, you can use it to keep
; an eye on how many times your computer's running your code per second, which of course is much more useful than just
; happening to notice if something you did caused it to go lower than 30. with the ifps copy of fr, you can always see if
; it's in the 300s, 400s... or even over 1000 if your program's very lite.

; however, as you'll see in my old post, that all changed when I got a laptop. I named that thread wrong BTW, it's more
; like "Ifps always stuck at 60", but whatever. please fix my code if you can. you'll need a laptop that causes the bug of
; course, so if it says 1000s on yours, no go. but 60? go! :)

; setup ------------------------------------------------------------------------------------------------------------------

Graphics3D 1024,768,32,1
SetBuffer BackBuffer()
blitz=LoadFont("blitz",11,1,0,0):SetFont blitz:Color 128,128,128
SeedRnd MilliSecs()
wireframestate = 0
flipstate      = 0

; ------------------------------------------------------------------------------------------------------------------------

; ifps -------------------------------------------------------------------------------------------------------------------

fps      = 30
period   =  1000/fps
time     =  MilliSecs()-period
elapsed  =  0
ticks    =  0
tween   #=  0.0
rt       =  0
fr       =  0
frtime   =  0
ifps     =  0

; ------------------------------------------------------------------------------------------------------------------------

; camera -----------------------------------------------------------------------------------------------------------------

Global camera=CreateCamera()
CameraRange camera,0.1,100
CameraZoom camera,1.6
PositionEntity camera,0,9,-15
RotateEntity camera,22.5,0,0
zoomswitch = 0

; ------------------------------------------------------------------------------------------------------------------------

; lights -----------------------------------------------------------------------------------------------------------------

Global light=CreateLight()
RotateEntity light,Rnd(40,50),Rnd(-85,-95),0 
AmbientLight 255,255,255
CameraClsColor camera,25,25,25

; ------------------------------------------------------------------------------------------------------------------------

; level ------------------------------------------------------------------------------------------------------------------

cement=CreateCube()
ScaleMesh    cement,10,10,7
PositionMesh cement,0,0,3
RotateMesh   cement,0,0,0
FlipMesh     cement
EntityColor  cement,40,40,30

; ------------------------------------------------------------------------------------------------------------------------

; EVERY 3D FRAME...

While Not KeyHit(1)
Cls
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween=Float(elapsed Mod period)/Float(period)
For rt=1 To ticks
time=time+period
If rt=ticks

; v code v

; camera -----------------------------------------------------------------------------------------------------------------

If KeyHit(44) zoomswitch=1-zoomswitch ; z
If zoomswitch=1 PositionEntity camera,0,9,-25
If zoomswitch=0 PositionEntity camera,0,9,-15

; ------------------------------------------------------------------------------------------------------------------------

; ^ code ^

CaptureWorld
EndIf

; MOST 3D FRAMES...

; v code v

; ^ code ^

UpdateWorld
Next
RenderWorld tween

; EVERY 2D FRAME...

fr=fr+1
If MilliSecs()-frtime>=1000
ifps=fr
fr=0
frtime=MilliSecs()
EndIf

; v code v

; readouts ---------------------------------------------------------------------------------------------------------------

Text  10,  5,"controls: esc"
Text 924,747,"ifps: "       +ifps

; ------------------------------------------------------------------------------------------------------------------------

; switches ---------------------------------------------------------------------------------------------------------------

If KeyHit(17) wireframestate=1-wireframestate ; w
WireFrame wireframestate

; ------------------------------------------------------------------------------------------------------------------------

; ^ code ^

Flip flipstate
Wend
End

;
RemiD commented:

after a quick look at your code, something that may help your issue :

when you want to divide a value, it is preferable to declare it as a float variable for the result to be more precise.

for example :
'period#'
'elapsed#'
'tween#'

fox95871 commented:

I read the whole thread. Having no notion of what I'm doing, I at least came up with this...


; creation

;time   =MilliSecs()  -period                                 ; previous
         millisecs_fix             =MilliSecs() And $7FFFFFFF ; now
 time   =millisecs_fix-period

; 3d

;elapsed=MilliSecs()  -time
         millisecs_fix             =MilliSecs() And $7FFFFFFF
 elapsed=millisecs_fix-time

; 2d

;If      MilliSecs()  -frtime>=1000
         millisecs_fix             =MilliSecs() And $7FFFFFFF
 If      millisecs_fix-frtime>=1000

;frtime =MilliSecs()
         millisecs_fix             =MilliSecs() And $7FFFFFFF
 frtime =millisecs_fix

;

but it's still at about 60. Also, if I do the $7F thing in creation only like I thought it should be at first, it's 1, AND my computer gets bricked for a bit.

RemiD commented:

can you reformulate what you are trying to achieve with this ?

fox95871 commented:

Not really, everyone's always said don't mess with the Render tween. Thus, I must do otherwise, though I don't really know what I'm doing when it comes to code like this. Avoidance of low level programming is why I got Blitz3d XD

No, I love programming with the commands and techniques I DO understand, but other times - like now - I need a mod by a born into it, dyed in the wool programmer. I started programming at 30 afterall, not 3. But to be practical now, does anyone else get a readout of about 60 running my program? I think I read that on Windows 10 laptops, system time related woes like this are pretty common.

Oh and to be clear, the FPS is what's set to 30, whereas what I call the IFPS, for "internal" frames per second, reveals that the computer's actually completing the main loop 100s or even over 1000 times a second - AMAZING - on computers where Millisecs or whatever isn't messing it up, that is. I suspect / borderline hope that it might just be the readout, and not the actual Render tween that's being affected, but it could be one, the other, or both.

Can't fix it if I don't know which part's broken nm^)

RemiD commented:

ok, so you have not idea what you want to achieve ?

an info related to this :
if you use flip(false), the main loop will not be slowed down by the frequency of your screen (60hz usually).

this may explain what you have noticed.

fox95871 commented:

It already WAS achieved, but I later found out it doesn't work on laptops. Also, Flip 1 deactivates the IFPS, but that's actually good for making a finished game not have screen tearing, and Flip 0 - IFPS on - is important for development, so you can see how changes affect your programs speed. I tested the refresh rate idea on a tower, and the IFPS is equal to IT for Flip 1, and in the 900s for Flip 0, whereas on my laptop, both were equal to the refresh rate. I haven't tried the variable declarations idea because I don't want to change anything about the original Render tween, but I DID try capturing the IFPS from other places in it than line 155 - basically a trial and error search for any readout in the high 100s to somewhere over 1000, usually - but no luck yet.

RemiD commented:

why do you need this ? what do you want to achieve with this ?

fox95871 commented:

As of today, I now understand why you don't know what its purpose is, because I just tested it out on yet another computer, and found it's not just a laptop problem, but a Windows 10 one.

Okay okay, what it does when it's working on my Windows XP tower, is tell me how much of an impact changes to my code have on a programs speed. If for example I put one cube on the screen, no problem, the IFPS readout would easily show it's between maybe 800 and 900, with minor active variations, usually in the single or double digits. BUT, if I put 50, or 100 cubes, oops! it then drops down to the low 100s. Also, if ever there's a memory leak, you see the readout start to decrease, which is of course exceedingly helpful in preventing your computer from going into meltdown mode while you go get snacks XD

I discovered this tool by mistake years ago when I put all the variables of the Render tween on the screen as readouts, and saw this unique behavior in one of them, then realized how useful it could be - sort of like the accidental invention of rubber, or sticky notes - and it's been pretty much indispensable to me ever since. I was hoping to be able to use it in Windows 10, as well as share it, if I can get it working. But as it stands, and for the record, the code for it in my first post does work on a tower running Windows XP ...or MINE, anyway. We all know that story, of course.

Sorry for the confusion, and I hope that clears things up :)

BlitzCoder commented:

if I put 50, or 100 cubes, oops! it then drops down to the low 100s

This actually depends on your gfx card and setup. Back then gfx cards are being pushed to the limits even with only the smallest effects.

Most PCs today have a capable gfx card, so you just have to rely on your game code to do its work and perhaps do some delta timing on the side.

I set mine to match my monitor refresh rate or flip true to avoid that annoying coil whine (the above code does that btw). ΓΆ ..unless i'm testing scene or renderer benchmark.

fox95871 commented:

I was able to find a LITTLE information on Delta timing...

https://archive.blitzcoder.org/forums/b3d-programming/28726.html
https://archive.blitzcoder.org/forums/b3d-programming/38185.html
https://archive.blitzcoder.org/forums/b3d-beginners/38202.html
https://archive.blitzcoder.org/forums/b3d-programming/35890.html
https://archive.blitzcoder.org/forums/b3d-programming/45655.html
https://archive.blitzcoder.org/forums/b3d-programming/45960.html
https://archive.blitzcoder.org/forums/b3d-programming/50289.html
https://archive.blitzcoder.org/forums/b3d-programming/69659.html
https://archive.blitzcoder.org/forums/b3d-programming/75617.html
https://archive.blitzcoder.org/forums/b3d-beginners/82959.html

thanks a lot, I'll be here all year XD

So Windows 10 overrides the Render tween and forces your game to run at the screens refresh rate, huh? Well, if I have to figure out how to make my games timing congruent on all computers now, I guess I'll just settle for the IFPS at least working for me.

[ edit, Windows 10 doesn't override the Render tween. I was tired, and had 2 .bbs confused with each other when I wrote that ]

As for the coil whine, is that just with Flip 0? If you could find out if changing flipstate to 1 prevents that on your computer, I'd appreciate it. I realized too late today - can't edit posted code after a week - that my zoom and wireframe switches should have been like this...

If KeyHit(44)
zoomswitch=1-zoomswitch ; z
If zoomswitch=1 PositionEntity camera,0,9,-25
If zoomswitch=0 PositionEntity camera,0,9,-15
EndIf

If KeyHit(17)
wireframestate=1-wireframestate ; w
WireFrame wireframestate
EndIf

I assume the other way doesn't cause coil whine or other harm, but I must whine about the time limit on editing posts, sorry! What if I DID post harmful code by accident, you know?

  RemiD commented:

as Rontek explained, your attempt is useless, because each computer has a different hardware (cpu, sram, gpu, vram) (and a different OS) and will therefore process and render at a different speeds. (take less of more millitime)

a better approach is to understand which procedures take a lot of time (and how to optimize them) and how to organize your images, your meshes (surfaces), your effects so that it takes less time to render...

simple example to determine which procedure / step takes a lot of time to render :

;for a procedure / function
updatethingsmillistart% = millisecs()
updatethings()
updatethingsmillitime% = millisecs() - updatethingsmillistart ; in milliseconds

;for render 3d
render3dmillistart% = millisecs()
renderworld()
render3dmillitime% = millisecs() - render3dmillistart ; in milliseconds

;for render 2d
render2dmillistart% = millisecs()
for i% = 1 to count
drawimage( thing_image(i), thing_x(i), thing_y(i) )
render2dmillitime% = millisecs() - render2dmillistart ; in milliseconds

it is possible to render at 60fps, but also at a chosen max fps (30fps for example) on Windows xp or 7 or 8 or 10 or 11, using :

;before the mainloop :
MainTimer = createtimer(30)

;in the mainloop :
Repeat

 ;update things here

 setbuffer( backbuffer() )

 ;render 3d
 Renderworld()

 ;render 2d
 drawimage( image, 0, 0 )
 text( 0, 0, "blahblah" )

   ;Flip(1)
  WaitTimer(MainTimer)
  VWait():Flip(False)

Until( keydown(1)=1 )
fox95871 commented:

I'll try to emulate that, then post the code, thanks. Should I continue this here, or start another thread? Either's fine by me, but this one IS starting to branch off a bit. I want to fully understand Vsinc, Delta timing, Render tweening, and how things should be arranged in the loop, so I can offer the most compatible system possible for the myriad of computer setups.

RemiD commented:

related to 'time based movements / animations' :

(copied my post on syntaxbomb) :
i have made more clear (imo) a bb code example of delta time based movement :

;delta coeff (movements based on time elapsed, whatever the fps)
;2d example

Graphics( 640,480,32,2 )

Global beforemilli%
Global aftermilli%
Global deltacoeff#

Global MainTimer = CreateTimer(30) ;change the max framerate (FPS) (between 10 to 60) and see how the rectangle will still move at the same speed, whatever the framerate (FPS)

Repeat

 ;get the milli time before the mainloop
 beforemilli = MilliSecs()

 ;update tranforms
 x = x + deltacoeff * 100 : If( x > 640 ) :  x = 0 : EndIf ;use the deltacoeff to calculate the movement / new position
 y= 480/2 - 16/2

 ;render
 SetBuffer( BackBuffer() )
 ClsColor(000,000,000) : Cls()

 Color( 120, 120, 120 ) : Rect( x, y, 16, 16, 1 )

 ;debug infos  
 Color( 240, 240, 240 ) : 
 Text( 0, 0, deltacoeff )
 Text( 0, 15, fps )

 ;display the result on the screen
 ;Flip(true)
 WaitTimer(MainTimer)
 VWait():Flip(False)

 ;get the milli time after the mainloop
 aftermilli = MilliSecs()
 ;calculate the deltacoeff ( = elapsed milli time / 1000 )
 deltacoeff#= Float( aftermilli - beforemilli ) / 1000
 ;calculate the fps
 fps% = 1000.0 / Float( aftermilli - beforemilli )

Until( KeyDown(1)=1 )

End()

initially by Rob :
https://archive.blitzcoder.org/forums/code-graphics/140.html

it seems to work well, however from what i understand, Rob made a mistake, the delta value is a coeff corresponding to the elapsed milli time value / 1000, not a milli time value,

BlitzCoder commented:

If you could find out if changing flipstate to 1 prevents that on your computer, I'd appreciate it.

yes, it's the default

I assume the other way doesn't cause coil whine or other harm, What if I DID post harmful code by accident, you know?

Hey no worries. :) with my old setup I really don't get the coil whine, must be grounded speakers causing this or my current hardware in particular.

but I must whine about the time limit on editing posts, sorry!

Post edit expiration are now longer btw.. for replies, a week is more than enough time.

fox95871 commented:

Hmm, I still can't edit my first post, but whatever. Things can never be too perfect for an editor XD

Well, it's beginning to look a lot like Starry night - Harvest moon reference - with this information, I should be able to get at least a pseudo version of my beloved IFPS meter working soon, thanks :)

Sorry this went on so long... persistent, aren't I? But as Otacon said after Solid snake griped about being almost nostalgic for the old key card system, "All you really have to do is reinterpret the old technology in terms of the new."

Thanks again guys, I'll post my results soon.

RemiD commented:

another example of how to use delata coeff, with 3d entities / movement :

;delta coeff (movements based on time elapsed, whatever the fps)
;3d example
Graphics3D( 640,480,32,2 )

Global camera = CreateCamera()
CameraRange( camera, 0.1, 100 )

Global shape = CreateCube() : ScaleMesh( shape, 1.0/2, 1.0/2, 1.0/2 )
PositionEntity( shape, 0, 0, 0, True )

PositionEntity( camera, +5, +2.5, +5, True ) : RotateEntity( camera, +22.5, +90, 0, True )

dlight = CreateLight(1)
LightColor( dlight, 240, 240, 240)
PositionEntity( dlight, 0, 1000, -1000, True )
RotateEntity( dlight, 45, 45, 0, True )

AmbientLight( 120, 120, 120 )

Global beforemilli%
Global aftermilli%
Global deltacoeff#

Global MainTimer = CreateTimer(30) ;change the max framerate (FPS) (between 10 to 60) and see how the cube will still move at the same speed, whatever the framerate (FPS)

Repeat

 ;get the milli time before the mainloop
 beforemilli = MilliSecs()

 ;update tranforms
 MoveEntity( shape, 0, 0, +1.5*deltacoeff ) : If( EntityZ(shape,True) > 10 ) : PositionEntity( shape, 0, 0, 0, True ) : EndIf

 WireFrame(False)
 If( KeyDown(2)=True ) : WireFrame(True) : EndIf

 ;render3d
 SetBuffer( BackBuffer() )
 ClsColor(000,000,000) : Cls()
 RenderWorld()

 ;debug infos  
 Color( 240, 240, 240 )
 Text( 0, 0, deltacoeff )
 Text( 0, 15, fps )

 ;display the result on the screen
 ;Flip(true)
 WaitTimer(MainTimer)
 VWait():Flip(False)

 ;get the milli time after the mainloop
 aftermilli = MilliSecs()
 ;calculate the deltacoeff ( = elapsed milli time / 1000 )
 deltacoeff# = Float( aftermilli - beforemilli ) / 1000
 ;calculate the fps
 fps% = 1000.0 / Float( aftermilli - beforemilli )

Until( KeyDown(1)=1 )

End()
BlitzCoder commented:

seems a bit weird but this bb archived delta timing code works differently, possibly only in Win 10 up:

https://www.blitzcoder.org/forum/topic.php?id=1066

Test video was in Win 7 back then..

@fox
There was a demo snippet that I tested a while back about render tweening stuff, I'd post it once I find it.

RemiD commented:

@Rontek>>
your example also works but since you use a deltatime value (in milliseconds) to make the entities move at the same speed whatever the fps, since this value is high, you have to decrease the speed / movement of the entity.

that's why i prefer to use a 'delta coef' instead of a 'delta time'.

but it is the same logic...

BlitzCoder commented:

your example also works but since you use a deltatime value..

code is a repost from the old bb archive and there's a "reverse jitter" going on between using Win 7 and 10.

here's another one in bmax from ziggy:
https://www.blitzcoder.org/forum/topic.php?id=556

fox95871 commented:

Okay, that's 16 things to try now... thanks, I think? XD

No, I look forward to going through them all eventually, but right now, I'm basing my patch on the one suggestion that wasn't over my head. I'm only a level 99 beginner, afterall.

BlitzCoder commented:

fox, in any case your interesting old question deserves a new thread or a part 2. cheers.

fox95871 commented:

All solved. I even thought of a way to keep it editable...

https://ia600504.us.archive.org/14/items/pseudo-ifps-meter/code.txt
https://ia600504.us.archive.org/14/items/pseudo-ifps-meter/hurling%20frootmig.ogg

The first link goes to a text only webpage with the code. Select all, copy, and paste it to a new bb. The second goes to a media only page. Pause the song, click the vertical ellipsis, click Download, get it from your Downloads folder, then put it wherever you have the bb.

[ edit, the non ascii character "οΏ½" somehow ended up in my code, so you might want to wait 'til it updates, or change it to an "X" if you can find it ]

Reply To Topic (minimum 10 characters)

Please log in to reply