PDA

View Full Version : Tilengine 2D Pascal Wrapper!



turrican
26-07-2016, 05:07 PM
Hi pascals,

I'm here to promote my little Pascal wrapper for Tilengine Library.

Tilengine is a Retro Raster based library to develop 2D complete games.

The engine library is coded in C++ and has most language language wrappers (C#, Phyton...) and now Pascal.

You can find here : http://www.tilengine.org

You can find the source here : https://github.com/megamarc/Tilengine

Pascal Wrapper only works with Delphi and FPC under windows from the moment but will be tested on linux ASAP.

Enjoy!

Ñuño Martínez
01-08-2016, 10:40 AM
Looks very interesting.

Does it include other stuff as user input and sound, or is it just graphics?

[edit] I've read the documentation intro (http://www.tilengine.org/documentation.htm). Seems to include some user input but no sound. I wonder if it is worth to use it along with Allegro or SDL. ::)

megamarc79
31-08-2016, 09:38 AM
Hello folks!

I'm the author of Tilengine. It is entirely written in C (not C++). Currently it's available for Windows x86 and x64, Linux, Raspberry Pi (Raspbian) and Android. Besides its native C interface, it has wrappers for Java, Python, C# and Pascal.

It's not a complete game development kit, it's specifically a graphics-only library. Think of it as a kind of virtual 2D graphics chip that must be paired with other components.

It was originally designed without any windowing system, you must provide an external surface for rendering in a compatible pixel format. In this way you can use Tilengine in a SDL application, an OpenGL texture, a Java applet, or whatever framework of your choice. Although very flexible, this approach makes initial steps difficult, because you have to setup an external environment first. For this reason I added a simple built-in windowing with user input, mimicking the controls of a basic arcade cabinet. This windowing system is built on top of SDL for portability and ease of implementation, and it's now easier to setup samples and tests. However this windowing is not intended to be very complete or used in big projects. The initial approach of integrating inside an external environment/framework is still preferred.

As for its suitability for being used in game development despite of its lack of sound or elaborated input, yes of course! It's like discarding OpenGL, FMOD Ex or Box2D for being graphics-only, sound-only or physics-only.

Please feel free to ask any other question.
Enjoy!

ironquark
31-08-2016, 12:01 PM
Hi pascals,

I'm here to promote my little Pascal wrapper for Tilengine Library.

Tilengine is a Retro Raster based library to develop 2D complete games.

The engine library is coded in C++ and has most language language wrappers (C#, Phyton...) and now Pascal.

You can find here : http://www.tilengine.org

You can find the source here : https://github.com/megamarc/Tilengine

Pascal Wrapper only works with Delphi and FPC under windows from the moment but will be tested on linux ASAP.

Enjoy!

Great work!

Can you provide a Super Mario clone with pascal source code?

You've a world editor to create the Super Mario Levels?

See ya!

megamarc79
02-09-2016, 07:28 AM
Great work!

Can you provide a Super Mario clone with pascal source code?

You've a world editor to create the Super Mario Levels?

See ya!

The SuperMarioClone sample was written in C# to showcase the wrapper for this language, which is very different than the pascal wrapper. Having a version of SMC in Pascal would require a full rewrite of the sample. However, anybody is encouraged to do the work, of course! I'll be glad to include it in the official package citating the author.

To edit the maps of all the samples (including super mario clone) I use the open source Tiled Map Editor (http://www.mapeditor.org/), Tilengine reads its file format natively.

Regards!

ironquark
02-09-2016, 01:31 PM
The SuperMarioClone sample was written in C# to showcase the wrapper for this language, which is very different than the pascal wrapper. Having a version of SMC in Pascal would require a full rewrite of the sample. However, anybody is encouraged to do the work, of course! I'll be glad to include it in the official package citating the author.

To edit the maps of all the samples (including super mario clone) I use the open source Tiled Map Editor (http://www.mapeditor.org/), Tilengine reads its file format natively.

Regards!

I'm glad to know about Map Editor thank you very much!

Ñuño Martínez
05-09-2016, 09:12 AM
Hello folks!

(...) you must provide an external surface for rendering in a compatible pixel format. (..) I see. That's the hard thing.

This works also in the other direction? I mean, loading/creating bitmaps with an external library (SDL, for example) and use them as tiles and sprites.

Super Vegeta
05-09-2016, 11:58 AM
Both in SDL1 and SDL2, when you create surfaces, you can specify the pixel format - when you create an RGB texture, you need to specify the R,G,B,A-masks. You can have RGBA, ABGR or whatever you really want (although with some pixel formats, SDL's "draw line" / "fill rect" functions seem buggy and may draw a blue rectangle instead of a red one). So I guess you could try creating a Tilengine-compatible surface that way.

megamarc79
05-09-2016, 06:23 PM
Both in SDL1 and SDL2, when you create surfaces, you can specify the pixel format - when you create an RGB texture, you need to specify the R,G,B,A-masks. You can have RGBA, ABGR or whatever you really want (although with some pixel formats, SDL's "draw line" / "fill rect" functions seem buggy and may draw a blue rectangle instead of a red one). So I guess you could try creating a Tilengine-compatible surface that way.

Tilengine uses an ARGB pixel format for 32 bpp, and packed 565 RGB for 16 bpp. Both formats are broadly supported almost anywhere.

megamarc79
05-09-2016, 06:39 PM
This works also in the other direction? I mean, loading/creating bitmaps with an external library (SDL, for example) and use them as tiles and sprites.
Yes! I wrote the loaders to support Tiled file formats (based on xml and png), but you can implement your own. The API has several functions to build the assets at runtime in memory, actually my standard loaders use those functions internally. Please check the GitHub (https://github.com/megamarc/Tilengine/tree/master/src_lib)project, the modules LoadTileset.c (https://github.com/megamarc/Tilengine/blob/master/src_lib/LoadTileset.c)and LoadTilemap.c (https://github.com/megamarc/Tilengine/blob/master/src_lib/LoadTilemap.c)for example. Using them as a reference, you can build yours. Source is C language, but the pascal wrapper is a very thin direct translation of the API, you'll get the point easily.

The website and GitHub project are a bit outdated, but I'm working to push the current updates and download links. Tilengine has now builds for Raspberry Pi and Android, and the new 16 bpp format for mobile GPUs that don't handle well 32 bpp textures. Managing so much target platforms, language wrappers and examples is becoming increasingly difficult!

SesillaAndromeda
06-09-2016, 09:59 AM
Hi megamarc79,

on website there are some examples but i don't found Pseudo 3D road (scaling). Can you share some example about it?

Thanks
Sesilla

megamarc79
07-09-2016, 01:42 PM
Hi megamarc79,

on website there are some examples but i don't found Pseudo 3D road (scaling). Can you share some example about it?

Thanks
Sesilla
The scaling pseudo 3d road is an unfinished sample I was working on. The still image appears ok, but the effect in motion is wrong so I didn't publish the source code. It's not a limitation of the engine, but a misunderstanding on how to implement the effect corrctly. Some real games that used this technique properly were Namco's Final Lap and Suzuka 8 hours series.

turrican
23-09-2016, 12:10 PM
Hi Pascals and Megamarc!

I was on my break time and unable to read the post responses, sorry.

Thanks to Megamarc for the awesome library!

I will try to port/translate Tilengine Super Mario to Object Pascal with Tilengine Object Pascal Wrapper.

megamarc79
04-01-2017, 02:34 PM
v1.10 released


Improved animation engine with new tileset sequencer
Improved spriteset loader with new csv format compatible with Leshy SpriteSheet Tool (https://www.leshylabs.com/blog/posts/2013-12-03-Leshy_SpriteSheet_Tool.html)
New blending mode: modulation
Many small bugfixes and improvements
New "SuperMarioClone" sample that showcases many of the new features

Thyandyr
29-05-2017, 02:06 PM
Fascinating https://www.youtube.com/watch?v=dgvYnyQ2sjA&feature=youtu.be

Thyandyr
01-06-2017, 05:12 PM
For Delphi on Windows

1) Change project output directory to ..\..\..\bin\
2) In Benchmark method CreateWindow('A', CWF_NONE); instead of CreateWindow(nil, CWF_NONE);
3) Copy everything from Tilengine-master\lib\win32 to Tilengine-master\bin
4) Compile
5) Open command promt to Tilengine-master\bin
6) Run TileEngine_Benchmark.exe

Now... that makes the benchmark work. I still have no idea what it does, some odd stuff appears on a window and the exe exits gracefully.


C:\Users\Admin\Downloads\Tilengine-master\bin>TileEngine_Benchmark.exe
Tilengine benchmark tool ObjectPascal
http://www.tilengine.org
Normal layer..........
217194570 pixels/s.
Scaling layer..........
331034483 pixels/s.
Affine layer..........
64602961 pixels/s.
Blend layer..........
132780083 pixels/s.
Scaling blend layer...
204255319 pixels/s.
Affine blend layer....
54825814 pixels/s.
Affine blend layer....
423841060 pixels/s.
Colliding sprites......
228571429 pixels/s.

C:\Users\Admin\Downloads\Tilengine-master\bin>

CPU 12.5%

The same project in C outputs:


Tilengine benchmark tool
Written by Megamarc - Jun 1 2017 19:20:44
Library version: 1.13.0
http://www.tilengine.org

Syntax: benchmark format
format : pixel format (16 or 32)

C:\Users\Admin\Downloads\Tilengine-master\bin>

PS. Got to love the authentic look of old CRT pixels

Thyandyr
01-06-2017, 05:47 PM
var
Version: Integer;

Begin
// Get version
Version := uTileEngine.GetVersion;
Writeln(
'Library version: ' + ((Version shr 16) and $FF).ToString +
'.' + ((Version shr 8 ) and $FF).ToString +
'.' + (Version and $FF).ToString
);

This adds the version number in Delphi as it is the C example.

Thyandyr
01-06-2017, 07:01 PM
// load layer (tileset + tilemap)

// tileset = TLN_LoadTileset ("Sonic_md_bg1.tsx");
tileset := uTileEngine.LoadTileset('Sonic_md_bg1.tsx');

// tilemap = TLN_LoadTilemap ("Sonic_md_bg1.tmx", "Layer 1");
tilemap := uTileEngine.LoadTileMap('Sonic_md_bg1.tmx', 'Layer 1');

Commented lines are from the C example.

Pascal header:
function LoadTileset(filename : string) : Pointer; cdecl; external dllname name 'TLN_LoadTileset';
function LoadTilemap(filename, layername : string) : Pointer; cdecl; external dllname name 'TLN_LoadTilemap';

Should be:
function LoadTileset(filename : PAnsiChar) : Pointer; cdecl; external dllname name 'TLN_LoadTileset';
function LoadTilemap(filename, layername : PAnsiChar) : Pointer; cdecl; external dllname name 'TLN_LoadTilemap';

and possibly for many others lines in the header...

Thyandyr
01-06-2017, 07:06 PM
How do I use this without the built-in windowing?

SetRenderTarget sounds like it might do the trick, but how do I get pointer to a framebuffer in VCL?


TLNAPI void TLN_SetRenderTarget (
uint8_t * data,
int pitch
)

Sets the output surface for rendering.
Parameters

data
Pointer to the start of the target framebuffer


pitch
Number of bytes per each scanline of the framebuffer




I don't get this command. What sort information can be passed in 8 bit pointer? Memory address for lego computer?

The source is not included so I cannot go look there what is done with the 'data'. Can you add a function returning the array of data created and let the users do what they want with it?

Haaalp plz I don't understand!

turrican
05-06-2017, 08:23 AM
I will ask megamarc and return here with answers. ;)

turrican
05-06-2017, 08:27 AM
// load layer (tileset + tilemap)

// tileset = TLN_LoadTileset ("Sonic_md_bg1.tsx");
tileset := uTileEngine.LoadTileset('Sonic_md_bg1.tsx');

// tilemap = TLN_LoadTilemap ("Sonic_md_bg1.tmx", "Layer 1");
tilemap := uTileEngine.LoadTileMap('Sonic_md_bg1.tmx', 'Layer 1');

Commented lines are from the C example.

Pascal header:
function LoadTileset(filename : string) : Pointer; cdecl; external dllname name 'TLN_LoadTileset';
function LoadTilemap(filename, layername : string) : Pointer; cdecl; external dllname name 'TLN_LoadTilemap';

Should be:
function LoadTileset(filename : PAnsiChar) : Pointer; cdecl; external dllname name 'TLN_LoadTileset';
function LoadTilemap(filename, layername : PAnsiChar) : Pointer; cdecl; external dllname name 'TLN_LoadTilemap';

and possibly for many others lines in the header...

Thanks for your changes! Do a pull request in the repo

megamarc79
08-09-2017, 02:59 PM
I see some recent activity here I didn't know :-)


How do I use this without the built-in windowing?
SetRenderTarget sounds like it might do the trick, but how do I get pointer to a framebuffer in VCL?

The two parameters required are returned by the typical "lock" function in many systems to get direct pixel acces to a video surface. Check the source code of the built-in windowing based in SDL2. This is what it does at line 785 on a SDL-based surface backbuffer:
https://github.com/megamarc/Tilengine/blob/master/src_lib/Window.c

Pascal wrapper
This wrapper was originally submitted by turrican, but as Tilengine evolves this wrapper is getting out of sync because it's not being updated anymore. It also lacks any example and build procedure for this language. To keep this language supported, someone should update the binding and provide a pascal version of any of the examples.

Support
Tilengine has its own dedicated forum, with threads in english and spanish. You can reach them here:
http://www.tilengine.org/forum/index.php

Darkhog
17-07-2018, 06:56 PM
I'd like someone to update it to the most current version of the Tilengine. And maybe provide a graphical Lazarus component, perhaps descendant of TImage (so we wouldn't need to worry about repainting it and it'll be easy to write screenshots) with set of events so we could utilize Tilengine in an OOP manner. Obviously it's not THAT important, but it would be good to have it, not to mention it would make development easier since the built-in windowing is weak and not many have enough skills to setup their own aside of putting components on a form.

turrican
30-10-2018, 09:51 PM
Here is the last version of the wrapper :

And is improved : https://github.com/turric4n/PascalTileEngine