Page 1 of 5

Hook framework (a.k.a LoG Framework 2)

Posted: Thu Nov 13, 2014 7:53 pm
by JKos
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.
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

Re: Hooker framework (a.k.a LoG Framework 2)

Posted: Thu Nov 13, 2014 8:27 pm
by Doridion
IN-CRE-DI-BLE ! Again an awesome work JKos ^^

Stick on the superthread !

Re: Hooker framework (a.k.a LoG Framework 2)

Posted: Thu Nov 13, 2014 9:29 pm
by minmay
Excellent work, although I'm a little hesitant to put that name in my credits.

Re: Hooker framework (a.k.a LoG Framework 2)

Posted: Thu Nov 13, 2014 9:49 pm
by JKos
minmay wrote:Excellent work, although I'm a little hesitant to put that name in my credits.
Haha, well I can still change the name if someone has a better suggestion. I think that the current one is pretty describing :mrgreen:

Edit: I changed it to a Hook framework, it was a bad joke anyway.

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Thu Nov 13, 2014 11:47 pm
by Doridion
Bah, LoG Framework is the better name you can give, and same as the first version in LoG1 ^^

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Fri Nov 14, 2014 12:31 am
by Teto
Sorry about my dumbness, what is a hook ? (it's not clear in the documentation, or I missed something) :oops:

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Fri Nov 14, 2014 10:16 am
by JKos
Teto wrote:Sorry about my dumbness, what is a hook ? (it's not clear in the documentation, or I missed something) :oops:
They are like event handlers. See LoG 1 documentation:
http://www.grimrock.net/modding_log1/scripting-hooks/

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Fri Nov 14, 2014 10:58 am
by Aisuu
Great work JKos :)

But I have trouble installing your script. I follow your instructions exactly.
But when I reload my mod it crash with error. I cant post error right now, Iam in work, but I remember it was something about script starting with hooks={} debug = false etc.. Error complain about commas, I think.

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Fri Nov 14, 2014 11:41 am
by JKos
Thanks for the info, I didn't test my own install instructions :roll: , I'll check this out and fix it if there is some problem.

Re: Hook framework (a.k.a LoG Framework 2)

Posted: Fri Nov 14, 2014 12:00 pm
by JKos
Installation instructions worked fine for me, but I changed it so that you don't have to copy paste anything (makes it less error prone).

https://sites.google.com/site/jkoslog2/install