See this post for the latest usage details:
http://www.pascalgamedevelopment.com...ll=1#post43270
Hi all,
I have made a program that someone may find useful.
As I am using freepascal, I was wanting to do similar things as the borland command line resource compiler program that processes resource script files (.rc) and creates windows resource files (.res) that can be compiled into your programs, but in a cross-platform way.
For example I can take a resource script file like so:
SpritesResource.rc
this is in the format of:Code:Background BITMAP "data\background.bmp" mario BITMAP "data\sprites_mario.bmp"
resource_name resource_type resource_filename (absolute or relative to the resource script file as in this example)
Resource_name has to be a valid pascal identifier.
Resource_type can be anything but shouldn't contain spaces. May be a validator or similar in the future.
Resource_file only needs "" around it if it has spaces in the path or name.
Pass it into my files2pas.exe program as the first parameter like this:
It will then spit out a .pas file for every resource from the script file like so containing the file in hex digit format as a large Const declaration:Code:files2pas c:\myprograms\SpritesResource.rc
Code:Unit mario_Resource; // Created by files2pas.exe // on 16-Mar-2007, 03:26:46p {$IFDEF FPC} {$Mode Delphi} {$ENDIF} Interface Const cmario_type = 'BITMAP'; cmario_data: Array[0..120054 - 1] of Byte = ( $42,$4D,$F6,$D4,$01,$00,$00,$00,$00,$00,$36,$00,$00,$00,$28,$00,$00,$00,$C8,$00,$00,$00,$C8,$00,$00, $00,$01,$00,$18,$00,$00,$00,$00,$00,$C0,$D4,$01,$00,$C4,$0E,$00,$00,$C4,$0E,$00,$00,$00,$00,$00,$00, $00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, <SNIP> $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, $FF,$FF,$FF,$FF ); Implementation End.
It will also spit out a .pas file with the same name as the resource script file that allows you to get the pointer to each resource data + the size + type using a function:
Code:Unit SpritesResource; // Created by files2pas.exe // on 16-Mar-2007, 03:26:43p {$IFDEF FPC} {$Mode Delphi} {$H+} {$ENDIF} Interface Function GetResourceByName(AResourceName: AnsiString; Var AData: Pointer; Var ASize: LongInt; Var AType: AnsiString): Boolean; Implementation Uses SysUtils, Background_Resource, mario_Resource; Function GetResourceByName(AResourceName: AnsiString; Var AData: Pointer; Var ASize: LongInt; Var AType: AnsiString): Boolean; Begin Result := False; AResourceName := UpperCase(AResourceName); If AResourceName = 'BACKGROUND' Then Begin AData := @cBackground_data[0]; ASize := SizeOf(cBackground_data); AType := cBackground_type; Result := True; End Else If AResourceName = 'MARIO' Then Begin AData := @cmario_data[0]; ASize := SizeOf(cmario_data); AType := cmario_type; Result := True; End; End; End.
So all you have to do is include the .pas file that has the information in it for retrieving the resource data info (SpritesResource.pas in this case) and use it.
Viola! now all your nice data files can be compiled into the executable file and not 'float' around for everyone to see.
It also makes it easy as you only have to distribute 1 file
EDIT:14-Sep-2012 - I have uploaded it to my dropbox folder now (includes source code):
https://dl.dropbox.com/u/1805932/files2pas.7z
cheers,
Paul.
Bookmarks