|
Re: What's (currently) your favourite snippet of code?
[Re: MasterQ32]
#444732
08/17/14 18:57
08/17/14 18:57
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
for( v=0; v<TEXTURESIZE; v++ ) {
SDL_GetRGB(getPixel(texture,u,v),screen->format,&b,&g,&r);
color = SDL_MapRGB(screen->format,r,g,b);
while( texelcount<=max(1.0,texelsize) && y<camera->winy+camera->winh ) {
if( y>=camera->winy ) {
*(Uint32 *)((Uint8 *)p + scanline)=color; // draw pixel
scanline += scanwidth;
}
y++;
texelcount+=min(texelsize,1.0);
}
texelcount -= max(1.0,texelsize);
if( y>=camera->winh+camera->winy )
break;
}
Column-based texture mapping on a per texel basis. It seems obvious but I just realized it a year ago, and it massively improved the speed of my raycaster when the camera was positioned close to walls. UV coordinates are recalculated only when the end of the texel is reached (instead of for every pixel), and if texelsize<0 the more obvious per-pixel method is used instead. Also: Fast float to integer conversion in x86. Weirdly enough I've found that many compilers will not do this. I discovered the trick several years ago and then found sometime later that John Carmack did the same thing in Quake 2.
my.pan = your.pan + random(360);
Where did you find this?
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: Redeemer]
#444738
08/17/14 19:28
08/17/14 19:28
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: Redeemer]
#444744
08/17/14 20:36
08/17/14 20:36
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: FBL]
#444843
08/19/14 19:51
08/19/14 19:51
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
#include <acknex.h>
#include <windows.h>
typedef int HKEY;
typedef int REGSAM;
long WINAPI RegEnumKeyEx(
HKEY hKey,
DWORD dwIndex,
char *lpName,
long *lpcName,
long *lpReserved,
char *lpClass,
long *lpcClass,
FILETIME *lpftLastWriteTime);
long WINAPI RegOpenKeyEx(HKEY hKey, char *lpSubKey, DWORD ulOptions, REGSAM samDesired, HKEY *phkResult);
long WINAPI RegCloseKey(HKEY hKey);
function main()
{
HKEY hTestKey;
if(RegOpenKeyEx(HKEY_CURRENT_USER,
"SOFTWARE\\Unity Technologies",
0,
KEY_READ,
&hTestKey) == ERROR_SUCCESS )
{
error("Traitor!");
RegCloseKey(hTestKey);
}
else
{
error("All fine!");
}
}
Snippet taken from Prince of Lotteria.
|
|
|
|