- Joined
- Jul 10, 2007
- Messages
- 6,306
I'm going to bed for now. I figured I'd post this up so that everyone could see this awesomeness =).
And here's some test code (not that the API isn't even there yet, I'm still working on the internals)
Keep in mind that I'm using TriggerSleepAction because the thread is crashing in debug mode.
TriggerTrees don't support trailing refs, only direct refs.
tree1.referenceTree(tree2)
tree2.referenceTree(tree3)
call TriggerEvaluate(tree1.triggerLeft)
that will only fire tree1 and tree2, not tree3. The ref lists are used to support trailing refs. I'm coding the ref lists next.
The code there will display
8
7
6
5
4
3
2
1
So yea, we can mix triggers now... yea
I know that there's not much code atm, I spent the majority of the day debugging BooleanExpression and Trigger. I had redone some things in them to improve performance a lot. Those changes broke everything, haha.
JASS:
library PriorityTrigger /* v1.0.0.0
************************************************************************************
*
* */ uses /*
*
* */ Trigger /* hiveworkshop.com/forums/submissions-414/snippet-error-message-239210/
* */ AVL /* hiveworkshop.com/forums/jass-resources-412/snippet-avl-tree-203168/
*
************************************************************************************
*
* struct PriorityTrigger extends array
*
* Fields
* -------------------------
*
* readonly trigger trigger
* - use to register events, nothing else
* - keep in mind that triggers referencing this trigger won't fire when events fire
* - this trigger will fire when triggers referencing this trigger are fired
*
* boolean enabled
*
* Methods
* -------------------------
*
* static method create takes nothing returns Trigger
* method destroy takes nothing returns nothing
*
* method register takes boolexpr expression, integer priority returns PriorityTriggerCondition
*
* method reference takes Trigger trig, integer priority returns PriorityTriggerReference
* - a referenced trigger will run before this trigger
* - referenced triggers run in order of reference
*
* method fire takes nothing returns nothing
*
* method clear takes nothing returns nothing
* - clears expressions
* method clearReferences takes nothing returns nothing
* - clears trigger references
* method clearBackReferences takes nothing returns nothing
* - removes references for all triggers referencing this trigger
* method clearEvents takes nothing returns nothing
* - clears events
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************
*
* struct PriorityTriggerReference extends array
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
*
************************************************************************************
*
* struct PriorityTriggerCondition extends array
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
*
************************************************************************************/
/*
* Stores Trigger Reference
*
* Stores list of trigger references between two priority triggers
*/
private struct RefListData extends array
implement UniqueList
endstruct
private struct TriggerTreeData extends array
private method lessThan takes thistype val returns boolean
return integer(this)<integer(val)
endmethod
private method greaterThan takes thistype val returns boolean
return integer(this)>integer(val)
endmethod
Trigger triggerLeft
Trigger triggerRight
Trigger trigger
TriggerReference link
/*
* Node Left Node Right
* Trigger Link Trigger Link
* right -> right
* trigger trigger
* triggers triggers
* expressions expressions
*/
implement AVL
endstruct
/*
* TriggerTreeData
*
* Stores referenced priority triggers
*/
private keyword BackRefListData
private keyword TriggerTree
private struct ForwardRefListData extends array
implement NxList
RefListData refList //list of trigger references
TriggerTree triggerTree //the referenced priority trigger
BackRefListData backRefList //the back ref node containing this list
endstruct
/*
* TriggerTreeData
*
* Stores priority triggers referencing this priority trigger
*/
private struct BackRefListData extends array
implement NxList
TriggerTree triggerTree //the priority trigger referencing this
ForwardRefListData forwardList //the forward ref node containing this list
endstruct
struct RefList extends array
method operator reference takes nothing returns TriggerReference
return this
endmethod
method enqueue takes TriggerReference ref returns nothing
call RefListData(this).enqueue(ref)
endmethod
method operator next takes nothing returns thistype
return RefListData(this).next
endmethod
method remove takes nothing returns nothing
call TriggerReference(this).destroy()
call RefListData(this).remove()
endmethod
static method create takes nothing returns thistype
return RefListData.create()
endmethod
method destroy takes nothing returns nothing
local RefListData node = RefListData(this).first
loop
exitwhen node == 0
call TriggerReference(node).destroy()
set node = node.next
endloop
call RefListData(this).destroy()
endmethod
endstruct
private struct TriggerTree extends array
method operator trigger takes nothing returns trigger
return TriggerTreeData(this).next.triggerLeft.trigger
endmethod
private method operator prev takes nothing returns TriggerTreeData
return TriggerTreeData(this).prev
endmethod
private method operator next takes nothing returns TriggerTreeData
return TriggerTreeData(this).next
endmethod
static method create takes nothing returns thistype
return TriggerTreeData.create()
endmethod
private method setRef takes nothing returns nothing
local TriggerTreeData node = this
if (not node.prev.head) then
if (node.prev.link == 0) then
set node.prev.link = node.prev.triggerRight.reference(node.triggerLeft)
else
call node.prev.link.replace(node.triggerLeft)
endif
endif
if (not node.next.head) then
set node.link = node.triggerRight.reference(node.next.triggerLeft)
endif
endmethod
method insert takes boolexpr expression, integer priority returns TriggerCondition
local TriggerTreeData node = TriggerTreeData(this).add(priority)
local thistype expr
if (node.trigger == 0) then
set node.triggerLeft = Trigger.create()
set node.triggerRight = Trigger.create()
set node.trigger = Trigger.create()
call node.triggerLeft.reference(node.triggerRight)
call node.triggerLeft.reference(node.trigger)
set expr = node.trigger.register(expression)
call thistype(node).setRef()
else
set expr = node.trigger.register(expression)
endif
return expr
endmethod
method reference takes Trigger trig, integer priority returns TriggerReference
local TriggerTreeData node = TriggerTreeData(this).add(priority)
local TriggerReference ref
if (node.trigger == 0) then
set node.triggerLeft = Trigger.create()
set node.triggerRight = Trigger.create()
set node.trigger = Trigger.create()
call node.triggerLeft.reference(node.triggerRight)
call node.triggerLeft.reference(node.trigger)
set ref = node.trigger.reference(trig)
call thistype(node).setRef()
else
set ref = node.trigger.reference(trig)
endif
return ref
endmethod
method referenceTree takes TriggerTreeData triggerTree returns RefList
local RefList refList = RefList.create()
local TriggerTreeData targetNode
set targetNode = triggerTree.next
loop
exitwhen targetNode.head
call refList.enqueue(reference(targetNode.trigger, targetNode.value))
set targetNode = targetNode.next
endloop
return refList
endmethod
method clear takes nothing returns nothing
local TriggerTreeData node = next
loop
exitwhen node.head
call node.triggerLeft.destroy()
call node.triggerRight.destroy()
call node.trigger.destroy()
set node.triggerLeft = 0
set node.triggerRight = 0
set node.trigger = 0
set node.link = 0
set node = node.next
endloop
call TriggerTreeData(this).clear()
endmethod
method destroy takes nothing returns nothing
call clear()
call TriggerTreeData(this).destroy()
endmethod
endstruct
private struct BackRefList extends array
method init takes nothing returns nothing
endmethod
method clear takes nothing returns nothing
endmethod
method destroy takes nothing returns nothing
endmethod
method reference takes nothing returns RefListData
return 0
endmethod
/*
* this == RefListData
*/
method dereference takes nothing returns nothing
endmethod
endstruct
private struct ForwardRefList extends array
method init takes nothing returns nothing
endmethod
method clear takes nothing returns nothing
endmethod
method destroy takes nothing returns nothing
endmethod
method reference takes nothing returns RefListData
return 0
endmethod
/*
* this == RefListData
*/
method dereference takes nothing returns nothing
endmethod
endstruct
//! runtextmacro optional TEST()
endlibrary
And here's some test code (not that the API isn't even there yet, I'm still working on the internals)
JASS:
//! textmacro TEST
private struct Tester extends array
implement TestFunctions
static method init takes nothing returns nothing
implement TestLocals
local TriggerTree tree1 = TriggerTree.create()
local TriggerTree tree2 = TriggerTree.create()
local TriggerTree tree3 = TriggerTree.create()
local TriggerTree tree4 = TriggerTree.create()
local TriggerTree tree5 = TriggerTree.create()
local TriggerTree tree6 = TriggerTree.create()
local TriggerTree tree7 = TriggerTree.create()
local TriggerTree tree8 = TriggerTree.create()
local TriggerTree tree9 = TriggerTree.create()
implement TestInit
call tree1.insert(Condition(function thistype.run1), 1)
call tree1.reference(t3, 3)
call tree2.insert(Condition(function thistype.run2), 2)
call tree2.reference(t4, 4)
call tree3.insert(Condition(function thistype.run5), 5)
call tree3.reference(t7, 7)
call tree4.insert(Condition(function thistype.run6), 6)
call tree4.reference(t8, 8)
call TriggerSleepAction(0)
call tree1.referenceTree(tree2)
call TriggerSleepAction(0)
call tree1.referenceTree(tree3)
call TriggerSleepAction(0)
call tree1.referenceTree(tree4)
call TriggerEvaluate(tree1.trigger)
endmethod
implement Init
endstruct
//! endtextmacro
Keep in mind that I'm using TriggerSleepAction because the thread is crashing in debug mode.
TriggerTrees don't support trailing refs, only direct refs.
tree1.referenceTree(tree2)
tree2.referenceTree(tree3)
call TriggerEvaluate(tree1.triggerLeft)
that will only fire tree1 and tree2, not tree3. The ref lists are used to support trailing refs. I'm coding the ref lists next.
The code there will display
8
7
6
5
4
3
2
1
So yea, we can mix triggers now... yea
I know that there's not much code atm, I spent the majority of the day debugging BooleanExpression and Trigger. I had redone some things in them to improve performance a lot. Those changes broke everything, haha.