public override mleaf_t Mod_PointInLeaf(Single[] p, model_t model) { mnode_t node; Single d; cplane_t plane; if (model == null || model.nodes == null) { Com.Error(Defines.ERR_DROP, "Mod_PointInLeaf: bad model"); } node = model.nodes[0]; while (true) { if (node.contents != -1) { return(( mleaf_t )node); } plane = node.plane; d = Math3D.DotProduct(p, plane.normal) - plane.dist; if (d > 0) { node = node.children[0]; } else { node = node.children[1]; } } }
/* * =============== * Mod_PointInLeaf * =============== */ protected mleaf_t Mod_PointInLeaf(float[] p, model_t model) { mnode_t node; float d; cplane_t plane; if (model == null || model.nodes == null) { Com.Error(Defines.ERR_DROP, "Mod_PointInLeaf: bad model"); } node = model.nodes[0]; // root node while (true) { if (node.contents != -1) { return((mleaf_t)node); } plane = node.plane; d = Math3D.DotProduct(p, plane.normal) - plane.dist; if (d > 0) { node = node.children[0]; } else { node = node.children[1]; } } // never reached }
public static void R_StoreEfrags(efrag_t ef) { while (ef != null) { entity_t pent = ef.entity; model_t clmodel = pent.model; switch (clmodel.type) { case modtype_t.mod_alias: case modtype_t.mod_brush: case modtype_t.mod_sprite: if ((pent.visframe != r_framecount) && (cl_numvisedicts < q_shared.MAX_VISEDICTS)) { cl_visedicts[cl_numvisedicts++] = pent; // mark that we've recorded this entity for this frame pent.visframe = r_framecount; } ef = ef.leafnext; break; default: Sys_Error("R_StoreEfrags: Bad entity type {0}\n", clmodel.type); break; } } }
public void clear() { this.offset[0] = this.offset[1] = this.offset[2] = this.start[0] = this.start[1] = this.start[2] = this.end[0] = this.end[1] = this.end[2] = this.entity = this.dest_entity = this.endtime = 0; this.model = null; }
public override Byte[] Mod_ClusterPVS(Int32 cluster, model_t model) { if (cluster == -1 || model.vis == null) { return(mod_novis); } return(Mod_DecompressVis(model_visibility, model.vis.bitofs[cluster][Defines.DVIS_PVS], model)); }
public override void Mod_Init( ) { for (var i = 0; i < MAX_MOD_KNOWN; i++) { mod_known[i] = new model_t(); } Lib.Fill(mod_novis, ( Byte )0xff); }
public double getCpuFreq(model_t model) { // The crystal clock that drives the VIC II chip is four times // the color burst frequency double crystalFreq = modelData[(int)model].colorBurst * 4.0; // The VIC II produces the two-phase system clock // by running the input clock through a divider return(crystalFreq / modelData[(int)model].divider); }
public model_t[] weaponmodel = new model_t[Defines.MAX_CLIENTWEAPONMODELS]; // arary of references // public void reset() // { // set(new clientinfo_t()); // } public void set(clientinfo_t from) { this.name = from.name; this.cinfo = from.cinfo; this.skin = from.skin; this.icon = from.icon; this.iconname = from.iconname; this.model = from.model; Array.Copy(from.weaponmodel, 0, this.weaponmodel, 0, Defines.MAX_CLIENTWEAPONMODELS); }
public void setModel(model_t model) { cpuFrequency = getCpuFreq(model); vic.chip(modelData[(int)model].vicModel); UInt32 rate = (UInt32)(cpuFrequency / modelData[(int)model].powerFreq); cia1.setDayOfTimeRate(rate); cia2.setDayOfTimeRate(rate); }
public virtual void Set(clientinfo_t from) { name = from.name; cinfo = from.cinfo; skin = from.skin; icon = from.icon; iconname = from.iconname; model = from.model; System.Array.Copy(from.weaponmodel, 0, weaponmodel, 0, Defines.MAX_CLIENTWEAPONMODELS); }
/* * ============== * Mod_ClusterPVS * ============== */ protected byte[] Mod_ClusterPVS(int cluster, model_t model) { if (cluster == -1 || model.vis == null) { return(this.mod_novis); } //return Mod_DecompressVis( (byte *)model.vis + model.vis.bitofs[cluster][Defines.DVIS_PVS], model); return(this.Mod_DecompressVis(this.model_visibility, model.vis.bitofs[cluster][Defines.DVIS_PVS], model)); }
public void chip(model_t model) { maxRasters = modelData[(int)model].rasterLines; cyclesPerLine = modelData[(int)model].cyclesPerLine; clock = modelData[(int)model].clock; lp.setScreenSize(maxRasters, cyclesPerLine); reset(); }
public virtual void Mod_LoadBrushModel(model_t mod, ByteBuffer buffer) { Int32 i; qfiles.dheader_t header; mmodel_t bm; loadmodel.type = mod_brush; if (loadmodel != mod_known[0]) { Com.Error(Defines.ERR_DROP, "Loaded a brush model after the world"); } header = new dheader_t(buffer); i = header.version; if (i != Defines.BSPVERSION) { Com.Error(Defines.ERR_DROP, "Mod_LoadBrushModel: " + mod.name + " has wrong version number (" + i + " should be " + Defines.BSPVERSION + ")"); } mod_base = fileBuffer; Mod_LoadVertexes(header.lumps[Defines.LUMP_VERTEXES]); Mod_LoadEdges(header.lumps[Defines.LUMP_EDGES]); Mod_LoadSurfedges(header.lumps[Defines.LUMP_SURFEDGES]); Mod_LoadLighting(header.lumps[Defines.LUMP_LIGHTING]); Mod_LoadPlanes(header.lumps[Defines.LUMP_PLANES]); Mod_LoadTexinfo(header.lumps[Defines.LUMP_TEXINFO]); Mod_LoadFaces(header.lumps[Defines.LUMP_FACES]); Mod_LoadMarksurfaces(header.lumps[Defines.LUMP_LEAFFACES]); Mod_LoadVisibility(header.lumps[Defines.LUMP_VISIBILITY]); Mod_LoadLeafs(header.lumps[Defines.LUMP_LEAFS]); Mod_LoadNodes(header.lumps[Defines.LUMP_NODES]); Mod_LoadSubmodels(header.lumps[Defines.LUMP_MODELS]); mod.numframes = 2; model_t starmod; for (i = 0; i < mod.numsubmodels; i++) { bm = mod.submodels[i]; starmod = mod_inline[i] = loadmodel.Copy(); starmod.firstmodelsurface = bm.firstface; starmod.nummodelsurfaces = bm.numfaces; starmod.firstnode = bm.headnode; if (starmod.firstnode >= loadmodel.numnodes) { Com.Error(Defines.ERR_DROP, "Inline model " + i + " has bad firstnode"); } Math3D.VectorCopy(bm.maxs, starmod.maxs); Math3D.VectorCopy(bm.mins, starmod.mins); starmod.radius = bm.radius; if (i == 0) { loadmodel = starmod.Copy(); } starmod.numleafs = bm.visleafs; } }
public static void PrintFrameName(model_t m, int frame) { aliashdr_t hdr = Mod_Extradata(m); if (hdr == null) { return; } Con_Printf("frame {0}: {1}\n", frame, hdr.frames[frame].name); }
public static void DrawTextureChains() { if (gl_texsort.value == 0) { GL_DisableMultitexture(); if (skychain != null) { R_DrawSkyChain(skychain); skychain = null; } return; } model_t world = cl.worldmodel; for (int i = 0; i < world.numtextures; i++) { texture_t t = world.textures[i]; if (t == null) { continue; } msurface_t s = t.texturechain; if (s == null) { continue; } if (i == skytexturenum) { R_DrawSkyChain(s); } else if (i == mirrortexturenum && r_mirroralpha.value != 1.0f) { R_MirrorChain(s); continue; } else { if ((s.flags & q_shared.SURF_DRAWTURB) != 0 && r_wateralpha.value != 1.0f) { continue; // draw translucent water later } for (; s != null; s = s.texturechain) { R_RenderBrushPoly(s); } } t.texturechain = null; } }
public static hull_t SV_HullForEntity(edict_t ent, ref Vector3 mins, ref Vector3 maxs, out Vector3 offset) { hull_t hull = null; // decide which clipping hull to use, based on the size if (ent.v.solid == q_shared.SOLID_BSP) { // explicit hulls in the BSP model if (ent.v.movetype != q_shared.MOVETYPE_PUSH) { Sys_Error("SOLID_BSP without MOVETYPE_PUSH"); } model_t model = sv.models[(int)ent.v.modelindex]; if (model == null || model.type != modtype_t.mod_brush) { Sys_Error("MOVETYPE_PUSH with a non bsp model"); } Vector3 size = maxs - mins; if (size.X < 3) { hull = model.hulls[0]; } else if (size.X <= 32) { hull = model.hulls[1]; } else { hull = model.hulls[2]; } // calculate an offset value to center the origin offset = hull.clip_mins - mins; offset += ToVector(ref ent.v.origin); } else { // create a temp hull from bounding box sizes Vector3 hullmins = ToVector(ref ent.v.mins) - maxs; Vector3 hullmaxs = ToVector(ref ent.v.maxs) - mins; hull = SV_HullForBox(ref hullmins, ref hullmaxs); offset = ToVector(ref ent.v.origin); } return(hull); }
public virtual void Clear() { model = null; Math3D.VectorClear(angles); Math3D.VectorClear(origin); frame = 0; Math3D.VectorClear(oldorigin); oldframe = 0; backlerp = 0; skinnum = 0; lightstyle = 0; alpha = 0; skin = null; flags = 0; }
public void set(entity_t src) { this.model = src.model; Math3D.VectorCopy(src.angles, this.angles); Math3D.VectorCopy(src.origin, this.origin); this.frame = src.frame; Math3D.VectorCopy(src.oldorigin, this.oldorigin); this.oldframe = src.oldframe; this.backlerp = src.backlerp; this.skinnum = src.skinnum; this.lightstyle = src.lightstyle; this.alpha = src.alpha; this.skin = src.skin; this.flags = src.flags; }
public void clear() { this.model = null; Math3D.VectorClear(this.angles); Math3D.VectorClear(this.origin); this.frame = 0; Math3D.VectorClear(this.oldorigin); this.oldframe = 0; this.backlerp = 0; this.skinnum = 0; this.lightstyle = 0; this.alpha = 0; this.skin = null; this.flags = 0; }
/* * ================== * Mod_ForName * * Loads in a model for the given name * ================== */ private model_t Mod_ForName(string name, bool crash) { model_t mod = null; int i; if (name == null || name.Length == 0) { Com.Error(Defines.ERR_DROP, "Mod_ForName: NULL name"); } // // inline models are grabbed only from worldmodel // if (name[0] == '*') { i = int.Parse(name[1..]);
public static void R_MarkLeaves() { if (r_oldviewleaf == r_viewleaf && r_novis.value == 0) { return; } if (mirror) { return; } r_visframecount++; r_oldviewleaf = r_viewleaf; byte[] vis; if (r_novis.value != 0) { vis = new byte[4096]; FillArray <Byte>(vis, 0xff); // todo: add count parameter? //memset(solid, 0xff, (cl.worldmodel->numleafs + 7) >> 3); } else { vis = Mod_LeafPVS(r_viewleaf, cl.worldmodel); } model_t world = cl.worldmodel; for (int i = 0; i < world.numleafs; i++) { if (vis[i >> 3] != 0 & (1 << (i & 7)) != 0) { mnodebase_t node = world.leafs[i + 1]; do { if (node.visframe == r_visframecount) { break; } node.visframe = r_visframecount; node = node.parent; } while (node != null); } } }
public static void R_NewMap() { for (int i = 0; i < 256; i++) { d_lightstylevalue[i] = 264; // normal light value } r_worldentity.Clear(); r_worldentity.model = cl.worldmodel; // clear out efrags in case the level hasn't been reloaded // FIXME: is this one short? for (int i = 0; i < cl.worldmodel.numleafs; i++) { cl.worldmodel.leafs[i].efrags = null; } r_viewleaf = null; R_ClearParticles(); GL_BuildLightmaps(); // identify sky texture skytexturenum = -1; mirrortexturenum = -1; model_t world = cl.worldmodel; for (int i = 0; i < world.numtextures; i++) { if (world.textures[i] == null) { continue; } if (world.textures[i].name != null) { if (world.textures[i].name.StartsWith("sky")) { skytexturenum = i; } if (world.textures[i].name.StartsWith("window02_1")) { mirrortexturenum = i; } } world.textures[i].texturechain = null; } }
/* * =================== * Mod_DecompressVis * =================== */ private byte[] Mod_DecompressVis(byte[] @in, int offset, model_t model) { int c; byte[] @out; int outp, inp; int row; row = (model.vis.numclusters + 7) >> 3; @out = this.decompressed; outp = 0; inp = offset; if (@in == null) { // no vis info, so make all visible while (row != 0) { @out[outp++] = (byte)0xFF; row--; } return(this.decompressed); } do { if (@in[inp] != 0) { @out[outp++] = @in[inp++]; continue; } c = @in[inp + 1] & 0xFF; inp += 2; while (c != 0) { @out[outp++] = 0; c--; } }while (outp < row); return(this.decompressed); }
public static void Host_Viewprev_f() { edict_t e = FindViewthing(); if (e == null) { return; } model_t m = cl.model_precache[(int)e.v.modelindex]; e.v.frame = e.v.frame - 1; if (e.v.frame < 0) { e.v.frame = 0; } PrintFrameName(m, (int)e.v.frame); }
public virtual void Mod_LoadSpriteModel(model_t mod, ByteBuffer buffer) { qfiles.dsprite_t sprout = new dsprite_t(buffer); if (sprout.version != qfiles.SPRITE_VERSION) { Com.Error(Defines.ERR_DROP, "%s has wrong version number (%i should be %i)", mod.name, sprout.version, qfiles.SPRITE_VERSION); } if (sprout.numframes > qfiles.MAX_MD2SKINS) { Com.Error(Defines.ERR_DROP, "%s has too many frames (%i > %i)", mod.name, sprout.numframes, qfiles.MAX_MD2SKINS); } for (var i = 0; i < sprout.numframes; i++) { mod.skins[i] = GL_FindImage(sprout.frames[i].name, it_sprite); } mod.type = mod_sprite; mod.extradata = sprout; }
public static void Host_Viewnext_f() { edict_t e = FindViewthing(); if (e == null) { return; } model_t m = cl.model_precache[(int)e.v.modelindex]; e.v.frame = e.v.frame + 1; if (e.v.frame >= m.numframes) { e.v.frame = m.numframes - 1; } PrintFrameName(m, (int)e.v.frame); }
public static void R_AddEfrags(entity_t ent) { if (ent.model == null) { return; } r_addent = ent; _LastObj = ent; // lastlink = &ent->efrag; r_pefragtopnode = null; model_t entmodel = ent.model; r_emins = ent.origin + entmodel.mins; r_emaxs = ent.origin + entmodel.maxs; R_SplitEntityOnNode(cl.worldmodel.nodes[0]); ent.topnode = r_pefragtopnode; }
public static void Host_Viewmodel_f() { edict_t e = FindViewthing(); if (e == null) { return; } model_t m = Mod_ForName(Cmd_Argv(1), false); if (m == null) { Con_Printf("Can't load {0}\n", Cmd_Argv(1)); return; } e.v.frame = 0; cl.model_precache[(int)e.v.modelindex] = m; }
public static void Host_Viewframe_f() { edict_t e = FindViewthing(); if (e == null) { return; } model_t m = cl.model_precache[(int)e.v.modelindex]; int f = atoi(Cmd_Argv(1)); if (f >= m.numframes) { f = m.numframes - 1; } e.v.frame = f; }
public virtual Byte[] Mod_DecompressVis(Byte[] in_renamed, Int32 offset, model_t model) { Int32 c; Byte[] out_renamed; Int32 outp, inp; Int32 row; row = (model.vis.numclusters + 7) >> 3; out_renamed = decompressed; outp = 0; inp = offset; if (in_renamed == null) { while (row != 0) { out_renamed[outp++] = ( Byte )0xFF; row--; } return(decompressed); } do { if (in_renamed[inp] != 0) { out_renamed[outp++] = in_renamed[inp++]; continue; } c = in_renamed[inp + 1] & 0xFF; inp += 2; while (c != 0) { out_renamed[outp++] = 0; c--; } }while (outp < row); return(decompressed); }
public void Clone(model_t model) { this.name = model.name; this.needload = model.needload; this.type = model.type; this.numframes = model.numframes; this.flags = model.flags; this.mins = (double[])model.mins.Clone(); this.maxs = (double[])model.maxs.Clone(); this.radius = model.radius; this.firstmodelsurface = model.firstmodelsurface; this.nummodelsurfaces = model.nummodelsurfaces; this.numsubmodels = model.numsubmodels; this.submodels = model.submodels; this.numplanes = model.numplanes; this.planes = model.planes; this.numleafs = model.numleafs; this.leafs = model.leafs; this.numvertexes = model.numvertexes; this.vertexes = model.vertexes; this.numedges = model.numedges; this.edges = model.edges; this.numnodes = model.numnodes; this.nodes = model.nodes; this.numtexinfo = model.numtexinfo; this.texinfo = model.texinfo; this.numsurfaces = model.numsurfaces; this.surfaces = model.surfaces; this.numsurfedges = model.numsurfedges; this.surfedges = model.surfedges; this.numclipnodes = model.numclipnodes; this.clipnodes = model.clipnodes; this.nummarksurfaces = model.nummarksurfaces; this.marksurfaces = model.marksurfaces; //this.hulls = model.hulls; //dodgey clone! firstclipnode breaks for world this.hulls = new hull_t[bspfile.MAX_MAP_HULLS]; for (int i = 0; i < model.hulls.Length; i++) { var h = model.hulls[i]; this.hulls[i] = new hull_t { clipnodes = h.clipnodes, firstclipnode= h.firstclipnode, clip_maxs = h.clip_maxs, clip_mins = h.clip_mins, lastclipnode = h.lastclipnode, planes = h.planes }; } this.numtextures = model.numtextures; this.textures = model.textures; this.visdata = model.visdata; this.lightdata = model.lightdata; this.entities = model.entities; }
static byte[] Mod_DecompressVis(bspfile.ByteBuffer @in, model_t model) { int c; int @out; int row; int ofs = @in.ofs; row = (model.numleafs+7)>>3; @out = 0; if (@in.buffer == null) { // no vis info, so make all visible while (row != 0) { decompressed[@out++] = 0xff; row--; } return decompressed; } do { if (@in.buffer[ofs] != 0) { decompressed[@out++] = @in.buffer[ofs++]; continue; } c = @in.buffer[ofs+1]; ofs += 2; while (c != 0) { decompressed[@out++] = 0; c--; } } while (@out < row); return decompressed; }
/* ================= Mod_LoadAliasModel ================= */ static void Mod_LoadAliasModel(model_t mod, byte[] buffer) { int i; mdl_t pmodel, pinmodel; stvert_t[] pstverts; stvert_t pinstverts; aliashdr_t pheader; mtriangle_t[] ptri; dtriangle_t pintriangles; int version, numframes, numskins; daliasframetype_t pframetype; daliasskintype_t pskintype; maliasskindesc_t[] pskindesc; int skinsize; int start, end, total; bspfile.ByteBuffer aux = new bspfile.ByteBuffer(buffer, 0); pinmodel = (mdl_t)buffer; version = pinmodel.version; if (version != ALIAS_VERSION) sys_linux.Sys_Error (mod.name + " has wrong version number (" + version + " should be " + ALIAS_VERSION + ")"); // // allocate space for a working header, plus all the data except the frames, // skin and group info // pheader = new aliashdr_t(); pmodel = new mdl_t(); // mod.cache = pheader; mod.flags = pinmodel.flags; // // endian-adjust and copy the data, starting with the alias model header // pmodel.boundingradius = pinmodel.boundingradius; pmodel.numskins = pinmodel.numskins; pmodel.skinwidth = pinmodel.skinwidth; pmodel.skinheight = pinmodel.skinheight; if (pmodel.skinheight > draw.MAX_LBM_HEIGHT) sys_linux.Sys_Error("model " + mod.name + " has a skin taller than " + draw.MAX_LBM_HEIGHT); pmodel.numverts = pinmodel.numverts; if (pmodel.numverts <= 0) sys_linux.Sys_Error("model " + mod.name + " has no vertices"); if (pmodel.numverts > render.MAXALIASVERTS) sys_linux.Sys_Error("model " + mod.name + " has too many vertices"); pmodel.numtris = pinmodel.numtris; if (pmodel.numtris <= 0) sys_linux.Sys_Error("model " + mod.name + " has no triangles"); pmodel.numframes = pinmodel.numframes; pmodel.size = pinmodel.size * render.ALIAS_BASE_SIZE_RATIO; mod.synctype = pinmodel.synctype; mod.numframes = pmodel.numframes; for (i = 0; i < 3; i++) { pmodel.scale[i] = pinmodel.scale[i]; pmodel.scale_origin[i] = pinmodel.scale_origin[i]; pmodel.eyeposition[i] = pinmodel.eyeposition[i]; } numskins = pmodel.numskins; numframes = pmodel.numframes; if ((pmodel.skinwidth & 0x03) != 0) sys_linux.Sys_Error("Mod_LoadAliasModel: skinwidth not multiple of 4"); pheader.model = pmodel; // // load the skins // skinsize = pmodel.skinheight * pmodel.skinwidth; if (numskins < 1) sys_linux.Sys_Error("Mod_LoadAliasModel: Invalid # of skins: " + numskins + "\n"); aux.ofs += sizeof_mdl_t; pskindesc = new maliasskindesc_t[numskins]; for(int kk = 0; kk < numskins; kk++) pskindesc[kk] = new maliasskindesc_t(); pheader.skindesc = pskindesc; for (i = 0; i < numskins; i++) { aliasskintype_t skintype; pskintype = (daliasskintype_t)aux; skintype = pskintype.type; pskindesc[i].type = skintype; if (skintype == aliasskintype_t.ALIAS_SKIN_SINGLE) { aux.ofs += sizeof_daliasskintype_t; Mod_LoadAliasSkin(aux, ref pskindesc[i].skin, skinsize, pheader); } else { aux.ofs += sizeof_daliasskintype_t; Mod_LoadAliasSkinGroup(aux, ref pskindesc[i].skin, skinsize, pheader); } } // // set base s and t vertices // pstverts = new stvert_t[pmodel.numverts]; pheader.stverts = pstverts; for (i = 0; i < pmodel.numverts; i++) { pinstverts = (stvert_t)aux; pstverts[i] = new stvert_t(); pstverts[i].onseam = pinstverts.onseam; // put s and t in 16.16 format pstverts[i].s = pinstverts.s << 16; pstverts[i].t = pinstverts.t << 16; aux.ofs += sizeof_stvert_t; } // // set up the triangles // ptri = new mtriangle_t[pmodel.numtris]; pheader.triangles = ptri; for (i = 0; i < pmodel.numtris; i++) { int j; pintriangles = (dtriangle_t)aux; ptri[i] = new mtriangle_t(); ptri[i].facesfront = pintriangles.facesfront; for (j = 0; j < 3; j++) { ptri[i].vertindex[j] = pintriangles.vertindex[j]; } aux.ofs += sizeof_dtriangle_t; } // // load the frames // if (numframes < 1) sys_linux.Sys_Error("Mod_LoadAliasModel: Invalid # of frames: " + numframes + "\n"); pheader.frames = new maliasframedesc_t[numframes]; for (i = 0; i < numframes; i++) { aliasframetype_t frametype; pframetype = (daliasframetype_t)aux; frametype = pframetype.type; pheader.frames[i] = new maliasframedesc_t(); pheader.frames[i].type = frametype; if (frametype == aliasframetype_t.ALIAS_SINGLE) { aux.ofs += sizeof_daliasframetype_t; Mod_LoadAliasFrame(aux, ref pheader.frames[i].frame, pmodel.numverts, pheader.frames[i].bboxmin, pheader.frames[i].bboxmax, pheader, pheader.frames[i].name); } else { aux.ofs += sizeof_daliasframetype_t; Mod_LoadAliasGroup(aux, ref pheader.frames[i].frame, pmodel.numverts, pheader.frames[i].bboxmin, pheader.frames[i].bboxmax, pheader, pheader.frames[i].name); } } mod.type = modtype_t.mod_alias; // FIXME: do this right mod.mins[0] = mod.mins[1] = mod.mins[2] = -16; mod.maxs[0] = mod.maxs[1] = mod.maxs[2] = 16; // // move the complete, relocatable alias model to the cache // mod.cache = pheader; }
/* ================== Mod_LoadModel Loads a model into the cache ================== */ static model_t Mod_LoadModel(model_t mod, bool crash) { //unsigned *buf; byte[] buf; byte[] stackbuf = new byte[1024]; // avoid dirtying the cache heap if (mod.type == modtype_t.mod_alias) { } else { if (mod.needload == NL_PRESENT) return mod; } // // because the world is so huge, load it one piece at a time // // // load the file // buf = common.COM_LoadStackFile (mod.name, stackbuf, stackbuf.Length); if (buf == null) { if (crash) sys_linux.Sys_Error("Mod_NumForName: " + mod.name + " not found"); return null; } // // allocate a new model // common.COM_FileBase (mod.name, ref loadname); loadmodel = mod; // // fill it in // // call the apropriate loader mod.needload = NL_PRESENT; int aux = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; switch (aux) { case IDPOLYHEADER: Mod_LoadAliasModel (mod, buf); break; case IDSPRITEHEADER: Mod_LoadSpriteModel (mod, buf); break; default: Mod_LoadBrushModel (mod, buf); break; } return mod; }
/* ================= Mod_LoadBrushModel ================= */ static void Mod_LoadBrushModel(model_t mod, byte[] buffer) { int i, j; bspfile.dheader_t header; bspfile.dmodel_t bm; loadmodel.type = modtype_t.mod_brush; header = (bspfile.dheader_t)buffer; i = header.version; if (i != bspfile.BSPVERSION) sys_linux.Sys_Error ("Mod_LoadBrushModel: " + mod.name + " has wrong version number (" + i + " should be " + bspfile.BSPVERSION + ")"); // swap all the lumps mod_base = buffer; // load into heap Mod_LoadVertexes (header.lumps[bspfile.LUMP_VERTEXES]); Mod_LoadEdges (header.lumps[bspfile.LUMP_EDGES]); Mod_LoadSurfedges (header.lumps[bspfile.LUMP_SURFEDGES]); Mod_LoadTextures (header.lumps[bspfile.LUMP_TEXTURES]); Mod_LoadLighting (header.lumps[bspfile.LUMP_LIGHTING]); Mod_LoadPlanes (header.lumps[bspfile.LUMP_PLANES]); Mod_LoadTexinfo (header.lumps[bspfile.LUMP_TEXINFO]); Mod_LoadFaces (header.lumps[bspfile.LUMP_FACES]); Mod_LoadMarksurfaces (header.lumps[bspfile.LUMP_MARKSURFACES]); Mod_LoadVisibility (header.lumps[bspfile.LUMP_VISIBILITY]); Mod_LoadLeafs (header.lumps[bspfile.LUMP_LEAFS]); Mod_LoadNodes (header.lumps[bspfile.LUMP_NODES]); Mod_LoadClipnodes (header.lumps[bspfile.LUMP_CLIPNODES]); Mod_LoadEntities (header.lumps[bspfile.LUMP_ENTITIES]); Mod_LoadSubmodels (header.lumps[bspfile.LUMP_MODELS]); Mod_MakeHull0 (); mod.numframes = 2; // regular and alternate animation mod.flags = 0; // // set up the submodels (FIXME: this is confusing) // for (i=0 ; i<mod.numsubmodels ; i++) { bm = mod.submodels[i]; mod.hulls[0].firstclipnode = bm.headnode[0]; for (j=1 ; j<bspfile.MAX_MAP_HULLS ; j++) { mod.hulls[j].firstclipnode = bm.headnode[j]; mod.hulls[j].lastclipnode = mod.numclipnodes-1; } mod.firstmodelsurface = bm.firstface; mod.nummodelsurfaces = bm.numfaces; mathlib.VectorCopy (bm.maxs, ref mod.maxs); mathlib.VectorCopy (bm.mins, ref mod.mins); mod.radius = RadiusFromBounds (mod.mins, mod.maxs); mod.numleafs = bm.visleafs; if (i < mod.numsubmodels-1) { // duplicate the basic information string name; name = "*" + (i+1); loadmodel = Mod_FindName (name); // *loadmodel = *mod; loadmodel.Clone(mod); loadmodel.name = name; mod = loadmodel; } } }
static model() { for(int kk = 0; kk < MAX_MOD_KNOWN; kk++) mod_known[kk] = new model_t(); }
public static byte[] Mod_LeafPVS(mleaf_t leaf, model_t model) { if (leaf == model.leafs[0]) return mod_novis; return Mod_DecompressVis (leaf.compressed_vis, model); }
/* =============== Mod_Extradata Caches the data if needed =============== */ public static object Mod_Extradata(model_t mod) { object r; r = mod.cache; if (r != null) return r; Mod_LoadModel(mod, true); if (mod.cache == null) sys_linux.Sys_Error("Mod_Extradata: caching failed"); return mod.cache; }
public static Uint8Array Mod_LeafPVS(node_or_leaf_t leaf, model_t model) { if (leaf == model.leafs[0]) return mod_novis; return Mod_DecompressVis (leaf.compressed_vis, model); }
public void Clone(model_t model) { this.name = model.name; this.needload = model.needload; this.type = model.type; this.numframes = model.numframes; this.flags = model.flags; this.mins = (double[])model.mins.Clone(); this.maxs = (double[])model.maxs.Clone(); this.radius = model.radius; this.firstmodelsurface = model.firstmodelsurface; this.nummodelsurfaces = model.nummodelsurfaces; this.numsubmodels = model.numsubmodels; this.submodels = model.submodels; this.numplanes = model.numplanes; this.planes = model.planes; this.numleafs = model.numleafs; this.leafs = model.leafs; this.numvertexes = model.numvertexes; this.vertexes = model.vertexes; this.numedges = model.numedges; this.edges = model.edges; this.numnodes = model.numnodes; this.nodes = model.nodes; this.numtexinfo = model.numtexinfo; this.texinfo = model.texinfo; this.numsurfaces = model.numsurfaces; this.surfaces = model.surfaces; this.numsurfedges = model.numsurfedges; this.surfedges = model.surfedges; this.numclipnodes = model.numclipnodes; this.clipnodes = model.clipnodes; this.nummarksurfaces = model.nummarksurfaces; this.marksurfaces = model.marksurfaces; this.hulls = model.hulls; this.numtextures = model.numtextures; this.textures = model.textures; this.visdata = model.visdata; this.lightdata = model.lightdata; this.entities = model.entities; }
/* ================= Mod_LoadSpriteModel ================= */ static void Mod_LoadSpriteModel(model_t mod, byte[] buffer) { int i; int version; dsprite_t pin; msprite_t psprite; int numframes; dspriteframetype_t pframetype; bspfile.ByteBuffer aux = new bspfile.ByteBuffer(buffer, 0); pin = (dsprite_t)buffer; version = pin.version; if (version != SPRITE_VERSION) sys_linux.Sys_Error (mod.name + " has wrong version number (" + version + " should be " + SPRITE_VERSION + ")"); numframes = pin.numframes; psprite = new msprite_t(); psprite.frames = new mspriteframedesc_t[numframes]; for(int kk = 0; kk < numframes; kk++) psprite.frames[kk] = new mspriteframedesc_t(); mod.cache = psprite; psprite.type = pin.type; psprite.maxwidth = pin.width; psprite.maxheight = pin.height; psprite.beamlength = pin.beamlength; mod.synctype = pin.synctype; psprite.numframes = numframes; mod.mins[0] = mod.mins[1] = -psprite.maxwidth/2; mod.maxs[0] = mod.maxs[1] = psprite.maxwidth/2; mod.mins[2] = -psprite.maxheight/2; mod.maxs[2] = psprite.maxheight/2; // // load the frames // if (numframes < 1) sys_linux.Sys_Error ("Mod_LoadSpriteModel: Invalid # of frames: " + numframes + "\n"); mod.numframes = numframes; mod.flags = 0; aux.ofs += sizeof_dsprite_t; for (i=0 ; i<numframes ; i++) { spriteframetype_t frametype; pframetype = (dspriteframetype_t)aux; frametype = pframetype.type; psprite.frames[i].type = frametype; if (frametype == spriteframetype_t.SPR_SINGLE) { aux.ofs += sizeof_dspriteframetype_t; Mod_LoadSpriteFrame(aux, ref psprite.frames[i].frameptr); } else { aux.ofs += sizeof_dspriteframetype_t; Mod_LoadSpriteGroup(aux, ref psprite.frames[i].frameptr); } } mod.type = modtype_t.mod_sprite; }
/* =============== Mod_PointInLeaf =============== */ public static mleaf_t Mod_PointInLeaf(double[] p, model_t model) { node_or_leaf_t node; double d; mplane_t plane; if (model == null || model.nodes == null) sys_linux.Sys_Error("Mod_PointInLeaf: bad model"); node = model.nodes[0]; while (true) { if (node.contents < 0) return (mleaf_t)node; mnode_t _node = (mnode_t)node; plane = _node.plane; d = mathlib.DotProduct(p, plane.normal) - plane.dist; if (d > 0) node = _node.children[0]; else node = _node.children[1]; } return null; // never reached }