Ggez: How to implement event-loop?

Created on 13 Jan 2018  路  6Comments  路  Source: ggez/ggez

Firstly I take the example eventloop.rs. __There is no reaction for window-resize-events__ like here.

I need my custom event-loop because:

  • I need to recognise multitouch gestures such as MultiGesture;
  • complicated pipeline.

So I can't implement my event-loop because method ctx.gfx_context.resize_viewport (here) is private.

_And off course I can't create my own __sub__-event-loop over the standard ggez::event::run because the sdl2::EventPump can be only one._ What am I missing?

*GOOD FIRST ISSUE* Type-CODE bug

All 6 comments

Aha. In that case, ctx.gfx_context.resize_viewport probably shouldn't be private, or should be able to be called through some other function.

For now, you can roll your own resize_viewport() by calling gfx_window_sdl::update_views(); you should be able to get the necessary arguments to pass through it through graphics::get_window() and graphics::get_gfx_objects().

It's a slightly touchy operation that invalidates some of the gfx-rs state however, which is why it's not public. It's caused some anguish in #134 and related issues. However, as you have discovered, it is also something that people implementing their own event-loop have to be able to do, and leaving that out is an oversight.

Roll your own resize_viewport for the moment, or just fork and modify the code. If it doesn't break anything horribly for you, say so and we'll shuffle things around a bit to make it public. Should be making a 0.4.1 release sometime soon anyway.

@icefoxen thx!
Maybe I can use ctx.event_context but I don't know how now?..

The ctx.event_context is just the SDL2 EventSubsystem. It's not used for anything in ggez itself except letting Context::quit() trigger a quit event.

pub(crate) gfx_context: graphics::GraphicsContext is private _for outers from crate_ too :)

@fzzr- I accidentally fixed this, I think. See this commit: https://github.com/ggez/ggez/commit/0896813451c691a28071a93f4345d7727c606afe

It adds a method Context::process_events() which calls resize_viewport() for you when necessary, so this should hopefully take care of your problem.

I think it's great! Thx!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ozkriff picture ozkriff  路  5Comments

BezPowell picture BezPowell  路  3Comments

Catvert picture Catvert  路  5Comments

t-veor picture t-veor  路  5Comments

TakWolf picture TakWolf  路  4Comments