public async Task LoadAnims() { // Read anims.bin Reader reader = files_array[SMem.Anims].reader; loadingState = "Loading animations"; await WaitIfNecessary(); uint num_anims = reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); Pointer eof = null; romAnims = new ROMAnimation[num_anims]; for (uint i = 0; i < num_anims; i++) { uint offset = reader.ReadUInt32(); romAnims[i] = new ROMAnimation() { compressed = (offset & 0x80000000) == 0x80000000, index = i }; romAnims[i].Init(new Pointer(offset & 0x7FFFFFFF, files_array[SMem.Anims])); if (i > 0) { romAnims[i - 1].compressedSize = romAnims[i].Offset.offset - romAnims[i - 1].Offset.offset; } } eof = new Pointer(reader.ReadUInt32(), files_array[SMem.Anims]); // EOF if (num_anims > 0) { romAnims[num_anims - 1].compressedSize = eof.offset - romAnims[num_anims - 1].Offset.offset; } for (uint i = 0; i < num_anims; i++) { romAnims[i].Read(reader); } // Read shAnims.bin reader = files_array[SMem.ShAnims].reader; List <ROMShAnimation> shAnimsList = new List <ROMShAnimation>(); while (reader.BaseStream.Position < reader.BaseStream.Length) { ROMShAnimation shAnim = new ROMShAnimation(); shAnim.Init(Pointer.Current(reader)); shAnim.Read(reader, true); shAnimsList.Add(shAnim); } shAnims = shAnimsList.ToArray(); // Read cuttable.bin reader = files_array[SMem.CutTable].reader; cutTable = new ROMAnimationCutTable(); cutTable.Init(Pointer.Current(reader)); cutTable.length = (ushort)num_anims; cutTable.Read(reader, true); }
void LoadNewAnimation(ushort shAnimIndex) { if (shAnimIndex != currentShAnim || forceAnimUpdate) { forceAnimUpdate = false; currentShAnim = shAnimIndex; DeinitAnimation(); currentFrame = 0; shAnim = null; animCuts = null; if (shAnimIndex != 0xFFFF) { shAnim = ROMStruct.Loader.shAnims[shAnimIndex]; animationSpeed = shAnim.speed; animCuts = ROMStruct.Loader.cutTable.GetAnimationChain(shAnimIndex); //print(animCuts.Length); forceAnimUpdate = true; SwitchAnimationCut(0); } } }
// Update is called once per frame void Update() { if (IsLoaded) { if (hasStates) { if (stateIndex != currentState) { currentState = stateIndex; SetState(currentState); } } MapLoader l = MapLoader.Loader; if (poListIndex != currentPOList && perso.p3dData != null) { if (poListIndex > 0 && poListIndex < poListNames.Length + 1) { currentPOList = poListIndex; ObjectsTable newOT = ROMStruct.Loader.objectsTables[currentPOList - 1]; perso.p3dData.Value.objectsTable = new Reference <ObjectsTable>(newOT.Index, newOT); } else { poListIndex = 0; currentPOList = 0; perso.p3dData.Value.objectsTable = new Reference <ObjectsTable>(); } forceAnimUpdate = true; SetState(currentState); } } if (!IsLoaded || !(controller.LoadState == Controller.State.Finished || controller.LoadState == Controller.State.Error)) { return; } bool sectorActive = false, insideSectors = false; if (sector == null || IsAlways || AlwaysPlayAnimation || sector.Loaded) { sectorActive = true; } if (sector == null || IsAlways || AlwaysPlayAnimation || controller.sectorManager.activeSector != null) { insideSectors = true; } if (controller.playAnimations && playAnimation && sectorActive) { updateCounter += Time.deltaTime * animationSpeed; // If the camera is not inside a sector, animations will only update 1 out of 2 times (w/ frameskip) to avoid lag if ((!insideSectors && updateCounter >= 2f) || (insideSectors && updateCounter >= 1f)) { uint passedFrames = (uint)Mathf.FloorToInt(updateCounter); updateCounter %= 1; currentFrame += passedFrames; if (shAnim != null && currentFrame >= shAnim.num_frames) { if (autoNextState) { ROMShAnimation prevshAnim = shAnim; GotoAutoNextState(); if (shAnim == prevshAnim) { currentFrame = currentFrame % shAnim.num_frames; UpdateAnimation(); } } else { currentFrame = currentFrame % shAnim.num_frames; UpdateAnimation(); } } else { UpdateAnimation(); } } } }