76
Axe / Re: What I've done?! O.o
« on: February 11, 2013, 08:20:06 am »
Some time ago, I made my own raycaster, however I halted the project... I need to finish it some day
Yours looks awesome so far
Looking at your code, I realized that it is quite slow. You only draw 1/4 segments of the screen, and it is running at 15 Mhz. I'm not an expert at raycasting, but I think you need to restructure parts of the code to really optimize it. Still, here are some minor optimization tricks you could use (but I don't think they really matter that much):
The next optimization helps almost everywhere:
If size doesn't matter, use a bunch of /2 instead of dividing by a power of 2. For example:
A/2/2/2 is faster than /8
This trick works due to the fact that /2 is replaced by a shift operation, whereas every other division calls a routine to divide (which is kinda slow)
I think the slowest part of your code is this, I don't know how to optimize this though, because I don't understand what you want to do with that.
Also, if you need a function only once in the code, you can type it inline where you need it to save some bytes and cycles without the call.
If you want to keep readability, you can include them in another program.
Also, what helps reading the code is the C++ style function calling syntax:
Function(arguments) instead of sub(Function,arguments)
For example:
I guess that's my part for now, maybe I take a closer look on it later. I hope it helps you a bit and good luck with your project.
Yours looks awesome so far
Looking at your code, I realized that it is quite slow. You only draw 1/4 segments of the screen, and it is running at 15 Mhz. I'm not an expert at raycasting, but I think you need to restructure parts of the code to really optimize it. Still, here are some minor optimization tricks you could use (but I don't think they really matter that much):
Code: [Select]
Pt-Off(0,,Pic0,L3)
If pxl-Test(V/8,W/8,L3)
Using a sprite is a cool idea to store the map, but the pixel-test function is incredible slow (and you're doing that a lot each frame!). Try directly accessing the data, e.g. in an 2d array/matrix etc.The next optimization helps almost everywhere:
If size doesn't matter, use a bunch of /2 instead of dividing by a power of 2. For example:
A/2/2/2 is faster than /8
This trick works due to the fact that /2 is replaced by a shift operation, whereas every other division calls a routine to divide (which is kinda slow)
Code: [Select]
√(((abs(X-V)²)+(abs(Y-W)²)))→G
Here you can leave out the abs(), because squaring gets rid of the sign. You don't even need the first parenthesis. So:Code: [Select]
√(X-V²+(Y-W)²)→G
Code: [Select]
If r1<64 or (r1>192)
Almost in every case you can substitute a logic "or" by an addition.Code: [Select]
If r1<64 + (r1>192)
I think the slowest part of your code is this, I don't know how to optimize this though, because I don't understand what you want to do with that.
Code: [Select]
Lbl TH
abs(Y-W)*128//sin(r1-r2)*cos(r1-r2)//128→U
r1<128?U+X→V,X-U→V
Return
Lbl TV
abs(V-X)*128//cos(r1)*sin(r1)//128→U
Return
This code looks slow because of signed division and trigonometry. These functions are also called a lot each frame!Also, if you need a function only once in the code, you can type it inline where you need it to save some bytes and cycles without the call.
If you want to keep readability, you can include them in another program.
Also, what helps reading the code is the C++ style function calling syntax:
Function(arguments) instead of sub(Function,arguments)
For example:
Code: [Select]
sub(TH,r1,128) becomes TH(r1,128)
I guess that's my part for now, maybe I take a closer look on it later. I hope it helps you a bit and good luck with your project.