Sfoglia il codice sorgente

Introduced new system driver initialisation.

woollybah 7 anni fa
parent
commit
f3055ff916

+ 32 - 3
system.mod/driver.bmx

@@ -1,8 +1,10 @@
 
 SuperStrict
 
-Type TSystemDriver
+Type TSystemDriver Abstract
 
+	Method Name:String() Abstract
+	
 	Method Poll() Abstract
 	Method Wait() Abstract
 	
@@ -21,7 +23,34 @@ Type TSystemDriver
 	Method DesktopHeight:Int() Abstract
 	Method DesktopDepth:Int() Abstract
 	Method DesktopHertz:Int() Abstract
-	
+
+	Method ToString:String()
+		Return Name()
+	End Method
+
 End Type
 
-Global Driver:TSystemDriver
+Private
+Global _Driver:TSystemDriver
+Public
+
+Rem
+bbdoc: Initialises the BlitzMax system driver.
+about: There can only be one system driver initialised. A second call to this function will result in an exception.
+End Rem
+Function InitSystemDriver(driver:TSystemDriver)
+	If _Driver Throw "Cannot initialise " + driver.ToString() + ". System driver already configured as " + _Driver.ToString()
+	_Driver = driver
+End Function
+
+Rem
+bbdoc: Returns the BlitzMax system driver, or throws an exception if #InitSystemDriver() hasn't been called with one.
+End Rem
+Function SystemDriver:TSystemDriver()
+	If Not _Driver Then
+		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
+	End If
+	Return _Driver
+End Function
+
+

+ 30 - 90
system.mod/system.bmx

@@ -96,11 +96,7 @@ End Rem
 Function PollSystem()
 	If _busy Return
 	_busy=True
-	If Driver Then
-		Driver.Poll
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().Poll
 	_busy=False
 End Function
 
@@ -120,11 +116,7 @@ End Rem
 Function WaitSystem()
 	If _busy Return
 	_busy=True
-	If Driver Then
-		Driver.Wait
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().Wait
 	_busy=False
 End Function
 
@@ -186,33 +178,21 @@ about:
 the current window or graphics display.
 End Rem
 Function MoveMouse( x,y )
-	If Driver Then
-		Driver.MoveMouse x,y
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().MoveMouse x,y
 End Function
 
 Rem
 bbdoc: Make the mouse pointer visible
 End Rem
 Function ShowMouse()
-	If Driver Then
-		Driver.SetMouseVisible True
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().SetMouseVisible True
 End Function
 
 Rem
 bbdoc: Make the mouse pointer invisible
 End Rem
 Function HideMouse()
-	If Driver Then
-		Driver.SetMouseVisible False
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().SetMouseVisible False
 End Function
 
 Rem
@@ -224,11 +204,7 @@ The optional @serious flag can be used to indicate a 'critical' event.
 Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function Notify( text$,serious=False )
-	If Driver Then
-		Driver.Notify text,serious
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	SystemDriver().Notify text,serious
 End Function
 
 Rem
@@ -242,11 +218,7 @@ False is returned.
 Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function Confirm( text$,serious=False )
-	If Driver Then
-		Return Driver.Confirm( text,serious )
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().Confirm( text,serious )
 End Function
 
 Rem
@@ -260,11 +232,7 @@ selects NO, then #Proceed returns 0. Otherwise, #Proceed returns -1.
 Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function Proceed( text$,serious=False )
-	If Driver Then
-		Return Driver.Proceed( text,serious )
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().Proceed( text,serious )
 End Function
 
 Rem
@@ -283,11 +251,7 @@ that begin with a "group:" and separated by a semicolon.
 Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function RequestFile$( text$,extensions$="",save_flag=False,initial_path$="" )
-	If Driver Then
-		Return Driver.RequestFile( text,extensions,save_flag,initial_path )
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().RequestFile( text,extensions,save_flag,initial_path )
 End Function
 
 Rem
@@ -301,11 +265,7 @@ about:
 Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function RequestDir$( text$,initial_path$="" )
-	If Driver Then
-		Return Driver.RequestDir( text,initial_path )
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().RequestDir( text,initial_path )
 End Function
 
 Rem
