Coder Social home page Coder Social logo

Comments (13)

kv-o avatar kv-o commented on August 17, 2024 1

Looks great!

from go-sdl2.

kv-o avatar kv-o commented on August 17, 2024 1

Certainly!

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

Hi @kv-o, you can add sleep using sdl.Delay() between the loop to reduce CPU usage.

from go-sdl2.

kv-o avatar kv-o commented on August 17, 2024

sdl.Delay seems somewhat like a hacky solution... Would sdl.WaitEvent be a better approach? I am unfamiliar with SDL2 and have little experience with graphics, so I apologise if I have overlooked/misunderstood something obvious.

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

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.

from go-sdl2.

kv-o avatar kv-o commented on August 17, 2024

If I understand correctly, specifying a hardcoded delay could introduce latencies between event occurrence and handling. sdl.WaitEvent seems (at least on initial impression) to block until an event actually occurs, thus reducing CPU time without introducing additional latencies. My interpretation might be wrong though; this is my first time interacting with SDL.

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

Hi @kv-o, you can calculate the time it takes to process one loop and pass appropriate value to sdl.Delay(). It doesn't need to be hard-coded. I suppose this approach makes sense when you have a target framerate but otherwise, feel free to use sdl.WaitEvent() if it's the better approach for your application.

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

Hi @kv-o, I have updated the README with two more examples that demonstrate the use of both WaitEvent() and PollEvent(). Let me know if that addresses your concern!

from go-sdl2.

kv-o avatar kv-o commented on August 17, 2024

The sdl.WaitEvent example only runs WaitEvent on the for loop's init statement, not the post statement. (I haven't tested it but this seems to be a bug)

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 WaitEvent and PollEvent examples could be reduced to two minimal code snippets that illustrate the difference?

Thanks for explaining the difference between using WaitEvent and Delay though — it made things a lot clearer!

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

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.

from go-sdl2.

kv-o avatar kv-o commented on August 17, 2024

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 WaitEvent and Delay to just a couple of lines? I think the difference between the two is easy to understand, so maybe a short explanation with a minimal code snippet should suffice.

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.

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

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?

from go-sdl2.

veeableful avatar veeableful commented on August 17, 2024

Thank you! Would it be okay if I close the issue then?

from go-sdl2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.