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

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

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

Post 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
Last edited by JKos on Thu Nov 13, 2014 10:25 pm, edited 1 time in total.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

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

Post by Doridion »

IN-CRE-DI-BLE ! Again an awesome work JKos ^^

Stick on the superthread !
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

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

Post by minmay »

Excellent work, although I'm a little hesitant to put that name in my credits.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

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

Post 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.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

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

Post by Doridion »

Bah, LoG Framework is the better name you can give, and same as the first version in LoG1 ^^
Teto
Posts: 7
Joined: Sat Apr 28, 2012 11:51 am

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

Post by Teto »

Sorry about my dumbness, what is a hook ? (it's not clear in the documentation, or I missed something) :oops:
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

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

Post 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/
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

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

Post 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.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

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

Post 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.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

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

Post 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
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
Post Reply