From 329e2b8eabd0f4ecb6e6a9bdc66d595c988d399a Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 17 Jul 2008 16:46:58 +0000 Subject: - 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 --- Game/Code/Classes/UPlatform.pas | 100 ++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 30 deletions(-) (limited to 'Game/Code/Classes/UPlatform.pas') 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. -- cgit v1.2.3