//is fed the previous generate if one is available, if not curVal is mid of outgoing window public void Evaluate(GeneratorEvalParams p)//float time, float curVal, Vector2 incomingWindow) { //Vector2 expandedWindow = new Vector2(Mathf.Min(p.currentWindow.x, outgoingWindow.x),Mathf.Max(p.currentWindow.y, outgoingWindow.y)); float curTime = IncrementAndWrap(p.increment); float ourVal = Generate(curTime); Combine(ourVal, p); if (p.first && genMethod != GenMethod.None) { p.currentWindow = generationWindow; p.first = false; } if (rerangeOutGoing) { p.currentVal = AID.UTIL.ReRange(p.currentVal, p.currentWindow.x, p.currentWindow.y, outgoingWindow.x, outgoingWindow.y); } //do we clamp, we still need to clamp even if rerange as we cannot trust others to have clamped also if (clampToOutputRange) { p.currentVal = Mathf.Clamp(p.currentVal, outgoingWindow.x, outgoingWindow.y); } //TODO do we gate }
void Combine(float ourVal, GeneratorEvalParams p) { if (genMethod == GenMethod.None) { return; } float sign = 1; switch (combineOp) { case CombineOp.Div: p.currentVal /= ourVal; if (!p.first) { // if there is any neg we must maintain it if (generationWindow.x < 0 || generationWindow.y < 0 || p.currentWindow.x < 0 || p.currentWindow.y < 0) { sign = -1; } p.currentWindow.x /= generationWindow.x * sign; p.currentWindow.y /= generationWindow.y; } break; case CombineOp.Mul: p.currentVal *= ourVal; //if there is any neg we must maintain it if (!p.first) { if (generationWindow.x < 0 || generationWindow.y < 0 || p.currentWindow.x < 0 || p.currentWindow.y < 0) { sign = -1; } p.currentWindow.x *= generationWindow.x * sign; p.currentWindow.y *= generationWindow.y; } break; case CombineOp.Add: p.currentVal += ourVal; if (!p.first) { p.currentWindow.x += generationWindow.x; p.currentWindow.y += generationWindow.y; } break; case CombineOp.Sub: p.currentVal -= ourVal; if (!p.first) { p.currentWindow.x -= generationWindow.x; p.currentWindow.y -= generationWindow.y; } break; case CombineOp.Min: p.currentVal = Mathf.Min(p.currentVal, ourVal); if (!p.first) { p.currentWindow.x = Mathf.Min(p.currentWindow.x, generationWindow.x); p.currentWindow.y = Mathf.Min(p.currentWindow.y, generationWindow.y); } break; case CombineOp.Max: p.currentVal = Mathf.Max(p.currentVal, ourVal); if (!p.first) { p.currentWindow.x = Mathf.Max(p.currentWindow.x, generationWindow.x); p.currentWindow.y = Mathf.Max(p.currentWindow.y, generationWindow.y); } break; case CombineOp.Mid: p.currentVal = (p.currentVal + ourVal) * 0.5f; if (!p.first) { p.currentWindow.x = (p.currentWindow.x + generationWindow.x) * 0.5f; p.currentWindow.y = (p.currentWindow.y + generationWindow.y) * 0.5f; } break; default: Debug.LogError("Unhandled combine op: " + combineOp.ToString()); break; } }