Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: files2pas data 'resource' creator

  1. #1

    files2pas data 'resource' creator

    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

    Code:
    Background BITMAP "data\background.bmp"
    mario BITMAP "data\sprites_mario.bmp"
    this is in the format of:

    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:

    Code:
    files2pas c:\myprograms\SpritesResource.rc
    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:
    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.
    Last edited by paul_nicholls; 14-09-2012 at 12:25 AM.

  2. #2

    files2pas data 'resource' creator

    Hi everyone,
    I'm curious as to what people think of this tool, as no-one at all has replied to this thread!!

    cheers,
    Paul

  3. #3

    files2pas data 'resource' creator

    Hi Paul

    Well done . Very nice work, I did something similar to embed images into my game engine (the engine logo) but I'm sure people will find this useful (I certainly will).

    You could make the system a bit more dynamic by having each resource unit register it's resource with a central manager, that way the GetResourcebyName would just do a lookup in an array or string list rather than hard coding the resource names (if you have allot of resources that procedure would get very big).

    Good work
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  4. #4

    files2pas data 'resource' creator

    {$R mario.bmp}
    FindResource
    LoadResource?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5

    files2pas data 'resource' creator

    usefull when you need to hide a resource
    From brazil (:

    Pascal pownz!

  6. #6

    files2pas data 'resource' creator

    Quote Originally Posted by JSoftware
    {$R mario.bmp}
    FindResource
    LoadResource?
    This utility is a cross-platform tool for 'resources' so I am not dependent on Windows routines, and I already know it works on arm-linux (GP2X) as well as Windows without modifications :-)

    Besides this, I have more control over how it does things, and may even add compression to the resources when the resource pas files are generated to save on space.

    cheers,
    Paul

  7. #7

    files2pas data 'resource' creator

    Quote Originally Posted by technomage
    Hi Paul

    Well done . Very nice work, I did something similar to embed images into my game engine (the engine logo) but I'm sure people will find this useful (I certainly will).

    You could make the system a bit more dynamic by having each resource unit register it's resource with a central manager, that way the GetResourcebyName would just do a lookup in an array or string list rather than hard coding the resource names (if you have allot of resources that procedure would get very big).

    Good work
    Thanks :-)

    I will look at changing the way it looks up the resources by name as you suggested.

    I am also upgrading it slightly to be even more handy, like being able to get a count of the number of resources, and get the resources by index too :-)

    Also, resource names won't have to be a valid pascal identifier in the end either

    cheers,
    Paul

  8. #8

    files2pas data 'resource' creator

    I really like it, is a good way to embed resources.
    I use a component to put resources into dfm (delphi), but i notice that large resources waste time, and lead to "stream read errors"
    You tool is clean, and fast... create the .pas file to hold and retrieve the resource...
    Is a inspiration for me... really... i think that i'll building something related to delphi...

  9. #9

  10. #10

    files2pas data 'resource' creator

    I'm glad to be a help to you :-)
    cheers,
    Paul

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •