From 2000d013348a8a398c89ac8c66914df5b4cadba2 Mon Sep 17 00:00:00 2001
From: Spoike <acceptthis@users.sourceforge.net>
Date: Fri, 18 Mar 2005 06:14:33 +0000
Subject: [PATCH] Small changes, a few bugs fixed.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@905 fc73d0e0-1445-4013-8a0c-d673dee63da5
---
 engine/gl/gl_alias.c | 15 +++++++--
 engine/gl/gl_draw.c  |  5 +++
 engine/gl/gl_model.c |  2 ++
 engine/gl/gl_model.h |  4 +--
 engine/gl/gl_ppl.c   | 77 ++++++++++++++++++++++++++++++++++++++++++++
 engine/gl/gl_rmain.c |  6 ++++
 engine/gl/gl_rsurf.c |  3 +-
 engine/gl/gl_warp.c  |  2 +-
 8 files changed, 108 insertions(+), 6 deletions(-)

diff --git a/engine/gl/gl_alias.c b/engine/gl/gl_alias.c
index 3f22a2b69..2fe83240b 100644
--- a/engine/gl/gl_alias.c
+++ b/engine/gl/gl_alias.c
@@ -591,7 +591,7 @@ static galiastexnum_t *GL_ChooseSkin(galiasinfo_t *inf, char *modelname, entity_
 
 	int tc, bc;
 
-	if (!gl_nocolors.value)
+	if (!gl_nocolors.value && !cls.q2server)
 	{
 		if (e->scoreboard)
 		{
@@ -809,6 +809,9 @@ static galiastexnum_t *GL_ChooseSkin(galiasinfo_t *inf, char *modelname, entity_
 		}
 	}
 
+	if (!inf->numskins)
+		return NULL;
+
 	skins = (galiasskin_t*)((char *)inf + inf->ofsskins);
 	if (e->skinnum >= 0 && e->skinnum < inf->numskins)
 		skins += e->skinnum;
@@ -2322,13 +2325,15 @@ static void Q2_LoadSkins(char *skins)
 	int i;
 	galiastexnum_t *texnums;
 	galiasskin_t *outskin = (galiasskin_t *)((char *)galias + galias->ofsskins);
+	galias->numskins = pq2inmodel->num_skins;
 
-	for (i = 0; i < pq2inmodel->num_skins; i++)
+	for (i = 0; i < pq2inmodel->num_skins; i++, outskin++)
 	{
 		texnums = Hunk_Alloc(sizeof(*texnums));
 		outskin->ofstexnums = (char *)texnums - (char *)outskin;
 		outskin->texnums=1;
 
+		COM_CleanUpPath(skins);	//blooming tanks.
 		texnums->base = Mod_LoadReplacementTexture(skins, true, false, true);
 		outskin->skinwidth = 0;
 		outskin->skinheight = 0;
@@ -2374,6 +2379,8 @@ void GL_LoadQ2Model (model_t *mod, void *buffer)
 
 	pq2inmodel = (md2_t *)buffer;
 
+	//FIXME: Endian
+
 	version = LittleLong (pq2inmodel->version);
 	if (version != MD2ALIAS_VERSION)
 		Sys_Error ("%s has wrong version number (%i should be %i)",
@@ -2390,6 +2397,8 @@ void GL_LoadQ2Model (model_t *mod, void *buffer)
 
 	mod->flags = 0;
 
+	loadmodel->numframes = pq2inmodel->num_frames;
+
 	size = sizeof(galiasinfo_t)
 		+ pq2inmodel->num_frames*sizeof(galiasgroup_t)
 		+ pq2inmodel->num_skins*sizeof(galiasskin_t);
@@ -2800,6 +2809,8 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
 	surf = (md3Surface_t *)((qbyte *)header + header->ofsSurfaces);
 	for (s = 0; s < header->numSurfaces; s++)
 	{
+		if (surf->ident != MD3_IDENT)
+			Con_Printf("Warning: md3 sub-surface doesn't match ident\n");
 		size = sizeof(galiasinfo_t) + sizeof(galiasgroup_t)*header->numFrames;
 		galias = Hunk_Alloc(size);
 		galias->groupofs = sizeof(*galias);	//frame groups
diff --git a/engine/gl/gl_draw.c b/engine/gl/gl_draw.c
index 2ed52e78f..0ea8be649 100644
--- a/engine/gl/gl_draw.c
+++ b/engine/gl/gl_draw.c
@@ -247,6 +247,11 @@ qboolean Draw_RealPicFromWad (mpic_t	*out, char *name)
 	
 	if (texnum)
 	{
+		if (!in)
+		{
+			out->width = image_width;
+			out->height = image_height;
+		}
 		gl->texnum = texnum;
 		gl->sl = 0;
 		gl->sh = 1;
diff --git a/engine/gl/gl_model.c b/engine/gl/gl_model.c
index a09dbf93d..cbd4ebb74 100644
--- a/engine/gl/gl_model.c
+++ b/engine/gl/gl_model.c
@@ -3038,6 +3038,8 @@ void GLMod_LoadSprite2Model (model_t *mod, void *buffer)
 		frame->down = frame->height - origin[1];
 		frame->left = -origin[0];
 		frame->right = frame->width - origin[0];
+
+		pframetype++;
 	}
 
 	mod->type = mod_sprite;
diff --git a/engine/gl/gl_model.h b/engine/gl/gl_model.h
index a3d026ddf..9ede07df3 100644
--- a/engine/gl/gl_model.h
+++ b/engine/gl/gl_model.h
@@ -805,7 +805,7 @@ void CM_Init(void);
 
 qboolean	CM_SetAreaPortalState (int portalnum, qboolean open);
 qboolean	CM_HeadnodeVisible (int nodenum, qbyte *visbits);
-qboolean	CM_AreasConnected (int area1, int area2);
+qboolean	VARGS CM_AreasConnected (int area1, int area2);
 int		CM_NumClusters (void);
 int		CM_ClusterSize (void);
 int		CM_LeafContents (int leafnum);
@@ -824,7 +824,7 @@ struct model_s *CM_TempBoxModel(vec3_t mins, vec3_t maxs);
 
 void Mod_ParseInfoFromEntityLump(char *data);
 
-void	CMQ2_SetAreaPortalState (int portalnum, qboolean open);
+void	VARGS CMQ2_SetAreaPortalState (int portalnum, qboolean open);
 #endif
 
 
diff --git a/engine/gl/gl_ppl.c b/engine/gl/gl_ppl.c
index 528698a18..aeae4c56b 100644
--- a/engine/gl/gl_ppl.c
+++ b/engine/gl/gl_ppl.c
@@ -1806,6 +1806,75 @@ void PPL_BaseBModelTextures(entity_t *e)
 		R_IBrokeTheArrays();
 }
 
+void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
+void PerpendicularVector( vec3_t dst, const vec3_t src );
+void R_DrawBeam( entity_t *e )
+{
+#define NUM_BEAM_SEGS 6
+
+	int	i;
+	float r, g, b;
+
+	vec3_t perpvec;
+	vec3_t direction, normalized_direction;
+	vec3_t	start_points[NUM_BEAM_SEGS], end_points[NUM_BEAM_SEGS];
+	vec3_t oldorigin, origin;
+
+	oldorigin[0] = e->oldorigin[0];
+	oldorigin[1] = e->oldorigin[1];
+	oldorigin[2] = e->oldorigin[2];
+
+	origin[0] = e->origin[0];
+	origin[1] = e->origin[1];
+	origin[2] = e->origin[2];
+
+	normalized_direction[0] = direction[0] = oldorigin[0] - origin[0];
+	normalized_direction[1] = direction[1] = oldorigin[1] - origin[1];
+	normalized_direction[2] = direction[2] = oldorigin[2] - origin[2];
+
+	if ( VectorNormalize( normalized_direction ) == 0 )
+		return;
+
+	PerpendicularVector( perpvec, normalized_direction );
+	VectorScale( perpvec, e->frame / 2, perpvec );
+
+	for ( i = 0; i < 6; i++ )
+	{
+		RotatePointAroundVector( start_points[i], normalized_direction, perpvec, (360.0/NUM_BEAM_SEGS)*i );
+		VectorAdd( start_points[i], origin, start_points[i] );
+		VectorAdd( start_points[i], direction, end_points[i] );
+	}
+
+	qglDisable( GL_TEXTURE_2D );
+	qglEnable( GL_BLEND );
+	qglDepthMask( GL_FALSE );
+	qglDisable(GL_ALPHA_TEST);
+
+	r = ( d_8to24rgbtable[e->skinnum & 0xFF] ) & 0xFF;
+	g = ( d_8to24rgbtable[e->skinnum & 0xFF] >> 8 ) & 0xFF;
+	b = ( d_8to24rgbtable[e->skinnum & 0xFF] >> 16 ) & 0xFF;
+
+	r *= 1/255.0F;
+	g *= 1/255.0F;
+	b *= 1/255.0F;
+
+	qglColor4f( r, g, b, e->alpha );
+
+	qglBegin( GL_TRIANGLE_STRIP );
+	for ( i = 0; i < NUM_BEAM_SEGS; i++ )
+	{
+		qglVertex3fv( start_points[i] );
+		qglVertex3fv( end_points[i] );
+		qglVertex3fv( start_points[(i+1)%NUM_BEAM_SEGS] );
+		qglVertex3fv( end_points[(i+1)%NUM_BEAM_SEGS] );
+	}
+	qglEnd();
+
+	qglEnable( GL_TEXTURE_2D );
+	qglDisable( GL_BLEND );
+	qglDepthMask( GL_TRUE );
+}
+
 void PPL_BaseEntTextures(void)
 {
 	extern qboolean r_inmirror;
@@ -1849,6 +1918,11 @@ void PPL_BaseEntTextures(void)
 				continue;
 		}
 
+		if (currententity->flags & Q2RF_BEAM)
+		{
+			R_DrawBeam(currententity);
+			continue;
+		}
 		if (!currententity->model)
 			continue;
 
@@ -2419,6 +2493,9 @@ void PPL_DrawEntFullBrights(void)
 		if (!Cam_DrawPlayer(0, currententity->keynum-1))
 			continue;
 
+		if (currententity->flags & Q2RF_BEAM)
+			continue;
+
 		if (!currententity->model)
 			continue;
 
diff --git a/engine/gl/gl_rmain.c b/engine/gl/gl_rmain.c
index 0e7307af0..3f26dbf6e 100644
--- a/engine/gl/gl_rmain.c
+++ b/engine/gl/gl_rmain.c
@@ -731,6 +731,9 @@ void GLR_DrawEntitiesOnList (void)
 		if (!Cam_DrawPlayer(0, currententity->keynum-1))
 			continue;
 
+		if (currententity->flags & Q2RF_BEAM)
+			continue;
+
 		if (!currententity->model)
 			continue;
 
@@ -787,6 +790,9 @@ void GLR_DrawEntitiesOnList (void)
 		if (cl.viewentity[r_refdef.currentplayernum] && currententity->keynum == cl.viewentity[r_refdef.currentplayernum])
 			continue;
 
+		if (currententity->flags & Q2RF_BEAM)
+			continue;
+
 		if (!currententity->model)
 			continue;
 
diff --git a/engine/gl/gl_rsurf.c b/engine/gl/gl_rsurf.c
index ca6350137..1b261e5c0 100644
--- a/engine/gl/gl_rsurf.c
+++ b/engine/gl/gl_rsurf.c
@@ -3899,7 +3899,7 @@ void GL_BuildLightmaps (void)
 		gl_lightmap_format = GL_RGB;
 	if (COM_CheckParm ("-lm_4"))
 		gl_lightmap_format = GL_RGBA;
-	if (*gl_lightmapmode.string)
+/*	if (*gl_lightmapmode.string)
 	{
 		switch(*gl_lightmapmode.string)
 		{
@@ -3924,6 +3924,7 @@ void GL_BuildLightmaps (void)
 			break;
 		}
 	}
+*/
 	if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA)
 		gl_lightmap_format = GL_RGB;
 
diff --git a/engine/gl/gl_warp.c b/engine/gl/gl_warp.c
index 79cd5c5b4..cd1b9a022 100644
--- a/engine/gl/gl_warp.c
+++ b/engine/gl/gl_warp.c
@@ -401,7 +401,7 @@ void R_DrawSkyChain (msurface_t *s)
 
 	GL_DisableMultitexture();
 
-	if (r_fastsky.value||!solidskytexture)	//this is for visability only... we'd otherwise not stoop this low (and this IS low)
+	if (r_fastsky.value||(!solidskytexture&&!usingskybox))	//this is for visability only... we'd otherwise not stoop this low (and this IS low)
 	{
 		int fc;
 		qbyte *pal;