maze-project
Show / Hide Table of Contents

Class MazeWasmInterop

This class provides C# interop to the maze_wasm web assembly, insulating the calling application from the specifics of the underlying Web Assembly interop operations.

Developers can use NewMazeWasm() to create a pointer to a maze object within Web Assembly and then other MazeWasm functions, such as MazeWasmInsertRows() and MazeWasmSolve(), to interact with the maze.

Once finished with, a maze should be destroyed using FreeMazeWasm() to prevent memory leaks within Web Assembly.

Inheritance
object
MazeWasmInterop
Implements
IDisposable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Maze.Wasm.Interop
Assembly: Maze.Wasm.Interop.dll
Syntax
public class MazeWasmInterop : IDisposable

Methods

AllocateSizedMemory(uint)

Allocates a sized memory block of a given size. A sized memory block is a block of memory of (size + 4) bytes, where the first 4 bytes contain the size of the block (u32) and then the next size bytes is reserved for data use.

Declaration
public uint AllocateSizedMemory(uint size)
Parameters
Type Name Description
uint size

Number of bytes to allocate

Returns
Type Description
uint

Pointer to memory

Disconnect()

Disconnects the WebAssembly connector

Declaration
public static void Disconnect()

Dispose()

Handles object disposal, releasing managed and unmanaged resources and marking the object as having been finalized

Declaration
public void Dispose()

Dispose(bool)

Handles object disposal

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

Flag indicating whether the object should be fully disposed (ie. including managed as well as unmanaged resources)

~MazeWasmInterop()

Handles object finalization (deletion)

Declaration
protected ~MazeWasmInterop()

FreeMazeWasm(uint)

Frees a MazeWasm pointer

