private void OnPathComputed(PathComputer pathResult) { // If the path find succeeded, the entity will set the new destination and start walking toward it if (pathResult.ResultCode == PathComputer.eResult.success) { // Tell the server where we would like to go AsyncJSONRequest serverRequest = AsyncJSONRequest.Create(m_requestOwnerObject); Dictionary <string, object> requestPayload = new Dictionary <string, object>(); requestPayload["character_id"] = m_entity.MyCharacterData.character_id; requestPayload["x"] = OriginPortalEntryPoint.x; requestPayload["y"] = OriginPortalEntryPoint.y; requestPayload["z"] = OriginPortalEntryPoint.z; requestPayload["angle"] = pathResult.DestinationFacingAngle; requestPayload["portal_id"] = OriginPortal.portal_id; Status = eRequestStatus.pending_server_response; serverRequest.POST( ServerConstants.characterPortalRequestURL, requestPayload, this.OnServerRequestComplete); } else { Status = eRequestStatus.completed; ResultCode = eResult.failed_path; ResultDetails = "Path Failure Code: " + pathResult.ResultCode.ToString(); // Notify the caller that the request is completed m_onCompleteCallback(this); } }
public bool MoveMob( Point3d targetPosition) { bool success = false; if (path == null) { PathComputer pathComputer = new PathComputer(); success = pathComputer.BlockingPathRequest( moveRequest.Room.runtime_nav_mesh, moveRequest.Room.room_key, new Point3d(mob.Position), new Point3d(targetPosition)); if (success) { RoomKey roomKey = moveRequest.Room.room_key; PathStep lastPathStep = pathComputer.FinalPath[pathComputer.FinalPath.Count - 1]; PathStep secondLastPathStep = pathComputer.FinalPath[pathComputer.FinalPath.Count - 2]; Vector3d lastPathHeading = lastPathStep.StepPoint - secondLastPathStep.StepPoint; float targetAngle = MathConstants.GetAngleForVector(lastPathHeading); path = new EntityPath() { entity_id = mob.ID, path = pathComputer.FinalPath }; // Post an event that we moved output_game_events.Add( new GameEvent_MobMoved() { mob_id = mob.ID, room_x = roomKey.x, room_y = roomKey.y, room_z = roomKey.z, from_x = mob.Position.x, from_y = mob.Position.y, from_z = mob.Position.z, from_angle = mob.Angle, to_x = targetPosition.x, to_y = targetPosition.y, to_z = targetPosition.z, to_angle = targetAngle }); // Update the mob position and facing mob.Position = targetPosition; mob.Angle = targetAngle; // TODO: Update the mob energy based on the distance traveled } } return(success); }
// Events private void OnPathCompleted(PathComputer pathResult) { m_state = ePathFindingState.completed; if (m_pathCompleteCallback != null) { m_pathCompleteCallback(pathResult); m_pathCompleteCallback = null; } }
public GameWorldDebug(GameWorldController gameWorldController) { _gameWorldController = gameWorldController; _pathComputer = new PathComputer(); DebugRegistry.SetToggle("entity.pathfinding.render_debug_path", false); DebugRegistry.SetToggle("entity.pathfinding.render_nav_mesh", false); DebugRegistry.SetToggle("entity.pathfinding.render_visibility", false); DebugRegistry.SetToggle("ui.outline_hover_widget", false); DebugRegistry.SetToggle("ui.show_cursor_position", false); }
private bool ComputePlayerPaths( out string result_code) { PathComputer pathComputer = new PathComputer(); bool success = true; result_code = SuccessMessages.GENERAL_SUCCESS; foreach (GameEventParameters gameEvent in m_relevantGameEvents) { if (gameEvent.GetEventType() == eGameEventType.character_moved) { GameEvent_CharacterMoved movedEvent = (GameEvent_CharacterMoved)gameEvent; success = pathComputer.BlockingPathRequest( m_room.runtime_nav_mesh, m_room.room_key, new Point3d((float)movedEvent.from_x, (float)movedEvent.from_y, (float)movedEvent.from_z), new Point3d((float)movedEvent.to_x, (float)movedEvent.to_y, (float)movedEvent.to_z)); if (success) { m_playerPaths.Add( new EntityPath() { entity_id = movedEvent.character_id, path = pathComputer.FinalPath }); } else { result_code = ErrorMessages.CANT_COMPUTE_PATH; break; } } } return(success); }
public void FindPath(Vec2i start, Vec2i target, Stack <Vector2> path, Action callback) { if (start != target && InBounds(target)) { path.Clear(); Assert.IsTrue(InBounds(start)); Assert.IsTrue(grid[start.x, start.y].passable); if (!grid[target.x, target.y].passable) { return; } // This allows for multithreading this in the future if necessary - a different PathComputer // instance must be used per thread to avoid thread contention. PathComputer d = GetData(); d.SetInfo(start, target, path); d.FindPath(callback); } }
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); }
void Update() { Stopwatch stopWatch = new Stopwatch(); // Keep processing requests while there is work to do and there is time left to do it while (m_requestQueue.Count > 0 && stopWatch.ElapsedMilliseconds < MAX_WORK_MILLISECONDS) { PathComputer pathRequest = m_requestQueue[0]; // If the next job isn't complete do work on it in the time we have remaining if (pathRequest.State != PathComputer.eState.complete) { pathRequest.UpdateNonBlockingPathRequest(MAX_WORK_MILLISECONDS - (uint)stopWatch.ElapsedMilliseconds); } // If it is complete, remove it from the queue // The request will notify the requester when it's complete if (pathRequest.State == PathComputer.eState.complete) { m_requestQueue.RemoveAt(0); } } }