Hook framework (a.k.a LoG Framework 2)
Posted: Thu Nov 13, 2014 7:53 pm
So I decided to implement the dynamic hook features of LoG Framework for LoG2. It has a few differences for the LoG Framework. The biggest difference is that it doesn't add framework hooks automatically to components, you have to add them manually. See documentation: https://sites.google.com/site/jkoslog2/home
This means that you have to do a bit more manual work than in LoG Framework, but it's much better solution performance vice.
Docs are pretty simple, so ask here if you don't understand something. Hope you find it useful.
Short description of features:
- dynamic hook support (can add and remove hooks in runtime)
- multiple hook support of same type (for example multiple party.onMove-hooks)
- set hooks to individual entity (a bit like connectors)
- passing variables to hooks
PS.
I have tested the performance and it executes 300 different hook calls in 1ms when there was 900 defined hooks total , so don't worry about that.
Here is the code I used for testing if you wan't to verify it.
This means that you have to do a bit more manual work than in LoG Framework, but it's much better solution performance vice.
Docs are pretty simple, so ask here if you don't understand something. Hope you find it useful.
Short description of features:
- dynamic hook support (can add and remove hooks in runtime)
- multiple hook support of same type (for example multiple party.onMove-hooks)
- set hooks to individual entity (a bit like connectors)
- passing variables to hooks
PS.
I have tested the performance and it executes 300 different hook calls in 1ms when there was 900 defined hooks total , so don't worry about that.
Here is the code I used for testing if you wan't to verify it.
SpoilerShow
Code: Select all
perfTest = {
startTime = 0
}
function performanceTest()
-- add 300 hooks for different targets
for i = 1,300 do
fw.script:set('tmp'..i..'.perftest'..i..'.onMove',function(hook) end)
end
fw.script:set('party.perftest0.onMove',function()
fw.script.perfTest.startTime = Time.systemTime()
end)
for i = 1,300 do
fw.script:set('tmp2'..i..'.perftest'..i..'.onTurn',function(hook) end) -- add dummy hooks
fw.script:set('party.perftest'..i..'.onMove',function(hook)
print('hook',hook.count)
end).count = i
end
fw.script:set('party.perftest21.onMove',function()
print('Executed 302 party.onMove-hooks in: '..Time.systemTime() - fw.script.perfTest.startTime..' seconds')
end)
end