#Inconsistent speed when changing window size

67 messages · Page 1 of 1 (latest)

hexed smeltBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

dense orchid
#

Hello, no one will download a zip

#

Please paste your code

hasty saffron
bleak trench
#

!howto ask

hexed smeltBOT
# bleak trench !howto ask
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
swift coyote
#

So do I just paste all?

dense orchid
#

!howto ask

hexed smeltBOT
# dense orchid !howto ask
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
dense orchid
#

read the last 3 lines of that^

bleak trench
#

No one wants to read hundreds of lines

#

It's best if you can send just the relevant parts

swift coyote
#

float delta_time = 0.016666f;
LARGE_INTEGER frame_begin_time;
QueryPerformanceCounter(&frame_begin_time);

float performance_frequency;
{
    LARGE_INTEGER perf;
    QueryPerformanceFrequency(&perf);
    performance_frequency = (float)perf.QuadPart;
}

simulate_game(&input, delta_time);
LARGE_INTEGER frame_end_time;
QueryPerformanceCounter(&frame_end_time);
delta_time = (float)(frame_end_time.QuadPart - frame_begin_time.QuadPart) / performance_frequency;
frame_begin_time = frame_end_time;

simulate_game(Input* input, float dt) {
clear_screen(0xff5500);

float speed = 5.f; // Units per second
if (is_down(BUTTON_UP)) player_pos_y += speed * dt;
if (is_down(BUTTON_DOWN)) player_pos_y -= speed * dt;
if (is_down(BUTTON_LEFT)) player_pos_x -= speed * dt;
if (is_down(BUTTON_RIGHT)) player_pos_x += speed * dt;
draw_rect(player_pos_x, player_pos_y, 0.5, 0.5, 0x00ff22);
#

I guess these are all of the important parts

#

Basically it calculates second per frame

#

From what the video told me

#

And then it just take delta_time and multiply with speed

bleak trench
#

!code

hexed smeltBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
swift coyote
#
internal void
simulate_game(Input* input, float dt) {
    clear_screen(0xff5500);

    float speed = 5.f; // Units per second
    if (is_down(BUTTON_UP)) player_pos_y += speed * dt;
    if (is_down(BUTTON_DOWN)) player_pos_y -= speed * dt;
    if (is_down(BUTTON_LEFT)) player_pos_x -= speed * dt;
    if (is_down(BUTTON_RIGHT)) player_pos_x += speed * dt;
    draw_rect(player_pos_x, player_pos_y, 0.5, 0.5, 0x00ff22);

}
int main(){
  float delta_time = 0.016666f;
    LARGE_INTEGER frame_begin_time;
    QueryPerformanceCounter(&frame_begin_time);

    float performance_frequency;
    {
        LARGE_INTEGER perf;
        QueryPerformanceFrequency(&perf);
        performance_frequency = (float)perf.QuadPart;
    }
   simulate_game(&input, delta_time);
  LARGE_INTEGER frame_end_time;
    QueryPerformanceCounter(&frame_end_time);
    delta_time = (float)(frame_end_time.QuadPart - frame_begin_time.QuadPart) / performance_frequency;
    frame_begin_time = frame_end_time;
}
dense orchid
#

And you need to calculate length of each frame?

#

To fix your issue?

swift coyote
#

From the video I watched. Yes that's what they did

#

And then they used that time length and multiply with speed

dense orchid
#

Speed of what

swift coyote
#

Movement speed

#

Of the object that the user controls

#

They did that so the movement speed doesn't change when the window changes in size

dense orchid
#

so the speed of the square/rectangle your drawing changes when you resize the application window

swift coyote
#

Yes that's the problem

#

The smaller the application window

dense orchid
#

i see your code calculating the length

swift coyote
#

It does that but I don't know why it doesn't apply

#

So it does calculate the length

#

And I multiply the length with movement speed

#

But the movement speed changes

#

Despite that

dense orchid
#

What are you doing with this value

#

Where is that handled

#

is length * initial rect speed = new rect speed

#

or what does this value represent

swift coyote
#

You can see that in simulate_game function

dense orchid
#

I only see you subtract initial frame time from final frame time

#

And divide it by “performance frequency”

#

i dont see you setting it to be the new speed of the rectangle

swift coyote
#

I guess it's time * speed = distance
Speed is already determined (5.f)
So what I want is for the time to change so that distance between first pos and next pos stays the same throughout despite the size of the window
However, time doesn't change or something not working which results in smaller window => distance longer I guess

#

Can I send video for you to see the problem?

#

I think it will be a bit easier if you can see the problem

dense orchid
#

send relevant timestamps too

swift coyote
#

At 50 second is where you can see my problem

#

The first part is the expected output

#

I'm currently learning this course on youtube

#

Hope this helps a bit

#

If you need more information, I will try to provide all everything

#

I will comeback after half an hour

#

Thankyou for taking your time looking into this

hexed smeltBOT
#

@swift coyote Has your question been resolved? If so, type !solved :)

hexed smeltBOT
#

@swift coyote

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

swift coyote
#

!solved