6 #include <unordered_map>
23 using std::make_unique;
26 using std::unique_ptr;
27 using std::unordered_map;
102 inline void handleHIDEvents(vector<GUIMouseEvent>& mouseEvents, vector<GUIKeyboardEvent>& keyEvents) {
103 miniScript->collectHIDEvents(mouseEvents, keyEvents);
108 if (
miniScript->enginePrototypesToAdd.empty() ==
false) {
110 for (
const auto& prototypeToAdd:
miniScript->enginePrototypesToAdd) {
112 Console::println(
"MiniScriptLogic::updateEngine(): adding prototype: id: " + prototypeToAdd.id +
", hierarchyId: " + prototypeToAdd.hierarchyId +
", hierarchy parent id: " + prototypeToAdd.hierarchyParentId);
115 if (prototypeToAdd.hierarchyId.empty() ==
false) {
118 auto transform = prototypeToAdd.transform;
120 prototypeToAdd.attachNodeId.empty() ==
false) {
122 auto prototype = prototypeIt ==
enginePrototypes.end()?
nullptr:prototypeIt->second;
124 if (prototype !=
nullptr &&
125 prototype->getModel() !=
nullptr &&
126 prototype->getModel()->computeTransformMatrix(
127 prototypeToAdd.attachNodeId,
128 prototype->getModel()->getImportTransformMatrix(),
129 attachNodeTransformMatrix
133 attachNodeTransform.
fromMatrix(attachNodeTransformMatrix, RotationOrder::ZYX);
134 transform = attachNodeTransform * transform;
136 Console::println(
"MiniScriptLogic::updateEngine(): " +
getId() +
": " + prototypeToAdd.attachNodeId +
"@" +
getId() +
" not found");
148 auto id = prototypeToAdd.attachNodeId.empty() ==
false?prototypeToAdd.attachNodeId +
"." + prototypeToAdd.id:prototypeToAdd.id;
152 prototypeToAdd.prototype,
153 prototypeToAdd.attachNodeId.empty() ==
false?prototypeToAdd.attachNodeId +
"." + prototypeToAdd.id:prototypeToAdd.id,
156 parentEntity !=
nullptr
158 if (parentEntity ==
nullptr) {
161 parentEntity->
addEntity(entity, prototypeToAdd.hierarchyParentId);
180 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
181 EngineMiniScript::ScriptVariable returnValue;
182 span argumentValuesSpan(argumentValues);
183 if (
miniScript->call(
"initializeEngine", argumentValuesSpan, returnValue) ==
false) {
190 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
191 EngineMiniScript::ScriptVariable returnValue;
192 span argumentValuesSpan(argumentValues);
193 if (
miniScript->call(
"updateEngine", argumentValuesSpan, returnValue) ==
false) {
200 if (
miniScript->physicsPrototypesToAdd.empty() ==
false) {
203 for (
const auto& prototypeToAdd:
miniScript->physicsPrototypesToAdd) {
205 Console::println(
"MiniScriptLogic::updateLogic(): adding prototype: id: " + prototypeToAdd.id +
", hierarchyId: " + prototypeToAdd.hierarchyId +
", hierarchy parent id: " + prototypeToAdd.hierarchyParentId);
208 auto transform = prototypeToAdd.transform;
210 prototypeToAdd.attachNodeId.empty() ==
false) {
211 auto prototypeIt =
logicPrototypes.find(prototypeToAdd.hierarchyParentId);
212 auto prototype = prototypeIt ==
logicPrototypes.end()?
nullptr:prototypeIt->second;
214 if (prototype !=
nullptr &&
215 prototype->getModel() !=
nullptr &&
216 prototype->getModel()->computeTransformMatrix(
217 prototypeToAdd.attachNodeId,
218 prototype->getModel()->getImportTransformMatrix(),
219 attachNodeTransformMatrix
223 attachNodeTransform.
fromMatrix(attachNodeTransformMatrix, RotationOrder::ZYX);
224 transform = attachNodeTransform * transform;
226 Console::println(
"MiniScriptLogic::updateLogic(): " +
getId() +
": " + prototypeToAdd.attachNodeId +
"@" +
getId() +
" not found");
238 auto id = prototypeToAdd.attachNodeId.empty() ==
false?prototypeToAdd.attachNodeId +
"." + prototypeToAdd.id:prototypeToAdd.id;
240 if (prototypeToAdd.hierarchyId.empty() ==
false) {
243 prototypeToAdd.prototype,
246 prototypeToAdd.hierarchyId,
247 prototypeToAdd.hierarchyParentId
252 prototypeToAdd.prototype,
255 Body::COLLISION_TYPEID_DYNAMIC
262 if (prototypeToAdd.prototype->hasScript() ==
true) {
263 auto prototype = prototypeToAdd.prototype;
264 auto logicMiniScript = make_unique<LogicMiniScript>();
265 logicMiniScript->parseScript(
266 Tools::getPathName(prototype->getScript()),
267 Tools::getFileName(prototype->getScript())
270 make_unique<MiniScriptLogic>(
273 prototype->isScriptHandlingHID(),
274 logicMiniScript.release(),
275 prototypeToAdd.prototype,
277 prototypeToAdd.hierarchyId,
278 prototypeToAdd.hierarchyParentId
291 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
292 EngineMiniScript::ScriptVariable returnValue;
293 span argumentValuesSpan(argumentValues);
294 if (
miniScript->call(
"initializeLogic", argumentValuesSpan, returnValue) ==
false) {
303 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
304 EngineMiniScript::ScriptVariable returnValue;
305 span argumentValuesSpan(argumentValues);
306 if (
miniScript->call(
"updateLogic", argumentValuesSpan, returnValue) ==
false) {
313 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
314 EngineMiniScript::ScriptVariable returnValue;
315 span argumentValuesSpan(argumentValues);
316 if (
miniScript->call(
"onLogicAdded", argumentValuesSpan, returnValue) ==
false) {
323 vector<EngineMiniScript::ScriptVariable> argumentValues(0);
324 EngineMiniScript::ScriptVariable returnValue;
325 span argumentValuesSpan(argumentValues);
326 if (
miniScript->call(
"onLogicsProcessed", argumentValuesSpan, returnValue) ==
false) {
void addEntity(Entity *entity)
Adds an entity by id.
Entity * getEntity(const string &id)
Returns a entity by given id.
Entity hierarchy to be used with engine class.
void update() override
Update transform.
void addEntity(Entity *entity, const string &parentId=string())
Adds a entity to the hierarchy.
Scene engine/physics connector.
static BodyHierarchy * createSubBody(World *world, Prototype *prototype, const string &id, const Transform &transform, const string &bodyHierarchyId, const string &bodyHierarchyParentId)
Create sub body in body hierarchy.
static Entity * createEntity(Prototype *prototype, const string &id, const Transform &transform, int instances=1, bool noEntityHierarchy=false)
Create engine entity.
static Body * createBody(World *world, Prototype *prototype, const string &id, const Transform &transform, uint16_t collisionTypeId=BODY_TYPEID_STANDARD, bool hierarchy=false, int index=BOUNDINGVOLUME_INDEX_NONE, PrototypePhysics_BodyType *overrideType=nullptr)
Create body.
static void addSounds(Audio *audio, Prototype *prototype, const string &id, int poolSize=1)
Add scene entity sounds into given audio instance associated with given id.
unordered_map< string, Prototype * > logicPrototypes
const string & getHierarchyParentId()
const string & getHierarchyId()
void updateLogic() override
Update logic.
void onLogicAdded() override
On logic added.
void updateEngine() override
Update engine.
LogicMiniScript * getMiniScript()
void onLogicsProcessed() override
On logics processed.
unique_ptr< LogicMiniScript > miniScript
void handleHIDEvents(vector< GUIMouseEvent > &mouseEvents, vector< GUIKeyboardEvent > &keyEvents)
Handle HID events.
unordered_map< string, Prototype * > enginePrototypes
Representation of a 3D model.
Represents rotation orders of a model.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
#define FORBID_CLASS_COPY(CLASS)