"input_system" inside Dispatcher?

(Boomber) #1

I have a system called “PaddleSystem” which get dispatch from “GamePlay” state.
I set them up via this code:

impl SimpleState for GamePlay {
  fn on_start(&mut self, data: ...) {
    // ...
    let mut dispatcher_builder = DispatcherBuilder::new();
    dispatcher_builder.add(PaddleSystem, "paddle_system", &["input_system"]);
    // ...
    let dispatcher = dispatcher_builder.build();
    self.dispatcher = Some(dispatcher);
  }
}

Which result in this crash message when I run it.

[ERROR][rendy_resource::escape] Terminal must be dropped after all `Escape`s
[ERROR][rendy_resource::escape] Terminal must be dropped after all `Escape`s
[ERROR][rendy_resource::escape] Terminal must be dropped after all `Escape`s
[ERROR][rendy_resource::escape] Terminal must be dropped after all `Escape`s
[ERROR][rendy_memory::allocator::dynamic] Memory leak: SizeEntry(1048576) is still used
[ERROR][rendy_memory::allocator::dynamic] Memory leak: SizeEntry(524288) is still used
...
[ERROR][rendy_descriptor::allocator] Not all descriptor sets were deallocated
[ERROR][rendy_descriptor::allocator] Descriptor pool is still in use during allocator disposal. DescriptorPool { size: 64, free: 55, freed: 0 }
[ERROR][rendy_resource::escape] `Escape` was dropped after a `Terminal`?
[ERROR][rendy_resource::escape] `Escape` was dropped after a `Terminal`?
[ERROR][rendy_resource::escape] `Escape` was dropped after a `Terminal`?
...

While I do know that I can run the program without "input_system" but the doc specify that I should put every system that should be completed before this system gets run. The “PaddleSystem” required input from user so I don’t know if I should follow the doc or not.

Is it safe to remove "input_system" or should I use any other way to define these systems?

(Azriel Hoh) #2

Hiya, short version, it is “safe”.

Long version:

  • A dispatcher is a “bucket of functions” to run. The functions are the System implementations.
  • Sometimes, you want to specify order between the functions, which is what that "input_system" string is (defined when you insert the function, and then used when you insert another function).
  • Amethyst comes with one dispatcher by default (the one inside GameData).
  • In the code above, there is another dispatcher (state specific). This means you have two buckets of functions.
  • You can’t specify dependencies between buckets, because they’re separate.

Regarding which bucket runs first, it’s going to run the state specific bucket first, before the main one, which means you will have 1 frame of input lag – input from frame 1 will only be processed by the state-specific dispatcher systems in frame 2.

You could implement State directly instead of SimpleState, and switch that order around to get frame 1 input being processed in frame 1 systems (and include that "input_system" dependency).

1 Like