/// <summary> Returns a modified seed with the given <see cref="offset"/> </summary> /// <param name="offset"> Index value to use </param> /// <returns> Returns a modified seed with the given <see cref="offset"/> </returns> public ItemGenSeed Offset(long offset) { ItemGenSeed next = this; next.offset = offset; return(next); }
/// <summary> Returns a modified seed with the given <see cref="index"/> </summary> /// <param name="index"> Index value to use </param> /// <returns> Returns a modified seed with the given <see cref="index"/> </returns> public ItemGenSeed Scale(double scale) { ItemGenSeed next = this; next.scale = scale; return(next); }
/// <summary> Generate some data, starting at a given rule, with a given seed. </summary> /// <param name="startingRule"> Name of rule to search for and begin at </param> /// <param name="igSeed"> Seed value used to generate data </param> /// <returns> Generated data + history. </returns> public JsonObject Generate(string startingRule, ItemGenSeed igSeed) { State state = new State(igSeed); state.result["startingRule"] = startingRule; state.result["genType"] = ruleset.Get <string>("type"); state.result["genId"] = startingRule; JsonObject initializer = ruleset.Pull <JsonObject>("initialize"); if (initializer != null) { state.result.SetRecursively(initializer); } long lseed = igSeed.seed; double scale = igSeed.scale; // The rule is to add the empty history for the next rule before calling Apply // This allows Apply to figure out exactly where in the chain it is. state.PushHistory(startingRule); Apply(state, startingRule, ruleset); state.PopHistory(); return(state.result); }
/// <summary> Returns a modified seed with +1 to the <see cref="index"/> field </summary> /// <returns> Returns a modified seed with +1 to the <see cref="index"/> field </returns> public ItemGenSeed Next() { ItemGenSeed next = this; next.scale += 1.0; return(next); }
public State(ItemGenSeed igSeed) { this.igSeed = igSeed; // Resulting creation + history result = new JsonObject( "name", "", "genId", "", "root", igSeed.root.ToString(), "offset", igSeed.offset, "scale", igSeed.scale, "genHistory", new JsonArray() ); path = new List <string>(); long seed = igSeed.seed; long hi = (seed >> 32) & 0x00000000FFFFFFFF; long low = seed & 0x00000000FFFFFFFF; int mix = (int)(low ^ hi); random = new Random(mix < 0 ? -mix : mix); }