If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Belgedin
Posts: 4
Registered: ‎06-21-2013
My Device: Z10
My Carrier: Verizon

Mix Cascades with BPS Events

Hi,

 

I've gone over some of the archives in the forum to see if this was answered, I found a few links which I will include as reference, but they didn't fully touch on situation I am envisioning. My specific question, which I will elaborate on momentarily, is whether or not its possible to include a native event loop within a Cascades project (which has a root Application object that provides its own event loop handling.)

 

This one just seemed confused as to whether C libraries and code could be included; this doesn't touch on the issue of the BPS event loop -- http://supportforums.blackberry.com/t5/Native-Development/How-to-combine-Cascade-C-code-with-Native-...

 

This one is actually almost the same question I'm curious about, but it wasn't really resolved -- http://supportforums.blackberry.com/t5/Native-Development/Using-cascades-screen-on-top-of-Native-scr...

 

Now, to elaborate on what I want. I'm specifically interested in developing a library, the library relies on being able to spawn WebViews. The largest user base of the library will be game programmers. Now, the library should able to be added to existing game projects(complete, in progress, just beginning. All stages). The problem, of course, is that in general game apps gravitate toward the lower level Native SDK and BPS for event handling (the trusty while(true) { handle_window_events(); update(); ... })

 

I don't expect to be able to just plop the library in there, obviously the project will need to be updated to a Cascades project, and there will need to be an instance of bb::cascades::Application, and its event loop and other services started with a call to the exec() static method. What I want is to minimize the amount of refactoring that the library user will have to do, that is, I don't want him/her to have to gut their game loop to accomodate the library. Would it just be necessary to have them move their gameloop out of the main() entry point and into the run method of a thread, or is it somehow possible to provide Cascades controls like WebView to such low-level native app like a game?

 

Thanks for any insight or wisdom you can provide. I hope I've made my point clear, if not please let me know and I will elaborate.

 

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Mix Cascades with BPS Events

Searching the forums should dig up some past answers to similar questions. The key is QAbstractEventDispatcher and its setEventFilter() call.

See for example http://supportforums.blackberry.com/t5/Native-Development/Qt-and-BlackBerry-Platform-Services-BPS/td... or http://supportforums.blackberry.com/t5/Native-Development/Not-getting-screen-events-from-Qt-event-fi...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
New Contributor
Belgedin
Posts: 4
Registered: ‎06-21-2013
My Device: Z10
My Carrier: Verizon

Re: Mix Cascades with BPS Events

Thanks Peter,

 

I didn't see these in my own search. I am aware of the QAbstractEventDispatcher. So, essentially, it is as I described: if someone is using a standard game loop (windowing event handling, game state update, etc.), they will have to move that to a new thread in order to play nice with the Cascades root Application's internal event handling.

 

I appreciate the response =)

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Mix Cascades with BPS Events

Generally mixing event loops is impossible unless one of those loops is specifically designed to play nicely. In the case of BPS, you can do it via the event filter. Whether or not it's possible with the "standard" game loop of your framework depends on that framework. It's *possible* it can be done... can't say without looking at the specific case and code (or APIs) involved.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
New Contributor
Belgedin
Posts: 4
Registered: ‎06-21-2013
My Device: Z10
My Carrier: Verizon

Re: Mix Cascades with BPS Events

Right, its not so much that I want to mix event loops(well, I guess technically.) The GoodCitizenApp does basically what I want to do, allows a low-level process to run a mostly standard game loop, while in a separate process allow high-level Cascades controls to be utilized. The only issue is that it would require more modification than is ideal to an already existing game.

 

A good example of what I mean is here:

 

https://github.com/blackberry/Core-Native-Community-Samples/tree/master/NativeAndOpenGLWindows

 

Its all Core-Native code, and the the main() entry point contains a pretty standard loop, such as would be found in a game (in fact, the GamePlay 3D framework provided by BlackBerry, uses a similar structure). To allow a WebView to be created in that example would require the uprooting of the game loop and transplantation of it in separate thread (as the GoodCitizenApp does), to allow it to asynchronously poll the BPS events without interfering with the Cascades Application event loop. 

 

I hope that makes sense. But essentially, I think it is necessary. The library I'm working on requires Cascades for, if nothing else, the WebView control, but I can make no guarantees about the code users will be placing it in.

 

 

 

Thanks for taking the time answer my questions.

 

 

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Mix Cascades with BPS Events

Just to add to Peter's reply...

If you want to utilize Cascades build your app off Cascades application template. Then digest all events you wish in QAbstractEventDispatcher, if the event is for Cascades just pass it to Cascades. This way you incapsulate your game event loop into Cascades' one.

Please use plain text.