Page 1 of 1
Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 18:31
by quantum
This is what I get if I print the frame number in GameFrame:
Code: Select all
[ 0] Hello from frame 0
[ 2] Hello from frame 2
[ 3] Hello from frame 3
[ 4] Hello from frame 4
[ 5] Hello from frame 5
[ 6] Hello from frame 6
[ 7] Hello from frame 7
[ 8] Hello from frame 8
[ 9] Hello from frame 9
[ 10] Hello from frame 10
...
Frame 1 is skipped. Other mods I've tested don't have this issue (The Cursed, S44, ZK).
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 18:40
by SirMaverick
They can have this issue if there is a gadget that gets removed. I think that might be the reason here, too.
See
http://springrts.com/mantis/view.php?id=1907
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:03
by trepan
The problem has been known for a while. It's not only a
problem with the lua event handling, it's also present in
the C++ EventHandler.
For BZFlag, I rewrote both the C++ and lua event
handling to use lists instead of arrays. List iterators
are unaffected by insertions and deletions of other
iterators. The lua event list code is actually faster than
the code that SpringRTS is currently using (the lua list
implementation is surprising fast compared to array
iteration, and the BZFlag lua event handling code doesn't
have to do named function lookups).
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:14
by jK
trepan wrote:the BZFlag lua event handling code doesn't
have to do named function lookups
How?
I thought Lua doesn't support `pointers` to lua_objects (note even a LUA_REGISTRYINDEX is a table lookup).
PS: I am working on the gadget-/widget handlers atm,
so the lua side will get fixed soon enough.
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:19
by trepan
jK wrote:trepan wrote:the BZFlag lua event handling code doesn't
have to do named function lookups
Instead of doing a widget["func_name"] lookup for each
function call, the functions are registered into the ordered
event lists.
simplified iteration example:
Code: Select all
local node = eventlist.start
while (node) do
node.func(...)
node = node.next
end
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:22
by trepan
As you can see from the last commit date,
this hasn't been touched in a while. As a
matter of fact, almost all BZFlag development
has ceased 8^)
EventClientList.h
http://bzflag.svn.sourceforge.net/viewv ... iew=markup
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:23
by jK
trepan wrote:jK wrote:trepan wrote:the BZFlag lua event handling code doesn't
have to do named function lookups
Instead of doing a widget["func_name"] lookup for each
function call, the functions are registered into the ordered
event lists.
simplified iteration example:
Code: Select all
local node = eventlist.start
while (node) do
node.func(...)
node = node.next
end
ah,
I thought you were still talking about the engine eventhandler.
Re: Bug report: gadget handler skips frames
Posted: 13 Nov 2010, 20:32
by trepan
One thing to note about the EventClientList.h example
is the "purify()" function (if anyone wants to take a shot
at fixing the C++ code). The reason for purify() is to
avoid problems when an EventClient is removed while
the list iterator pointing to it is active (being used to run
code).
One trick to solving this problem is shown in the following
header file (look for the CallbackList<F>::doIterate() method):
http://bzflag.svn.sourceforge.net/viewv ... iew=markup
That's seemed clunky to me, so instead I setup a dummy
EventClient instance, and replaced the EventClient pointer
in the list with the dummy instance (which has member
functions that don't do anything). A 'purify' flag is set on any
EventClientList with a removal, and you just have to clean
out the dummy instance pointers every once in a while.
Re: Bug report: gadget handler skips frames
Posted: 14 Nov 2010, 07:20
by zwzsg
quantum wrote:Bug report: gadget handler skips frames
Frame 1 is skipped.
I encountered this problem as well. lurker wrote me a gadget handler patch to fix this. See my "hotfixes.lua" gadget (in KP for instance). Eh, I actually even have released a BA version with this fix:
http://springrts.com/phpbb/viewtopic.php?f=44&t=24034