Jump to content
  • Advertisement
Sign in to follow this  
reapz

Cross Platform Mobile Layer

This topic is 2774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently working on an iPhone game which uses OpenGL ES where most of the code is in C++ so that I can port to Android later on. My problem is I'm not quite sure where to start in building a cross platform layer between the C++ of my engine and the Objective-C of the OS.

An example would be accessing the native keyboard of the device. I'd like to be able to call a function in the wrapper which would return a keyboard object which handles the keyboard of that particular OS. I did try once with function pointers but ran into a nasty issue with Objective-C that wouldn't have been trivial to solve.

Does anyone either have any suggestions, or a good source of material to read about the subject? Ideally I'd like to write something nicely object oriented and reusable for future projects.

Share this post


Link to post
Share on other sites
Advertisement
Simple way is to create 2 Keyboard class files, iphone/keyboard.hpp and android/keyboard.hpp and then just select the one which contains the correct implementation when compiling via an #ifdef. If there is common code between the two classes you can have a base interface for that.




keyboard.hpp

#ifndef KEYBOARD_HPP

#define KEYBOARD_HPP

/*abstract*/ class KeyboardBase { ... };

#ifdef PLATFORM_IOS

#include "iphone/keyboard.hpp"

typedef IPhoneKeyboard Keyboard;

#elif PLATFORM_ANDROID

#include "android/keyboard.hpp"

typedef AndroidKeyboard Keyboard;

#endif

#endif

Share this post


Link to post
Share on other sites
Thanks for the response. I guess it is pretty much what I expected.

I think you would probably need some sort of Shell based class in which you would derive an AndroidShell and IOSShell from, again using #ifndefs. These two classes would be where the OS specific Keyboard object is created and used from. So the Shell would be the interfacing layer between the engine/app and the OS. In other words, the app never needs to know about which OS is on the other side. Am I on the right track? Or is there a better way?

Share this post


Link to post
Share on other sites
You should also try to declare a pure abstract Interface for each os-specific Subsystem / component / module. For instance you can define a keyboard-interface and the classes IPhoneKeyboard and AndroidKeyboard are derived from this. Using this the build will fail if you missed the implementation for a subsystem.

Kimmi

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!