iMiniB3D - force screen flip

BlitzMax Forums/MiniB3D Module/iMiniB3D - force screen flip

ima747(Posted 2009) [#1]
in love with iMiniB3d, but I don't understand Objective C very well so I don't know how to pull out what I want...

I need to force the screen to update mid flow to display a basic loading screen. drawView in EAGLView.mm does the flipping it seems, and is called by the animation loop on the GLView, which is all well and good, but I don't know how (assuming it's possible) to do the update commands from another file, as I can't figure out how to get to the contexts etc.

Or (more likely I think) is there a way to basicly let the program go for a loop, like giving it system time so it will try to process a frame?

Sorry if this is inapropriate for the forums since it's iMini and not bmax, I didn't want to bother simon since it's not a bug etc.


Sledge(Posted 2009) [#2]
I need to force the screen to update mid flow to display a basic loading screen. drawView in EAGLView.mm does the flipping it seem

[myEAGLView drawView] might work (I only just took a quick look at the class and assume it is he equivalent of [myNSView setNeedsDisplay]) where myEAGLView is a member of your application delegate, but even so it might not cause an instantaneous screen update. However, to call it outside of the application delegate you would go...

[((MyAppDelegate *)[UIApplication sharedApplication].delegate).myEAGLView drawView]

...assuming you had readied your EAGLView instance for dot-syntax (ie defined and synthesised an @property entry for it in MyAppDelegate.h) and ensured that MyAppDelegate.h was imported into EAGLView.mm. There might be a more succinct way to access a member of MyAppDelegate with C++ but the above is the Objective-C method (unless you want to use a singleton).

Or (more likely I think) is there a way to basicly let the program go for a loop, like giving it system time so it will try to process a frame?

Sure. If you write your program as a state machine the loading state could traverse a list of files to load, one per loop.

I assume you're asking about this because you want to implement a loading bar. Remember that these are mobile devices and if you're taking so long to load stuff that you need a progress bar then you should probably have a rethink.


ima747(Posted 2009) [#3]
Very interesting, I will have a poke, thank you!

A loading bar would be nice, but my load times I don't expect to be more than a few seconds, it's more for the initial app load, so the user isn't left with a black screen going "did this just crash?" for 5 seconds while I prep the base stuff. and depending on how big a level gets it may take a few seconds to load so I'd like another splash screen there. I've played a few games (iDracula comes to mind) that have longer loading times than I'm planning so I don't think it's too unreasonable, but the decent games all have at least a loading screen so you know you're not frozen.


Sledge(Posted 2009) [#4]
it's more for the initial app load, so the user isn't left with a black screen going "did this just crash?"

Oh in that case just stick Default.png (320x480 pixels) in your project directory (and drag its icon onto your "Groups & Files" list) and it will be displayed automatically.


ima747(Posted 2009) [#5]
dangit, how can there be that many usefull auto loading things on iphone. Is there a list somewhere with all "make file x and it'll do this without any code or touching interface builder" etc?

That will do for now, but I'm still curious about loading screen type display, basicly a manual flip.

what I've got so far just modifying the base files

Add #import "AppDelegate.h" to EAGLView.h

add the following functions to EAGLView.mm (and declare them in EAGLView.h)
- (void)drawFlipPrep { // Perpare for drawing

[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

}

- (void)drawFlip { // Post Renderworld flip

glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

}

add #include "EAGLView.h" to my .mm file I want to do the flip from

when I want to flip I do

[((b3dAppDelegate *)[UIApplication sharedApplication].delegate).glView drawFlipPrep];
Global::RenderWorld();
[((b3dAppDelegate *)[UIApplication sharedApplication].delegate).glView drawFlip];

which crashes in drawFlip on [context presentRenderbuffer:GL_RENDERBUFFER_OES]; but I'm calling this in the Game::Init() so it might be that not everything is set up yet so the renderbuffer croaks... going to do some more poking.


Sledge(Posted 2009) [#6]
Is there a list somewhere with all "make file x and it'll do this without any code or touching interface builder" etc?
The other one is Icon.png, which should be 64x64 57x57 pixels [see below].


ima747(Posted 2009) [#7]
[Update]
It works out of the init loop. so Default.png for initial loading screen, and
[((b3dAppDelegate *)[UIApplication sharedApplication].delegate).glView drawFlipPrep];
Global::RenderWorld();
[((b3dAppDelegate *)[UIApplication sharedApplication].delegate).glView drawFlip];
if you want to force a flip

the reason I'm not using [((b3dAppDelegate *)[UIApplication sharedApplication].delegate).glView drawView]; is that it calls Game::Run() which will run through the game logic, which if you loading etc. might not work so great since you may not have the resources loaded... you could check for that in your game logic and just do a draw screen and return, but I'd prefer not to add that extra if to every single frame cycle when I only need it 1 in a thousand times.

So, thank you again sledge! saved me many a headache and gave me another (much needed) push towards Objective C


simonh(Posted 2009) [#8]
It's 57x57 for the icon - you have to get the size right otherwise the app gets rejected by Apple.

I didn't know about default.png myself - thanks for the tip!


Sledge(Posted 2009) [#9]
Thanks for mentioning that -- 64x64 works so I would've stiffed myself there.


ima747(Posted 2009) [#10]
Just stumbled upon this. If anyone else wants to know the various special names etc. take a look at

http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationEnvironment/ApplicationEnvironment.html#//apple_ref/doc/uid/TP40007072-CH7-SW20

Settings.bundle - a settings bundle that will be put into the Settings app so people can configure your app without launching it
Icon.png - Icon for your application 57x57 72dpi 24bit PNG. you can use anything for testing but when trying to publish to the app store it must conform. I use my big app picture for the icon too while testing because I make changes along the way and it's anoying to export it then scale and export again.
Icon-Settings.png - 29 x 29 72dpi 24bit PNG. if you use a settings.bundle you can also put this in for a custom icon in the settings, if it's not there it uses the icon.png and scales for you.
MainWindow.xib - the nib file with the main window for your app, have to have this or your app has no window and therefore no display, and won't run. should be created for you when you make any new project.
Default.png - 480 x 320 72dpi png that will automatically load and be displayed while your application loads. for games a loading screen could be appropriate for apps I think the standard is to use a fake starting view to give the impression the interface is loaded before it actually has. some of the apple examples do this (see list view examples) some don't, it's optional but quite handy
iTunesArtwork - (note, NO extension) 512 x 512 png or jpeg that will show up for your app in itunes for add-hoc distribution. you can also toss this in for your testers and they'll see it as well since testing is basically ad-hoc, just not commercial. I can't get my app to run on my own device when using this and it isn't supported for app store distribution (for the app store you upload this image seprately when submitting the app)
Info.plist - plist file with all your app configuration info like bundle identifier etc. should be created for you when you make any new project, you will need to change your bundle identifier as part of the distribution to app store, and it's pretty poorly documented as to what you're supposed to set it to, atleast from what I could find.
en.lproj,fr.lproj,**.lproj,... - language specific resources. used to localize your app to other languages, put a version of each resource file that needs localizing in each language folder. i.e. Hello.png is a picture with the word hello, if you're making a french version you need another Hello.png in the fr.lproj folder that contains a picture of the word Bonjour. when you request a path to a bundle resource in your app it will automaticly grab the localized version if there is one, for whatever language the user has active.
anything else you want - any other pictures, nibs, string files, plists etc. that you may need. If you're going to be using a database you can make a starter database in your resources with all your tables layed out and any initial content you want, and then on first run make a copy of it to the application's document folder (see the sqlite tutorials for examples) so you can make changes since the bundle is read only at run time.

I believe there's a way to have the app put some files in it's documents folder (so you have write access to them) for you, but I haven't needed that yet so I haven't dug deep enough.