aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UPlatform.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-17 16:46:58 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-17 16:46:58 +0000
commit329e2b8eabd0f4ecb6e6a9bdc66d595c988d399a (patch)
tree0edc4be7cae34b876bc7cc2104c5d49f96b28c8a /Game/Code/Classes/UPlatform.pas
parent9a393bf11f43ba649fa28c17408ea91c43c97a93 (diff)
downloadusdx-329e2b8eabd0f4ecb6e6a9bdc66d595c988d399a.tar.gz
usdx-329e2b8eabd0f4ecb6e6a9bdc66d595c988d399a.tar.xz
usdx-329e2b8eabd0f4ecb6e6a9bdc66d595c988d399a.zip
- UPlatformXYZ.pas clean-up
- TPlatform now implements common behaviour - added TPlatform.Init() git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1207 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UPlatform.pas')
-rw-r--r--Game/Code/Classes/UPlatform.pas100
1 files changed, 70 insertions, 30 deletions
diff --git a/Game/Code/Classes/UPlatform.pas b/Game/Code/Classes/UPlatform.pas
index 2c0fc6ee..f75e5858 100644
--- a/Game/Code/Classes/UPlatform.pas
+++ b/Game/Code/Classes/UPlatform.pas
@@ -16,26 +16,26 @@ interface
uses Classes;
type
- TDirectoryEntry = Record
- Name : WideString;
- IsDirectory : boolean;
- IsFile : boolean;
- end;
-
+ TDirectoryEntry = record
+ Name : WideString;
+ IsDirectory : boolean;
+ IsFile : boolean;
+ end;
+
TDirectoryEntryArray = array of TDirectoryEntry;
-
- IPlatform = interface
- ['{63A5EBC3-3F4D-4F23-8DFB-B5165FCA23DF}']
- function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : boolean) : TDirectoryEntryArray;
- function TerminateIfAlreadyRunning(var WndTitle : string) : boolean;
- function FindSongFile(Dir, Mask: WideString): WideString;
- procedure Halt;
- function GetLogPath : WideString;
- function GetGameSharedPath : WideString;
- function GetGameUserPath : WideString;
+
+ TPlatform = class
+ procedure Init; virtual;
+ function DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: boolean): TDirectoryEntryArray; virtual; abstract;
+ function TerminateIfAlreadyRunning(var WndTitle : string): boolean; virtual;
+ function FindSongFile(Dir, Mask: WideString): WideString; virtual;
+ procedure Halt; virtual;
+ function GetLogPath : WideString; virtual; abstract;
+ function GetGameSharedPath : WideString; virtual; abstract;
+ function GetGameUserPath : WideString; virtual; abstract;
end;
- function Platform : IPlatform;
+ function Platform(): TPlatform;
implementation
@@ -56,25 +56,65 @@ uses
// so that this variable can NOT be overwritten from anywhere else in the application.
// the accessor function platform, emulates all previous calls to work the same way.
var
- Platform_singleton : IPlatform;
+ Platform_singleton : TPlatform;
+
+function Platform : TPlatform;
+begin
+ Result := Platform_singleton;
+end;
+
+(**
+ * Default Init() implementation
+ *)
+procedure TPlatform.Init;
+begin
+end;
-function Platform : IPlatform;
+(**
+ * Default Halt() implementation
+ *)
+procedure TPlatform.Halt;
begin
- result := Platform_singleton;
+ // Note: Application.terminate is NOT the same
+ System.Halt;
+end;
+
+(**
+ * Default TerminateIfAlreadyRunning() implementation
+ *)
+function TPlatform.TerminateIfAlreadyRunning(var WndTitle : string): Boolean;
+begin
+ Result := false;
+end;
+
+(**
+ * Default FindSongFile() implementation
+ *)
+function TPlatform.FindSongFile(Dir, Mask: WideString): WideString;
+var
+ SR: TSearchRec; // for parsing song directory
+begin
+ Result := '';
+ if SysUtils.FindFirst(Dir + Mask, faDirectory, SR) = 0 then
+ begin
+ Result := SR.Name;
+ end;
+ SysUtils.FindClose(SR);
end;
initialization
- {$IFDEF MSWINDOWS}
- Platform_singleton := TPlatformWindows.Create;
- {$ENDIF}
- {$IFDEF LINUX}
- Platform_singleton := TPlatformLinux.Create;
- {$ENDIF}
- {$IFDEF DARWIN}
- Platform_singleton := TPlatformMacOSX.Create;
- {$ENDIF}
+{$IFDEF MSWINDOWS}
+ Platform_singleton := TPlatformWindows.Create;
+{$ENDIF}
+{$IFDEF LINUX}
+ Platform_singleton := TPlatformLinux.Create;
+{$ENDIF}
+{$IFDEF DARWIN}
+ Platform_singleton := TPlatformMacOSX.Create;
+{$ENDIF}
finalization
- Platform_singleton := nil;
+ Platform_singleton.Free;
+
end.