public static void add_cell_block(int min_x, int min_y, int max_x, int max_y, CellArray cellArray, uint id) { for (var i = min_x; i <= max_x; i++) { for (var j = min_y; j <= max_y; j++) { if (i < 0 || j < 0 || i >= LandDefs.LandLength || j >= LandDefs.LandLength) { continue; } var ui = (uint)i; var uj = (uint)j; var cellID = (((uj >> 3) | 32 * (ui & 0xFFFFFFF8)) << 16) | ((uj & 7) + 8 * (ui & 7) + 1); // FIXME! if (id >> 16 != cellID >> 16) { continue; } var cell = LScape.get_landcell(cellID); cellArray.add_cell(cellID, cell); } } }
public void find_building_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { /*foreach (var portal in Portals) * { * var otherCell = portal.GetOtherCell(); * if (otherCell != null) * otherCell.check_building_transit(portal.OtherPortalID, numParts, parts, cellArray); * }*/ }
public static void add_all_outside_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray, uint id) { if (cellArray.AddedOutside) { return; } cellArray.AddedOutside = true; if (numParts == 0) { return; } var min_x = 0; var min_y = 0; var max_x = 0; var max_y = 0; for (var i = 0; i < numParts; i++) { var curPart = parts[i]; var loc = new Position(curPart.Pos); if (!LandDefs.AdjustToOutside(loc)) { continue; } var _lcoord = LandDefs.gid_to_lcoord(loc.ObjCellID); if (_lcoord == null) { continue; } var lcoord = _lcoord.Value; var lx = (int)(((loc.ObjCellID & 0xFFFF) - 1) / 8); var ly = (int)(((loc.ObjCellID & 0xFFFF) - 1) % 8); for (var j = 0; j < numParts; j++) { var otherPart = parts[j]; if (otherPart == null) { continue; } // add if missing: otherPart.Always2D, checks degrades.degradeMode != 1 var bbox = new BBox(); bbox.LocalToGlobal(otherPart.GetBoundingBox(), otherPart.Pos, loc); var min_cx = (int)Math.Floor(bbox.Min.X / 24.0f); var min_cy = (int)Math.Floor(bbox.Min.Y / 24.0f); var max_cx = (int)Math.Floor(bbox.Max.X / 24.0f); var max_cy = (int)Math.Floor(bbox.Max.Y / 24.0f); min_x = Math.Min(min_cx - lx, min_x); min_y = Math.Min(min_cy - ly, min_y); max_x = Math.Max(max_cx - lx, max_x); max_y = Math.Max(max_cy - ly, max_y); } add_cell_block(min_x + (int)lcoord.X, min_y + (int)lcoord.Y, max_x + (int)lcoord.X, max_y + (int)lcoord.Y, cellArray, id); } }
public override void find_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { var checkOutside = false; foreach (var portal in Portals) { var portalPoly = CellStructure.Polygons[portal.PolygonId]; foreach (var part in parts) { if (part == null) { continue; } var sphere = part.GfxObj.PhysicsSphere; if (sphere == null) { sphere = part.GfxObj.DrawingSphere; } if (sphere == null) { continue; } var center = Pos.LocalToLocal(part.Pos, sphere.Center); var rad = sphere.Radius + PhysicsGlobals.EPSILON; var dist = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (portal.PortalSide) { if (dist < -rad) { continue; } } else { if (dist > rad) { continue; } } var bbox = part.GetBoundingBox(); var box = new BBox(); box.LocalToLocal(bbox, part.Pos, Pos); var sidedness = portalPoly.Plane.intersect_box(box); if (sidedness == Sidedness.Positive && !portal.PortalSide || sidedness == Sidedness.Negative && portal.PortalSide) { continue; } if (portal.OtherCellId == ushort.MaxValue) { checkOutside = true; break; } // LoadCells var otherCell = GetVisible(portal.OtherCellId); if (otherCell == null) { cellArray.add_cell(portal.OtherCellId, null); break; } var cellBox = new BBox(); cellBox.LocalToLocal(bbox, part.Pos, otherCell.Pos); if (otherCell.CellStructure.box_intersects_cell(cellBox)) { cellArray.add_cell(otherCell.ID, otherCell); break; } } } if (checkOutside) { LandCell.add_all_outside_cells(numParts, parts, cellArray, ID); } }
public static void find_cell_list(Position pos, int numCylSphere, CylSphere cylSphere, CellArray cellArray, SpherePath path) { }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { add_all_outside_cells(position, numSphere, sphere, cellArray); base.find_transit_cells(position, numSphere, sphere, cellArray, path); }
public void check_building_transit(ushort portalId, Position pos, int numSphere, List <Sphere> spheres, CellArray cellArray, SpherePath path) { //if (portalId == 0) return; if (portalId == ushort.MaxValue) { return; } foreach (var sphere in spheres) { var globSphere = new Sphere(Pos.Frame.GlobalToLocal(sphere.Center), sphere.Radius); if (CellStructure.sphere_intersects_cell(globSphere) == BoundingType.Outside) { continue; } if (path != null) { path.HitsInteriorCell = true; } cellArray.add_cell(ID, this); } }
public static void find_cell_list(Position position, int numSphere, Sphere sphere, CellArray cellArray, ref ObjCell currCell, SpherePath path) { find_cell_list(position, numSphere, new List <Sphere>() { sphere }, cellArray, ref currCell, path); }
public virtual void find_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { // empty base }
public static void find_cell_list(Position position, int numCylSphere, List <CylSphere> cylSphere, CellArray cellArray, SpherePath path) { if (numCylSphere > 10) { numCylSphere = 10; } var spheres = new List <Sphere>(); for (var i = 0; i < numCylSphere; i++) { var sphere = new Sphere(); sphere.Center = position.LocalToGlobal(cylSphere[i].LowPoint); sphere.Radius = cylSphere[i].Radius; spheres.Add(sphere); } ObjCell empty = null; find_cell_list(position, numCylSphere, spheres, cellArray, ref empty, path); }
public static void find_cell_list(CellArray cellArray, ref ObjCell checkCell, SpherePath path) { find_cell_list(path.CheckPos, path.NumSphere, path.GlobalSphere, cellArray, ref checkCell, path); }
public static void find_cell_list(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, ref ObjCell currCell, SpherePath path) { cellArray.NumCells = 0; cellArray.AddedOutside = false; var visibleCell = GetVisible(position.ObjCellID); if ((position.ObjCellID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } cellArray.add_cell(position.ObjCellID, visibleCell); } else { LandCell.add_all_outside_cells(position, numSphere, sphere, cellArray); } if (visibleCell != null && numSphere != 0) { for (var i = 0; i < cellArray.Cells.Count; i++) { var cell = cellArray.Cells.Values.ElementAt(i); if (cell == null) { continue; } cell.find_transit_cells(position, numSphere, sphere, cellArray, path); } //var checkCells = cellArray.Cells.Values.ToList(); //foreach (var cell in checkCells) //cell.find_transit_cells(position, numSphere, sphere, cellArray, path); if (currCell != null) { currCell = null; foreach (var cell in cellArray.Cells.Values) { if (cell == null) { continue; } var blockOffset = LandDefs.GetBlockOffset(position.ObjCellID, cell.ID); var localPoint = sphere[0].Center - blockOffset; if (cell.point_in_cell(localPoint)) { currCell = cell; if ((cell.ID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } return; // break? } } } } } if (!cellArray.LoadCells && (position.ObjCellID & 0xFFFF) >= 0x100) { var cells = cellArray.Cells.Values.ToList(); foreach (var cell in cells) { if (cell == null) { continue; } if (visibleCell.ID == cell.ID) { continue; } var found = false; foreach (var stab in ((EnvCell)visibleCell).VisibleCells.Values) { if (cell.ID == stab.ID) { found = true; break; } } if (!found) { cellArray.remove_cell(cell); } } } }
public void find_building_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { foreach (var portal in Portals) { var otherCell = portal.GetOtherCell(CurCell.ID); if (otherCell != null) { otherCell.check_building_transit(portal.OtherPortalId, numParts, parts, cellArray); } } }
public void find_building_transit_cells(Position pos, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { foreach (var portal in Portals) { var otherCell = portal.GetOtherCell(CurCell.ID); if (otherCell != null) { otherCell.check_building_transit(portal.OtherPortalId, pos, numSphere, sphere, cellArray, path); } } }
public static void add_outside_cell(CellArray cellArray, Vector2 lcoord) { add_outside_cell(cellArray, lcoord.X, lcoord.Y); }
public virtual void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { // empty base }
public override void find_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { add_all_outside_cells(numParts, parts, cellArray, ID); base.find_transit_cells(numParts, parts, cellArray); }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { if (Building != null) { Building.find_building_transit_cells(position, numSphere, sphere, cellArray, path); } }
public static void add_all_outside_cells(Position position, int numSphere, List <Sphere> spheres, CellArray cellArray) { if (cellArray.AddedOutside) { return; } if (numSphere != 0) { foreach (var sphere in spheres) { var cellPoint = position.ObjCellID; var center = sphere.Center; if (!LandDefs.AdjustToOutside(ref cellPoint, ref center)) { break; } var point = new Vector2(); point.X = center.X - (float)Math.Floor(center.X / 24.0f) * 24.0f; point.Y = center.Y - (float)Math.Floor(center.Y / 24.0f) * 24.0f; var minRad = sphere.Radius; var maxRad = 24.0f - minRad; var lcoord = LandDefs.gid_to_lcoord(cellPoint); if (lcoord != null) { add_outside_cell(cellArray, lcoord.Value); check_add_cell_boundary(cellArray, point, lcoord.Value, minRad, maxRad); } } } else { if (!LandDefs.AdjustToOutside(position)) { return; } var lcoord = LandDefs.gid_to_lcoord(position.ObjCellID); if (lcoord != null) { add_outside_cell(cellArray, lcoord.Value); } } }
public override void find_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { if (Building != null) { Building.find_building_transit_cells(numParts, parts, cellArray); } }
public void check_building_transit(int portalId, int numParts, List <PhysicsPart> parts, CellArray cellArray) { //if (portalId == 0) return; if (portalId == ushort.MaxValue) { return; } var portal = Portals[portalId]; var portalPoly = CellStructure.Portals[portalId]; foreach (var part in parts) { if (part == null) { continue; } Sphere boundingSphere = null; if (part.GfxObj.PhysicsSphere != null) { boundingSphere = part.GfxObj.PhysicsSphere; } else { boundingSphere = part.GfxObj.DrawingSphere; } if (boundingSphere == null) { continue; } var center = Pos.LocalToLocal(part.Pos, boundingSphere.Center); var rad = boundingSphere.Radius + PhysicsGlobals.EPSILON; var diff = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (portal.PortalSide) { if (diff > rad) { continue; } } else { if (diff < -rad) { continue; } } var box = new BBox(); box.LocalToLocal(part.GetBoundingBox(), part.Pos, Pos); var intersect = portalPoly.Plane.intersect_box(box); if (intersect == Sidedness.Crossing || intersect == Sidedness.Positive && portal.PortalSide || intersect == Sidedness.Negative && !portal.PortalSide) { if (!CellStructure.box_intersects_cell(box)) { continue; } cellArray.add_cell(ID, this); find_transit_cells(numParts, parts, cellArray); return; } } }
public void find_building_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { /*foreach (var portal in Portals) * { * var otherCell = portal.GetOtherCell(); * if (otherCell != null) * otherCell.check_building_transit(portal.OtherPortalID, numSphere, sphere, cellArray, path); * }*/ }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> spheres, CellArray cellArray, SpherePath path) { var checkOutside = false; foreach (var portal in Portals) { var portalPoly = CellStructure.Polygons[portal.PolygonId]; if (portal.OtherCellId == ushort.MaxValue) { foreach (var sphere in spheres) { var rad = sphere.Radius + PhysicsGlobals.EPSILON; var center = Pos.Frame.GlobalToLocal(sphere.Center); var dist = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (dist > -rad && dist < rad) { checkOutside = true; break; } } } else { var otherCell = GetVisible(portal.OtherCellId); if (otherCell != null) { foreach (var sphere in spheres) { var center = otherCell.Pos.Frame.GlobalToLocal(sphere.Center); var _sphere = new Sphere(center, sphere.Radius); var boundingType = otherCell.CellStructure.sphere_intersects_cell(_sphere); if (boundingType != BoundingType.Outside) { cellArray.add_cell(otherCell.ID, otherCell); break; } } } else { foreach (var sphere in spheres) { var center = Pos.Frame.GlobalToLocal(sphere.Center); var _sphere = new Sphere(center, sphere.Radius + PhysicsGlobals.EPSILON); var portalSide = portal.PortalSide; var dist = Vector3.Dot(_sphere.Center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (dist > -_sphere.Radius && portalSide || dist < _sphere.Radius && !portalSide) { cellArray.add_cell(portal.OtherCellId, null); break; } } } } } if (checkOutside) { LandCell.add_all_outside_cells(position, numSphere, spheres, cellArray); } }
public static void add_all_outside_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { // not implemented yet }