aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Code/Classes')
-rw-r--r--Game/Code/Classes/UCommon.pas24
-rw-r--r--Game/Code/Classes/ULight.pas29
-rw-r--r--Game/Code/Classes/UPlatformLinux.pas101
3 files changed, 83 insertions, 71 deletions
diff --git a/Game/Code/Classes/UCommon.pas b/Game/Code/Classes/UCommon.pas
index 418c0c1a..768abe89 100644
--- a/Game/Code/Classes/UCommon.pas
+++ b/Game/Code/Classes/UCommon.pas
@@ -88,15 +88,26 @@ uses
{$IFDEF Delphi}
Dialogs,
{$ENDIF}
- {$IFDEF LINUX}
- libc,
+ {$IFDEF FPC_VERSION_2_2_2_PLUS}
+ clocale,
{$ENDIF}
UMain,
UConfig;
+
+// data used by the ...Locale() functions
+{$IFDEF LINUX}
var
PrevNumLocale: string;
+{$IFNDEF FPC_VERSION_2_2_2_PLUS}
+const
+ __LC_NUMERIC = 1;
+
+function setlocale(category: integer; locale: pchar): pchar; cdecl; external 'c' name 'setlocale';
+{$ENDIF}
+{$ENDIF}
+
// In Linux and maybe MacOSX some units (like cwstring) call setlocale(LC_ALL, '')
// to set the language/country specific locale (e.g. charset) for this application.
// Unfortunately, LC_NUMERIC is set by this call too.
@@ -116,15 +127,15 @@ var
procedure SetDefaultNumericLocale();
begin
{$ifdef LINUX}
- PrevNumLocale := setlocale(LC_NUMERIC, nil);
- setlocale(LC_NUMERIC, 'C');
+ PrevNumLocale := setlocale(__LC_NUMERIC, nil);
+ setlocale(__LC_NUMERIC, 'C');
{$endif}
end;
procedure RestoreNumericLocale();
begin
{$ifdef LINUX}
- setlocale(LC_NUMERIC, PChar(PrevNumLocale));
+ setlocale(__LC_NUMERIC, PChar(PrevNumLocale));
{$endif}
end;
@@ -258,13 +269,14 @@ function QueryPerformanceCounter(lpPerformanceCount:TLARGEINTEGER):Bool;
end;
begin
- // Use clock_gettime here maybe ... from libc
+ // Use clock_gettime(CLOCK_REALTIME, ...) here (but not from the libc unit)
lpPerformanceCount := RDTSC();
result := true;
end;
function QueryPerformanceFrequency(lpFrequency:TLARGEINTEGER):Bool;
begin
+ // clock_getres(CLOCK_REALTIME, ...)
lpFrequency := 0;
result := true;
end;
diff --git a/Game/Code/Classes/ULight.pas b/Game/Code/Classes/ULight.pas
index f91d614c..a4bebfd2 100644
--- a/Game/Code/Classes/ULight.pas
+++ b/Game/Code/Classes/ULight.pas
@@ -41,42 +41,25 @@ uses
{$IFDEF UseSerialPort}
zlportio,
{$ENDIF}
- {$IFNDEF win32}
- libc,
- {$ENDIF}
UTime;
{$IFDEF FPC}
function GetTime: TDateTime;
- {$IFDEF win32}
var
SystemTime: TSystemTime;
begin
GetLocalTime(SystemTime);
with SystemTime do
-{$IFDEF DARWIN}
+ begin
+ {$IFDEF UNIX}
Result := EncodeTime(Hour, Minute, Second, MilliSecond);
-{$ELSE}
+ {$ELSE}
Result := EncodeTime(wHour, wMinute, wSecond, wMilliSeconds);
-{$ENDIF}
- end;
- {$ELSE}
- Type
- Time_t = longint;
- TTime_T = Time_t;
- var
- T : TTime_T;
- TV: TTimeVal;
- UT: TUnixTime;
- begin
- gettimeofday(TV, nil);
- T := TV.tv_sec;
- localtime_r(@T, @UT);
- Result := EncodeTime(UT.tm_hour, UT.tm_min, UT.tm_sec, TV.tv_usec div 1000);
+ {$ENDIF}
+ end;
end;
- {$ENDIF}
-
+
{$ENDIF}
diff --git a/Game/Code/Classes/UPlatformLinux.pas b/Game/Code/Classes/UPlatformLinux.pas
index 985f9db1..fabca659 100644
--- a/Game/Code/Classes/UPlatformLinux.pas
+++ b/Game/Code/Classes/UPlatformLinux.pas
@@ -8,13 +8,15 @@ interface
{$I switches.inc}
-uses Classes, UPlatform;
+uses
+ Classes,
+ UPlatform;
type
TPlatformLinux = class(TInterfacedObject, IPlatform)
private
- function GetHomedir(): string;
+ function GetHomeDir(): string;
public
function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray;
function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean;
@@ -29,28 +31,23 @@ type
implementation
-// check for version of FPC >= 2.2.0
-{$IFDEF FPC}
- {$IF (FPC_VERSION > 2) or ((FPC_VERSION = 2) and (FPC_RELEASE >= 2))}
- {$DEFINE FPC_VERSION_2_2_0_PLUS}
- {$IFEND}
-{$ENDIF}
-
-uses
- libc,
+uses
UCommandLine,
BaseUnix,
+ {$IFDEF FPC_VERSION_2_2_2_PLUS}
+ pwd,
+ {$ENDIF}
SysUtils,
ULog,
UConfig;
function TPlatformLinux.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray;
var
- i : Integer;
- TheDir : pDir;
- ADirent : pDirent;
- Entry : Longint;
- lAttrib : integer;
+ i : Integer;
+ TheDir : pDir;
+ ADirent : pDirent;
+ Entry : Longint;
+ lAttrib : integer;
begin
i := 0;
Filter := LowerCase(Filter);
@@ -61,7 +58,7 @@ begin
repeat
ADirent := FpReadDir(TheDir^);
- If Assigned(ADirent) and (ADirent^.d_name <> '.') and (ADirent^.d_name <> '..') then
+ if Assigned(ADirent) and (ADirent^.d_name <> '.') and (ADirent^.d_name <> '..') then
begin
lAttrib := FileGetAttr(Dir + ADirent^.d_name);
if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then
@@ -91,14 +88,14 @@ function TPlatformLinux.GetLogPath : WideString;
begin
if FindCmdLineSwitch( cUseLocalPaths ) then
begin
- result := ExtractFilePath(ParamStr(0));
+ Result := ExtractFilePath(ParamStr(0));
end
else
begin
{$IFDEF UseLocalDirs}
- result := ExtractFilePath(ParamStr(0));
+ Result := ExtractFilePath(ParamStr(0));
{$ELSE}
- result := LogPath+'/';
+ Result := LogPath + PathDelim;
{$ENDIF}
end;
@@ -108,43 +105,63 @@ end;
function TPlatformLinux.GetGameSharedPath : WideString;
begin
if FindCmdLineSwitch( cUseLocalPaths ) then
- result := ExtractFilePath(ParamStr(0))
+ Result := ExtractFilePath(ParamStr(0))
else
begin
-{$IFDEF UseLocalDirs}
- result := ExtractFilePath(ParamStr(0));
-{$ELSE}
- result := SharedPath+'/';
-{$ENDIF}
+ {$IFDEF UseLocalDirs}
+ Result := ExtractFilePath(ParamStr(0));
+ {$ELSE}
+ Result := SharedPath + PathDelim;
+ {$ENDIF}
end;
end;
-function TPlatformLinux.GetGameUserPath : WideString;
+function TPlatformLinux.GetGameUserPath: WideString;
begin
if FindCmdLineSwitch( cUseLocalPaths ) then
- result := ExtractFilePath(ParamStr(0))
+ Result := ExtractFilePath(ParamStr(0))
else
begin
-{$IFDEF UseLocalDirs}
- result := ExtractFilePath(ParamStr(0));
-{$ELSE}
- result := get_homedir()+'/.'+PathSuffix+'/';
-{$ENDIF}
+ {$IFDEF UseLocalDirs}
+ Result := ExtractFilePath(ParamStr(0));
+ {$ELSE}
+ Result := GetHomeDir() + '.'+PathSuffix + PathDelim;
+ {$ENDIF}
end;
end;
-function TPlatformLinux.GetHomedir(): string;
+(**
+ * Returns the user's home directory terminated by a path delimiter
+ *)
+function TPlatformLinux.GetHomeDir(): string;
+{$IFDEF FPC_VERSION_2_2_2_PLUS}
var
- pPasswdEntry : Ppasswd;
- lUserName : String;
+ PasswdEntry: PPasswd;
+{$ENDIF}
begin
- pPasswdEntry := getpwuid( getuid() );
- result := pPasswdEntry^.pw_dir;
+ Result := '';
+
+ {$IFDEF FPC_VERSION_2_2_2_PLUS}
+ // try to retrieve the info from passwd
+ PasswdEntry := FpGetpwuid(FpGetuid());
+ if (PasswdEntry <> nil) then
+ Result := PasswdEntry.pw_dir;
+ {$ENDIF}
+ // fallback if passwd does not contain the path
+ if (Result = '') then
+ Result := GetEnvironmentVariable('HOME');
+ // add trailing path delimiter (normally '/')
+ if (Result <> '') then
+ Result := IncludeTrailingPathDelimiter(Result);
+
+ {$IFDEF FPC_VERSION_2_2_2_PLUS}
+ // GetUserDir() is another function that returns a user path.
+ // It uses env-var HOME or a fallback to a temp-dir.
+ //Result := GetUserDir();
+ {$ENDIF}
end;
-// FIXME: just a dirty-fix to make the linux build work again.
-// This i the same as the corresponding function for MacOSX.
-// Maybe this should be TPlatformBase.Halt()
+// FIXME: Maybe this should be TPlatformBase.Halt() for all platforms
procedure TPlatformLinux.Halt;
begin
System.Halt;
@@ -152,7 +169,7 @@ end;
function TPlatformLinux.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean;
begin
- // Linux and Mac don't check for running apps at the moment
+ // Linux does not check for running apps at the moment
Result := false;
end;