From 984163a013087ab3dafb0e3a86554c7c349cd09f Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 18 Dec 2007 09:32:24 +0000 Subject: [PATCH] moved entity_render_t modellight_* field updates from renderer to client merged entity_render_t colormap_pantscolor and shirtcolor updates to a single function called CL_SetEntityColormapColors other little cleanups git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7819 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 91 ++++++++++++++++++++++++++++---------------------- cl_parse.c | 1 - client.h | 14 +++++--- clvm_cmds.c | 5 +-- csprogs.c | 32 ++++++------------ gl_rmain.c | 60 ++++++--------------------------- model_brush.c | 16 --------- model_shared.c | 12 +++++-- palette.c | 2 +- 9 files changed, 95 insertions(+), 138 deletions(-) diff --git a/cl_main.c b/cl_main.c index 66d68acf..717f156c 100644 --- a/cl_main.c +++ b/cl_main.c @@ -197,7 +197,6 @@ void CL_ClearState(void) ent->state_current.active = true; ent->render.model = cl.worldmodel = NULL; // no world model yet ent->render.alpha = 1; - ent->render.colormap = -1; // no special coloring ent->render.flags = RENDER_SHADOW | RENDER_LIGHT; Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1); CL_UpdateRenderEntity(&ent->render); @@ -497,6 +496,30 @@ static void CL_SoundIndexList_f(void) } } +static void CL_UpdateRenderEntity_Lighting(entity_render_t *ent) +{ + vec3_t tempdiffusenormal; + + // fetch the lighting from the worldmodel data + VectorSet(ent->modellight_ambient, r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f)); + VectorClear(ent->modellight_diffuse); + VectorClear(tempdiffusenormal); + if ((ent->flags & RENDER_LIGHT) && cl.worldmodel && cl.worldmodel->brush.LightPoint) + { + vec3_t org; + Matrix4x4_OriginFromMatrix(&ent->matrix, org); + cl.worldmodel->brush.LightPoint(cl.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal); + } + else // highly rare + VectorSet(ent->modellight_ambient, 1, 1, 1); + + // move the light direction into modelspace coordinates for lighting code + Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, ent->modellight_lightdir); + if(VectorLength2(ent->modellight_lightdir) <= 0) + VectorSet(ent->modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here + VectorNormalize(ent->modellight_lightdir); +} + //static const vec3_t nomodelmins = {-16, -16, -16}; //static const vec3_t nomodelmaxs = {16, 16, 16}; void CL_UpdateRenderEntity(entity_render_t *ent) @@ -550,6 +573,7 @@ void CL_UpdateRenderEntity(entity_render_t *ent) ent->maxs[1] = org[1] + 16; ent->maxs[2] = org[2] + 16; } + CL_UpdateRenderEntity_Lighting(ent); } /* @@ -595,7 +619,6 @@ entity_t *CL_NewTempEntity(void) memset (ent, 0, sizeof(*ent)); r_refdef.entities[r_refdef.numentities++] = &ent->render; - ent->render.colormap = -1; // no special coloring ent->render.alpha = 1; VectorSet(ent->render.colormod, 1, 1, 1); return ent; @@ -828,7 +851,6 @@ void CL_AddQWCTFFlagModel(entity_t *player, int skin) flag->render.model = cl.model_precache[cl.qw_modelindex_flag]; flag->render.skinnum = skin; - flag->render.colormap = -1; // no special coloring flag->render.alpha = 1; VectorSet(flag->render.colormod, 1, 1, 1); // attach the flag to the player matrix @@ -846,6 +868,23 @@ extern void V_FadeViewFlashs(void); extern void V_CalcViewBlend(void); extern void V_CalcRefdef(void); +void CL_SetEntityColormapColors(entity_render_t *ent, int colormap) +{ + const unsigned char *cbcolor; + if (colormap >= 0) + { + cbcolor = palette_rgb_pantscolormap[colormap & 0xF]; + VectorScale(cbcolor, (1.0f / 255.0f), ent->colormap_pantscolor); + cbcolor = palette_rgb_shirtcolormap[(colormap & 0xF0) >> 4]; + VectorScale(cbcolor, (1.0f / 255.0f), ent->colormap_shirtcolor); + } + else + { + VectorClear(ent->colormap_pantscolor); + VectorClear(ent->colormap_shirtcolor); + } +} + // note this is a recursive function, recursionlimit should be 32 or so on the initial call void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolate) { @@ -869,37 +908,11 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod); e->render.entitynumber = e - cl.entities; if (e->state_current.flags & RENDER_COLORMAPPED) - { - unsigned char *cbcolor; - e->render.colormap = e->state_current.colormap; - cbcolor = palette_rgb_pantscolormap[e->render.colormap & 0xF]; - e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f); - cbcolor = palette_rgb_shirtcolormap[(e->render.colormap & 0xF0) >> 4]; - e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f); - } - else if (e->state_current.colormap && cl.scores != NULL && e->state_current.colormap <= cl.maxclients) - { - unsigned char *cbcolor; - e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it - cbcolor = palette_rgb_pantscolormap[e->render.colormap & 0xF]; - e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f); - cbcolor = palette_rgb_shirtcolormap[(e->render.colormap & 0xF0) >> 4]; - e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f); - } + CL_SetEntityColormapColors(&e->render, e->state_current.colormap); + else if (e->state_current.colormap > 0 && e->state_current.colormap <= cl.maxclients && cl.scores != NULL) + CL_SetEntityColormapColors(&e->render, cl.scores[e->state_current.colormap-1].colors); else - { - e->render.colormap = -1; // no special coloring - VectorClear(e->render.colormap_pantscolor); - VectorClear(e->render.colormap_shirtcolor); - } + CL_SetEntityColormapColors(&e->render, -1); e->render.skinnum = e->state_current.skin; if (e->state_current.tagentity) { @@ -1061,9 +1074,6 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat Matrix4x4_CreateFromQuakeEntity(&e->render.matrix, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale); } - // make the other useful stuff - CL_UpdateRenderEntity(&e->render); - // tenebrae's sprites are all additive mode (weird) if (gamemode == GAME_TENEBRAE && e->render.model && e->render.model->type == mod_sprite) e->render.effects |= EF_ADDITIVE; @@ -1081,6 +1091,9 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat e->render.flags |= RENDER_SHADOW; if (e->render.flags & RENDER_VIEWMODEL) e->render.flags |= RENDER_NOSELFSHADOW; + + // make the other useful stuff + CL_UpdateRenderEntity(&e->render); } // creates light and trails from an entity @@ -1453,11 +1466,11 @@ void CL_RelinkWorld(void) entity_t *ent = &cl.entities[0]; // FIXME: this should be done at load ent->render.matrix = identitymatrix; - CL_UpdateRenderEntity(&ent->render); ent->render.flags = RENDER_SHADOW; if (!r_fullbright.integer) ent->render.flags |= RENDER_LIGHT; VectorSet(ent->render.colormod, 1, 1, 1); + CL_UpdateRenderEntity(&ent->render); r_refdef.worldentity = &ent->render; r_refdef.worldmodel = cl.worldmodel; } @@ -1472,7 +1485,6 @@ static void CL_RelinkStaticEntities(void) // if the model was not loaded when the static entity was created we // need to re-fetch the model pointer e->render.model = cl.model_precache[e->state_baseline.modelindex]; - CL_UpdateRenderEntity(&e->render); // either fullbright or lit if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) e->render.flags |= RENDER_LIGHT; @@ -1481,6 +1493,7 @@ static void CL_RelinkStaticEntities(void) e->render.flags |= RENDER_SHADOW; VectorSet(e->render.colormod, 1, 1, 1); R_LerpAnimation(&e->render); + CL_UpdateRenderEntity(&e->render); r_refdef.entities[r_refdef.numentities++] = &e->render; } } @@ -1555,7 +1568,6 @@ static void CL_RelinkEffects(void) ent->render.model = cl.model_precache[e->modelindex]; else ent->render.model = cl.csqc_model_precache[-(e->modelindex+1)]; - ent->render.colormap = -1; // no special coloring ent->render.alpha = 1; VectorSet(ent->render.colormod, 1, 1, 1); @@ -1701,7 +1713,6 @@ static void CL_RelinkQWNails(void) // normal stuff ent->render.model = cl.model_precache[cl.qw_modelindex_spike]; - ent->render.colormap = -1; // no special coloring ent->render.alpha = 1; VectorSet(ent->render.colormod, 1, 1, 1); diff --git a/cl_parse.c b/cl_parse.c index bf0ba3ee..97ec0235 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -1909,7 +1909,6 @@ void CL_ParseStatic (int large) ent->render.framelerp = 0; // make torchs play out of sync ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1); - ent->render.colormap = -1; // no special coloring ent->render.skinnum = ent->state_baseline.skin; ent->render.effects = ent->state_baseline.effects; ent->render.alpha = 1; diff --git a/client.h b/client.h index b98beec1..0d906975 100644 --- a/client.h +++ b/client.h @@ -226,6 +226,12 @@ frameblend_t; // LordHavoc: this struct is intended for the renderer but some fields are // used by the client. +// +// The renderer should not rely on any changes to this struct to be persistent +// across multiple frames because temp entities are wiped every frame, but it +// is acceptable to cache things in this struct that are not critical. +// +// For example the r_cullentities_trace code does such caching. typedef struct entity_render_s { // location @@ -245,9 +251,7 @@ typedef struct entity_render_s model_t *model; // number of the entity represents, or 0 for non-network entities int entitynumber; - // entity shirt and pants colors (-1 if not colormapped) - int colormap; - // literal colors for renderer + // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped vec3_t colormap_pantscolor; vec3_t colormap_shirtcolor; // light, particles, etc @@ -282,11 +286,12 @@ typedef struct entity_render_s // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead frameblend_t frameblend[4]; - // current lighting from map + // current lighting from map (updated ONLY by client code, not renderer) vec3_t modellight_ambient; vec3_t modellight_diffuse; // q3bsp vec3_t modellight_lightdir; // q3bsp + // FIELDS UPDATED BY RENDERER: // last time visible during trace culling double last_trace_visibility; } @@ -1136,6 +1141,7 @@ void CL_Disconnect (void); void CL_Disconnect_f (void); void CL_UpdateRenderEntity(entity_render_t *ent); +void CL_SetEntityColormapColors(entity_render_t *ent, int colormap); void CL_UpdateViewEntities(void); // diff --git a/clvm_cmds.c b/clvm_cmds.c index f19b66db..83b0bf02 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -1257,12 +1257,12 @@ static void VM_CL_makestatic (void) entity_t *staticent = &cl.static_entities[cl.num_static_entities++]; // copy it to the current state + memset(staticent, 0, sizeof(*staticent)); staticent->render.model = CL_GetModelByIndex((int)ent->fields.client->modelindex); staticent->render.frame1 = staticent->render.frame2 = (int)ent->fields.client->frame; staticent->render.framelerp = 0; // make torchs play out of sync staticent->render.frame1time = staticent->render.frame2time = lhrandom(-10, -1); - staticent->render.colormap = (int)ent->fields.client->colormap; // no special coloring staticent->render.skinnum = (int)ent->fields.client->skin; staticent->render.effects = (int)ent->fields.client->effects; staticent->render.alpha = 1; @@ -1282,7 +1282,6 @@ static void VM_CL_makestatic (void) } else Matrix4x4_CreateFromQuakeEntity(&staticent->render.matrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], staticent->render.scale); - CL_UpdateRenderEntity(&staticent->render); // either fullbright or lit if (!(staticent->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) @@ -1290,6 +1289,8 @@ static void VM_CL_makestatic (void) // turn off shadows from transparent objects if (!(staticent->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (staticent->render.alpha >= 1)) staticent->render.flags |= RENDER_SHADOW; + + CL_UpdateRenderEntity(&staticent->render); } else Con_Printf("Too many static entities"); diff --git a/csprogs.c b/csprogs.c index 96a51244..4b04475c 100644 --- a/csprogs.c +++ b/csprogs.c @@ -125,6 +125,7 @@ extern cvar_t cl_noplayershadow; qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) { int renderflags; + int c; float scale; prvm_eval_t *val; entity_t *e; @@ -140,7 +141,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) return false; e->render.model = model; - e->render.colormap = (int)ed->fields.client->colormap; e->render.skinnum = (int)ed->fields.client->skin; e->render.effects |= e->render.model->effects; scale = 1; @@ -195,8 +195,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) // concat the matrices to make the entity relative to its tag Matrix4x4_Concat(&e->render.matrix, &tagmatrix, &matrix2); - // make the other useful stuff - CL_UpdateRenderEntity(&e->render); if(renderflags) { @@ -206,24 +204,13 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) if(renderflags & RF_ADDITIVE) e->render.effects |= EF_ADDITIVE; } - if ((e->render.colormap > 0 && e->render.colormap <= cl.maxclients) || e->render.colormap >= 1024) - { - unsigned char *cbcolor; - int palcol; - if (e->render.colormap >= 1024) - palcol = (unsigned char)(e->render.colormap-1024); - else - palcol = cl.scores[e->render.colormap-1].colors; - - cbcolor = palette_rgb_pantscolormap[palcol & 0xF]; - e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f); - cbcolor = palette_rgb_shirtcolormap[(palcol & 0xF0) >> 4]; - e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f); - e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f); - } + c = (int)ed->fields.client->colormap; + if (c <= 0) + CL_SetEntityColormapColors(&e->render, -1); + else if (c <= cl.maxclients && cl.scores != NULL) + CL_SetEntityColormapColors(&e->render, cl.scores[c-1].colors); + else + CL_SetEntityColormapColors(&e->render, c); // either fullbright or lit if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) @@ -237,6 +224,9 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) if (e->render.flags & RENDER_VIEWMODEL) e->render.flags |= RENDER_NOSELFSHADOW; + // make the other useful stuff + CL_UpdateRenderEntity(&e->render); + return true; } diff --git a/gl_rmain.c b/gl_rmain.c index 091e7e62..06f94247 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1369,11 +1369,11 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl else if (mode == SHADERMODE_LIGHTDIRECTION) { if (r_glsl_permutation->loc_AmbientColor >= 0) - qglUniform3fARB(r_glsl_permutation->loc_AmbientColor, rsurface.modellight_ambient[0] * ambientscale, rsurface.modellight_ambient[1] * ambientscale, rsurface.modellight_ambient[2] * ambientscale); + qglUniform3fARB(r_glsl_permutation->loc_AmbientColor, rsurface.modellight_ambient[0] * ambientscale * r_refdef.lightmapintensity, rsurface.modellight_ambient[1] * ambientscale * r_refdef.lightmapintensity, rsurface.modellight_ambient[2] * ambientscale * r_refdef.lightmapintensity); if (r_glsl_permutation->loc_DiffuseColor >= 0) - qglUniform3fARB(r_glsl_permutation->loc_DiffuseColor, rsurface.modellight_diffuse[0] * diffusescale, rsurface.modellight_diffuse[1] * diffusescale, rsurface.modellight_diffuse[2] * diffusescale); + qglUniform3fARB(r_glsl_permutation->loc_DiffuseColor, rsurface.modellight_diffuse[0] * diffusescale * r_refdef.lightmapintensity, rsurface.modellight_diffuse[1] * diffusescale * r_refdef.lightmapintensity, rsurface.modellight_diffuse[2] * diffusescale * r_refdef.lightmapintensity); if (r_glsl_permutation->loc_SpecularColor >= 0) - qglUniform3fARB(r_glsl_permutation->loc_SpecularColor, rsurface.modellight_diffuse[0] * specularscale, rsurface.modellight_diffuse[1] * specularscale, rsurface.modellight_diffuse[2] * specularscale); + qglUniform3fARB(r_glsl_permutation->loc_SpecularColor, rsurface.modellight_diffuse[0] * specularscale * r_refdef.lightmapintensity, rsurface.modellight_diffuse[1] * specularscale * r_refdef.lightmapintensity, rsurface.modellight_diffuse[2] * specularscale * r_refdef.lightmapintensity); if (r_glsl_permutation->loc_LightDir >= 0) qglUniform3fARB(r_glsl_permutation->loc_LightDir, rsurface.modellight_lightdir[0], rsurface.modellight_lightdir[1], rsurface.modellight_lightdir[2]); } @@ -2141,43 +2141,6 @@ int R_CullBoxCustomPlanes(const vec3_t mins, const vec3_t maxs, int numplanes, c //================================================================================== -static void R_UpdateEntityLighting(entity_render_t *ent) -{ - vec3_t tempdiffusenormal; - - // fetch the lighting from the worldmodel data - VectorSet(ent->modellight_ambient, r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f)); - VectorClear(ent->modellight_diffuse); - VectorClear(tempdiffusenormal); - if ((ent->flags & RENDER_LIGHT) && r_refdef.worldmodel && r_refdef.worldmodel->brush.LightPoint) - { - vec3_t org; - Matrix4x4_OriginFromMatrix(&ent->matrix, org); - r_refdef.worldmodel->brush.LightPoint(r_refdef.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal); - } - else // highly rare - VectorSet(ent->modellight_ambient, 1, 1, 1); - - // move the light direction into modelspace coordinates for lighting code - Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, ent->modellight_lightdir); - if(VectorLength2(ent->modellight_lightdir) > 0) - { - VectorNormalize(ent->modellight_lightdir); - } - else - { - VectorSet(ent->modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here - } - - // scale ambient and directional light contributions according to rendering variables - ent->modellight_ambient[0] *= ent->colormod[0] * r_refdef.lightmapintensity; - ent->modellight_ambient[1] *= ent->colormod[1] * r_refdef.lightmapintensity; - ent->modellight_ambient[2] *= ent->colormod[2] * r_refdef.lightmapintensity; - ent->modellight_diffuse[0] *= ent->colormod[0] * r_refdef.lightmapintensity; - ent->modellight_diffuse[1] *= ent->colormod[1] * r_refdef.lightmapintensity; - ent->modellight_diffuse[2] *= ent->colormod[2] * r_refdef.lightmapintensity; -} - static void R_View_UpdateEntityVisible (void) { int i, renderimask; @@ -2220,10 +2183,6 @@ static void R_View_UpdateEntityVisible (void) r_viewcache.entityvisible[i] = !(ent->flags & renderimask) && ((ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE)) || !R_CullBox(ent->mins, ent->maxs)); } } - - // update entity lighting (even on hidden entities for r_shadows) - for (i = 0;i < r_refdef.numentities;i++) - R_UpdateEntityLighting(r_refdef.entities[i]); } // only used if skyrendermasked, and normally returns false @@ -5365,12 +5324,13 @@ static void RSurf_DrawBatch_GL11_VertexShade(int texturenumsurfaces, msurface_t // TODO: optimize // model lighting VectorCopy(rsurface.modellight_lightdir, lightdir); - ambientcolor[0] = rsurface.modellight_ambient[0] * r * 0.5f; - ambientcolor[1] = rsurface.modellight_ambient[1] * g * 0.5f; - ambientcolor[2] = rsurface.modellight_ambient[2] * b * 0.5f; - diffusecolor[0] = rsurface.modellight_diffuse[0] * r * 0.5f; - diffusecolor[1] = rsurface.modellight_diffuse[1] * g * 0.5f; - diffusecolor[2] = rsurface.modellight_diffuse[2] * b * 0.5f; + f = 0.5f * r_refdef.lightmapintensity; + ambientcolor[0] = rsurface.modellight_ambient[0] * r * f; + ambientcolor[1] = rsurface.modellight_ambient[1] * g * f; + ambientcolor[2] = rsurface.modellight_ambient[2] * b * f; + diffusecolor[0] = rsurface.modellight_diffuse[0] * r * f; + diffusecolor[1] = rsurface.modellight_diffuse[1] * g * f; + diffusecolor[2] = rsurface.modellight_diffuse[2] * b * f; if (VectorLength2(diffusecolor) > 0) { // generate color arrays for the surfaces in this list diff --git a/model_brush.c b/model_brush.c index 8d671c00..3baf1aeb 100644 --- a/model_brush.c +++ b/model_brush.c @@ -3534,14 +3534,6 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend) if (loadmodel->brush.numsubmodels) loadmodel->brush.submodels = (model_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brush.numsubmodels * sizeof(model_t *)); - if (loadmodel->isworldmodel) - { - // clear out any stale submodels or worldmodels lying around - // if we did this clear before now, an error might abort loading and - // leave things in a bad state - Mod_RemoveStaleWorldModels(loadmodel); - } - // LordHavoc: to clear the fog around the original quake submodel code, I // will explain: // first of all, some background info on the submodels: @@ -5727,14 +5719,6 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend) loadmodel->brush.num_leafs = 0; Mod_Q3BSP_RecursiveFindNumLeafs(loadmodel->brush.data_nodes); - if (loadmodel->isworldmodel) - { - // clear out any stale submodels or worldmodels lying around - // if we did this clear before now, an error might abort loading and - // leave things in a bad state - Mod_RemoveStaleWorldModels(loadmodel); - } - mod = loadmodel; for (i = 0;i < loadmodel->brush.numsubmodels;i++) { diff --git a/model_shared.c b/model_shared.c index c376d4af..5825d1fa 100644 --- a/model_shared.c +++ b/model_shared.c @@ -245,11 +245,17 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea VectorSet(mod->rotatedmins, -mod->radius, -mod->radius, -mod->radius); VectorSet(mod->rotatedmaxs, mod->radius, mod->radius, mod->radius); - // if we're loading a worldmodel, then this is a level change, and we - // should reload all q3 shaders to make sure they are current (which will - // also be used by any other models loaded after this world model) + // if we're loading a worldmodel, then this is a level change if (mod->isworldmodel) + { + // clear out any stale submodels or worldmodels lying around + // if we did this clear before now, an error might abort loading and + // leave things in a bad state + Mod_RemoveStaleWorldModels(mod); + // reload q3 shaders, to make sure they are ready to go for this level + // (including any models loaded for this level) Mod_LoadQ3Shaders(); + } if (buf) { diff --git a/palette.c b/palette.c index 89193b87..f95c4891 100644 --- a/palette.c +++ b/palette.c @@ -24,7 +24,7 @@ unsigned int palette_bgra_embeddedpic[256]; // John Carmack said the quake palette.lmp can be considered public domain because it is not an important asset to id, so I include it here as a fallback if no external palette file is found. unsigned char host_quakepal[768] = { -// marked: colormap colors: cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12; +// marked: colormap colors: cb = (colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12; // 0x0* 0,0,0, 15,15,15, 31,31,31, 47,47,47, 63,63,63, 75,75,75, 91,91,91, 107,107,107, 123,123,123, 139,139,139, 155,155,155, 171,171,171, 187,187,187, 203,203,203, 219,219,219, 235,235,235, -- 2.39.2