moocow1452
moocow1452

Reputation: 13

How can one port Cave Story (NXEngine) to Native Client

So, Native Client can run C++ code from the browser, and I know that the NX Engine is build from C++, and can be tweaked to run on Android. So, if the NX Engine can run Cave Story, and that can in theory run in the native client, how do you get it to work and host so that one could visit the page and play the game within a browser?

Upvotes: 0

Views: 932

Answers (2)

binji
binji

Reputation: 1860

Funny you ask, I've already ported it! It really doesn't require much changing (but I made a lot of changes anyway).

I haven't tried to recompile it in a while, so it is probably broken. Maybe I'll spend some time trying to get it working again... :)

You can find it at http://github.com/binji/nacl-nxengine

Upvotes: 1

West 39th
West 39th

Reputation: 634

To port NXEngine to Native Client, you'd need to port NXEngine itself (of course!) plus its dependencies. Let's consider each of them:

Porting to Native Client is very much like porting to a new - in many ways rather Linux-like - operating system. However, there are some important differences:

  • The "operating system" API of Native Client is Pepper, or PPAPI, a set of APIs that provide access to the capabilities of the browser. The bulk of the porting work is typically to get your code to use the Pepper APIs for opening files, displaying graphics, playing sounds, etc. (SDL makes input, sound, and graphics a lot easier, though). To open files, people often use nacl_mounts, a library that wraps the Pepper File API, so that one can mount the HTML5 Web Storage of the app or URLs on the web as file systems and then use the familiar fopen, fread, etc. From Pepper 25, parts of nacl_mounts are included in the NaCl SDK.

  • Native Client modules cannot use native operating system calls and do not have access to the host file system. This is for security reasons and to ensure portability.

  • There is no non-experimental font API in Pepper currently. Hence all font rendering must be done in your code and any .ttf file must be supplied as part of the app, as the Native Client will not able to access .ttf. files on the host system for security reasons.

Chrome/Pepper 25 recommended: Historically, Pepper API calls could only be made from the main thread. This required significant refactoring of games and other multithreaded programs that were designed to, say, render on one thread and play music on another thread. From Chrome 25 and onwards this restriction no longer exists. For details see https://developers.google.com/native-client/dev/peppercpp/classpp_1_1_message_loop. Targeting Chrome 25 or newer and thus using the Pepper 25 version of the NaCl SDK is likely to reduce the amount of refactoring work for this class of applications.

Running Native Client on a web page: The question mentions that one could "visit the page and play the game within a browser". It is important to know that only Chrome supports Native Client at this time. There is also an important difference between current-generation Native Client, which requires that the web app be put in Chrome Web Store for Native Client to work, and the forthcoming Portable Native Client, which will allow Native Client content on any web page. To allow visitors on a web page to use a current-generation NaCl-based app with minimal detours, Chrome Web Store Inline Installation (see https://developers.google.com/chrome/web-store/docs/inline_installation) can obviate the need for users to go to the Chrome Web Store.

A note on naclports: naclports is a community-based repository for Native Client. It contains several libraries and previous ports. You can see the list of libraries in naclports at http://code.google.com/p/naclports/source/browse/trunk/src/libraries/. While it contains useful examples of how to do ports, naclports is not for the faint-hearted as it often breaks and - given that it's maintained on a volunteer/best-effort basis - may take time to get fixed.

Additional pointers:* There are some additional tips and pointers to guides in this answer: Google Chrome Extension using NaCL with an external library.

Upvotes: 1

Related Questions