Skip to content

Commit

Permalink
Added trigger for when spawning is started and stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
OlaOst committed Apr 11, 2012
1 parent bdc73c0 commit 91d8f84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions data/engine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ torqueForce = 50.0
slideForce = 25.0


#spawn.sound.soundFile = 59__fectoper__nostromo.wav
spawn.sound.soundFile = engine.wav
# we only want the sound to play once when engines fire - not every frame while the engines are firing
spawn.sound.trigger = startSpawning

spawn.exhaust.radius = 1.0
spawn.exhaust.lifetime = 0.2
Expand Down
8 changes: 8 additions & 0 deletions src/CommsCentral.d
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,16 @@ void setSpawnerFromController(Controller controller, Spawner spawner)
{
subSystemCommunication!(ControlComponent, SpawnerComponent)(controller, spawner, (ControlComponent controllerComponent, SpawnerComponent spawnerComponent)
{
spawnerComponent.startSpawning = (spawnerComponent.isSpawning == false &&
controllerComponent.isFiring &&
spawnerComponent.startSpawning == false);

spawnerComponent.isSpawning = controllerComponent.isFiring;

spawnerComponent.stopSpawning = (spawnerComponent.isSpawning &&
controllerComponent.isFiring == false &&
spawnerComponent.stopSpawning);

return spawnerComponent;
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/SubSystem/Spawner.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ struct SpawnerComponent
int entityId;
int ownerId;

bool startSpawning = false;
bool isSpawning = false;
bool stopSpawning = false;
}


Expand All @@ -87,10 +89,12 @@ public:
foreach (ref component; components)
{
//writeln("spawner.update: " ~ to!string(component.entityId) ~ ": " ~ to!string(component.isSpawning));

if (component.isSpawning)
foreach (spawnName, spawnValuesOriginal; component.spawnValuesNames)
{
foreach (spawnName, spawnValuesOriginal; component.spawnValuesNames)
if ((component.isSpawning && ("trigger" !in spawnValuesOriginal || spawnValuesOriginal["trigger"] == "isSpawning")) ||
(component.startSpawning && "trigger" in spawnValuesOriginal && spawnValuesOriginal["trigger"] == "startSpawning") ||
(component.stopSpawning && "trigger" in spawnValuesOriginal && spawnValuesOriginal["trigger"] == "stopSpawning"))
{
string[string] spawnValues = spawnValuesOriginal.dup;

Expand Down

0 comments on commit 91d8f84

Please sign in to comment.