1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
| public class App { [StructLayout(LayoutKind.Sequential)] private struct Message { public IntPtr hWnd; public int msg; public IntPtr wParam; public IntPtr lParam; public uint time; public Point p; }
[return: MarshalAs(UnmanagedType.Bool)] [SuppressUnmanagedCodeSecurity, DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
private Console console; private StateMachine stateMachine;
public App(Console console, int width, int height, string title) { this.console = console; this.console.Text = title;
stateMachine = new StateMachine();
Run(width, height); }
public void Run(int width, int height) { Application.Idle += Application_Idle; stateMachine.AddState(new SplashState(width, height), false); Application.Run(console); }
private void Application_Idle(object sender, EventArgs e) { Message msg; Time.startTime = DateTime.Now;
while(!PeekMessage(out msg, IntPtr.Zero, 0, 0, 0)) { float elapsed = (float)DateTime.Now.Subtract(Time.startTime).TotalSeconds;
Time.deltaTime = elapsed; Time.totalElapsedTime += elapsed; Time.startTime = DateTime.Now;
stateMachine.GetActiveState().Update(); stateMachine.GetActiveState().Render(console); } } } |