Skip to content

Commit 6726026

Browse files
author
Joe King
committed
Increase precision
1 parent 56d7144 commit 6726026

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

rcast.bas

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include once "SDL2/SDL.bi"
22

33
#define FULLSCREEN 1
4-
#define SCREEN_X 1920'352'1920'352
5-
#define SCREEN_Y 1080'198'1080'198
4+
#define SCREEN_X 352'1920'352
5+
#define SCREEN_Y 198'1080'198
66
#define HALF_X SCREEN_X \ 2
77
#define HALF_Y SCREEN_Y \ 2
88
#define TO_RAD 0.0174532925
@@ -12,9 +12,10 @@
1212
#define MAP_WIDTH 1024
1313
#define MAP_HEIGHT 1024
1414
#define HEIGHT_RATIO 127*(SCREEN_Y/300)
15-
#define PREC (2^11)
16-
#define PREC_SHIFT 11
15+
#define PREC (2^14)
16+
#define PREC_SHIFT 14
1717
#define MAX_DISTANCE 4096*PREC' 300
18+
#define MAX_INT (2^16)
1819

1920
'// TIMER FUNCTIONS ===================================================
2021
declare function UpdateSpeed (save_time as integer=1) as double
@@ -504,18 +505,18 @@ sub main()
504505
dim vr as Vector
505506
dim vray as Vector
506507

507-
dim dx as integer, dy as integer
508+
dim dx as uinteger, dy as uinteger
508509
dim ax as integer, ay as integer
509510
dim ex as integer, ey as integer
510-
dim x_dx as integer, x_dy as integer
511-
dim y_dx as integer, y_dy as integer
511+
dim x_dx as uinteger, x_dy as uinteger
512+
dim y_dx as uinteger, y_dy as uinteger
512513
dim x_ax as integer, x_ay as integer
513514
dim y_ax as integer, y_ay as integer
514-
dim x_ex as integer, x_ey as integer
515-
dim y_ex as integer, y_ey as integer
516-
dim lx as integer, ly as integer
515+
dim x_ex as uinteger, x_ey as uinteger
516+
dim y_ex as uinteger, y_ey as uinteger
517+
dim lx as uinteger, ly as uinteger
517518
dim xHit as integer, yHit as integer
518-
dim xDist as integer, yDist as integer
519+
dim xDist as uinteger, yDist as uinteger
519520
dim dist as integer
520521
dim dc as double
521522
dim sliceSize as single
@@ -850,7 +851,7 @@ sub main()
850851

851852
fx += abs(iif(vray.x > 0, map->w-1-px, -px)/vray.x)
852853

853-
if fx > 524288 then fx = 524288
854+
if fx > MAX_INT then fx = MAX_INT
854855
xDistMax = fx*PREC
855856

856857
if py < 0 or py >= map->h then
@@ -859,7 +860,7 @@ sub main()
859860

860861
fy += abs(iif(vray.y > 0, map->h-1-py, -py)/vray.y)
861862

862-
if fy > 524288 then fy = 524288
863+
if fy > MAX_INT then fy = MAX_INT
863864
yDistMax = fy*PREC
864865

865866
distMax = iif(xDistMax < yDistMax, xDistMax, yDistMax)
@@ -873,13 +874,13 @@ sub main()
873874
fx = iif(vray.x > 0, -px, MAP_WIDTH-px)
874875
end if
875876
fy = vray.y*abs(fx/vray.x)
876-
if fy > 524288 then fy = 524288
877-
if fy < -524288 then fy = -524288
877+
if fy > MAX_INT then fy = MAX_INT
878+
if fy < -MAX_INT then fy = -MAX_INT
878879
ex = iif(vray.x >= 0, 0, -1)
879880
ey = 0
880881

881882
fo = abs(fx/vray.x)
882-
if fo > 524288 then fo = 524288
883+
if fo > MAX_INT then fo = MAX_INT
883884
xDist = fo*PREC
884885

885886
dx = (fx+px)*PREC
@@ -894,13 +895,13 @@ sub main()
894895
fy = iif(vray.y > 0, -py, MAP_HEIGHT-py)
895896
end if
896897
fx = vray.x*abs(fy/vray.y)
897-
if fx > 524288 then fx = 524288
898-
if fx < -524288 then fx = -524288
898+
if fx > MAX_INT then fx = MAX_INT
899+
if fx < -MAX_INT then fx = -MAX_INT
899900
ex = 0
900901
ey = iif(vray.y >= 0, 0, -1)
901902

902903
fo = abs(fy/vray.y)
903-
if fo > 524288 then fo = 524288
904+
if fo > MAX_INT then fo = MAX_INT
904905
yDist = fo*PREC
905906

906907
dy = (fy+py)*PREC

0 commit comments

Comments
 (0)