getChildEntities method

  1. @override
Future<List<ThermionEntity>> getChildEntities(
  1. ThermionEntity parent,
  2. bool renderableOnly
)
override

Returns all child entities under parent.

Implementation

@override
Future<List<ThermionEntity>> getChildEntities(
    ThermionEntity parent, bool renderableOnly) async {
  var entityCountJS = _module.ccall(
      "get_entity_count",
      "int",
      ["void*".toJS, "int".toJS, "bool".toJS].toJS,
      [_sceneManager!, parent.toJS, renderableOnly.toJS].toJS,
      null) as JSNumber;
  var entityCount = entityCountJS.toDartInt;
  var entities = <ThermionEntity>[];
  var buf = _module._malloc(entityCount * 4) as JSNumber;

  _module.ccall(
      "get_entities",
      "void",
      ["void*".toJS, "int".toJS, "bool".toJS, "int*".toJS].toJS,
      [_sceneManager!, parent.toJS, renderableOnly.toJS, buf].toJS,
      null);
  for (int i = 0; i < entityCount; i++) {
    var entityId =
        _module.getValue((buf.toDartInt + (i * 4)).toJS, "i32") as JSNumber;
    entities.add(entityId.toDartInt);
  }
  _module._free(buf);
  return entities;
}