Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Any analog to SDL's expose event?  (Read 7440 times)

0 Members and 1 Guest are viewing this topic.

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Any analog to SDL's expose event?
« on: October 10, 2012, 07:21:31 pm »
My game library is implementing a display list structure to only refresh the screen (and specifically, the dirty rectangles) when things move.

For instance, in a tile-based 2D engine, if enemies are walking around, one won't have to do the (potentially, based on the speed of the underlying graphics implementation) expensive operation of redrawing the tile matrix every single frame. The display list will keep track of only the rectangles needing updating and rendering what's necessary.

The problem I'm having is that if I let my app do this, and for instance grab the window and move it offscreen and back, or if another window is dragged over my window, there is no event to let me know that due to something outside of the scope of my application, I need to redraw some or all of the window contents.

SDL has SDL_ExposeEvent, is there an analog for SFML?

EDIT: That page really showcases how lame SDL docs are in places :P The relevant part is:

Quote from: SDL docs
SDL_ExposeEvent is a member of the SDL_Event union and is used whan an event of type SDL_VIDEOEXPOSE is reported.

A VIDEOEXPOSE event is triggered when the screen has been modified outside of the application, usually by the window manager and needs to be redrawn.
« Last Edit: October 10, 2012, 07:23:13 pm by cha0s »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Any analog to SDL's expose event?
« Reply #1 on: October 10, 2012, 07:59:10 pm »
No there isn't anything similar.

Also the method "update only when needed" isn't what SFML is build for.
SFML requires you to call clear(), draw(), display() in every frame iteration. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #2 on: October 10, 2012, 08:20:33 pm »
SFML requires you to call clear(), draw(), display() in every frame iteration. ;)

Actually, SFML requires you to call draw and display when you want to update what's on the window :)

Unfortunately, there's no way to tell SFML to update the window when the window manager requires I guess, and that's unfortunate.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Any analog to SDL's expose event?
« Reply #3 on: October 10, 2012, 08:26:38 pm »
Actually, SFML requires you to call draw and display when you want to update what's on the window :)
No if you use sf::RenderWindow you need to call window.clear() (at least that's what Laurent the developer is saying)! ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #4 on: October 10, 2012, 08:42:07 pm »
I did some research and I've found that to be correct, with possibly conflicting information.

Here, Laurent says, "And yes, you need to clear/draw/display everything every frame, the back buffer is not a persistent object where you can accumulate rendered objects."

Which leads me to believe that partial "dirty rectangle" rendering isn't supported in SFML. That's a disappointment, but not a show-stopper when implementing a common runtime that can handle dirty rectangle refreshing in a backend-agnostic way (I can just entirely copy my own dirty-rectangle-enabled backbuffer to the window for SFML).

There is a potential conflict in the tutorials. At least, I believe that the clear() requirement was only since 2.0 or the 1.6 tutorial saying, "Note that clearing the window is not actually needed if what you have to draw is going to cover the entire screen; do it only if you have some pixels which would remain undrawn." is wrong or the clear requirement isn't a hard requirement. I'm trying to figure out what the real information is!

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #5 on: October 10, 2012, 09:02:13 pm »
We used SDL in commercial projects, distributed to tens of thousands of PC systems. After finding SFML, we decided to move, and I have to say, we would never consider another library now - even with things like Unity3D available.

As for your dirty-rectangles requirement, this is a very old fashioned way of doing things and creates more problems than it solves. Modern GPUs can easily handle high resolution, high framerate programs without much trouble.

If there is a specific engineering or commercial reason for using dirty rectangles, then OK, but if the only reason is you don't want to change your mindset or style of coding, then you need to think carefully about what you're doing and why.
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Any analog to SDL's expose event?
« Reply #6 on: October 10, 2012, 09:16:49 pm »
Quote
There is a potential conflict in the tutorials. At least, I believe that the clear() requirement was only since 2.0 or the 1.6 tutorial saying, "Note that clearing the window is not actually needed if what you have to draw is going to cover the entire screen; do it only if you have some pixels which would remain undrawn." is wrong or the clear requirement isn't a hard requirement. I'm trying to figure out what the real information is!
You misunderstood this comment. In any case, you must write every pixel of the window every frame. What I said is just that if what you draw covers the whole window, there's no need to clear it first. The clear() function is just a way to fill the entire window with a color, it doesn't do any magic.

Back to the "dirty rectangle" strategy: it was good 15 years ago, but today's graphics cards don't work like this anymore. If you think that you can't get your app running at decent framerate without using this strategy, then you're wrong. You're very far from complex 3D games that can display millions of polygons.

And why can't it work anyway? Because of double-buffering. The buffer you draw the current frame to, is not the buffer where the previous frame is.
Laurent Gomila - SFML developer

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #7 on: October 10, 2012, 09:37:42 pm »
Well, since this technical question has seemingly become a philosophical debate, I feel like I should justify my position. :)

