Hello Haliop_New. thanks, but help no help to much...,I can assure you that I have read the help more than 20 times, of all the commands on the subject.
I am not an expert in the subject "CORE", I am testing, by force of trial and error, to find that my code works to have a constant speed of logic, and to regulate the renders of the game.
this function, it worked well for me in B3d, I am sure that if I understood better about CORE, buffers, and others, this would be easier for me.
I share a code, which I used in Blitz3D to make my games run fast on slow computers.
Not having limits in the main-loop, it was also very useful to measure the performance of the resources and handle the optimization of the game more efficiently.
Basically, what my program would do is.
Calculate logic at a constant frequency per second
Render whenever you can, without luring logic
and that the fps of the main loop have no limits.
this code works perfect, if someone know how to put correctly in place and orders this commands:
draw
render
swap
ender2dback
render
2dfront
cleardepthbuffer
update 2d
update3d
u hope don't forget any command...
// Project: constants FPS
// Created: 2020-06-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "constants FPS" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
// generate a simple way to load light or heavy scene, add more cubes to push the core
for i = 1 to 1000
cubo = createobjectbox(1,1,1)
setobjectcolor (cubo,random(1,254),random(2,244),random(3,200),random(100,255))
SetObjectTransparency(cubo,1)
a=100
SetObjectPosition(cubo,random2(-a,a),random2(-a,a),random2(-a,a))
next i
// SISTEMA DE FPS LOGICOS Y DE RENDER
Global fps_logica = 60 //;cantidad de veces que se debe repertir la logica por segundo / how many logic frame i wan per second
Global fps_render = 30 // ;cantidad de veces que quisieramos que se renderee. / how many render frame i wan per second
Global fps_start = 0 //;cuando se inicio el loop / loop millisec start
Global fps_frame //;el numero de frames que llevamos en este segundo / count frames
Global fps_last //;millisec en el que se inicio el ultimo fps / last millisec frame
Global fps = 0 //;cantidad de veces que se repitio el loop principal / frame per second main loop
Global fps_logicos = 0 //;cantidad de veces que se repitio la logica en 1 segundo / logic frames per second count
Global fps_renders = 0 //;cantidad de veces que se rendereo en un segundo / render frames per second count
Global fps_do_render //;indica si hay que renderear / i must render?
Global fps_do_logic //;indica si hay que procesar logica / i must do the logic?
Global fps_frame_render //;cantidad de veces que se rendereo en el ultimo segundo / count how many renders in last second
Global fps_frame_logica //;cantidad de veces que se calculo la logica en el ultimo segundo / count how many logic have in the las second
Global fps_last_millisec_logic //;ultimo milisegundo en el que se calculo la logica / when was the last logic millisecs
Global fps_last_millisec_render //;ultimo milisegundo en el que se calculo el RENDER / when was the last render millisect
Global fps_last_render_delay = 0 // ; / count how many millisecs take to render
Global fps_last_logic_delay = 0 //; / count how many millisecs take to do the logic
Global fps_step_render_per_frame //;cantidad de frames que tienen que esperar para renderear / how many steps logic to do the render
Global fps_frame_steped //;veces que llevo haciendo la logica sin renderear
print ("this render image was make in the first and only one sync of this code")
sync()
SetPrintSize(23)
do
update_fps()
If fps_do_logic = 1 Then logica() // < logic of the game 60 times per second
If fps_do_render = 1 Then render_my_game() // < render when you can't but no delay the logic please.
update2d(0) // THIS MUST BE LIKE UPDATEWORLD() IN BLITZ3d update update update update update update update update update update
update3d(0) // update update update update update update update update update update update update update update update
//render2dback()
//ClearDepthBuffer()
//render3d()
//ClearDepthBuffer()
//Render2DFront()
//swap()
loop
Function logica() // LOGIC
Local time as integer
time = GetMilliseconds()
fps_frame_logica = fps_frame_logica + 1
fps_last_millisec_logic = GetMilliseconds()
fps_do_logic = 0
fps_frame_steped = fps_frame_steped + 1
x# = sin(GetMilliseconds()*.05)*50
y# = cos((30+GetMilliseconds()*.02))*20
z# = cos((-30+GetMilliseconds()*.01))*10
SetCameraPosition(1,x#,y#,z#)
SetCameraLookAt(1,x#,y#,z#,0)
UPDATE_GAME() // HERE I JUST UPDATE THE LOGIC OF THE GAME
//count how much millisecs i use to do this function
fps_last_logic_delay = GetMilliseconds() - time
EndFunction
Function render_my_game() // ; R e n d e r
Local time as integer
time = GetMilliseconds()
fps_frame_render = fps_frame_render + 1
fps_last_millisec_render = GetMilliseconds()
fps_do_render = 0
fps_frame_steped = 0
Print( "FPS LOOP : " + str(ScreenFPS()) + " << this value must be very very high!! depending of speed of computer" ) /// can be very high. usefull to know about resources optimization
Print( "RENDER FPS : " + str(fps_renders) + " << this value depends on 3d load and yout graphic card and computer " ) // render fps depending on the time
Print( "LOGIC FPS : " + str(fps_logicos) + " << this must be constant setting " + str(fps_logica)) // update logic allways must be in 60 times per second
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
// RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D RENDER 3D
//render() //????????
/// i don't know where put this comandsSS!!!! hellppppppp!!!!!!
render2dback()
ClearDepthBuffer()
render3d()
ClearDepthBuffer()
Render2DFront()
swap()
fps_last_render_delay = GetMilliseconds() - time
EndFunction
Function update_fps()
Local render_step_time
Local logic_step_time
Local render_millisec_step_recomended as integer
render_millisec_step_recomended = 1000/60 //veces maxima que se deberia renderear por segundo.
If fps_start = 0
fps_start = GetMilliseconds()
EndIf
If GetMilliseconds() > fps_start + 1000
fps_renders = fps_frame_render
fps_frame_render = 0
fps_logicos = fps_frame_logica
fps_frame_logica = 0
fps_start = GetMilliseconds()
fps = fps_frame
fps_frame = 0
EndIf
fps_frame = fps_frame + 1
logic_step_time = 1000 / fps_logica
If fps_last_millisec_logic + logic_step_time < GetMilliseconds()
fps_do_logic = 1
Else
fps_do_logic = 0
EndIf
fps_step_render_per_frame = 5
//;here i have the problem!!! in this conditions!
fps_step_render_per_frame = 1+(((fps_last_render_delay * 60)/1000))*2
If fps_step_render_per_frame < 1 Then fps_step_render_per_frame = 1
If fps_logicos < fps_logica Then fps_step_render_per_frame = fps_step_render_per_frame
//;this work but dont know how to do it
//;fps_step_render_per_frame = 3
If fps_logicos < fps_logica Then fps_step_render_per_frame = fps_step_render_per_frame + fps_logica-fps_logicos-1
If fps_frame_steped => fps_step_render_per_frame And fps_logicos <= fps_logica
fps_do_render = 1
Else
fps_do_render = 0
EndIf
EndFunction
FUNCTION UPDATE_GAME()
//MOVE CARS
//MOVE EVERTITHING
ENDFUNCTION