download gl_model_alias.c
Language: C
License: GPL
Copyright: (C) 1996-1997 Id Software, Inc.
LOC: 200
Project Info
QuakeForge(quake)
Server: SourceForge
Type: cvs
...ake\quake\newtree32\source\
   .cvsignore
   .gdbinit
   .indent.pro
   buildnum.c
   cd_dos.c
   cd_linux.c
   cd_null.c
   cd_sdl.c
   cd_sgi.c
   cd_win.c
   checksum.c
   cl_cam.c
   cl_cmd.c
   cl_cvar.c
   cl_demo.c
   cl_ents.c
   cl_input.c
   cl_main.c
   cl_misc.c
   cl_parse.c
   cl_pred.c
   cl_slist.c
   cl_sys_sdl.c
   cl_sys_unix.c
   cl_sys_win.c
   cl_tent.c
   cmd.c
   com.c
   console.c
   context_x11.c
   crc.c
   cvar.c
   d_edge.c
   d_fill.c
   d_init.c
   d_modech.c
   d_part.c
   d_polyse.c
   d_scan.c
   d_sky.c
   d_sprite.c
   d_surf.c
   d_vars.c
   d_zpoint.c
   dga_check.c
   dirent.c
   draw.c
   fbset.c
   fbset_modes_y.y
   fnmatch.c
   fractalnoise.c
   gl_draw.c
   gl_dyn_fires.c
   gl_dyn_part.c
   gl_dyn_textures.c
   gl_mesh.c
   gl_model_alias.c
   gl_model_brush.c
   gl_model_fullbright.c
   gl_model_sprite.c
   gl_ngraph.c
   gl_rlight.c
   gl_rmain.c
   gl_rmisc.c
   gl_rsurf.c
   gl_screen.c
   gl_skin.c
   gl_sky.c
   gl_sky_clip.c
   gl_view.c
   gl_warp.c
   hash.c
   in_fbdev.c
   in_ggi.c
   in_null.c
   in_sdl.c
   in_svgalib.c
   in_win.c
   in_x11.c
   info.c
   joy_linux.c
   joy_null.c
   joy_win.c
   keys.c
   link.c
   locs.c
   Makefile.am
   makefile.mgw
   makefile.win
   mathlib.c
   mdfour.c
   menu.c
   model.c
   model_alias.c
   model_brush.c
   model_sprite.c
   msg.c
   net_chan.c
   net_com.c
   net_packetlog.c
   net_udp.c
   net_udp6.c
   nonintel.c
   pcx.c
   pmove.c
   pmovetst.c
   pr_edict.c
   pr_exec.c
   pr_offs.c
   qargs.c
   qendian.c
   qfgl_ext.c
   quakefs.c
   quakeio.c
   r_aclip.c
   r_alias.c
   r_bsp.c
   r_draw.c
   r_edge.c
   r_efrag.c
   r_light.c
   r_main.c
   r_misc.c
   r_part.c
   r_sky.c
   r_sprite.c
   r_surf.c
   r_vars.c
   r_view.c
   sbar.c
   screen.c
   sizebuf.c
   skin.c
   snd_alsa_0_5.c
   snd_alsa_0_6.c
   snd_disk.c
   snd_dma.c
   snd_mem.c
   snd_mix.c
   snd_null.c
   snd_oss.c
   snd_sdl.c
   snd_sgi.c
   snd_sun.c
   snd_win.c
   sv_ccmds.c
   sv_cvar.c
   sv_ents.c
   sv_init.c
   sv_main.c
   sv_misc.c
   sv_model.c
   sv_move.c
   sv_nchan.c
   sv_phys.c
   sv_pr_cmds.c
   sv_progs.c
   sv_send.c
   sv_sys_unix.c
   sv_sys_win.c
   sv_user.c
   sw_model_alias.c
   sw_model_brush.c
   sw_model_sprite.c
   sw_skin.c
   sw_view.c
   sys_null.c
   sys_unix.c
   sys_win.c
   teamplay.c
   tga.c
   va.c
   ver_check.c
   vid.c
   vid_3dfxsvga.c
   vid_common_gl.c
   vid_fbdev.c
   vid_ggi.c
   vid_glx.c
   vid_mgl.c
   vid_null.c
   vid_sdl.c
   vid_sgl.c
   vid_svgalib.c
   vid_wgl.c
   vid_win.c
   vid_x11.c
   wad.c
   world.c
   zone.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
	gl_model.c

	model loading and caching

	Copyright (C) 1996-1997  Id Software, Inc.

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to:

		Free Software Foundation, Inc.
		59 Temple Place - Suite 330
		Boston, MA  02111-1307, USA

	$Id: gl_model_alias.c,v 1.1.1.1 2001/03/06 09:33:29 lordhavoc Exp $
