Skip to content

Instantly share code, notes, and snippets.

@msg555
Created January 21, 2020 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg555/c4c7fe81cfcb344b5c13297e291c484f to your computer and use it in GitHub Desktop.
Save msg555/c4c7fe81cfcb344b5c13297e291c484f to your computer and use it in GitHub Desktop.
Sample script using the subframe callback API.
class script : callback_base {
scene@ g;
array<dustman@> players;
script() {
@g = get_scene();
}
void step(int num_entities) {
int nc = num_cameras();
puts("STEP");
players.resize(nc);
for (int i = 0; i < nc; i++) {
dustman@ dm = @controller_entity(i).as_dustman();
if (@dm != null && !dm.is_same(@players[i])) {
puts("REGISTER CALLBACK");
dm.on_subframe_end_callback(this, "subframe_cb", i);
}
@players[i] = @dm;
}
}
void subframe_cb(dustman@ dm, int player_index) {
puts("SUBSTEP " + player_index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment