AppTitle "Separar la logica de los renders. "Global gancho = 1000Global galto = 800Global gbits = 0Global gmode = 2;the idea is to have 60 logic frames per second;and render only each X logic frame if i have my 60 logic frames per second;I don't won render more than 60 times per second, becouse if i don't change the logic, the render will be the same ;! Sorry my english and spansh useGraphics3D gancho,galto,gbits,gmodeGlobal cam = CreateCamera()MoveEntity cam,0,20,-80TurnEntity cam,20,0,0Global light = CreateLight(1)MoveEntity light,-50,-50,-50Global fps_logica = 60 ;cantidad de veces que se debe repertir la logica por segundo / how many logic frame i wan per secondGlobal fps_render = 60 ;cantidad de veces que quisieramos que se renderee. / how many render frame i wan per secondGlobal fps_start = 0 ;cuando se inicio el loop / loop millisec startGlobal fps_frame ;el numero de frames que llevamos en este segundo / count framesGlobal fps_last ;millisec en el que se inicio el ultimo fps / last millisec frameGlobal fps = 0 ;cantidad de veces que se repitio el loop principal / frame per second main loopGlobal fps_logicos = 0 ;cantidad de veces que se repitio la logica en 1 segundo / logic frames per second countGlobal fps_renders = 0 ;cantidad de veces que se rendereo en un segundo / render frames per second countGlobal 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 secondGlobal fps_frame_logica ;cantidad de veces que se calculo la logica en el ultimo segundo / count how many logic have in the las secondGlobal fps_last_millisec_logic ;ultimo milisegundo en el que se calculo la logica / when was the last logic millisecsGlobal 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 renderGlobal fps_last_logic_delay = 0 ; / count how many millisecs take to do the logicGlobal fps_step_render_per_frame ;cantidad de frames que tienen que esperar para renderear / how many steps logic to do the renderGlobal fps_frame_steped ;veces que llevo haciendo la logica sin renderear / how many times i make logic witouth renderType objecto ;objets to render something Field entidad End Type; higher more slow :)Global cube_count = 10000For i = 1 To cube_count a=100 b=30 o.Objecto = New objecto o\entidad = CreateCube() PositionEntity o\entidad,Rnd(-a,a),Rnd(-b,b),Rnd(-a,a) RotateEntity o\entidad,Rnd(360),Rnd(360),Rnd(360)NextWhile Not KeyHit(1) update_fps() If fps_do_logic = 1 Then logica() If fps_do_render = 1 Then render() If KeyHit(57) Then For o.objecto = Each objecto FreeEntity o\entidad Delete o Next cube_count = Rnd(100,10000) For i = 1 To cube_count a=100 b=30 o.Objecto = New objecto o\entidad = CreateCube() PositionEntity o\entidad,Rnd(-a,a),Rnd(-b,b),Rnd(-a,a) RotateEntity o\entidad,Rnd(360),Rnd(360),Rnd(360) Next End If WendEndFunction logica() Local time = MilliSecs() fps_frame_logica = fps_frame_logica + 1 fps_last_millisec_logic = MilliSecs() fps_do_logic = 0 fps_frame_steped = fps_frame_steped + 1 ;game logic For o.Objecto = Each objecto TurnEntity o\entidad ,1,Sin(MilliSecs()*.1),1 EntityAlpha o\entidad,1 EntityColor o\entidad,128 + Sin(o\entidad + MilliSecs()*.1)*100,128 + Cos(o\entidad + MilliSecs()*.1)*100,128 + Tan((MilliSecs())*.1)*100 Next CameraClsColor cam, 58 + Sin(MilliSecs()*.01)*10,28 + Cos(MilliSecs()*.1)*10,0 ;count how much millisecs i use to do this function fps_last_logic_delay = MilliSecs() - time End FunctionFunction render() Local time = MilliSecs() fps_frame_render = fps_frame_render + 1 fps_last_millisec_render = MilliSecs() fps_do_render = 0 fps_frame_steped = 0 RenderWorld Color 10,10,10 Rect 0,0,500,120,1 Color 0,255,0 Text 10,10,"Loop fps : " + fps Color 255,255,0 Text 10,25, "Logic fps : " + fps_logicos ;Text 200,25, " > " + fps_last_logic_delay + " ms" Color 255,100,0 Text 10,40, "Render fps : " + fps_renders ;Text 200,40, " > " + fps_last_render_delay + " ms" Color 255,255,255 Text 10,55,"fps_step_render_per_frame " + fps_step_render_per_frame Text 10,70,"press SPACE to change the count of cubes " + cube_count Flip 0 fps_last_render_delay = MilliSecs() - time End FunctionFunction update_fps() Local render_step_time Local logic_step_time Local render_millisec_step_recomended = 1000/60 ;veces maxima que se deberia renderear por segundo. If fps_start = 0 Then fps_start = MilliSecs() End If If MilliSecs() > fps_start + 1000 Then fps_renders = fps_frame_render fps_frame_render = 0 fps_logicos = fps_frame_logica fps_frame_logica = 0 fps_start = MilliSecs() fps = fps_frame fps_frame = 0 End If fps_frame = fps_frame + 1 ; debo calcular logica en este frame? ; Do logic? logic_step_time = 1000 / fps_logica If fps_last_millisec_logic + logic_step_time < MilliSecs() Then fps_do_logic = 1 Else fps_do_logic = 0 End If ; Debo calcular render? ; Render?? fps_step_render_per_frame = 5 ;here i have the problem!!! in this conditions! fps_step_render_per_frame = 1+Int(Float((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 Then fps_do_render = 1 Else fps_do_render = 0 End If End Function
that the code has to be as realistic as life. and make the game as false as a television studio, that if there is a unit 100km away, don't worry about how your physics will respond, because simply NO ONE SEES IT!
function update_gui_image()SetBuffer ImageBuffer(gui_image) Cls Color 0,0,0 Rect 0,0,gancho,galto,1 Color 0,255,0 Text 10,10,"Loop fps : " + fps Color 0,155,0 Text 10,25, "Logic fps : " + fps_logicos Text 200,25, " > time : " + fps_last_logic_delay + " ms" Color 155,100,0 Text 10,40, "Render fps : " + fps_renders Text 200,40, " > time : " + fps_last_render_delay + " ms" Color 55,100,155 Text 10,55,"Gui_update/s " + fps_gui_update_per_sec + " / " + fps_gui_pudates_this_sec Color 255,255,255 Text 10,100,"Millisecs : " + MilliSecs()SetBuffer BackBuffer()
i don't know what happens when using fastext, but with Blitz3d, when your use renderworld (to render the 3D scene), the render is an image.