Using haxe as a transpiler between c++ and JavaScript [closed] - haxe

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Firstly I apologise for the long post. I have been asking a few questions about haxe and its suitability as a tool to solve a problem I am facing. I have very limited knowledge of haxe but what I do know is my ideal role for haxe in my project is not the normal use of haxe. So what I'm trying to avoid is wasting time I don't have learning this language (despite it looking really fun and powerful) only to find that it isn't fit for purpose. So I am hoping to get some advice from you haxe seasoned vets on whether it is fit for purpose. I truly hope that it is.
Here is what I am trying to achieve:
I work in the games industry and I need to create a game in both C++ and JS. C++ for an embedded system and JS for online and mobile. I am very experienced in both C++ and JS.
The games I develop I only want to write the once. Now I could use something like emscripten for going from C++ to JS but this will result in compiled JS code that cant be debugged with chrome dev tools easily. I'm converned that I will run into edge case bugs with the compiled JS that I cant easily tace back to the original C++. Plus some platforms for the game would require fairness laboratories to view the source code which would be an issue for compiled JS.
What I really need is a source to source compiler that produces native and human readable c++ and JS code that I can then work with and modify in its native form if necessary, hence haxe. I've looked at the code produced by haxe for C++ and JS. JS looks perfectly easy to understand and work with. C++ not so much but still just about acceptable. I can even stop haxe from compiling and linking C++ which I dont need. I only want the source code.
So far so good.
Now I have a game framework in c++ that uses oxygine 2d engine. It is capable of showing sprites etc as well as a framework I have created for message buses and finite state machines (loads more useful classes too). I also have a similar framework in JS which uses Pixijs for its 2d engine and has its own message bus etc just like the C++ engine.
Now what I want to be able to do is write modules in haxe that when I transpile to both C++ and JS that the code can be included as part of the framework and work with its respected language engine. Each object I create in haxe will be very encapsulated and will just need to subscribe to the message bus, handle messages and send messages back. It may also need to know how to use its engines state machine. So I have no idea if this is even possible with haxe as the message bus (along with other objects) will not be written in haxe but will be supplied to the module after it has been transpiled and built in its native project. Maybe I can write my own haxe library that knows the syntax for my two game engines and can transpile depending on its target language? Not sure it that is possible.
Thanks for taking the time to read, and any advice you can give.

You can use
#if cpp
// c++ implementation
#elseif js
// javascript implementation
#end
to allow some different implementations for different targets, this can go anywhere in your code, so you can pass a Haxe value to different functions for different targets.
To use extern definitions:
http://haxe.org/manual/lf-externs.html
http://old.haxe.org/doc/js/extern_libraries
With c++ specifically it might be more complex you need to look at CFFI or Linc
https://snowkit.github.io/linc/
The complexity is probably getting the types across. Remember Haxe c++ has managed memory your engine might do things differently. Also HL is coming soon and may have some advantages.
Looking at oxygine2d it seems a bit like the Flash API? And I know pixijs is based roughly off the Flash API. I believe that OpenFL now uses pixijs for WebGL rendering. You might want to also look at NME ( has nearly same interface for C++ as OpenFL, but NME has stuff like Cppia setup and is sometimes more stable ). If the JS or C++ is too slow you need to look into shaders and Luxe/Kha for render and you might want to also try Heaps it uses Lime ( openfl ) and some haxe js webgl I think.
If you need 2D physics then use Nape it can be used with any of the Haxe toolkits (Luxe, OpenFL, Kha, Flambe), there is physaxe but that's not used as much. Kha and Nape info eg:
https://github.com/lewislepton/kha-examples/blob/master/NAPE/Sources/Project.hx
I really suspect that your making your life hard by wanting to use different engines for different platforms when probably HaxeFlixel or Punk could give you all you need running with Nape on one of the cross target toolkits, but it's very feasible to do it your way.
Maybe look at Tink or Thx for signals event buses and the like, macros (like used in Tink) allow a lot of structures to be built at compile and so can reduce much of the overhead by doing it before run-time, so tweens can be pre-calculated by the compiler. There is a hxcpp debugger and if you run Haxe in chrome it should give you the Haxe line number via js source mapping.
Hopefully I have covered some aspects of your large question.
Haxe allows you to mix and match with native, but I think to use Pixijs and oxygine 2d is probably not ideal as there is bound to be enough good game tools in pure Haxe with target optimizations built in, you just need to go onto Kha IRC, Luxe gitter, and Haxe IRC and OpenFL forum and ask a few questions.

Related

Anjuta/Glade Tutorials or Better IDE?

I am attempting to develop a GUI application for Tails. I'm doing the initial development on Debian 8 since development directly in Tails can be a pain.
I started out using Anjuta, but the documentation is essentially non-existent. The Anjuta website has nothing at all about how Glade is integrated or how to use it. I can't even track down documentation on how to change the main window title. The only tutorial I found has you start a project and build it using the default files that are generated for a GTKmm project.
Is there a good book or online tutorial out there for doing GUI development in Anjuta?
This is maybe not a complete answer, but it's too large to put in as a comment. I use Anjuta fairly regularly, but I share your feeling about the missing documentation (which is, by the way, not unique for Anjuta). I appreciate Anjuta (and Glade) very much, so don't take the following as criticisms on either program.
I would recommend you consider using PyGTK for GUI creation. It is a lot more productive. You can design the GUI in Glade - exactly the same way you would do for C/C++ - and then implement the code in Python, which you can also edit and manage from Anjuta. There are plenty of code examples, for example on the nullege code search engine.
About the work flow in Anjuta (for C/C++). It is based mainly on the Autotools system, so you should really read up a little on make, Makefile, and related tools. Though in principle Anjuta manages this, you will, sooner or later hit a problem, and some knowledge about Autotools will help you a long way (also this tutorial or this one. This slide series is interesting - probably because it is more graphical. There are even some video tutorials, like this one.).
There is no real necessity to use Glade from inside Anjuta. In fact, Glade has passed a long process distancing itself from 'code generation'. It now only contains an XML generator, which can be called separately. I find the screen space left for Glade inside Anjuta insufficient for comfortable work anyway.
So, in conclusion: If you mainly need a GUI, consider Python + Gtk. If you do need C or C++, Anjuta is a great IDE, but look at Gtk Development examples (like this one). Following those, the use of Anjuta should be a lot clearer.
EDIT:
Very useful answer. I have some underlying legacy code that has to be
C++. Is there a way to mix Python and C++ in Anjuta, or do you know of
any guideposts or tutorials for such?
You can open a C++ project in Anjuta - maybe even import you legacy code directly as a Makefile project. You can also add new files to your C/C++ project and create them as Python files. I've never tried to do that though, and I'm not sure how Anjuta would treat them, for example, in the Makefile(s). I don't have large projects mixing languages at the moment, but for small projects, I like 'Geany', because it doesn't get in the way. You do have to maintain the Makefiles manually.

FlashDevelop / Haxe - How to Choose a Project Type

