Removing .ms2 meshing from GLQuake

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Removing .ms2 meshing from GLQuake

Post by Baker »

1. Open gl_vidnt.c
Find and comment out this:

Code: Select all

//  Baker: no longer need this
//	sprintf (gldir, "%s/glquake", com_gamedir);
//	Sys_mkdir (gldir);
Since the glquake dir where the .ms2 files used to be output will no longer be used.
2. Open gl_model.c
Find "GL_MakeAliasModelDisplayLists (mod, pheader);"

Delete the yellow text above ^^ so it reads like this:

Code: Select all

GL_MakeAliasModelDisplayLists (pheader);
3. Open gl_mesh.c
Find this ...

Code: Select all

/*
================
GL_MakeAliasModelDisplayLists
================
*/
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
{
	int		i, j;
	maliasgroup_t	*paliasgroup;
	int			*cmds;
	trivertx_t	*verts;
	char	cache[MAX_QPATH], fullpath[MAX_OSPATH], *c;
	FILE	*f;
	int		len;
	byte	*data;

	aliasmodel = m;
	paliashdr = hdr;	// (aliashdr_t *)Mod_Extradata (m);

	//
	// look for a cached version
	//
	strcpy (cache, "glquake/");
	COM_StripExtension (m->name+strlen("progs/"), cache+strlen("glquake/"));
	strcat (cache, ".ms2");

	COM_FOpenFile (cache, &f);	
	if (f)
	{
		fread (&numcommands, 4, 1, f);
		fread (&numorder, 4, 1, f);
		fread (&commands, numcommands * sizeof(commands[0]), 1, f);
		fread (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f);
		fclose (f);
	}
	else
	{
		//
		// build it from scratch
		//
		Con_Printf ("meshing %s...\n",m->name);

		BuildTris ();		// trifans or lists

		//
		// save out the cached version
		//
		sprintf (fullpath, "%s/%s", com_gamedir, cache);
		f = fopen (fullpath, "wb");
		if (f)
		{
			fwrite (&numcommands, 4, 1, f);
			fwrite (&numorder, 4, 1, f);
			fwrite (&commands, numcommands * sizeof(commands[0]), 1, f);
			fwrite (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f);
			fclose (f);
		}
	}


	// save the data out

	paliashdr->poseverts = numorder;

	cmds = Hunk_Alloc (numcommands * 4);
	paliashdr->commands = (byte *)cmds - (byte *)paliashdr;
	memcpy (cmds, commands, numcommands * 4);

	verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts 
		* sizeof(trivertx_t) );
	paliashdr->posedata = (byte *)verts - (byte *)paliashdr;
	for (i=0 ; i<paliashdr->numposes ; i++)
		for (j=0 ; j<numorder ; j++)
			*verts++ = poseverts[i][vertexorder[j]];
}
Delete and replace with ...

Code: Select all

void GL_MakeAliasModelDisplayLists (aliashdr_t *paliashdr) {
	int		i, j, *cmds;
	trivertx_t	*verts;

	// Tonik: don't cache anything, because it seems just as fast
	// (if not faster) to rebuild the tris instead of loading them from disk
		BuildTris ();		// trifans or lists

	// save the data out
	paliashdr->poseverts = numorder;

	cmds = Hunk_Alloc (numcommands * 4);
	paliashdr->commands = (byte *)cmds - (byte *)paliashdr;
	memcpy (cmds, commands, numcommands * 4);

   verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t));
	paliashdr->posedata = (byte *)verts - (byte *)paliashdr;
	for (i=0 ; i<paliashdr->numposes ; i++)
		for (j=0 ; j<numorder ; j++)
			*verts++ = poseverts[i][vertexorder[j]];
}
Compile, delete c:\quake\id1\glquake folder. Start up newly compiled glquake and you'll notice it no longer builds the .ms2 files "meshing something.mdl ..." nor does it read them.
MeTcHsteekle
Posts: 399
Joined: Thu May 15, 2008 10:46 pm
Location: its a secret

Post by MeTcHsteekle »

yay :D
bah
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

what are they?
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

ceriux wrote:what are they?
Load up original GLQuake. They are annoying files that senselessly get written to the glquake directory and serve no purpose except to trash up models.
Tomaz
Posts: 67
Joined: Fri Nov 05, 2004 8:21 pm

Post by Tomaz »

WTF?!?!?!?!

First you write a tutorial without a single comment on what is done or why. And then when someone asks what the old code did, you dont even know?

So for those that wonder.

BuildTris() parses all the triangles in the model and builds tri strips and tri fans ( makes the rendering alot faster )

The purpose of the ms2 files was to save out these "commands" that tell the renderer how the tri fans and tri strips are built to avoid having to reparse the model the next time the game was played.

Now as mentioned by TONIK's code comment ( not Baker's ) on a modern computer the parsing is done so fast that caching it does'nt make any sense anymore. The reason the ms2 thrases models is if someone has made a mod with a custum model that has the same name as an original quake model. Because then it will load the .ms2 from the quake id1 dir that is for the original quake model, and use it with the custom model. So the commands for the tri strips and tri fans is'nt correct. This was never an issue if one didnt play mods that shared models with the same name as an original quake model.

After typing this I found out another thing.

Baker, next time you make a tutorial based on code you didnt write ( which I assume you havent given the fact the code has a comment by Tonik and the fact you dont even know what the code does or even mention why one should remove the mod part when calling the function ) please mention who wrote the code.
Post Reply