Box3D
Safe HaskellNone
LanguageGHC2021

Box3D.Base

Description

Low-level bindings to box3d/base.h: version info, global allocator / assert / log hooks, and timing helpers.

Synopsis

Version

data Version Source #

Version numbering scheme, see https://semver.org/.

Instances

Instances details
Storable Version Source # 
Instance details

Defined in Box3D.Base

Show Version Source # 
Instance details

Defined in Box3D.Base

Eq Version Source # 
Instance details

Defined in Box3D.Base

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #

getVersion :: IO Version Source #

Get the current version of Box3D.

Allocator

type AllocFcn = Int32 -> Int32 -> IO (Ptr ()) Source #

User allocation function: void* (int32 size, int32 alignment).

type FreeFcn = Ptr () -> IO () Source #

User free function: void (void* mem).

setAllocator :: FunPtr AllocFcn -> FunPtr FreeFcn -> IO () Source #

Override the default allocation functions. Set during application startup.

The FunPtrs must point to C functions: the engine calls the hooks from inside unsafe FFI calls, where re-entering Haskell is undefined behaviour, so wrapping Haskell functions is not supported yet.

getByteCount :: IO Int32 Source #

Total bytes allocated by Box3D.

Assert / log hooks

type AssertFcn = CString -> CString -> CInt -> IO CInt Source #

Assert callback: int (const char* condition, const char* file, int line). Return 0 to skip the debugger break.

type LogFcn = CString -> IO () Source #

Log callback: void (const char* message).

setAssertFcn :: FunPtr AssertFcn -> IO () Source #

Override the default assert callback. Must point to a C function, see setAllocator.

setLogFcn :: FunPtr LogFcn -> IO () Source #

Override the default logging callback. Must point to a C function, see setAllocator.

Timing

getTicks :: IO Word64 Source #

Absolute number of system ticks. The value is platform specific.

getMilliseconds :: Word64 -> IO CFloat Source #

Milliseconds passed from an initial tick value.

getMillisecondsAndReset :: Ptr Word64 -> IO CFloat Source #

Milliseconds passed from an initial tick value, resetting it to now.

yield :: IO () Source #

Yield to be used in a busy loop.

sleep :: CInt -> IO () Source #

Sleep the current thread for a number of milliseconds. Imported as a safe call so the blocked thread releases its capability instead of stalling the RTS for the whole duration.

hash :: Word32 -> Ptr Word8 -> CInt -> IO Word32 Source #

Simple djb2 hash function for determinism testing.