Jump to content

  • Log In with Google      Sign In   
  • Create Account

Long Time Coder, First Time Going Cross-Platform


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 adt7   Members   -  Reputation: 425

Like
0Likes
Like

Posted 21 December 2012 - 08:48 AM

I'm not sure if this really belongs in for beginners, since it's not really a beginner question. However I feel like I'm a beginner due to my ignorance when it comes to cross-platform development.

---

A friend and I have finally finished building a fully working prototype of our 2D game (we still need to produce some more content and assets, but all the mechanics are there).

We set out to develop the game primarily for the three major mobile platforms (iOS, Android, Windows Phone 8) and the Windows Store, with Windows (non-Store), Mac and Linux as a secondary objective. Unfortunately, we didn't really think about how we were planning to achieve this in the beginning.

Ideally I want to avoid using a "write once, build anywhere" engine as I want to avoid licensing fees and this is our first time trying to go cross-platform so I'm hoping it will be a good learning experience.

Thankfully our prototype has been written so that it should be easy to seperate the code for the game mechanics and the graphical display.

I think I've identified a set of technologies that will allow us to re-use the majority of code accross all/most platforms, but I was looking for some input/advice before we set this in stone and start re-writing our prototype.

Window Creation/Input/etc.
Some platform specific "glue" (i.e. Java for Android) to create a window, handle input etc. built for each platform.

Game Mechanics
C/C++ (Compiled separately for each platform, preferably straight C if we can get away with it)

Graphics
Windows Store/Phone 8
C++ & DirectX
iOS/Android
C/C++ & SDL

My first set of questions is that we're having difficultly determining if this approach will work for the Windows Store/Phone version, specifically:

  • Can we reference external C libraries in a Windows Phone/Store app?
  • If not, will we have to re-write everything in C++/CX or are we able to use regular C/C++ for the generic parts?

The next question I think is more a symptom of my own ignorance of C++/Objective-C more than anything else:

  • As C++/Objective-C are supersets of C, if I write straight C, can I simply compile it as C++/Objective-C on the platforms where that is required? This seems like I'm asking a really stupid question here, but I just want to make sure I'm not missing something.

Edited by adt7, 21 December 2012 - 12:23 PM.


Sponsor:

#2 6677   Members   -  Reputation: 1058

Like
0Likes
Like

Posted 21 December 2012 - 10:25 AM

Which version of windows phone are we talking? Because windows phone 7 only supports C# or VB.net with XNA. Windows phone 8 does allow native code with directX.

As far as I know there are no libraries or engines with any support for windows phone 8 at this time.



#3 DekuTree64   Members   -  Reputation: 986

Like
0Likes
Like

Posted 21 December 2012 - 11:44 AM

Sounds like you've got the right idea. In C/C++, cross-platforming is usually done with #ifdef, preferably with all the platform-specific code relegated to a few files. Although there is the issue of only being able to use the highest functionality that's common between ALL systems you're targeting, which usually means wasting a lot of potential from each individual system. So, sometimes you end up with a few more code switching spots to toss in a little extra on systems that can handle it.

 

SDL is one of the best cross-platform libraries around, because it's free and lightweight, therefore people generally make versions of it for any and everything. You may not even need anything more.

 

Otherwise, you'll need to figure out the common functionality for all the libraries on all the systems you're using. For example, how to blit a character to the screen in DirectX, versus how to do it in SDL, and how to do it in whatever Macs use. Then design your wrapper function to where it has all the options your game needs, and write the 2 or 3 versions of it that translate the options into each target library's blit function.

 

Same with loading assets. The game just says "Load Bob's walk cycle", and then the load wrapper function does whatever needs to be done on the current platform. Allocate VRAM and load the file, or maybe create a texture map in OpenGL if you were using 3D to render 2D on one platform. Then return a handle object (a class you write), which the game never looks into, but just passes around to other wrapper functions. On one platform it might contain a DirectX handle, on another it might just contain a VRAM address, or it might contain a whole image class that you wrote yourself, including an allocated memory block for the data. But from the game code perspective, it's just a handle, and all you need to remember is to delete it when you're done with it so it can do any platform-specific cleanup it needs to do.



#4 adt7   Members   -  Reputation: 425

Like
0Likes
Like

Posted 21 December 2012 - 12:19 PM

Which version of windows phone are we talking? Because windows phone 7 only supports C# or VB.net with XNA. Windows phone 8 does allow native code with directX.

As far as I know there are no libraries or engines with any support for windows phone 8 at this time.

 

We're just planning on targeting Windows Phone 8.

 

