xaya / libxayagame

MIT License
21 stars 19 forks source link

Provide separate library with default main #10

Closed domob1812 closed 5 years ago

domob1812 commented 5 years ago

The core libxayagame is intentionally designed to be primarily a library. It makes it easy to write a game daemon, but there has to be some main function provided which handles things like configuration and command-line flags.

To make it even easier for game developers and to avoid duplicated code, we should provide a separate library that can be linked to with a "default main" that does all that. I.e. the user would still provide a main, but it would only have to instantiate the GameLogic and pass that together with the game ID to the provided default main. Standard configuration and command-line flags would be done by that.

Going one step further, we could also provide another library that has a real main function, but calls declared and not defined extern "C" functions from it for the game-specific logic. That would make it easily possible to write simple games in a language other than C++ (e.g. C#) as long as it allows to provide C-callable functions.

domob1812 commented 5 years ago

First experimental implementation of this (including the C# interop library) is in 09456de25fd2dc4ec9731333345dd5ce60efed27. Before this can be merged to master, it needs refactoring with proper unit tests and will be tested by @RyuMaster for actual usability from C#.

domob1812 commented 5 years ago

It seems that C# interop is a bit different - since C# is not linked in the normal way, it is not easily possible to "just" fill in the undefined functions from C#. Instead, it seems easier to provide callbacks in C# and pass those as function pointers to C++.

I've updated the work in progress now (30b617104a0ae251b4edb396c870122f72d16f29) to reflect that.

domob1812 commented 5 years ago

f98494484800fae2e23034732eac8950b248bf35 added a utility DefaultMain function, to make the main from mover reusable for other projects in the future.

What we should still work out here (@RyuMaster is working on it) is how to best write a C++ "main" function that can be integrated easily with C#.