Adam's Multi Floors - Making it Work With Ceilings This is Adam's Multi Floors, but motified for ceilings too. It uses the third plane for both the ceiling and floor.
void DrawFlats(unsigned tex_f, unsigned tex_c)
{
int x, y, y0, halfheight;
unsigned top_offset0, bot_offset0, top_offset, bot_offset;
unsigned top_add, bot_add;
byte p, color;
byte far *src_bot, far *src_top;
fixed dist; // distance to row projection
fixed tex_step; // global step per one screen pixel
fixed gu, gv, du, dv; // global texture coordinates
int u, v; // local texture coordinates
int floorx,floory;
unsigned curfloortex, lastfloortex;
int roofx,roofy;
unsigned currooftex, lastrooftex;
// ------ * prepare * --------
halfheight=viewheight>>1;
y0=min_wallheight>>3; // starting y value
if(y0>halfheight)
return; // view obscued by walls
if(y0==0)
y0=1; // don't let division by zero
top_offset0=80*(halfheight-y0-1); // and will decrease by 80 each row
bot_offset0=80*(halfheight+y0); // and will increase by 80 each row
//src_top=PM_GetPage(tex_c); // load ceiling texture
lastrooftex=-1;
// draw horizontal lines
for(p=0; p<4; p++)
{
asm mov ax,0x0102
asm mov cl,[p]
asm shl ah,cl
asm mov dx,0x3c4
asm out dx,ax
for(y=y0, top_offset=top_offset0; y<halfheight; y++, top_offset-=80)
{
dist=(heightnumerator/y)<<5;
gu= viewx+FixedByFrac(dist, viewcos);
gv=-viewy+FixedByFrac(dist, viewsin);
tex_step=(dist<<8)/viewwidth/175;
du= FixedByFrac(tex_step, viewsin);
dv=-FixedByFrac(tex_step, viewcos);
gu-=((viewwidth>>1)-p)*du;
gv-=((viewwidth>>1)-p)*dv; // starting point (leftmost)
du<<=2; // 4pix step
dv<<=2;
for(x=p, top_add=top_offset; x<viewwidth; x+=4, top_add++)
{
if(wallheight[x]>>3<=y)
{
roofx = (gu>>TILESHIFT)&63;
roofy = (-(gv>>TILESHIFT)-1)&63;
currooftex=MAPSPOT(roofx,roofy,2)+1;
if (currooftex != lastrooftex)
{
lastrooftex=currooftex;
src_top=PM_GetPage(currooftex);
}
u=(gu>>10)&63;
v=(gv>>10)&63;
color=*(src_top+((63-u)<<6)+(63-v));
// draw top pixel using <color>
asm mov es,[screenseg]
asm mov di,[bufferofs]
asm add di,[top_add]
asm mov al,[color]
asm mov es:[di],al
}
gu+=du;
gv+=dv;
}
}
}
// src_bot=PM_GetPage(tex_f); // load floor texture
lastfloortex=-1;
for(p=0; p<4; p++)
{
asm mov ax,0x0102
asm mov cl,[p]
asm shl ah,cl
asm mov dx,0x3c4
asm out dx,ax
for(y=y0, bot_offset=bot_offset0; y<halfheight; y++, bot_offset+=80)
{
dist=(heightnumerator/y)<<5;
gu= viewx+FixedByFrac(dist, viewcos);
gv=-viewy+FixedByFrac(dist, viewsin);
tex_step=(dist<<8)/viewwidth/175;
du= FixedByFrac(tex_step, viewsin);
dv=-FixedByFrac(tex_step, viewcos);
gu-=((viewwidth>>1)-p)*du;
gv-=((viewwidth>>1)-p)*dv; // starting point (leftmost)
du<<=2; // 4pix step
dv<<=2;
for(x=p, bot_add=bot_offset; x<viewwidth; x+=4, bot_add++)
{
if(wallheight[x]>>3<=y)
{
floorx = (gu>>TILESHIFT)&63;
floory = (-(gv>>TILESHIFT)-1)&63;
curfloortex=MAPSPOT(floorx,floory,2);
if (curfloortex != lastfloortex)
{
lastfloortex=curfloortex;
src_bot=PM_GetPage(curfloortex);
}
u=(gu>>10)&63;
v=(gv>>10)&63;
color=*(src_bot+(u<<6)+(63-v));
// draw bottom pixel using <color>
asm mov es,[screenseg]
asm mov di,[bufferofs]
asm add di,[bot_add]
asm mov al,[color]
asm mov es:[di],al
}
gu+=du;
gv+=dv;
}
}
}
}
Now, if you noticed, the ceiling checks MAPSPOT(roofx,roofy,2)+1. This sets the ceiling to the wall image after the floor image. THIS IS NOT THE NEXT WALL ID, that is not how it works. If you want the 4th plane (you would need WDC to place these) for the ceiling, change:
MAPSPOT(roofx,roofy,2)+1
to:
MAPSPOT(roofx,roofy,3)
Of course, you need to follow the tutorial in the WDC help to allow more than 3 planes.
Credit goes to Adam, Deathshead, and just a tad to me. Thanks to Adam for the base!
Kyo Kusanagi- 07-04-2005
kool I'll try it out on my Part 3 of my Spear of Dreams saga
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.