Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tilengine as libretro core with LUA games
#1
I'm working on an experimental version of tilengine. It's a libretro core with loadable games written in lua. Libretro cores are plugins that can be run inside Retroarch emulation environment, which provides unified input and windowing with post-processing shaders.

To be able to load many tilengine-based games from a single core, I integrated luajit parser inside it, so the game logic is implemented in external LUA script. This script must define the following items:
  • a config {} table with initialization parameters
  • a game_load() function that loads assets and performs initial game setup
  • a game_loop(frame) function that gets executed every frame
  • a game_unload() function that gets called when closing the game
The input is still not implemented, so only non-interactive demos are working right now. And as the system depends on luajit and retroarch, only Windows versions are tested.

User -> RetroArch <-> tilengine_libretro <-> game.lua

Maybe this experiment is a dead end, but it looks promising and it's a great integration example.

You can check progress in this GitHub branch:
https://github.com/megamarc/Tilengine/tree/libretro

This is the basic "game":
https://github.com/megamarc/Tilengine/bl...e/game.lua

Let me know what you think


Attached Files Thumbnail(s)
   
#2
Raster effects already implemented. Added LUA_SetFrameCallback() and LUA_SetRasterCallback() functions to be called from the lua script.
#3
Hi,
I tested it on Linux (ArchLinux x64) making some modifications.

https://github.com/daltomi/Tilengine/tre...etro-linux

Thanks.


Attached Files Thumbnail(s)
   
#4
This is great Biggrin
I see you have taken inspiration from my post earlier!
I have had this on my to-do list for a long time, but never got around to doing it yet (extremely busy with other things).
This will be extremely useful for me, I was about to do all of this myself. Thanks for making this!

I have some questions about this, however.
How easy is it to port existing code to retroarch without separately maintaining multiple code bases?
What about using libraries like SDL2 and SDL2 Mixer?

Another thing, if you will be writing a lot of Lua, I suggest setting up ZeroBrane Studio (https://studio.zerobrane.com/), a Lua IDE.
It is extremely extendable, and if you look through the documentation enough, you will be able to do things like integration with your own interpreter (the retroarch core), API definitions, line-by-line debugging, and autocomplete.
It makes life so much easier, and I have configured it to where it runs a program I wrote that compiles all Lua files to bytecode, exports all my assets, and puts it all into a package, so it isn't as much of a hassle at it used to be.
#5
Yes I was thinking about how to integrate tilengine as a libretro core for some time but I didn't know how to handle loadable games. The conversation about lua gave me the missing piece Smile
The integration itself was quite simple:
  • removed all the built-in windoinwg support (Window.c and GaussianBlur.c), and libSDL2 dependency,
  • added a libretro.c module that implements both the client-side to retroarch, and the host-side of lua scripts
Everything else are the same tilengine modules without any modification. I created a separate branch to not mess up the main project, but it can be maintained as two separate makefiles of the same codebase with minimal differences.

The difficult part is debugging the lua script. This two-way integration -retroarch hosts tilengine_libretro, who in turn hosts the lua script-. This setup is far from your typical "launch your application and set up breakpoints". I'll give a look to your recommended "ZeroBrane Studio" and "Decoda" IDE. However I won't spend much time on this project, once I get something fully working I'll move to work on other ideas I have. Managing to get a Lua debugger working inside this chain of hosts can be more complex than completing tilengine_libretro itself.


Forum Jump:


Users browsing this thread: 1 Guest(s)