minor efficiency refactors
@@ -6,8 +6,9 @@ ENGINE_record(void* ptr) {
engine->record.gifPixels = (uint32_t*)malloc(imageSize*4*sizeof(uint8_t));
size_t scale = GIF_SCALE;
uint32_t* scaledPixels = (uint32_t*)malloc(imageSize*4*sizeof(uint8_t)* scale * scale);
+ CANVAS canvas = engine->canvas;
- jo_gif_t gif = jo_gif_start(engine->record.gifName, engine->canvas.width * scale, engine->canvas.height * scale, 0, 31);
+ jo_gif_t gif = jo_gif_start(engine->record.gifName, canvas.width * scale, canvas.height * scale, 0, 31);
uint8_t FPS = 30;
double MS_PER_FRAME = ceil(1000.0 / FPS);
double lag = 0;
@@ -29,12 +30,12 @@ ENGINE_record(void* ptr) {
lag += elapsed;
if (lag >= MS_PER_FRAME) {
if (scale > 1) {
- for (size_t j = 0; j < engine->canvas.height * scale; j++) {
- for (size_t i = 0; i < engine->canvas.width * scale; i++) {
+ for (size_t j = 0; j < canvas.height * scale; j++) {
+ for (size_t i = 0; i < canvas.width * scale; i++) {
size_t u = i / scale;
size_t v = j / scale;
- int32_t c = ((uint32_t*)engine->record.gifPixels)[v * engine->canvas.width + u];
- scaledPixels[j * engine->canvas.width * scale + i] = c;
+ int32_t c = ((uint32_t*)engine->record.gifPixels)[v * canvas.width + u];
+ scaledPixels[j * canvas.width * scale + i] = c;
}
}
jo_gif_frame(&gif, (uint8_t*)scaledPixels, 4, true);
@@ -1004,7 +1005,8 @@ ENGINE_canvasResize(ENGINE* engine, uint32_t newWidth, uint32_t newHeight, uint3
internal void
ENGINE_takeScreenshot(ENGINE* engine) {
- stbi_write_png("screenshot.png", engine->canvas.width, engine->canvas.height, 4, engine->canvas.pixels, engine->canvas.width * 4);
+ CANVAS canvas = engine->canvas;
+ stbi_write_png("screenshot.png", canvas.width, canvas.height, 4, canvas.pixels, canvas.width * 4);
}