*/

// models are the only shared resource between a client and server running
// on the same machine.

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

#include "console.h"
#include "glquake.h"
#include "model.h"
#include "qendian.h"
#include "server.h"
#include "skin.h"

extern model_t *loadmodel;

/*
	ALIAS MODELS
*/

extern aliashdr_t *pheader;

extern stvert_t stverts[MAXALIASVERTS];
extern mtriangle_t triangles[MAXALIASTRIS];

// a pose is a single set of vertexes.  a frame may be
// an animating sequence of poses
extern trivertx_t *poseverts[MAXALIASFRAMES];
extern int  posenum;

//=========================================================

/*
	Mod_FloodFillSkin

	Fill background pixels so mipmapping doesn't have haloes - Ed
*/

typedef struct {
	short       x, y;
} floodfill_t;

extern unsigned int d_8to24table[];

// must be a power of 2
#define FLOODFILL_FIFO_SIZE 0x1000
#define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)

#define FLOODFILL_STEP( off, dx, dy ) \
{ \
	if (pos[off] == fillcolor) \
	{ \
		pos[off] = 255; \
		fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
		inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
	} \
	else if (pos[off] != 255) fdc = pos[off]; \
}

void
Mod_FloodFillSkin (byte * skin, int skinwidth, int skinheight)
{
	byte        fillcolor = *skin;		// assume this is the pixel to fill
	floodfill_t fifo[FLOODFILL_FIFO_SIZE];
	int         inpt = 0, outpt = 0;
	int         filledcolor = -1;
	int         i;

	if (filledcolor == -1) {
		filledcolor = 0;
		// attempt to find opaque black
		for (i = 0; i < 256; ++i)
			if (d_8to24table[i] == (255 << 0))	// alpha 1.0
			{
				filledcolor = i;
				break;
			}
	}
	// can't fill to filled color or to transparent color (used as visited
	// marker)
	if ((fillcolor == filledcolor) || (fillcolor == 255)) {
		// printf( "not filling skin from %d to %d\n", fillcolor, filledcolor 
		// );
		return;
	}

	fifo[inpt].x = 0, fifo[inpt].y = 0;
	inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;

	while (outpt != inpt) {
		int         x = fifo[outpt].x, y = fifo[outpt].y;
		int         fdc = filledcolor;
		byte       *pos = &skin[x + skinwidth * y];

		outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;

		if (x > 0)
			FLOODFILL_STEP (-1, -1, 0);
		if (x < skinwidth - 1)
			FLOODFILL_STEP (1, 1, 0);
		if (y > 0)
			FLOODFILL_STEP (-skinwidth, 0, -1);
		if (y < skinheight - 1)
			FLOODFILL_STEP (skinwidth, 0, 1);
		skin[x + skinwidth * y] = fdc;
	}
}

int         Mod_Fullbright (byte * skin, int width, int height, char *name);

void       *
Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group)
{
	char        name[32];
	int         fbtexnum;

	Mod_FloodFillSkin (skin, pheader->mdl.skinwidth, pheader->mdl.skinheight);
	// save 8 bit texels for the player model to remap
	if (!strcmp (loadmodel->name, "progs/player.mdl")) {
		if (skinsize > sizeof (player_8bit_texels))
			SV_Error ("Player skin too large");
		memcpy (player_8bit_texels, skin, skinsize);
	}

	if (group) {
		snprintf (name, sizeof (name), "fb_%s_%i_%i", loadmodel->name, snum,
				  gnum);
	} else {
		snprintf (name, sizeof (name), "fb_%s_%i", loadmodel->name, snum);
	}
	fbtexnum =
		Mod_Fullbright (skin + 1, pheader->mdl.skinwidth,
						pheader->mdl.skinheight, name);
	if ((loadmodel->hasfullbrights = (fbtexnum))) {
		pheader->gl_fb_texturenum[snum][gnum] = fbtexnum;
	}
	if (group) {
		snprintf (name, sizeof (name), "%s_%i_%i", loadmodel->name, snum, gnum);
	} else {
		snprintf (name, sizeof (name), "%s_%i", loadmodel->name, snum);
	}
	pheader->gl_texturenum[snum][gnum] =
		GL_LoadTexture (name, pheader->mdl.skinwidth,
						pheader->mdl.skinheight, skin, true, false, 1);
	// alpha param was true for non group skins
	return skin + skinsize;
}

