From bb2fd1c05daa37e9926526b2b1ae36271b4c9b4a Mon Sep 17 00:00:00 2001
From: Spoike <acceptthis@users.sourceforge.net>
Date: Tue, 22 Mar 2005 05:00:25 +0000
Subject: [PATCH] Okay, so it's still not working perfectly, it just looks like
 it. :) Trivial_accept is switched on, but the asm is disabled for now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@913 fc73d0e0-1445-4013-8a0c-d673dee63da5
---
 engine/sw/d_edge.c   |   2 +-
 engine/sw/d_ifacea.h |   1 +
 engine/sw/d_polysa.s | 117 +++++++++++++++---------------
 engine/sw/d_polyse.c | 168 +++++++++++++------------------------------
 engine/sw/r_aclip.c  |  15 +++-
 engine/sw/r_alias.c  |  26 ++++---
 engine/sw/r_draw.c   |  74 ++++++++++---------
 7 files changed, 174 insertions(+), 229 deletions(-)

diff --git a/engine/sw/d_edge.c b/engine/sw/d_edge.c
index 8fc811a09..28491e245 100644
--- a/engine/sw/d_edge.c
+++ b/engine/sw/d_edge.c
@@ -282,7 +282,7 @@ void D_DrawSurfaces (void)
 					d_zistepv = 0;
 					d_ziorigin = -0.9;
 
-					D_DrawSolidSurface (s, (int)r_clearcolor.value & 0xFF);
+					D_DrawSolidSurface (s, (int)r_fastskycolour.value & 0xFF);
 					D_DrawZSpans (s->spans);
 					continue;
 				}
diff --git a/engine/sw/d_ifacea.h b/engine/sw/d_ifacea.h
index 9cc4a213a..25bb36a4e 100644
--- a/engine/sw/d_ifacea.h
+++ b/engine/sw/d_ifacea.h
@@ -74,6 +74,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define stv_s		0
 #define stv_t		4
 #define stv_size	8
+#define stv_shift	4
 
 
 // trivertx_t structure
diff --git a/engine/sw/d_polysa.s b/engine/sw/d_polysa.s
index 7379047c7..a678a820a 100644
--- a/engine/sw/d_polysa.s
+++ b/engine/sw/d_polysa.s
@@ -1104,7 +1104,7 @@ C(D_PolysetDrawAsm):
 //		D_DrawNonSubdiv ();
 	movl	C(r_affinetridesc)+atd_drawtype,%eax
 	testl	%eax,%eax
-	jz		C(D_DrawNonSubdiv)
+	jz		C(D_DrawNonSubdivAsm)
 
 	pushl	%ebp				// preserve caller stack frame pointer
 
@@ -1564,8 +1564,8 @@ LNextVert:
 // not C-callable because of stack buffer cleanup
 //----------------------------------------------------------------------
 
-.globl C(D_DrawNonSubdiv)
-C(D_DrawNonSubdiv):
+.globl C(D_DrawNonSubdivAsm)
+C(D_DrawNonSubdivAsm):
 	pushl	%ebp				// preserve caller stack frame pointer
 	movl	C(r_affinetridesc)+atd_numtriangles,%ebp
 	pushl	%ebx
@@ -1626,104 +1626,101 @@ LNDLoop:
 	movl	%eax,C(d_xdenom)
 	fildl	C(d_xdenom)
 
+	//ecx = index0
+	//edx = index1
+	//ebx = index2
+
+	//edi = temp
+	//eax = temp (non cachable)
+	//esi = temp (non cachable)
+
+	//use esi for st pointer?
+//edi contains base triangles
+//ebp is the current triangle number
+//
+	movl	C(r_affinetridesc)+atd_pstverts,%edi
+
 //		r_p0[0] = index0->v[0];		// u
 //		r_p0[1] = index0->v[1];		// v
-//		r_p0[2] = index0->v[2];		// s
-//		r_p0[3] = index0->v[3];		// t
 //		r_p0[4] = index0->v[4];		// light
 //		r_p0[5] = index0->v[5];		// iz
 	movl	fv_v+0(%ecx),%eax
 	movl	fv_v+4(%ecx),%esi
 	movl	%eax,C(r_p0)+0
 	movl	%esi,C(r_p0)+4
-	movl	fv_v+8(%ecx),%eax
-	movl	fv_v+12(%ecx),%esi
-	movl	%eax,C(r_p0)+8
-	movl	%esi,C(r_p0)+12
 	movl	fv_v+16(%ecx),%eax
 	movl	fv_v+20(%ecx),%esi
 	movl	%eax,C(r_p0)+16
 	movl	%esi,C(r_p0)+20
 
+	//now we can reuse ecx
+	movl	C(r_affinetridesc)+atd_ptriangles,%ecx
+
+//esi = edi + ecx->st_index[0];
+//		r_p0[2] = esi->v[2];		// s
+//		r_p0[3] = esi->v[3];		// t
+
+	movl mtri_stindex+0-mtri_size(%ecx,%ebp),%esi
+	shll $(stv_shift), %esi
+	addl %edi, %esi
+
+	movl	stv_s(%esi), %eax
+	movl	stv_t(%esi), %esi
+	movl	%eax,C(r_p0)+8
+	movl	%esi,C(r_p0)+12
+
+
+
 	fdivrs	float_1
 
 //		r_p1[0] = index1->v[0];
 //		r_p1[1] = index1->v[1];
-//		r_p1[2] = index1->v[2];
-//		r_p1[3] = index1->v[3];
 //		r_p1[4] = index1->v[4];
 //		r_p1[5] = index1->v[5];
 	movl	fv_v+0(%edx),%eax
 	movl	fv_v+4(%edx),%esi
 	movl	%eax,C(r_p1)+0
 	movl	%esi,C(r_p1)+4
-	movl	fv_v+8(%edx),%eax
-	movl	fv_v+12(%edx),%esi
-	movl	%eax,C(r_p1)+8
-	movl	%esi,C(r_p1)+12
 	movl	fv_v+16(%edx),%eax
 	movl	fv_v+20(%edx),%esi
 	movl	%eax,C(r_p1)+16
 	movl	%esi,C(r_p1)+20
 
+//		r_p1[2] = index1->v[2];
+//		r_p1[3] = index1->v[3];
+	movl mtri_stindex+4-mtri_size(%ecx,%ebp),%esi
+	shll $(stv_shift), %esi
+	addl %edi, %esi
+
+	movl	stv_s(%esi), %eax
+	movl	stv_t(%esi), %esi
+	movl	%eax,C(r_p1)+8
+	movl	%esi,C(r_p1)+12
+
 //		r_p2[0] = index2->v[0];
 //		r_p2[1] = index2->v[1];
-//		r_p2[2] = index2->v[2];
-//		r_p2[3] = index2->v[3];
 //		r_p2[4] = index2->v[4];
 //		r_p2[5] = index2->v[5];
 	movl	fv_v+0(%ebx),%eax
 	movl	fv_v+4(%ebx),%esi
 	movl	%eax,C(r_p2)+0
 	movl	%esi,C(r_p2)+4
-	movl	fv_v+8(%ebx),%eax
-	movl	fv_v+12(%ebx),%esi
-	movl	%eax,C(r_p2)+8
-	movl	%esi,C(r_p2)+12
 	movl	fv_v+16(%ebx),%eax
 	movl	fv_v+20(%ebx),%esi
 	movl	%eax,C(r_p2)+16
-	movl	C(r_affinetridesc)+atd_ptriangles,%edi
 	movl	%esi,C(r_p2)+20
+
+//		r_p2[2] = index2->v[2];
+//		r_p2[3] = index2->v[3];
+	movl mtri_stindex+8-mtri_size(%ecx,%ebp),%esi
+	shll $(stv_shift), %esi
+	addl %edi, %esi
+
+	movl	stv_s(%esi), %eax
+	movl	stv_t(%esi), %esi
+	movl	%eax,C(r_p2)+8
+	movl	%esi,C(r_p2)+12
 			
-#ifdef ONSEAMSTUFF
-	movl	mtri_facesfront-mtri_size(%edi,%ebp,1),%eax
-
-//		if (!ptri->facesfront)
-//		{
-	testl	%eax,%eax
-	jnz		LFacesFront
-
-//			if (index0->flags & ALIAS_ONSEAM)
-//				r_p0[2] += r_affinetridesc.seamfixupX16;
-	movl	fv_flags(%ecx),%eax
-	movl	fv_flags(%edx),%esi
-	movl	fv_flags(%ebx),%edi
-	testl	$(ALIAS_ONSEAM),%eax	
-	movl	C(r_affinetridesc)+atd_seamfixupX16,%eax
-	jz		LOnseamDone0
-	addl	%eax,C(r_p0)+8
-LOnseamDone0:
-
-//			if (index1->flags & ALIAS_ONSEAM)
-// 				r_p1[2] += r_affinetridesc.seamfixupX16;
-	testl	$(ALIAS_ONSEAM),%esi
-	jz		LOnseamDone1
-	addl	%eax,C(r_p1)+8
-LOnseamDone1:
-
-//			if (index2->flags & ALIAS_ONSEAM)
-//				r_p2[2] += r_affinetridesc.seamfixupX16;
-	testl	$(ALIAS_ONSEAM),%edi
-	jz		LOnseamDone2
-	addl	%eax,C(r_p2)+8
-LOnseamDone2:
-//		}
-
-LFacesFront:
-
-#endif
-
 	fstps	C(d_xdenom)
 
 //		D_PolysetSetEdgeTable ();
diff --git a/engine/sw/d_polyse.c b/engine/sw/d_polyse.c
index 9e6220851..a451437e8 100644
--- a/engine/sw/d_polyse.c
+++ b/engine/sw/d_polyse.c
@@ -126,6 +126,7 @@ void D_PolysetScanLeftEdge (int height);
 #endif
 
 void D_PolysetDrawSpans8 (spanpackage_t *pspanpackage);
+void D_PolysetDrawSpans8C (spanpackage_t *pspanpackage);
 void D_PolysetCalcGradients (int skinwidth);
 void D_PolysetCalcGradients32 (int skinwidth);
 void D_DrawSubdiv (void);
@@ -628,7 +629,10 @@ void D_PolysetDrawSpans8Trans (spanpackage_t *pspanpackage)
 
 	if (t_state & TT_REVERSE)
 	{
-		D_PolysetDrawSpans8ReverseTrans(pspanpackage);
+		if (t_state & TT_ONE)
+			D_PolysetDrawSpans8C(pspanpackage);
+		else
+			D_PolysetDrawSpans8ReverseTrans(pspanpackage);
 		return;
 	}
 
@@ -1194,7 +1198,7 @@ void D_PolysetDraw16 (void)
 	else
 		*/
 	{
-		D_DrawNonSubdiv ();
+		D_DrawNonSubdivC ();
 	}
 }
 
@@ -1269,66 +1273,36 @@ void D_DrawSubdivC (void)
 	int				i;
 	int				lnumtriangles;
 
+	void (*drawfnc) (int *p1, int *p2, int *p3);
+
 	pfv = r_affinetridesc.pfinalverts;
 	ptri = r_affinetridesc.ptriangles;
 	lnumtriangles = r_affinetridesc.numtriangles;
 
+
+
 #ifdef PEXT_TRANS
 	if (r_pixbytes == 4)
-	{		
-		for (i=0 ; i<lnumtriangles ; i++)
-		{
-			index0 = pfv + ptri[i].xyz_index[0];
-			index1 = pfv + ptri[i].xyz_index[1];
-			index2 = pfv + ptri[i].xyz_index[2];
-
-			if (((index0->v[1]-index1->v[1]) *
-				 (index0->v[0]-index2->v[0]) -
-				 (index0->v[0]-index1->v[0]) * 
-				 (index0->v[1]-index2->v[1])) >= 0)
-			{
-				continue;
-			}
-
-			d_pcolormap = &((qbyte *)acolormap)[index0->v[4] & 0xFF00];
-
-			D_PolysetRecursiveTriangle32Trans(index0->v, index1->v, index2->v);
-		}
-		return;
-	}
-	if (currententity->alpha != 1)
+		drawfnc = D_PolysetRecursiveTriangle32Trans;
+	else if (currententity->alpha != 1)
 	{
-		Set_TransLevelF(currententity->alpha);
-		if (!(t_state & TT_ONE))
-		{
-			if (t_state & TT_ZERO)
-				return;
-
-			for (i=0 ; i<lnumtriangles ; i++)
-			{
-				index0 = pfv + ptri[i].xyz_index[0];
-				index1 = pfv + ptri[i].xyz_index[1];
-				index2 = pfv + ptri[i].xyz_index[2];
-
-				if (((index0->v[1]-index1->v[1]) *
-					 (index0->v[0]-index2->v[0]) -
-					 (index0->v[0]-index1->v[0]) * 
-					 (index0->v[1]-index2->v[1])) >= 0)
-				{
-					continue;
-				}
-
-				d_pcolormap = &((qbyte *)acolormap)[index0->v[4] & 0xFF00];
-
-				if (t_state & TT_REVERSE)
-					D_PolysetRecursiveTriangleReverseTrans(index0->v, index1->v, index2->v);
-				else
-					D_PolysetRecursiveTriangleTrans(index0->v, index1->v, index2->v);
-			}
+		Set_TransLevelF(currententity->alpha);	//fixme: this is being called by every poly!
+		if (t_state & TT_ZERO)
 			return;
+
+		if (t_state & TT_ONE)	//it's solid anyway.
+			drawfnc = D_PolysetRecursiveTriangle;
+		else
+		{
+			if (t_state & TT_REVERSE)
+				drawfnc = D_PolysetRecursiveTriangleReverseTrans;
+			else
+				drawfnc = D_PolysetRecursiveTriangleTrans;
 		}
 	}
+	else
 #endif
+		drawfnc = D_PolysetRecursiveTriangle;
 
 	for (i=0 ; i<lnumtriangles ; i++)
 	{
@@ -1377,19 +1351,6 @@ void D_DrawSubdiv32C (void)
 			continue;
 		}
 
-		st0 = pst + ptri[i].st_index[0];
-		st1 = pst + ptri[i].st_index[1];
-		st2 = pst + ptri[i].st_index[2];
-
-		index0->v[2] = st0->s;
-		index0->v[3] = st0->t;
-
-		index1->v[2] = st1->s;
-		index1->v[3] = st1->t;
-
-		index2->v[2] = st2->s;
-		index2->v[3] = st2->t;
-
 		d_pcolormap = &((qbyte *)acolormap)[index0->v[4] & 0xFF00];
 
 		D_PolysetRecursiveTriangle32Trans(index0->v, index1->v, index2->v);
@@ -1408,17 +1369,13 @@ void D_DrawNonSubdivC (void)
 	int				i;
 	int				lnumtriangles;
 
-	mstvert_t		*pst, *st0, *st1, *st2;
+	mstvert_t		*pst, *stv;
 
 	pst = r_affinetridesc.pstverts;
 	pfv = r_affinetridesc.pfinalverts;
 	ptri = r_affinetridesc.ptriangles;
 	lnumtriangles = r_affinetridesc.numtriangles;
 
-	Set_TransLevelF(currententity->alpha);
-	if (t_state & TT_ZERO)
-		return;
-
 	for (i=0 ; i<lnumtriangles ; i++, ptri++)
 	{
 		index0 = pfv + ptri->xyz_index[0];
@@ -1434,28 +1391,27 @@ void D_DrawNonSubdivC (void)
 			continue;
 		}
 
-		st0 = pst + ptri->st_index[0];
-		st1 = pst + ptri->st_index[1];
-		st2 = pst + ptri->st_index[2];
-
 		r_p0[0] = index0->v[0];		// u
 		r_p0[1] = index0->v[1];		// v
-		r_p0[2] = st0->s;		// s
-		r_p0[3] = st0->t;		// t
+		stv = pst + ptri->st_index[0];
+		r_p0[2] = stv->s;		// s
+		r_p0[3] = stv->t;		// t
 		r_p0[4] = index0->v[4];		// light
 		r_p0[5] = index0->v[5];		// iz
 
 		r_p1[0] = index1->v[0];
 		r_p1[1] = index1->v[1];
-		r_p1[2] = st1->s;
-		r_p1[3] = st1->t;
+		stv = pst + ptri->st_index[1];
+		r_p1[2] = stv->s;
+		r_p1[3] = stv->t;
 		r_p1[4] = index1->v[4];
 		r_p1[5] = index1->v[5];
 
 		r_p2[0] = index2->v[0];
 		r_p2[1] = index2->v[1];
-		r_p2[2] = st2->s;
-		r_p2[3] = st2->t;
+		stv = pst + ptri->st_index[2];
+		r_p2[2] = stv->s;
+		r_p2[3] = stv->t;
 		r_p2[4] = index2->v[4];
 		r_p2[5] = index2->v[5];
 
@@ -1471,8 +1427,8 @@ void D_DrawNonSubdiv32C (void)
 
 	int				i;
 	int				lnumtriangles;
-#if 0
-	stvert_t		*pst, *st0, *st1, *st2;
+#if 1
+	mstvert_t		*pst, *stv;
 	pst = r_affinetridesc.pstverts;
 #endif
 	pfv = r_affinetridesc.pfinalverts;
@@ -1493,53 +1449,30 @@ void D_DrawNonSubdiv32C (void)
 		{
 			continue;
 		}
-#if 0
-		st0 = pfv + ptri->st_index[0];
-		st1 = pfv + ptri->st_index[1];
-		st2 = pfv + ptri->st_index[2];
 
 		r_p0[0] = index0->v[0];		// u
 		r_p0[1] = index0->v[1];		// v
-		r_p0[2] = st0->s;//index0->v[2];		// s
-		r_p0[3] = st0->t;//index0->v[3];		// t
+		stv = pst + ptri->st_index[0];
+		r_p0[2] = stv->s;//index0->v[2];		// s
+		r_p0[3] = stv->t;//index0->v[3];		// t
 		r_p0[4] = index0->v[4];		// light
 		r_p0[5] = index0->v[5];		// iz
 
 		r_p1[0] = index1->v[0];
 		r_p1[1] = index1->v[1];
-		r_p1[2] = st1->s;//index1->v[2];
-		r_p1[3] = st1->t;//index1->v[3];
+		stv = pst + ptri->st_index[1];
+		r_p1[2] = stv->s;//index1->v[2];
+		r_p1[3] = stv->t;//index1->v[3];
 		r_p1[4] = index1->v[4];
 		r_p1[5] = index1->v[5];
 
 		r_p2[0] = index2->v[0];
 		r_p2[1] = index2->v[1];
-		r_p2[2] = st2->s;//index2->v[2];
-		r_p2[3] = st2->t;//index2->v[3];
+		stv = pst + ptri->st_index[2];
+		r_p2[2] = stv->s;//index2->v[2];
+		r_p2[3] = stv->t;//index2->v[3];
 		r_p2[4] = index2->v[4];
 		r_p2[5] = index2->v[5];
-#else
-		r_p0[0] = index0->v[0];		// u
-		r_p0[1] = index0->v[1];		// v
-		r_p0[2] = index0->v[2];		// s
-		r_p0[3] = index0->v[3];		// t
-		r_p0[4] = index0->v[4];		// light
-		r_p0[5] = index0->v[5];		// iz
-
-		r_p1[0] = index1->v[0];
-		r_p1[1] = index1->v[1];
-		r_p1[2] = index1->v[2];
-		r_p1[3] = index1->v[3];
-		r_p1[4] = index1->v[4];
-		r_p1[5] = index1->v[5];
-
-		r_p2[0] = index2->v[0];
-		r_p2[1] = index2->v[1];
-		r_p2[2] = index2->v[2];
-		r_p2[3] = index2->v[3];
-		r_p2[4] = index2->v[4];
-		r_p2[5] = index2->v[5];
-#endif
 
 		D_PolysetSetEdgeTable ();
 		D_RasterizeAliasPolySmoothC ();
@@ -1891,14 +1824,12 @@ void InitGel (qbyte *palette)
 }
 #endif
 
