04-13-2003, 12:35 AM
Hey, I decided to join this place after some nudging from Mofu, so... I guess I'll start out with a question.
How can I optimize this floormapping code to be realllly reallllllly fast, like pasco's floormapper?
Note: I tried to make this pure qb, but I wouldn't let me blit the buffer to the screen with PUT, so I had to use gslib's pcopy.
::EDIT::
Ok, I fixed it, code updated.
::EDIT 2::
Lithium gave me some advice on the MOD, so that's updated.
How can I optimize this floormapping code to be realllly reallllllly fast, like pasco's floormapper?
Note: I tried to make this pure qb, but I wouldn't let me blit the buffer to the screen with PUT, so I had to use gslib's pcopy.
::EDIT::
Ok, I fixed it, code updated.
::EDIT 2::
Lithium gave me some advice on the MOD, so that's updated.
Code:
'$DYNAMIC
DEFINT A-Z
DIM SHARED PIC(63, 63)
DIM SHARED buffer(32001) AS INTEGER
DIM SHARED Sine(1920) AS SINGLE, Cosine(1920) AS SINGLE
DIM SHARED Raylength(99), lsy(199) AS LONG, presum AS LONG
t# = TIMER
CameraHeight = 100
CameraDistance = 128
FOR i# = 0 TO 6.28165 STEP 6.28165 / 1920
Sine(a) = SIN(i#)
Cosine(a) = COS(i#)
a = a + 1
NEXT
FOR y = 0 TO 63
FOR x = 0 TO 63
PIC(x, y) = COS(x / 30) * SIN(y / 30) * 4 + 24
NEXT
NEXT
FOR n = 0 TO 99
Raylength(n) = (CameraHeight / (CameraHeight - n)) * CameraDistance
NEXT
FOR n& = 0 TO 199
lsy(n&) = n& * 320 + 4
NEXT
SCREEN 13
buffer(0) = 2560: buffer(1) = 200
DEF SEG = VARSEG(buffer(0))
PlayerX = 0
PlayerAngle = 1920 / 4
PlayerY = 0
DO
PlayerX = PlayerX + 10 * Cosine(PlayerAngle)
PlayerY = PlayerY + 10 * Sine(PlayerAngle)
presum = lsy(100)
FOR y = 99 TO 0 STEP -1
xang = PlayerAngle - 159
IF xang < 0 THEN xang = xang + 1920
FOR x = 0 TO 319
vx = PlayerX + Raylength(y) * Cosine(xang)
vy = PlayerY + Raylength(y) * Sine(xang)
POKE presum + x, (PIC(ABS(vx) MOD 64, ABS(vy) MOD 64))
xang = xang + 1
IF xang > 1919 THEN xang = 0
NEXT
presum = presum + 320
NEXT
presum = lsy(99)
FOR y = 99 TO 0 STEP -1
xang = PlayerAngle - 159
IF xang < 0 THEN xang = xang + 1920
FOR x = 0 TO 319
vx = PlayerX + Raylength(y) * Cosine(xang)
vy = PlayerY + Raylength(y) * Sine(xang)
POKE presum + x, (PIC(ABS(vx) AND 63, ABS(vy) AND 63))
xang = xang + 1
IF xang > 1919 THEN xang = 0
NEXT
presum = presum - 320
NEXT
frames& = frames& + 1
PUT (0, 0), buffer, PSET
LOOP UNTIL INKEY$ = CHR$(27)
COLOR 63: PRINT frames& / (TIMER - t#)
DO: LOOP UNTIL INKEY$ = CHR$(27)
SYSTEM
am an asshole. Get used to it.