Recent

Author Topic: [SOLVED] Game speed and fps  (Read 24900 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Game speed and fps
« Reply #45 on: September 15, 2016, 02:14:36 am »
@Manu12x
Just an observation:

function declaration:
Code: [Select]
procedure SDL_WriteButton(Rect: PSDL_Rect; Clip: PSDL_Rect;ClipOnClick: PSDL_Rect; State: boolean; Purpose : boolean );

call method:
Code: [Select]
...
SDL_WriteButton(Button^.Play.Rect, Button^.Play.Clip, Button^.Play.OnClick.Clip, Button^.Play.OnClick.State, Play);
SDL_WriteButton(Button^.Options.Rect, Button^.Options.Clip,Button^.Options.OnClick.Clip, Button^.Options.OnClick.State, Options);
...

Since all buttons are of the same type, would it not be more efficient to:

Type declaration:
Code: [Select]
Type
  TMyMarvelousButton = record
    Rect: PSDL_Rect;
    Clip : PSDL_Rect;
    OnClick : record
      State : boolean;
      Clip : PSDL_Rect;
    end;
  end;

Buttons = record
  Texture : PSDL_Texture;
  Info, Play, Menu, Retry, Icons, Options, Quit, Back : TMyMarvelousButton;
  CheckBox : array[1..10] of record
  .... rest of your type definition(s)

function declaration:
Code: [Select]
procedure SDL_WriteButton(var SomeButton: TMyMarvelousButton; Purpose : boolean );
begin
  if Event^.type_ = SDL_MouseButtonDown then
      if SDL_MouseHover(Event, SomeButton.Button.Rect) then
        SomeButton.State := True
      else
        SomeButton.State := False;

    if SomeButton.State then
      SDL_RenderCopy(GameRenderer, Buttons^.Texture, SomeButton.OnClick.Click, SomeButton.Rect)
    else
      SDL_RenderCopy(GameRenderer, Buttons^.Texture, SomeButton.Clip, SomeButton.Rect);

    if Event^.type_ = SDL_MouseButtonUp then
      if SDL_MouseHover(Event, SomeButton.Rect) then
      begin
        SomeButton.State := False;
        Done := True;
        Purpose := True;
      end
      else
        SomeButton.State := False;
  end;   
end;

Do note however that in above code i made some assumptions, based on your 'faulty' code and so still contain some errors. Please use it as a small hint only, not as a literal copy (it will fail if you do so)

And call it with:
Code: [Select]
...
SDL_WriteButton(Buttons^.Play, Play);
SDL_WriteButton(Buttons^.Options, Options);
...

Is that code not much easier to read and maintain ? ;)


With regards to your remark "I don't know why it doesn't works":

Code: [Select]
...
if SDL_MouseHover(Event, Rect) then
        State := True
      else
        State := False;
...

Are you expecting that the state value inside your provided button record is changed ? If so, then declare state as being a var parameter

The same applies to your purpose parameter as you do:
Code: [Select]
  ...
  Purpose := True;
  ...

As already said by lainz,: it is very difficult to analyze code that is faulty without being able to compile something.

The only reason i was able to make my suggestion in the beginning of my post is because i actually took the time to analyze some of your original code of the complete game that you provided with your archive a while ago. You have changed some things since then so, even i am not sure if what i wrote still applies.

Only because i did what i did, i was able to spot some of the errors in the code you posted above. With posting non-compilable code, you almost leave no other choice.

The dumb thing is that you could have checked your outcomes yourself by simply writing out all the different fields of your button-record before and after calling SDL_WriteButton and check if they match up to your expectations. You now ask someone else to do that for you, but they would have to invent the rest of the code in order to be able to do so -> the chance that code being 100% exactly the same as what you have in front of you is .... /me sticks finger in air.... zero percent.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Game speed and fps
« Reply #46 on: September 15, 2016, 07:31:21 am »
If we can't test the code is really hard to help you.
I'll fix the code myself, thanks
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

 

TinyPortal © 2005-2018