Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_Compare.cpp
Go to the documentation of this file.
1/**
2 * @file Task_Compare.cpp
3 * @brief Atomic task: compare two values and return Success or Failure.
4 * @author Olympe Engine
5 * @date 2026-02-23
6 *
7 * Supports Int, Float, and String comparisons. Numeric operators
8 * (<, <=, >, >=) are only valid for Int and Float.
9 *
10 * C++14 compliant - no C++17/20 features.
11 */
12
13#include "Task_Compare.h"
14#include "../../AtomicTaskRegistry.h"
15#include "../../../system/system_utils.h"
16
17namespace Olympe {
18
20
22{
23 SYSTEM_LOG << "[Task_Compare] Abort()\n";
24}
25
27{
28 // Stateless: no context needed, so the legacy path works too.
31}
32
34 const ParameterMap& params)
35{
36 (void)ctx;
37
38 // --- Resolve Operator ---
39 std::string op;
40 {
41 auto it = params.find("Operator");
42 if (it == params.end() || it->second.GetType() != VariableType::String)
43 {
44 SYSTEM_LOG << "[Task_Compare] Missing or invalid 'Operator' parameter\n";
46 }
47 op = it->second.AsString();
48 }
49
50 // --- Resolve LHS and RHS ---
51 auto lhsIt = params.find("LHS");
52 auto rhsIt = params.find("RHS");
53
54 if (lhsIt == params.end() || rhsIt == params.end())
55 {
56 SYSTEM_LOG << "[Task_Compare] Missing 'LHS' or 'RHS' parameter\n";
58 }
59
60 const TaskValue& lhs = lhsIt->second;
61 const TaskValue& rhs = rhsIt->second;
62
63 if (lhs.GetType() != rhs.GetType())
64 {
65 SYSTEM_LOG << "[Task_Compare] Type mismatch between LHS and RHS\n";
67 }
68
69 bool result = false;
70
71 switch (lhs.GetType())
72 {
74 {
75 int l = lhs.AsInt();
76 int r = rhs.AsInt();
77 if (op == "==") result = (l == r);
78 else if (op == "!=") result = (l != r);
79 else if (op == "<") result = (l < r);
80 else if (op == "<=") result = (l <= r);
81 else if (op == ">") result = (l > r);
82 else if (op == ">=") result = (l >= r);
83 else
84 {
85 SYSTEM_LOG << "[Task_Compare] Unknown operator '" << op << "'\n";
87 }
88 break;
89 }
91 {
92 float l = lhs.AsFloat();
93 float r = rhs.AsFloat();
94 // Note: == and != perform exact bitwise float comparison.
95 // Callers using == or != for computed floats should consider
96 // using epsilon-tolerant comparisons via LocalBB pre-processing.
97 if (op == "==") result = (l == r);
98 else if (op == "!=") result = (l != r);
99 else if (op == "<") result = (l < r);
100 else if (op == "<=") result = (l <= r);
101 else if (op == ">") result = (l > r);
102 else if (op == ">=") result = (l >= r);
103 else
104 {
105 SYSTEM_LOG << "[Task_Compare] Unknown operator '" << op << "'\n";
106 return TaskStatus::Failure;
107 }
108 break;
109 }
111 {
112 const std::string& l = lhs.AsString();
113 const std::string& r = rhs.AsString();
114 if (op == "==") result = (l == r);
115 else if (op == "!=") result = (l != r);
116 else if (op == "<") result = (l < r);
117 else if (op == "<=") result = (l <= r);
118 else if (op == ">") result = (l > r);
119 else if (op == ">=") result = (l >= r);
120 else
121 {
122 SYSTEM_LOG << "[Task_Compare] Unknown operator '" << op << "'\n";
123 return TaskStatus::Failure;
124 }
125 break;
126 }
127 default:
128 SYSTEM_LOG << "[Task_Compare] Unsupported type for comparison\n";
129 return TaskStatus::Failure;
130 }
131
132 SYSTEM_LOG << "[Task_Compare] Comparison result: " << (result ? "true" : "false") << "\n";
134}
135
136REGISTER_ATOMIC_TASK(Task_Compare, "Task_Compare")
137
138} // namespace Olympe
#define REGISTER_ATOMIC_TASK(ClassName, Id)
Registers a factory for ClassName under Id at static init time.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Atomic task that compares two values and returns Success or Failure.
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition IAtomicTask.h:67
C++14-compliant type-safe value container for task parameters.
int AsInt() const
Returns the int value.
Atomic task that returns Success if a comparison holds, Failure otherwise.
TaskStatus Execute(const ParameterMap &params) override
Executes the atomic task for one frame.
void Abort() override
Aborts the task, releasing any in-progress state.
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params) override
Executes the atomic task for one frame with full runtime context.
< Provides AssetID and INVALID_ASSET_ID
@ Int
32-bit signed integer
@ Float
Single-precision float.
@ String
std::string
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition IAtomicTask.h:38
@ Success
Task completed successfully.
@ Failure
Task failed.
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
#define SYSTEM_LOG