public void Recycle() { state.Recycle(); state = null; goal.Recycle(); goal = null; cachedNodes.Push(this); }
public void Recycle() { state.Recycle(); state = null; Goal.Recycle(); Goal = null; lock (cachedNodes) { cachedNodes.Push(this); } }
protected virtual void OnDestroy() { goal.Recycle(); }
private void Init(IGoapPlanner <T, W> planner, ReGoapState <T, W> newGoal, ReGoapNode <T, W> parent, IReGoapAction <T, W> action) { expandList.Clear(); this.planner = planner; this.parent = parent; this.action = action; if (action != null) { actionSettings = action.GetSettings(planner.GetCurrentAgent(), newGoal); } if (this.parent != null) { state = this.parent.GetState(); // g(node) g = parent.GetPathCost(); } else { state = (ReGoapState <T, W>)planner.GetCurrentAgent().GetMemory().GetWorldState().Clone(); } var nextAction = parent == null ? null : parent.action; if (action != null) { // since in backward search we relax the problem all preconditions are valid but are added to the current goal var preconditions = action.GetPreconditions(newGoal, nextAction); goal = newGoal + preconditions; var effects = action.GetEffects(newGoal, nextAction); state += effects; g += action.GetCost(newGoal, nextAction); // removing current action effects from goal, no need to do with to the whole state // since the state is the sum of all the previous actions's effects. var missingState = ReGoapState <T, W> .Instantiate(); goal.MissingDifference(effects, ref missingState); goal.Recycle(); goal = missingState; // this is needed every step to make sure that any precondition is not already satisfied // by the world state var worldMissingState = ReGoapState <T, W> .Instantiate(); goal.MissingDifference(planner.GetCurrentAgent().GetMemory().GetWorldState(), ref worldMissingState); goal.Recycle(); goal = worldMissingState; } else { var diff = ReGoapState <T, W> .Instantiate(); newGoal.MissingDifference(state, ref diff); goal = diff; } h = goal.Count; // f(node) = g(node) + h(node) cost = g + h * heuristicMultiplier; }
void OnDestroy() { goal.Recycle(); }
void OnDestroy() { state.Recycle(); }
protected virtual void OnDestroy() { state.Recycle(); }