static model_t mod_known[MAX_MOD_KNOWN];
rtexturepool_t *mod_shared_texturepool;
-rtexture_t *r_notexture;
+rtexture_t *r_texture_notexture;
rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
rtexture_t *mod_shared_distorttexture[64];
return;
}
-texture_t r_surf_notexture;
-
void Mod_SetupNoTexture(void)
{
- int x, y;
- qbyte pix[16][16][4];
-
- // this makes a light grey/dark grey checkerboard texture
- for (y = 0;y < 16;y++)
- {
- for (x = 0;x < 16;x++)
- {
- if ((y < 8) ^ (x < 8))
- {
- pix[y][x][0] = 128;
- pix[y][x][1] = 128;
- pix[y][x][2] = 128;
- pix[y][x][3] = 255;
- }
- else
- {
- pix[y][x][0] = 64;
- pix[y][x][1] = 64;
- pix[y][x][2] = 64;
- pix[y][x][3] = 255;
- }
- }
- }
-
- r_notexture = R_LoadTexture2D(mod_shared_texturepool, "notexture", 16, 16, &pix[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP, NULL);
}
static void mod_start(void)
static void mod_newmap(void)
{
- msurface_t *surf;
- int i, surfnum, ssize, tsize;
+ msurface_t *surface;
+ int i, surfacenum, ssize, tsize;
- if (!cl_stainmapsclearonload.integer)
+ if (!cl_stainmaps_clearonload.integer)
return;
- for (i=0; i<MAX_MOD_KNOWN; i++)
+ for (i = 0;i < MAX_MOD_KNOWN;i++)
{
- if (mod_known[i].name[0] && mod_known[i].type == mod_brushq1)
+ if (mod_known[i].name[0])
{
- for (surfnum=0, surf=mod_known[i].brushq1.surfaces; surfnum<mod_known[i].brushq1.numsurfaces;surfnum++, surf++)
+ for (surfacenum = 0, surface = mod_known[i].brush.data_surfaces;surfacenum < mod_known[i].brush.num_surfaces;surfacenum++, surface++)
{
- if (surf->texinfo->texture->flags & SURF_LIGHTMAP)
+ if (surface->lightmapinfo && surface->lightmapinfo->stainsamples)
{
- ssize = (surf->extents[0] >> 4) + 1;
- tsize = (surf->extents[1] >> 4) + 1;
-
- if (ssize > 256 || tsize > 256)
- Host_Error("Bad surface extents");
-
- if (surf->stainsamples)
- memset(surf->stainsamples, 255, ssize * tsize * 3);
-
- surf->cached_dlight = true;
+ ssize = (surface->lightmapinfo->extents[0] >> 4) + 1;
+ tsize = (surface->lightmapinfo->extents[1] >> 4) + 1;
+ memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3);
+ surface->cached_dlight = true;
}
}
}
Mod_FreeModel(mod);
strcpy(mod->name, name);
mod->isworldmodel = isworldmodel;
- mod->needload = true;
+ mod->loaded = false;
}
/*
crc = 0;
buf = NULL;
if (mod->isworldmodel != isworldmodel)
- mod->needload = true;
- if (mod->needload || checkdisk)
+ mod->loaded = false;
+ if (!mod->loaded || checkdisk)
{
- if (checkdisk && !mod->needload)
+ if (checkdisk && mod->loaded)
Con_DPrintf("checking model %s\n", mod->name);
buf = FS_LoadFile (mod->name, tempmempool, false);
if (buf)
{
crc = CRC_Block(buf, fs_filesize);
if (mod->crc != crc)
- mod->needload = true;
+ mod->loaded = false;
}
}
- if (!mod->needload)
+ if (mod->loaded)
return mod; // already loaded
Con_DPrintf("loading model %s\n", mod->name);
// LordHavoc: unload the existing model in this slot (if there is one)
Mod_UnloadModel(mod);
+
// load the model
mod->isworldmodel = isworldmodel;
mod->used = true;
mod->crc = crc;
- // errors can prevent the corresponding mod->needload = false;
- mod->needload = true;
+ // errors can prevent the corresponding mod->loaded = true;
+ mod->loaded = false;
// default model radius and bounding box (mainly for missing models)
mod->radius = 16;
}
// no errors occurred
- mod->needload = false;
+ mod->loaded = true;
return mod;
}
{
if (mod)
{
- if (mod->needload)
+ if (!mod->loaded)
Mod_LoadModel(mod, true, true, mod->isworldmodel);
else
{
Mod_FreeModel(mod);
}
+// only used during loading!
+void Mod_RemoveStaleWorldModels(model_t *skip)
+{
+ int i;
+ for (i = 0;i < MAX_MOD_KNOWN;i++)
+ if (mod_known[i].isworldmodel && skip != &mod_known[i])
+ Mod_UnloadModel(mod_known + i);
+}
+
void Mod_LoadModels(void)
{
int i;
{
mod = freemod;
strcpy (mod->name, name);
- mod->needload = true;
+ mod->loaded = false;
mod->used = true;
return mod;
}
return NULL;
}
-/*
-==================
-Mod_TouchModel
-
-==================
-*/
-void Mod_TouchModel(const char *name)
-{
- model_t *mod;
-
- mod = Mod_FindName(name);
- mod->used = true;
-}
-
/*
==================
Mod_ForName
VectorNormalize(v);
}
+surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors)
+{
+ surfmesh_t *mesh;
+ qbyte *data;
+ mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int));
+ mesh->num_vertices = numvertices;
+ mesh->num_triangles = numtriangles;
+ data = (qbyte *)(mesh + 1);
+ if (mesh->num_vertices)
+ {
+ mesh->data_vertex3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_svector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_tvector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_normal3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_texcoordtexture2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ mesh->data_texcoordlightmap2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ if (detailtexcoords)
+ mesh->data_texcoorddetail2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ if (vertexcolors)
+ mesh->data_lightmapcolor4f = (float *)data, data += sizeof(float[4]) * mesh->num_vertices;
+ if (lightmapoffsets)
+ mesh->data_lightmapoffsets = (int *)data, data += sizeof(int) * mesh->num_vertices;
+ }
+ if (mesh->num_triangles)
+ {
+ mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+ if (neighbors)
+ mesh->data_neighbor3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+ }
+ return mesh;
+}
+
shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable)
{
shadowmesh_t *newmesh;
return i;
}
+void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap)
+{
+ int i;
+ double isnap = 1.0 / snap;
+ for (i = 0;i < numvertices*numcomponents;i++)
+ vertices[i] = floor(vertices[i]*isnap)*snap;
+}
+
int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f)
{
int i, outtriangles;