The big reason for using this technique is because the (ambitious) game engine Avocado that I'm developing as a hobby project is a JavaScript engine. While it's running on the PC, I am binding to the V8 JavaScript engine. SFML is one avenue I've been experimenting with to provide Graphics, Sound, potentially etc. to the engine using the SPI framework I've developed for Avocado. I also have an SDL backend that works in software, so it should go quite far back in terms of hardware.

That's great! While we're on PC we have access to crazy amounts of power, and it works awesome. The problem is... JavaScript doesn't only run on the PC. ;) The vision for Avocado is that it will run everywhere JS will run (which if you've been paying attention is... everywhere :P).

The rub here is that pretty much every JS implementation that isn't V8 SUCKS @$$ compared to V8. That's what I get in other browsers that aren't Google Chrome. So, what seems like "old, useless" techniques actually can make the difference between a smooth experience and a horrible laggy one.

In the browser I'm using HTML5 canvas and it isn't hardware-accelerated yet. This means we're "15 years ago" all over again. I'm not attached to optimization techniques such as display lists out of habit or because "it's all I know". I'm only 28 years old :P

I was working on a game project when the artist walked away and I had to halt it. It sucked, we were doing well on Kickstarter. I was developing this engine for that project and I've since started basically from scratch, re-architecting it. Avocado isn't currently in the browser again yet (In fact, I've only got it compiling on Linux as yet since I'm now on my own time, and getting the latest V8 compiling in MSYS is a PITA which I will eventually get around to solving), but our demo was a proof-of-concept and it actually worked very well. It just lagged behind in non-Chrome browsers and using these techniques I will solve that problem.

Sorry if it's a long post but I felt like I needed to explain myself. :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Any analog to SDL's expose event?
« Reply #8 on: October 10, 2012, 09:50:28 pm »
Interesting to read. ;)

Anyways, SFML is not made for every hardware out there, so if use SFML you can only target a specific spectrum and for that spectrum those methods are outdated. ;)
« Last Edit: October 10, 2012, 09:52:37 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #9 on: October 10, 2012, 10:22:04 pm »
Also, if you want true cross platform stuff for more than PC/Mac then look at something like Marmalade (www.madewithmarmalade.com) or Unity3D.
SFML 2.1

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #10 on: October 10, 2012, 10:25:25 pm »
Two words: gratis and libre. ;D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Any analog to SDL's expose event?
« Reply #11 on: October 10, 2012, 10:26:43 pm »
Quote
The problem is... JavaScript doesn't only run on the PC.
Quote
In the browser I'm using HTML5 canvas and it isn't hardware-accelerated yet.
Sorry but I don't get it
- SFML does only run on PC
- what's the relation between a HTML5 canvas and a SFML window?

My point is that everywhere SFML runs, the dirty rectangles strategy is useless. And I don't see how all that you describe can be possible with a SFML backend. Can you explain more how things work internally, from SFML to the browser?
Laurent Gomila - SFML developer

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #12 on: October 10, 2012, 10:45:50 pm »
Sorry if I was confusing! SFML indeed does not run on the browser, Avocado does!

The whole point of me using SFML is as a graphics backend for my game engine. You have a JavaScript codebase that does things like:

image = avo.Image.load("/images/my-image.png")

and on the PC you can select SFML as your graphics SPII, and it will do this:

http://cha0s.github.com/avocado/cpp/classavo_1_1SfmlImage.html#a271112e413d3f9a79c7e4d1c6c91f1ed

You can also select SDL as an implementation, and it will do this:

http://cha0s.github.com/avocado/cpp/classavo_1_1SdlImage.html#ad7b1cad32b8202f001b70f4e504daab6

In the browser, it's more like, you crate an img tag in script, set the src, and then fulfill a promise in an onload callback.

So again, the whole point here is that when I refer to a display list or any other engine logic, I'm talking about JavaScript code, completely platform-agnostic stuff. I'm just using SFML as one backend implementation for stuff... on PC. I'm liking it so far, I think it's a very nice library.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Any analog to SDL's expose event?
« Reply #13 on: October 10, 2012, 11:05:48 pm »
Ok, that's what I thought, so... what's the point of this discussion? Because as I said, anywhere you can use a SFML window, this "problem" (of refreshing only the parts that have changed) doesn't exist. From what you said, it exists only in contexts where you'll need another backend anyway.
Laurent Gomila - SFML developer

cha0s

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Any analog to SDL's expose event?
« Reply #14 on: October 11, 2012, 12:09:46 am »
lol, I'm not trying to drag out the discussion. I was just explaining why I was doing what I was doing and trying to clear up your confusion. I feel like it's a little harsh to ask "what's the point" ...

It's really no problem for me, I've already committed the fixes on my develop branch. Thanks for the input.