Sounds like you've got the right idea. In C/C++, cross-platforming is usually done with #ifdef, preferably with all the platform-specific code relegated to a few files. Although there is the issue of only being able to use the highest functionality that's common between ALL systems you're targeting, which usually means wasting a lot of potential from each individual system. So, sometimes you end up with a few more code switching spots to toss in a little extra on systems that can handle it.

 

Rather than this the only stuff I'm planning on taking a "write once" approach are the game mechanics, i.e. the model. Each of the platform projects will be completely standalone and will reference this and the appropriate graphics code. Therefore if I need a slightly different approach between SDL and DirectX this shouldn't be a problem, since the only place these interface differences will appear is in platform specific code.

 

SDL is one of the best cross-platform libraries around, because it's free and lightweight, therefore people generally make versions of it for any and everything. You may not even need anything more.

 

I know I'll at least need more for Windows Phone/Store, but I'm hoping SDL will do the job fr everything else, from everything I've read it looks like it.



#5 L. Spiro   Crossbones+   -  Reputation: 13581

Like
0Likes
Like

Posted 21 December 2012 - 12:49 PM

Window Creation/Input/etc.
Some platform specific "glue" (i.e. Java for Android) to create a window, handle input etc. built for each platform.
Among the platforms you listed the only glue would be on iOS using Objective-C or Objective-C++ in a maximum of 3 files.
For Android, use NativeActivity (or better yet, conserve your sanity and don’t target Android). Seriously if you are just starting out in cross-platform development you shouldn’t compound your troubles by doing native development for Android. I watched my coworker’s heart turn black starting since his task was to port our engine to Android, and I am still trying to change his heart back to its original green.

My first set of questions is that we're having difficultly determining if this approach will work for the Windows Store/Phone version, specifically:
  • Can we reference external C libraries in a Windows Phone/Store app?


Yes.

The next question I think is more a symptom of my own ignorance of C++/Objective-C more than anything else:
  • As C++/Objective-C are supersets of C, if I write straight C, can I simply compile it as C++/Objective-C


Yes.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 SimonForsman   Crossbones+   -  Reputation: 6109

Like
0Likes
Like

Posted 21 December 2012 - 05:05 PM

<p><p>





Window Creation/Input/etc.
Some platform specific "glue" (i.e. Java for Android) to create a window, handle input etc. built for each platform.

Among the platforms you listed the only glue would be on iOS using Objective-C or Objective-C++ in a maximum of 3 files.
For Android, use NativeActivity (or better yet, conserve your sanity and don’t target Android). Seriously if you are just starting out in cross-platform development you shouldn’t compound your troubles by doing native development for Android. I watched my coworker’s heart turn black starting since his task was to port our engine to Android, and I am still trying to change his heart back to its original green.

<p><p>My first set of questions is that we're having difficultly determining if this approach will work for the Windows Store/Phone version, specifically:

  • Can we reference external C libraries in a Windows Phone/Store app?
Yes.

The next question I think is more a symptom of my own ignorance of C++/Objective-C more than anything else:
  • As C++/Objective-C are supersets of C, if I write straight C, can I simply compile it as C++/Objective-C
Yes.


L. Spiro
Hmm, my long post disappeared....

Ah well, Just wanted to add, i started making my own Android/iOS game/"engine" (And i've made crossplatform games/"engines" for Win+Linux before) and quite quickly switched to Unity when i noticed just how much time i would have to spend fixing device or version specific issues. (just look at the changelog for Unity3D, Android gets more than twice the number of fixes iOS does, a fairly large number of the Android fixes are for a specific device, a specific architecture, a specific Android version (or group of versions), a specific GPU/GPU vendor, etc. it is quite nice to have someone else take care of that mess for you. (Allthough Unity obviously havn't fixed all device specific issues since they keep adding new device specific fixes in each minor release)

Edited by SimonForsman, 21 December 2012 - 05:21 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 Karsten_   Members   -  Reputation: 1603

Like
0Likes
Like

Posted 21 December 2012 - 05:37 PM

Using OpenGL, developing for android and iOS is very similar. The difficulty is Windows Phone 8. I am not sure that they will even let you upload native code to the device without an expensive developers license.

 

That aside, I would suggest creating a very basic 2D engine in OpenGL and DirectX with the same interface so your game will compile on both seemlessly when it comes to making builds for each of the platforms. This is the approach I am taking with my software, but luckily I don't have to worry about DirectX or Windows Phone platforms.

 

Another option could be SDL, but again I don't think the Windows 8 Platform will allow it to work.


Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS