Giter Site home page Giter Site logo

megamarc / tilengine Goto Github PK

View Code? Open in Web Editor NEW
797.0 38.0 93.0 25.33 MB

Free 2D graphics engine with raster effects for retro/classic style game development

Home Page: https://www.tilengine.org

License: Mozilla Public License 2.0

C 99.26% Batchfile 0.05% Makefile 0.24% Shell 0.18% CMake 0.27%

tilengine's Introduction

Tilengine logo

Tilengine - The 2D retro graphics engine

License: MPL 2.0 Build Status

Tilengine is an open source, cross-platform 2D graphics engine for creating classic/retro games with tile maps, sprites and palettes. Its unique scanline-based rendering algorithm makes raster effects a core feature, a technique used by many games running on real 2D graphics chips.

http://www.tilengine.org

Contents

Features

  • Written in portable C (C99)
  • MPL 2.0 license: free for any project, including commercial ones, allows console development
  • Cross platform: available builds for Windows (32/64), Linux PC(32/64), MacOS and Raspberry Pi
  • High performance: all samples run at 60 fps with CRT emulation enabled on a Raspberry Pi 3
  • Streamlined, easy to learn API that requires very little lines of code
  • Built-in SDL-based windowing for quick tests
  • Integrate inside any existing framework as a slave renderer
  • Loads assets from open standard standard file formats
  • Create or modify graphic assets procedurally at run time
  • True raster effects: modify render parameters between scanlines
  • Background layer scaling and rotation
  • Sprite scaling
  • Several blending modes for layers and sprites
  • Pixel accurate sprite vs sprite and sprite vs layer collision detection
  • Special effects: per-column offset, mosaic, per-pixel displacement, CRT emulation...
  • Supports packaged assets with optional AES-128 encryption

Getting binaries

Download from itch.io

The recommended way to get prebuilt binaries ready to install, run and test samples is grabbing them from official itch.io download. Just download the package for your platform, they contain required dependencies to run.

Build from source

You can also build the library from source. Tilengine requires SDL2 and libpng to build, you must provide these libraries yourself depending on your target platform.

Windows

You must provide development libraries:

Put the following files inside the src directory:

Path Files
src\libpng libpng headers
src\libpng\$(Platform) libpng.lib import library
src\sdl\SDL2 SDL2 headers
src\sdl\lib\$(Platform) SDL2.lib import library

NOTE: If you're having problems setting up these dependencies, you can download them already pre-packaged from itch.io downloads, file is windows_libs.zip. It contains headers and libraries for both 32 and 64 bit platforms.

Debian-based linux

Just install standard packages libpng-dev and libsdl2-dev

MacOS

Tilengine depends on having SDL2 in Framework format installed on your system. Homebrew port won't work. Download the latest dmg here: https://github.com/libsdl-org/SDL/releases.

Running the samples

C samples are located in Tilengine/samples folder. To build them you need the gcc compiler suite, and/or Visual C++ in windows.

Once installed, open a console window in the C samples folder and type the suitable command depending on your platform:

Windows

> mingw32-make

Unix-like

> make

The tilengine window

The following actions can be done in the created window:

  • Press Esc to close the window
  • Press Alt + Enter to toggle full-screen/windowed
  • Press Backspace to toggle built-in CRT effect (enabled by default)

Creating your first program

The following section shows how to create from scratch and execute a simple tilengine application that does the following:

  1. Reference the inclusion of Tilengine module
  2. Initialize the engine with a resolution of 400x240, one layer, no sprites and no palette animations
  3. Load a tilemap, the asset that contains background layer data
  4. Attach the loaded tilemap to the allocated background layer
  5. Create a display window with default parameters: windowed, auto scale and CRT effect enabled
  6. Run the window loop, updating the display at each iteration until the window is closed
  7. Release allocated resources

Test

Create a file called test.c in Tilengine/samples folder, and type the following code:

#include "Tilengine.h"

void main(void) {
    TLN_Tilemap foreground;

    TLN_Init (400, 240, 1, 0, 0);
    foreground = TLN_LoadTilemap ("assets/sonic/Sonic_md_fg1.tmx", NULL);
    TLN_SetLayerTilemap (0, foreground);

    TLN_CreateWindow (NULL, 0);
    while (TLN_ProcessWindow()) {
        TLN_DrawFrame (0);
    }

    TLN_DeleteTilemap (foreground);
    TLN_Deinit ();
}

Now the program must be built to produce an executable. Open a console window in the C samples folder and type the suitable command for your platform:

Windows

> gcc test.c -o test.exe -I"../include" ../lib/Win32/Tilengine.dll
> test.exe