I am not a completely inexperienced developer, but I often find myself struggling with tools and workflow related questions due to not understanding the related compilation process well at all. I have worked with FlashDevelop before, and with Haxe, but one simple thing that I’ve never understood is what occurs when choosing a specific "project type" for a new project.
The primary reason I want to work with Haxe is to be able to more easily target multiple platforms, but I am very new to this. I’d like to make a play-project, a game, with the purpose of learning. One thing I would definitely like to get more experience with is the process and pitfalls of simultaneously targeting web-host-able platforms like Flash and HTML5, tablets, and potentially one day, consoles, etc. In addition, I’m told that targeting Neko can make early-game debugging easier. Finally, should I have the bulk of my 3rd party libraries chosen before deciding on this, or will all of these project types allow me roughly the same flexibility on this as well?
With that in mind, even though I have a rudimentary understanding of the differences between Flash, OpenFL, and Lime, I don’t know which project type to choose to get the best balance of flexibility and ease of setup. I found one answer that seemed to indicate that adding a second target isn’t that difficult. My instinct is to use the OpenFL Project because I have AS3 experience, but I’m not entirely in love with the Flash-centric structure of building games using the display list. Might I be better off just starting with the Haxe “Empty Project” and learning to set it all up myself?
Basically I’d just like to understand what FlashDevlop projects are, and how do I chose the appropriate one to start with Haxe, without losing flexibility to add more targets and various libraries later on.
I hope I phrased that well and that it is an appropriate question. Thank you!
Start with OpenFl project. Haxe is a language that allows you to compile your code to other language(c++,as3,js...). But it's Lime or other frameworks that make it work in all those platforms(c). OpenFl is build over Lime. OpenFl implements all the flash API, so if you know As3 that's a great place to start. You can start there implementing things and getting to know the language. You can start programming immediately, but it's cool to learn all the other cool features that as3 doesn't have.
You have other frameworks, but not all let you export to all platforms.
some popular frameworks are
http://snowkit.org/2014/09/20/about-snowkit/
http://getflambe.com/
I use openFL because I think its the easiest to use, and I think it has the biggest community.
My personal experience, I never had an experience as great as OpenFl. Flash is awesome and OpenFl is like flash on steroids. As any framework you need to know how to use it to get the most out of it.
Best of lucks!

Haxe / OpenFL / Flixel

I've been looking through the sites of Haxe / OpenFL / Flixel but am struggling to understand what each one is for.
As I understand it:
Haxe is a language that can be deployed to multiple platforms.
OpenFL is something to do with Flash.
Flixel is a library to help you make games.
Could anyone correct me/make it clearer.
Haxe
To quote from haxe.org:
Haxe is an open source toolkit based on a modern, high level, strictly typed programming language, a cross-compiler, a complete cross-platform standard library and ways to access each platform's native capabilities.
Language:
Haxe is a programming language. It's similar to AS3, C# etc. It is strictly typed, but has great type inference. It has a lot of powerful features such as Pattern Matching, Enums (ADTs), Macros etc. These work no matter which target you compile to.
Standard Library:
Haxe can compile to JavaScript, C++, Flash, Java, C#, PHP, Neko, HashLink, Python and Lua. It has low level standard classes that work consistently across platforms, such as: String, Int, Float, Date, Map etc. It also has some useful cross platform code for things like Serialization, Xml, Json, Date formatting etc.
As a general rule, anything on api.haxe.org that is in the top level, or in the haxe package, is going to work whichever target you compile to.
Each target has its own package. These let you access native capabilities of that target via externs. Eg. js.html has DOM externs, flash has externs for the Flash API, etc.
There is the sys package, which is available on "backend" targets: C++, Java, Neko, HashLink, PHP, Python and Lua. It's also available on JavaScript/Node with the hxnodejs library.
Other stuff:
The Haxe compiler is super fast compared to a bunch of other compilers. That's a selling point in itself. There's also macros, which let you do a bunch of pre-processing in a really powerful way. Then there's tools like Haxelib which let you link in with 3rd party libraries.
OpenFL
When Haxe first started, Flash was still a big target, it was installed everywhere, and it was great for making games. A lot of Flash developers liked Haxe because it was fast, type safe, open source, and gave them more features. But the flash API (sprites, graphics, movie clips, events) only worked on Flash, not on mobile, or on HTML5 etc. Which was a problem once flash started becoming less popular.
What OpenFL does is make that Flash API work on other Haxe targets. So you wrote a Haxe game targeting the flash API using sprites and graphics and flash-style code. Then, you want to compile to C++ (for targeting mobile etc). OpenFL lets your Haxe code use the Flash API, even if targeting C++ or JavaScript. For example, OpenFL creates the flash.graphics.DisplayObject class not only for flash, but for C++ and JavaScript. So if you know how to write Flash games, you are close to writing OpenFL games already.
OpenFL also has some great tools for making it easier to deploy your games to specific platforms. Where Haxe targets are things like "JS", "SWF", "C++", OpenFL platforms are things like "iOS", "Android", "Switch", "HTML5", "Windows EXE" etc. When you hear about Haxe targeting mobile, a lot of the time it is OpenFL, because it works with Haxe to compile your code (into C++, JS, SWF or whatever) and then packages those binaries for mobile.
Flixel
Haxe is a language, compiler and standard library.
OpenFL builds on this and adds the Flash API working across targets.
HaxeFlixel builds on this even further and provides game specific APIs that work on OpenFL.
An example of how it all works together:
You create a game. All of it is written in Haxe. Things like player name, scores, and completion info all use data structures from the standard library. They'll work in your game, but you could also make them work on your PHP website.
Your game uses OpenFL to compile to Flash, HTML5, iOS and Android. As part of OpenFL, you also have access to standard Flash API classes, like the Stage and Buttons and MouseEvents, which you might use for your menu screen. Because OpenFL provides the flash.* classes for other targets, your app compiles to all different things.
For your actual game, performance is important, and the flash DisplayList approach is a bit slow and not optimised for gaming. HaxeFlixel is optimised for gaming, and is very fast. So you design your game with HaxeFlixel using their APIs.
Summary
Haxe is a language, compiler, toolkit and standard library. It provides the most basic tools for cross-platform code.
OpenFL is built on Haxe, and provides the Flash API to multiple targets (Flash, C++, JavaScript) and makes it easy to compile to a bunch of platforms: web, native, iOS, Android, Nintendo Switch etc.
HaxeFlixel is built on OpenFL - it uses the APIs provided by OpenFL to create a game specific framework that is high performance and easy to make 2D games.
I just recently discovered HaxeFlixel, and I LOVE it! I came from making games in AS3 using Flixel, and now I'll probably never go back!
So, to attempt to answer your question (and the way I understand it):
Haxe is sort of the bottom layer. It's the programing language that can be compiled into Flash, Windows, Android, iOS, etc, etc, etc.
OpenFL is a software development kit which uses Haxe to make it easier and smoother to get games to work via Haxe and allow you to easily harness the power of Haxe's compatibility while not having to deal with a lot of the hassle and problems that you can get into. It takes care of a lot of the basic stuff for you and makes it easier to code.
HaxeFlixel is a 2D Game framework based on a combination of Adam Atomic's Flixel for AS3 and Flixel Power Tools by Photon Storm. It makes it easier to make 2D games in almost the same type of code as in AS3/Flixel.
When just starting out, you should only need to worry about the highest level, which in your case is HaxeFlixel.
So, to summarize a bit: Haxe is a powerful programing language. You can try to figure out how to code with it 'as-is', which is complicated, or you can use one of a number of libraries to make it easier - OpenFL is one of these libraries.
You can use OpenFL on its own, and code a game with it, or you can use one of a number of different frameworks to make it easier - HaxeFlixel is one of these frameworks. There's also the Starling and HaxePunk frameworks which have their own pros and cons.
Opinion Time!
I highly recommend sticking with HaxeFlixel - since it was so similar to Flixel, I managed to pick it up and learn how to use it, and made this complete game in exactly 1 month and released a Flash, Windows, and Android version all on the same day - which is outstanding considering I had not touched Haxe before, and had never had time to even start looking at Android Development before. That game's source code, by the way, is completely open source, so feel free to dig in and see how I did stuff.
The community for HaxeFlixel is also pretty amazing and people will help you out and answer questions.
It's really not too hard to jump in and start working with HaxeFlixel:
http://haxeflixel.com/documentation/getting-started/
Follow those steps and you'll at least have a Hello, World! up and running in minutes (excluding the time it takes to download and install all the stuff). Like I mentioned earlier, until you're more comfortable with it, just follow the directions for Haxe and OpenFL but don't even think about it for now!
Good luck! And let me know if you make it anywhere or not!

How to create Flash animations / movies on Linux? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This is more of an assignment work. I'm trying to help a friend debugging his Flash animation. Now, when I'm at his place and at his MacBook, he's using Adobe Flash to create his animation, with those timelines, the AS3 editor, etc.
Now, I want to help him while I'm at home, but I don't have a Windows or Mac computer, and I don't have a Flash license (he's got his from the school he's going to).
I know about osflash.org, but can I work the same way as he does in Flash? I need those timelines, and obviously I need to compile and preview the .swf files.
I should explain, I've never worked with Flash before, and the IDE is quite weird to me. The only way I help him, is by providing general programming skills (since AS3 is just another OO language). I was thinking of installing a cracked Flash version in a Windows VM, but that's not how I'd like to work.
Is there a better solution to this?
He's doing his work in AS3, as I mentioned.
Since you are not much familiar with the flash IDE you should be not at problem. Since the only problem with linux & flash developers is lack of decent IDE.
AS3 programs can be compiled with the flex SDK. So you simply need to download the SDK for your linux ditribution. However do note that there are no timelines in case when you develop applications with code. Instead you work with Timer events.
Flash IDE actually hides the Timer implementation in a easy usable (neat) way to provide anyone to create an application quickly.
FLA is a proprietary format for Flash CS and earlier files. No, you cannot use them with Flex compiler, because the later is an OOS software. But you can tell your friend to avoid using them. It is in fact very common to use them only to generate graphic assets, but not the code. The typical workflow is to compile SWC or SWF to use as a library and to write the code in another editor.
Anyways, some practical things:
Developing AS3 proper, you can use Intellij IDEA (some people even like it and use on other OS then Linux, to be honest, I'm not a big fan of it, but it is of the same quality as the most industry-standard level IDEs)
Your another option (which I'm using) Some good soul "ported" Flash Builder for Linux (Flash Builder is originally an Eclipse plugin developed by Adobe). It's story on Linux is fogged by a mire of inconsequential decisions. Once there was a trial version, but Adobe never released it for Linux. The trial expired, then Adobe granted continuation for the trial version. Later, they seemed to abandon the product entirely. I'm not sure of its current status, but you can find it here: https://code.google.com/p/fb4linux/
Your another option, absolutely legal, but problematic: FlashDevelop, it runs considerably well in virtualization and the devs made an effort to ensure the best they can that the virtualized version runs fine. It also runs (to an extend...) under Wine. I tried the later, but I tried it a lot time ago, it was far from being perfect, but it was workable. Here's the thread at FD forum on this: http://flashdevelop.org/community/viewtopic.php?f=9&t=7621
FDT (from Powerflashers, a commercial IDE based on Eclipse) is said to run on Linux - never tried.
What I also used: Emacs with actionscrip-mode - it is barely a syntax highlighter. While using it I added some functions to run the compiler and debugger, but they are too crappy to share them :) seriously. So I won't.
More options:
Haxe, is another language that compiles to SWF. Less well-known, but considerably more advanced and more modern language. Besides compiling to Flash does a whole bunch of other things. I've seen it used inside MonoDevelop http://haxe.org/com/ide/monodevelop (haven't used myself). Similarly, it should be possible to use it inside FDT.
Haxe mode for Emacs (I'm currently trying to improve it, but it's not there yet), hopefully, in a couple of month it will be. Here's what I've gotten for now: https://code.google.com/p/haxe-mode/
Graphics:
It seems unlikely that you can find an editor matched to Flash CS in terms of editing vector graphics for Flash, but MXMLC (Flex compiler) can fairly well compile SVG. You can thus use Inkscape to produce some non-animated graphics... but YMMV

What's the most cross-platform friendly coding language? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Let's say I want to create FPS game, let's say clone Crysis so everybody understand what type of graphics & performance I'm after. What's the best code to write this game with so it's as easy as possible to port it to all the common platforms? Of course I want the application to feel and be native to the platform. This also means that it should be easy to take advantage of Snow Leopard's new features like OpenCL and Windows 7's new features. I realize that GUI has the written separately for different platforms and that's not a problem.
So my question is that what's the best language for the job. I'm not looking for one-for-all solution but more like language for the core. I guess one way to put it is to say that what's the best language if you need to port the same program to Windows, OS X & Linux? Java is out of the question.
C (and now for some padding to reach 15 chars)
Have you ever seen the Blues Brothers? In the movie, Jake and Elwood go into a hick bar to do a gig and ask what sort of music they like, to which the woman behind the bar answers:
We have both kinds: country AND
western.
What has this got to do with this question? Well, you want to create high performance 3D graphics and you're asking what language to use?
We have both kinds: C and C++.
You probably want C for your lower level graphics performance, either the variant of C89 that Visual C++ supports, or use MinGW and gcc C99 ( VC++ 2008 doesn't support declarations in for loops in C99 code, which is very annoying, but then they didn't do that right in C++ for years ).
Admittedly, if you're taking GNU with you and running full-screen with your own GUI then it's not really cross platform any more.
You also probably want either Lua or Python or another scripting language which plays well with calling C to give a sensible higher level way of controlling the game.
C++. You can avoid millions of "if #define"'s for platform dependent things and instead use inheritance (derived classes for each platform and client using/knowing the abstract base class). A few exceptions to this can be made for the performance critical parts.
There are also lots of libraries for cross-platform development.
I really recommend using Lua for any scripting. It is an ANSI C library so that means that a: it can be compiled in (at least most) C++ compilers, and: if there's a C compiler for the platform then you can use lua. It allows for significant extension of flexibility of your game and if you want it will let your players customize it too!
Java is probably one of the easiest to learn, personally. Java though doesn't have have that great of a graphical system, it needs more code to support the graphical display if you are coding "GAMES," if you're going to code a website though choose JavaScript, CSS, and HTML/5. Or use only one of these languages normally best to choose two that best fit your comforts... =) For an FPS, I would recommend for beginners to use Java, if you have a good sense in what you want to create and it is a more complex game then use C# or C++, just because it uses less hardware if you want to make more complex games to run on multi platform.
Whatever you use you're going to have to write platform-specific code. Languages like Java or other interpreted languages (Python be my personal preference) are going to allow you to use a lot of commonalities. However, since it's not a quick and simple project, I'd suggest </intelligent-looking-padding> C or C++.
Edit: GUI doesn't necessarily have to be written from scratch for every platform. Check wxWidgets.
Most cross platform games are written in C++, because it is very good - performance wise; and its more user friendly than C. Games need maximum speed & efficiency!
You can hide away platform specific stuff behind certain abstractions and API's that you write so that you can port it easily. You can also use a cross platform framework such as Qt or wxWidgets for the window & GUI elements. Adding a scripting language to non critical parts is also nice. :)
As most have noted here, you are almost certainly going to need C/C++ for your graphics in the end particularly for your high performance (graphics) requirements.
However there might be an opportunity to develop the "core" as you call it, in a scripting language which in turn is easy to embed within a C/C++ application. In which case, the top 2 scripting languages to look into would be Lua and Tcl.
Lua in particular is used in WoW among others I'm sure. Tcl on the other hand has more "batteries included" (libraries).
I'd recommend C++ for large cross-platform projects as well. But I think what's also important are the build-tools you use. For example SCons or CMake can create project files/makefiles for most compilers under Windows/Linux/MacOS.
C is a good language, but generally you want an object oriented language for programming game. If your looking for speed, go with C++, but if you don't have much programming experience, go with python. look into the sfml and pygame libraries.

Resources