public ActionResult Index(string _signedRequest) { dynamic response = GetFacebookUserData(_signedRequest); if (response == null) return new RedirectResult("/"); Contact contact = new Contact(); contact.FirstName = response.first_name; contact.LastName = response.last_name; contact.DateOfBirth = DateTime.Parse(response.birthday); contact.Email = response.email; StateData stateData = new StateData(); stateData.FBSignedRequest = _signedRequest; stateData.FBUserId = response.id; ContactInfoViewModel model = new ContactInfoViewModel(); model.contact = contact; model.state = stateData; if (contactRepository.IsRegistered(response.id)) return RedirectToAction("RegisterComplete"); else return View(model); }
public NodeData( ExplorationNode node, Dictionary<ExplorationEdge, uint> edgeToId) { this.NodeId = node.Id; this.State = new StateData(node.State); this.PageRank = node.PageRank; this.InversePageRank = node.InversePageRank; this.MinCutIn = this.EncodeMinCuts(node.GetMinCutsIn()); this.MinCutOut = this.EncodeMinCuts(node.GetMinCutsOut()); IList<ExplorationEdge> incoming = node.IncomingExploration; this.Incoming = new uint[incoming.Count]; for (int i = 0; i < incoming.Count; i++) this.Incoming[i] = edgeToId[incoming[i]]; IList<ExplorationEdge> outgoing = node.OutgoingExploration; this.Outgoing = new uint[outgoing.Count]; for (int i = 0; i < outgoing.Count; i++) this.Outgoing[i] = edgeToId[outgoing[i]]; IList<ExplorationEdge[]> paths = node.GetPathsOut(); this.Paths = new uint[paths.Count][]; for (int i = 0; i < paths.Count; i++) { ExplorationEdge[] path = paths[i]; this.Paths[i] = new uint[path.Length]; for (int j = 0; j < path.Length; j++) this.Paths[i][j] = edgeToId[path[j]]; } }
public static void Main() { Console.WriteLine("Start new timer..."); // Remember start time var state = new StateData { InitialTickCount = Environment.TickCount }; // Short version FlexTimer.Factory.StartNew(() => Console.WriteLine(" --- ping!"), 1000); // Short typed version FlexTimer<double>.Factory.StartNew(d => Console.WriteLine(" --- double: " + d), 3.14, 1000); // Create a timer and pass 'state' object using (var timer = new FlexTimer<StateData>(SlowAction, state, 2000)) { // Prevent handler call if the previous call is still processed timer.EnableConcurrency = false; // MissedCallHandler will execute if a handler call has prevented due // a long time of processing previous one timer.SetMissedCallHandler(MissedCallHandler); timer.Start(TimeSpan.Zero); // Call a handler immediately Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
protected virtual void SequenceChangeState(string state) { if(mStateInstance != null) { mStateInstance.terminate = true; } mStateInstance = new StateData(); sequencer.Start(this, mStateInstance, state); }
protected virtual void Start() { if(sequencer != null) { //Sequencer.StateInstance mStateInstance = new StateData(); sequencer.Start(this, mStateInstance, mStartState); } }
protected InternalEntityEntry( [NotNull] IStateManager stateManager, [NotNull] IEntityType entityType, [NotNull] IEntityEntryMetadataServices metadataServices) { StateManager = stateManager; MetadataServices = metadataServices; EntityType = entityType; _stateData = new StateData(entityType.GetProperties().Count()); }
protected StateEntry( [NotNull] DbContextConfiguration configuration, [NotNull] IEntityType entityType) { Check.NotNull(configuration, "configuration"); Check.NotNull(entityType, "entityType"); _configuration = configuration; _entityType = entityType; _stateData = new StateData(entityType.Properties.Count); }
public static Dictionary<string, Sequencer> Load(StateData[] sequences) { fastJSON.JSON.Instance.UseSerializerExtension = true; Dictionary<string, Sequencer> ret = new Dictionary<string, Sequencer>(sequences.Length); foreach(StateData dat in sequences) { if(dat.source != null) { Sequencer newSequence = (Sequencer)fastJSON.JSON.Instance.ToObject(dat.source.text, typeof(Sequencer)); ret[dat.name] = newSequence; } } return ret; }
public NodeData() { this.NodeId = uint.MaxValue; this.Paths = null; this.State = null; this.MinCutOut = null; this.MinCutIn = null; this.Incoming = null; this.Outgoing = null; this.PageRank = -1; this.InversePageRank = -1; }
public static WorldData EncodeWorldData(ObjectManager manager, EventLibrary library) { string ids = ""; foreach (IHasState obj in manager.GetObjects()) ids += ((Component)obj).gameObject.name + ": " + obj.Id + "\n"; Debug.Log(ids); StateData initialState = new StateData( new WorldState( manager.GetObjects().Cast<IHasState>())); EventData[] events = library.GetSignatures().Convert(s => new EventData(s)).ToArray(); return new WorldData(initialState, events); }
public static Dictionary<string, Sequencer> Load(StateData[] sequences) { JSON.Instance.Parameters.UseExtensions = true; Dictionary<string, Sequencer> ret = new Dictionary<string, Sequencer>(sequences.Length); foreach(StateData dat in sequences) { if(dat.source != null) { //load file data SequencerFile sequenceFile = JSON.Instance.ToObject<SequencerFile>(dat.source.text); //construct sequencer ret[dat.name] = new Sequencer(sequenceFile); } } return ret; }
public void Save(Guid aggregateId, IAggregateState state) { StateData storedState; if (store.TryGetValue(aggregateId, out storedState)) { storedState.Data = JsonConvert.SerializeObject(state, _jsonSettings); storedState.StateType = state.GetType().FullName; } else { storedState = new StateData() { Data = JsonConvert.SerializeObject(state, _jsonSettings), StateType = state.GetType().FullName }; store.Add(aggregateId, storedState); } }
void StickToGroundIfNecessary(ref StateData currentState, StateData lastState, List <ContactPoint> wallPoints, out bool overwroteStateData) { overwroteStateData = false; if (currentState.onGround) { return; } if (currentState.onLadder) { return; } if (currentState.inWater) { return; } if (lastState.jumped) { return; } if (!lastState.onGround) { return; } if (!lastState.onSolidGround) { return; } if (!currentState.velocityComesFromMove) { return; } if (wallPoints.Count > 0) { return; } // if(currentState.incomingOwnVelocity.magnitude > moveSpeedRegular) return; //TODO this one's new, might not be necessary Vector3 start = player.Bottom + (rb.transform.up * col.radius); // Vector3 dir = -lastState.surfacePoint.normal; //this works more often // Vector3 dir = lastState.surfacePoint.normal + rb.transform.up).normalized * -1f; //this is smoother... less jerky... Vector3 dir = (2f * lastState.surfacePoint.normal + rb.transform.up).normalized * -1f; //best of both worlds float dist = col.radius + (2.5f * moveSpeedRegular * Time.fixedDeltaTime); RaycastHit hit; Debug.DrawRay(start, dir.normalized * dist, Color.magenta, 10f); if (Physics.Raycast(start, dir, out hit, dist, collisionLayerMaskForRaycasting)) { bool hitAngleOkay = (Vector3.Angle(hit.normal, rb.transform.up) <= moveSlopeAngleLimit); bool angleBetweenVelocityAndHitOkay = (Vector3.Angle(currentState.incomingOwnVelocity, hit.normal) < 90f); bool colliderSolid = ColliderIsSolid(hit.collider); if (hitAngleOkay && angleBetweenVelocityAndHitOkay && colliderSolid) { // Vector3 properPosition = hit.point + (hit.normal * (col.radius + 0.05f)) - (rb.transform.up * col.radius); //(old) why the 0.05f? it works fine without... it seems... Vector3 properPosition = hit.point + (hit.normal * col.radius) - (rb.transform.up * col.radius); Vector3 projectedVelocity = Vector3.ProjectOnPlane(currentState.incomingVelocity, hit.normal).normalized *currentState.incomingVelocity.magnitude; Vector3 additionalGravity = -hit.normal * Physics.gravity.magnitude * Time.fixedDeltaTime; // rb.MovePosition(properPosition); player.Bottom = properPosition; rb.velocity = projectedVelocity + additionalGravity; //debug Debug.DrawLine(player.Bottom, properPosition, Color.yellow, 10f); Debug.LogWarning("HIT! STICKING!"); //overwrite state data with new info SurfacePoint newSurfacePoint = new SurfacePoint(hit.point, hit.normal, hit.collider, rb.transform.up); currentState = GetStateData(newSurfacePoint, currentState.moveInput, new List <ContactPoint>(), lastState); overwroteStateData = true; } else { Debug.DrawRay(hit.point, Vector3.up, Color.red, 10f); Debug.LogWarning("HIT! No stick tho! angle:" + hitAngleOkay + " angleBetweenVAndHit:" + angleBetweenVelocityAndHitOkay + " solid:" + colliderSolid); } } else { Debug.DrawRay(player.Bottom, Vector3.up, Color.red, 10f); Debug.LogWarning("No hit, no stick..."); } }
public void ExecuteFixedUpdate(MoveInput moveInput) { StateData currentState; List <ContactPoint> wallPoints; ManageCollisions(contactPoints, moveInput, out currentState, out wallPoints); ManageHeight(currentState); MovementType movementType = GetMovementType(currentState); Vector3 acceleration, gravity; float friction; switch (movementType) { case MovementType.GROUNDED: GroundedMovement(ref currentState, lastState, out acceleration, out gravity, out friction); break; case MovementType.AIRBORNE: AirborneMovement(ref currentState, out acceleration, out gravity, out friction); break; case MovementType.SWIMMING: WaterMovement(ref currentState, out acceleration, out gravity, out friction); break; case MovementType.LADDER: LadderMovement(ref currentState, out acceleration, out gravity, out friction); break; default: throw new UnityException("Unsupported MovementType \"" + movementType.ToString() + "\""); } if (Input.GetKey(KeyCode.R)) { currentState.velocityComesFromMove = true; } ProjectOnAllSolidAndNearSolidObjects(ref acceleration, wallPoints); rb.velocity += (acceleration + gravity) * Time.fixedDeltaTime; currentState.outgoingVelocity = rb.velocity; currentState.outgoingOwnVelocity = GetRelativeVelocity(rb.velocity, currentState.surfacePoint); //TODO refactor to take currentState instead of just surfacePoint col.material.staticFriction = friction; col.material.dynamicFriction = friction; //do it after saving the state to not factor into own velocity and stuff if (movementType == MovementType.GROUNDED && currentState.onValidGround) { float slopeLerpFactor = GetSlopeLerpFactor(currentState); //reminder : 0 = walkable, 1 = not walkable float inputLerpFactor = currentState.moveInput.directionalInput.magnitude; //if input, then no sliding float resultLerpFactor = slopeLerpFactor * (1f - inputLerpFactor); resultLerpFactor = Mathf.Pow(resultLerpFactor, 0.333f); Vector3 slopeAccel = Vector3.ProjectOnPlane(Physics.gravity, currentState.surfacePoint.normal) * resultLerpFactor; rb.velocity += slopeAccel * Time.fixedDeltaTime; } debugInfo = "vFromMove? : " + currentState.velocityComesFromMove.ToString() + "\n"; debugInfo += movementType.ToString() + "\n"; if (currentState.onGround) { debugInfo += currentState.surfacePoint.angle + "°\n"; debugInfo += "valid? : " + currentState.onValidGround; } Quaternion gravityRotation = GetGravityRotation(Physics.gravity, rb.transform.up, rb.transform.forward); Quaternion newRotation = Quaternion.RotateTowards(rb.transform.rotation, gravityRotation, gravityTurnDegreesPerSecond * Time.fixedDeltaTime); rb.MoveRotation(newRotation); //save and/or reset fields lastState = currentState; contactPoints.Clear(); canSwim = false; //needs to be reset as it is done in triggerstay }
/// <summary> /// Serialises all body properties. The output will be a dictionary containing the /// body of the request in a form that can easily be converted to Json. Will return /// an empty dictionary if there is no body. /// </summary> /// /// <returns>The body Json in dictionary form.</returns> public IDictionary <string, object> SerialiseBody() { var dictionary = new Dictionary <string, object>(); // Match Type Key dictionary.Add("MatchTypeKey", MatchTypeKey); // Turn Type dictionary.Add("TurnType", TurnType); // Player Limit dictionary.Add("PlayerLimit", PlayerLimit); // Properties if (Properties != null) { var serialisedProperties = JsonSerialisation.Serialise(Properties, (MultiTypeValue element) => { return(element.Serialise()); }); dictionary.Add("Properties", serialisedProperties); } // State Data if (StateData != null) { dictionary.Add("StateData", StateData.Serialise()); } // Turn Timeout if (TurnTimeout != null) { dictionary.Add("TurnTimeout", TurnTimeout); } // Waiting Timeout if (WaitingTimeout != null) { dictionary.Add("WaitingTimeout", WaitingTimeout); } // Turn Order Type if (TurnOrderType != null) { dictionary.Add("TurnOrderType", TurnOrderType); } // Players if (Players != null) { var serialisedPlayers = JsonSerialisation.Serialise(Players, (string element) => { return(element); }); dictionary.Add("Players", serialisedPlayers); } // Auto Start if (AutoStart != null) { dictionary.Add("AutoStart", AutoStart); } // Private if (Private != null) { dictionary.Add("Private", Private); } return(dictionary); }
protected abstract bool CheckAttributes(StateData data);
public WorldData() { this.InitialState = null; this.Events = null; }
protected virtual void OnDestroy() { mStateInstance = null; }
public bool DriveDistanceSM_StopState(StateBehaviorEnum behavior, StateData submachineState, Signal signal, EntryTypeEnum enumEntryType, EntryEnum[] entryArray, int nArrayCount) { if (m_StateMachineImpl == null) return false; StateData state = m_StateMachineImpl.GetStateObject(submachineState, (int)StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_STOPSTATE); switch (behavior) { case StateBehaviorEnum.ENTRY: if(state.active_count > 0) return false; m_drivedistancesm = StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_STOPSTATE; state.IncrementActiveCount(); DriveDistanceSM_StopState_behavior(StateBehaviorEnum.ENTRY); if(enumEntryType == EntryTypeEnum.HistoryEntry) { return true; } DriveDistanceSM_StopState_behavior(StateBehaviorEnum.DO); if((enumEntryType == EntryTypeEnum.EntryPointEntry || enumEntryType == EntryTypeEnum.DefaultEntry) && state.IsActiveState()) m_StateMachineImpl.deferInternalEvent(EventEnum.COMPLETION, null, state); break; case StateBehaviorEnum.EXIT: if(state.active_count == 0) return false; m_drivedistancesm = StateEnum.NOSTATE; state.DecrementActiveCount(); DriveDistanceSM_StopState_behavior(StateBehaviorEnum.EXIT); m_StateMachineImpl.removeInternalEvent(state); break; } return true; }
void GenerateArgumentPermutations(StateData stateData, NativeList <ActionKey> argumentPermutations) { var CharacterFilter = new NativeArray <ComponentType>(1, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Character>(), }; var ToFilter = new NativeArray <ComponentType>(3, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Waypoint>(), [1] = ComponentType.Exclude <Generated.AI.Planner.StateRepresentation.ActivationLock>(), [2] = ComponentType.Exclude <Generated.AI.Planner.StateRepresentation.KeyLock>(), }; var FromFilter = new NativeArray <ComponentType>(2, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Waypoint>(), [1] = ComponentType.Exclude <Generated.AI.Planner.StateRepresentation.ActivationLock>(), }; var CharacterObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(CharacterObjectIndices, CharacterFilter); var ToObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(ToObjectIndices, ToFilter); var FromObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(FromObjectIndices, FromFilter); var WaypointBuffer = stateData.WaypointBuffer; var CharacterBuffer = stateData.CharacterBuffer; for (int i0 = 0; i0 < CharacterObjectIndices.Length; i0++) { var CharacterIndex = CharacterObjectIndices[i0]; var CharacterObject = stateData.TraitBasedObjects[CharacterIndex]; for (int i1 = 0; i1 < ToObjectIndices.Length; i1++) { var ToIndex = ToObjectIndices[i1]; var ToObject = stateData.TraitBasedObjects[ToIndex]; if (!(WaypointBuffer[ToObject.WaypointIndex].Occupied == false)) { continue; } if (!(WaypointBuffer[ToObject.WaypointIndex].Up == CharacterBuffer[CharacterObject.CharacterIndex].Waypoint)) { continue; } for (int i2 = 0; i2 < FromObjectIndices.Length; i2++) { var FromIndex = FromObjectIndices[i2]; var FromObject = stateData.TraitBasedObjects[FromIndex]; if (!(CharacterBuffer[CharacterObject.CharacterIndex].Waypoint == stateData.GetTraitBasedObjectId(FromIndex))) { continue; } var actionKey = new ActionKey(k_MaxArguments) { ActionGuid = ActionGuid, [k_CharacterIndex] = CharacterIndex, [k_ToIndex] = ToIndex, [k_FromIndex] = FromIndex, }; argumentPermutations.Add(actionKey); } } } CharacterObjectIndices.Dispose(); ToObjectIndices.Dispose(); FromObjectIndices.Dispose(); CharacterFilter.Dispose(); ToFilter.Dispose(); FromFilter.Dispose(); }
float Reward(StateData originalState, ActionKey action, StateData newState) { var reward = -0.1f; return(reward); }
private static void SlowAction(StateData state) { state.Print("Begin slow action"); Thread.Sleep(3000); state.Print("End slow action"); }
public bool defer(Event _event, StateData toState, bool bCheckOnly) { bool bDefer = false; if(_event.eventEnum == EventEnum.COMPLETION) return bDefer; if(!bDefer) { if (toState.parent_state != null) { bDefer = defer(_event, toState.parent_state, true); if(bDefer && !bCheckOnly) { defer(_event, toState.parent_state, false); } } } else if(!bCheckOnly) { bool bExist = false; foreach (Event evt in m_StateMachineImpl.deferredEvents) { if (evt == _event) { bExist = true; break; } } if(!bExist) { m_StateMachineImpl.deferredEvents.Add(_event); } } return bDefer; }
public void Start(StateData stateData) { MoveManager.SetState(MoveState.MapMove); enemyManager.MapMove(MoveManager); mapManager.MapMove(stateData); }
public bool Contains(StateData state) { return(_states.Contains(state)); }
public WorldData(StateData initialState, EventData[] events) { this.InitialState = initialState; this.Events = events; }
/// <summary> /// </summary> /// <param name="stateData"></param> /// <param name="newState"></param> /// <param name="args"></param> public StateChangingEventArgs(StateData <TState> stateData, TState newState, params object[] args) { this.StateData = stateData; this.NewState = newState; this.Args = args; }
public float TerminalReward(StateData stateData) { var reward = 0f; return(reward); }
public static void SaveStateData(string key, StateData stateData) { RedisStringStore.Save(key, stateData); }
void BuildIfConditionNode(IfConditionNodeModel node, RoslynEcsTranslator translator, int stateIndex) { translator.BuildNode(node); var firstThenStack = RoslynTranslator.GetConnectedStack(node, 0); var firstElseStack = RoslynTranslator.GetConnectedStack(node, 1); var ifState = m_States[stateIndex]; var ifIndex = GetCurrentStateIndex(); var endStackIndex = 0; if (translator.EndStack != null) { m_StackIndexes.TryGetValue(translator.EndStack, out endStackIndex); } // Reserve then/else/complete states first var thenIndex = ifIndex; var thenBlock = Block().AddStatements(ReturnStatement(LiteralExpression(SyntaxKind.FalseLiteralExpression))); StateData thenState = null; if (firstThenStack != null) { if (firstThenStack == translator.EndStack && endStackIndex != 0) { thenBlock = Block().AddStatements(BuildGoToState(endStackIndex)); } else { thenIndex += 1; thenState = RequestNewState(); TryAddStackIndex(firstThenStack, thenIndex); thenBlock = Block().AddStatements(BuildGoToState(thenIndex)); } } var elseIndex = thenIndex + 1; var elseBlock = Block().AddStatements(ReturnStatement(LiteralExpression(SyntaxKind.FalseLiteralExpression))); StateData elseState = null; if (firstElseStack != null) { if (firstElseStack == translator.EndStack && endStackIndex != 0) { elseBlock = Block().AddStatements(BuildGoToState(endStackIndex)); } else { elseState = RequestNewState(); TryAddStackIndex(firstElseStack, elseIndex); elseBlock = Block().AddStatements(BuildGoToState(elseIndex)); } } // Then Build stacks ifState.Statements.Add(RoslynBuilder.IfStatement( translator.BuildPort(node.IfPort).SingleOrDefault(), thenBlock, elseBlock) .WithAdditionalAnnotations( new SyntaxAnnotation(Annotations.VSNodeMetadata, node.Guid.ToString()))); ifState.Statements.Add(ReturnStatement(LiteralExpression(SyntaxKind.TrueLiteralExpression))); ifState.SkipStateBuilding = true; var reserveEndStackState = translator.EndStack != null && translator.EndStack != firstElseStack && translator.EndStack != firstThenStack && endStackIndex == 0; if (reserveEndStackState) { var endState = RequestNewState(); endState.NextStateIndex = GetNextStateIndex(translator.EndStack); TryAddStackIndex(translator.EndStack, GetCurrentStateIndex()); } var origBuiltStacks = translator.BuiltStacks; translator.BuiltStacks = new HashSet <IStackModel>(origBuiltStacks); if (translator.EndStack != firstThenStack) { if (translator.EndStack != null && thenState != null) { thenState.NextStateIndex = m_StackIndexes[translator.EndStack]; } BuildStack(translator, firstThenStack, thenIndex, StackExitStrategy.Inherit); } var partialStacks = translator.BuiltStacks; translator.BuiltStacks = new HashSet <IStackModel>(origBuiltStacks); if (translator.EndStack != firstElseStack) { if (translator.EndStack != null && elseState != null) { elseState.NextStateIndex = m_StackIndexes[translator.EndStack]; } BuildStack(translator, firstElseStack, elseIndex, StackExitStrategy.Inherit); } translator.BuiltStacks.UnionWith(partialStacks); }
public SwordAttack(StateData stateData) : base(stateData) { }
private void ForwardState__TO__StopState_6(Signal signal, StateData submachineState) { if (m_StateMachineImpl == null) return; if(!m_StateMachineImpl.GetStateObject(submachineState, (int)StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE).IsActiveState()) { return; } StateProc(StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE, submachineState, StateBehaviorEnum.EXIT, null); ForwardState__TO__StopState_6_effect(signal); m_StateMachineImpl.currentTransition.SetActive(m_StateMachineImpl); StateProc(StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_STOPSTATE, submachineState, StateBehaviorEnum.ENTRY, signal, EntryTypeEnum.DefaultEntry); }
void GenerateArgumentPermutations(StateData stateData, NativeList <ActionKey> argumentPermutations) { var GameFilter = new NativeArray <ComponentType>(1, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Game>(), }; var SourceFilter = new NativeArray <ComponentType>(3, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Coordinate>(), [1] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Cell>(), [2] = ComponentType.Exclude <Generated.AI.Planner.StateRepresentation.Blocker>(), }; var TargetFilter = new NativeArray <ComponentType>(3, Allocator.Temp) { [0] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Coordinate>(), [1] = ComponentType.ReadWrite <Generated.AI.Planner.StateRepresentation.Cell>(), [2] = ComponentType.Exclude <Generated.AI.Planner.StateRepresentation.Blocker>(), }; var GameObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(GameObjectIndices, GameFilter); var SourceObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(SourceObjectIndices, SourceFilter); var TargetObjectIndices = new NativeList <int>(2, Allocator.Temp); stateData.GetTraitBasedObjectIndices(TargetObjectIndices, TargetFilter); var CellBuffer = stateData.CellBuffer; for (int i0 = 0; i0 < GameObjectIndices.Length; i0++) { var GameIndex = GameObjectIndices[i0]; var GameObject = stateData.TraitBasedObjects[GameIndex]; for (int i1 = 0; i1 < SourceObjectIndices.Length; i1++) { var SourceIndex = SourceObjectIndices[i1]; var SourceObject = stateData.TraitBasedObjects[SourceIndex]; if (!(CellBuffer[SourceObject.CellIndex].Type != CellType.None)) { continue; } for (int i2 = 0; i2 < TargetObjectIndices.Length; i2++) { var TargetIndex = TargetObjectIndices[i2]; var TargetObject = stateData.TraitBasedObjects[TargetIndex]; if (!(CellBuffer[SourceObject.CellIndex].Right == stateData.GetTraitBasedObjectId(TargetIndex))) { continue; } if (!(CellBuffer[TargetObject.CellIndex].Type != CellType.None)) { continue; } var actionKey = new ActionKey(k_MaxArguments) { ActionGuid = ActionGuid, [k_GameIndex] = GameIndex, [k_SourceIndex] = SourceIndex, [k_TargetIndex] = TargetIndex, }; argumentPermutations.Add(actionKey); } } } GameObjectIndices.Dispose(); SourceObjectIndices.Dispose(); TargetObjectIndices.Dispose(); GameFilter.Dispose(); SourceFilter.Dispose(); TargetFilter.Dispose(); }
public override void Execute() { WriteLiteral("\r\n"); #line 11 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Layout = new LayoutPage(Strings.AwaitingJobsPage_Title); int from, perPage; int.TryParse(Query("from"), out from); int.TryParse(Query("count"), out perPage); List <string> jobIds = null; Pager pager = null; using (var connection = Storage.GetConnection()) { var storageConnection = connection as JobStorageConnection; if (storageConnection != null) { pager = new Pager(from, perPage, storageConnection.GetSetCount("awaiting")); jobIds = storageConnection.GetRangeFromSet("awaiting", pager.FromRecord, pager.FromRecord + pager.RecordsPerPage - 1); } } #line default #line hidden WriteLiteral("\r\n<div class=\"row\">\r\n <div class=\"col-md-3\">\r\n "); #line 36 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.JobsSidebar()); #line default #line hidden WriteLiteral("\r\n </div>\r\n <div class=\"col-md-9\">\r\n <h1 class=\"page-header\">"); #line 39 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_Title); #line default #line hidden WriteLiteral("</h1>\r\n\r\n"); #line 41 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (jobIds == null) { #line default #line hidden WriteLiteral(" <div class=\"alert alert-warning\">\r\n <h4>"); #line 44 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_ContinuationsWarning_Title); #line default #line hidden WriteLiteral("</h4>\r\n <p>"); #line 45 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_ContinuationsWarning_Text); #line default #line hidden WriteLiteral("</p>\r\n </div>\r\n"); #line 47 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } else if (jobIds.Count > 0) { #line default #line hidden WriteLiteral(" <div class=\"js-jobs-list\">\r\n <div class=\"btn-toolbar b" + "tn-toolbar-top\">\r\n"); #line 52 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (!IsReadOnly) { #line default #line hidden WriteLiteral(" <button class=\"js-jobs-list-command btn btn-sm btn-primar" + "y\"\r\n data-url=\""); #line 55 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Url.To("/jobs/awaiting/enqueue")); #line default #line hidden WriteLiteral("\"\r\n data-loading-text=\""); #line 56 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_Enqueueing); #line default #line hidden WriteLiteral("\">\r\n <span class=\"glyphicon glyphicon-repeat\"></span>\r" + "\n "); #line 58 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_EnqueueButton_Text); #line default #line hidden WriteLiteral("\r\n </button>\r\n"); #line 60 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden #line 61 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (!IsReadOnly) { #line default #line hidden WriteLiteral(" <button class=\"js-jobs-list-command btn btn-sm btn-defaul" + "t\"\r\n data-url=\""); #line 64 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Url.To("/jobs/awaiting/delete")); #line default #line hidden WriteLiteral("\"\r\n data-loading-text=\""); #line 65 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_Deleting); #line default #line hidden WriteLiteral("\"\r\n data-confirm=\""); #line 66 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_DeleteConfirm); #line default #line hidden WriteLiteral("\">\r\n <span class=\"glyphicon glyphicon-remove\"></span>\r" + "\n "); #line 68 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_DeleteSelected); #line default #line hidden WriteLiteral("\r\n </button>\r\n"); #line 70 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" "); #line 71 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.PerPageSelector(pager)); #line default #line hidden WriteLiteral("\r\n </div>\r\n\r\n <div class=\"table-responsive\">\r\n " + " <table class=\"table table-hover\">\r\n <thead" + ">\r\n <tr>\r\n"); #line 78 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (!IsReadOnly) { #line default #line hidden WriteLiteral(" <th class=\"min-width\">\r\n " + " <input type=\"checkbox\" class=\"js-jobs-list-select-all\"/>\r\n " + " </th>\r\n"); #line 83 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" <th class=\"min-width\">"); #line 84 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_Id); #line default #line hidden WriteLiteral("</th>\r\n <th>"); #line 85 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_Job); #line default #line hidden WriteLiteral("</th>\r\n <th class=\"min-width\">"); #line 86 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_Table_Options); #line default #line hidden WriteLiteral("</th>\r\n <th class=\"min-width\">"); #line 87 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_Table_Parent); #line default #line hidden WriteLiteral("</th>\r\n <th class=\"align-right\">"); #line 88 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_Created); #line default #line hidden WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n " + " <tbody>\r\n"); #line 92 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" foreach (var jobId in jobIds) { JobData jobData; StateData stateData; StateData parentStateData = null; using (var connection = Storage.GetConnection()) { jobData = connection.GetJobData(jobId); stateData = connection.GetStateData(jobId); if (stateData != null && stateData.Name == AwaitingState.StateName) { parentStateData = connection.GetStateData(stateData.Data["ParentId"]); } } #line default #line hidden WriteLiteral(" <tr class=\"js-jobs-list-row "); #line 109 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(jobData != null ? "hover" : null); #line default #line hidden WriteLiteral("\">\r\n"); #line 110 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (!IsReadOnly) { #line default #line hidden WriteLiteral(" <td>\r\n " + " <input type=\"checkbox\" class=\"js-jobs-list-checkbox\" name=\"jobs[]\" valu" + "e=\""); #line 113 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(jobId); #line default #line hidden WriteLiteral("\"/>\r\n </td>\r\n"); #line 115 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" <td class=\"min-width\">\r\n " + " "); #line 117 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.JobIdLink(jobId)); #line default #line hidden WriteLiteral("\r\n </td>\r\n"); #line 119 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (jobData == null) { #line default #line hidden WriteLiteral(" <td colspan=\"2\"><em>"); #line 121 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_JobExpired); #line default #line hidden WriteLiteral("</em></td>\r\n"); #line 122 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } else { #line default #line hidden WriteLiteral(" <td class=\"word-break\">\r\n " + " "); #line 126 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.JobNameLink(jobId, jobData.Job)); #line default #line hidden WriteLiteral("\r\n </td>\r\n"); WriteLiteral(" <td class=\"min-width\">\r\n"); #line 129 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (stateData != null && stateData.Data.ContainsKey("Options") && !String.IsNullOrWhiteSpace(stateData.Data["Options"])) { var optionsDescription = stateData.Data["Options"]; if (Enum.TryParse(optionsDescription, out JobContinuationOptions options)) { optionsDescription = options.ToString("G"); } #line default #line hidden WriteLiteral(" <code>"); #line 136 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(optionsDescription); #line default #line hidden WriteLiteral("</code>\r\n"); #line 137 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } else { #line default #line hidden WriteLiteral(" <em>"); #line 140 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_NotAvailable); #line default #line hidden WriteLiteral("</em>\r\n"); #line 141 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" </td>\r\n"); WriteLiteral(" <td class=\"min-width\">\r\n"); #line 144 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" if (parentStateData != null) { #line default #line hidden WriteLiteral(" <a href=\""); #line 146 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Url.JobDetails(stateData.Data["ParentId"])); #line default #line hidden WriteLiteral("\" class=\"text-decoration-none\">\r\n " + " "); #line 147 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.StateLabel(parentStateData.Name, parentStateData.Name, hover: true)); #line default #line hidden WriteLiteral("\r\n </a>\r\n"); #line 149 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } else { #line default #line hidden WriteLiteral(" <em>"); #line 152 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.Common_NotAvailable); #line default #line hidden WriteLiteral("</em>\r\n"); #line 153 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" </td>\r\n"); WriteLiteral(" <td class=\"min-width align-right\">\r\n " + " "); #line 156 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.RelativeTime(jobData.CreatedAt)); #line default #line hidden WriteLiteral("\r\n </td>\r\n"); #line 158 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" </tr>\r\n"); #line 160 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" </tbody>\r\n </table>\r\n <" + "/div>\r\n "); #line 164 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Html.Paginator(pager)); #line default #line hidden WriteLiteral("\r\n </div>\r\n"); #line 166 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } else { #line default #line hidden WriteLiteral(" <div class=\"alert alert-info\">\r\n "); #line 170 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" Write(Strings.AwaitingJobsPage_NoJobs); #line default #line hidden WriteLiteral("\r\n </div>\r\n"); #line 172 "..\..\Dashboard\Pages\AwaitingJobsPage.cshtml" } #line default #line hidden WriteLiteral(" </div>\r\n</div>\r\n"); }
protected override void OnUpdate() { StateData stateData = GetSingleton <StateData>(); if (stateData.state == StateData.State.WaitingToPlay) { if (!selfDestructCompleted) { // Destroy all projectiles EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob); Entities.WithAll <ProjectileTag>().ForEach((ref Entity entity) => { EntityManager.DestroyEntity(entity); }).WithStructuralChanges().Run(); ecb.Playback(EntityManager); ecb.Dispose(); selfDestructCompleted = true; } } if (stateData.state == StateData.State.Playing) { EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob); Entities.WithAll <ProjectileTag>().ForEach((ref Entity entity, ref MovementData data, ref Translation translation) => { if ((Math.Abs(data.direction.x - translation.Value.x)) <= 0.5) { // TODO : Move player destruction logic to another system. Entity player = GetSingletonEntity <PlayerTag>(); Translation playerPosition = EntityManager.GetComponentData <Translation>(player); float playerHeight = EntityManager.GetComponentData <PlayerHeight>(player).Value; float projectileY = translation.Value.y; float playerYBound, distanceToPlayer; if (projectileY > playerPosition.Value.y) { playerYBound = playerPosition.Value.y + (playerHeight / 2); distanceToPlayer = projectileY - playerYBound; } else { playerYBound = playerPosition.Value.y - (playerHeight / 2); distanceToPlayer = playerYBound - projectileY; } if (distanceToPlayer <= 0.5) { selfDestructCompleted = false; stateData.state = StateData.State.Dead; SetSingleton(stateData); //ecb.DestroyEntity(player); - Don't destroy player entity. } else { ecb.DestroyEntity(entity); } } }).WithoutBurst().Run(); ecb.Playback(EntityManager); ecb.Dispose(); } }
public CameraMessageClient(ref StateData dataIn, ref NewCameraTargetData posDataIn) { clientID = ClientID.CAMERA_CLIENT; c_stateData = dataIn; c_posData = posDataIn; }
/// <summary> /// Stores built automaton in pre-allocated <see cref="Automaton{TSequence,TElement,TElementDistribution,TSequenceManipulator,TThis}"/> object. /// </summary> public DataContainer GetData(bool?isDeterminized = null) { if (this.StartStateIndex < 0 || this.StartStateIndex >= this.states.Count) { throw new InvalidOperationException( $"Built automaton must have a valid start state. " + $"StartStateIndex = {this.StartStateIndex}, states.Count = {this.states.Count}"); } var hasEpsilonTransitions = false; var usesGroups = false; var hasSelfLoops = false; var hasOnlyForwardTransitions = true; var resultStates = ImmutableArray.CreateBuilder <StateData>(this.states.Count); var resultTransitions = ImmutableArray.CreateBuilder <Transition>(this.transitions.Count - this.numRemovedTransitions); var nextResultTransitionIndex = 0; for (var i = 0; i < resultStates.Count; ++i) { var firstResultTransitionIndex = nextResultTransitionIndex; var transitionIndex = this.states[i].FirstTransitionIndex; while (transitionIndex != -1) { var node = this.transitions[transitionIndex]; var transition = node.Transition; Debug.Assert( transition.DestinationStateIndex < resultStates.Count, "Destination indexes must be in valid range"); resultTransitions[nextResultTransitionIndex] = transition; ++nextResultTransitionIndex; hasEpsilonTransitions = hasEpsilonTransitions || transition.IsEpsilon; usesGroups = usesGroups || (transition.Group != 0); if (transition.DestinationStateIndex == i) { hasSelfLoops = true; } else if (transition.DestinationStateIndex < i) { hasOnlyForwardTransitions = false; } transitionIndex = node.Next; } resultStates[i] = new StateData( firstResultTransitionIndex, nextResultTransitionIndex - firstResultTransitionIndex, this.states[i].EndWeight); } Debug.Assert( nextResultTransitionIndex == resultTransitions.Count, "number of copied transitions must match result array size"); // Detect two very common automata shapes var isEnumerable = hasSelfLoops ? false : hasOnlyForwardTransitions ? true : (bool?)null; return(new DataContainer( this.StartStateIndex, resultStates.MoveToImmutable(), resultTransitions.MoveToImmutable(), !hasEpsilonTransitions, usesGroups, isDeterminized, isZero: null, isEnumerable: isEnumerable)); }
/// <summary> /// 0 = walkable, 1 = not walkable /// </summary> float GetSlopeLerpFactor(StateData currentState) { return(Mathf.Clamp01((currentState.surfacePoint.angle - moveSlopeSlideStartAngle) / (moveSlopeAngleLimit - moveSlopeSlideStartAngle))); }
abstract public void Enter(StateData data);
StateData GetStateData(SurfacePoint surfacePoint, MoveInput moveInput, List <ContactPoint> wallPoints, StateData lastState) { StateData currentState = new StateData(); currentState.surfacePoint = surfacePoint; currentState.incomingVelocity = rb.velocity; currentState.incomingOwnVelocity = GetRelativeVelocity(rb.velocity, surfacePoint); float currentOwnSpeed = currentState.incomingOwnVelocity.magnitude; float lastOwnSpeed = lastState.outgoingOwnVelocity.magnitude; currentState.velocityComesFromMove = (lastState.velocityComesFromMove && (currentOwnSpeed <= lastOwnSpeed)); currentState.moveInput = moveInput; currentState.onGround = GetIsGrounded(surfacePoint, lastState); if (currentState.onGround) { currentState.onValidGround = GetIsOnValidGround(surfacePoint); currentState.onSolidGround = GetIsOnSolidGround(surfacePoint); } currentState.onLadder = GetIsOnLadder(wallPoints, out currentState.ladderPoint); currentState.inWater = canSwim; return(currentState); }
private void runStateMachine(StateMachineEnum statemachine, StateData submachineState, Signal signal, EntryEnum[] entryArray, int nEntryCount) { if (m_StateMachineImpl == null) return; if(submachineState == null) { StateInitialData initialData = new StateInitialData((int)StateEnum.DriveDistance_VIRTUAL_SUBMACHINESTATE, (int)StateEnum.NOSTATE, 1, false, "DriveDistance_VIRTUAL_SUBMACHINESTATE", ""); submachineState = new StateData(m_StateMachineImpl, initialData); submachineState.IncrementActiveCount(); m_StateMachineImpl.GetStateData().Add(submachineState); } switch (statemachine) { case StateMachineEnum.DriveDistance_ENUM_DRIVEDISTANCESM: { const int nArrayCount = 2; StateInitialData[] initialDataArray = new StateInitialData[nArrayCount] { new StateInitialData((int)StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE, (int)StateEnum.NOSTATE, 0, false, "DriveDistance_DriveDistanceSM_ForwardState", "{7C4E3CFB-F8EA-4d72-83D7-1257A76F1FFF}"), new StateInitialData((int)StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_STOPSTATE, (int)StateEnum.NOSTATE, 0, false, "DriveDistance_DriveDistanceSM_StopState", "{EB0BB228-E76D-4701-B2F9-04C5EC06EC50}") }; m_StateMachineImpl.CreateStateObjects(initialDataArray, nArrayCount, submachineState); } for(int i = 0; i < nEntryCount; i++) { switch(entryArray[i]) { case EntryEnum.DriveDistance_ENUM_DRIVEDISTANCESM_INITIAL_10: TransitionProc(TransitionEnum.DriveDistance_ENUM_INITIAL_10__TO__FORWARDSTATE_5, signal, submachineState); break; } } if(submachineState.IsActiveState()) m_StateMachineImpl.deferInternalEvent(EventEnum.COMPLETION, null, submachineState); break; } }
//actual movement void GroundedMovement(ref StateData currentState, StateData lastState, out Vector3 outputAcceleration, out Vector3 outputGravity, out float outputFriction) { SurfacePoint surfacePoint = currentState.surfacePoint; Vector3 currentVelocity = currentState.incomingOwnVelocity; Vector3 inputVector = rb.transform.TransformDirection(currentState.moveInput.directionalInput); float currentSpeed = currentVelocity.magnitude; float desiredSpeed = GetDesiredSpeed(currentState); float frictionLerpFactor = GetSurfaceFrictionLerpFactor(currentState); float frictionAppropriateAccel = Mathf.Lerp(moveAccelerationMin, moveAccelerationMax, (frictionLerpFactor * frictionLerpFactor)); if (currentState.onValidGround) { Vector3 projectedInput = GetSurfaceMoveVector(inputVector, surfacePoint.normal); Vector3 desiredVector = projectedInput * desiredSpeed; Vector3 tempAccel = projectedInput * frictionAppropriateAccel; float maxAccel = tempAccel.magnitude; if (!lastState.onGround) //TODO why only in this case? why not in general? { currentState.velocityComesFromMove = (currentSpeed <= desiredSpeed); } if (currentVelocity.sqrMagnitude > desiredVector.sqrMagnitude) { desiredVector = projectedInput.normalized * currentSpeed; if ((currentSpeed <= desiredSpeed) && currentState.velocityComesFromMove) //case : deceleration { maxAccel = frictionAppropriateAccel; } tempAccel = ClampedDeltaVAcceleration(currentVelocity, desiredVector, maxAccel); } else { Vector3 tempVelocity = currentVelocity + (tempAccel * Time.fixedDeltaTime); if (tempVelocity.sqrMagnitude > desiredVector.sqrMagnitude) { desiredVector = tempVelocity.normalized * desiredVector.magnitude; tempAccel = ClampedDeltaVAcceleration(currentVelocity, desiredVector, maxAccel); } if (tempVelocity.sqrMagnitude >= currentVelocity.sqrMagnitude) { currentState.velocityComesFromMove = true; } } if (currentState.moveInput.jumpInput) { tempAccel = Horizontalized(tempAccel) + (rb.transform.up * jumpSpeed / Time.fixedDeltaTime) - Verticalized(currentVelocity / Time.fixedDeltaTime); currentState.jumped = true; } float slopeLerpFactor = GetSlopeLerpFactor(currentState); Vector3 tempGravity; if (currentState.onSolidGround) { tempGravity = Vector3.Lerp(Physics.gravity, -surfacePoint.normal * Physics.gravity.magnitude, frictionLerpFactor);; } else { tempGravity = Physics.gravity; } if (slopeLerpFactor > 0) { Vector3 downward = Vector3.ProjectOnPlane(Physics.gravity, surfacePoint.normal).normalized; Vector3 downwardAccel = Vector3.Project(tempAccel, downward); float accelDot = Vector3.Dot(tempAccel, downward); if (accelDot < 0f) { tempAccel -= downwardAccel * slopeLerpFactor; } tempGravity = Vector3.Lerp(tempGravity, Physics.gravity, slopeLerpFactor); } outputAcceleration = tempAccel; outputGravity = tempGravity; outputFriction = (1f - slopeLerpFactor) * frictionLerpFactor * normalFriction; if (!currentState.velocityComesFromMove) { outputFriction *= GetCrouchLerpFactor(); } } else { Vector3 downward = Vector3.ProjectOnPlane(Physics.gravity, surfacePoint.normal).normalized; Vector3 downwardVelocity = Vector3.Project(currentVelocity, downward); Vector3 lateralVelocity = currentVelocity - downwardVelocity; Vector3 tempAccel = inputVector * frictionAppropriateAccel; if (Vector3.Dot(tempAccel, surfacePoint.normal) < 0f) { tempAccel = Vector3.ProjectOnPlane(tempAccel, surfacePoint.normal); Vector3 tempVelocity = currentVelocity + (tempAccel * Time.fixedDeltaTime); Vector3 lateralTempVelocity = tempVelocity - downwardVelocity; if (lateralTempVelocity.sqrMagnitude > (desiredSpeed * desiredSpeed)) { Vector3 desiredVector = tempVelocity.normalized * lateralVelocity.magnitude; tempAccel = ClampedDeltaVAcceleration(currentVelocity, desiredVector, moveAccelerationMax); } tempAccel -= Vector3.Project(tempAccel, downward); } currentState.velocityComesFromMove = false; outputAcceleration = tempAccel; outputGravity = Physics.gravity; outputFriction = 0f; } }
private void runStateMachine(StateMachineEnum statemachine, StateData submachineState, Signal signal) { runStateMachine(statemachine, submachineState, signal, null, 0); }
private bool wasPressed = true; // Tracks if thumbstick was pressed public PlayerStatePocketMenu(StateData init_data) : base(init_data) { ; }
private void Initial_10__TO__ForwardState_5(Signal signal, StateData submachineState) { if (m_StateMachineImpl == null) return; if(submachineState != null) submachineState.IncrementActiveCount(); Initial_10__TO__ForwardState_5_effect(signal); m_StateMachineImpl.currentTransition.SetActive(m_StateMachineImpl); StateProc(StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE, submachineState, StateBehaviorEnum.ENTRY, signal, EntryTypeEnum.DefaultEntry); }
public Patrol(StateData stateData) : base(stateData) { _patrolPath = StateData.PatrolPath; }
void GenerateArgumentPermutations(StateData stateData, NativeList <ActionKey> argumentPermutations) { GameObjectIndices.Clear(); stateData.GetTraitBasedObjectIndices(GameObjectIndices, GameFilter); SourceObjectIndices.Clear(); stateData.GetTraitBasedObjectIndices(SourceObjectIndices, SourceFilter); TargetObjectIndices.Clear(); stateData.GetTraitBasedObjectIndices(TargetObjectIndices, TargetFilter); var CellBuffer = stateData.CellBuffer; for (int i0 = 0; i0 < GameObjectIndices.Length; i0++) { var GameIndex = GameObjectIndices[i0]; var GameObject = stateData.TraitBasedObjects[GameIndex]; for (int i1 = 0; i1 < SourceObjectIndices.Length; i1++) { var SourceIndex = SourceObjectIndices[i1]; var SourceObject = stateData.TraitBasedObjects[SourceIndex]; if (!(CellBuffer[SourceObject.CellIndex].Type != CellType.None)) { continue; } for (int i2 = 0; i2 < TargetObjectIndices.Length; i2++) { var TargetIndex = TargetObjectIndices[i2]; var TargetObject = stateData.TraitBasedObjects[TargetIndex]; if (!(CellBuffer[SourceObject.CellIndex].Top == stateData.GetTraitBasedObjectId(TargetIndex))) { continue; } if (!(CellBuffer[TargetObject.CellIndex].Type != CellType.None)) { continue; } var actionKey = new ActionKey(k_MaxArguments) { ActionGuid = ActionGuid, [k_GameIndex] = GameIndex, [k_SourceIndex] = SourceIndex, [k_TargetIndex] = TargetIndex, }; argumentPermutations.Add(actionKey); } } } }
public bool StateProc(StateEnum state, StateData submachineState, StateBehaviorEnum behavior, Signal signal, EntryTypeEnum enumEntryType, EntryEnum[] entryArray, int nArrayCount) { switch (state) { case StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE: DriveDistanceSM_ForwardState(behavior, submachineState, signal, enumEntryType, entryArray, nArrayCount); break; case StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_STOPSTATE: DriveDistanceSM_StopState(behavior, submachineState, signal, enumEntryType, entryArray, nArrayCount); break; } return false; }
public static T GetTargetTrait <T>(StateData state, ActionKey action) where T : struct, ITrait { return(state.GetTraitOnObjectAtIndex <T>(action[k_TargetIndex])); }
public bool StateProc(int state, StateData submachineState, StateBehaviorEnum behavior, Signal signal, EntryTypeEnum enumEntryType, int[] entryArray, int nArrayCount) { EntryEnum[] entryEnumArray = new EntryEnum[nArrayCount]; for (int i = 0; i < nArrayCount; i++) { if (entryArray != null && i < entryArray.Length) entryEnumArray[i] = (EntryEnum)entryArray[i]; } return StateProc((StateEnum)state, submachineState, behavior, signal, enumEntryType, entryEnumArray, nArrayCount); }
public static void SwapCellAndUpdateBoard(ActionKey action, StateData state, Cell cell1, Cell cell2) { // Swap cell types (cell1.Type, cell2.Type) = (cell2.Type, cell1.Type); state.SetTraitOnObjectAtIndex(cell1, action[Cell1Index]); state.SetTraitOnObjectAtIndex(cell2, action[Cell2Index]); int newScore = 0; var cellsToDestroy = new NativeList <int>(1, Allocator.Temp); // Check match3 and destroy used Gem (set to Type = None) CheckMatchOnGem(state, cell1, action[Cell1Index], ref cellsToDestroy); CheckMatchOnGem(state, cell2, action[Cell2Index], ref cellsToDestroy); if (cellsToDestroy.Length > 0) { // Unset all destroyed cells var cellQueue = new NativeQueue <int>(Allocator.Temp); var cellsQueued = new NativeHashMap <int, byte>(3, Allocator.Temp); var cellChanged = new NativeHashMap <int, byte>(3, Allocator.Temp); while (cellsToDestroy.Length > 0) { foreach (var cellIndex in cellsToDestroy) { if (cellsQueued.ContainsKey(cellIndex)) { continue; } var cellTrait = state.GetTraitOnObjectAtIndex <Cell>(cellIndex); newScore += GetScore(cellTrait.Type); cellTrait.Type = CellType.None; state.SetTraitOnObjectAtIndex(cellTrait, cellIndex); cellQueue.Enqueue(cellIndex); cellsQueued.TryAdd(cellIndex, default); } cellsToDestroy.Clear(); // Stitch Unset Gems with Top Gem while (cellQueue.Count > 0) { var cellIndex = cellQueue.Dequeue(); cellsQueued.Remove(cellIndex); var cell = state.GetTraitOnObjectAtIndex <Cell>(cellIndex); if (cell.Top.Id == ObjectId.None) { continue; } if (cell.Type == CellType.None) { var cellTopObject = state.GetTraitBasedObject(cell.Top); var cellTop = state.GetTraitOnObject <Cell>(cellTopObject); // Find first cell with a known type on top while (cellTop.Type == CellType.None) { if (cellTop.Top.Id == ObjectId.None) { break; } cellTopObject = state.GetTraitBasedObject(cellTop.Top); cellTop = state.GetTraitOnObject <Cell>(cellTopObject); } if (cellTop.Type != CellType.None) { cell.Type = cellTop.Type; state.SetTraitOnObjectAtIndex(cell, cellIndex); var newCellTop = cellTop; newCellTop.Type = CellType.None; state.SetTraitOnObject(newCellTop, ref cellTopObject); var index = state.GetTraitBasedObjectIndex(cellTopObject); cellQueue.Enqueue(index); cellsQueued.TryAdd(index, default); // Queue all vertical cells for checking var cellTopIndex = state.GetTraitBasedObjectIndex(cell.Top); while (cellTop.Type != CellType.None) { cellChanged.TryAdd(cellTopIndex, default); if (cellTop.Top == TraitBasedObjectId.None) { break; } cellTopIndex = state.GetTraitBasedObjectIndex(cellTop.Top); cellTop = state.GetTraitOnObjectAtIndex <Cell>(cellTopIndex); } } } } // Check cells affected by stitching for chained-explosion using (var changedKeys = cellChanged.GetKeyArray(Allocator.Temp)) { for (int i = 0; i < changedKeys.Length; i++) { var cellIndex = changedKeys[i]; var cell = state.GetTraitOnObjectAtIndex <Cell>(cellIndex); CheckMatchOnGem(state, cell, cellIndex, ref cellsToDestroy); } } cellChanged.Clear(); } cellQueue.Dispose(); cellsQueued.Dispose(); cellChanged.Dispose(); } // Store information in Game state var gameId = state.GetTraitBasedObjectId(action[GameIndex]); var game = state.GetTraitBasedObject(gameId); var gameTrait = state.GetTraitOnObject <Game>(game); // Score is stored in the Game Object and apply later in the reward function gameTrait.Score = newScore; state.SetTraitOnObject(gameTrait, ref game); cellsToDestroy.Dispose(); }
public virtual bool StateProc(StateEnum state, StateData submachineState, StateBehaviorEnum behavior, Signal signal, EntryTypeEnum enumEntryType) { return StateProc(state, submachineState, behavior, signal, enumEntryType, null, 0); }
public bool dispatch(Event _event, StateData toState, bool bCheckOnly) { if (m_StateMachineImpl == null) return false; bool bDispatched = false; if(toState == null || !toState.IsActiveState() && !bCheckOnly) return bDispatched; switch ((StateEnum)toState.state_enum) { case StateEnum.DriveDistance_VIRTUAL_SUBMACHINESTATE: if(_event.eventEnum == EventEnum.COMPLETION) { if(!bCheckOnly) { m_StateMachineImpl.ReleaseSubmachineState(toState); List<StateData> lstStateData = m_StateMachineImpl.GetStateData(); foreach (StateData state in lstStateData) { if (state == toState) { lstStateData.Remove(state); break; } } //delete toState; toState = null; } bDispatched = true; } break; case StateEnum.DriveDistance_ENUM_DRIVEDISTANCESM_FORWARDSTATE: switch (_event.eventEnum) { case EventEnum.COMPLETION: if(abs(nMotorEncoder[MOTOR_A]) > STOP_DIST) { if(!bCheckOnly) TransitionProc(TransitionEnum.DriveDistance_ENUM_FORWARDSTATE__TO__STOPSTATE_6, null, toState.submachine_state); bDispatched = true; break; } break; } break; } if (!bDispatched && toState != null && toState.parent_state != null && _event.eventEnum != EventEnum.COMPLETION) { bDispatched = dispatch(_event, toState.parent_state, true); if (bDispatched && !bCheckOnly) { /*1. Exit the current state; 2. Decrement the active count of the parent state; 3. dispatch the event to parent state*/ StateProc((StateEnum)toState.state_enum, toState.submachine_state, StateBehaviorEnum.EXIT, null); toState.parent_state.DecrementActiveCount(); dispatch(_event, toState.parent_state, false); _event = null; } } return bDispatched; }
abstract public void Execute(StateData data);
void Awake() { Instance = this; }
abstract public void Exit(StateData data);
public void Restart() { state = new StateData(); Initialize(); }
/// <summary> /// Data for undoing /// </summary> /// <returns>Data for undoing</returns> internal void RestoreState(StateData state) { field = new Field<int>(state.Elements, state.width, state.height); }
public void TransitionProc(TransitionEnum transition, Signal signal, StateData submachineState) { if (m_StateMachineImpl == null) return; switch (transition) { case TransitionEnum.DriveDistance_ENUM_INITIAL_10__TO__FORWARDSTATE_5: m_StateMachineImpl.currentTransition.SetTransition((int)transition, submachineState, "DriveDistance_Initial_10__TO__ForwardState_5", "{349C5E01-7C43-4303-AB4B-888A0D4917F2},"); Initial_10__TO__ForwardState_5(signal, submachineState); break; case TransitionEnum.DriveDistance_ENUM_FORWARDSTATE__TO__STOPSTATE_6: m_StateMachineImpl.currentTransition.SetTransition((int)transition, submachineState, "DriveDistance_ForwardState__TO__StopState_6", "{8083DC99-F5F9-4020-8F9A-8B14BF7FC814},"); ForwardState__TO__StopState_6(signal, submachineState); break; } m_StateMachineImpl.currentTransition.SetTransition((int)TransitionEnum.NOTRANSITION, null, "", ""); }