Red: thats whatI allready use. infact, here is the Manager that does all that.
this is a Generic class that sets up the display, creates the needed vars and settings to run the game and then handles the Mainloop. The mainloop in turn simple triggers the needed events for Setup, Rendering, Inputhandling and unloading.
the way to use this is simple:
All i have to do is create a Game file that simply handles the events mentioned above:
- SceneLoadCallback -- Handle scene loading
- SceneRenderCallback -- called every loop to do the drawing.
- SceneInputCallback -- called every loop to handle Input
- SceneUnloadCallback -- Handle Scene unloading
- SceneStateCallback -- optional State change event handler
All this stuff is getting far out of scope of what the thread was intended for though.
Type Manager Extends IDisposable '// Vars Global Instance:Manager = New Manager; Field Driver:TGraphicsDriver; Field VSync:Int, IsRunning:Byte; Field State:Int, OldState:Int; Field RandomSeed:Long; Field DatabaseFile:String; Field DBase:Database; '// Delegates Field SceneLoadFunc() Field SceneInputFunc( time:Float ) Field SceneRenderFunc( time:Float ) Field SceneUnloadFunc() Field SceneStateFunc( currstate:Int, prevstate:Int ) '// Ctor Method New() Self.VSync = True; Self.IsRunning = False; Self.RandomSeed = GetTickCount(); Self.DatabaseFile = "data.bin"; Self.DBase = Database.Create( DatabaseFile ); End Method '// Methods Method Start() SceneLoadFunc(); IsRunning = True; Repeat Timer.Instance.Update(); Local time:Float = Timer.Instance.GetTimeMSec() / 1000.0; Cls(); ResetCollisions(); SceneInputFunc( time ); SceneRenderFunc( time ); Flip(VSync); Until( AppTerminate() Or (Not IsRunning) ) SceneUnloadFunc(); End Method Method Stop() IsRunning = False; End Method Method SetState( newstate:Int ) OldState = State; State = newstate; SceneStateFunc( State, OldState ); End Method Method Initialize:Byte( gw:Int, gh:Int, gd:Int = 0, hz:Int = 60, flags:Int = 0, forcedDriver:TGraphicsDriver = Null ) If( forcedDriver = Null ) Then ?Win32 Driver = D3D7Max2DDriver(); ? ?Linux Driver = GLMax2DDriver(); ? ?MacOS Driver = GLMax2DDriver(); ? Else Driver = forcedDriver; End If Try SetGraphicsDriver(Driver); Graphics( gw, gh, gd, hz, flags ); Print( "Graphics Context Created for driver: " + Driver.ToString() ); Local s:String = ""; If( gd = 0 ) Then s = " (Windowed)"; Else s = " @ " + gd + " (" + hz + "hz.)"; End If Print( "Selected Displaymode: " + gw + "x" + gh + s ); Catch e:Object Notify( e.ToString(), True ); Return False; End Try HideMouse(); AutoMidHandle( True ); Return True; End Method Method Dispose() If( Self.DBase <> Null ) Then If( Self.DBase.IsOpen ) Then Self.DBase.Close(); End If End If ShowMouse(); GCCollect(); End; End Method '// Functions End Type
this is a Generic class that sets up the display, creates the needed vars and settings to run the game and then handles the Mainloop. The mainloop in turn simple triggers the needed events for Setup, Rendering, Inputhandling and unloading.
the way to use this is simple:
If( Manager.Instance.Initialize( 800,600, 0 ) ) Then '// Hook the available events Manager.Instance.SceneLoadFunc = SceneLoadCallback; Manager.Instance.SceneRenderFunc = SceneRenderCallback; Manager.Instance.SceneInputFunc = SceneInputCallback; Manager.Instance.SceneUnloadFunc = SceneUnloadCallback; Manager.Instance.SceneStateFunc = SceneStateCallback; '// Start the whole thing up. Manager.Instance.Start(); End If '// Dispose of any resources. Manager.Instance.Dispose();
All i have to do is create a Game file that simply handles the events mentioned above:
- SceneLoadCallback -- Handle scene loading
- SceneRenderCallback -- called every loop to do the drawing.
- SceneInputCallback -- called every loop to handle Input
- SceneUnloadCallback -- Handle Scene unloading
- SceneStateCallback -- optional State change event handler
Function SceneRenderCallback( time:Float ) End Function Function SceneInputCallback( time:Float ) If( KeyHit( KEY_ESCAPE ) ) Then Manager.Instance.Stop(); End Function Function SceneLoadCallback() End Function Function SceneUnloadCallback() End Function Function SceneStateCallback( currstate:Int, prevstate:Int ) End Function
All this stuff is getting far out of scope of what the thread was intended for though.