Linux

> gcc test.c -o test -lTilengine -lm
> ./test

MacOS

> gcc test.c -o test "/usr/local/lib/Tilengine.dylib" -lm
> ./test

Documentation

Doxygen-based documentation and API reference can be found in the following link: http://www.tilengine.org/doc

Editing assets

Tilengine is just a programming library that doesn't come with any editor, but the files it loads are made with standard open-source tools. Samples come bundled with several ready-to-use assets, but these are the tools you'll need to edit or create new ones:

Creating packages

To create a package with all the assets, the add-on tool ResourcePacker must be used. It's a Windows command-line tool that creates packages with files keeping the same directory structure. Tilengine has built-in support for loading assets from these packages just as if they still were stand-alone files.

Bindings

There are bindings to use Tilengine from several programming languages:

Language Binding
C/C++ Native support, no binding required
Python PyTilengine
C# CsTilengine
C# CsTilenginePure
Pascal PascalTileEngine
FreeBasic FBTilengine
Java JTilengine
Rust tilengine-sys
LuaJIT tilengine_libretro (libretro core)
Ring RingTilengine
Nim nim-tilengine
V V-Tilengine
Go gotilengine
Zig zigtilengine
D dtilengine
Odin odintilengine
Odin odin-tilengine

Contributors

These kind users contributed to tilengine:

@turric4an - the Pascal wrapper
@davideGiovannini - help with the Linux-x86_64 port
@shayneoneill - help with the OS X port
@adtennant - provided cmake and pkg-config support
@tvasenin - improved C# binding
@tyoungjr - LUA/FFI binding
@vonhoff - provided CsTilenginePure binding
@system64MC - provided bindings for Nim an V

tilengine's People

Contributors

brunodeangelis avatar daltomi avatar exelotl avatar isaacbreen avatar lxxxxl avatar mahmoudfayed avatar mechakotik avatar megamarc avatar preemeijer avatar rjalarvo avatar t-money-g avatar thechampagne avatar thundervox avatar tvasenin avatar vonhoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tilengine's Issues

Can't load IA 32-bit .dll on a AMD 64-bit platform

