public RoomTemplate() { m_templateName = ""; m_navMeshTemplate = null; m_floor = null; m_walls = null; m_backgroundObjects = null; m_forgroundObjects = null; }
public NavCellNeighborIterator(NavMesh navMesh, uint navCellIndex) { m_navMesh = navMesh; m_navCellIndex = navCellIndex; m_neighborDirection = MathConstants.eDirection.none; m_neighborNavCellIndex = navCellIndex; Next(); }
private void UpdateCurrentNavRef() { SessionData sessionData = SessionData.GetInstance(); GameData gameData = sessionData.CurrentGameData; RoomData roomData = gameData.GetCachedRoomData(gameData.CurrentRoomKey); if (roomData != null) { AsyncRPGSharedLib.Navigation.NavMesh navMesh = roomData.StaticRoomData.NavMesh; Point2d pixelPoint = WidgetEventDispatcher.GetMousePosition(); Point3d roomPoint = GameConstants.ConvertPixelPositionToRoomPosition(pixelPoint); m_currentNavRef = navMesh.ComputeNavRefAtPoint(roomPoint); } }
public Point3d world_position; // World space coordinates of the lower-left hand corner (min corner) #endregion Fields #region Constructors public Room(RoomKey rk) { room_key = rk; random_seed = rk.GetHashCode(); world_position.Set( (float)room_key.x * WorldConstants.ROOM_X_SIZE, (float)room_key.y * WorldConstants.ROOM_Y_SIZE, (float)room_key.z * WorldConstants.ROOM_Z_SIZE); portalRoomSideBitmask = new TypedFlags<MathConstants.eSignedDirection>(); connectivity_id= -1; portals = new List<Portal>(); mobSpawners = new List<MobSpawner>(); static_room_data = new StaticRoomData(); static_room_data.room_template_name = ""; static_room_data.objects = null; runtime_nav_mesh = new NavMesh(); }
// Utilities public bool IsWorldPointOnNavMesh(Point3d testPoint) { GameData gameData = CurrentGame; RoomData roomData = gameData.GetCachedRoomData(gameData.CurrentRoomKey); bool pointOnNavMesh = false; if (roomData != null) { AsyncRPGSharedLib.Navigation.NavMesh navMesh = roomData.StaticRoomData.NavMesh; NavRef navRef = navMesh.ComputeNavRefAtPoint(testPoint); if (navRef != null && navRef.IsValid) { pointOnNavMesh = true; } } return(pointOnNavMesh); }
private static bool ValidateCompressedNavMeshData( RoomTemplate roomTemplate, byte[] compressedNavCells, byte[] compressedPVS) { bool success = true; AsyncRPGSharedLib.Navigation.NavMesh testNavMesh = AsyncRPGSharedLib.Navigation.NavMesh.FromCompressedNavMeshData(compressedNavCells, compressedPVS); if (!testNavMesh.Equals(roomTemplate.NavMeshTemplate)) { Debug.LogError( string.Format("RoomTemplateParser: ERROR: Template {0} nav mesh decompressed incorrectly", roomTemplate.TemplateName)); Assert.Throw("RoomTemplateParser: Nav Mesh decompression error"); success = false; } return(success); }
private void DebugDrawNavMesh() { RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { for (uint navCellIndex = 0; navCellIndex < navMesh.GetNavCellCount(); navCellIndex++) { int connectivityId = navMesh.GetNavCellConnectivityID(navCellIndex); if (connectivityId != AsyncRPGSharedLib.Navigation.NavMesh.EMPTY_NAV_CELL) { for (MathConstants.eDirection direction = MathConstants.eDirection.first; direction < MathConstants.eDirection.count; direction++) { if (!navMesh.NavCellHasNeighbor(navCellIndex, direction)) { Point3d portalLeft, portalRight; Vector3 portalVertexLeft, portalVertexRight; navMesh.ComputePointsOnNavCellSide(navCellIndex, direction, out portalLeft, out portalRight); portalVertexLeft = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalLeft); portalVertexRight = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalRight); Debug.DrawLine( portalVertexLeft, portalVertexRight, Color.yellow, 0.0f, // duration false); // depth test } } } } } }
public static bool AddPathRequest( RoomKey roomKey, Point3d startPoint, Point3d endPoint, PathComputer.OnPathComputerComplete onComplete) { bool success = false; if (m_instance != null) { PathComputer pathComputer = new PathComputer(); AsyncRPGSharedLib.Navigation.NavMesh navMesh = GetNavMesh(roomKey); if (pathComputer.NonBlockingPathRequest(navMesh, roomKey, startPoint, endPoint, onComplete)) { m_instance.m_requestQueue.Add(pathComputer); success = true; } } return(success); }
} // Regular grid of connectivity ids public StaticRoomData() { RoomObjects = new List <RoomObject>(); RoomTemplate = null; NavMesh = new AsyncRPGSharedLib.Navigation.NavMesh(); }
private void DebugDrawTestVisibility() { int characterID = _gameWorldController.Model.CurrentCharacterID; RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; CharacterEntity entity = _gameWorldController.Model.GetCharacterEntity(characterID); if (entity != null) { Point3d startWorldPos = entity.Position; Point2d endPixelPos = GetMousePixelPosition(); Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos); // Draw the target nav cell AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos); NavRef endNavRef = navMesh.ComputeNavRefAtPoint(endWorldPos); if (startNavRef.IsValid && endNavRef.IsValid) { bool canSee = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef); Color debugColor = canSee ? Color.green : Color.red; // Draw a box around the nav cell { Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex); Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos); float halfWidth = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f; Vector3 boxUL = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f); Vector3 boxUR = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f); Vector3 boxLR = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f); Vector3 boxLL = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f); Debug.DrawLine(boxUL, boxUR, debugColor); Debug.DrawLine(boxUR, boxLR, debugColor); Debug.DrawLine(boxLR, boxLL, debugColor); Debug.DrawLine(boxLL, boxUL, debugColor); } // Update the visibility status label _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE"; _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y); _visibilityStatusLabel.Color = debugColor; _visibilityStatusLabel.Visible = true; // Render the ray-cast line { Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos); Vector3 endVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos); Debug.DrawLine(startVertex, endVertex, debugColor); } } } } }
private void DebugDrawTestPath() { int characterID = _gameWorldController.Model.CurrentCharacterID; RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; CharacterEntity entity = _gameWorldController.Model.GetCharacterEntity(characterID); if (entity != null) { Point2d mousePixelPos = GetMousePixelPosition(); Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos); // Draw the target nav cell string targetLabel = ""; AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos); if (navRef.IsValid) { Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex); Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos); float halfWidth = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f; Vector3 boxUL = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f); Vector3 boxUR = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f); Vector3 boxLR = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f); Vector3 boxLL = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f); Debug.DrawLine(boxUL, boxUR, Color.blue); Debug.DrawLine(boxUR, boxLR, Color.blue); Debug.DrawLine(boxLR, boxLL, Color.blue); Debug.DrawLine(boxLL, boxUL, Color.blue); targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString(); } // Attempt to compute a path from the active player to the mouse _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos); // Update the path status label { if (_pathComputer.ResultCode == PathComputer.eResult.success) { _pathStatusLabel.Text = "VALID" + targetLabel; _pathStatusLabel.Color = Color.green; } else { _pathStatusLabel.Text = _pathComputer.ResultCode + targetLabel; _pathStatusLabel.Color = Color.red; } _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y); _pathStatusLabel.Visible = true; } // Render the raw path for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++) { Point3d previousPoint = _pathComputer.FinalPath[stepIndex - 1].StepPoint; Point3d currentPoint = _pathComputer.FinalPath[stepIndex].StepPoint; Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint); Vector3 currentPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint); Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green); } } } }
public static NavMesh FromNavMeshXML(XmlNode navMeshXml) { NavMesh navMesh = new NavMesh(); navMesh.NavCellsFromXML(navMeshXml); if (navMesh.m_navCells != null && navMesh.m_navCells.Length > 0) { navMesh.BuildNavCellPotentiallyVisibleSet(); } return navMesh; }
public bool Equals(NavMesh other) { if ((m_roomKey == null && other.m_roomKey != null) || (m_roomKey != null && other.m_roomKey == null) || (m_roomKey != null && other.m_roomKey != null && m_roomKey.Equals(other.m_roomKey))) { return false; } if (!m_boundingBox.Equals(other.m_boundingBox)) { return false; } if (m_rowCount != other.m_rowCount) { return false; } if (m_colomnCount != other.m_colomnCount) { return false; } if (m_nonEmptyNavCellCount != other.m_nonEmptyNavCellCount) { return false; } if ((m_navCells == null && other.m_navCells != null) || (m_navCells != null && other.m_navCells == null)) { return false; } else if (m_navCells != null && other.m_navCells != null) { if (m_navCells.Length != other.m_navCells.Length) { return false; } else { for (int navCellIndex = 0; navCellIndex < m_navCells.Length; navCellIndex++) { if (!m_navCells[navCellIndex].Equals(other.m_navCells[navCellIndex])) { return false; } } } } if ((m_pvs == null && other.m_pvs != null) || (m_pvs != null && other.m_pvs == null)) { return false; } else if (m_pvs != null && other.m_pvs != null && !m_pvs.Equals(other.m_pvs)) { return false; } return true; }
// Helper Functions private void ResetRequest() { m_navMesh = null; m_roomKey = null; m_startPosition = new Point3d(); m_endPosition = new Point3d(); m_startNavRef = null; m_endNavRef = null; }
public static NavMesh FromCompressedNavMeshData(byte[] compressedNavCells, byte[] compressedPVS) { NavMesh navMesh = new NavMesh(); if (compressedNavCells != null && compressedNavCells.Length > 0) { navMesh.NavCellsFromCompressedRawByteArray(compressedNavCells); } if (compressedPVS != null && compressedPVS.Length > 0) { navMesh.m_pvs = PotentiallyVisibleSet.FromCompressedRawByteArray(navMesh.m_nonEmptyNavCellCount, compressedPVS); } return navMesh; }
// Non-Blocking Query Functions public bool NonBlockingPathRequest( NavMesh navMesh, RoomKey roomKey, Point3d startPosition, Point3d endPosition, OnPathComputerComplete onComplete) { bool success = false; if (m_state == eState.invalid || m_state == eState.complete) { ResetRequest(); ResetResult(); m_navMesh = navMesh; m_roomKey = roomKey; m_startPosition = startPosition; m_endPosition = endPosition; m_state = eState.compute_end_points; m_maxNodesSearchedPerUpdate = NON_BLOCKING_MAX_NODES_SEARCHED_PER_UPDATE; m_completeCallback = onComplete; success = true; } return success; }
public RoomTemplate(string templateName, XmlDocument xmlDoc, byte[] compressedNavCells, byte[] compressedPVS) { m_templateName = templateName; m_treasures = new List<TreasureTemplate>(); m_traps = new List<TrapTemplate>(); m_mobSpawners = new List<MobSpawnerTemplate>(); m_portals = new List<PortalTemplate>(); m_energyTanks = new List<EnergyTankTemplate>(); m_portalRoomSideBitmask = new TypedFlags<MathConstants.eSignedDirection>(); m_navMesh = NavMesh.FromCompressedNavMeshData(compressedNavCells, compressedPVS); ParseEntities(xmlDoc.SelectSingleNode("/level/Entities")); }
public StaticRoomData() { RoomObjects = new List<RoomObject>(); RoomTemplate = null; NavMesh = new AsyncRPGSharedLib.Navigation.NavMesh(); }
private uint GetNavCellIndex(uint row, uint colomn) { return(NavMesh.GetNavCellIndex(m_colomnCount, row, colomn)); }
private uint GetNavCellRow(uint navCellIndex) { return(NavMesh.GetNavCellRow(m_colomnCount, navCellIndex)); }
public bool Equals(NavMesh other) { if ((m_roomKey == null && other.m_roomKey != null) || (m_roomKey != null && other.m_roomKey == null) || (m_roomKey != null && other.m_roomKey != null && m_roomKey.Equals(other.m_roomKey))) { return(false); } if (!m_boundingBox.Equals(other.m_boundingBox)) { return(false); } if (m_rowCount != other.m_rowCount) { return(false); } if (m_colomnCount != other.m_colomnCount) { return(false); } if (m_nonEmptyNavCellCount != other.m_nonEmptyNavCellCount) { return(false); } if ((m_navCells == null && other.m_navCells != null) || (m_navCells != null && other.m_navCells == null)) { return(false); } else if (m_navCells != null && other.m_navCells != null) { if (m_navCells.Length != other.m_navCells.Length) { return(false); } else { for (int navCellIndex = 0; navCellIndex < m_navCells.Length; navCellIndex++) { if (!m_navCells[navCellIndex].Equals(other.m_navCells[navCellIndex])) { return(false); } } } } if ((m_pvs == null && other.m_pvs != null) || (m_pvs != null && other.m_pvs == null)) { return(false); } else if (m_pvs != null && other.m_pvs != null && !m_pvs.Equals(other.m_pvs)) { return(false); } return(true); }
// Blocking Query Functions public bool BlockingPathRequest( NavMesh navMesh, RoomKey roomKey, Point3d startPosition, Point3d endPosition) { ResetRequest(); ResetResult(); m_navMesh = navMesh; m_roomKey = roomKey; m_startPosition = startPosition; m_endPosition = endPosition; m_state = eState.compute_end_points; m_maxNodesSearchedPerUpdate = 0; // Allowed to search as many nodes as we want while (m_state != eState.complete) { ComputeState(); } return m_resultCode == eResult.success; }
public NavMesh(RoomKey roomKey, NavMesh navMeshTemplate) { m_roomKey = new RoomKey(roomKey); m_boundingBox = new AABB3d(navMeshTemplate.m_boundingBox); m_rowCount = navMeshTemplate.m_rowCount; m_colomnCount = navMeshTemplate.m_colomnCount; m_nonEmptyNavCellCount = navMeshTemplate.m_nonEmptyNavCellCount; m_navCells = new NavCell[navMeshTemplate.m_navCells.Length]; Array.Copy(navMeshTemplate.m_navCells, m_navCells, m_navCells.Length); m_pvs = new PotentiallyVisibleSet(navMeshTemplate.m_pvs); }