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_LoadVertexes ================= */ static void Mod_LoadVertexes(bspfile.lump_t l) { bspfile.dvertex_t[] @in; mvertex_t[] @out; int i, count; if ((l.filelen % bspfile.sizeof_dvertex_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dvertex_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dvertex_t[count]; @out = new mvertex_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dvertex_t)buf; buf.ofs += bspfile.sizeof_dvertex_t; @out[kk] = new mvertex_t(); } loadmodel.vertexes = @out; loadmodel.numvertexes = count; for ( i=0 ; i<count ; i++) { @out[i].position[0] = @in[i].point[0]; @out[i].position[1] = @in[i].point[1]; @out[i].position[2] = @in[i].point[2]; } }
/* ================= Mod_LoadVisibility ================= */ static void Mod_LoadVisibility(bspfile.lump_t l) { if (l.filelen == 0) { loadmodel.visdata = null; return; } loadmodel.visdata = new byte[l.filelen]; Buffer.BlockCopy(mod_base, l.fileofs, loadmodel.visdata, 0, l.filelen); }
/* ================= Mod_LoadEntities ================= */ static void Mod_LoadEntities(bspfile.lump_t l) { if (l.filelen == 0) { loadmodel.entities = null; return; } loadmodel.entities = new char[l.filelen]; byte[] tmp = new byte[l.filelen]; Buffer.BlockCopy(mod_base, l.fileofs, tmp, 0, l.filelen); for (int kk = 0; kk < l.filelen; kk++) loadmodel.entities[kk] = (char)tmp[kk]; tmp = null; }
/* ================= Mod_LoadClipnodes ================= */ private static void Mod_LoadClipnodes(bspfile.lump_t l) { bspfile.dclipnode_t[] @in, @out; int i, count; hull_t hull; if ((l.filelen % bspfile.sizeof_dclipnode_t) != 0) sys_linux.Sys_Error("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dclipnode_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dclipnode_t[count]; @out = new bspfile.dclipnode_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dclipnode_t)buf; buf.ofs += bspfile.sizeof_dclipnode_t; @out[kk] = new bspfile.dclipnode_t(); } loadmodel.clipnodes = @out; loadmodel.numclipnodes = count; hull = loadmodel.hulls[1]; hull.clipnodes = @out; hull.firstclipnode = 0; hull.lastclipnode = count - 1; hull.planes = loadmodel.planes; hull.clip_mins[0] = -16; hull.clip_mins[1] = -16; hull.clip_mins[2] = -24; hull.clip_maxs[0] = 16; hull.clip_maxs[1] = 16; hull.clip_maxs[2] = 32; //Debug.WriteLine("@hull1 firstclipnode: " + hull.firstclipnode); hull = loadmodel.hulls[2]; hull.clipnodes = @out; hull.firstclipnode = 0; hull.lastclipnode = count - 1; hull.planes = loadmodel.planes; hull.clip_mins[0] = -32; hull.clip_mins[1] = -32; hull.clip_mins[2] = -24; hull.clip_maxs[0] = 32; hull.clip_maxs[1] = 32; hull.clip_maxs[2] = 64; //Debug.WriteLine("@hull2 firstclipnode: "+ hull.firstclipnode); for (i = 0; i < count; i++) { @out[i].planenum = @in[i].planenum; @out[i].children[0] = @in[i].children[0]; //LittleShort @out[i].children[1] = @in[i].children[1]; /*Debug.WriteLine( string.Format( " @planenum: {0}, @children[0]: {1}, @children[1]: {2}", @in[i].planenum, @in[i].children[0], @in[i].children[1]));*/ } }
/* ================= Mod_LoadAliasSkin ================= */ static void Mod_LoadAliasSkin(bspfile.ByteBuffer pin, ref object pskinindex, int skinsize, aliashdr_t pheader) { int i; byte[] pskin; pskin = new byte[skinsize * render.r_pixbytes]; pskinindex = (object)pskin; if (render.r_pixbytes == 1) { Buffer.BlockCopy(pin.buffer, pin.ofs, pskin, 0, skinsize); } else if (render.r_pixbytes == 2) { } else { sys_linux.Sys_Error("Mod_LoadAliasSkin: driver set invalid r_pixbytes: " + render.r_pixbytes + "\n"); } pin.ofs += skinsize; }
/* ================= Mod_LoadClipnodes ================= */ static void Mod_LoadClipnodes(bspfile.lump_t l) { }
//============================================================================= /* ================= Mod_LoadSpriteFrame ================= */ static void Mod_LoadSpriteFrame(bspfile.ByteBuffer pin, ref object ppframe) { dspriteframe_t pinframe; mspriteframe_t pspriteframe; int width, height, size; int[] origin = new int[2]; pinframe = (dspriteframe_t)pin; width = pinframe.width; height = pinframe.height; size = width * height; pspriteframe = new mspriteframe_t(); pspriteframe.pixels = new byte[size*render.r_pixbytes]; ppframe = pspriteframe; pspriteframe.width = width; pspriteframe.height = height; origin[0] = pinframe.origin[0]; origin[1] = pinframe.origin[1]; pspriteframe.up = origin[1]; pspriteframe.down = origin[1] - height; pspriteframe.left = origin[0]; pspriteframe.right = width + origin[0]; if (render.r_pixbytes == 1) { pin.ofs += sizeof_dspriteframe_t; for(int kk = 0; kk < size; kk++) pspriteframe.pixels[kk] = pin.buffer[pin.ofs + kk]; } else if (render.r_pixbytes == 2) { } else { sys_linux.Sys_Error ("Mod_LoadSpriteFrame: driver set invalid r_pixbytes: " + render.r_pixbytes + "\n"); } pin.ofs += size; }
/* ================= Mod_LoadSpriteGroup ================= */ static void Mod_LoadSpriteGroup(bspfile.ByteBuffer pin, ref object ppframe) { dspritegroup_t pingroup; mspritegroup_t pspritegroup; int i, numframes; double[] poutintervals; pingroup = (dspritegroup_t)pin; numframes = pingroup.numframes; pspritegroup = new mspritegroup_t(); pspritegroup.frames = new mspriteframe_t[numframes]; for(int kk = 0; kk < numframes; kk++) pspritegroup.frames[kk] = new mspriteframe_t(); pspritegroup.numframes = numframes; ppframe = pspritegroup; pin.ofs += sizeof_dspritegroup_t; poutintervals = new double[numframes]; pspritegroup.intervals = poutintervals; for (i=0 ; i<numframes ; i++) { poutintervals[i] = BitConverter.ToSingle(pin.buffer, pin.ofs); pin.ofs += sizeof(Single); if (poutintervals[i] <= 0.0) sys_linux.Sys_Error ("Mod_LoadSpriteGroup: interval<=0"); } for (i=0 ; i<numframes ; i++) { Mod_LoadSpriteFrame (pin, ref pspritegroup.frames[i]); } }
/* ================= Mod_LoadNodes ================= */ static void Mod_LoadNodes(bspfile.lump_t l) { int i, j, count, p; bspfile.dnode_t[] @in; mnode_t[] @out; if ((l.filelen % bspfile.sizeof_dnode_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dnode_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dnode_t[count]; @out = new mnode_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dnode_t)buf; buf.ofs += bspfile.sizeof_dnode_t; @out[kk] = new mnode_t(); } loadmodel.nodes = @out; loadmodel.numnodes = count; for ( i=0 ; i<count ; i++) { for (j=0 ; j<3 ; j++) { @out[i].minmaxs[j] = @in[i].mins[j]; @out[i].minmaxs[3+j] = @in[i].maxs[j]; } p = @in[i].planenum; @out[i].plane = loadmodel.planes[p]; @out[i].firstsurface = @in[i].firstface; @out[i].numsurfaces = @in[i].numfaces; for (j=0 ; j<2 ; j++) { p = @in[i].children[j]; if (p >= 0) @out[i].children[j] = loadmodel.nodes[p]; else @out[i].children[j] = loadmodel.leafs[-1 - p]; } } Mod_SetParent (loadmodel.nodes[0], null); // sets nodes and leafs }
/* ================= Mod_LoadPlanes ================= */ static void Mod_LoadPlanes(bspfile.lump_t l) { int i, j; mplane_t[] @out; bspfile.dplane_t[] @in; int count; int bits; if ((l.filelen % bspfile.sizeof_dplane_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dplane_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dplane_t[count]; @out = new mplane_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dplane_t)buf; buf.ofs += bspfile.sizeof_dplane_t; @out[kk] = new mplane_t(); } loadmodel.planes = @out; loadmodel.numplanes = count; for ( i=0 ; i<count ; i++) { bits = 0; for (j=0 ; j<3 ; j++) { @out[i].normal[j] = @in[i].normal[j]; if (@out[i].normal[j] < 0) bits |= 1<<j; } @out[i].dist = @in[i].dist; @out[i].type = (byte)@in[i].type; @out[i].signbits = (byte)bits; } }
/* ================= Mod_LoadMarksurfaces ================= */ static void Mod_LoadMarksurfaces(bspfile.lump_t l) { int i, j, count; short[] @in; msurface_t[] @out; if ((l.filelen % sizeof(short)) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / sizeof(short); @in = new short[count]; @out = new msurface_t[count]; int ofs = l.fileofs; for (int kk = 0; kk < count; kk++) { @in[kk] = BitConverter.ToInt16(mod_base, ofs); ofs += sizeof(short); } loadmodel.marksurfaces = @out; loadmodel.nummarksurfaces = count; for ( i=0 ; i<count ; i++) { j = @in[i]; if (j >= loadmodel.numsurfaces) sys_linux.Sys_Error ("Mod_ParseMarksurfaces: bad surface number"); @out[i] = loadmodel.surfaces[j]; } }
/* ================= Mod_LoadLighting ================= */ static void Mod_LoadLighting(bspfile.lump_t l) { if (l.filelen == 0) { loadmodel.lightdata = null; return; } loadmodel.lightdata = new byte[l.filelen]; Buffer.BlockCopy(mod_base, l.fileofs, loadmodel.lightdata, 0, l.filelen); }
/* ================= Mod_LoadLeafs ================= */ static void Mod_LoadLeafs(bspfile.lump_t l) { bspfile.dleaf_t[] @in; mleaf_t[] @out; int i, j, count, p; if ((l.filelen % bspfile.sizeof_dleaf_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dleaf_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dleaf_t[count]; @out = new mleaf_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dleaf_t)buf; buf.ofs += bspfile.sizeof_dleaf_t; @out[kk] = new mleaf_t(); } loadmodel.leafs = @out; loadmodel.numleafs = count; for ( i=0 ; i<count ; i++) { for (j=0 ; j<3 ; j++) { @out[i].minmaxs[j] = @in[i].mins[j]; @out[i].minmaxs[3+j] = @in[i].maxs[j]; } p = @in[i].contents; @out[i].contents = p; @out[i].firstmarksurface = new helper.ObjectBuffer(loadmodel.marksurfaces, @in[i].firstmarksurface); @out[i].nummarksurfaces = @in[i].nummarksurfaces; p = @in[i].visofs; if (p == -1) @out[i].compressed_vis = null; else @out[i].compressed_vis = new bspfile.ByteBuffer(loadmodel.visdata, p); @out[i].efrags = null; for (j=0 ; j<4 ; j++) @out[i].ambient_sound_level[j] = @in[i].ambient_level[j]; } }
/* ============================================================================== ALIAS MODELS ============================================================================== */ /* ================= Mod_LoadAliasFrame ================= */ static void Mod_LoadAliasFrame(bspfile.ByteBuffer pin, ref object pframeindex, int numv, trivertx_t pbboxmin, trivertx_t pbboxmax, aliashdr_t pheader, string name) { trivertx_t[] pframe; trivertx_t pinframe; int i, j; daliasframe_t pdaliasframe; pdaliasframe = (daliasframe_t)pin; name = pdaliasframe.name; for (i=0 ; i<3 ; i++) { // these are byte values, so we don't have to worry about // endianness pbboxmin.v[i] = pdaliasframe.bboxmin.v[i]; pbboxmax.v[i] = pdaliasframe.bboxmax.v[i]; } pin.ofs += sizeof_daliasframe_t; pframe = new trivertx_t[numv]; pframeindex = (object)pframe; for (j=0 ; j<numv ; j++) { int k; pinframe = (trivertx_t)pin; // these are all byte values, so no need to deal with endianness pframe[j] = new trivertx_t(); pframe[j].lightnormalindex = pinframe.lightnormalindex; for (k=0 ; k<3 ; k++) { pframe[j].v[k] = pinframe.v[k]; } pin.ofs += sizeof_trivertx_t; } }
/* ================= Mod_LoadSubmodels ================= */ static void Mod_LoadSubmodels(bspfile.lump_t l) { bspfile.dmodel_t[] @out; int i, j, count; if ((l.filelen % bspfile.sizeof_dmodel_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dmodel_t; @out = new bspfile.dmodel_t[count]; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); for (int kk = 0; kk < count; kk++) { @out[kk] = (bspfile.dmodel_t)buf; buf.ofs += bspfile.sizeof_dmodel_t; } loadmodel.submodels = @out; loadmodel.numsubmodels = count; for ( i=0 ; i<count ; i++) { for (j=0 ; j<3 ; j++) { // spread the mins / maxs by a pixel @out[i].mins[j] -= 1; @out[i].maxs[j] += 1; } } }
/* ================= Mod_LoadAliasGroup ================= */ static void Mod_LoadAliasGroup(bspfile.ByteBuffer pin, ref object pframeindex, int numv, trivertx_t pbboxmin, trivertx_t pbboxmax, aliashdr_t pheader, string name) { daliasgroup_t pingroup; maliasgroup_t paliasgroup; int i, numframes; double[] poutintervals; pingroup = (daliasgroup_t)pin; numframes = pingroup.numframes; paliasgroup = new maliasgroup_t(); paliasgroup.frames = new maliasgroupframedesc_t[numframes]; for (int kk = 0; kk < numframes; kk++) paliasgroup.frames[kk] = new maliasgroupframedesc_t(); paliasgroup.numframes = numframes; for (i=0 ; i<3 ; i++) { // these are byte values, so we don't have to worry about endianness pbboxmin.v[i] = pingroup.bboxmin.v[i]; pbboxmax.v[i] = pingroup.bboxmax.v[i]; } pframeindex = (object)paliasgroup; pin.ofs += sizeof_daliasgroup_t; poutintervals = new double[numframes]; paliasgroup.intervals = poutintervals; for (i = 0; i < numframes; i++) { poutintervals[i] = BitConverter.ToSingle(pin.buffer, pin.ofs); pin.ofs += sizeof(Single); if (poutintervals[i] <= 0.0) sys_linux.Sys_Error("Mod_LoadAliasGroup: interval<=0"); } for (i=0 ; i<numframes ; i++) { Mod_LoadAliasFrame (pin, ref paliasgroup.frames[i].frame, numv, paliasgroup.frames[i].bboxmin, paliasgroup.frames[i].bboxmax, pheader, name); } }
/* ================= Mod_LoadSurfedges ================= */ static void Mod_LoadSurfedges(bspfile.lump_t l) { int i, count; int[] @out; if ((l.filelen % sizeof(int)) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / sizeof(int); @out = new int[count]; int ofs = l.fileofs; for (int kk = 0; kk < count; kk++) { @out[kk] = BitConverter.ToInt32(mod_base, ofs); ofs += sizeof(int); } loadmodel.surfedges = @out; loadmodel.numsurfedges = count; }
/* ================= Mod_LoadAliasSkinGroup ================= */ static void Mod_LoadAliasSkinGroup(bspfile.ByteBuffer pin, ref object pskinindex, int skinsize, aliashdr_t pheader) { daliasskingroup_t pinskingroup; maliasskingroup_t paliasskingroup; int i, numskins; double[] poutskinintervals; pinskingroup = (daliasskingroup_t)pin; numskins = pinskingroup.numskins; paliasskingroup = new maliasskingroup_t(); paliasskingroup.skindescs = new maliasskindesc_t[numskins]; for(int kk = 0; kk < numskins; kk++) paliasskingroup.skindescs[kk] = new maliasskindesc_t(); paliasskingroup.numskins = numskins; pskinindex = (object)paliasskingroup; pin.ofs += sizeof_daliasskingroup_t; poutskinintervals = new double[numskins]; paliasskingroup.intervals = poutskinintervals; for (i = 0; i < numskins; i++) { poutskinintervals[i] = BitConverter.ToSingle(pin.buffer, pin.ofs); pin.ofs += sizeof(Single); if (poutskinintervals[i] <= 0.0) sys_linux.Sys_Error("Mod_LoadAliasSkinGroup: interval<=0"); } for (i=0 ; i<numskins ; i++) { Mod_LoadAliasSkin (pin, ref paliasskingroup.skindescs[i].skin, skinsize, pheader); } }
/* ================= Mod_LoadTexinfo ================= */ static void Mod_LoadTexinfo(bspfile.lump_t l) { bspfile.texinfo_t[] @in; mtexinfo_t[] @out; int i, j, count; int miptex; double len1, len2; if ((l.filelen % bspfile.sizeof_texinfo_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_texinfo_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.texinfo_t[count]; @out = new mtexinfo_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.texinfo_t)buf; buf.ofs += bspfile.sizeof_texinfo_t; @out[kk] = new mtexinfo_t(); } loadmodel.texinfo = @out; loadmodel.numtexinfo = count; for ( i=0 ; i<count ; i++) { for(int k = 0; k < 2; k++) for (j=0 ; j<4 ; j++) @out[i].vecs[k][j] = @in[i].vecs[k][j]; len1 = mathlib.Length (@out[i].vecs[0]); len2 = mathlib.Length (@out[i].vecs[1]); len1 = (len1 + len2)/2; if (len1 < 0.32) @out[i].mipadjust = 4; else if (len1 < 0.49) @out[i].mipadjust = 3; else if (len1 < 0.99) @out[i].mipadjust = 2; else @out[i].mipadjust = 1; miptex = @in[i].miptex; @out[i].flags = @in[i].flags; if (loadmodel.textures == null) { @out[i].texture = render.r_notexture_mip; // checkerboard texture @out[i].flags = 0; } else { if (miptex >= loadmodel.numtextures) sys_linux.Sys_Error ("miptex >= loadmodel.numtextures"); @out[i].texture = loadmodel.textures[miptex]; if (@out[i].texture == null) { @out[i].texture = render.r_notexture_mip; // texture not found @out[i].flags = 0; } } } }
/* ================= Mod_LoadEdges ================= */ static void Mod_LoadEdges(bspfile.lump_t l) { bspfile.dedge_t[] @in; medge_t[] @out; int i, count; if ((l.filelen % bspfile.sizeof_dedge_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dedge_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dedge_t[count]; @out = new medge_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dedge_t)buf; buf.ofs += bspfile.sizeof_dedge_t; @out[kk] = new medge_t(); } loadmodel.edges = @out; loadmodel.numedges = count; for ( i=0 ; i<count ; i++) { @out[i].v[0] = (ushort)@in[i].v[0]; @out[i].v[1] = (ushort)@in[i].v[1]; } }
/* ================= Mod_LoadTextures ================= */ static void Mod_LoadTextures(bspfile.lump_t l) { int i, j, pixels, num, max, altmax; bspfile.miptex_t mt; texture_t tx, tx2; texture_t[] anims = new texture_t[10]; texture_t[] altanims = new texture_t[10]; bspfile.dmiptexlump_t m; for(int kk = 0; kk < 10; kk++) { anims[kk] = new texture_t(); altanims[kk] = new texture_t(); } if (l.filelen == 0) { loadmodel.textures = null; return; } bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); m = (bspfile.dmiptexlump_t)buf; loadmodel.numtextures = m.nummiptex; loadmodel.textures = new texture_t[m.nummiptex]; for (i=0 ; i<m.nummiptex ; i++) { loadmodel.textures[i] = new texture_t(); if (m.dataofs[i] == -1) continue; buf.ofs = l.fileofs + m.dataofs[i]; mt = (bspfile.miptex_t)buf; if ( (mt.width & 15) != 0 || (mt.height & 15) != 0 ) sys_linux.Sys_Error ("Texture " + mt.name + " is not 16 aligned"); pixels = (int)(mt.width*mt.height/64*85); tx = new texture_t(); tx.pixels = new byte[pixels]; loadmodel.textures[i] = tx; tx.name = mt.name; tx.width = mt.width; tx.height = mt.height; for (j=0 ; j<bspfile.MIPLEVELS ; j++) tx.offsets[j] = mt.offsets[j]/* + sizeof_texture_t*/ - bspfile.sizeof_miptex_t; // the pixels immediately follow the structures Buffer.BlockCopy(buf.buffer, buf.ofs + bspfile.sizeof_miptex_t, tx.pixels, 0, pixels); if (mt.name.StartsWith("sky")) render.R_InitSky(tx); } // // sequence the animations // for (i=0 ; i<m.nummiptex ; i++) { tx = loadmodel.textures[i]; if (tx == null || tx.name[0] != '+') continue; if (tx.anim_next != null) continue; // allready sequenced // find the number of frames in the animation //memset (anims, 0, sizeof(anims)); //memset (altanims, 0, sizeof(altanims)); max = tx.name[1]; altmax = 0; if (max >= 'a' && max <= 'z') max -= 'a' - 'A'; if (max >= '0' && max <= '9') { max -= '0'; altmax = 0; anims[max] = tx; max++; } else if (max >= 'A' && max <= 'J') { altmax = max - 'A'; max = 0; altanims[altmax] = tx; altmax++; } else sys_linux.Sys_Error ("Bad animating texture " + tx.name); for (j=i+1 ; j<m.nummiptex ; j++) { tx2 = loadmodel.textures[j]; if (tx2 == null || tx2.name[0] != '+') continue; if (tx2.name.Substring(2).CompareTo(tx.name.Substring(2)) != 0) continue; num = tx2.name[1]; if (num >= 'a' && num <= 'z') num -= 'a' - 'A'; if (num >= '0' && num <= '9') { num -= '0'; anims[num] = tx2; if (num+1 > max) max = num + 1; } else if (num >= 'A' && num <= 'J') { num = num - 'A'; altanims[num] = tx2; if (num+1 > altmax) altmax = num+1; } else sys_linux.Sys_Error ("Bad animating texture " + tx.name); } // link them all together for (j=0 ; j<max ; j++) { tx2 = anims[j]; if (tx2 == null) sys_linux.Sys_Error ("Missing frame " + j + " of " + tx.name); tx2.anim_total = max * ANIM_CYCLE; tx2.anim_min = j * ANIM_CYCLE; tx2.anim_max = (j+1) * ANIM_CYCLE; tx2.anim_next = anims[ (j+1)%max ]; if (altmax != 0) tx2.alternate_anims = altanims[0]; } for (j=0 ; j<altmax ; j++) { tx2 = altanims[j]; if (tx2 == null) sys_linux.Sys_Error ("Missing frame " + j + " of " + tx.name); tx2.anim_total = altmax * ANIM_CYCLE; tx2.anim_min = j * ANIM_CYCLE; tx2.anim_max = (j+1) * ANIM_CYCLE; tx2.anim_next = altanims[ (j+1)%altmax ]; if (max != 0) tx2.alternate_anims = anims[0]; } } }
/* ================= Mod_LoadFaces ================= */ static void Mod_LoadFaces(bspfile.lump_t l) { bspfile.dface_t[] @in; msurface_t[] @out; int i, count, surfnum; int planenum, side; if ((l.filelen % bspfile.sizeof_dface_t) != 0) sys_linux.Sys_Error ("MOD_LoadBmodel: funny lump size in " + loadmodel.name); count = l.filelen / bspfile.sizeof_dface_t; bspfile.ByteBuffer buf = new bspfile.ByteBuffer(mod_base, l.fileofs); @in = new bspfile.dface_t[count]; @out = new msurface_t[count]; for (int kk = 0; kk < count; kk++) { @in[kk] = (bspfile.dface_t)buf; buf.ofs += bspfile.sizeof_dface_t; @out[kk] = new msurface_t(); } loadmodel.surfaces = @out; loadmodel.numsurfaces = count; int color = colors[(icolor++) % 8]; for ( surfnum=0 ; surfnum<count ; surfnum++) { @out[surfnum].firstedge = @in[surfnum].firstedge; @out[surfnum].numedges = @in[surfnum].numedges; @out[surfnum].flags = 0; planenum = @in[surfnum].planenum; side = @in[surfnum].side; if (side != 0) @out[surfnum].flags |= SURF_PLANEBACK; @out[surfnum].plane = loadmodel.planes[planenum]; @out[surfnum].color = color; color += 0x40; @out[surfnum].texinfo = loadmodel.texinfo[@in[surfnum].texinfo]; CalcSurfaceExtents (@out[surfnum]); // lighting info for (i=0 ; i<bspfile.MAXLIGHTMAPS ; i++) @out[surfnum].styles[i] = @in[surfnum].styles[i]; i = @in[surfnum].lightofs; if (i == -1) @out[surfnum].samples = null; else @out[surfnum].samples = new bspfile.ByteBuffer(loadmodel.lightdata, i); // set the drawing flags flag if (@out[surfnum].texinfo.texture.name.StartsWith("sky")) // sky { @out[surfnum].flags |= (SURF_DRAWSKY | SURF_DRAWTILED); continue; } if (@out[surfnum].texinfo.texture.name.StartsWith("*")) // turbulent { @out[surfnum].flags |= (SURF_DRAWTURB | SURF_DRAWTILED); for (i=0 ; i<2 ; i++) { @out[surfnum].extents[i] = 16384; @out[surfnum].texturemins[i] = -8192; } continue; } } }
/* ================= Mod_LoadAliasSkin ================= */ static object Mod_LoadAliasSkin(bspfile.ByteBuffer pin, object pskinindex, int skinsize, aliashdr_t pheader) { int i; Uint8Array pskin; pskin = new Uint8Array(skinsize * render.r_pixbytes); pskinindex = (object)pskin; if (render.r_pixbytes == 1) { Buffer.BlockCopy(pin.buffer, pin.ofs, pskin, 0, skinsize); } else if (render.r_pixbytes == 2) { } else { sys_linux.Sys_Error("Mod_LoadAliasSkin: driver set invalid r_pixbytes: " + render.r_pixbytes + "\n"); } pin.ofs += skinsize; return pskinindex; }