saharan / OimoPhysics

A cross-platform 3D physics engine
MIT License
852 stars 68 forks source link

TypeScript declarations #20

Closed brundonsmith closed 4 years ago

brundonsmith commented 5 years ago

Hi. I've noticed the API documentation includes type info. I've only recently become aware of Haxe, so I don't know if that type info is part of the language or not, but would it be feasible to generate TypeScript type declarations from it when building to javascript? If not, I'm inclined to try and write some manually. In case you aren't familiar:

https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#classes

saharan commented 5 years ago

Hi, I think it's possible to generate TypeScript type declarations as Haxe is a statically typed language. But I'm not sure if I can implement it (I'm not very familiar with TypeScript, and maybe heavy usage of macro is required), so any contributions would be greatly appreciated.

brundonsmith commented 5 years ago

I'm familiar with TypeScript but I'd never even heard of Haxe until very recently, so I'm afraid I would be useless at trying to create macros for it, but I can certainly give advisement on the TS side.

As a workaround for my own project, I actually wrote a little script that does a decent job scraping type info from the documentation web pages. It would be hacky, but I could probably polish it up into a more complete, fully-automated tool. Sounds like that could be much easier than trying to do this the "right" way.

fabiodr commented 5 years ago

TypeScript can compile to Wasm with AssemblyScript. But it's new, requires the code to be written with a TypeScript subset and may have another limitations.

The SIMD in browsers is coming again through Wasm, it would be great if Oimo could compile to Wasm, probably beating Bullet performance in browsers.

brundonsmith commented 5 years ago

@fabiodr I think you misunderstand. Oimo is written in Haxe, not JavaScript. It is compiled in this case from Haxe (a typed language) to plain JavaScript (an untyped language). My interest was in preserving the Haxe type info in the form of TypeScript declaration files (.d.ts) to be shipped optionally alongside the actual .js build, for those who are using it in a TypeScript context.

fabiodr commented 5 years ago

@brundonsmith sorry, i didn’t make my thoughts clear, it’s very nice to have type definitions but i was just wandering it would be great if Oimo could be ported to a language with Wasm as compilation target, i believe C++ or Rust are a better choices now but TypeScript is also becoming a good one, with clear syntax and more similar to Haxe :)

Maybe this project can help to do a small convert test project, it separates the generated javascript files and create typescript declarations. But probably won’t behave well with Oimo macros.

I checked before if Haxe has Wasm target but unfortunately i found only an integration to do Wasm calls without overhead and there is no roadmap for Wasm compilation yet.

fabiodr commented 5 years ago

One more side-note: Oimo.js is much better known than original Oimo and this last and improved version, because it is ported to JS, a language that engage more people on the web.

TypeScript also would invite more people to try and collaborate, giving Oimo the attention it deserves.

brundonsmith commented 5 years ago

I tried Oimo.js; it's incomplete, the API is not as good, and as far as I can tell it's no longer being maintained. I made a feature request and the developer pointed me back to this repository.

fabiodr commented 5 years ago

Yeah, Oimo.js is based on an old Oimo ActionScript version (which can be found in this repo), this new Haxe version has a lot of improvements, including many joints, precision and performance.

mrEuler commented 4 years ago

@brundonsmith We are on the finish line with TS declarations, so I will keep everybody here posted

saharan commented 4 years ago

I'm sorry for leaving this issue for a long time, and thank you for your all efforts!

I've been trying to use hxtsdgen, but it doesn't seem to be straightforward; hxtsdgen uses @:expose notations to detect types to declare, but OimoPhysics doesn't use @:expose to export the classes (I don't remember clearly, but there were some problems using expose notation I guess).

I think it's preferable to generate TS declarations automatically, so I would switch to use @:expose notations in future versions.

mrEuler commented 4 years ago

@saharan @brundonsmith If you could like this pull request: https://github.com/elsassph/hxtsdgen/pull/35

mrEuler commented 4 years ago

25