From: Ben Sherratt Date: Tue, 31 Dec 2024 16:44:50 +0000 (+0000) Subject: Updates for bindings X-Git-Url: https://git.bts.cx/benzene.git/commitdiff_plain/76064b2ae48e49da4341490dd00f8977ea540fd8?ds=sidebyside Updates for bindings --- diff --git a/src/bz/gfx/aseprite.c b/src/bz/gfx/aseprite.c index b2a829f..2581206 100644 --- a/src/bz/gfx/aseprite.c +++ b/src/bz/gfx/aseprite.c @@ -405,11 +405,11 @@ static void renderChunkCel(uint8_t *outData, ASE_SHORT *zBuffer, BZMemoryArenaID bzResourcesReadBytes(handle, &image, sizeof(image)); size_t compressedSize = chunk.chunkSize - sizeof(ASE_Chunk_Cel_CompressedImage) - sizeof(ASE_Chunk_Cel) - sizeof(ASE_Chunk); - int8_t *compressedData = bzMemoryAlloc(arena, compressedSize); // If we do this on the stack (alloca) the Playdate will explode! + uint8_t *compressedData = bzMemoryAlloc(arena, compressedSize); // If we do this on the stack (alloca) the Playdate will explode! bzResourcesReadBytes(handle, compressedData, compressedSize); size_t imagePixelDataSize = image.pixelWidth * image.pixelHeight * pixelDataSize; - int8_t *imagePixelData = bzMemoryAlloc(arena, imagePixelDataSize); + uint8_t *imagePixelData = bzMemoryAlloc(arena, imagePixelDataSize); stbi_zlib_decode_buffer(imagePixelData, imagePixelDataSize, compressedData, compressedSize); for (size_t y = 0; y < image.pixelHeight; ++y) { diff --git a/src/bz/math/random.c b/src/bz/math/random.c index 30f6e6c..368d269 100644 --- a/src/bz/math/random.c +++ b/src/bz/math/random.c @@ -41,3 +41,7 @@ void *bzRandomArrayValue(size_t count, size_t arrayTypeSize, void *array) { uint32_t idx = bzRandomInteger(count); return array + idx * arrayTypeSize; } + +void bzRandomReseed(uint64_t seed) { + pcg32_srandom(seed, 1); +} diff --git a/src/bz/math/random.h b/src/bz/math/random.h index 4a3df98..e96f597 100644 --- a/src/bz/math/random.h +++ b/src/bz/math/random.h @@ -14,6 +14,8 @@ extern int32_t bzRandomIntegerRange(int32_t v1, int32_t v2); extern void *bzRandomArrayValue(size_t count, size_t arrayTypeSize, void *array); //extern void *bzRandomArrayValue(pcg32_random_t *rng, size_t count, size_t arrayTypeSize, void *array); +extern void bzRandomReseed(uint64_t seed); + #define bzRandom(T, ...) (*((T *)bzRandomArrayValue(sizeof((T[]){__VA_ARGS__})/sizeof(T), sizeof(T), (T[]){__VA_ARGS__}))) #ifdef __cplusplus diff --git a/src/bz/scripting/bindings.cpp b/src/bz/scripting/bindings.cpp index 2a88b12..06ede90 100644 --- a/src/bz/scripting/bindings.cpp +++ b/src/bz/scripting/bindings.cpp @@ -112,6 +112,8 @@ static void native_rnd(SVMModuleInstance *instance, int32_t parameterCount, SVMO } } +_FUNCTION_BINDING(srand, bzRandomReseed, _INT_PARAMETER(1)) + _FUNCTION_BINDING_RTN(lerp, fixedLerp, _FUNCTION_PARAMETER(1, float), _FUNCTION_PARAMETER(2, float), _FUNCTION_PARAMETER(3, float)) static void native_dot(SVMModuleInstance *instance, int32_t parameterCount, SVMOperand stack[]) { @@ -676,6 +678,7 @@ SVMFunctionCallback bzScriptingBindingsLookupNativeFunction(uint32_t nameCRC, vo FUNCTION_BIND(ceil) FUNCTION_BIND(adelta) FUNCTION_BIND(rnd) + FUNCTION_BIND(srand) FUNCTION_BIND(lerp) FUNCTION_BIND(dot) diff --git a/third_party/sun b/third_party/sun index a5b6b9e..b4bfa0d 160000 --- a/third_party/sun +++ b/third_party/sun @@ -1 +1 @@ -Subproject commit a5b6b9ea53d78b2019201a9fb75b763b7d92873c +Subproject commit b4bfa0d90e747a0f6f3080246823471423a30951