Recent

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

Handoko

  • Hero Member
  • *****
  • Posts: 5549
  • My goal: build my own game engine using Lazarus
Re: Game speed and fps
« Reply #30 on: September 12, 2016, 06:52:39 pm »
I found a good explanation about game loop and how to use delta time in SDl:
http://www.brandonfoltz.com/downloads/tutorials/The_Game_Loop_and_Frame_Rate_Management.pdf

Interestingly to know, someone said it is bad to use delta time:
http://www.learn-cocos2d.com/2013/10/game-engine-multiply-delta-time-or-not/

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #31 on: September 12, 2016, 07:07:13 pm »
No matter what you do: Games requires more or less hardware. I can't run the newest need for speed in my PC lacking of a proper video card, even if they use or not the delta time or any technique, it will not run on my PC.

Manu needs to ensure that the game at least works fine on their PC and then that don't run too fast on better PC's.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Game speed and fps
« Reply #32 on: September 12, 2016, 07:29:20 pm »
No matter what you do: Games requires more or less hardware. I can't run the newest need for speed in my PC lacking of a proper video card, even if they use or not the delta time or any technique, it will not run on my PC.

Manu needs to ensure that the game at least works fine on their PC and then that don't run too fast on better PC's.
I already fixed that with no diifficulty.. Yes, i know about game loop but i will fix that order next time .
Update information:
  -Game Speed and fps fixed
  -Resouces Scale = -20%
  -Added Clouds
  -Added Birds
  -Ufo can shot lasers
  -Nightmode
  -More options ( now only Music )
  -and myve much more..
This evening i will upload it
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #33 on: September 12, 2016, 07:31:20 pm »
Very well, you go fast  :)

Handoko

  • Hero Member
  • *****
  • Posts: 5549
  • My goal: build my own game engine using Lazarus
Re: Game speed and fps
« Reply #34 on: September 12, 2016, 07:47:32 pm »
Manu needs to ensure that the game at least works fine on their PC and then that don't run too fast on better PC's.

It should be no problem, even runs on Pentium 4 computers. It doesn't use heavy 3D objects, multiple lamps, shadow calculations nor shader. I'm sure about it, because I'm a computer technician, I handle lots of computer ranging from Pentium 1 to Core I7. Pentium 4 can run most 2D games without problem and some simple 3D games.

If the game run too slow, there should be something wrong in the code. Or perhaps his computer is a Pentium 4 or older?  :o Very not likely. I ever saw his code for collision checking, that was very not efficient.

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #35 on: September 12, 2016, 07:49:22 pm »
Yes he says that fixed it so it's ok!

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Game speed and fps
« Reply #36 on: September 13, 2016, 09:17:59 am »
Works.. A bit .  but thanks.
No, it works *period*

You don't believe me ? Then make a small test example doing exactly as showed and you'll be able to see for yourself.

Just a friendly warning: Never ever directly implement a solution that is given to you if you do not know what you are doing. Instead, make a small test project that allows you to explore the given solution so that you are able to understand. If you have a couple of hundreds or even thousands lines of code then doing such things might be perfectly ok but, you are screwing yourself in case your code is running into tens of thousands lines of code and you do not have a clue anymore what you changed to implement such a provided solution made by someone else.

Of course, a proper version control would be able to help with that but, i have the vague notion you do not use that atm.

Quote
In game, it now tells 90 frames per second.. And after  5 seconds of playing, frames per second are 125.
That is because you are using multiple render-loops inside your code. For every render-loop you would have to calculate the ticks and apply as i wrote.

However, the solution as presented will only slow down on faster machines. It will do nothing for you in case your rendering loops take longer then those 16 ticks. In that case it will simply ignore and will not call the delay.

It is not very accurate which is why i named it a poor man's solution. If you want more precision then use high precision timers.

Furthermore, if you 'take over' your render-loop with a inner loop and bound things to that inner-loop then the calculation will also fail to do its job properly. You would have to account for that manually.

But, it does not matter if all you care for is to prevent the actual game-play to 'over speed' on faster machines. Simply apply the calculation to that render-loop only.

You also asked about vsync. That is not the holy grail. Note that different monitors, GPU's and video modes all have their own (different) refresh rates. You cannot assume anything about them, let alone sync your game with it as the speed differences will still be present if you rely on SDL's vsync option only.

What vsync option is very good for, is to prevent tearing.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1225
    • Burdjia
Re: Game speed and fps
« Reply #37 on: September 13, 2016, 10:29:46 am »
If you're really interested in games you must join in Pascal Game Developers forum.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Handoko

  • Hero Member
  • *****
  • Posts: 5549
  • My goal: build my own game engine using Lazarus
Re: Game speed and fps
« Reply #38 on: September 13, 2016, 10:41:55 am »
If you're really interested in games you must join in Pascal Game Developers forum.

