Advertisement

Making Breakout - Code Structure help requested

Started by September 11, 2017 01:08 PM
77 comments, last by Kylotan 7 years, 5 months ago
9 minutes ago, MarcusAseth said:

I do not understand the question

You have two update functions: one that can only handle one delta time (not provided as argument since it is constant for a complete game) and one that can handle all delta times. If you have not overriden any fixed update function, your game loop will basically spin (like a spin lock) without doing useful stuff.

This sounds a bit esoteric, but I mostly do graphics stuff and have few scripts in my demos.

🧙

1 minute ago, matt77hias said:

You have a two update functions: one that can only handle one delta time (not provided as argument since it is constant for a complete game) and one that can handle all delta times. If you have not overriden any fixed update function, your game loop will basically spin (like a spin lock) without doing useful stuff.

This isn't Unity.

Hello to all my stalkers.

Advertisement
Just now, Lactose said:

This isn't Unity.

That is not the only game engine, I have seen, that use two distinct methods.

But since you mention them, how do they handle such a situation?

🧙

@matt77hias I still don't understand :D

If you're asking me how do I am using those delta times inside the overridden function update() and draw() of my entities, the answer is I am not using them yet because I have no entities, just getting the timing right for now.

If you want to know how I plan to use them, then Update(DeltaTime) will actually modify an object data, that's why is called update, while Draw(Interpolation) will still access the last calculated delta time and multiply by Interpolation to predict a new position, but it will not modify any Entity data.

1 minute ago, matt77hias said:

But since you mention them, how do they handle such a situation?

The source code isn't available to me, but at a guess I would say FixedUpdate is like the "Fix your timestep" setup, and the Update with variable delta time just runs once per render, either before or after the FixedUpdate loop.

Hello to all my stalkers.

4 minutes ago, Lactose said:

The source code isn't available to me, but at a guess I would say FixedUpdate is like the "Fix your timestep" setup, and the Update with variable delta time just runs once per render, either before or after the FixedUpdate loop.

But then it keeps spinning if you have no FixedUpdates?

Btw.: since you explicitly refer to Unity, is it rare in your opinion to have two update functions in a game engine?

4 minutes ago, MarcusAseth said:

@matt77hias I still don't understand

If you're asking me how do I am using those delta times inside the overridden function update() and draw() of my entities, the answer is I am not using them yet because I have no entities, just getting the timing right for now.

If you want to know how I plan to use them, then Update(DeltaTime) will actually modify an object data, that's why is called update, while Draw(Interpolation) will still access the last calculated delta time and multiply by Interpolation to predict a new position, but it will not modify any Entity data.

Take a look at Unity's Script Lifecycle Flowchart

They have an Update and FixedUpdate (physics stuff).

🧙

Advertisement

I don't get why Unity functions are suddenly relevant to my code :D

In that link it says that this "FixedUpdate" runs on a reliable timer or something like that, so it doesn't need delta time. I don't think mine is reliable, as I shown in the page before, enabling SDL_VSYNC makes my code enter that update function later than is supposed to, and it also messes up the Interpolation value for some reason noone spotted. So...let's not add problems with unity specific stuff :)

 

1 minute ago, MarcusAseth said:

In that link it says that this "FixedUpdate" runs on a reliable timer or something like that

This FixedUpdate is the update/integrate or whatever it is called in DeWitters and Gaffer On's game loop and in your game loop. 

🧙

11 minutes ago, matt77hias said:

But then it keeps spinning if you have no FixedUpdates?

Also what do you mean with "spinning"? That time keep passing? 

32 minutes ago, MarcusAseth said:

Also what do you mean with "spinning"? That time keep passing? 


while (time_budget >= m_fixed_update_time) {
    time_budget -= m_fixed_update_time;
}

Similar to a spinning or spin lock (which is a very poor user-side implementation of a lock, since it wastes CPU cycles):


while (m_lock->CheckLocked()) {

}

Currently, I will use:


if (m_fixed_delta_time) {
    time_budget += delta_time;
    while (time_budget >= m_fixed_delta_time) {
        FixedUpdate();
        time_budget -= m_fixed_delta_time;
    }
}
else {
    FixedUpdate();
}

Update(delta_time);

 

🧙

This topic is closed to new replies.

Advertisement