Declaration
public void FreeMazeWasm(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to MazeWasm

FreeMazeWasmSolution(uint)

Frees a maze solution pointer

Declaration
public void FreeMazeWasmSolution(uint solutionPtr)
Parameters
Type Name Description
uint solutionPtr

Pointer to solution

FreeSizedMemory(uint)

Frees the sized memory associated with a given pointer

Declaration
public void FreeSizedMemory(uint ptr)
Parameters
Type Name Description
uint ptr

Pointer to memory

GetInstance(ConnectionType, bool, byte[]?)

Returns the instance for the interop (creating if needed)

Declaration
public static MazeWasmInterop GetInstance(MazeWasmInterop.ConnectionType connectionType = ConnectionType.Wasmtime, bool createNew = false, byte[]? wasmBytes = null)
Parameters
Type Name Description
MazeWasmInterop.ConnectionType connectionType

Type of WebAssembly connection technology to use

bool createNew

Create a new instance even if a global one already exists

byte[] wasmBytes

WebAssembly bytes. If this is null then at attempt is made to load the WebAssembly from the default location.(

Returns
Type Description
MazeWasmInterop

Interop instance

GetNumObjectsAllocated()

Gets the number of objects currenty allocated

Declaration
public long GetNumObjectsAllocated()
Returns
Type Description
long

Object count

GetSizedMemoryUsed()

Gets the amount of sized memory currenty allocated

Declaration
public long GetSizedMemoryUsed()
Returns
Type Description
long

Memory used count

GetWasmPath()

Returns the path to the maze_wasm Web Assembly

Declaration
public static string GetWasmPath()
Returns
Type Description
string

Web Assembly path

Initialize(ConnectionType, bool, byte[]?)

Initializes the interop instance if needed

Declaration
public static void Initialize(MazeWasmInterop.ConnectionType connectionType = ConnectionType.Wasmtime, bool createNew = false, byte[]? wasmBytes = null)
Parameters
Type Name Description
MazeWasmInterop.ConnectionType connectionType

Type of WebAssembly connection technology to use

bool createNew

Create a new instance, even if a global one already exists (overwriting existing)

byte[] wasmBytes

WebAssembly bytes. If this is null then at attempt is made to load the WebAssembly from the default location.(

MazeWasmClearCells(uint, uint, uint, uint, uint)

Clears a range of wall cells within a MazeWasm, or will throw an exception if the cells cannot be cleared

Declaration
public void MazeWasmClearCells(uint mazeWasmPtr, uint startRow, uint startCol, uint endRow, uint endCol)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startRow

Target start row

uint startCol

Target start column

uint endRow

Target end row

uint endCol

Target end column

MazeWasmDeleteCols(uint, uint, uint)

Deletes columns from a MazeWasm, or will throw an exception if the columns cannot be deleted

Declaration
public void MazeWasmDeleteCols(uint mazeWasmPtr, uint startCol, uint count)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startCol

Target start column

uint count

Number columns to delete

MazeWasmDeleteRows(uint, uint, uint)

Deletes rows from a MazeWasm, or will throw an exception if the rows cannot be deleted

Declaration
public void MazeWasmDeleteRows(uint mazeWasmPtr, uint startRow, uint count)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startRow

Target start row

uint count

Number rows to delete

MazeWasmFromJson(uint, string)

Reinitialises a MazeWasm from a JSON string, or will throw an exception if the operation fails

Declaration
public void MazeWasmFromJson(uint mazeWasmPtr, string json)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

string json

JSON strimg

MazeWasmGetCellType(uint, uint, uint)

Gets the cell type associated with a cell within a MazeWasm, or will throw an exception if the cell type cannot be determined

Declaration
public MazeWasmInterop.MazeWasmCellType MazeWasmGetCellType(uint mazeWasmPtr, uint row, uint col)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint row

Target row

uint col

Target column

Returns
Type Description
MazeWasmInterop.MazeWasmCellType

Cell type

MazeWasmGetColCount(uint)

Gets the column count associated with a MazeWasm

Declaration
public uint MazeWasmGetColCount(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
uint

Column count

MazeWasmGetFinishCell(uint)

Gets the finish cell associated with a MazeWasm, or will throw an exception if the finish cell cannot be retrieved

Declaration
public MazeWasmInterop.MazeWasmPoint MazeWasmGetFinishCell(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
MazeWasmInterop.MazeWasmPoint

Finish cell point

MazeWasmGetRowCount(uint)

Gets the row count associated with a MazeWasm

Declaration
public uint MazeWasmGetRowCount(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
uint

Row count

MazeWasmGetStartCell(uint)

Gets the start cell associated with a MazeWasm, or will throw an exception if the start cell cannot be retrieved

Declaration
public MazeWasmInterop.MazeWasmPoint MazeWasmGetStartCell(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
MazeWasmInterop.MazeWasmPoint

Start cell point

MazeWasmInsertCols(uint, uint, uint)

Inserts columns into a MazeWasm, or will throw an exception if the columns cannot be inserted

Declaration
public void MazeWasmInsertCols(uint mazeWasmPtr, uint startCol, uint count)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startCol

Target start column

uint count

Number columns to insert

MazeWasmInsertRows(uint, uint, uint)

Inserts rows into a MazeWasm, or will throw an exception if the rows cannot be inserted

Declaration
public void MazeWasmInsertRows(uint mazeWasmPtr, uint startRow, uint count)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startRow

Target start row

uint count

Number rows to insert

MazeWasmIsEmpty(uint)

Tests whether a MazeWasm is empty

Declaration
public bool MazeWasmIsEmpty(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
bool

Boolean

MazeWasmReset(uint)

Resets a MazeWasm to empty

Declaration
public void MazeWasmReset(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

MazeWasmResize(uint, uint, uint)

Resizes a MazeWasm

Declaration
public void MazeWasmResize(uint mazeWasmPtr, uint newRowCount, uint newColCount)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint newRowCount

New number of rows

uint newColCount

New number of columns

MazeWasmSetFinishCell(uint, uint, uint)

Sets the finish cell associated with a MazeWasm, or will throw an exception if the finish cell cannot be set

Declaration
public void MazeWasmSetFinishCell(uint mazeWasmPtr, uint finishRow, uint finishCol)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint finishRow

New finish cell row

uint finishCol

New finsh cell column

MazeWasmSetStartCell(uint, uint, uint)

Sets the start cell associated with a MazeWasm, or will throw an exception if the start cell cannot be set

Declaration
public void MazeWasmSetStartCell(uint mazeWasmPtr, uint startRow, uint startCol)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startRow

New start cell row

uint startCol

New start cell column

MazeWasmSetWallCells(uint, uint, uint, uint, uint)

Sets a range of cells to walls within a MazeWasm, or will throw an exception if the walls cannot be set

Declaration
public void MazeWasmSetWallCells(uint mazeWasmPtr, uint startRow, uint startCol, uint endRow, uint endCol)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

uint startRow

Target start row

uint startCol

Target start column

uint endRow

Target end row

uint endCol

Target end column

MazeWasmSolutionGetPathPoints(uint)

Returns the list of points associated with a solution's path, or will throw an exception if the operation fails

Declaration
public List<MazeWasmInterop.MazeWasmPoint> MazeWasmSolutionGetPathPoints(uint solutionPtr)
Parameters
Type Name Description
uint solutionPtr

Pointer to solution

Returns
Type Description
List<MazeWasmInterop.MazeWasmPoint>

List of points

MazeWasmSolve(uint)

Solves a maze, else will throw an exception if the operation fails.

If successful, use MazeWasmSolutionGetPathPoints() to obtain the solution path.

Declaration
public uint MazeWasmSolve(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
uint

Solution pointer, which should later be freed by calling FreeMazeWasmSolution()

MazeWasmToJson(uint)

Converts a MazeWasm to a JSON string, or will throw an exception if the operation fails

Declaration
public string MazeWasmToJson(uint mazeWasmPtr)
Parameters
Type Name Description
uint mazeWasmPtr

Pointer to maze

Returns
Type Description
string

JSON string

NewMazeWasm()

Creates a new, empty MazeWasm, or will throw an exception if the operation fails

Declaration
public uint NewMazeWasm()
Returns
Type Description
uint

Pointer to the MazeWasm, which should later be freed by calling FreeMazeWasm()

Implements

IDisposable
In this article
Back to top Generated by DocFX