| 328 | } |
| 329 | |
| 330 | void World::update_scene(f32 dt) |
| 331 | { |
| 332 | // Process animation events |
| 333 | { |
| 334 | EventStream &events = _animation_state_machine->_events; |
| 335 | const u32 size = array::size(events); |
| 336 | u32 read = 0; |
| 337 | while (read < size) { |
| 338 | const EventHeader *eh = (EventHeader *)&events[read]; |
| 339 | const char *data = (char *)&eh[1]; |
| 340 | |
| 341 | read += sizeof(*eh) + eh->size; |
| 342 | |
| 343 | switch (eh->type) { |
| 344 | case 0: { |
| 345 | const SpriteFrameChangeEvent &ptev = *(SpriteFrameChangeEvent *)data; |
| 346 | const SpriteId si = _render_world->sprite_instance(ptev.unit); |
| 347 | _render_world->sprite_set_frame(si, ptev.frame_num); |
| 348 | break; |
| 349 | } |
| 350 | |
| 351 | default: |
| 352 | CE_FATAL("Unknown event type"); |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | array::clear(events); |
| 357 | } |
| 358 | |
| 359 | _scene_graph->get_changed(_changed_units, _changed_world); |
| 360 | |
| 361 | _physics_world->update_actor_world_poses(array::begin(_changed_units) |
| 362 | , array::end(_changed_units) |
| 363 | , array::begin(_changed_world) |
| 364 | ); |
| 365 | |
| 366 | _physics_world->update(dt); |
| 367 | |
| 368 | // Process physics transform events. |
| 369 | { |
| 370 | EventStream &events = _physics_world->events(); |
| 371 | const u32 size = array::size(events); |
| 372 | u32 read = 0; |
| 373 | while (read < size) { |
| 374 | const EventHeader *eh = (EventHeader *)&events[read]; |
| 375 | const char *data = (char *)&eh[1]; |
| 376 | |
| 377 | read += sizeof(*eh) + eh->size; |
| 378 | |
| 379 | switch (eh->type) { |
| 380 | case EventType::PHYSICS_TRANSFORM: { |
| 381 | const PhysicsTransformEvent &ptev = *(PhysicsTransformEvent *)data; |
| 382 | const TransformId ti = _scene_graph->instance(ptev.unit_id); |
| 383 | if (is_valid(ti)) // User code may have destroyed the actor |
| 384 | _scene_graph->set_world_pose_and_rescale(ti, ptev.world); |
| 385 | break; |
| 386 | } |
| 387 |
no test coverage detected