-#if	!id386
-
 /*
 ================
 D_PolysetDrawSpans8
 ================
 */
-void D_PolysetDrawSpans8 (spanpackage_t *pspanpackage)
+void D_PolysetDrawSpans8C (spanpackage_t *pspanpackage)
 {
 	int		lcount;
 	qbyte	*lpdest;
@@ -1961,7 +1892,6 @@ void D_PolysetDrawSpans8 (spanpackage_t *pspanpackage)
 		pspanpackage++;
 	} while (pspanpackage->count != -999999);
 }
-#endif	// !id386
 
 
 /*
@@ -2434,7 +2364,7 @@ void D_RasterizeAliasPolySmooth8C (void)
 		DrawSpans (pstart);
 	}
 }
-
+/*
 void D_RasterizeAliasPolySmooth1Asm (void)
 {
 	int				initialleftheight, initialrightheight;
@@ -2642,7 +2572,7 @@ void D_RasterizeAliasPolySmooth1Asm (void)
 		D_PolysetDrawSpans8 (pstart);
 	}
 }
-
+*/
 
 /*
 ================
diff --git a/engine/sw/r_aclip.c b/engine/sw/r_aclip.c
index 16a94e00e..e13ec6957 100644
--- a/engine/sw/r_aclip.c
+++ b/engine/sw/r_aclip.c
@@ -240,6 +240,8 @@ void R_AliasClipTriangle (mtriangle_t *ptri, void (*drawfnc) (void))
 	mtriangle_t		mtri;
 	unsigned		clipflags;
 
+	mstvert_t	tst[3];	//temp st
+
 	mstvert_t	*pst = r_affinetridesc.pstverts;
 
 
@@ -336,18 +338,25 @@ void R_AliasClipTriangle (mtriangle_t *ptri, void (*drawfnc) (void))
 // draw triangles
 	r_affinetridesc.ptriangles = &mtri;
 	r_affinetridesc.pfinalverts = fv[pingpong];
-	r_affinetridesc.pstverts = fstv[pingpong];
+	r_affinetridesc.pstverts = tst;
 
 // FIXME: do all at once as trifan?
 	mtri.xyz_index[0] = 0;
 	mtri.st_index[0] = 0;
+	tst[0].s = fv[pingpong][0].v[2];
+	tst[0].t = fv[pingpong][0].v[3];
 
 	for (i=1 ; i<k-1 ; i++)
 	{
 		mtri.xyz_index[1] = i;
-		mtri.st_index[1] = i;
+		mtri.st_index[1] = 1;
+		tst[1].s = fv[pingpong][i].v[2];
+		tst[1].t = fv[pingpong][i].v[3];
+
 		mtri.xyz_index[2] = i+1;
-		mtri.st_index[2] = i+1;
+		mtri.st_index[2] = 2;
+		tst[2].s = fv[pingpong][i+1].v[2];
+		tst[2].t = fv[pingpong][i+1].v[3];
 		drawfnc ();
 	}
 	r_affinetridesc.pstverts = pst;
diff --git a/engine/sw/r_alias.c b/engine/sw/r_alias.c
index 579ec977e..df6f9ed77 100644
--- a/engine/sw/r_alias.c
+++ b/engine/sw/r_alias.c
@@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "d_local.h"	// FIXME: shouldn't be needed (is needed for patch
 						// right now, but that should move)
 
+#undef	id386
+
 #define	Q2RF_DEPTHHACK			16		// for view weapon Z crunching
 
 #define LIGHT_MIN	5		// lowest light value we'll allow, to avoid the
@@ -311,8 +313,8 @@ void R_AliasPreparePoints (void)
  	fv = pfinalverts;
 	av = pauxverts;
 
-#if	id386
-	if (currententity->alpha == 1)	//use the asm routines if we have it, and don't have alpha
+#if	0//id386
+	if (t_state & TT_ONE)	//use the asm routines if we have it, and don't have alpha
 	{
 		if (r_pixbytes == 4)
 			drawfnc = D_PolysetDraw32;
@@ -368,15 +370,6 @@ void R_AliasPreparePoints (void)
 		if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP) )
 			continue;		// completely clipped
 
-		pfv[0]->v[2] = pstverts[ptri->st_index[0]].s;
-		pfv[0]->v[3] = pstverts[ptri->st_index[0]].t;
-
-		pfv[1]->v[2] = pstverts[ptri->st_index[1]].s;
-		pfv[1]->v[3] = pstverts[ptri->st_index[1]].t;
-
-		pfv[2]->v[2] = pstverts[ptri->st_index[2]].s;
-		pfv[2]->v[3] = pstverts[ptri->st_index[2]].t;
-		
 		if ( ! ( (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) &
 			(ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP) ) )
 		{	// totally unclipped
@@ -883,6 +876,9 @@ void R_AliasDrawModel (alight_t *plighting)
 	extern qbyte transfactor;
 	extern qbyte transbackfac;
 
+	Set_TransLevelF(currententity->alpha);
+	if (t_state & TT_ZERO)
+		return;
 
 	r_amodels_drawn++;
 
@@ -910,6 +906,14 @@ void R_AliasDrawModel (alight_t *plighting)
 			r_recursiveaffinetriangles;
 
 	r_affinetridesc.pstverts = (mstvert_t *)((qbyte *)paliashdr + paliashdr->stverts);
+/*	{
+	int i;
+	for (i = 0; i < pmdl->numstverts; i++)
+	{
+		r_affinetridesc.pstverts[i].s = rand()<<8;
+		r_affinetridesc.pstverts[i].t = rand()<<8;
+	}
+	}*/
 
 	if (r_affinetridesc.drawtype)
 	{
diff --git a/engine/sw/r_draw.c b/engine/sw/r_draw.c
index 1f37718ce..dfd1cad97 100644
--- a/engine/sw/r_draw.c
+++ b/engine/sw/r_draw.c
@@ -123,41 +123,6 @@ extern	mtexinfo_t		r_skytexinfo[6];
 extern cvar_t gl_skyboxname;
 
 char skyname[128];
-void SWR_SetSky (char *name, float rotate, vec3_t axis)
-{
-	int		i;
-
-	Q_strncpyz (skyname, name, sizeof(skyname));
-//	skyrotate = rotate;
-//	VectorCopy (axis, skyaxis);
-
-	for (i=0 ; i<6 ; i++)
-	{
-		r_skytexinfo[i].texture = NULL;
-	}
-}
-
-qboolean SWR_CheckSky (void)
-{
-	int		i;
-	char	pathname[MAX_QPATH];
-
-	if (!*skyname)
-		return true;
-	for (i=0 ; i<6 ; i++)
-	{
-		sprintf (pathname, "env/%s%s.pcx", skyname, suf[r_skysideimage[i]]);
-		if (COM_FCheckExists(pathname))
-		{
-			continue;// it exists, don't bother going for a tga version
-		}
-
-		sprintf (pathname, "env/%s%s.tga", skyname, suf[r_skysideimage[i]]);
-		if (!CL_CheckOrDownloadFile(pathname, -1))
-			return false;
-	}
-	return true;
-}
 
 /*
 ================
@@ -182,6 +147,45 @@ void R_LoadSkyBox (void)
 	}
 #endif
 }
+
+void SWR_SetSky (char *name, float rotate, vec3_t axis)
+{
+	int		i;
+
+	Q_strncpyz (skyname, name, sizeof(skyname));
+//	skyrotate = rotate;
+//	VectorCopy (axis, skyaxis);
+
+	for (i=0 ; i<6 ; i++)
+	{
+		r_skytexinfo[i].texture = NULL;
+	}
+
+	R_LoadSkyBox();
+}
+
+qboolean SWR_CheckSky (void)
+{
+	int		i;
+	char	pathname[MAX_QPATH];
+
+	if (!*skyname)
+		return true;
+	for (i=0 ; i<6 ; i++)
+	{
+		sprintf (pathname, "env/%s%s.pcx", skyname, suf[r_skysideimage[i]]);
+		if (COM_FCheckExists(pathname))
+		{
+			continue;// it exists, don't bother going for a tga version
+		}
+
+		sprintf (pathname, "env/%s%s.tga", skyname, suf[r_skysideimage[i]]);
+		if (!CL_CheckOrDownloadFile(pathname, -1))
+			return false;
+	}
+	return true;
+}
+
 /*
 ================
 R_InitSkyBox