/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here UserData.RegisterType <Guid>(); gauge = new Script(); store = new SpriteStore(graphics.GraphicsDevice, gauge); kvStore = new KeyValueStore(); network = new Network(12800); protocol = new Protocol(kvStore, store, network); gauge.Globals["Test"] = (System.Action)store.test; gauge.Globals["addSprite"] = (Func <string, int, int, int?, int?, Guid>)store.addSprite; gauge.Globals["rotateSprite"] = (System.Action <Guid, float>)store.rotateSprite; gauge.Globals["setSpriteOrigin"] = (System.Action <Guid, float, float>)store.setSpriteOrigin; gauge.Globals["subscribeSprite"] = (System.Action <object[]>)store.subscribeSprite; gauge.Globals["setAircraftType"] = (System.Action <string>)kvStore.setAircraftType; gauge.Globals["setSpriteViewPort"] = (System.Action <Guid, int, int, int, int>)store.spriteViewPort; rotation = 0; network.MessageReceived += protocol.MessageReceivedHandler; network.Start(); aFile = "C:/Users/whartsell/Documents/ARU-2/resources/Horizon.png"; using (FileStream fs = File.OpenRead(aFile)) { test = Texture2D.FromStream(graphics.GraphicsDevice, fs); } base.Initialize(); }
public void update(SpriteStore store) { foreach (var pair in store.RegisteredCallbacks) // iterate through the registered callbacks { foreach (var value in pair.Value) // iterating through the registered keys for the callback { if (kvDirty.ContainsKey(value)) // if the registered key is in the dirty store a callback needs to be made { //build the callback Closure callback = pair.Key; List <object> parameters = new List <object>(); // build the parameters based on the registered keys for the call back foreach (string key in pair.Value) { object keyValue; kvStore.TryGetValue(key, out keyValue); // sometimes a key may not exist yet in the datastore so send nil parameters.Add(keyValue); } callback.Call(parameters.ToArray()); break; } } } kvDirty.Clear(); }
public Protocol(KeyValueStore store, SpriteStore spriteStore, Network network) { kvStore = store; this.spriteStore = spriteStore; this.network = network; }