]> git.bts.cx Git - benzene.git/commitdiff
Updates for bindings
authorBen Sherratt <redacted>
Tue, 31 Dec 2024 16:44:50 +0000 (16:44 +0000)
committerBen Sherratt <redacted>
Tue, 31 Dec 2024 16:44:50 +0000 (16:44 +0000)
src/bz/gfx/aseprite.c
src/bz/math/random.c
src/bz/math/random.h
src/bz/scripting/bindings.cpp
third_party/sun

index b2a829ff0bdbf442333ed4bd96186bf1b2f51058..2581206f0790bec8c768db3e24bf9db449083f29 100644 (file)
@@ -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);
                                        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;
                                        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) {
                                        stbi_zlib_decode_buffer(imagePixelData, imagePixelDataSize, compressedData, compressedSize);
 
                                        for (size_t y = 0; y < image.pixelHeight; ++y) {
index 30f6e6c5538207b8b18eb1f2d31dc6e40fbfe6f8..368d2695f1ded56f5954c5d4cb2585b62af4ebd7 100644 (file)
@@ -41,3 +41,7 @@ void *bzRandomArrayValue(size_t count, size_t arrayTypeSize, void *array) {
        uint32_t idx = bzRandomInteger(count);
        return array + idx * arrayTypeSize;
 }
        uint32_t idx = bzRandomInteger(count);
        return array + idx * arrayTypeSize;
 }
+
+void bzRandomReseed(uint64_t seed) {
+       pcg32_srandom(seed, 1);
+}
index 4a3df98e092c84fc6f084af2000977146b78d993..e96f597b1d2afdf15055e18042b0293c7f5408d4 100644 (file)
@@ -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 *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
 #define bzRandom(T, ...) (*((T *)bzRandomArrayValue(sizeof((T[]){__VA_ARGS__})/sizeof(T), sizeof(T), (T[]){__VA_ARGS__})))
 
 #ifdef __cplusplus
index 2a88b12d02946fb65924466380ef87b8f93c44f6..06ede90243861c02748e20ef124be835d406538d 100644 (file)
@@ -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[]) {
 _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(ceil)
                FUNCTION_BIND(adelta)
                FUNCTION_BIND(rnd)
+               FUNCTION_BIND(srand)
                FUNCTION_BIND(lerp)
                FUNCTION_BIND(dot)
 
                FUNCTION_BIND(lerp)
                FUNCTION_BIND(dot)
 
index a5b6b9ea53d78b2019201a9fb75b763b7d92873c..b4bfa0d90e747a0f6f3080246823471423a30951 160000 (submodule)
@@ -1 +1 @@
-Subproject commit a5b6b9ea53d78b2019201a9fb75b763b7d92873c
+Subproject commit b4bfa0d90e747a0f6f3080246823471423a30951