I'm currently writing a game in Tilengine, and am using Java since I don't know Python or C.I added the .dll to my java.library.path, but when I launch the program it claims java.lang.UnsatisfiedLinkError: I:\Game\src\org\tilengine\engine\win32\TilengineJNI.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform (Full error: http://pastebin.com/ZduxDJqH)

I need help!

I know that this isnt really an issue, but I didn't know how to solve my problem in any other way.
I succesfully downloaded the binaries fro itch.io and I also have python and sdl2 installed, but when i try to import tilengine in python, I receive the error "no module named 'tilengine'". It's obvious to me that python does not find the module, but because I am relatively new to coding, I don't know what I did wrong. Do I have to put the files in any particular directory? I also think that a lot of relatively new coders could be stuck here as well and so the README could have a little more detailed instructions on this topic?

Add Mouse Support

I have a project I'd like to do in this engine that would require mouse support. I'm not asking for something complicated; just letting me know when a mouse button has been clicked and which pixel position on the screen (I'd expect I'd be figuring out which tile or sprite had been clicked on myself). I don't know how hard that would be to implement.

Won’t Work with latest version of SDL2

Firstly, This looks amazing and just what i was looking for! I planned to use this as a graphics engine and use SDL as the core engine, however when I try to add tilengine to my project, I get “error: uint_t redefinition” and it won’t compile.

I have tried everything and nothing seems to work, including removing SDL2 from my project but the issue there is that some of the scripts in my project require functions of SDL2 that I don’t know how/can’t replicate in tilengine, so that doesn’t work either.

float2fix's argument lacks parenthesis

Hello. I'm currently in search of works done around affine transformations to have reference results to build my own idea and I found your library like this. So far, I like to tinker around it, so I'll see later if I'm going to stick with it for some prototypes.

I just found an issue with float2fix: its implementation doesn't wrap properly its argument in the macro's expansion

#define float2fix(f)	(fix_t)(f*(1 << FIXED_BITS))

should be instead

#define float2fix(f)	(fix_t)((f)*(1 << FIXED_BITS))

Else it breaks once the the user code involves operations other than just value/variable.
(I didn't think a PR for such a microscopic change felt relevant)

Have a nice day

PNG requires redundant colours

We have a number of sprites that only have 8 colours, When trying to load the images I get an error 'Resource file has invalid format'. We realised that if we add up to 32 redundant colours, it works. We are using Fireworks CS5 and it is a challenge having to always add redundant colours for every new image. Is there something we are missing here? Any suggestions on how we can work around this issue?

Here are two examples:

shot_red_(32colors)
32 colour palette image (working)

shot_red_(8colors)
8 colour palette image (causes error)

Crash on CheckBaseObject

Hello,

I have tried to run sample mosaic.py, but it crashes with the following backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5de62b5 in CheckBaseObject () from /usr/lib/x86_64-linux-gnu/libTilengine.so
(gdb) backtrace
#0  0x00007ffff5de62b5 in CheckBaseObject () from /usr/lib/x86_64-linux-gnu/libTilengine.so
#1  0x00007ffff5de6c55 in TLN_GetSequence () from /usr/lib/x86_64-linux-gnu/libTilengine.so
#2  0x00007ffff6284ec0 in ffi_call_unix64 () from /home/user/anaconda2/lib/python2.7/lib-dynload/../../libffi.so.6
#3  0x00007ffff628487d in ffi_call () from /home/user/anaconda2/lib/python2.7/lib-dynload/../../libffi.so.6
#4  0x00007ffff649a736 in _ctypes_callproc () from /home/user/anaconda2/lib/python2.7/lib-dynload/_ctypes.so
#5  0x00007ffff6490a61 in PyCFuncPtr_call () from /home/user/anaconda2/lib/python2.7/lib-dynload/_ctypes.so

Input keys of PLAYER1 cannot be changed

Changing an input key for PLAYER1 is currently not working. I can change INPUT_UP for PLAYER2 to e. But for PLAYER1 the INPUT_UP remains the upper arrow and not the w key.

Example code:

#include <stdio.h>

#include <SDL2/SDL.h>
#include <Tilengine.h>


int main() {
    TLN_Init (400,240, 0,0,0);
    TLN_SetLogLevel(TLN_LOG_VERBOSE);

    TLN_DefineInputKey(PLAYER1, INPUT_UP, SDLK_w);
    TLN_EnableInput(PLAYER1, true);

    TLN_DefineInputKey(PLAYER2, INPUT_UP, SDLK_e);
    TLN_EnableInput(PLAYER2, true);

    TLN_CreateWindow(NULL, 0);

    int frame = 0;

    while(TLN_ProcessWindow()) {
        if(TLN_GetInput(INPUT_P1 + INPUT_UP)) {
            fprintf(stderr, "P1 - INPUT UP is pressed\n");
        }

        if(TLN_GetInput(INPUT_P2 + INPUT_UP)) {
            fprintf(stderr, "P2- INPUT UP is pressed\n");
        }

        TLN_DrawFrame(frame);

        frame++;
    }

    TLN_Deinit();

    return 0;
}

Compiling problem

There are lots of undefined references when compiling samples after the library.

Is the repository completed?

It seems lack some sources in src_lib directory because some TLN_xxxxx implementation calls cannot be found, e.g. TLN_CreateSpriteset

$ make -f Makefile_linux64
gcc Barrel.o Simon.o -o ../bin/barrel -lTilengine -lm -s -L../lib/linux64/
Barrel.o: In function LoadLayer': Barrel.c:(.text+0x8d): undefined reference to TLN_SetLayer'
Barrel.o: In function raster_callback': Barrel.c:(.text+0x127): undefined reference to TLN_SetLayerAffineTransform'
Barrel.c:(.text+0x146): undefined reference to TLN_SetLayerPalette' Barrel.c:(.text+0x17c): undefined reference to TLN_SetLayerPalette'
Barrel.c:(.text+0x1a3): undefined reference to TLN_SetLayerPalette' Barrel.o: In function main':
Barrel.c:(.text.startup+0x2b): undefined reference to TLN_Init' Barrel.c:(.text.startup+0x38): undefined reference to TLN_SetRasterCallback'
Barrel.c:(.text.startup+0x4c): undefined reference to TLN_SetBGColor' Barrel.c:(.text.startup+0x82): undefined reference to TLN_GetTilesetPalette'
Barrel.c:(.text.startup+0x91): undefined reference to TLN_ClonePalette' Barrel.c:(.text.startup+0xaf): undefined reference to TLN_GetPaletteData'
Barrel.c:(.text.startup+0x164): undefined reference to TLN_SetLayerPosition' Barrel.c:(.text.startup+0x173): undefined reference to TLN_SetLayerPosition'
Barrel.c:(.text.startup+0x19f): undefined reference to TLN_DeleteTileset' Barrel.c:(.text.startup+0x1ab): undefined reference to TLN_DeleteTilemap'
Barrel.c:(.text.startup+0x1b7): undefined reference to TLN_DeleteTileset' Barrel.c:(.text.startup+0x1c3): undefined reference to TLN_DeleteTilemap'
Barrel.c:(.text.startup+0x1cd): undefined reference to TLN_Deinit' Simon.o: In function SimonDeinit':
Simon.c:(.text+0xc): undefined reference to TLN_DeleteSequencePack' Simon.o: In function SimonSetState':
Simon.c:(.text+0x4b): undefined reference to TLN_DisableAnimation' Simon.c:(.text+0x57): undefined reference to TLN_SetSpritePicture'
Simon.c:(.text+0x71): undefined reference to TLN_DisableAnimation' Simon.o: In function SimonInit':
Simon.c:(.text+0xcf): undefined reference to TLN_FindSequence' Simon.c:(.text+0xe4): undefined reference to TLN_SetSpriteSet'
Simon.c:(.text+0xf7): undefined reference to TLN_SetSpritePosition' Simon.o: In function SimonTasks':
Simon.c:(.text+0x1db): undefined reference to TLN_GetLayerTile' Simon.c:(.text+0x216): undefined reference to TLN_SetSpritePosition'
Simon.c:(.text+0x377): undefined reference to TLN_SetSpriteFlags' Simon.c:(.text+0x392): undefined reference to TLN_SetSpriteFlags'
Simon.o: In function SimonDeinit': Simon.c:(.text+0x1c): undefined reference to TLN_DeleteSpriteset'
Simon.o: In function SimonSetState': Simon.c:(.text+0x7e): undefined reference to TLN_SetSpritePicture'
Simon.c:(.text+0x9a): undefined reference to TLN_SetSpriteAnimation' ../lib/linux64//libTilengine.so: undefined reference to TLN_CreateCycle'
../lib/linux64//libTilengine.so: undefined reference to TLN_DrawNextScanline' ../lib/linux64//libTilengine.so: undefined reference to TLN_SetTilesetPixels'
../lib/linux64//libTilengine.so: undefined reference to TLN_CreateBitmap' ../lib/linux64//libTilengine.so: undefined reference to TLN_SetRenderTarget'
../lib/linux64//libTilengine.so: undefined reference to TLN_CreateSpriteset' ../lib/linux64//libTilengine.so: undefined reference to TLN_SetPaletteColor'
../lib/linux64//libTilengine.so: undefined reference to TLN_CreateTileset' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapPitch'
../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapWidth' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetHeight'
../lib/linux64//libTilengine.so: undefined reference to TLN_DeleteBitmap' ../lib/linux64//libTilengine.so: undefined reference to TLN_SetBitmapPalette'
../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapPtr' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetWidth'
../lib/linux64//libTilengine.so: undefined reference to TLN_SetLastError' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapPalette'
../lib/linux64//libTilengine.so: undefined reference to TLN_BeginFrame' ../lib/linux64//libTilengine.so: undefined reference to TLN_CreateSequencePack'
../lib/linux64//libTilengine.so: undefined reference to TLN_CreateTilemap' ../lib/linux64//libTilengine.so: undefined reference to TLN_CreateSequence'
../lib/linux64//libTilengine.so: undefined reference to SelectBlendTable' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapHeight'
../lib/linux64//libTilengine.so: undefined reference to TLN_CreatePalette' ../lib/linux64//libTilengine.so: undefined reference to TLN_SetTilemapTile'
../lib/linux64//libTilengine.so: undefined reference to TLN_AddSequenceToPack' ../lib/linux64//libTilengine.so: undefined reference to TLN_GetBitmapDepth'
../lib/linux64//libTilengine.so: undefined reference to `TLN_UpdateFrame'

Comments and folders in English

While it's easy to translate, having everything in English makes the project more homogeneous and makes it look more "serious".

TLN_GetErrorString() Crashes C# apps

Whenever TLN_GetErrorString() is called the application immediatly closes with no error or anything, this happens in my project and both C# samples, and it makes Debugging really annoying as even the slightest issue crashes my game with no error codes, so I can't find out what I need to fix...

CRT effect looks too dark

Historically my CRT effect keeps brightnes compared to unfiltered image. Release 2.2.0 (February 2019) shows correct behavior.

I've noticed that at least release 2.4.1 shows too dark image when filtered, brightness isn't conserved. I've built it with the 2.2.0 Window.c module (responsible of all window related things, including the CRT effect) but the brightness problem persist. Baffling, must investigate in depth because no other modules are involved.

TLN_LoadSpriteset: Valgrind shows that memory is lost

When testing my projects unit tests with valgrind for memory losses, I noticed that using TLN_LoadSpriteset resulted in bytes getting lost. I reproduced this behaviour with an example program, see below. I also added the Valgrind output I got below:

gcc -lTilengine Tutorial.c && valgrind --track-origins=yes --leak-check=full -q ./a.out 
Tilengine v2.4.0 64-bit built Nov  8 2019 19:43:19
==16072== 1,044 bytes in 1 blocks are definitely lost in loss record 2 of 2
==16072==    at 0x483AB65: calloc (vg_replace_malloc.c:762)
==16072==    by 0x4892515: CreateBaseObject (in /usr/lib/libTilengine.so)
==16072==    by 0x489CA89: TLN_CreatePalette (in /usr/lib/libTilengine.so)
==16072==    by 0x489867A: ??? (in /usr/lib/libTilengine.so)
==16072==    by 0x48986FF: TLN_LoadBitmap (in /usr/lib/libTilengine.so)
==16072==    by 0x488E915: TLN_LoadSpriteset (in /usr/lib/libTilengine.so)
==16072==    by 0x109205: main (in /home/username/Downloads/Tilengine/samples/a.out)
==16072==
#include <Tilengine.h>

#define HRES	424
#define VRES	240

int main(int argc, char* argv[])
{
    TLN_Init(HRES, VRES, 1, 8, 8);

    TLN_Spriteset player;
    TLN_Sequence idle, skip;

    /* load assets */
    TLN_SetLoadPath("assets/forest");
    player = TLN_LoadSpriteset("player");

    /* create sprite sequences */
    idle = TLN_CreateSpriteSequence(NULL, player, "player-idle-", 9, 6);
    skip = TLN_CreateSpriteSequence(NULL, player, "player-skip-", 8, 6);

    TLN_ConfigSprite(0, player, 0);
    TLN_SetSpriteAnimation(0, 0, idle, 0);

    /* free sprites/sequences */
    TLN_DeleteSequence(idle);
    TLN_DeleteSequence(skip);
    TLN_DeleteSpriteset(player);

    TLN_Deinit();

    return 0;
}

C# sample attempted to read or write protected memory.

Whenever I run the C# sample, it gives me the following error:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Tilengine.Window.TLN_DrawFrame(Int32 time)
at Tilengine.Window.DrawFrame(Int32 time) in c:\Users\Dallas\Downloads\Tilengine_windows_win32\samples\csharp\Tilengine.cs:line 808
at Platformer.Main(String[] args) in c:\Users\Dallas\Downloads\Tilengine_windows_win32\samples\csharp\Platformer.cs:line 116

I copy-pasted tilengine.dll, because it is required. Also, I am using SharpDevelop.

Determining which sprites collided with each other

I am currently using Tilengine's collision detection, which works well for certain scenarios. However, from what I can tell, Tilengine has no way of determining exactly which sprite or sprites are colliding with each other. Are there any plans (or would it even be reasonably possible) for Tilengine to determine this? For example, maybe a function that returns an array of sprite indexes which are colliding with a certain sprite.

144hz and VSync

Hi Marc,

Samples and main game loop are unplayable under 144Hz (aka 144 fps). VSync is not working here...

I don't know if caused by SDL2 or by Tilengine... How can be addressed?

FR: Ability to set sprite pixels

Currently, there's no way to set pixels for individual sprite in the sprite set, so you have to build single-image sprite sheet in order to initialize sprites, and in some cases it's not convenient.

The request is to be able to set pixel data for the sprites (in the already-initialized sprite set) the same way it can be done for tiles and bitmaps.

Unable to install on MacOS

Hi,
Im having trouble installing on my mac. I've cloned the repo and have SDL2.framework install at: /Library/Frameworks/SDL2.framework

I tried this command:

Tilengine (master) $ ./sudo install
bash: ./sudo: No such file or directory

Then this:

Tilengine (master) $ sudo sh install
Installing Darwin x86_64
mkdir: /usr/lib/x86_64-linux-gnu: Operation not permitted
cp: /usr/lib/x86_64-linux-gnu: Operation not permitted
mkdir: /usr/lib/x86_64-linux-gnu/cmake/Tilengine: Operation not permitted
install: line 35: /usr/lib/x86_64-linux-gnu/cmake/Tilengine/tilengine-config.cmake: No such file or directory
mkdir: /usr/lib/x86_64-linux-gnu/pkgconfig: Operation not permitted
install: line 37: /usr/lib/x86_64-linux-gnu/pkgconfig/tilengine.pc: No such file or directory
chmod: /usr/lib/x86_64-linux-gnu/Tilengine.dylib: No such file or directory

Any ideas? :)

Sprite Not Showing Up...

I Have Created a Loader to load .gif images that is based off src_lib\loadbitmap.h but when i load a sprite using this method, nothing is displayed...

When i check the values the width, height, bit_depth and palette are all correct and assigned but the image still isn't showing up...

Here is My Code (I am using gif_lib (http://giflib.sourceforge.net) to get the data for the .gif images):

#include "..\src\GifLib\gif_lib.h"

static TLN_Bitmap LoadGIF(const char* filename)
{
	//Init
	TLN_Bitmap bitmap = NULL;
	GifFileType* Gif = DGifOpenFileName(filename, 0);
	DGifSlurp(Gif);

	//General Gif Values
	int width = Gif->Image.Width; std::cout << "Image Width = " << width << std::endl;
	int height = Gif->Image.Height; std::cout << "Image Height = " << height << std::endl;
	int bit_depth = Gif->SColorResolution; std::cout << "Colour = " << bit_depth << std::endl;

	bitmap = TLN_CreateBitmap(width, height, bit_depth);

	//Load ScanLines
	int pitch = TLN_GetBitmapPitch(bitmap);
	int l;

	for (l = 0; l<height; l++)
	{
		uint8_t* line = TLN_GetBitmapPtr(bitmap, 0, l);
	}

	//Colour Palette Values
	TLN_Palette pal;

	int palette_entries = Gif->SColorMap->ColorCount;
	int c;
	pal = TLN_CreatePalette(palette_entries);
	std::cout << palette_entries << std::endl;
	for (c = 0; c < palette_entries; c++)
	{
		TLN_SetPaletteColor(pal, c, Gif->SColorMap->Colors[c].Red, Gif->SColorMap->Colors[c].Green, Gif->SColorMap->Colors[c].Blue);
	}
	TLN_SetBitmapPalette(bitmap, pal);

	/* bitmap loaded */
	if (bitmap)
	{
		/* accept only 8 bpp */
		int bpp = TLN_GetBitmapDepth(bitmap);
		if (bpp == 8)
			TLN_SetLastError(TLN_ERR_OK);
		else
		{
			TLN_DeleteBitmap(bitmap);
			bitmap = NULL;
		}
	}

	if (!bitmap)
		TLN_SetLastError(TLN_ERR_WRONG_FORMAT);

	return bitmap;
}

Compiling on Mac.

I've been trying to get this thing porting on the mac. As an SDL project it should just compile with a few tweaks, but there seems to be a showstopper where its asking TileEngine.so before its compiled, which seems back to front, and I'm stumped as to how to fix it.

Samples failing to execute

I have a fresh install of Debian 9 (running in VirtualBox), followed the readme instructions: installed your dependencies (along with mono-complete), ran "make" and "install", and all seemed to go fine.

Following that I went into /samples/csharp, and ran "msc *.cs" to compile the Platformer.exe (which was fine), however, running it yields an unhandled exception:

System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper managed-to-native) Tilengine.Tilemap.TLN_LoadTilemap(string,string)
  at Tilengine.Tilemap.FromFile (System.String filename, System.String layername) [0x00000] in <7575f3660863472cbab376510af7a113>:0 
  at Platformer.LoadLayer (Tilengine.Layer layer, System.String filename) [0x00000] in <7575f3660863472cbab376510af7a113>:0 
  at Platformer.Main (System.String[] args) [0x00063] in <7575f3660863472cbab376510af7a113>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper managed-to-native) Tilengine.Tilemap.TLN_LoadTilemap(string,string)
  at Tilengine.Tilemap.FromFile (System.String filename, System.String layername) [0x00000] in <7575f3660863472cbab376510af7a113>:0 
  at Platformer.LoadLayer (Tilengine.Layer layer, System.String filename) [0x00000] in <7575f3660863472cbab376510af7a113>:0 
  at Platformer.Main (System.String[] args) [0x00063] in <7575f3660863472cbab376510af7a113>:0 

So I went into the /samples/c folder and ran "make", and they all compiled without a problem, but running them all give
Segmentation fault

Can't really understand why it's actually failing

Just can't get the examples to load

For all of the examples I get this message:

Traceback (most recent call last):
  File "mode7.py", line 6, in <module>
    from tilengine import *
  File "C:\Users\Finlay Laidlaw\Desktop\Tilengine\samples\python\tilengine.py", line 271, in <module>
    _tln = cdll.LoadLibrary("Tilengine.dll")
  File "C:\Users\Finlay Laidlaw\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\Finlay Laidlaw\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

I'm running Python 3.7 on Windows 10 64-bit
Please help me out, I'm relatively new to python and not very good at debugging.

Attempting To Load A Tileset With A Non 8 Multiple Size Returns A "No Error" Error

(Apologies for the issue spam, but I'm starting to try and adapt my game to use Tilengine, and I know these are the sorts of issues someone working on the project is likely to forget about/not encounter, but can really affect first impressions, so I figured I'd throw them up here as I see 'em)

The LoadTileset code isn't checking the return value of TLN_CreateTileset, and is wiping out the error message. Which, if it doesn't mention the dimension issue being the reason for the failure, it probably should.

c samples - mingw64 on windows - had to edit Makefile to run samples

thank you for the cool project, I can't wait to play with this! Wanting to play with the c samples, I ran the windows install.bat which correctly copied the 64bit dlls into the samples directory, but then ran into some issues with the make file.

on lines 8 and 9

    CFLAGS  = -m32 -msse2 -std=c99 -O2 -I"../../include"
    LDFLAGS = ../../lib/win32/Tilengine.lib -s  

I had to remove the -m32 flag and change win32 to x64. I was then able to compile and run all the cool samples.

It occurred to me that not everyone would know to do this, and it's far more likely someone will be compiling on 64bit windows I think. Maybe the Makefile should target 64bit windows?

Install doesn't work on Manjaro Linux

Builds fine, but when I run install as sudo it gives the errors:

Installing Linux x86_64
mkdir: cannot create directory ‘/usr/lib/x86_64-linux-gnu’: Not a directory
./install: line 35: /usr/lib/x86_64-linux-gnu/cmake/Tilengine/tilengine-config.cmake: Not a directory
mkdir: cannot create directory ‘/usr/lib/x86_64-linux-gnu’: Not a directory
./install: line 37: /usr/lib/x86_64-linux-gnu/pkgconfig/tilengine.pc: Not a directory
chmod: cannot access '/usr/lib/x86_64-linux-gnu/libTilengine.so': Not a directory

License and Release/UseCase

Can anyone take TileEngine and wrap or alter the GUI and release it as part of modding or end user content creation?

If someone wanted to take this code and make it as part of the game specific level editors, with hooks into the game database editor and animation editor? Think of RPGMaker style system where this would be the map element

I would like to release my first game on steam in the next year or so. It would be neat if I could release a set of tools that could work with steam workshop and general level editing.

Map making guide

There could be a guide or spec document on how to make maps and tilesets that will work, noting things like:

  • Map file and its tileset files all must be in the root of the load path (files can't be loaded from a subdirectory of the load path).
  • Tileset image is 8-bit index color
  • Tile size is power-of-2
  • Any hardcoded memory limitations - I got "out of memory" and crashes loading a map with either too many layers or too many tilesets, not sure which, but there was still plenty of system memory left. (I haven't had time to investigate this in depth.)

.Gif Support (and other minor issues)

  1. Hello! I have been working on integrating this into my project and I noticed that all my .gif files I use as assets (spritesheets) don’t load, and upon further reading it seems that (non-animated) gif files aren’t supported, are there any plans to add support for them?

  2. Also as a side note, I have developed my own animation engine for sprites that defines properties for each frame (clip rectangle, spritesheet, delay, etc.) but I am unsure how I can pass this data to the tilengine sprite class without having to write it to a text file. For example, is there a way for me to load the values from my animation file and pass them into the tilengine sprite class?

  3. Not a huge issue right now, but is there anyway that I could pass data from my own map file format to tilengine without having to remake it in tiled?

Other than that tilengine works like a dream!

[Bug] Sample Barrel, collision fails.

Hola Marc

Encontré una característica en éste bug y es que sucede en la unión del tilemap. Voy tratar de explicarme 😃
collision

Lo que ocurre en la línea

if (ti.index)
es que, en unos ciclos (~8 aprox.) del for, ti.index no se cumple por lo tanto sy no se asigna a cero.
Esto es porque en la línea
xpos = x % layer->width;
x es negativo(por lo tanto también xpos) y desde ahí cualquier ti.index es igual a cero, ya sea en Layer.c o Simon.c.

Lo solucioné agregando la siguiente línea en el archivo Layer.c :

...
xpos  = x % layer->width;
...
if(xpos < 0)
      xpos += layer->width;

Esto hace xpos positivo (xpos=2047en el join) y así se soluciona el bug.
Pero como desconozco sobre tilemaps tengo mis dudas, no se si es aquí en la librería el bug o es sólo un bug en Simon.c que hace que Layer.c (TLN_GetLayerTile) no funcione correctamente.

Nota:

TLN_GetLayerTile (0, x+c+xworld, y2+48, &ti);

x+c+xworld tiene valores entre 72 .. -21, etc.

Saludos.

Renaming python directory

There is an error with the installation file under linux.
It complains about not being able to find the python directory.
A simple change inside the bash script to upper case 'P' should do the job.

cp python/*.py $target

to

cp Python/*.py $target

Incompatibility with non indexed PNG

I was recently trying out Tilengine for a possible game idea but found that if I saved sprites using the sprite tool Aseprite (https://www.aseprite.org/), things would not load! I believe this may be a fault from the used libpng which I suggest looking into. Aseprite is open source as well.
(https://github.com/aseprite/aseprite/)
I suggest look into this soon as many sprite artists today have been using it.

I am sending too the image I saved with Aseprite. Maybe you could find what went on.

beach

SDL2 not linking correctly in OSX version (And a fix)

When using the demos with the OSX version, I get the error;-

OSError: dlopen(Tilengine.dylib, 6): Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
  Referenced from: /usr/local/lib/Tilengine.dylib

This is from the python bindings, but similar issues emerge with the C examples.

My copy of SDL2 is in the standard /usr/local/lib location (Which is where homebrew puts it. Ignore fink and macports, homebrew is more or less the standard these days).

So heres a fix!

install_name_tool -add_rpath /usr/local/lib /usr/local/lib/Tilengine.dylib

Perhaps putting this in the makefile with an $SDL_PATH type option to let folks change that for unconventional installs might be the way to go.

TLN_SetLoadPath Doesn't Check The Length Of Input Before Copying It To A Fixed Buffer

The code in question.

The buffer is a fixed size stack variable, and the code just strcpy's it in there, without checking the length. In regular use, I imagine this will never come up (as 255 must be approaching Windows maximum path length), but maybe someone exposes this to users (perhaps to allow mods) and then this is suddenly a vulnerability vector (someone downloads a malicious mod that can suddenly run arbitrary code). A longshot I know, but I'd feel wrong not pointing it out, even if it is a bit nitpicky.

Unable to install (Fedora 28)

During installation: It fails with the following error message:

[wmellema@localhost Tilengine] $ sudo ./install
Installing Linux x86_64
mkdir: cannot create directory ‘/usr/lib/x86_64-linux-gnu’: Not a directory
./install: line 35: /usr/lib/x86_64-linux-gnu/cmake/Tilengine/tilengine-config.cmake: Not a directory
mkdir: cannot create directory ‘/usr/lib/x86_64-linux-gnu’: Not a directory
./install: line 37: /usr/lib/x86_64-linux-gnu/pkgconfig/tilengine.pc: Not a directory
chmod: cannot access '/usr/lib/x86_64-linux-gnu/libTilengine.so': Not a directory

Mouse position is off

I just tried Tilengine on OpenBSD. I got it to compile and run, but am having trouble with the mouse, as it thinks the window is 3 times wider and higher than it is.

So in the TestMouse.c static void sdl_callback(SDL_Event* evt) function, I have to do the following so a mouse click finds the entity. Is there a way to fix this?

int div_x = 3; int div_y = 3; /* search clicked entity */ for (c = 0; c < MAX_ENTITIES; c++) { Entity* entity = &entities[c]; if (entity->enabled && mouse->x/div_x >= entity->x && mouse->y/div_y >= entity->y && mouse->x/div_x < entity->x + entity->w && mouse->y/div_y < entity->y + entity->h) {

Attempting To Load A PNG-24 Results In A Crash, Rather Than An Error

The fact that the formats supported does not include PNG-24 will catch a lot of people out I'd imagine. I think it should return an error indicating an invalid bitmap format, rather than a rather alarming crash as happens now.

I also think that the error message returned by TLN_GetErrorString should mention PNG8 and BMP8 somewhere in there, as it will set new users on the right path sooner rather than later.

(Side note: the only way I've found that I can create reliable PNG8 files is using an old webexport plugin for the GIMP -- the PNG8 files produced by Photoshop CS2 (the version I have available) end up with weird black corruption when displayed by Tilengine)

4:3 Aspect Ratio Option

Hello! I have looked into using Tilengine again as I've improved more on my willingness to keep on learning about gamedev, and I began to notice something peculiar about old televisions: The SNES has a framebuffer of 256x224, considered an aspect ratio of 8:7, but the result as drawn by the electron gun of a CRT would often result in a 4:3 picture! This is debated better in a video by Displaced Gamers.

It would be interesting to have this as an option in Tilengine as to be further accurate with how things actually worked on the old systems, lemme know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.