Anonymous Login
2020-09-25 04:12 UTC

View Revisions: Issue #1384

Summary 0001384: Make cross-check script-accessible
Revision 2015-09-05 22:03 by Sven2
Description The engine cross-check was once used for object collection, object tumbling, incineration and fight-check (for CR-style clonk2clonk melee fights). These days, most of them have been replaced by FindObjects happening in one of the interaction objects.

This is actually a very inefficient method because it runs though the script engine, has to construct the whole FindObject-context, etc. It's OK for many cases, but when you get to many objects (like Mosquitos stinging clonks), there's always trade-off of performance vs accuracy when you need to decide how often to repeat the check.

I propose to replace the current CrossCheck method by one for which you can register properties to be added to the check. E.g. for a monster, on definition initialization:

AddCrossCheck("Monster", "Prey", "OnHitPrey")

The engine would do this:
1. Reserve a bit for the "Monster" and the "Prey" properties.
2. Set these bit for all objects that have the properties set
3. Add a listener to the object property change function to update the bits when the respective properties change
4. Run the cross check using the bit mask check
5. If it finds a hit, do the callback function on the first object

That method would be resitrcted to e.g. 32 bits at first, but can easily be extended to a bitset or multiple 32 bit masks if we run out of bits for cross checks.

Multiple calls to AddCrossCheck could just update/ignore the call, so you can do it in Initialize of the monster.

Objects can use two bitmasks: One for its own collision bits (first property in AddCrossCheck) and one for its target collision bits (I.e. link second property in AddCrossCheck to first and set all these bits). Then the cross check becomes even simpler because it only needs to do one bit mask comparison (if (obj->bit1 & obj2->bit) ...). It would also mean only one bit is required to be registered per cross-check (i.e.: Only the first bit). The second property can be looked up when a collision has actually happened.

We could also remove OCF and replace it with these custom bits. In fact the features could be separated and work like this:

static OCF_Prey = RegisterOCF("Prey");
static OCF_Monster = RegisterOCF("Monster");
RegisterCrossCheck(OCF_Monster, OCF_Prey, "OnHitPrey");

It could even be made downwards compatible with some of old OCFs like OCF_Alive, and also work in FindObject(Find_OCF(...)).

Of course, instead of bit masks, we can also just use properties and check them on every collision. That would be slightly less efficient but easier to implement.
Revision 2015-09-05 21:58 by Sven2
Description The engine cross-check was once used for object collection, object tumbling, incineration and fight-check (for CR-style clonk2clonk melee fights). These days, most of them have been replaced by FindObjects happening in one of the interaction objects.

This is actually a very inefficient method because it runs though the script engine, has to construct the whole FindObject-context, etc.

I propose to replace the current CrossCheck method by one for which you can register properties to be added to the check. E.g. for a monster, on definition initialization:

AddCrossCheck("Monster", "Prey", "OnHitPrey")

The engine would do this:
1. Reserve a bit for the "Monster" and the "Prey" properties.
2. Set these bit for all objects that have the properties set
3. Add a listener to the object property change function to update the bits when the respective properties change
4. Run the cross check using the bit mask check
5. If it finds a hit, do the callback function on the first object

That method would be resitrcted to e.g. 32 bits at first, but can easily be extended to a bitset or multiple 32 bit masks if we run out of bits for cross checks.

Multiple calls to AddCrossCheck could just update/ignore the call, so you can do it in Initialize of the monster.

Objects can use two bitmasks: One for its own collision bits (first property in AddCrossCheck) and one for its target collision bits (I.e. link second property in AddCrossCheck to first and set all these bits). Then the cross check becomes even simpler because it only needs to do one bit mask comparison (if (obj->bit1 & obj2->bit) ...). It would also mean only one bit is required to be registered per cross-check (i.e.: Only the first bit). The second property can be looked up when a collision has actually happened.

We could also remove OCF and replace it with these custom bits. In fact the features could be separated and work like this:

static OCF_Prey = RegisterOCF("Prey");
static OCF_Monster = RegisterOCF("Monster");
RegisterCrossCheck(OCF_Monster, OCF_Prey, "OnHitPrey");

It could even be made downwards compatible with some of old OCFs like OCF_Alive, and also work in FindObject(Find_OCF(...)).

Of course, instead of bit masks, we can also just use properties and check them on every collision. That would be slightly less efficient but easier to implement.
Revision 2015-09-05 21:57 by Sven2
Description The engine cross-check was once used for object collection, object tumbling, incineration and fight-check (for CR-style clonk2clonk melee fights). These days, most of them have been replaced by FindObjects happening in one of the interaction objects.

This is actually a very inefficient method because it runs though the script engine, has to construct the whole FindObject-context, etc.

I propose to replace the current CrossCheck method by one for which you can register properties to be added to the check. E.g. for a monster, on definition initialization:

AddCrossCheck("Monster", "Prey", "OnHitPrey")

The engine would do this:
1. Reserve a bit for the "Monster" and the "Prey" properties.
2. Set these bit for all objects that have the properties set
3. Add a listener to the object property change function to update the bits when the respective properties change
4. Run the cross check using the bit mask check
5. If it finds a hit, do the callback function on the first object

That method would be resitrcted to e.g. 32 bits at first, but can easily be extended to a bitset or multiple 32 bit masks if we run out of bits for cross checks.

Multiple calls to AddCrossCheck could just update/ignore the call, so you can do it in Initialize of the monster.

Objects can use two bitmasks: One for its own collision bits (first property in AddCrossCheck) and one for its target collision bits (I.e. link second property in AddCrossCheck to first and set all these bits). Then the cross check becomes even simpler because it only needs to do one bit mask comparison (if (obj->bit1 & obj2->bit) ...). It would also mean only one bit is required to be registered per cross-check (i.e.: Only the first bit). The second property can be looked up when a collision has actually happened.

We could also remove OCF and replace it with these custom bits. In fact the features could be separated and work like this:

static OCF_Prey = RegisterOCF("Prey");
static OCF_Monster = RegisterOCF("Monster");
RegisterCrossCheck(OCF_Monster, OCF_Prey);

It could even be made downwards compatible with some of old OCFs like OCF_Alive, and also work in FindObject(Find_OCF(...)).

Of course, instead of bit masks, we can also just use properties and check them on every collision. That would be slightly less efficient but easier to implement.
Revision 2015-09-05 21:51 by Sven2
Description The engine cross-check was once used for object collection, object tumbling, incineration and fight-check (for CR-style clonk2clonk melee fights). These days, most of them have been replaced by FindObjects happening in one of the interaction objects.

This is actually a very inefficient method because it runs though the script engine, has to construct the whole FindObject-context, etc.

I propose to replace the current CrossCheck method by one for which you can register properties to be added to the check. E.g. for a monster, on definition initialization:

AddCrossCheck("Monster", "Prey", "OnHitPrey")

The engine would do this:
1. Reserve a bit for the "Monster" and the "Prey" properties.
2. Set these bit for all objects that have the properties set
3. Add a listener to the object property change function to update the bits when the respective properties change
4. Run the cross check using the bit mask check
5. If it finds a hit, do the callback function on the first object

That method would be resitrcted to e.g. 32 bits at first, but can easily be extended to a bitset or multiple 32 bit masks if we run out of bits for cross checks.

Multiple calls to AddCrossCheck could just update/ignore the call, so you can do it in Initialize of the monster.

Objects can use two bitmasks: One for its own collision bits (first property in AddCrossCheck) and one for its target collision bits (I.e. link second property in AddCrossCheck to first and set all these bits). Then the cross check becomes even simpler because it only needs to do one bit mask comparison (if (obj->bit1 & obj2->bit) ...). It would also mean only one bit is required to be registered per cross-check (i.e.: Only the first bit). The second property can be looked up when a collision has actually happened.

Of course, instead of bit masks, we can also just use properties and check them on every collision. That would be slightly less efficient but easier to implement.