Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Static Public Member Functions | Static Private Member Functions | List of all members
Olympe::ConditionPresetEvaluator Class Reference

Evaluates a ConditionPreset against a RuntimeEnvironment. More...

#include <ConditionPresetEvaluator.h>

Static Public Member Functions

static bool Evaluate (const ConditionPreset &preset, RuntimeEnvironment &env, std::string &outErrorMsg)
 Evaluates a single ConditionPreset and returns the boolean result.
 
static bool EvaluateConditionChain (const std::vector< NodeConditionRef > &conditions, const ConditionPresetRegistry &registry, RuntimeEnvironment &env, std::string &outErrorMsg)
 Evaluates a chain of conditions combined with logical operators (AND/OR).
 

Static Private Member Functions

static bool ResolveOperand (const Operand &operand, RuntimeEnvironment &env, std::string &outErrorMsg, float &outValue)
 Resolves an Operand to its runtime float value.
 
static bool EvaluateOperator (float left, ComparisonOp op, float right, std::string &outErrorMsg)
 Applies a ComparisonOp to two float values.
 

Detailed Description

Evaluates a ConditionPreset against a RuntimeEnvironment.

Typical usage:

env.SetBlackboardVariable("mHealth", 1.0f);
std::string error;
// result == true, error == ""
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static bool Evaluate(const ConditionPreset &preset, RuntimeEnvironment &env, std::string &outErrorMsg)
Evaluates a single ConditionPreset and returns the boolean result.
Provides Blackboard variable values and dynamic pin values at runtime.
void SetBlackboardVariable(const std::string &key, float value)
Stores or overwrites a Blackboard variable.
A globally-stored, reusable condition expression.
static Operand CreateVariable(const std::string &variableID)
Factory — creates a Variable-mode operand.
Definition Operand.cpp:33
static Operand CreateConst(double constVal)
Factory — creates a Const-mode operand.
Definition Operand.cpp:43

For multiple conditions with logical operators:

std::vector<NodeConditionRef> conditions;
// (populated with NodeConditionRef entries referencing presets)
conditions, env, outErrorMsg);
static bool EvaluateConditionChain(const std::vector< NodeConditionRef > &conditions, const ConditionPresetRegistry &registry, RuntimeEnvironment &env, std::string &outErrorMsg)
Evaluates a chain of conditions combined with logical operators (AND/OR).

Definition at line 69 of file ConditionPresetEvaluator.h.

Member Function Documentation

◆ Evaluate()

bool Olympe::ConditionPresetEvaluator::Evaluate ( const ConditionPreset preset,
RuntimeEnvironment env,
std::string &  outErrorMsg 
)
static

Evaluates a single ConditionPreset and returns the boolean result.

Parameters
presetThe condition preset to evaluate.
envRuntime environment providing variable and pin values.
outErrorMsgReceives a human-readable error description on failure. Empty on success.
Returns
true when the condition holds; false on failure or when the comparison evaluates to false.

Definition at line 22 of file ConditionPresetEvaluator.cpp.

References EvaluateOperator(), GetComponentTypeID_Static(), and ResolveOperand().

Referenced by EvaluateConditionChain(), Olympe::Examples::Example1_SimpleHealthCheck(), Olympe::Examples::Example2_ConstModeOperand(), and Olympe::Examples::Example6_ErrorHandling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EvaluateConditionChain()

bool Olympe::ConditionPresetEvaluator::EvaluateConditionChain ( const std::vector< NodeConditionRef > &  conditions,
const ConditionPresetRegistry registry,
RuntimeEnvironment env,
std::string &  outErrorMsg 
)
static

Evaluates a chain of conditions combined with logical operators (AND/OR).

Implements short-circuit evaluation:

  • For AND chains: stops and returns false at the first false condition
  • For OR chains: stops and returns true at the first true condition

The first condition's LogicalOp is ignored (treated as Start).

Parameters
conditionsVector of NodeConditionRef objects referencing presets. Each preset ID is resolved via the provided registry.
registryRegistry containing the ConditionPreset objects.
envRuntime environment providing variable and pin values.
outErrorMsgReceives a human-readable error description on failure. Empty on success.
Returns
true when the combined condition chain evaluates to true; false on evaluation failure or when conditions are empty.
Precondition
conditions vector must not be empty.
registry must be valid (non-null).

Definition at line 42 of file ConditionPresetEvaluator.cpp.

References Olympe::And, Evaluate(), GetComponentTypeID_Static(), Olympe::Or, and Olympe::Start.

Referenced by Olympe::VSGraphExecutor::HandleBranch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EvaluateOperator()

bool Olympe::ConditionPresetEvaluator::EvaluateOperator ( float  left,
ComparisonOp  op,
float  right,
std::string &  outErrorMsg 
)
staticprivate

Applies a ComparisonOp to two float values.

Parameters
leftLeft-hand side value.
opOperator to apply.
rightRight-hand side value.
outErrorMsgReceives an error description for unknown operators.
Returns
Result of the comparison, or false on unknown operator.

Definition at line 202 of file ConditionPresetEvaluator.cpp.

References Olympe::Equal, GetComponentTypeID_Static(), Olympe::Greater, Olympe::GreaterEqual, Olympe::Less, Olympe::LessEqual, and Olympe::NotEqual.

Referenced by Evaluate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResolveOperand()

bool Olympe::ConditionPresetEvaluator::ResolveOperand ( const Operand operand,
RuntimeEnvironment env,
std::string &  outErrorMsg,
float outValue 
)
staticprivate

Resolves an Operand to its runtime float value.

Parameters
operandOperand to resolve.
envRuntimeEnvironment used for Variable / Pin lookup.
outErrorMsgReceives an error description when resolution fails.
outValueReceives the resolved float value on success.
Returns
true on success; false when the variable / pin is not found.

Definition at line 157 of file ConditionPresetEvaluator.cpp.

References Olympe::Const, GetComponentTypeID_Static(), Olympe::Pin, and Olympe::Variable.

Referenced by Evaluate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: