Adaptive <GameStateWithInputs, GameInput> GetTestAdaptive(string hostname, int peerId, int bufferSize) { var game = new GameManager() { testInput = Vector3.right }; var inputClock = new TestClock(framesPerSecond: 60, autostart: false, endOfFrame: true, startFrame: 0, name: string.Format("H{0} inputclock", hostname)) { ExecutionOrder = 2 }; var network = new Network <GameStateWithInputs, GameInput> (inputClock, transport: new TestTransport(hostname), peerId: peerId); var adaptive = new Adaptive <GameStateWithInputs, GameInput> (game, simulationDelay: bufferSize, inputClock: inputClock, simulationClock: new TestClock(framesPerSecond: 60, autostart: false, name: string.Format("H{0} simclock", hostname)) { ExecutionOrder = 0 }, bufferClock: new TestClock(framesPerSecond: 60) { ExecutionOrder = 1 }, network: network); adaptive.Simulation.InputHandler = delegate(GameStateWithInputs mutableState, System.Collections.Generic.KeyValuePair <int, GameInput>[] inputs, int frameIndex) { foreach (var kv in inputs) { var input = kv.Value; mutableState.Move(input.direction); } }; return(adaptive); }
// Use this for initialization void Start() { #if SERVER Adaptive = new Adaptive <GameState, GameInput> (gameManager: this, maxPeerDelay: 2, simulationDelay: 1, port: 12500); Adaptive.Simulation.InputHandler = HandleSimulationInputHandler; Adaptive.Host(GetStartState()); #else Adaptive = new Adaptive <GameState, GameInput> (gameManager: this, maxPeerDelay: 2, simulationDelay: 1, port: 12501); Adaptive.Simulation.InputHandler = HandleSimulationInputHandler; Adaptive.Connect("127.0.0.1", 12500); #endif }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { IGH_Goo goo = null; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int mode = 0; DA.GetData(1, ref mode); int numValA = 1; DA.GetData(2, ref numValA); int numValB = 1; DA.GetData(3, ref numValB); Filter filter = new Filter(); int[] indices = new int[] { 2, 3 }; switch ((FilterModes)mode) { case FilterModes.Adaptive: ClearParameters(indices); filter = new Adaptive(); image.Filters.Add(new Adaptive()); break; case FilterModes.Conservative: ClearParameters(indices); filter = new Conservative(); image.Filters.Add(new Conservative()); break; case FilterModes.Median: ClearParameters(indices); filter = new Median(); image.Filters.Add(new Median()); break; case FilterModes.Gaussian: SetParameter(2, "D", "Divisor", "Division factor"); SetParameter(3, "T", "Threshold", "Threshold weighted sum"); filter = new Gaussian(numValA, numValB); image.Filters.Add(new Gaussian(numValA, numValB)); break; case FilterModes.HighBoost: SetParameter(2, "D", "Divisor", "Division factor"); SetParameter(3, "T", "Threshold", "Threshold weighted sum"); filter = new HighBoost(numValA, numValB); image.Filters.Add(new HighBoost(numValA, numValB)); break; case FilterModes.Mean: SetParameter(2, "D", "Divisor", "Division factor"); SetParameter(3, "T", "Threshold", "Threshold weighted sum"); filter = new Mean(numValA, numValB); image.Filters.Add(new Mean(numValA, numValB)); break; case FilterModes.Simple: SetParameter(2, "D", "Divisor", "Division factor"); SetParameter(3, "T", "Threshold", "Threshold weighted sum"); filter = new Simple(numValA, numValB); image.Filters.Add(new Simple(numValA, numValB)); break; } message = ((FilterModes)mode).ToString(); UpdateMessage(); DA.SetData(0, image); DA.SetData(1, filter); }