GAMELEGEND 2023-11-15 20:08 (Edited)
I found this website for making a raycast program and then later found it in the file for the raycaster made by nathanielbabiak. https://lodev.org/cgtutor/raycasting.html
So, I made a version for Lowres NX that uses the 8 x 8 pixel cells to draw. I saved some cycles here and there and then a lot by making it not draw lines when the player is not moving, but I was wondering if I could increase the performance even more.
nathanielbabiak 2023-11-16 12:47
I'll take a look... Just been so busy lately!
Might be a few days
nathanielbabiak 2023-11-19 20:40 (Edited)
I checked out Raycast v2.nx, found a few things you can do differently...
Save 5% CPU. Your main code writes the background cells twice to draw each frame: once with CLS and then a second time with DRAW_LINE. Remove CLS from the code entirely, and revise DRAW_LINE to clear the vertical strip of cells above and below the line being drawn.
Save 1% CPU. The DDA loop (that is, the one that begins with WHILE WALL_HIT = 0) can be reduced by 2 clock cycles per step. The statement SIDE = 1 uses 3 clock cycles. The statement RESTORE LABEL1 uses 1. After the DDA loop, you'd use READ SIDE.
Save 2% CPU. The ray's X and Y components are calculated at the beginning of each cell column loop. You could calculate those values (for the initial ray) before entering the loop, then inside the loop you'd just increment with an ADD instruction. Before entering the loop, you'd also need to pre-calculate the increment amount.
Run faster. The main loop uses WAIT VBL at the end of the loop, but for raycasting on this fantasy console you might want to implement your own timing. There's a bunch of ways to do this. Try using WAIT VBL only when waiting for input. But when there is input, don't wait.
GAMELEGEND 2023-11-19 21:25 (Edited)
I also realized that I can get rid of SIDE in
CALL DRAW_LINE(X, DRAW_START, DRAW_END, SIDE)
because SIDE is a global variable