MCPcopy Create free account
hub / github.com/crownengine/crown / write

Method write

src/resource/state_machine_resource.cpp:401–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399 }
400
401 s32 write()
402 {
403 StateMachineResource smr;
404 smr.version = RESOURCE_HEADER(RESOURCE_VERSION_STATE_MACHINE);
405 smr.initial_state_offset = hash_map::get(_offsets, _initial_state, UINT32_MAX);
406 smr.num_variables = vector::size(_variables);
407 smr.variables_offset = _offset_accumulator._offset; // Offset of last state + 1
408 smr.bytecode_size = array::size(_byte_code)*4;
409 smr.bytecode_offset = smr.variables_offset + smr.num_variables*4*2;
410 smr.animation_type = StringId64(_animation_type.c_str());
411 smr.skeleton_name = _skeleton_name;
412 _opts.write(smr.version);
413 _opts.write(smr.initial_state_offset);
414 _opts.write(smr.num_variables);
415 _opts.write(smr.variables_offset);
416 _opts.write(smr.bytecode_size);
417 _opts.write(smr.bytecode_offset);
418 _opts.write(smr.animation_type);
419 _opts.write(smr.skeleton_name);
420
421 // Write states
422 auto cur = hash_map::begin(_states);
423 auto end = hash_map::end(_states);
424 for (; cur != end; ++cur) {
425 HASH_MAP_SKIP_HOLE(_states, cur);
426
427 const StateInfo &si = cur->second;
428 const u32 num_animations = vector::size(si.animations);
429 const u32 num_transitions = vector::size(si.transitions);
430
431 // Write speed
432 _opts.write(si.speed_bytecode);
433
434 // Write loop
435 _opts.write(si.loop);
436
437 // Write transitions
438 TransitionArray ta;
439 ta.num = num_transitions;
440 _opts.write(ta.num);
441 for (u32 i = 0; i < num_transitions; ++i) {
442 Transition t = si.transitions[i].transition;
443 t.state_offset = hash_map::get(_offsets, si.transitions[i].state, UINT32_MAX);
444
445 _opts.write(t.event);
446 _opts.write(t.state_offset);
447 _opts.write(t.mode);
448 }
449
450 // Write animations
451 AnimationArray aa;
452 aa.num = num_animations;
453 _opts.write(aa.num);
454 for (u32 i = 0; i < num_animations; ++i) {
455 Animation a;
456 a.name = si.animations[i].name;
457 a.bytecode_entry = si.animations[i].bytecode_entry;
458 a.pad = 0;

Callers 1

compileFunction · 0.45

Calls 6

getFunction · 0.85
sizeFunction · 0.50
StringId64Class · 0.50
beginFunction · 0.50
endFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected