UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

183 lines 5.63 kB
/** * Compact binary table storage. * Very efficient in terms of memory usage and allocation. * Read and write speeds are optimized through code generation. * You can think of it as an SQL table but only for numeric types. * * @copyright Company Named Limited (c) 2025 * @author Alex Goldring */ export class RowFirstTable { /** * * @param {RowFirstTableSpec} spec what does the schema look like? How many columns do we have and what are their types? * @param {boolean} [shared_array] should we use SharedArrayBuffer instead of ArrayBuffer? * @constructor */ constructor(spec: RowFirstTableSpec, shared_array?: boolean); /** * * @type {RowFirstTableSpec} */ spec: RowFirstTableSpec; /** * * @type {ArrayBuffer} */ data: ArrayBuffer; /** * number of records * @type {number} */ length: number; /** * capacity in number of records * @type {number} */ capacity: number; /** * * @type {DataView} */ dataView: DataView; /** * * @type {{added: Signal}} */ on: { added: Signal; }; /** * Useful for deserialization. * This is an unsafe method, avoid using it if you are not sure. * NOTE: capacity is set automatically * NOTE: length is not set automatically, you have to do that yourself * @param {ArrayBuffer|SharedArrayBuffer} buffer */ set array_buffer(arg: ArrayBuffer | SharedArrayBuffer); /** * * @returns {number} */ hash(): number; /** * * @param {number} rowCount */ setCapacity(rowCount: number): void; /** * Drop excess capacity, setting capacity exactly to the current length */ trim(): void; /** * * @param {number} row_count */ resize(row_count: number): void; /** * * @param {number} row_index * @param {number} column_index * @param {number} value */ writeCellValue(row_index: number, column_index: number, value: number): void; /** * read a single cell value from the table * @param {number} row_index * @param {number} column_index * @returns {number} */ readCellValue(row_index: number, column_index: number): number; /** * Remove rows from the table * @param {number} index starting row * @param {number} row_count number of rows to be removed */ removeRows(index: number, row_count: number): void; /** * Insert a number of blank rows at the given offset * Table becomes larger as a result * NOTE: doesn't send {@link on.added} signal * @param {number} index * @param {number} row_count */ insertRows(index: number, row_count: number): void; /** * Created a new row at the end of the table, does not dispatch {@link on.added} signal * Values are undefined, typically it will be 0s, but if data was previously written in that memory region - that data will be retained. * Make sure to clear the row or write to it before reading it * @return {number} index of the created row */ createEmptyRow(): number; /** * * @param {Array.<number>} values * @returns {number} index of newly added row */ addRow(values: Array<number>): number; /** * @deprecated Use {@link addRow} and {@link writeRow} instead * @param {number} count number of rows to be added * @param {function(row_index:number, row:Array.<number>):*} valueSupplier supplier of row values, called with row index and an empty row to be filled */ addRows(count: number, valueSupplier: any): void; /** * Copy a single row, value in the source row is unaffected * @param {number} source * @param {number} target */ copyRow(source: number, target: number): void; /** * Read a single row of values from the table * @param {number} index * @param {number[]} [result] where row values are to be stored * @returns {number[]} result */ readRow(index: number, result?: number[]): number[]; /** * Write a single row of values * @param {number} index * @param {number[]} record */ writeRow(index: number, record: number[]): void; /** * Sets memory region of the row to 0s. * Useful for initializing dirty rows for re-use. * If you have a specific value in mind - use {@link writeRow} method instead * NOTE: All numeric types will produce a 0 after this, so every cell of this row will be 0 * @param {number} index */ clearRow(index: number): void; /** * Reverse order of rows, row-0 will end up at and previously last row will become the first row etc. */ reverse_rows(): void; /** * clear out all the data and free memory */ clear(): void; /** * Utility method. Returns table contents as a 2d array of [row][cell] form. * Primarily useful for data conversion and debugging. * @returns {number[][]} */ toRowArray(): number[][]; /** * Print the table to console. * Useful for debugging. */ printToConsole(): void; /** * Copy data from another table. Specs must match. * NOTE: does not dispatch {@link onAdded} signal * @param {RowFirstTable} other */ copy(other: RowFirstTable): void; /** * @param {RowFirstTable} other * @returns {boolean} */ equals(other: RowFirstTable): boolean; } import Signal from "../../events/signal/Signal.js"; //# sourceMappingURL=RowFirstTable.d.ts.map