summary refs log tree commit diff stats
path: root/src/systems/realizing.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-13 00:50:11 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb (patch)
tree94a3f4ce0a0e54375cd2f27fb90d7c35295bda2e /src/systems/realizing.cpp
parent59808c86bf0e4d5cf0b6ab3d6ed1d8bdcd303a37 (diff)
downloadtherapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.gz
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.bz2
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.zip
Started event handlers
The AutomatingSystem has been renamed to the ScriptingSystem, since the automatic behavior script is just a special case of the scripts that an entity can exhibit. The AutomatableComponent has largely been moved to the new RunnableComponent (might not be the final name for it).

The Lua state object, previously living on the singleton RealizableComponent, is now a member of the ScriptingSystem itself, because it A) doesn't really belong on the realizable entity, and B) a singleton entity seems weird and like a cumbersome attempt to apply the ECS rules to places they don't apply. In a similar vein, the RealizableComponent itself will probably soon be integrated into the RealizingSystem too.

The attempt at using Lua environments in order to encapsulate the different behaviors that objects exhibit was scrapped in preference of just creating differently named Lua tables for each prototype.

The new PrototypableComponent contains some information about entities which were prototyped. It is partially used by the ScriptingSystem to figure out what event handlers are appropriate, which may not be the best approach. It also has some data about automatic behavior, which also maybe does not belong in this component.

The OnTouch event is raised by a player colliding with a physics body with the collider type "event", which may not be the best way to implement this.

The result of all of this is that checkpoints now work, although no sound is played, and the result is not persistent across exiting the game.
Diffstat (limited to 'src/systems/realizing.cpp')
-rw-r--r--src/systems/realizing.cpp66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/systems/realizing.cpp b/src/systems/realizing.cpp index 28e2279..2ee5897 100644 --- a/src/systems/realizing.cpp +++ b/src/systems/realizing.cpp
@@ -12,11 +12,11 @@
12#include "components/playable.h" 12#include "components/playable.h"
13#include "components/ponderable.h" 13#include "components/ponderable.h"
14#include "components/transformable.h" 14#include "components/transformable.h"
15#include "components/automatable.h" 15#include "components/prototypable.h"
16#include "systems/mapping.h" 16#include "systems/mapping.h"
17#include "systems/animating.h" 17#include "systems/animating.h"
18#include "systems/pondering.h" 18#include "systems/pondering.h"
19#include "systems/automating.h" 19#include "systems/scripting.h"
20 20
21inline xmlChar* getProp(xmlNodePtr node, const char* attr) 21inline xmlChar* getProp(xmlNodePtr node, const char* attr)
22{ 22{
@@ -40,9 +40,6 @@ EntityManager::id_type RealizingSystem::initSingleton(
40 auto& realizable = game_.getEntityManager(). 40 auto& realizable = game_.getEntityManager().
41 emplaceComponent<RealizableComponent>(world); 41 emplaceComponent<RealizableComponent>(world);
42 42
43 game_.getSystemManager().getSystem<AutomatingSystem>().
44 initScriptEngine(realizable.scriptEngine);
45
46 realizable.worldFile = worldFile; 43 realizable.worldFile = worldFile;
47 realizable.prototypeFile = prototypeFile; 44 realizable.prototypeFile = prototypeFile;
48 45
@@ -216,14 +213,28 @@ EntityManager::id_type RealizingSystem::initSingleton(
216 game_.getSystemManager().getSystem<PonderingSystem>(). 213 game_.getSystemManager().getSystem<PonderingSystem>().
217 initializeBody(mapObject, PonderableComponent::Type::vacuumed); 214 initializeBody(mapObject, PonderableComponent::Type::vacuumed);
218 215
216
217
218
219
220 auto& prototypable = game_.getEntityManager().
221 emplaceComponent<PrototypableComponent>(mapObject);
222
223 prototypable.prototypeId = prototypeId;
224
225 key = getProp(mapNode, "index");
226 prototypable.mapObjectIndex = atoi(reinterpret_cast<char*>(key));
227 xmlFree(key);
228
219 if (prototypeId == "movplat") 229 if (prototypeId == "movplat")
220 { 230 {
221 auto& automatable = game_.getEntityManager(). 231 prototypable.hasBehavior = true;
222 emplaceComponent<AutomatableComponent>(mapObject); 232 } else if (prototypeId == "checkpoint")
223 233 {
234 auto& ponderable = game_.getEntityManager().
235 getComponent<PonderableComponent>(mapObject);
224 236
225 realizable.scriptEngine.script_file( 237 ponderable.colliderType = PonderableComponent::Collision::event;
226 "res/platform.lua");//,
227 } 238 }
228 239
229 mappable.objects.push_back(mapObject); 240 mappable.objects.push_back(mapObject);
@@ -319,7 +330,6 @@ void RealizingSystem::loadMap(id_type mapEntity)
319 330
320 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); 331 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>();
321 auto& pondering = game_.getSystemManager().getSystem<PonderingSystem>(); 332 auto& pondering = game_.getSystemManager().getSystem<PonderingSystem>();
322 auto& automating = game_.getSystemManager().getSystem<AutomatingSystem>();
323 333
324 std::set<id_type> players = 334 std::set<id_type> players =
325 game_.getEntityManager().getEntitiesWithComponents< 335 game_.getEntityManager().getEntitiesWithComponents<
@@ -380,11 +390,6 @@ void RealizingSystem::loadMap(id_type mapEntity)
380 pondering.initPrototype(prototype); 390 pondering.initPrototype(prototype);
381 } 391 }
382 392
383 if (game_.getEntityManager().hasComponent<AutomatableComponent>(prototype))
384 {
385 automating.initPrototype(prototype);
386 }
387
388 enterActiveMap(prototype); 393 enterActiveMap(prototype);
389 } 394 }
390 395
@@ -419,12 +424,19 @@ void RealizingSystem::enterActiveMap(id_type entity)
419 ponderable.active = true; 424 ponderable.active = true;
420 } 425 }
421 426
422 if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity)) 427 if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity))
423 { 428 {
424 auto& automatable = game_.getEntityManager(). 429 auto& prototypable = game_.getEntityManager().
425 getComponent<AutomatableComponent>(entity); 430 getComponent<PrototypableComponent>(entity);
431
432 if (prototypable.hasBehavior)
433 {
434 auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>();
426 435
427 automatable.active = true; 436 prototypable.hasBehavior = true;
437 prototypable.runningBehavior = true;
438 prototypable.behaviorScript = scripting.runBehaviorScript(entity);
439 }
428 } 440 }
429} 441}
430 442
@@ -446,11 +458,17 @@ void RealizingSystem::leaveActiveMap(id_type entity)
446 ponderable.active = false; 458 ponderable.active = false;
447 } 459 }
448 460
449 if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity)) 461 if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity))
450 { 462 {
451 auto& automatable = game_.getEntityManager(). 463 auto& prototypable = game_.getEntityManager().
452 getComponent<AutomatableComponent>(entity); 464 getComponent<PrototypableComponent>(entity);
453 465
454 automatable.active = false; 466 if (prototypable.runningBehavior)
467 {
468 auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>();
469 scripting.killScript(prototypable.behaviorScript);
470
471 prototypable.runningBehavior = false;
472 }
455 } 473 }
456} 474}