/*
	Mod_LoadAllSkins
*/
void       *
Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex)
{
	int         i, j, k;
	int         skinsize;
	byte       *skin;
	daliasskingroup_t *pinskingroup;
	int         groupskins;
	daliasskininterval_t *pinskinintervals;

	if (numskins < 1 || numskins > MAX_SKINS)
		SV_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);

	skinsize = pheader->mdl.skinwidth * pheader->mdl.skinheight;

	for (i = 0; i < numskins; i++) {
		if (pskintype->type == ALIAS_SKIN_SINGLE) {
			skin = (byte *) (pskintype + 1);
			skin = Mod_LoadSkin (skin, skinsize, i, 0, false);

			for (j = 1; j < 4; j++) {
				pheader->gl_texturenum[i][j] = pheader->gl_texturenum[i][j - 1];
				pheader->gl_fb_texturenum[i][j] =
					pheader->gl_fb_texturenum[i][j - 1];
			}
		} else {
			// animating skin group.  yuck.
			// Con_Printf("Animating Skin Group, if you get this message
			// please notify warp@debian.org\n");
			pskintype++;
			pinskingroup = (daliasskingroup_t *) pskintype;
			groupskins = LittleLong (pinskingroup->numskins);
			pinskinintervals = (daliasskininterval_t *) (pinskingroup + 1);

			pskintype = (void *) (pinskinintervals + groupskins);
			skin = (byte *) pskintype;

			for (j = 0; j < groupskins; j++) {
				skin = Mod_LoadSkin (skin, skinsize, i, j & 3, true);
			}
			k = j;
			for ( /* */ ; j < 4; j++) {
				pheader->gl_texturenum[i][j] = pheader->gl_texturenum[i][j - k];
				pheader->gl_fb_texturenum[i][j] =
					pheader->gl_fb_texturenum[i][j - k];
			}
		}
		pskintype = (daliasskintype_t *) skin;
	}

	return pskintype;
}

/*
	Mod_LoadAliasFrame
*/
void *
Mod_LoadAliasFrame (void *pin, maliasframedesc_t *frame)
{
	trivertx_t *pinframe;
	int         i;
	daliasframe_t *pdaliasframe;

	pdaliasframe = (daliasframe_t *) pin;

	strcpy (frame->name, pdaliasframe->name);
	frame->firstpose = posenum;
	frame->numposes = 1;

	for (i = 0; i < 3; i++) {	// byte values, don't worry about endianness
		frame->bboxmin.v[i] = pdaliasframe->bboxmin.v[i];
		frame->bboxmin.v[i] = pdaliasframe->bboxmax.v[i];
	}

	pinframe = (trivertx_t *) (pdaliasframe + 1);

	poseverts[posenum] = pinframe;
	posenum++;

	pinframe += pheader->mdl.numverts;

	return (void *) pinframe;
}

/*
	Mod_LoadAliasGroup
*/
void *
Mod_LoadAliasGroup (void *pin, maliasframedesc_t *frame)
{
	daliasgroup_t *pingroup;
	int         i, numframes;
	daliasinterval_t *pin_intervals;
	void       *ptemp;

	pingroup = (daliasgroup_t *) pin;

	numframes = LittleLong (pingroup->numframes);

	frame->firstpose = posenum;
	frame->numposes = numframes;

	for (i = 0; i < 3; i++) {
		// these are byte values, so we don't have to worry about endianness
		frame->bboxmin.v[i] = pingroup->bboxmin.v[i];
		frame->bboxmin.v[i] = pingroup->bboxmax.v[i];
	}

	pin_intervals = (daliasinterval_t *) (pingroup + 1);

	frame->interval = LittleFloat (pin_intervals->interval);

	pin_intervals += numframes;

	ptemp = (void *) pin_intervals;

	for (i = 0; i < numframes; i++) {
		poseverts[posenum] = (trivertx_t *) ((daliasframe_t *) ptemp + 1);
		posenum++;
		ptemp =	(trivertx_t *) ((daliasframe_t *) ptemp + 1) + pheader->mdl.numverts;
	}
	return ptemp;
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us