ent_support.txt

来自「quake1 dos源代码最新版本」· 文本 代码 · 共 201 行

TXT
201
字号
================================================================
Title         : Tutorial: Implementing .ENT support into the Quake engine
Date          : 2001-12-29
Filename      : ENT.TXT
Author        : Matthias "Maddes" Buecher
Email Address : maddes@go.to
Homepage      : Quake Info Pool
				http://www.quake-info-pool.net/
				Quake Standards Group (short QSG)
				http://www.quakesource.org/
Complexity    : Moderate
================================================================


Introduction
============
Especially server admins have their harddisk filled with duplicates of several
maps with modified entity lists for several addons. With this tutorial you just
have to put the modified .ENT file into the addon's MAPS folder.

WARNING!!!
Mutiple line comments enclosed with /* and */ do NOT work, use single line
comments starting with // in .ENT files


Definition
==========
When the engine loads a map (.BSP file) it shall search for a corresponding .ENT
file.

As there could be a mixture of .BSP and .ENT files for different addons, the
engine shall not search .ENT files further back than the folder the .BSP file
was loaded from.

Examples:
A) The engine loads the original map E1M1.BSP from the ID1 folder and the
   modified entity list E1M1.ENT from the CTF folder.
B) If it finds E1M1.BSP in the CTF folder, it will not load E1M1.ENT from the
   ID1 folder, only from the CTF folder if available. This will avoid loading
   entity changes not done for this addon (e.g. which were done for normal
   deathmatch).

Hence .ENT support consists of two new functionalities:
1. Finding the last searchpath of a directory
   (which needs my tutorial for additonal file information)
2. .ENT support itself


Implementation
==============
I you didn't already implemented my additonal file information tutorial, then
please do so now.

1. Finding the last searchpath of a directory
---------------------------------------------
The function shall find the last searchpath of the same directory of a given
searchpath. So it just goes through the list and compares the directory names
with the one of the given searchpath, until they do not match. The last match is
the wanted result.
Insert the following function at the end of COMMON.C ...

// 2001-09-12 Finding the last searchpath of a directory  start
/*
============
COM_GetDirSearchPath

Find the last searchpath entry of the same directory of the given searchpath
============
*/
searchpath_t *COM_GetDirSearchPath(searchpath_t *startsearch)
{
	searchpath_t *search, *lastsearch;

    lastsearch = startsearch;

	while ( (search = lastsearch->next) )
	{
		if (strcmp(search->filename, startsearch->filename))	// different directories, then stop here
		{
			break;
		}
		lastsearch = search;
	}

	return lastsearch;
}
// 2001-09-12 Finding the last searchpath of a directory  end

Also put a declaration of this function at the end of COMMON.H.


Unfortunately searchpath entries of PAK files do not contain the directory, so
we have to fix this little oversight in "COM_AddGameDirectory" of COMMON.C.
Before...

//
// add any pak files in the format pak0.pak pak1.pak, ...
//
	for (i=0 ; ; i++)
	{
		...
		search = Hunk_Alloc (sizeof(searchpath_t));

... and after ...

		search->pack = pak;

... insert the following line ...

		strcpy (search->filename, dir);	// 2001-09-12 Finding the last searchpath of a directory by Maddes



2. .ENT support itself
----------------------
All requirements are now implemented, so you can finally add .ENT support to
your engine.
We'll add a new console variable to switch .ENT support on and off. In
Mod_LoadEntities we initialize the entitiy pointer and check if .ENT support is
wanted. If wanted we create the name of the .ENT file (<mapname>.ent) and try to
load it. When the file was loaded, we check if its path is behind the path of
the map, if not the .ENT file is used for the maps loadmodel and exit the
function. In all other cases the original id code is processed.

You have to do the changes in MODEL.C and GL_MODEL.C.

First change the definition and declaration of Mod_LoadEntities to accept a
pointer to the map's file info...

void Mod_LoadEntities (lump_t *l, loadedfile_t *map_fileinfo)	// 2001-09-12 .ENT support by Maddes

Put the following code right at the top of Mod_LoadEntities...

// 2001-09-12 .ENT support by Maddes  start
	char	entfilename[1024];
	loadedfile_t	*fileinfo;
	searchpath_t	*s_check;

	loadmodel->entities = NULL;

	if (external_ent->value)
	{
		// check for a .ENT file
		strcpy(entfilename, loadmodel->name);
		COM_StripExtension(entfilename, entfilename);
		strcat(entfilename, ".ent");

		fileinfo = COM_LoadHunkFile (entfilename);
		if (fileinfo && fileinfo->filelen)
		{
			// .ENT file only allowed from same directory of map file or another directory before in the searchpath
			s_check = COM_GetDirSearchPath(map_fileinfo->path);	// get last searchpath of map directory
			while ( (s_check = s_check->next) )		// next searchpath
			{
				if (s_check == fileinfo->path)	// found .ENT searchpath = after map directory
				{
					Con_DPrintf("%s not allowed from %s as map is from %s\n", entfilename, fileinfo->path->pack ? fileinfo->path->pack->filename : fileinfo->path->filename, map_fileinfo->path->pack ? map_fileinfo->path->pack->filename : map_fileinfo->path->filename);
					break;
				}
			}

			if (!s_check)	// .ENT searchpath not found = before map directory
			{
				Con_Printf("%s loaded from %s\n", entfilename, fileinfo->path->pack ? fileinfo->path->pack->filename : fileinfo->path->filename);
				loadmodel->entities = fileinfo->data;
				return;
			}
		}

		// no .ENT found, use the original entity list
	}
// 2001-09-12 .ENT support by Maddes  end


As all models are loaded in Mod_LoadModel and BSP models are then processed in
Mod_LoadBrushModel, we must pass the file info up to the Mod_LoadBrushModel
function.
Change the definition and declaration of Mod_LoadBrushModel to...

void Mod_LoadBrushModel (model_t *mod, void *buffer, loadedfile_t *fileinfo)	// 2001-09-12 .ENT support by Maddes

... then change its call in Mod_LoadModel...

		Mod_LoadBrushModel (mod, buf, fileinfo);	// 2001-09-12 .ENT support by Maddes

Now we can pass the file info to Mod_LoadEntities, change its call in
Mod_LoadBrushModel to...

	Mod_LoadEntities (&header->lumps[LUMP_ENTITIES], fileinfo);	// 2001-09-12 .ENT support by Maddes


At last we need to add the console variable, at the top of [GL_]MODEL.C put...

cvar_t	external_ent = {"external_ent", "1", false, false};

... and register it in Mod_Init ...

	Cvar_RegisterVariable (&external_ent);

Recompile and test.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?