12 Replies - 3175 Views - Last Post: 27 September 2017 - 12:30 AM Rate Topic: -----

#1 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 12:54 PM

Hello. First of all know that I am amateur in the world of game development, however experienced web developer. We have to look at example in order to understand my question and oppression:
A lot of logic executes, this "a lot of logic" always takes 5 seconds (lets say deliberately so slow). Than the code runs this logic: In the game scene there is one gun (always) and it is firing automatically one bullet once a second (the first bullet will get fired immediately). The bullet hits wall always in one second from the time of fire, when hits the wall it disappears, the wall losses 1 strength.

For the simplicity of the example we imagined a lot of logic is running at constant time of 5 seconds and in reality it will not be surely constant and eventually much less in time. Back to the example. Each five second I will be running the logic "hey gun, fire one bullet please. Bullet gets created, moves toward wall, collisions with the wall, wall's strength decreases by 1 and the bullet gets destroyed/removed".

If I code this literally than with this speed of the game loop the first time this logic runs it will have to create 5 bullets at the same time, they will be calculated that all they reached the wall and so 5 time the wall will get call to "decreaseStrenth()". But how this exactly happens? If I call update(5.0f) on all the bullets it will be wrong, right? Because only the first bullet is created before 5 seconds, but the next are all created by 1 second earlier than the previous. If this is right than this means that I have to care about calculating the elapsed time in some hacky way because I have to count how many bullets may be fired in the elapsed time, create the instances and update them with locally calculated value for the elapsed time for each of them specifically!? And at the end I still am not sure if this is the way. If I imagine other entities in logical relation with the weapon, the bullets, or the wall than it start getting really confusing. I have to create 5 bullets at once this is crazy because if the speed was faster than the algorithm never will need to create five bullets before executing the rest of the game loop before each other bullet.

It is still different logic. In high FPS we have:
1) bullet-wall, rest game logic (if we imagine we have such) 2) bullet-wall, rest game logic 3,4,5)etc...

and If we are in low FPS we have:
1) bullet-wall, bullet-wall,bullet-wall,etc.. 2) rest game logic. So this algorithm is compensating what happened in the past, at the present NOW moment. But it is unnatural to happens in this way, isn't it?

I call it hacky because of this and because it seems "a hidden logic" for me. The method is fireABullet() but it have to care about the elapsed time and create more than one bullets in this example. I hardly will assume this happens in the first place if I do not know this kind of problem exist in game development and I am curious if there is way to design/see logic to make it impossible to miss such cases. This example is so simple compared to dynamic, customizable game with a lot of logically iterating entities/objects in time and this make me question how experienced developers manage this issue? Maybe I have to imagine what happens with "big" and "small" update interval with each update(float time) method in my source? But I feel like I will get in "designing/coding hell" very fast with each new entity introduced in eventual game I start to code because I am willing testing it in low-FPS mode in order to prove the algorithms networking-ready.

Is This A Good Question/Topic? 0
  • +

Replies To: How to design logics/architecture related to time elapsed?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 01:02 PM

Quote

If I code this literally than with this speed of the game loop the first time this logic runs it will have to create 5 bullets at the same time,

Huh?
Was This Post Helpful? 0
  • +
  • -

#3 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 01:52 PM

View Postmodi123_1, on 25 September 2017 - 01:02 PM, said:

Quote

If I code this literally than with this speed of the game loop the first time this logic runs it will have to create 5 bullets at the same time,

Huh?

I mean that because 5 seconds are elapsed than I have to create 5 bullets to simulate them in the past. This is the technique which I know as solution for the problem. Basically the issues in my head are all related with big update intervals and how to handle them.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 01:58 PM

Okay.. then I am not certain if I understand your issue. If the update is happening at X time then why would you have five bullets from the past to go?

One update to update all objects.
Was This Post Helpful? 0
  • +
  • -

#5 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 02:22 PM

The time that passed in other algorithm is 5 seconds. The update method of the weapon gets elapsed time X = 5. And we wanted the weapon to fire automatically each one second. Because it is told update only once in the last 5 seconds(roughly) it has to actualize the game entities which are in direct and indirect relation in some way as if it was called 5 times in the past as it was going to happen if 5 seconds was not lost in the imagined "time expensive algorithm".

The more I think about this the more I am getting confused of how to handle this, it seems extremely hard to achieve on general purpose level.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 02:35 PM

Who is 'we'?

Typically a video game is measured in 'frames per second'.. and frames are typically generated by an update.. so the average 30 FPS means there's at least thirty update method hits.

From this basic video game tutorial..

Posted Image
http://www.dreaminco...-basics-part-1/
Was This Post Helpful? 0
  • +
  • -

#7 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 02:50 PM

'We' is you and me looking at my example :)

I see your point but this is not typical problem as far as I am aware. This seems a problem occurring in rare conditions. I actually want to find universally stable design/pattern for updating entities, this is why I have to find general solution for this example I give. How to code in order to handle easier and properly events which happened in the past. Maybe the problem can be reproduced in a lot of games if the thread (supposing is only one) is forced to wait for seconds in the game loop. Each game update mechanism I have read about works but it assumes that the update interval is small so it catch state changes at the right moment. When big update interval comes the algorithms get out of logic.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 25 September 2017 - 02:56 PM

Maybe that's the issue.. there is no "past event". There is just the event happening now and the current state of everything.
Was This Post Helpful? 0
  • +
  • -

#9 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 26 September 2017 - 06:47 AM

If the speed of the game loop is 5 seconds than you will have past. A lot of the game actions happens in much less time than 0.5 seconds.
Am I wrong about this?

Later I will send one "game" which has bug related to the elapsed time to give a visual representation of the issue I am explaining.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 26 September 2017 - 06:54 AM

Why would a game loop tick be five seconds? I am not even certain my QBASIC games were that long.

Sounds like you are dealing with a hypothetical that doesn't exist... or at best - shouldn't exist using normal game engine development.
Was This Post Helpful? 0
  • +
  • -

#11 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 26 September 2017 - 11:09 AM

Hey. I am attaching the game I mentioned earlier. When the game is started it will start spawning entities which move towards predefined points. This is coded using SFML and SFGUI. Once I started dragging the window (the game starts in 800x600 window) and released it I saw that the entities were all over one point. When I checked the code I realized this happens because of big update interval.

Rationally I guessed that the solution is to stop the game clock on drag and resume it on drag release. This was before maybe two years. I asked in the SFML IRC channel and they replied that this can't be done using ANY library because windows does not provide that information or something like that. Than I asked same thing in the SFGUI IRC channel and a guy nicknamed "binary" which is the creator of SFGUI (and currently develops for SFML as far as I know) told me that: no matter of what update value your entities get they should be able to handle it. I believe these answers since now. Assuming that anything out of my knowledge may trigger the same kind of problem when big interval comes. One big CPU "freeze" because of glitch may cause severe bugs in the game. What is your opinion?

When the game is started watch how the entities normally moving than hold the window in drag state for 3-4 second, when released the issue is obvious.

Download the game
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,896
  • Joined: 12-June 08

Re: How to design logics/architecture related to time elapsed?

Posted 26 September 2017 - 11:16 AM

I am not following what you wrote.
Was This Post Helpful? 0
  • +
  • -

#13 mimipimbg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 14

Re: How to design logics/architecture related to time elapsed?

Posted 27 September 2017 - 12:30 AM

Right, it is all about content.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1