Yes, I agree. I haven't joined in, but I visit it often.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Game speed and fps
« Reply #39 on: September 14, 2016, 09:50:19 pm »
I'm optimizing my source code game a lot thanks to lazarus! Update will take a long
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #40 on: September 14, 2016, 10:05:41 pm »
I'm optimizing my source code game a lot thanks to lazarus! Update will take a long

One of my fav things is the automatic code formatting.

Source > JEDI Code Format > Current Editor Window (Ctrl+D).

And the shortcuts in code: Ctrl + Shift + C, read it on the wiki, there are a lot of shortcuts!

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Game speed and fps
« Reply #41 on: September 14, 2016, 10:33:56 pm »
I'm optimizing my source code game a lot thanks to lazarus! Update will take a long

One of my fav things is the automatic code formatting.

Source > JEDI Code Format > Current Editor Window (Ctrl+D).

And the shortcuts in code: Ctrl + Shift + C, read it on the wiki, there are a lot of shortcuts!
I tried JEDI code format.. That's cool! Thanks! Ctrl+shift+c is..?
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #42 on: September 14, 2016, 10:39:39 pm »
Ctrl + Shift + C

for example write:

procedure DoSomething;

with the cursor over the procedure press Ctrl + Shift + C and it will create the body of the procedure.

This command has other uses

for example

procedure DoSomething;
begin
  i := 10; // press ctrl + shift + c over the "i" and it will automatically add the 'var i: integer' to the procedure.
end;

for Classes it creates the methods and automatically creates properties variables and methods (but you learn first Object Oriented Programming and you will use them a lot).

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Game speed and fps
« Reply #43 on: September 14, 2016, 11:36:07 pm »
There's something bad with this:
Code: Pascal  [Select][+][-]
  1.  
  2. procedure SDL_WriteButton(Rect: PSDL_Rect; Clip: PSDL_Rect;
  3. ClipOnClick: PSDL_Rect; State: boolean; Purpose : boolean );
  4.   begin
  5.     if Event^.type_ = SDL_MouseButtonDown then
  6.       if SDL_MouseHover(Event, Rect) then
  7.         State := True
  8.       else
  9.         State := False;
  10.  
  11.     if State then
  12.       SDL_RenderCopy(GameRenderer, Button^.Texture, ClipOnClick, Rect)
  13.     else
  14.       SDL_RenderCopy(GameRenderer, Button^.Texture, Clip, Rect);
  15.  
  16.     if Event^.type_ = SDL_MouseButtonUp then
  17.       if SDL_MouseHover(Event, Rect) then
  18.       begin
  19.         State := False;
  20.         Done := True;
  21.         Purpose := True;
  22.       end
  23.       else
  24.         State := False;
  25.   end;                        
  26.  
  27.  begin
  28.     if Menu then
  29.       repeat
  30.         SDL_RenderClear(GameRenderer);
  31.         SDL_RenderCopy(GameRenderer, bg, nil, nil);
  32.         SDL_RenderCopy(GameRenderer, Deco^.Title.Texture, nil, Deco^.Title.Rect);
  33.         while SDL_PollEvent(Event) = 1 do
  34.         begin
  35.         end;
  36.         SDL_WriteButton(Button^.Play.Rect, Button^.Play.Clip,
  37.           Button^.Play.OnClick.Clip, Button^.Play.OnClick.State, Play);
  38.         SDL_WriteButton(Button^.Options.Rect, Button^.Options.Clip,
  39.           Button^.Options.OnClick.Clip, Button^.Options.OnClick.State, Options);
  40.         SDL_WriteButton(Button^.Icons.Rect, Button^.Icons.Clip,
  41.           Button^.Icons.OnClick.Clip, Button^.Icons.OnClick.State, Icons);
  42.         SDL_WriteButton(Button^.Info.Rect, Button^.Info.Clip,
  43.           Button^.Info.OnClick.Clip, Button^.Info.OnClick.State, Info);
  44.         SDL_WriteButton(Button^.Quit.Rect, Button^.Quit.Clip,
  45.           Button^.Quit.OnClick.Clip, Button^.Quit.OnClick.State, Quit);
  46.         SDL_RenderPresent(GameRenderer);
  47.       until Done;
  48.     Done := False;
  49.     Menu := False;
  50.   end;            
  51.  
  52.  
SDL_WriteButton writes a button with all rect parameters required, State ( if the button is clicked or not ) and Purpose ( when player click a button, the game should change scene.. "Menu" ( Boolean ) is a scene.. )
I don't know why it doesn't works.. i click on a button.. after leaving, Menu Scene is already on and After some seconds game halts. Possible help.?
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Game speed and fps
« Reply #44 on: September 15, 2016, 01:23:52 am »
If we can't test the code is really hard to help you.

 

TinyPortal © 2005-2018