public void Initalize(bool _headless) { // Game this.Runner = new Interpreter(this); this.GlobalScope = new LInstance(this, (double)LVariableScope.Global); this.StaticScope = new LInstance(this, (double)LVariableScope.Static); this.CurrentColor = LColour.FromColor4(Color4.White); this.CirclePrecision = 24; // Window this.Headless = _headless; if (_headless == false) { this.Window = new GameWindow(this.RoomWidth, this.RoomHeight); this.Window.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().Location); // meh (big meh -sanae) this.Window.Title = this.DisplayName; this.Window.Load += OnLoad; this.Window.Closing += OnClose; this.Window.UpdateFrame += OnUpdate; this.Window.RenderFrame += OnRender; Input.Initalize(this); this.Window.Run(); VM.Timer.Start(); } else { OnLoad(null, null); } }
public static LValue instance_destroy(Game _assets, Domain _environment, LValue[] _arguments, Int32 _count, Stack <LValue> _stack) { bool _instDestroy = (_count < 2 || LValue.GetBool(_arguments[1]) == true); if (_count > 0) { double _instIndex = _arguments[1].Number; if (_instIndex < LInstance.IDStart) { LInstance _instGet = LInstance.Find(_assets, _instIndex, false); while (_instGet != null) { _instGet.Remove(_assets, _instDestroy); _instGet = LInstance.Find(_assets, _instIndex, false); } } else { LInstance _instGet = LInstance.Find(_assets, _instIndex, false); if (_instGet != null) { _instGet.Remove(_assets, _instDestroy); } } } else { if (_environment.Instance.ID >= LInstance.IDStart) { _environment.Instance.Remove(_assets, _instDestroy); } } return(LValue.Real(0)); }
public static void DrawDefaultObject(Game _assets, LInstance _inst) { LValue _index = _inst.Variables["sprite_index"]; LValue _image = _inst.Variables["image_index"]; if (_index.I32 >= 0 && _index < _assets.SpriteMapping.Count) { LSprite _sprite = _assets.SpriteMapping[_index]; double _x = _inst.Variables["x"]; double _y = _inst.Variables["y"]; GL.PushMatrix(); GL.Translate(_x, _y, 0); GL.Rotate(_inst.Variables["image_angle"].Number, 0, 0, 1); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, _assets.TextureEntries[_image].GLTexture); GL.Begin(PrimitiveType.TriangleStrip); byte[] _color = BitConverter.GetBytes((int)_inst.Variables["image_blend"].Number); GL.Color4(_color[2] / 255d, _color[1] / 255d, _color[0] / 255d, _inst.Variables["image_alpha"]); GL.TexCoord2(0.0, 0.0); GL.Vertex2(-_sprite.XOrigin, -_sprite.YOrigin); GL.TexCoord2(1.0, 0.0); GL.Vertex2(-_sprite.XOrigin + _sprite.Width, -_sprite.YOrigin); GL.TexCoord2(0.0, 1.0); GL.Vertex2(-_sprite.XOrigin, -_sprite.YOrigin + _sprite.Height); GL.TexCoord2(1.0, 1.0); GL.Vertex2(-_sprite.XOrigin + _sprite.Width, -_sprite.YOrigin + _sprite.Height); GL.End(); GL.Disable(EnableCap.Texture2D); GL.PopMatrix(); } }
private void OnClose(object sender, System.ComponentModel.CancelEventArgs e) { for (int i = 0; i < this.InstanceList.Count; i++) { LInstance _inst = this.InstanceList[i]; if (_inst.Destroy != null) { _inst.Environment.ExecuteCode(this, _inst.Destroy); } } Environment.Exit(0); }
public static LValue instance_create_depth(Game _assets, Domain _environment, LValue[] _arguments, Int32 _count, Stack <LValue> _stack) { LInstance _instCreate = new LInstance(_assets, _assets.ObjectMapping[(int)_arguments[3].Number], true, _arguments[0].Number, _arguments[1].Number); _instCreate.Variables["depth"] = _arguments[2]; if (_instCreate.PreCreate != null) { _instCreate.Environment.ExecuteCode(_assets, _instCreate.PreCreate); } if (_instCreate.Create != null) { _instCreate.Environment.ExecuteCode(_assets, _instCreate.Create); } return(LValue.Real(_instCreate.ID)); }
public static void LoadRoom(Game _assets, LRoom _room) { _assets.CurrentRoom = _room; LInstance[] _roomInstances = new LInstance[_room.Instances.Count]; for (int i = 0; i < _room.Instances.Count; i++) { LRoomInstance _instGet = _room.Instances[i]; LInstance _instCreate = new LInstance(_assets, _instGet.Index, true, _instGet.X, _instGet.Y); _instCreate.Variables["image_xscale"] = LValue.Real(_instGet.ScaleX); _instCreate.Variables["image_yscale"] = LValue.Real(_instGet.ScaleY); _instCreate.Variables["image_speed"] = LValue.Real(_instGet.ImageSpeed); _instCreate.Variables["image_index"] = LValue.Real(_instGet.ImageIndex); _instCreate.Variables["image_blend"] = LValue.Real(_instGet.ImageBlend); _instCreate.Variables["image_angle"] = LValue.Real(_instGet.Rotation); _instCreate.RoomPreCreate = _instGet.PreCreate; _instCreate.RoomCreate = _instGet.CreationCode; _roomInstances[i] = _instCreate; } for (int i = 0; i < _roomInstances.Length; i++) { LInstance _instGet = _roomInstances[i]; if (_instGet.PreCreate != null) { _instGet.Environment.ExecuteCode(_assets, _instGet.PreCreate); } if (_instGet.RoomPreCreate != null) { _instGet.Environment.ExecuteCode(_assets, _instGet.RoomPreCreate); } if (_instGet.Create != null) { _instGet.Environment.ExecuteCode(_assets, _instGet.Create); } if (_instGet.RoomCreate != null) { _instGet.Environment.ExecuteCode(_assets, _instGet.RoomCreate); } } if (_room.CreationCode != null) { Domain _roomEnvironment = new LInstance(_assets, -100, false).Environment; _roomEnvironment.ExecuteCode(_assets, _room.CreationCode); } }
public static Dictionary <string, LValue> GetVariables(Game _assets, Domain _environment, double _scope) { switch ((LVariableScope)_scope) { case LVariableScope.Instance: return(_environment.Instance.Variables); case LVariableScope.Local: return(_environment.Locals); default: { LInstance _instGet = LInstance.Find(_assets, _scope); if (_instGet != null) { return(_instGet.Variables); } throw new Exception(String.Format("Could not find object or instance with the index: {0}", _scope)); } } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { double _instScope = _stack.Pop().Number; switch (_instScope) { case -9: { _instScope = _stack.Pop().Number; break; } } /* * NOTE: * The code here isn't great, I don't really want to do code execution this way. * I think that the code should be ran in the current scope, and we'll just have a stack * that holds each instance scope in it. This does work, but doesn't really follow the * pattern set by Runner.exe and will likely lead to issues down the line. * - Nommiin */ if (_instScope >= 0 && _instScope < LInstance.IDStart) { List <LInstance> _instList = LInstance.FindList(_assets, _instScope, true); if (_instList != null) { foreach (LInstance _instGet in _instList) { _instGet.Environment.Locals = _environment.Locals; _instGet.Environment.ExecuteCode(_assets, _code, new Tuple <int, int>(_environment.ProgramCounter + 1, this.Jump)); } } } else { LInstance _instGet = _assets.InstanceMapping[_instScope]; if (_instGet != null) { _instGet.Environment.Locals = _environment.Locals; _instGet.Environment.ExecuteCode(_assets, _code, new Tuple <int, int>(_environment.ProgramCounter + 1, this.Jump)); } } _environment.ProgramCounter = this.Jump; }
private void OnUpdate(object sender, FrameEventArgs e) { Input.OnKeyUpdate(); for (int i = 0; i < this.InstanceList.Count; i++) { LInstance _instGet = this.InstanceList[i]; if (_instGet.BeginStep != null) { _instGet.Environment.ExecuteCode(this, _instGet.BeginStep); } if (_instGet.Step != null) { _instGet.Environment.ExecuteCode(this, _instGet.Step); } if (_instGet.EndStep != null) { _instGet.Environment.ExecuteCode(this, _instGet.EndStep); } _instGet.Variables["xprevious"] = _instGet.Variables["x"]; _instGet.Variables["yprevious"] = _instGet.Variables["y"]; } }
private void OnRender(object sender, FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0f, this.RoomWidth, this.RoomHeight, 0f, 0f, 1.0f); for (int i = 0; i < this.InstanceList.Count; i++) { LInstance _instGet = this.InstanceList[i]; if (_instGet.Draw != null) { _instGet.Environment.ExecuteCode(this, _instGet.Draw); } else { VM.DrawDefaultObject(this, _instGet); } } GL.Flush(); Window.SwapBuffers(); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { if (_environment.ArrayNext == true) { int _arrayIndex = (int)(double)_stack.Pop().Value; Dictionary <string, LValue> _variableList = Helper.GetVariables(_assets, _environment, (double)_stack.Pop().Value); if (_variableList.ContainsKey(this.Variable.Name) == false || _variableList[this.Variable.Name].Type != LType.Array) { _variableList[this.Variable.Name] = new LValue(LType.Array, new LValue[_arrayIndex + 1]); for (int i = 0; i <= _arrayIndex; i++) { _variableList[this.Variable.Name].Array[i] = new LValue(LType.Number, (double)0); } } LValue _valGet = _variableList[this.Variable.Name]; if (_arrayIndex > _valGet.Array.Length) { LValue _valCopy = new LValue(LType.Array, new LValue[_arrayIndex + 1]); for (int i = 0; i <= _arrayIndex; i++) { if (i < _valGet.Array.Length) { _valCopy.Array[i] = _valGet.Array[i]; } else { _valCopy.Array[i] = new LValue(LType.Number, (double)0); } } _variableList[this.Variable.Name] = _valCopy; _valGet = _valCopy; } _valGet.Array[_arrayIndex] = _stack.Pop(); _environment.ArrayNext = false; } else { double _varScope = this.Data; if (this.Data == 0 && _stack.Count > 1) { switch ((double)_stack.Pop()) { case -9: { _varScope = _stack.Pop(); break; } } } if (_varScope >= 0 && _varScope < LInstance.IDStart) { LValue _valSet = _stack.Pop(); List <LInstance> _instList = LInstance.FindList(_assets, _varScope, true); if (_instList != null) { foreach (LInstance _instGet in _instList) { _instGet.Variables[this.Variable.Name] = _valSet; } } } else { Helper.GetVariables(_assets, _environment, _varScope)[this.Variable.Name] = _stack.Pop(); } } }
public Domain(LInstance _inst, Domain _other) { this.Scope = _inst.ID; this.Instance = _inst; this.Locals = _other.Locals; }
public Domain(LInstance _inst) { this.Scope = _inst.ID; this.Instance = _inst; this.Locals = new Dictionary <string, LValue>(); }