The default implementation of the IRuleEngine interface. RuleEngine stores all of the IRules, ILogics, mixin strings, and priority branching logic provided by the loaded RuleSets in string-based hash maps. The functions required by the IRuleEngine interface are implemented by taking the string-based hash maps and performing the necessary operations. See the function and variable documentation below for more details.
RuleEngine.h
The default implementation of the IRuleEngine interface. | |
Stops the RuleEngine. | |
Executes the given IRule with the given DataObject. | |
Calls the given logic with the given DataObjects. | |
Returns whether there is anything on the undo stack that can be undone. | |
Undoes the last action. | |
Branches down the rule chain. | |
The string-based hash of IRule objects. | |
The string-based hash of ILogic objects. | |
The string-based hash of string mixin names. | |
The string-based hash of priority branching logic. | |
The undo stack. |
Stops the RuleEngine. | |
Executes the given IRule with the given DataObject. | |
Calls the given logic with the given DataObjects. | |
Returns whether there is anything on the undo stack that can be undone. | |
Undoes the last action. |
|
Executes the given IRule with the given DataObject. Looks up the IRule name in the string hash map. If the string name does not exist in the hash, an error is thrown to the screen. If the IRule is potentially undoable, it may be added to the undo stack if its CanUndo function returns true. If there are any mixins that belong to this IRule, they are added to the IRule before it executes. After the rule executes, the Branch function is called to see if the IRule has any branching logic that needs to get called.
| rule | The name of the IRule to execute. |
| object | The DataObject to pass to the IRule. |
|
Calls the given logic with the given DataObjects. Looks up the ILogic name in the string hash map. If the string name does not exist in the hash, an error is thrown to the screen. If there are any mixins that belong to this ILogic, they are added to the ILogic before it is called. The output DataObject must be empty before the ILogic’s Decide function is called and non-empty afterwards.
| logic | The name of the ILogic to call. |
| input | The input DataObject. |
| output | The output DataObject. Must be NULL. |
| virtual void Undo() |
Undoes the last action. Pops the last IRule name/DataObject pair off the undo stack and calls that IRules Unexecute function with the DataObject. Plays the undo sound.
|
Branches down the rule chain. Looks up the given IRule in the hash of rule chain logic. If an entry is found with the given IRule name, the branch logic at that entry is called in priority order. If any of the branch logic returns the name of another IRule, that IRule is then immediately executed via the Execute function. In this way branching logic for IRules may be implemented without the IRules themselves knowing about each other.
| rule | The name of the IRule to branch from. |
| object | The DataObject to pass down the rule chain. |
|
Adds any mixins to the given IRule or ILogic. Looks up the name in the mixin hash. If there are any mixin names available for that IRule or ILogic name, they are added to the given BaseMixin pointer so that the IRule or ILogic has access to them during its execution.
| name | The name of the IRule or ILogic to look up mixins for. |
| pMixin | A pointer to the BaseMixin object that will receive any mixin data. It is safe for the pointer to be NULL. |
| RuleHash mRuleHash |
The string-based hash of IRule objects. The rule hash contains the IRules specific to the game being played, copied from all of the RuleSets loaded by the IPluginEngine. Each IRule is stored in a one to one mapping with a string that is the rule name. Rules are executed by calling the Execute function with the rule name and a DataObject to pass to the IRule.
| LogicHash mLogicHash |
The string-based hash of ILogic objects. The logic hash contains the ILogic specific to the game being played, copied from all of the RuleSets loaded by the IPluginEngine. Each piece of ILogic is stored in a one to one mapping with a string that is the logic name. Logic is executed by calling the Decide function with the logic name, an input DataObject, which may not be empty, and an output DataObject, which must be empty, and is filled with the rendered decision of the piece of ILogic.
| MixinHash mMixinHash |
The string-based hash of string mixin names. Each IRule or ILogic that has mixins provided by the loaded RuleSets has an entry by name in the mixin hash. At each mixin hash entry is stored another string-based hash map that contains the actual mixin entry names for that IRule or ILogic.
| BranchPriorityHash mBranchHash |
The string-based hash of priority branching logic. Some RuleSets need certain IRules to immediately branch to another IRule after it has finished executing. However, other RuleSets may need to overload even this existing branching. The priority branch hash provides a mechanism for this to happen. The name of each rule with branching logic is stored as a key in the hash. For each key, a std::map of integer/ILogic pairs is stored, with higher integer values being stored first (meaning, they have greater priority). When the Branch function is called, the given rule name is looked up in the priority branching hash. If it is discovered, each of its associated ILogic is called in the priority order. If any piece of ILogic returns the name of a rule, that IRule is immediately branched to with the Execute function.
| void Stop() |
|
|
| virtual bool CanUndo() const |
| virtual void Undo() |
|
|
| RuleHash mRuleHash |
| LogicHash mLogicHash |
| MixinHash mMixinHash |
| BranchPriorityHash mBranchHash |
| UndoStack mUndoStack |