Page 13 of 21 FirstFirst ... 31112131415 ... LastLast
Results 121 to 130 of 206

Thread: TANX (Iron Strike)

  1. #121
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    TANX (Iron Strike)

    I don't usually have as much trouble with strings. I usually just treat them like arrays of Chars or as a fixed datachunk. They are just arrays of chars after all, right?

    And when I use an array or a list in my structures, I'll have a Count variable --usually a 4-byte Integer for speed sake-- that reads just before the data.

    So basically, I'll do something like this....
    [pascal]var
    MsgTxtLength: Integer;
    MsgTxt: Array[0 .. 255] of Char;

    ...

    BlockRead(FileStream, MsgTxtLength, SizeOf(MsgTxtLength));
    for i := 0 to MsgTxtLength - 1 do
    BlockRead(FileStream, MsgTxt[i], SizeOf(Char));
    // or BlockRead(FileStream, MsgTxt[i], SizeOf(MsgTxt[i])); should work too!

    ...[/pascal]

    It may seem like a slower way to do things, but to be honest, it's an array you're trying to retrive from file afterall right?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #122

    TANX (Iron Strike)

    Slightly faster:
    [pascal]var
    MsgTxtLength: Integer;
    MsgTxt: Array[0 .. 255] of Char;
    MyString: AnsiString;
    ...

    BlockRead(FileStream, MsgTxtLength, SizeOf(MsgTxtLength));
    BlockRead(FileStream, MsgTxt[0], MsgTxtLength); // Char is size 1 so length works
    // Or into a string
    BlockRead(FileStream, MyString[1], MsgTxtLength);
    ...
    [/pascal]

  3. #123

    TANX (Iron Strike)

    Actually here is real code
    [pascal]
    procedure WriteString(ToStream:TStream; Str : AnsiString);
    var
    i : Integer;
    begin
    i := Length(Str);
    ToStream.WriteBuffer(i, SizeOf(Integer));
    ToStream.WriteBuffer(Str[1], i);
    end;

    function ReadString(FromStream:TStream) : String;
    var
    i : Integer;
    begin
    FromStream.ReadBuffer(i, SizeOf(Integer));
    SetLength(result, i);
    FromStream.ReadBuffer(result[1], i);
    end;
    [/pascal]

  4. #124
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    TANX (Iron Strike)

    Ah... nice use of TStreams.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  5. #125

    TANX (Iron Strike)

    Oh! :idea: I got an idea! I will modify my persistent sysem slightly, making it usable by anybody. It's really not too big a work, compared to the pain of building it!

    TRuly: there are lots of ready *visual* systems (GlScene, DelphiX, etc.), but there is no such thing as a ready persistency system!

    I wish you luck then

  6. #126

    TANX (Iron Strike)

    Actually here is real code
    Bah! Streams are too slow!

    [pascal]procedure RP_AnsiString (PField: pointer; OP: TFieldOperation); typeprocscall;
    begin
    case op of
    fio_Load: AnsiString(PField^):=ReadAnsiString();
    fio_Save: WriteAnsiString(AnsiString(PField^));
    fio_Skip: SkipAnsiString;
    end;
    end;[/pascal]

  7. #127

    TANX (Iron Strike)

    Ok, this is getting off-topic. Let's continue it somewhere else.
    But, anyway, when you have a dozen types or more, having two separate procedures for saving and loading begins to get messy.

  8. #128

    TANX (Iron Strike)

    Hehe, indeed it's getting a little offtopic

    The way I am doing it now is something like this:

    Code:
        // read buildings
        BlockRead(MapFile,ItemCount,sizeof(integer));
        for i := 1 to ItemCount do
        begin
          new(BuildingItem);
          BlockRead(MapFile,BuildingItem^.PosX,sizeof(integer)); // PosX
          BlockRead(MapFile,BuildingItem^.PosY,sizeof(integer)); // PosY
          BlockRead(MapFile,BuildingItem^.Angle,sizeof(integer)); // Angle
          BlockRead(MapFile,BuildingItem^.BuildingType,sizeof(integer)); // type
          BlockRead(MapFile,BuildingItem^.Destroyable,sizeof(boolean)); // Is it destroyable?
          BlockRead(MapFile,Size,SizeOf(Integer));
          SetLength(TmpString,Size);
          BlockRead(MapFile,TmpString[1],Size);
          BuildingItem^.DestroyOn := TmpString; // triggeraction that destroys the building
          BlockRead(MapFile,Size,SizeOf(Integer));
          SetLength(TmpString,Size);
          BlockRead(MapFile,TmpString[1],Size);
          BuildingItem^.OpenOn := TmpString; // For gates only (Triggeraction that opens Gate)
          BlockRead(MapFile,BuildingItem^.Active,sizeof(boolean)); // Is it active (atm radar only)?
          BlockRead(MapFile,Size,SizeOf(Integer));
          SetLength(TmpString,Size);
          BlockRead(MapFile,TmpString[1],Size);
          BuildingItem^.ActivateOn := TmpString; // Triggeraction that activates building (radar only atm)
          // Read Dummy 1
          BlockRead(MapFile,Size,SizeOf(Integer));
          SetLength(TmpString,Size);
          BlockRead(MapFile,TmpString[1],Size);
          BuildingItem^.Dummy1 := TmpString; // For future implementations
          // Read Dummy 2
          BlockRead(MapFile,BuildingItem^.Dummy2,sizeof(integer));// For future implementations
          // Read Dummy 3
          BlockRead(MapFile,BuildingItem^.Dummy3,sizeof(integer));// For future implementations
          // Read Dummy 4
          BlockRead(MapFile,BuildingItem^.Dummy4,sizeof(integer));// For future implementations
          // Read Dummy 5
          BlockRead(MapFile,BuildingItem^.Dummy5,sizeof(boolean));// For future implementations
          BuildingList.Add(BuildingItem);
        end;
    This is the code to read building data from level file. It is nearly exactly the way WILL described, so I think there is no need to change it for IGF now. We can add things to the editor which are unused yet, and I am also able to convert old level data to new level data if there is any need. All other things will cost too much time now.

    Greetings,
    Dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  9. #129

    TANX (Iron Strike)

    All other things will cost too much time now.
    Which is the key here.


    Other than that... I last used BlockWrite in the times of 80486 and MS-DOS. A terribly inflexible approach. The streams are much better: you always can swap TFileStream with TMemoryStream for saving to a memory buffer, or with a custom stream with compression, CRC checking or something else equally useful -- without touching the saving/loading code.

    For a competition entry it's, probably, Ok.
    But for anything else... My own sad experience says that using the "shortcut" ways and simplifying things to quickly get your game working leads to limitations and unnecessary work later, when you try to evolve and finish it. In short - you save today, you get sorry later.

  10. #130

    TANX (Iron Strike)

    The key is that I definately HAVE to save today

    Nearly my whole engine needs a review due to the many additions in level design. There are so much things I have to do. Graphics, Sound, Gameplay, Collisions, Menus, everything needs a final touch.

    And, there are only 3 weeks left until the entry deadline for IGF.

    I have a job, 2 kids, a girlfriend, some other projects which need some spare time. I have no time at the moment to exchange anything within my game until IGF I don't mind changing anything later. But first I need to complete a working entry. Even if it uses a loading procedure which is not perfect. Main task is that it is loading the level and this, it does

    The way my engine loads data is one of the most "unimportant" things right now, because it works as it is implemented right now. My main task is to let the engine process all this data as it was intended...

    Greetings,
    Dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

Page 13 of 21 FirstFirst ... 31112131415 ... 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
  •