From 6a8837801b8272f311dcb0c39e4b6b72b0a05a97 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 18 Apr 2008 10:11:43 +0000 Subject: [PATCH] changed cl_stainmaps to be a loadtime cvar which decides whether to allocate stainmaps at all, this saves some memory if it's 0 (which is the default) changed stainmap allocation to lump all allocations into one big one, this saves 1.5MB of memory system overhead (tracking about 28000 allocations for stainmaps in cavetest2.bsp has a lot of overhead) and probably a good deal more malloc overhead on top of that git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8258 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_particles.c | 23 ++++++++++------------- gl_rmain.c | 2 +- gl_rsurf.c | 23 ++++++++++++++++++----- model_brush.c | 29 ++++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/cl_particles.c b/cl_particles.c index 71071548..b491a0f2 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -656,7 +656,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); } else if (effectnameindex == EFFECT_TE_SPIKEQUAD) @@ -676,7 +676,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); CL_AllocLightFlash(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE); } @@ -697,7 +697,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); } else if (effectnameindex == EFFECT_TE_SUPERSPIKEQUAD) @@ -717,7 +717,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); CL_AllocLightFlash(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE); } @@ -741,7 +741,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o else if (effectnameindex == EFFECT_TE_PLASMABURN) { // plasma scorch mark - if (cl_stainmaps.integer) R_Stain(center, 48, 96, 96, 96, 32, 128, 128, 128, 32); + R_Stain(center, 48, 96, 96, 96, 32, 128, 128, 128, 32); CL_SpawnDecalParticleForPoint(center, 6, 6, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); CL_AllocLightFlash(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE); } @@ -759,7 +759,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); } else if (effectnameindex == EFFECT_TE_GUNSHOTQUAD) @@ -776,7 +776,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o } } // bullet hole - if (cl_stainmaps.integer) R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); + R_Stain(center, 32, 96, 96, 96, 24, 128, 128, 128, 24); CL_SpawnDecalParticleForPoint(center, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); CL_AllocLightFlash(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE); } @@ -884,8 +884,7 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o else if (effectnameindex == EFFECT_TE_TEI_PLASMAHIT) { float f; - if (cl_stainmaps.integer) - R_Stain(center, 40, 96, 96, 96, 40, 128, 128, 128, 40); + R_Stain(center, 40, 96, 96, 96, 40, 128, 128, 128, 40); CL_SpawnDecalParticleForPoint(center, 6, 8, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); if (cl_particles_smoke.integer) for (f = 0;f < count;f += 4.0f / cl_particles_quality.value) @@ -1387,8 +1386,7 @@ void CL_ParticleExplosion (const vec3_t org) trace_t trace; //vec3_t v; //vec3_t v2; - if (cl_stainmaps.integer) - R_Stain(org, 96, 80, 80, 80, 64, 176, 176, 176, 64); + R_Stain(org, 96, 80, 80, 80, 64, 176, 176, 176, 64); CL_SpawnDecalParticleForPoint(org, 40, 48, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF); if (cl_particles_quake.integer) @@ -2355,8 +2353,7 @@ void R_DrawParticles (void) // blood - splash on solid if (trace.hitq3surfaceflags & Q3SURFACEFLAG_NOMARKS) goto killparticle; - if (cl_stainmaps.integer) - R_Stain(p->org, 32, 32, 16, 16, (int)(p->alpha * p->size * (1.0f / 40.0f)), 192, 48, 48, (int)(p->alpha * p->size * (1.0f / 40.0f))); + R_Stain(p->org, 32, 32, 16, 16, (int)(p->alpha * p->size * (1.0f / 40.0f)), 192, 48, 48, (int)(p->alpha * p->size * (1.0f / 40.0f))); if (cl_decals.integer) { // create a decal for the blood splat diff --git a/gl_rmain.c b/gl_rmain.c index 76864258..2ce371f1 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -5680,7 +5680,7 @@ static void RSurf_DrawBatch_GL11_VertexColor(int texturenumsurfaces, msurface_t int i; float *c; // TODO: optimize - if (texturesurfacelist[0]->lightmapinfo && texturesurfacelist[0]->lightmapinfo->stainsamples) + if (texturesurfacelist[0]->lightmapinfo) { // generate color arrays for the surfaces in this list for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++) diff --git a/gl_rsurf.c b/gl_rsurf.c index e7d39184..23e6f3af 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -99,12 +99,25 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface) // scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will // be doubled during rendering to achieve 2x overbright // (0 = 0.0, 128 = 1.0, 256 = 2.0) - for (i = 0;i < size;i++, bl += 3, stain += 3, out += 4) + if (stain) { - l = (bl[0] * stain[0]) >> 16;out[2] = min(l, 255); - l = (bl[1] * stain[1]) >> 16;out[1] = min(l, 255); - l = (bl[2] * stain[2]) >> 16;out[0] = min(l, 255); - out[3] = 255; + for (i = 0;i < size;i++, bl += 3, stain += 3, out += 4) + { + l = (bl[0] * stain[0]) >> 16;out[2] = min(l, 255); + l = (bl[1] * stain[1]) >> 16;out[1] = min(l, 255); + l = (bl[2] * stain[2]) >> 16;out[0] = min(l, 255); + out[3] = 255; + } + } + else + { + for (i = 0;i < size;i++, bl += 3, out += 4) + { + l = bl[0] >> 8;out[2] = min(l, 255); + l = bl[1] >> 8;out[1] = min(l, 255); + l = bl[2] >> 8;out[0] = min(l, 255); + out[3] = 255; + } } R_UpdateTexture(surface->lightmaptexture, templight, surface->lightmapinfo->lightmaporigin[0], surface->lightmapinfo->lightmaporigin[1], smax, tmax); diff --git a/model_brush.c b/model_brush.c index 134b8959..dbf98b02 100644 --- a/model_brush.c +++ b/model_brush.c @@ -2410,11 +2410,6 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l) ssize = (surface->lightmapinfo->extents[0] >> 4) + 1; tsize = (surface->lightmapinfo->extents[1] >> 4) + 1; - // stainmap for permanent marks on walls - surface->lightmapinfo->stainsamples = (unsigned char *)Mem_Alloc(loadmodel->mempool, ssize * tsize * 3); - // clear to white - memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3); - if (!lightmaptexture || !Mod_Q1BSP_AllocLightmapBlock(&allocState, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy)) { // allocate a texture pool if we need it @@ -2451,6 +2446,30 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l) } } + + if (cl_stainmaps.integer) + { + // allocate stainmaps for permanent marks on walls + int stainmapsize = 0; + unsigned char *stainsamples = NULL; + for (surfacenum = 0, surface = loadmodel->data_surfaces;surfacenum < count;surfacenum++, surface++) + { + ssize = (surface->lightmapinfo->extents[0] >> 4) + 1; + tsize = (surface->lightmapinfo->extents[1] >> 4) + 1; + stainmapsize += ssize * tsize * 3; + } + // allocate and clear to white + stainsamples = (unsigned char *)Mem_Alloc(loadmodel->mempool, stainmapsize); + memset(stainsamples, 255, stainmapsize); + // assign pointers + for (surfacenum = 0, surface = loadmodel->data_surfaces;surfacenum < count;surfacenum++, surface++) + { + ssize = (surface->lightmapinfo->extents[0] >> 4) + 1; + tsize = (surface->lightmapinfo->extents[1] >> 4) + 1; + surface->lightmapinfo->stainsamples = stainsamples; + stainsamples += ssize * tsize * 3; + } + } } // generate ushort elements array if possible -- 2.39.2