Using haxe as a transpiler between C ++ and JavaScript

First, I apologize for the long post. I asked a few questions about haxe and its suitability as a tool to solve the problem I am facing. I have very limited knowledge of haxe, but what I know is my ideal role for haxe in my project, this is not normal use of haxe. So I try to avoid wasting time, I do not learn this language (despite the fact that it looks very fun and powerful), only to understand that it is not suitable for the purpose. Therefore, I hope to receive recommendations from experienced veterinarians about whether this is suitable for the purpose. I really hope so.

Here is what I am trying to achieve:

I work in the gaming industry, and I need to create a game in both C ++ and JS. C ++ for the embedded system and JS for online and mobile devices. I am very experienced in both C ++ and JS.

The games that I develop, I only want to write once. Now I could use something like emscripten to migrate from C ++ to JS, but this will lead to compiled JS code that cannot be debugged using the chrome dev tools. I have converted that I will encounter errors as a last resort with compiled JS, which I cannot easily revert back to the original C ++. In addition, some platforms for the game will require equity labs to view the source code, which will be a problem for compiled JS.

I really need a source for the source compiler, which creates its own readable C ++ and JS code, which I can then process and modify in my native form, if necessary, therefore, haxe. I looked at the code created by haxe for C ++ and JS. JS looks very easy to understand and work. C ++ is not much, but still pretty much acceptable. I can even stop haxe from compiling and binding C ++, which I don't need. I only need the source code.

So far so good.

Now I have a game environment in C ++ that uses the 2d oxygen engine. It is capable of displaying sprites, etc., as well as the structure that I created for messages and state machines (it also loads more useful classes). I also have a similar structure in JS that uses Pixijs for its 2d engine and has its own message bus and so on, like the C ++ engine.

Now what I want to do is write the modules in haxe, which, when I pass both C ++ and JS, that the code can be included as part of the structure and work with its respected language engine. Every object that I create in haxe will be very encapsulated and you just need to subscribe to the message bus, process the messages and send messages back. In addition, you may need to know how to use your engine machine. Therefore, I have no idea whether this is possible with haxe, since the message bus (along with other objects) will not be written to haxe, but will be provided to the module after it is full and built in my own project. Maybe I can write my own haxe library that knows the syntax for my two game engines and can be broadcast depending on its target language? Not sure if this is possible.

Thank you for taking the time to read and any tips you can give.

+5
source share
1 answer

you can use

#if cpp // c++ implementation #elseif js // javascript implementation #end 

to allow some different implementations for different purposes, this can go anywhere in your code, so you can pass the Haxe value to different functions for different purposes.

To use extern definitions:

With C ++ in particular, this can be trickier, you need to take a look at CFFI or Linc https://snowkit.imtqy.com/linc/
Complexity is probably related to types. Remember that Haxe C ++ manages memory, your engine may do something different. Also, HL will be available soon and may have some benefits.

Looking at oxygine2d, does this look like a Flash API? And I know that pixijs is based roughly on the Flash API. I believe that OpenFL now uses pixijs to render WebGL. You might also want to take a look at NME (it has almost the same interface for C ++ as OpenFL, but NME has things like Cppia setup and is sometimes more stable). If JS or C ++ is too slow, you need to look into the shaders and Luxe / Kha for rendering, and you might also want to try Heaps, it uses Lime (openfl) and some haxe js webgl that I think.
If you need 2D physics, then use Nape, which can be used with any Haxe toolkit (Luxe, OpenFL, Kha, Flambe), there is physics, but it is not used so much. Information about Kha and Nape, for example: https://github.com/lewislepton/kha-examples/blob/master/NAPE/Sources/Project.hx

I really suspect you are making your life hard, wanting to use different engines for different platforms, when probably HaxeFlixel or Punk can provide you with everything you need to run using Nape on one of the cross-targeted toolboxes, but this it is very possible to make your way.

Perhaps look at Tink or thanks for signaling buses, etc., macros (for example, used in Tink) allow you to create many structures at compilation and, therefore, can reduce a significant part of the overhead by doing this before execution, so teenagers can be pre-calculated by the compiler. There is a hxcpp debugger, and if you are running Haxe in chrome, it should give you the Haxe line number through the js source mapping.

I hope I touched on some aspects of your big question.

Haxe allows you to mix and match with your family, but I think that using Pixijs and oxygine 2d is probably not ideal, since pure Haxe has enough good game tools with optimized target optimization, you just need to go for Kha IRC, Luxe gitter and Haxe IRC and the OpenFL forum and ask a few questions.

+1
source

All Articles