private void GetChunkCoord(float x, float y, out int chunk_x, out int chunk_y) { // yeah, this is ugly. But safe for (chunk_x = 0; chunk_x < 64; chunk_x++) { float max_y = ChunkReader.ZEROPOINT - (chunk_x) * ChunkReader.TILESIZE; float min_y = max_y - ChunkReader.TILESIZE; if (y >= min_y - 0.1f && y < max_y + 0.1f) { break; } } for (chunk_y = 0; chunk_y < 64; chunk_y++) { float max_x = ChunkReader.ZEROPOINT - (chunk_y) * ChunkReader.TILESIZE; float min_x = max_x - ChunkReader.TILESIZE; if (x >= min_x - 0.1f && x < max_x + 0.1f) { break; } } if (chunk_y == 64 || chunk_x == 64) { PathGraph.Log(x + " " + y + " is at " + chunk_x + " " + chunk_y); //GetChunkCoord(x, y, out chunk_x, out chunk_y); } }
public TriangleMatrix(TriangleCollection tc) { { DateTime pre = DateTime.Now; PathGraph.Log("Build hash " + tc.GetNumberOfTriangles()); matrix = new SparseFloatMatrix2D <List <int> >(resolution, tc.GetNumberOfTriangles()); Vector vertex0; Vector vertex1; Vector vertex2; for (int i = 0; i < tc.GetNumberOfTriangles(); i++) { tc.GetTriangleVertices(i, out vertex0.x, out vertex0.y, out vertex0.z, out vertex1.x, out vertex1.y, out vertex1.z, out vertex2.x, out vertex2.y, out vertex2.z); float minx = Utils.min(vertex0.x, vertex1.x, vertex2.x); float maxx = Utils.max(vertex0.x, vertex1.x, vertex2.x); float miny = Utils.min(vertex0.y, vertex1.y, vertex2.y); float maxy = Utils.max(vertex0.y, vertex1.y, vertex2.y); Vector box_center; Vector box_halfsize; box_halfsize.x = resolution / 2; box_halfsize.y = resolution / 2; box_halfsize.z = 1E6f; int startx = matrix.LocalToGrid(minx); int endx = matrix.LocalToGrid(maxx); int starty = matrix.LocalToGrid(miny); int endy = matrix.LocalToGrid(maxy); for (int x = startx; x <= endx; x++) { for (int y = starty; y <= endy; y++) { float grid_x = matrix.GridToLocal(x); float grid_y = matrix.GridToLocal(y); box_center.x = grid_x + resolution / 2; box_center.y = grid_y + resolution / 2; box_center.z = 0; if (Utils.TestTriangleBoxIntersect(vertex0, vertex1, vertex2, box_center, box_halfsize)) { AddTriangleAt(grid_x, grid_y, i); } } } } DateTime post = DateTime.Now; TimeSpan ts = post.Subtract(pre); PathGraph.Log("done " + maxAtOne + " time " + ts); } }
public bool AddArchive(string file) { var a = new Archive(GameDir + file, 0, 0); if (a.IsOpen()) { archives.Add(a); PathGraph.Log("Add archive " + file); return(true); } return(false); }
public static bool TestTriangleBoxIntersect(Vector vertex0, Vector vertex1, Vector vertex2, Vector boxcenter, Vector boxhalfsize) { int i = 0; var pcenter = (float *)&boxcenter; var phalf = (float *)&boxhalfsize; var ptriangle0 = (float *)&vertex0; var ptriangle1 = (float *)&vertex1; var ptriangle2 = (float *)&vertex2; //int triBoxOverlap(float boxcenter[3],float boxhalfsize[3],float triverts[3][3]); try { i = ccode.triBoxOverlap(pcenter, phalf, ptriangle0, ptriangle1, ptriangle2); } catch (Exception e) { PathGraph.Log("WTF " + e); } if (i == 1) { return(true); } return(false); /* * Vector min, max; * min.x = ((vertex0.x < vertex1.x && vertex0.x < vertex2.x) ? vertex0.x : ((vertex1.x < vertex2.x) ? vertex1.x : vertex2.x)); * min.y = ((vertex0.y < vertex1.y && vertex0.y < vertex2.y) ? vertex0.y : ((vertex1.y < vertex2.y) ? vertex1.y : vertex2.y)); * min.z = ((vertex0.z < vertex1.z && vertex0.z < vertex2.z) ? vertex0.z : ((vertex1.z < vertex2.z) ? vertex1.z : vertex2.z)); * * max.x = ((vertex0.x > vertex1.x && vertex0.x > vertex2.x) ? vertex0.x : ((vertex1.x > vertex2.x) ? vertex1.x : vertex2.x)); * max.y = ((vertex0.y > vertex1.y && vertex0.y > vertex2.y) ? vertex0.y : ((vertex1.y > vertex2.y) ? vertex1.y : vertex2.y)); * max.z = ((vertex0.z > vertex1.z && vertex0.z > vertex2.z) ? vertex0.z : ((vertex1.z > vertex2.z) ? vertex1.z : vertex2.z)); * * bool outside = false; * if (min.x > boxcenter.x + boxhalfsize.x) outside = true; * if (max.x < boxcenter.x - boxhalfsize.x) outside = true; * * if (min.y > boxcenter.y + boxhalfsize.y) outside = true; * if (max.y < boxcenter.y - boxhalfsize.y) outside = true; * * if (min.z > boxcenter.z + boxhalfsize.z) outside = true; * if (max.z < boxcenter.z - boxhalfsize.z) outside = true; * * return !outside;*/ }
public TriangleQuadtree(TriangleCollection tc) { PathGraph.Log("Build oct " + tc.GetNumberOfTriangles()); this.tc = tc; tc.GetBBox(out min.x, out min.y, out min.z, out max.x, out max.y, out max.z); rootNode = new Node(this, min, max); var tlist = new SimpleLinkedList(); for (int i = 0; i < tc.GetNumberOfTriangles(); i++) { tlist.AddNew(i); } rootNode.Build(tlist, 0); PathGraph.Log("done"); }
private void EvictIfNeeded() { if (loadedChunks.Count >= maxCached) { TriangleCollection toEvict = null; foreach (TriangleCollection tc in loadedChunks) { int LRU = tc.LRU; if (toEvict == null || LRU < toEvict.LRU) { toEvict = tc; } } loadedChunks.Remove(toEvict); chunks.Clear(toEvict.grid_x, toEvict.grid_y); PathGraph.Log("Evict chunk at " + toEvict.base_x + " " + toEvict.base_y); } }
public bool Contains(T k) { uint key = GetEntryIn(array, k); Entry rover = array[key]; while (rover != null) { if (rover.next == rover) { PathGraph.Log("lsdfjlskfjkl>"); } if (rover.value.Equals(k)) { return(true); } rover = rover.next; } return(false); }
public bool TryGetValue(TKey k, out TValue v) { uint key = GetEntryIn(array, k); Entry rover = array[key]; while (rover != null) { if (rover.next == rover) { PathGraph.Log("ksjdflksdjf"); } if (rover.key.Equals(k)) { v = rover.value; return(true); } rover = rover.next; } v = default(TValue); return(false); }
private void LoadChunkAt(float x, float y) { int grid_x, grid_y; GetGridStartAt(x, y, out grid_x, out grid_y); if (chunks.IsSet(grid_x, grid_y)) { return; } EvictIfNeeded(); var tc = new TriangleCollection(); float min_x, max_x, min_y, max_y; GetGridLimits(grid_x, grid_y, out min_x, out min_y, out max_x, out max_y); PathGraph.Log("Got asked for triangles at " + x + ", " + y); PathGraph.Log("Need triangles grid (" + min_x + " , " + min_y + ") - (" + max_x + ", " + max_y); tc.SetLimits(min_x - 1, min_y - 1, -1E30f, max_x + 1, max_y + 1, 1E30f); foreach (TriangleSupplier s in suppliers) { s.GetTriangles(tc, min_x, min_y, max_x, max_y); } tc.CompactVertices(); tc.ClearVertexMatrix(); // not needed anymore tc.base_x = grid_x; tc.base_y = grid_y; PathGraph.Log(" it got " + tc.GetNumberOfTriangles() + " triangles and " + tc.GetNumberOfVertices() + " vertices"); loadedChunks.Add(tc); chunks.Set(grid_x, grid_y, tc); PathGraph.Log("Got triangles grid (" + tc.min_x + " , " + tc.min_y + ") - (" + tc.max_x + ", " + tc.max_y); }
public void ReportSize(string pre) { PathGraph.Log(pre + "no_vertices: " + no_vertices); PathGraph.Log(pre + "no_triangles: " + no_triangles); }
public void Build(SimpleLinkedList triangles, int depth) { if (triangles.Count < SplitSize || depth >= 10) { this.triangles = new int[triangles.Count]; SimpleLinkedList.Node rover = triangles.first; int i = 0; while (rover != null) { this.triangles[i] = rover.val; rover = rover.next; i++; } if (triangles.Count >= SplitSize) { Vector size; Utils.sub(out size, ref max, ref min); PathGraph.Log("New leaf " + depth + " size: " + triangles.Count + " " + size); } } else { this.triangles = null; var xl = new float[3] { min.x, mid.x, max.x }; var yl = new float[3] { min.y, mid.y, max.y }; var boxhalfsize = new Vector( mid.x - min.x, mid.y - min.y, 1E10f); children = new Node[2, 2]; Vector vertex0; Vector vertex1; Vector vertex2; // if (depth <= 3) // PathGraph.Log(depth + " Pre tris: " + triangles.Count); int ugh = 0; //foreach (int triangle in triangles) for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { SimpleLinkedList.Node rover = triangles.GetFirst(); var childTris = new SimpleLinkedList(); children[x, y] = new Node(tree, new Vector(xl[x], yl[y], 0), new Vector(xl[x + 1], yl[y + 1], 0)); children[x, y].parent = this; int c = 0; while (rover != null) { c++; SimpleLinkedList.Node next = rover.next; int triangle = rover.val; tree.tc.GetTriangleVertices(triangle, out vertex0.x, out vertex0.y, out vertex0.z, out vertex1.x, out vertex1.y, out vertex1.z, out vertex2.x, out vertex2.y, out vertex2.z); if (Utils.TestTriangleBoxIntersect(vertex0, vertex1, vertex2, children[x, y].mid, boxhalfsize)) { childTris.Steal(rover, triangles); ugh++; } rover = next; } if (c == 0) { children[x, y] = null; // drop that } else { //PathGraph.Log(depth + " of " + c + " stole " + childTris.RealCount + "(" + childTris.Count + ")" + " left is " + triangles.RealCount + "(" + triangles.Count + ")"); children[x, y].Build(childTris, depth + 1); triangles.StealAll(childTris); } /*if (depth == 0) * { * PathGraph.Log("Post tris: " + triangles.Count); * PathGraph.Log("count: " + c); * }*/ } } } }
private void Error(string error) { PathGraph.Log(error); }
private void AddTriangles(TriangleCollection s, WMOInstance wi) { float dx = wi.pos.x; float dy = wi.pos.y; float dz = wi.pos.z; float dir_x = wi.dir.z; float dir_y = wi.dir.y - 90; float dir_z = -wi.dir.x; PathGraph.Log("modeli: " + dir_x + " " + dir_y + " " + dir_z); WMO wmo = wi.wmo; foreach (WMOGroup g in wmo.groups) { var vertices = new int[g.nVertices]; for (int i = 0; i < g.nVertices; i++) { int off = i * 3; float x = g.vertices[off]; float y = g.vertices[off + 2]; float z = g.vertices[off + 1]; rotate(z, y, dir_x, out z, out y); rotate(x, y, dir_z, out x, out y); rotate(x, z, dir_y, out x, out z); float xx = x + dx; float yy = y + dy; float zz = -z + dz; float finalx = ChunkReader.ZEROPOINT - zz; float finaly = ChunkReader.ZEROPOINT - xx; float finalz = yy; vertices[i] = s.AddVertex(finalx, finaly, finalz); } // PathGraph.Log("nTriangles: " + g.nTriangles); for (int i = 0; i < g.nTriangles; i++) { //if ((g.materials[i] & 0x1000) != 0) { int off = i * 3; int i0 = vertices[g.triangles[off]]; int i1 = vertices[g.triangles[off + 1]]; int i2 = vertices[g.triangles[off + 2]]; int t = s.AddTriangle(i0, i1, i2, ChunkedTriangleCollection.TriangleFlagObject); //if(t != -1) s.SetTriangleExtra(t, g.materials[0], 0, 0); } } } int doodadset = wi.doodadset; if (doodadset < wmo.nDoodadSets) { uint firstDoodad = wmo.doodads[doodadset].firstInstance; uint nDoodads = wmo.doodads[doodadset].nInstances; for (uint i = 0; i < nDoodads; i++) { uint d = firstDoodad + i; ModelInstance mi = wmo.doodadInstances[d]; if (mi != null) { //PathGraph.Log("I got model " + mi.model.fileName + " at " + mi.pos); //AddTrianglesGroupDoodads(s, mi, wi.dir, wi.pos, 0.0f); // DOes not work :( } } } }
public MPQTriangleSupplier() { string[] archiveNames = { "patch.MPQ", "enUS\\patch-enUS.MPQ", "enGB\\patch-enGB.MPQ", "lichking.MPQ", "common-2.MPQ", "common.MPQ", "expansion.MPQ", "enUS\\lichking-locale-enUS.MPQ","enUS\\locale-enUS.MPQ", "enUS\\expansion-locale-enUS.MPQ", "enGB\\lichking-locale-enGB.MPQ","enGB\\locale-enGB.MPQ", "enGB\\expansion-locale-enGB.MPQ", "enUS\\base-enUS.MPQ", "enGB\\base-enGB.MPQ", "enUS\\backup-enUS.MPQ", "enGB\\backup-enGB.MPQ" }; //StormDll.ArchiveSet archive = null; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); archive = new ArchiveSet(); string regGameDir = archive.SetGameDirFromReg(); //string gameDir = @"C:\WoW 335\Data\"; //archive.SetGameDir(gameDir); zoneToMapId = new Dictionary <string, int>(); mapIdToFile = new Dictionary <int, string>(); areaIdToName = new Dictionary <int, string>(); PathGraph.Log("Game dir is " + regGameDir); archive.AddArchives(archiveNames); modelmanager = new ModelManager(archive, 80); wmomanager = new WMOManager(archive, modelmanager, 30); archive.ExtractFile("DBFilesClient\\AreaTable.dbc", "PPather\\AreaTable.dbc"); var areas = new DBC(); var af = new DBCFile("PPather\\AreaTable.dbc", areas); for (int i = 0; i < areas.recordCount; i++) { var AreaID = (int)areas.GetUint(i, 0); var WorldID = (int)areas.GetUint(i, 1); var Parent = (int)areas.GetUint(i, 2); string Name = areas.GetString(i, 11); areaIdToName.Add(AreaID, Name); if (WorldID != 0 && WorldID != 1 && WorldID != 530) { //// PathGraph.Log(String.Format("{0,4} {1,3} {2,3} {3}", AreaID, WorldID, Parent, Name)); } //0 uint AreaID //1 uint Continent (refers to a WorldID) //2 uint Region (refers to an AreaID) } for (int i = 0; i < areas.recordCount; i++) { var AreaID = (int)areas.GetUint(i, 0); var WorldID = (int)areas.GetUint(i, 1); var Parent = (int)areas.GetUint(i, 2); string Name = areas.GetString(i, 11); string TotalName = ""; //areaIdToName.Add(AreaID, Name); //areaIdParent.Add(AreaID, Parent); string ParentName = ""; if (!areaIdToName.TryGetValue(Parent, out ParentName)) { TotalName = ":" + Name; } else { TotalName = Name + ":" + ParentName; } if (!zoneToMapId.ContainsKey(Name) && !zoneToMapId.ContainsKey(TotalName)) { zoneToMapId.Add(TotalName, WorldID); //PathGraph.Log(TotalName + " => " + WorldID); } else { int id; zoneToMapId.TryGetValue(TotalName, out id); //// PathGraph.Log("Duplicate: " + TotalName + " " + WorldID +" " + id); } //0 uint AreaID //1 uint Continent (refers to a WorldID) //2 uint Region (refers to an AreaID) } }
private void GetChunkData(TriangleCollection triangles, int chunk_x, int chunk_y, SparseMatrix3D <WMO> instances) { if (chunk_x < 0) { return; } if (chunk_y < 0) { return; } if (chunk_x > 63) { return; } if (chunk_y > 63) { return; } if (triangles == null) { return; } if (wdtf == null) { return; } if (wdt == null) { return; } wdtf.LoadMapTile(chunk_x, chunk_y); MapTile t = wdt.maptiles[chunk_x, chunk_y]; if (t != null) { //Console.Write(" render"); // Map tiles for (int ci = 0; ci < 16; ci++) { for (int cj = 0; cj < 16; cj++) { MapChunk c = t.chunks[ci, cj]; if (c != null) { AddTriangles(triangles, c); } } } // World objects foreach (WMOInstance wi in t.wmois) { if (wi != null && wi.wmo != null) { String fn = wi.wmo.fileName; int last = fn.LastIndexOf('\\'); fn = fn.Substring(last + 1); // PathGraph.Log(" wmo: " + fn + " at " + wi.pos); if (fn != null) { WMO old = instances.Get((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z); if (old == wi.wmo) { //PathGraph.Log("Already got " + fn); } else { instances.Set((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z, wi.wmo); AddTriangles(triangles, wi); } } } } foreach (ModelInstance mi in t.modelis) { if (mi != null && mi.model != null) { String fn = mi.model.fileName; int last = fn.LastIndexOf('\\'); // fn = fn.Substring(last + 1); //PathGraph.Log(" wmi: " + fn + " at " + mi.pos); AddTriangles(triangles, mi); //PathGraph.Log(" model: " + fn); } } PathGraph.Log("wee"); /*PathGraph.Log( * String.Format(" Triangles - Map: {0,6} Objects: {1,6} Models: {2,6}", * map_triangles.GetNumberOfTriangles(), * obj_triangles.GetNumberOfTriangles(), * model_triangles.GetNumberOfTriangles())); */ } PathGraph.Log(" done"); wdt.maptiles[chunk_x, chunk_y] = null; // clear it atain //myChunk.triangles.ClearVertexMatrix(); // not needed anymore //return myChunk; }