From b063e5606e179569b3a9715c3e9e4d38b0ee3bc6 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Tue, 10 Jan 2023 10:09:20 +0100 Subject: [PATCH] Optimization: Do not reinitialize pixel array at every line draw --- v2/raycaster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2/raycaster.py b/v2/raycaster.py index faacfd6..7946ab2 100755 --- a/v2/raycaster.py +++ b/v2/raycaster.py @@ -107,6 +107,7 @@ class Main: self.raycastWindow = sdl2.ext.Window("3D View", size=(RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT)) self.raycastWindow.show() self.raycastSurface = self.raycastWindow.get_surface() + self.raycast_u32_pixels = ctypes.cast(self.raycastSurface.pixels, ctypes.POINTER(ctypes.c_uint32)) # Raw SDL surface pixel array # Player self.player_position = PLAYER_SPAWN_POSITION @@ -379,10 +380,9 @@ class Main: self.drawVline(self.raycastSurface, color, x, int(lineStart), int(lineEnd)) def drawVline(self, surface, color, x, startY, endY): - u32_pixels = ctypes.cast(self.raycastSurface.pixels, ctypes.POINTER(ctypes.c_uint32)); startIdx = startY * RAYCAST_WIN_WIDTH + x for idx in range(startIdx, endY * RAYCAST_WIN_WIDTH + x, RAYCAST_WIN_WIDTH): - u32_pixels[idx] = color + self.raycast_u32_pixels[idx] = color def dist(self, ax, ay, bx, by):