From 9808c606d87c5f3b6df0ca0310f719129576fea0 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 23 Dec 2009 07:43:05 +0000 Subject: [PATCH] load maps/levelname_effectinfo.txt in addition to effectinfo.txt git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9636 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_particles.c | 36 +++++++++++++++++++++++------------- sv_main.c | 16 +++++++++++++--- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/cl_particles.c b/cl_particles.c index f76851f8..90c57459 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -221,7 +221,7 @@ cvar_t cl_decals_bias = {CVAR_SAVE, "cl_decals_bias", "0.125", "distance to bias cvar_t cl_decals_max = {CVAR_SAVE, "cl_decals_max", "4096", "maximum number of decals allowed to exist in the world at once"}; -void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) +void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend, const char *filename) { int arrayindex; int argc; @@ -250,7 +250,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) } if (argc < 1) continue; -#define checkparms(n) if (argc != (n)) {Con_Printf("effectinfo.txt:%i: error while parsing: %s given %i parameters, should be %i parameters\n", linenumber, argv[0], argc, (n));break;} +#define checkparms(n) if (argc != (n)) {Con_Printf("%s:%i: error while parsing: %s given %i parameters, should be %i parameters\n", filename, linenumber, argv[0], argc, (n));break;} #define readints(array, n) checkparms(n+1);for (arrayindex = 0;arrayindex < argc - 1;arrayindex++) array[arrayindex] = strtol(argv[1+arrayindex], NULL, 0) #define readfloats(array, n) checkparms(n+1);for (arrayindex = 0;arrayindex < argc - 1;arrayindex++) array[arrayindex] = atof(argv[1+arrayindex]) #define readint(var) checkparms(2);var = strtol(argv[1], NULL, 0) @@ -263,7 +263,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) effectinfoindex++; if (effectinfoindex >= MAX_PARTICLEEFFECTINFO) { - Con_Printf("effectinfo.txt:%i: too many effects!\n", linenumber); + Con_Printf("%s:%i: too many effects!\n", filename, linenumber); break; } for (effectnameindex = 1;effectnameindex < MAX_PARTICLEEFFECTNAME;effectnameindex++) @@ -282,7 +282,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) // if we run out of names, abort if (effectnameindex == MAX_PARTICLEEFFECTNAME) { - Con_Printf("effectinfo.txt:%i: too many effects!\n", linenumber); + Con_Printf("%s:%i: too many effects!\n", filename, linenumber); break; } info = particleeffectinfo + effectinfoindex; @@ -312,7 +312,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) } else if (info == NULL) { - Con_Printf("effectinfo.txt:%i: command %s encountered before effect\n", linenumber, argv[0]); + Con_Printf("%s:%i: command %s encountered before effect\n", filename, linenumber, argv[0]); break; } else if (!strcmp(argv[0], "countabsolute")) {readfloat(info->countabsolute);} @@ -332,7 +332,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) else if (!strcmp(argv[1], "smoke")) info->particletype = pt_smoke; else if (!strcmp(argv[1], "decal")) info->particletype = pt_decal; else if (!strcmp(argv[1], "entityparticle")) info->particletype = pt_entityparticle; - else Con_Printf("effectinfo.txt:%i: unrecognized particle type %s\n", linenumber, argv[1]); + else Con_Printf("%s:%i: unrecognized particle type %s\n", filename, linenumber, argv[1]); info->blendmode = particletype[info->particletype].blendmode; info->orientation = particletype[info->particletype].orientation; } @@ -342,7 +342,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) if (!strcmp(argv[1], "alpha")) info->blendmode = PBLEND_ALPHA; else if (!strcmp(argv[1], "add")) info->blendmode = PBLEND_ADD; else if (!strcmp(argv[1], "invmod")) info->blendmode = PBLEND_INVMOD; - else Con_Printf("effectinfo.txt:%i: unrecognized blendmode %s\n", linenumber, argv[1]); + else Con_Printf("%s:%i: unrecognized blendmode %s\n", filename, linenumber, argv[1]); } else if (!strcmp(argv[0], "orientation")) { @@ -351,7 +351,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) else if (!strcmp(argv[1], "spark")) info->orientation = PARTICLE_SPARK; else if (!strcmp(argv[1], "oriented")) info->orientation = PARTICLE_ORIENTED_DOUBLESIDED; else if (!strcmp(argv[1], "beam")) info->orientation = PARTICLE_HBEAM; - else Con_Printf("effectinfo.txt:%i: unrecognized orientation %s\n", linenumber, argv[1]); + else Con_Printf("%s:%i: unrecognized orientation %s\n", filename, linenumber, argv[1]); } else if (!strcmp(argv[0], "color")) {readints(info->color, 2);} else if (!strcmp(argv[0], "tex")) {readints(info->tex, 2);} @@ -382,7 +382,7 @@ void CL_Particles_ParseEffectInfo(const char *textstart, const char *textend) else if (!strcmp(argv[0], "staintex")) {readints(info->staintex, 2);} else if (!strcmp(argv[0], "stainless")) {info->staintex[0] = -2; info->staincolor[0] = (unsigned int)-1; info->staincolor[1] = (unsigned int)-1;} else - Con_Printf("effectinfo.txt:%i: skipping unknown command %s\n", linenumber, argv[0]); + Con_Printf("%s:%i: skipping unknown command %s\n", filename, linenumber, argv[0]); #undef checkparms #undef readints #undef readfloats @@ -451,16 +451,26 @@ static const char *standardeffectnames[EFFECT_TOTAL] = void CL_Particles_LoadEffectInfo(void) { int i; + int filepass; unsigned char *filedata; fs_offset_t filesize; + char filename[MAX_QPATH]; memset(particleeffectinfo, 0, sizeof(particleeffectinfo)); memset(particleeffectname, 0, sizeof(particleeffectname)); for (i = 0;i < EFFECT_TOTAL;i++) strlcpy(particleeffectname[i], standardeffectnames[i], sizeof(particleeffectname[i])); - filedata = FS_LoadFile("effectinfo.txt", tempmempool, true, &filesize); - if (filedata) + for (filepass = 0;;filepass++) { - CL_Particles_ParseEffectInfo((const char *)filedata, (const char *)filedata + filesize); + if (filepass == 0) + dpsnprintf(filename, sizeof(filename), "effectinfo.txt"); + else if (filepass == 1) + dpsnprintf(filename, sizeof(filename), "maps/%s_effectinfo.txt", cl.levelname); + else + break; + filedata = FS_LoadFile(filename, tempmempool, true, &filesize); + if (!filedata) + continue; + CL_Particles_ParseEffectInfo((const char *)filedata, (const char *)filedata + filesize, filename); Mem_Free(filedata); } } @@ -474,7 +484,7 @@ void CL_ReadPointFile_f (void); void CL_Particles_Init (void) { Cmd_AddCommand ("pointfile", CL_ReadPointFile_f, "display point file produced by qbsp when a leak was detected in the map (a line leading through the leak hole, to an entity inside the level)"); - Cmd_AddCommand ("cl_particles_reloadeffects", CL_Particles_LoadEffectInfo, "reloads effectinfo.txt"); + Cmd_AddCommand ("cl_particles_reloadeffects", CL_Particles_LoadEffectInfo, "reloads effectinfo.txt and maps/levelname_effectinfo.txt (where levelname is the current map)"); Cvar_RegisterVariable (&cl_particles); Cvar_RegisterVariable (&cl_particles_quality); diff --git a/sv_main.c b/sv_main.c index 160fb56c..69208a95 100644 --- a/sv_main.c +++ b/sv_main.c @@ -2697,19 +2697,29 @@ SV_ParticleEffectIndex int SV_ParticleEffectIndex(const char *name) { int i, argc, linenumber, effectnameindex; + int filepass; fs_offset_t filesize; unsigned char *filedata; const char *text, *textstart, *textend; char argv[16][1024]; + char filename[MAX_QPATH]; if (!sv.particleeffectnamesloaded) { sv.particleeffectnamesloaded = true; memset(sv.particleeffectname, 0, sizeof(sv.particleeffectname)); for (i = 0;i < EFFECT_TOTAL;i++) strlcpy(sv.particleeffectname[i], standardeffectnames[i], sizeof(sv.particleeffectname[i])); - filedata = FS_LoadFile("effectinfo.txt", tempmempool, true, &filesize); - if (filedata) + for (filepass = 0;;filepass++) { + if (filepass == 0) + dpsnprintf(filename, sizeof(filename), "effectinfo.txt"); + else if (filepass == 1) + dpsnprintf(filename, sizeof(filename), "maps/%s_effectinfo.txt", sv.name); + else + break; + filedata = FS_LoadFile(filename, tempmempool, true, &filesize); + if (!filedata) + continue; textstart = (const char *)filedata; textend = (const char *)filedata + filesize; text = textstart; @@ -2750,7 +2760,7 @@ int SV_ParticleEffectIndex(const char *name) // if we run out of names, abort if (effectnameindex == SV_MAX_PARTICLEEFFECTNAME) { - Con_Printf("effectinfo.txt:%i: too many effects!\n", linenumber); + Con_Printf("%s:%i: too many effects!\n", filename, linenumber); break; } } -- 2.39.2