Skip to content

Commit 7c134f3

Browse files
committed
clear tempory lindas that helps, but lindas can still block for 10-20 ms which is no good so really needs replacing
1 parent 24340a5 commit 7c134f3

File tree

7 files changed

+96
-16
lines changed

7 files changed

+96
-16
lines changed

lua/wetgenes/gamecake/mods/console.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ font.vbs_idx=1
325325
console.lines_display[1]=s
326326
-- console.display(s)
327327

328+
if oven.times.update.time+oven.times.draw.time > 0.030 then -- slow frame
329+
330+
PRINT("SLOW",s)--, oven.now.now.scene:status())
331+
end
332+
328333
console.fps_count=console.fps_count+1
329334
end
330335

lua/wetgenes/gamecake/oven.lua

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ local coroutine,package,string,table,math,io,os,debug,assert,dofile,error,_G,get
66
--local log,dump,PRINT=require("wetgenes.logs"):export("log","dump","PRINT")
77
local logs=require("wetgenes.logs")
88
local global=require("global")
9+
910
local toaster=require("wetgenes.gamecake.toaster")
1011
-- help luajit work on android/arm
1112
toaster.jit_prealloc()
12-
13+
local profile=require("jit.profile")
1314

1415
--[[#lua.wetgenes.gamecake.oven
1516
@@ -666,7 +667,6 @@ os.exit()
666667

667668
function oven.setup()
668669
if oven.now and oven.now.setup then
669-
toaster.garbage_collect_restart() -- in case of large allocations
670670
oven.now.setup() -- this will probably load data and call the preloader
671671
end
672672
--print("setup preloader=off")
@@ -718,6 +718,16 @@ os.exit()
718718
function oven.update()
719719
--print(oven.ticks)
720720

721+
local prof={TOTAL=0}
722+
if false then
723+
local ms=5
724+
profile.start("fi"..ms,function(thread, samples, vmstate)
725+
prof.TOTAL=prof.TOTAL+samples*ms
726+
local s=profile.dumpstack(thread, "l", 1)
727+
prof[s]=(prof[s] or 0 ) +samples*ms
728+
end)
729+
end
730+
721731
if oven.do_backtrace then
722732
oven.do_backtrace=false
723733
if oven.update_co then
@@ -787,6 +797,25 @@ os.exit()
787797
end
788798
oven.update_co=nil
789799

800+
if false then
801+
profile.stop()
802+
if prof.TOTAL >= 10 then
803+
local list={}
804+
for n,v in pairs(prof) do
805+
list[#list+1]=string.format("%4i",v).." : "..n
806+
end
807+
table.sort(list)
808+
local c=0
809+
for i=#list,1,-1 do
810+
PRINT(list[i])
811+
c=c+1
812+
if c>=5 then break end
813+
end
814+
PRINT("")
815+
end
816+
-- DUMP(oven.tasks.linda:dump())
817+
end
818+
790819
end
791820

792821
oven.preloader_enabled=false -- do we need this? we is fast and it is broken

lua/wetgenes/gamecake/toaster.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ local M={ modname=(...) } ; package.loaded[M.modname]=M
5353
-- this will stop gc and take control of it
5454
M.garbage_collect_step=function()
5555
collectgarbage("stop") -- from now on we must explicitly call step as often as we can
56-
collectgarbage("setpause",400) -- this number adjusts when collection will start ( still seems to effect us here )
57-
collectgarbage("setstepmul",1) -- this number adjusts how much time that each step should take
56+
collectgarbage("setpause",500) -- this number adjusts when collection will start ( still seems to effect us here )
57+
collectgarbage("setstepmul",10) -- this number adjusts how much time that each step should take
5858
collectgarbage("step",0) -- this function may do nothing or may collect some garbage
5959
end
6060

lua/wetgenes/gamecake/upnet.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,9 @@ M.upnet_code=function(linda,task_id,task_idx)
835835
local lanes=require("lanes")
836836
if lane_threadname then lane_threadname(task_id) end
837837

838+
local toaster=require("wetgenes.gamecake.toaster")
839+
toaster.jit_prealloc() -- help luajit work on android/arm
840+
838841
local wtasks=require("wetgenes.tasks")
839842
local wwin=require("wetgenes.win")
840843
local now=wwin.time -- function to get time now in seconds with ms accuracy, probs
@@ -921,6 +924,7 @@ M.upnet_code=function(linda,task_id,task_idx)
921924
end
922925
end
923926
until not memo
927+
toaster.garbage_collect_step() -- try and avoid gc glitching
924928
end
925929

926930
end

lua/wetgenes/gamecake/zone/system/all_code.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ all.code.db=function(linda,task_id,task_idx)
112112
local lanes=require("lanes")
113113
if lane_threadname then lane_threadname(task_id) end
114114

115-
local oven=require("wetgenes.gamecake.toaster").bake({linda=linda})
115+
local toaster=require("wetgenes.gamecake.toaster")
116+
toaster.jit_prealloc() -- help luajit work on android/arm
117+
local oven=toaster.bake({linda=linda})
116118

117119
local db=all.db.open({linda=linda,time=oven.time})
118120

@@ -163,7 +165,10 @@ all.code.popins=function(linda,task_id,task_idx)
163165
local lanes=require("lanes")
164166
if lane_threadname then lane_threadname(task_id) end
165167

166-
local oven=require("wetgenes.gamecake.toaster").bake({linda=linda})
168+
local toaster=require("wetgenes.gamecake.toaster")
169+
toaster.jit_prealloc() -- help luajit work on android/arm
170+
local oven=toaster.bake({linda=linda})
171+
167172
oven.upnet=oven.rebake("wetgenes.gamecake.upnet")
168173

169174
local scene
@@ -231,8 +236,10 @@ all.code.values=function(linda,task_id,task_idx)
231236
local lanes=require("lanes")
232237
if lane_threadname then lane_threadname(task_id) end
233238

234-
-- basic oven, nogl etc
235-
local oven=require("wetgenes.gamecake.toaster").bake({linda=linda})
239+
local toaster=require("wetgenes.gamecake.toaster")
240+
toaster.jit_prealloc() -- help luajit work on android/arm
241+
local oven=toaster.bake({linda=linda})
242+
236243
oven.upnet=oven.rebake("wetgenes.gamecake.upnet")
237244

238245
local scene
@@ -312,6 +319,7 @@ all.code.values=function(linda,task_id,task_idx)
312319
end
313320
main() -- probably getting called every 1ms ish
314321
until not memo
322+
toaster.garbage_collect_step() -- try and avoid gc glitching
315323
end
316324

317325
end
@@ -326,8 +334,10 @@ all.code.tweens=function(linda,task_id,task_idx)
326334
local lanes=require("lanes")
327335
if lane_threadname then lane_threadname(task_id) end
328336

329-
-- basic oven, nogl etc
330-
local oven=require("wetgenes.gamecake.toaster").bake({linda=linda})
337+
local toaster=require("wetgenes.gamecake.toaster")
338+
toaster.jit_prealloc() -- help luajit work on android/arm
339+
local oven=toaster.bake({linda=linda})
340+
331341
oven.upnet=oven.rebake("wetgenes.gamecake.upnet")
332342

333343
local scene
@@ -438,6 +448,7 @@ all.code.tweens=function(linda,task_id,task_idx)
438448
end
439449
main() -- probably getting called every 1ms ish
440450
until not memo
451+
toaster.garbage_collect_step() -- try and avoid gc glitching
441452
end
442453

443454
end

lua/wetgenes/gamecake/zone/system/all_scene.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ all.scene.initialize=function(scene)
117117
}
118118
scene:sortby_update()
119119

120+
scene.scrib={}
120121
scene.db=db
121122
for caste,info in pairs(scene.infos) do -- initialize each system from info
122123
local sys={}
@@ -351,21 +352,34 @@ counts.draw=0
351352

352353
-- counts.undo , counts.update = scene:do_update_values()
353354

355+
if not scene.scrib.tim then
356+
scene.scrib.tim=oven.times.create()
357+
end
358+
scene.scrib.tim.start()
359+
360+
scene.scrib.tween=0
361+
scene.scrib.pull=0
362+
scene.scrib.merge=0
354363
for memo in oven.tasks:memos("all_draws") do
355364
if memo.cmd=="tweens" then
356365
scene:values_call( function(it) it.tweens:push() end )
357366
scene:load_all_tweens(memo.tweens)
367+
scene.scrib.tween=scene.scrib.tween+1
358368
end
359369
end
360370
scene:ticks_sync()
361371
-- shrink tweens down to two slots so we may tween between them
362372
while #scene.tweens > 2 and scene.tweens:get("tick",2) <= scene.ticks.now do
363373
scene:values_call( function(it) it.tweens:pull() end ) -- merge 2 into 1
374+
scene.scrib.pull=scene.scrib.pull+1
364375
end
365376
while #scene.tweens > 2 do
366377
scene:values_call( function(it) it.tweens:merge() end ) -- merge 3 into 2
378+
scene.scrib.merge=scene.scrib.merge+1
367379
end
368380

381+
scene.scrib.tim.stop()
382+
369383
--if #scene.tweens==2 then
370384
--print( scene.tweens:get("tick",1) , scene.tweens:get("tick",2) , scene.ticks.time )
371385
--end
@@ -386,8 +400,17 @@ all.scene.do_draw=function(scene)
386400

387401
scene:ticks_sync()
388402

403+
scene.scrib.tim.done()
404+
--[[
405+
if scene.scrib.tim.time > 0.01 then
406+
PRINT("TIM",math.floor(scene.scrib.tim.time*1000))
407+
end
408+
]]
409+
389410
-- local upnet=scene.oven.upnet
390-
oven.console.lines_display[2]=("now:"..scene.ticks.now.." inp:"..scene.ticks.input.." agr:"..scene.ticks.agreed.." bse:"..scene.ticks.base)
411+
oven.console.lines_display[2]=(
412+
-- "tween:"..scene.scrib.tween.." pull:"..scene.scrib.pull.." merge:"..scene.scrib.merge.." "..
413+
"now:"..scene.ticks.now.." inp:"..scene.ticks.input.." agr:"..scene.ticks.agreed.." bse:"..scene.ticks.base)
391414

392415
-- local nowtick=upnet.nowticks()
393416
-- print("do_draw",scene.ticks.time)

lua/wetgenes/tasks.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ M.do_memo=function(linda,memo,timeout)
6666
if linda:send( timeout , memo.task , memo ) then -- send on memo.task (a public name of another task)
6767
if memo.id then
6868
local ok,r=linda:receive( timeout , memo.id ) -- receive the result on memo.id
69+
linda:set(memo.id) -- cleanup
6970
--log("memo",memo.task,memo.id,"done")
7071
return r
7172
end
@@ -204,6 +205,7 @@ M.tasks_functions.claim_global=function(tasks,name,value)
204205
memo.value=value
205206
if tasks.linda:send( nil , memo.task , memo ) then -- send on memo.task (a public name of another task)
206207
local ok,r=tasks.linda:receive( nil , memo.id ) -- receive the result on memo.id
208+
tasks.linda:set(memo.id) -- cleanup
207209
return r.result
208210
end
209211
end
@@ -228,6 +230,7 @@ M.tasks_functions.eject_global=function(tasks,name)
228230
memo.name=name
229231
if tasks.linda:send( nil , memo.task , memo ) then -- send on memo.task (a public name of another task)
230232
local ok,r=tasks.linda:receive( nil , memo.id ) -- receive the result on memo.id
233+
tasks.linda:set(memo.id) -- cleanup
231234
return r.result
232235
end
233236
end
@@ -250,6 +253,7 @@ M.tasks_functions.fetch_global=function(tasks,name)
250253
memo.name=name
251254
if tasks.linda:send( nil , memo.task , memo ) then -- send on memo.task (a public name of another task)
252255
local ok,r=tasks.linda:receive( nil , memo.id ) -- receive the result on memo.id
256+
tasks.linda:set(memo.id) -- cleanup
253257
return r.result
254258
end
255259
end
@@ -571,7 +575,8 @@ M.tasks_functions.receive=function(tasks,memo,timeout)
571575
tasks:send(memo,timeout)
572576
end
573577
memo.state="receiving"
574-
local ok,result=(tasks.main_thread and tasks.colinda or tasks.linda):receive( timeout , memo.id )
578+
local ok,result=(tasks.main_thread and tasks.colinda or tasks.linda):receive( timeout , memo.id ) ;
579+
(tasks.main_thread and tasks.colinda or tasks.linda):set(memo.id) -- cleanup
575580
memo.state="done"
576581
tasks:del_memo(memo)
577582

@@ -712,11 +717,14 @@ M.colinda_functions.send=function(colinda,...)
712717
local timestart
713718
if timeout then timestart=os.time() end
714719

720+
--PRINT(timeout)
721+
--TRACEBACK()
722+
715723
local ret
716724
repeat
717-
ret={ colinda.linda:send(0,unpack(aa)) }
725+
ret={ colinda.linda:send(1,unpack(aa)) }
718726
if ret[1] then break end -- got a result
719-
if timeout and os.time() > timestart+timeout then break end
727+
if timeout and os.time() >= timestart+timeout then break end
720728
coroutine.yield()
721729
until false
722730

@@ -734,9 +742,9 @@ M.colinda_functions.receive=function(colinda,...)
734742

735743
local ret
736744
repeat
737-
ret={ colinda.linda:receive(0,unpack(aa)) }
745+
ret={ colinda.linda:receive(1,unpack(aa)) }
738746
if ret[1] then break end -- got a result
739-
if timeout and os.time() > timestart+timeout then break end
747+
if timeout and os.time() >= timestart+timeout then break end
740748
coroutine.yield()
741749
until false
742750

0 commit comments

Comments
 (0)