-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running readme example yields 30% CPU usage #594
Comments
Hi @kv-o, you can add sleep using |
|
Hi @kv-o, could you elaborate on why you find it to be hacky? My impression is that most games use similar approach, unless it updates only on events. |
If I understand correctly, specifying a hardcoded delay could introduce latencies between event occurrence and handling. |
Hi @kv-o, you can calculate the time it takes to process one loop and pass appropriate value to |
Hi @kv-o, I have updated the README with two more examples that demonstrate the use of both |
The I've found the following to work decently for my use case: running := true
for event := sdl.WaitEvent();; event = sdl.WaitEvent() {
if event == nil {
continue
}
switch event := event.(type) {
case *sdl.QuitEvent:
running = false
}
if !running {
break
}
} I've had a look at the updated readme and I think there is a lot of code now (that newcomers might get lost in). Perhaps the Thanks for explaining the difference between using |
Hi @kv-o, thanks for noticing the typo! I have fixed it in the latest commit. What do you think can be done to make it simpler? I wanted to illustrate by drawing moving rectangle that reacts to user input for sdl.WaitEvent and another that reacts to user input while continuing to move for sdl.PollEvent. |
I think it's more about keeping the readme itself concise so that newcomers don't get overwhelmed by having to digest a lot of new information upfront. It might be too confusing for someone who is reading the readme for the first time. Perhaps reduce the explanation of the difference between In my opinion it's probably better to have only one complete example in the readme, supplemented by a few guiding words of advice. Other standalone examples could probably be moved into the examples folder. |
Hi @kv-o, I have moved the two examples into the examples repository which is referred to in the README. Do you think that looks alright now? |
Looks great! |
Thank you! Would it be okay if I close the issue then? |
Certainly! |
Go version: 1.21.5
Go-SDL2 version: 0.4.38
SDL2 version: 2.30.1
OS: Windows 11
Architecture: amd64
I built the example from
README.md
, with all dependencies linked statically, and the program runs as expected (filled purple rectangle in top left corner), but CPU usage hovers between 20-30%.I built the example like so:
Here is a screenshot of the CPU usage as shown by Task Manager:
The text was updated successfully, but these errors were encountered: