watabou / TownGeneratorOS

The source code of the Medieval Fantasy City Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate cpp code?

RonYanDaik opened this issue · comments

Is there a way to generate c++ code out of this source?
Internet say that Haxe can generate cpp but i can find any helpful examples or documentary.
I want to try to use generated source in UE4.

UE4 has a ton of their own macros, so it's unlikely you could use the output.
I have used Haxe with JS and Python targets, and the code generated is mangled so it's next to useless for anything other than using it directly.

The goal is to convert and use all classes/code, except rendering, to c++ and create then rendering/controling wrappers.
So I've followed these steps for now (if anyone wants to follow):

  1. I've installed Neko libs. Because haxelib needs those. (In the command line type: haxelib install hxcpp 4.1.15
  2. Then install haxelib install minimingw
  3. Then I've created cpp.hxml file in TownGenerator project source directory. File contains:
-p Source
-D windows
-m com.watabou.towngenerator.Main
--cpp outcppsource
  1. Then from project directory I'm executing: haxe.exe cpp.hxml

And the result is this.

Source/com/watabou/towngenerator/Main.hx:3: characters 8-34 : Type not found : openfl.system.Capabilities
Source/com/watabou/coogee/Game.hx:3: characters 8-29 : Type not found : openfl.display.Sprite
Source/com/watabou/coogee/Game.hx:4: characters 8-33 : Type not found : openfl.display.StageAlign
Source/com/watabou/coogee/Game.hx:5: characters 8-37 : Type not found : openfl.display.StageScaleMode
Source/com/watabou/coogee/Game.hx:6: characters 8-27 : Type not found : openfl.events.Event
Source/com/watabou/coogee/Game.hx:7: characters 8-28 : Type not found : openfl.system.System

I'm trying to find out if there is openfl c++ version.

The question is: how can I remove all rendering platform-dependend code to compile only "logic" so i could create wrappers with controls and rendering functions?

You would have to manually comment out the rendering functions in your copy of the source.

Ok. Then i need to convert to c++ first.

@Zireael07 if you've converted to JS may be you've seen these errors?

Source/com/watabou/geom/Polygon.hx:25: characters 12-16 : Unknown identifier : last
Source/com/watabou/towngenerator/wards/Ward.hx:96: characters 81-99 : Float should be Int
Source/com/watabou/towngenerator/wards/Ward.hx:96: characters 81-99 : For function argument 'x'

next i had to install:
5. again in the command line:

haxelib install msignal
haxelib install openfl
  1. in the cpp.hxml file I've had to add dependencies.
-lib openfl
-lib lime
-lib msignal

Now only listed above errors appear. Could be source Haxe version outdated?

Yep. looks like it:
https://github.com/watabou/TownGeneratorOS/pull/12/files

now only these 2 have left

Source/com/watabou/towngenerator/wards/Ward.hx:96: characters 81-99 : Float should be Int
Source/com/watabou/towngenerator/wards/Ward.hx:96: characters 81-99 : For function argument 'x'

And here i have no idea what is going on. Don't see any floats or types.

Source/com/watabou/towngenerator/Main.hx:11: lines 11-33 : Invalid -main : com.watabou.towngenerator.Main does not have static function main

I was trying to generate C# code form it to reuse this generator in a game, having the same issues.
It would be great to separate a library out of this which could be used in different languages.
A docker image would be awesome to make it easy for people that are not into Haxe.