@@ -313,27 +273,23 @@ bbdoc: Opens a URL with the system's default web browser.
 about: Note that a user interface may not be available when in graphics mode on some platforms.
 End Rem
 Function OpenURL( url$ )
-	If Driver Then
-		Local dev$,anchor$
-	
-		dev=url[..5].toLower()
-		If dev<>"http:" And dev<>"file:" And url[..6].ToLower()<>"https:"
-			Local h=url.find("#")
-			If h>-1
-				anchor=url[h..]
-				url=url[..h]
-			EndIf
-			Local f$=RealPath(url)
-			If FileType(f) 
-				url="file:"+f +anchor
-			Else
-				url="http:"+url+anchor
-			EndIf
+	Local dev$,anchor$
+
+	dev=url[..5].toLower()
+	If dev<>"http:" And dev<>"file:" And url[..6].ToLower()<>"https:"
+		Local h=url.find("#")
+		If h>-1
+			anchor=url[h..]
+			url=url[..h]
 		EndIf
-		Return Driver.OpenURL( url )
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+		Local f$=RealPath(url)
+		If FileType(f) 
+			url="file:"+f +anchor
+		Else
+			url="http:"+url+anchor
+		EndIf
+	EndIf
+	Return SystemDriver().OpenURL( url )
 End Function
 
 
@@ -342,11 +298,7 @@ bbdoc: Get desktop width
 returns: Width of the desktop, in pixels
 End Rem
 Function DesktopWidth()
-	If Driver Then
-		Return Driver.DesktopWidth()
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().DesktopWidth()
 End Function
 
 Rem
@@ -354,11 +306,7 @@ bbdoc: Get desktop height
 returns: Height of the desktop, in pixels
 End Rem
 Function DesktopHeight()
-	If Driver Then
-		Return Driver.DesktopHeight()
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().DesktopHeight()
 End Function
 
 Rem
@@ -370,11 +318,7 @@ The depth of the desktop is the number of bits per pixel.
 Note that on some platforms this function may return 0 if the desktop depth cannot be determined.
 End Rem
 Function DesktopDepth()
-	If Driver Then
-		Return Driver.DesktopDepth()
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().DesktopDepth()
 End Function
 
 Rem
@@ -384,11 +328,7 @@ about:
 Note that on some platforms this function may return 0 if the desktop refresh rate cannot be determined.
 End Rem
 Function DesktopHertz()
-	If Driver Then
-		Return Driver.DesktopHertz()
-	Else
-		Throw "No System Driver installed. Maybe Import BRL.SystemDefault ?"
-	End If
+	Return SystemDriver().DesktopHertz()
 End Function
 
 'End Extern

+ 5 - 1
systemdefault.mod/system.linux.bmx

@@ -121,8 +121,12 @@ Type TLinuxSystemDriver Extends TSystemDriver
 		Return bbSystemDesktopHertz()
 	End Method
 
+	Method Name:String()
+		Return "LinuxSystemDriver"
+	End Method
+	
 End Type
 
-Driver=New TLinuxSystemDriver
+InitSystemDriver(New TLinuxSystemDriver)
 
 ?

+ 4 - 0
systemdefault.mod/system.macos.bmx

@@ -127,5 +127,9 @@ Type TMacOSSystemDriver Extends TSystemDriver
 		Return bbSystemDesktopHertz()
 	End Method
 
+	Method Name:String()
+		Return "MacOSSystemDriver "
+	End Method
+
 End Type
 

+ 4 - 0
systemdefault.mod/system.win32.bmx

@@ -147,4 +147,8 @@ Type TWin32SystemDriver Extends TSystemDriver
 		Return bbSystemDesktopHertz()
 	End Method
 
+	Method Name:String()
+		Return "Win32SystemDriver"
+	End Method
+	
 End Type

+ 2 - 2
systemdefault.mod/systemdefault.bmx

@@ -78,11 +78,11 @@ Import "system.c"
 
 ?osx
 Import "system.macos.bmx"
-Driver=New TMacOSSystemDriver
+InitSystemDriver(New TMacOSSystemDriver)
 ?Win32
 Import "system.win32.bmx"
 Import "-lcomdlg32"
-Driver=New TWin32SystemDriver
+InitSystemDriver(New TWin32SystemDriver)
 ?Linux
 Import "system.linux.bmx"
 ?