aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UTexture.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-07 08:50:43 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-07 08:50:43 +0000
commitc316180c74e144a5faecfe30ab38c8e4e0ef9e91 (patch)
treec3c917ece6b85f6284e474b28e64680a3cc20836 /Game/Code/Classes/UTexture.pas
parentb007aad2fa55bb72b69ecfb56ba6207d31eff684 (diff)
downloadusdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.tar.gz
usdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.tar.xz
usdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.zip
- Removed lrs resource usage in linux. Resources are copied to /usr/share/resources now.
- Unified resource handling: call GetResourceStream (UCommon) to retrieve a resource. - Removed the lazarus dependency in the Makefile (it will also use the main .dpr-file now) - Now that the lazarus dependency is gone, the MacOSX and Linux version might use a shared codebase. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1013 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UTexture.pas')
-rw-r--r--Game/Code/Classes/UTexture.pas161
1 files changed, 43 insertions, 118 deletions
diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas
index 712c54bf..3fac0524 100644
--- a/Game/Code/Classes/UTexture.pas
+++ b/Game/Code/Classes/UTexture.pas
@@ -131,12 +131,6 @@ implementation
uses ULog,
DateUtils,
UThemes,
- {$ifdef LINUX}
- fileutil,
- {$endif}
- {$IFDEF LCL}
- LResources,
- {$ENDIF}
{$IFDEF DARWIN}
MacResources,
{$ENDIF}
@@ -186,6 +180,7 @@ end;
end;
Result := stream.Seek( offset, origin );
end;
+
function SdlStreamRead( context : PSDL_RWops; Ptr : Pointer; size : Integer; maxnum: Integer ) : Integer; cdecl;
var
stream : TStream;
@@ -199,6 +194,7 @@ end;
Result := -1;
end;
end;
+
function SDLStreamClose( context : PSDL_RWops ) : Integer; cdecl;
var
stream : TStream;
@@ -212,36 +208,10 @@ end;
// -----------------------------------------------
function TTextureUnit.LoadImage(const Identifier: string): PSDL_Surface;
-
- function FileExistsInsensative( var aFileName : PChar ): boolean;
- begin
-{$IFDEF LINUX} // eddie: Changed FPC to LINUX: Windows and Mac OS X dont have case sensitive file systems
- result := true;
-
- if FileExists( aFileName ) then
- exit;
-
- aFileName := pchar( FindDiskFileCaseInsensitive( aFileName ) );
- result := FileExists( aFileName );
-{$ELSE}
- result := FileExists( aFileName );
-{$ENDIF}
- end;
-
var
-
TexRWops: PSDL_RWops;
- dHandle: THandle;
-
- {$IFDEF LCL}
- lLazRes : TLResource;
- lResData : TStringStream;
- {$ELSE}
TexStream: TStream;
- {$ENDIF}
-
- lFileName : pchar;
-
+ FileName: string;
begin
Result := nil;
TexRWops := nil;
@@ -249,100 +219,61 @@ begin
if Identifier = '' then
exit;
- lFileName := PChar(Identifier);
-
-// Log.LogStatus( Identifier, 'LoadImage' );
+ //Log.LogStatus( Identifier, 'LoadImage' );
-// Log.LogStatus( 'Looking for File ( Loading : '+Identifier+' - '+ FindDiskFileCaseInsensitive(Identifier) +')', ' LoadImage' );
+ FileName := Identifier;
- if ( FileExistsInsensative(lFileName) ) then
+ if (FileExistsInsensitive(FileName)) then
begin
// load from file
- Log.LogStatus( 'Is File ( Loading : '+lFileName+')', ' LoadImage' );
+ //Log.LogStatus( 'Is File ( Loading : '+FileName+')', ' LoadImage' );
try
- Result:=IMG_Load(lFileName);
- Log.LogStatus( ' '+inttostr( integer( Result ) ), ' LoadImage' );
+ Result := IMG_Load(PChar(FileName));
+ //Log.LogStatus( ' '+inttostr( integer( Result ) ), ' LoadImage' );
except
- Log.LogStatus( 'ERROR Could not load from file' , Identifier);
+ Log.LogError('Could not load from file "'+FileName+'"', 'TTextureUnit.LoadImage');
Exit;
end;
end
else
begin
- Log.LogStatus( 'IS Resource, because file does not exist.('+Identifier+')', ' LoadImage' );
+ //Log.LogStatus( 'IS Resource, because file does not exist.('+Identifier+')', ' LoadImage' );
- // load from resource stream
- {$IFDEF LCL}
- lLazRes := LazFindResource( Identifier, 'TEX' );
- if lLazRes <> nil then
- begin
- lResData := TStringStream.create( lLazRes.value );
- try
- lResData.position := 0;
- try
- TexRWops := SDL_AllocRW;
- TexRWops.unknown := TUnknown( lResData );
- TexRWops.seek := SDLStreamSeek;
- TexRWops.read := SDLStreamRead;
- TexRWops.write := nil;
- TexRWops.close := SDLStreamClose;
- TexRWops.type_ := 2;
- except
- Log.LogStatus( 'ERROR Could not assign resource ('+Identifier+')' , Identifier);
- Exit;
- end;
-
- Result := IMG_Load_RW(TexRWops,0);
- SDL_FreeRW(TexRWops);
- finally
- freeandnil( lResData );
- end;
- end
- else
- begin
- Log.LogStatus( 'NOT found in Resource ('+Identifier+')', ' LoadImage' );
- end;
- {$ELSE}
- dHandle := FindResource(hInstance, PChar(Identifier), 'TEX');
- if dHandle=0 then
- begin
- Log.LogStatus( 'ERROR Could not find resource' , ' '+ Identifier);
- Exit;
- end;
+ TexStream := GetResourceStream(Identifier, 'TEX');
+ if (not assigned(TexStream)) then
+ begin
+ Log.LogError( 'Invalid file or resource "'+ Identifier+'"', 'TTextureUnit.LoadImage');
+ Exit;
+ end;
+ TexRWops := SDL_AllocRW();
+ if (TexRWops = nil) then
+ begin
+ Log.LogError( 'Could not assign resource "'+Identifier+'"', 'TTextureUnit.LoadImage');
+ TexStream.Free();
+ Exit;
+ end;
- TexStream := nil;
- try
- TexStream := TResourceStream.Create(HInstance, Identifier, 'TEX');
- except
- Log.LogStatus( 'ERROR Could not load from resource' , Identifier);
- Exit;
- end;
+ // user defined RW-callbacks
+ with TexRWops^ do
+ begin
+ unknown := TUnknown(TexStream);
+ seek := SDLStreamSeek;
+ read := SDLStreamRead;
+ write := nil;
+ close := SDLStreamClose;
+ type_ := 2;
+ end;
- try
- TexStream.position := 0;
- try
- TexRWops := SDL_AllocRW;
- TexRWops.unknown := TUnknown(TexStream);
- TexRWops.seek := SDLStreamSeek;
- TexRWops.read := SDLStreamRead;
- TexRWops.write := nil;
- TexRWops.close := SDLStreamClose;
- TexRWops.type_ := 2;
- except
- Log.LogStatus( 'ERROR Could not assign resource' , Identifier);
- Exit;
- end;
-
- Log.LogStatus( 'resource Assigned....' , Identifier);
- Result:=IMG_Load_RW(TexRWops,0);
- SDL_FreeRW(TexRWops);
-
- finally
- if assigned( TexStream ) then
- freeandnil( TexStream );
- end;
- {$ENDIF}
+ //Log.LogStatus( 'resource Assigned....' , Identifier);
+ try
+ Result := IMG_Load_RW(TexRWops, 0);
+ except
+ Log.LogError( 'Could not read resource "'+Identifier+'"', 'TTextureUnit.LoadImage');
+ end;
+
+ SDL_FreeRW(TexRWops);
+ TexStream.Free();
end;
end;
@@ -1019,10 +950,4 @@ begin
Result := TEXTURE_TYPE_PLAIN;
end;
-{$IFDEF LCL}
-initialization
- {$I UltraStar.lrs}
-{$ENDIF}
-
-
end.