Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: First try at OOP oriented OpenGL

  1. #11

    First try at OOP oriented OpenGL

    Has anyone done any benchmarks to see if this slightly changed version of the previous code is slightly faster, due to caching the result of the count-1 call?

    [pascal]
    function TTextureSystem.FindItem(TexID: string): TTextureItem;
    var
    i : integer;
    lCount : integerl
    begin
    lCount := count - 1;
    for i := 0 to lCount do
    if Items[i].TexId = TexID then
    begin
    result := Items[i];
    break;
    end;
    end;
    [/pascal]
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  2. #12

    First try at OOP oriented OpenGL

    Doesn't this give you a warning? result may be undefined if you pass a string that you don't have.
    If so then you (the programmer) has a problem and not the unit.

    I'll benchmark the 2 functions a bit later ... I'm preocuppied at the moment.

  3. #13
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    First try at OOP oriented OpenGL

    savage - I dont think that makes a difference. In Delphi the final value of the loop cannot be changed after the loop has started:

    [pascal]
    procedure TForm1.Button2Click(Sender: TObject);
    Var
    I : Integer;
    C : Integer;
    begin
    C := 100;
    For I := 1 to C do
    Begin
    C := C + 1;
    End;
    Button2.Caption := IntToStr(C);
    end;
    [/pascal]

    Gives a final value of?
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #14

    First try at OOP oriented OpenGL

    Quote Originally Posted by Robert Kosek
    Doesn't this give you a warning? result may be undefined if you pass a string that you don't have.
    If so then you (the programmer) has a problem and not the unit.
    :shock:

    Can I disagree completely with that ?
    How do you test if the returned object is valid ? In such case you should return nil if you don't find the item.
    btw the corrected method is very simple:

    [pascal]
    function TTextureSystem.FindItem(TexID: string): TTextureItem;
    var i: integer;
    begin
    for i := 0 to count-1 do
    if Items[i].TexId = TexID then begin
    result := Items[i];
    exit;
    end;
    result:=nil;
    end;
    [/pascal]

    Edited: damned Java
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  5. #15

    First try at OOP oriented OpenGL

    Quote Originally Posted by savage
    Has anyone done any benchmarks to see if this slightly changed version of the previous code is slightly faster, due to caching the result of the count-1 call?
    I think it calculates the upper limit of the for cycle only once.
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

Page 2 of 2 FirstFirst 12

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
  •