classicborne
    Preparing search index...

    Class ChangeRecord

    I am a change record for a BaseLevel. I keep an append-only record of block changes and commands, allowing for restoring changes to levels.

    I append actions representing block changes or commands to my record. My changes are buffered and periodically flushed to disk in compressed form. These actions can be restored to a level, replaying the recorded changes. I also support committing actions up to a specific action count, trimming the record.

    Because of my append-only nature, long records can take a while to restore. In case that happens, my keyframeRecord can store periodic snapshots of the level state, allowing for faster restoration by starting from a recent keyframe instead of replaying all changes from the beginning.

    Index

    Constructors

    • Creates a new ChangeRecord instance.

      Parameters

      • path: string

        The path to the change record file.

      • loadedCallback: Function = ...

        The callback function to call when file handles are opened.

      • options: { useKeyframeRecord?: boolean } = {}

        Options for the change record.

        • OptionaluseKeyframeRecord?: boolean

          Whether to use a keyframe record for snapshots. Default is true

      Returns ChangeRecord

    Properties

    actionCount: number
    bounds: Vector3
    currentActionCount: number
    currentBuffer: SmartBuffer
    dirty: boolean
    draining: boolean
    keyframeRecord: KeyframeRecord
    path: string
    vhsFh: FileHandle

    The handle for the vhs.bin file.

    lagKeyframeTime: number = 250

    The keyframe creation threshold in milliseconds. ChangeRecord.restoreBlockChangesToLevel uses this by checking how much time has passed when restoring from changes alone.

    Methods

    • Appends a block change to the change record.

      Parameters

      • position: Vector3

        The position of the block change.

      • block: number

        The block type.

      Returns void

    • Append an action to the change record.

      Parameters

      • isCommand: boolean = false

        Whether the action is a command.

      • actionBytes: number[]

        The action bytes to append.

      • OptionalcommandString: string

        The command string (if applicable).

      Returns void

    • Trims the VHS file to the specified action count, discarding any actions beyond that count.

      Parameters

      • toActionCount: number

        The action count to trim to.

      • level: any

      Returns Promise<number>

    • Flush changes to disk by compressing current buffer and append it to the VHS file.

      Returns Promise<number>

      The length of the flushed buffer.

    • Restore block changes to a level.

      Parameters

      • level: BaseLevel<any>

        The level to restore changes to.

      • OptionalmaxActions: number

        The maximum number of actions to restore.

      • Optionalstaller: Function

        The function to call to stall the restore process. Also prevents creating keyframes if defined.

      Returns Promise<number>

      The total number of actions restored.