Giter Club home page Giter Club logo

libtcod / libtcod Goto Github PK

View Code? Open in Web Editor NEW
912.0 27.0 60.0 39.85 MB

A collection of tools and algorithms for developing traditional roguelikes. Such as field-of-view, pathfinding, and a tile-based terminal emulator.

License: BSD 3-Clause "New" or "Revised" License

Batchfile 0.01% Makefile 0.08% M4 2.38% C 44.27% C++ 40.50% Python 11.55% Shell 0.12% GLSL 0.04% CMake 1.05%
libtcod roguelikedev roguelike-library fov-algorithms pathfinding-algorithms pathfinding field-of-view noise-generator cpp c99

libtcod's Introduction

Introduction

libtcod is a free, fast, portable and uncomplicated API for roguelike developers providing a true color console, pathfinding, field-of-view, and a few other utilities frequently used in roguelikes.

Status

GitHub Workflow Status Documentation Status codecov GitHub commits since latest release (by date) Packaging status

How do I get set up?

Using Vcpkg

This is the easiest way to get the latest stable version of libtcod for any project.

Libtcod is included as a port in Vcpkg. You can install libtcod via Vcpkg and then link the library using a CMake script as you normally do for that package manager.

As a submodule

This is the best option for testing the development versions of libtcod.

You can include libtcod in a project by adding the libtcod repository as a submodule and then adding that directory to a CMake script. You will want to fork this template project if you plan on starting a project with this setup.

It is expected that Vcpkg will be used, but libtcod's CMake script can be configured to compile without using Vcpkg for dependencies. See CONTRIBUTING.md for details on configuring dependencies.

Using one of our downloads

This is not recommend as these releases are unwieldy, are more difficult to update, and are less cross-platform. Do not upload binary files to your projects source repository.

If you are programming in C or C++ then Windows and MacOS binaries are available from the GitHub Releases page.

Various C/C++ sample projects are included within the repository which can be used as examples of various features.

Keep in mind that as a C++ library, you may need to distribute the appropriate runtime with your program such as the Visual Studio 2015 runtimes or else the program will fail to run.

For those who wish to program in Python you can install python-tcod using this installation guide. Once installed you can follow the Python 3 tutorial or you can find Python example scripts on the python-tcod repository.

A alternative version of the Python library (libtcodpy) exists in the binary downloads, but you should avoid using this version as it is not as well maintained.

Compiling from source

This is only recommended for libtcod developers. See CONTRIBUTING.md.

Getting Started

The latest documentation is here. Currently it's very incomplete, so most people will want to read the 1.6.4 documentation instead. Python users should use the python-tcod documentation.

libtcod comes with a sample application, implementations of which are provided in each of C (samples_c.c), C++ (samples_cpp.cpp), and Python (samples_py.py). This provides a decent overview of the basic features, in an interactive fashion. Each should be identical for the most part, so if you are using Windows, downloading the pre-compiled binaries and running the included samples.exe which is compiled from the C source code, should be representative of the other versions.

Contact / Community

For reporting bugs or requesting features you should use the GitHub Issues page. For smaller questions or help with a tutorial or project you can join #libtcod on the Roguelikes Discord or on the Libera.​Chat IRC.

Sponsors

Sponsors donating $25 or more per month will have their names or logos listed here.

libtcod's People

Contributors

anylonen avatar artemoz avatar cottog avatar daviskauffmann avatar fabianwolff avatar flags avatar hackedsnow avatar hexdecimal avatar invisiblephil avatar itsmaxymoo avatar jalornales avatar jaydg avatar jice-nospam avatar kyzrati avatar laanwj avatar michaelmackus avatar mingos777 avatar namore avatar nataraj-hates-ms-for-stealing-github avatar noelcody avatar pre-commit-ci[bot] avatar rmtew avatar sensualcoder avatar siennasaito avatar sptramer avatar svenstaro avatar taiyu-len avatar theq629 avatar tomassedovic avatar zsparal 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

libtcod's Issues

Unable to run lua sample with error

lua: libtcodlua.lua:11: attempt to call global 'a' (a nil value)
stack traceback:
	libtcodlua.lua:11: in main chunk
	[C]: in function 'dofile'
	samples_lua.lua:2: in main chunk
	[C]: ?

Compiled libtcod from source from this repo, version 1.10.2 built following autotools intructions on (l)ubuntu bionic beaver. Using Lua 5.1.5

Refactor console data structure.

I need to put the character, foreground color, and background color values into a single struct and change the console struct to use an array of that one struct. I should also add an alpha channel to the colors for later.

The console struct was never public, so I can change it without issues, but there is a lot to change internally.

Procedural Block Elements.

I need to add the ability to generate these at runtime. A lot of methods to load a font don't have the full set and some drawing functions depend on them.

These are the glyphs which need to be generated: https://en.wikipedia.org/wiki/Block_Elements

Once this is done it will be easier to generate other types of simple glyphs.

Seperate console rendering and window present routines.

libtcod can be possessive of the SDL window sometimes, making it hard to add any kind of drawing routine in the middle of libtcod's console_flush function.

Splitting console_flush into a render_console and display_flip function would make any custom drawing onto SDL much easier.

This would also mean libtcod should be able to return the pointer to its SDL window and renderer, so that the user can access them.

Defunct Documentation

The readme links to the roguecentral.org documentation but that site seems to be defunct (the link just times out), so there is just the incomplete current documentation available.

Crash when trying to use SDL2 as renderer?

When trying to use the SDL2 renderer in TCOD_console_init_root (I'm using Visual Studio 2017), I get a "Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000." error immediately after the function is called. SDL(1) works fine.

I tried manually including the sdl2 headers, as well as manually linking the SDL2 library and includes to no avail.

SCons samples don't run on on OSX.

I seem unable to build on OSX Catalina 10.15.4

Autotools fails at the end of building: Autotools working now, please update libtcod.

libtool:   error: CURRENT '-lpthread' must be a nonnegative integer
libtool:   error: '-lpthread' is not valid version information
make: *** [libtcod.la] Error 1

scons also fails, Xcode seems to have deprecated/broken i386:

ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [libtcod-1.15.1-x86.x86_64-DEBUG-macos/libtcod.dylib] Error 1
scons: building terminated because of errors.

I noticed your travis builds are working for OSX, but it appears you are using Xcode 9. Does this work at all with updated Xcode versions? I'm just using the Xcode command line tools, installed via xcode-select --install. It would be very inconvenient to say the least to require an old Xcode installation.

is this correct

I am planning to make a roguelike but before I do that, I looked at the Readme and it said I am required to have this Visual Studio 2015 runtimes. Is Microsoft Visual C++ 2015 Redistributable (x64) -14.0.24215 the same thing?

Remove all old renderers during refactoring.

The plan is to remove all old renderers which will move everything to the new rendering contexts and tileset objects. I'll no longer need to maintain any of the old internal functions.

All existing code will still work, but will use the new renderers internally.

  • Support SDL callback in SDL2 renderer.
  • Config file support for the newer renderers.
  • Rewrite OpenGL 1 renderer for C.
  • Rewrite OpenGL 2 renderer for C.
  • Remove old SDL renderer.
  • Remove old OPENGL renderer.
  • Remove old GLSL renderer.
  • Remove old rendering code.

Rewrite Dijkstra implemenation.

The current API can only handle one goal point for Dijkstra. This locks out many popular Dijkstra tricks such as auto-exploration and safety maps.

BDF/PCF font support.

Because of how libtcod renders tiles, supporting these bitmap fonts would make a lot of sense.

It might also be nice to save tilesets as these font types, if that isn't too ambitious.

updateChar not working

In MSVC++ 2017 using libtcod 1.14.0 coupled with the SDL2 renderer the following does not actually change anything, there are no errors produced:

int base = 0x300;
TCODSystem::updateChar(base, 0, 16, mImgTest, 0, 0);
mConsole->mapAsciiCodeToFont(base, 0, 16);
mConsole->putChar(10, 0, base);

I do load a custom font with blank spaces around the standard font, doubling the size of both dimensions. I should point out that this function only works on the SDL renderer, but then literally nothing else I have comes out correctly, no matter which renderer besides SDL2 that I use i.e. regular text, standard box drawing, etc. not to mention some crashes here and there.

The custom test image DOES load and blits (regular and 2x modes) perfectly fine. It's currently one cell size of the font, which is 12x12.

I then tried updating to libtcod 1.15.1 but it still didn't work, and while the image would load and blit, blit2x produced markedly bad results.

Some field-of-view implementations are not reentrant.

There are several implementations which are using non-const global variables. These prevent the algorithms from being thread-compatible.

static int origx,origy; /* fov origin */
static ray_data_t **raymap; /* result rays */
static ray_data_t *raymap2; /* temporary rays */
static int perimidx;

/* Defines the parameters of the permissiveness */
/* Derived values defining the actual part of the square used as a range. */
static int offset;
static int limit;

static view_t **current_view=NULL;
static view_t *views=NULL;
static viewbump_t *bumps=NULL;
static int bumpidx=0;

/* angle ranges */
double * start_angle = NULL;
double * end_angle = NULL;
/* number of allocated angle pairs */
int allocated = 0;

These variables need to be moved into the stack so that they can't be overwritten by reentrant calls.

build.bat cannot find internal_function_teardown

Hello
I've tried to run the build.bat script on Win10 but got an error "cannot find internal_function_teardown"

Full log bellow
`

build.bat
'hg' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes

Usage: build.bat [OPTION]
-fd, fetch-dependencies download if necessary
-pd, prepare-dependencies extract and/or build, ready for project build
-mr, make-release construct release directory for packaging
-pr, package-release compress and archive release directory

-d, dependencies           fetch and prepare the dependencies
-p, project                build this project using the dependencies
-r, release                construct/compress/archive built project

WARNING: 'hg.exe' cannot be located. Mercurial may not be installed.
This script can operate without it, but that mode is less supported.
If Mercurial is not in PATH, you can set HG_EXE to full filename of 'hg.exe'

Le système ne trouve pas le nom de fichier de commandes - internal_function_teardown
`

OSx pkg-config fails

Hello,

A minor issue I noticed after building with autotools is the following error when invoking pkg-config with the --cflags option:

pkg-config libtcod --cflags
Package x11 was not found in the pkg-config search path.
Perhaps you should add the directory containing `x11.pc'
to the PKG_CONFIG_PATH environment variable
Package 'x11', required by 'libtcod', not found

If I manually include the cflags into my project (which just consist of the SDL2 & libtcod include headers), the samples compile just fine. This leads me to believe x11 actually isn't required (at least for MacOSx).

Console.set_key_color() not working

So, I've continued to test the Console class and the set_key_color method seems to not work.
The key_color as a blit argument works fine though.

Those lines in the blit method seems to be what's causing the issue :

        if key_color or self._key_color:
            key_color = ffi.new("TCOD_color_t*", key_color)

Context objects.

Create a portable context object to be used instead of libtcod's global singleton.

  • Add context struct.
  • Switch all renderers to use contexts.
  • Add initialization functions.
  • Add interface functions.
  • Document C functions.
  • Add C++ API.
  • Document C++ API.
  • Deprecate non-context functions.

Corrupt text when running samples_c.c

Hi, I'm currently trying to get set up for libtcod development on Ubuntu 20.04. After installing I built and ran samples/samples_c.c and got the following result:

Screenshot from 2020-07-02 15-33-24
Screenshot from 2020-07-02 15-48-02
Screenshot from 2020-07-02 15-48-07

I built and installed libtcod using autotools as described here

I built sample_c.c with the following command:

gcc samples_c.c `pkg-config libtcod --cflags --libs` `sdl2-config --cflags` `sdl2-config --libs` -lm

anyone have any idea what is going on here?

libtcod does not compile

$ scons build
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
CC -o libtcod-1.11.3-x86_64-DEBUG/src/libtcod/console_c.os -c -std=c++14 -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wuseless-cast -Wall -Wextra -Wpedantic -Wshadow=local -Wcast-align -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference -Wdouble-promotion -Wformat=2 -g -fvisibility=hidden -m64 -Wno-deprecated -Wno-deprecated-declarations -fPIC -D_REENTRANT -D_THREAD_SAFE -DLIBTCOD_EXPORTS -Ilibtcod-1.11.3-x86_64-DEBUG/src/vendor/zlib -I/usr/home/dogg/Downloads/libtcod-1.11.3/src/vendor/zlib -I/usr/local/include/SDL2 -I/usr/local/include -I/usr/home/dogg/Downloads/libtcod-1.11.3/src/vendor /usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp
warning: unknown warning option '-Wuseless-cast' [-Wunknown-warning-option]
warning: unknown warning option '-Wshadow=local' [-Wunknown-warning-option]
warning: unknown warning option '-Wduplicated-cond'; did you mean '-Wduplicate-enum'? [-Wunknown-warning-option]
warning: unknown warning option '-Wduplicated-branches' [-Wunknown-warning-option]
warning: unknown warning option '-Wlogical-op'; did you mean '-Wlong-long'? [-Wunknown-warning-option]
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:682:10: error: C++ requires a type specifier for all declarations
uint16_t bswap16(uint16_t s){
         ^
/usr/include/sys/endian.h:61:20: note: expanded from macro 'bswap16'
#define bswap16(x)      __bswap16(x)
                        ^
/usr/include/x86/endian.h:76:16: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                      ^
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:682:10: error: expected ')'
/usr/include/sys/endian.h:61:20: note: expanded from macro 'bswap16'
#define bswap16(x)      __bswap16(x)
                        ^
/usr/include/x86/endian.h:76:40: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                              ^
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:682:10: note: to match this '('
/usr/include/sys/endian.h:61:20: note: expanded from macro 'bswap16'
#define bswap16(x)      __bswap16(x)
                        ^
/usr/include/x86/endian.h:76:15: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                     ^
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:683:44: error: use of undeclared identifier 's'
        uint8_t* ps = reinterpret_cast<uint8_t*>(&s);
                                                  ^
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:691:10: error: expected ')'
uint32_t bswap32(uint32_t s){
         ^
/usr/include/sys/endian.h:62:20: note: expanded from macro 'bswap32'
#define bswap32(x)      __bswap32(x)
                        ^
/usr/include/x86/endian.h:79:27: note: expanded from macro '__bswap32'
        (__builtin_constant_p(x) ?      \
                                 ^
/usr/home/dogg/Downloads/libtcod-1.11.3/src/libtcod/console_c.cpp:691:10: note: to match this '('
/usr/include/sys/endian.h:62:20: note: expanded from macro 'bswap32'
#define bswap32(x)      __bswap32(x)
                        ^
/usr/include/x86/endian.h:79:2: note: expanded from macro '__bswap32'
        (__builtin_constant_p(x) ?      \
        ^
5 warnings and 4 errors generated.
scons: *** [libtcod-1.11.3-x86_64-DEBUG/src/libtcod/console_c.os] Error 1
scons: building terminated because of errors.
$ uname -a
FreeBSD nyann.tanasinn.mochi 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64
$ freebsd-version
12.0-RELEASE-p3

It also fails to compile when installing via pip, for different reasons/errors. I've already uninstalled pip, but I can re-install it to get those errors too, if desired.

I know C, but don't know C++ or Python so don't know how to solve this.

Minor suggestion : add a NO_BUTTON mask for MouseMotion event

Hey there,

I'm currently fiddling with the Event module.
When using a MouseMotion event, you can know if a button is pressed with the state masks but you can't check if no button are pressed.
Of course, you could just do something like

if event.state == 0:
    #Do something

But it's less clear than having a mask I think.
So my suggestion would be to have a mask for this.
What do you think ?

Emscripten Support.

Something that'd be really nice would be the ability to compile the samples to WebAssembly, and then make proper instructions on how to build WASM with other libtcod projects.

Right now I think the best method to attempt this would be to run Conan with an Emscripten profile.

I'm welcome for any suggestions on how to get this working. Anything preventing a WebAssembly build can be removed from libtcod.

Things I need to do:

  • Fix fullscreen toggle.
  • Update samples to use Emscripten.
  • Fix GLES2 renderer. (The SDL2 renderer is good enough that this is no longer a requirement.)
  • Add fallback tileset (or at least set an error.)

Build without SDL

Is it possible to build this without the SDL requirements, to enable using the utility part of the library without having bundle SDL?

Attempting to load the library dynamically will fail if SDL isn't present, even if it is unused.

Random crash when moving my mouse with exist status 11

Hey,

So I've had this issue a couple of time now, and I can't determine the exact condition under which it is happening.

When using my program, a crash may happen, I think during the mouse movement in particular.
There is no python exception raised, my application just ends and I get an exist status 11.
I thought it might be due to my setup, but maybe it is something related to libtcod.

I'm on Linux.
Tell me if you need more information or if you have an idea how to dig the problem more next time it happens.

Current font and image assets have an ambiguous copyright status.

The assets in data/img and data/fonts need to be replaced with new assets which need a more clear license for international use. The origins of the current assets are unclear, with some names implying they're derived from Microsoft fonts.

Generally, every font derived from a proprietary TrueType font needs to be removed.

  • Arial: Microsoft font, and should be removed.
  • Caeldera: Non-free font and should be removed.
  • Celtic Garamond: Non-free font and should be removed.
  • Consolas: Microsoft font, and should be removed. Could be replaced by Inconsolata.
  • Courier: This font could be free, but you'd need to know which specific version of the font was used. Otherwise this will need to be removed.
  • DejaVu: This is a known free font.
  • Dundalk: Non-free font and should be removed.
  • Lucida: Non-free font and should be removed.
  • Prestige: Non-free font and should be removed.
  • Terminal: Looks like it's based off of older DOS fonts. They don't seem to match the SDL Fonts pacakge. I'll need to do more research or replace the font.

Some images from data/fonts:

  • circle.png: Looks like engineering art used to test the colors on libtcod.
  • skull.png: At best I can trace this back to here, should probably be replaced by some actual clip art with a more clear copyright.

TrueType support.

Currently only .png/.bmp files are able to be loaded as fonts.

Will likely be implemented with FreeType.

I'll add it to the new tileset system. Which is easier for me to work on, but it will only support the new renderers.

Clarification on event.KeyboardEvent attributes behaviour

Hey,

I'm currently implementing an input field, and for this I need some clarification on how the event.KeyboardEvent attributes work.
If I'm not mistaken, the value of a key input should be in sym
Which is neat because I can in theory directly do a chr(event.sym) to put it on my input field.

The thing is, it does not work nicely with meta key (shift,altgr,etc.). And instead of having 'A' when I pressshift+a, I get the value for a
First : is this the intended behaviour ?
With a program like xev (on linux), I can get the keysym value as well, and when i press shift+a the value is definitely A, not a

So, I could get around this by manually modifying the value of sym when a modifier key is pressed (that I get with mod attribute) but that would be a lot of work and there are a lot of keyboard layout out there, so the mapping I'd be doing would work for me, but not necessarily for someone with another keyboard layout.

Is there a work around for this or is it outside the scope of tcod ?

Thanks again !

Port TCOD layout to Unicode.

I've been trying to ignore it, but it's pretty clear that the TCOD layout will need to be converted into Unicode before I can even think of removing it.

  • Invert the TCOD layout codec so that maps tiles to codepoints, instead of the other way around.
  • Add a TCOD to Unicode mapping, TCOD_chars_t could be used as a reference.
  • Deprecate TCOD_chars_t, just updating it to Unicode would be too limiting.

This should help with #51 and any other updates to the printing functions.

Problem with TCOD_NODISCARD

In trying to compile an app with libtcod 1.15.1 on macOS (Mojave and Catalina), I'm getting an error with the TCOD_NODISCARD values everywhere. I believe it's an incompatibility with clang.

libtcod/sys.h:58:17: error: 'nodiscard' attribute cannot be applied to types TCODLIB_API int TCOD_NODISCARD TCOD_sys_set_renderer(TCOD_renderer_t renderer);

libtcod/engine/display.h:195:14: error: an attribute list cannot appear here TCODLIB_CAPI TCOD_NODISCARD int TCOD_console_init_root(

libtcod/engine/display.h:197:14: error: an attribute list cannot appear here TCODLIB_CAPI TCOD_NODISCARD int TCOD_console_init_root_(

libtcod/engine/display.h:281:14: error: an attribute list cannot appear here TCODLIB_CAPI TCOD_NODISCARD int TCOD_sys_init_sdl2_renderer_(

A quick fix for this is to simply disable TCOD_NODISCARD for clang in portability.h (line 201):

#if !defined(__clang__) && defined(__cplusplus) && __cplusplus >= 201703L

I'm not a great C++ programmer, but I think the correct fix is to move TCOD_NODISCARD before TCODLIB_CAPI in each of the above lines. At least, this worked on macOS. I don't know what it does to other compilers.

SDL2 2.0.12 fails with "No available video device"

Hi,
I just did set-up a new project, built with conan which pulls SDL2 in version 2.0.12.
I use libtcod v1.16.0-alpha.12 from https://bintray.com/hexdecimal/conan/libtcod%3Ahexdecimal (via conan too).

It builds fine, but whenever I want to start the application I get:
terminate called after throwing an instance of 'std::runtime_error'
what(): libtcod 1.16.0-alpha.12 /build/.conan/data/libtcod/1.16.0-alpha.12/hexdecimal/stable/build/0ef918539b619597dc39f7f04ca3684886ea676a/src/libtcod/renderer_sdl2.c:621
Could not initialize SDL:
No available video device
Aborted (core dumped)

Seems like problem with the latest SDL2?

Random segmentation faults with samples

I got everything compiled and working, but am getting random segmentation faults with the samples. Sometimes it runs successfully, other times, not:

 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
 ~/dev/libtcod/samples (master) $
(Runs successfully)

Is this related to #13? If so, any guidance on how to avoid?

Remove C++ dependencies.

As much as I liked using C++ over C it has made the code less portable and made the C ABI harder to maintain. I now plan on rewriting the code in C and porting to C++ instead of the other way around.

The following needs to be rewritten in C:

  • New tileset objects.
  • Tileset font loader.
  • TrueType font loader.
  • SDL2 renderer.
  • OpenGL2 renderer.
  • Libtcod initialization.
  • Console UTF-8 functions.
  • Console drawing functions.
  • Console initialization.
  • Image functions.
  • Event functions.
  • System functions.
  • Compile without C++.

Replace framerate functions.

The time functions will be deprecated and removed, and users will be told to use the SDL time functions or any language specific options instead.

The only functions which can't be replaced like this are the framerate functions: TCOD_sys_set_fps, TCOD_sys_get_fps, and TCOD_sys_get_last_frame_length. These will need to be replaced with a specialized object.

  • Add clock struct.
  • Add framerate sync function.
  • Add C++ API.
  • Document C/C++ API.
  • Deprecate all other libtcod time functions.

Please migrate build scripts to Python 3

Python 2 will reach its end-of-life soon. Therefore, some Linux distributions such as Debian have recently intensified their efforts to remove dependencies on Python 2, compare e. g. Debian bug #936925 concerning the libtcod package.

The Python scripts in build/autotools/ are still using Python 2; please migrate them to Python 3 (i. e., the first line should say #!/usr/bin/env python3, and maybe some minor adjustments in the code will be necessary (I haven't tried running them with Python 3 yet, but there should be no major issues)).

TCODConsole::print(int x, int y, const std::string &str) unicode exception std::logic_error

Hello,
The following line produce a std::logic_error
TCODConsole::root->print(x + width / 2, y, std::string("plop"); produce a std::logic_error
When I use c string like:
TCODConsole::root->print(x + width / 2, y, "plop";
or
TCODConsole::root->print(x + width / 2, y, std::string("plop").c_str();
I don't get the error.

The full stack is :

 	KernelBase.dll!00007ffe2a11a839()	Inconnu
 	[Code externe]	
>	libtcod.dll!tcod::console::UnicodeIterator::parse_unicode() Ligne 895	C++
 	[Cadre en ligne] libtcod.dll!tcod::console::UnicodeIterator::operator++() Ligne 824	C++
 	[Cadre en ligne] libtcod.dll!tcod::console::FormattedUnicodeIterator::operator++() Ligne 932	C++
 	libtcod.dll!tcod::console::next_split_(tcod::console::FormattedUnicodeIterator it, const tcod::console::UnicodeIterator & end, int max_width, int can_split) Ligne 1051	C++
 	libtcod.dll!tcod::console::print_internal_(TCOD_Console & con, int x, int y, int width, int height, const std::string & string, const TCOD_ColorRGB * fg, const TCOD_ColorRGB * bg, TCOD_bkgnd_flag_t flag, TCOD_alignment_t align, int can_split, int count_only) Ligne 1109	C++
 	[Cadre en ligne] libtcod.dll!tcod::console::print(TCOD_Console * con, int fg, int bg, const std::string &) Ligne 1183	C++
 	[Cadre en ligne] libtcod.dll!TCODConsole::print(int) Ligne 278	C++
 	libtcod.dll!TCODConsole::print(int x, int y, const std::string & str) Ligne 275	C++

I'm developing on Windows with my system set in French.

Source code is available at https://gitlab.com/JasonMarechal25/roguemanager/tree/feature/GUI

A* custom heuristic function

It would be helpful to add a parameter to the pathfinding for a custom heuristic function. I'm not too familiar with the internals of the TCOD pathfinding, but looking into it it looks like you're just using straight euclidian distance for the heuristic. Perhaps adding a function argument could help simplify this, I was thinking something like:

TCOD_path_t TCOD_path_new_using_map(TCOD_map_t map, float diagonalCost, TCOD_path_func_t heuristicFunc)

This could also further simplify things by eliminating the need to maintain a separate set of functions for the Dijkstra algorithm (could just use the NULL case for heuristicFunc here). Just an idea, I've implemented something similar and it seems to work pretty well.

Heightmap lookups easily go out-of-bounds.

Heightmap logic uses a GET_VALUE macro which doesn't perform any kind of bounds checking. This causes a segmentation fault in some of the current C++ examples which use it.

Seperate mipmaps from images.

The current way mipmaps are implemented is not good. They need to be their own separate object.

  • Create a new "mipmapped image" struct.
  • New C functions for mipmaps.
  • Document C functions.
  • Add C++ API.
  • Document C++ API.
  • Deprecate old image functions.

While I'm refactoring the image struct I should make it more consistent.

  • Change images to use TCOD_ColorRGBA pixels.
  • Public documentation for the image struct.
  • C++ API for image structs.
  • Document C++ API.

allow TCOD_sys_accumulate_console to target a specific area of the display

The new SDL rendering functionality works wonderfully (thank you for that!), but I've noticed that the TCOD_sys_accumulate_console function overwrites the entire display when SDL_RenderPresent is called, even if the console specified is smaller than the main console.

Thus I have to do all my SDL manipulation after my libtcod manipulation. Not a problem in itself, but I'd like the ability to specify only a partial overwrite, so I can for example, produce something like the screen uploaded to a previous issue (#18) where this functionality was mentioned:

image

The border/bottom text is the "background" layer, then I'd use SDL to render the view, and then I blit a small libtcod console displaying the "An Encounter" message. Currently if I do a second TCOD_sys_accumulate_console the "An Encounter" is scaled up to the entire screen.

If this is a matter of adding a overrides to the wrapper function engine/display.cpp#TCOD_sys_accumulate_console to translate libtcod coordinates into SDL coordinates for the viewport parameter used in TCOD_sys_accumulate_console_(and optionally providing an alpha value) would you be open to an appropriate pull request on this?

Compiler switches for library dependencies.

Would you be opposed to adding compiler switches for the various features? Currently, libtcod requires 3 external libs from what I can tell: SDL2, zlib, and pthreads. However, some games might not need all these external dependencies in order to work properly - for example, I'm working on a simple roguelike with the only dependency being the curses library. If I could disable some/all of the above libraries, that would be helpful.

Problems Compiling Under GNU/Linux x86-64

I tried to compile Libtcod and received the following errors:

../../src/libtcod/sdl2/gl2_renderer.cpp:210:47: error: array must be initialized with a brace-enclosed initializer
   std::array<ptrdiff_t, 2> cached_size_{-1, -1};
                                               ^
../../src/libtcod/sdl2/gl2_renderer.cpp:210:47: error: too many initializers for ‘std::array<long int, 2ul>’
../../src/libtcod/sdl2/gl2_renderer.cpp:385:41: error: array must be initialized with a brace-enclosed initializer
   std::array<int, 2> cached_size_{-1, -1};
                                         ^
../../src/libtcod/sdl2/gl2_renderer.cpp:385:41: error: too many initializers for ‘std::array<int, 2ul>’

GNU/Linux version: 4.15.0-36-generic
Hardware Platform: x86-64
GCC version: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0
SDL version: 2.0.9

Translated by Deepl

Minor suggestion : add an optional default_bg/default_fg in console_new

Hey ! it's me again,

So, I've been experimenting with the deault_bg/default_fg attribute of the console object and was a bit confused why it was not working properly.
It was actually working properly, but I just wasn't using it right.
I was doing :

con = tcod.console_new(w,h)
con.default_bg = (20,20,20)

While I really should have done this :

con = tcod.console_new(w,h)
con.default_bg = (20,20,20)
con.clear()

Which I find a bit weird but it makes sense.
However, I think we could make it a little less weird by initializing the default_bg/fg when creating a new console.
Something like that would be nice :

con = tcod.console_new(w,h,default_bg = (20,20,20))

What do you think ?

Linker Errors compiling 1.16.0.alpha 8 Samples

On Ubuntu 18.0.4, trying to compile/link (using the autotools method) 1.16.0.alpha 8 I get the following linker errors linking the samples, which I believe is something to do with the version of SDL2 I have installed (according to https://askubuntu.com/questions/1160697/undefined-reference-when-using-sdl-ttf).

CCLD     samples_c
./.libs/libtcod.so: undefined reference to `SDL_RWclose'
./.libs/libtcod.so: undefined reference to `SDL_RWwrite'
./.libs/libtcod.so: undefined reference to `SDL_RWread'
./.libs/libtcod.so: undefined reference to `SDL_RWtell'
./.libs/libtcod.so: undefined reference to `SDL_RWseek'
collect2: error: ld returned 1 exit status
Makefile:1378: recipe for target 'samples_c' failed

The output of dpkg -l | grep sdl2 is:


dpkg -l | grep sdl2
ii  libsdl2-2.0-0:amd64                                              2.0.10+dfsg1-2ubuntu5~ubuntu18.04.1~ppa1         amd64        Simple DirectMedia Layer
ii  libsdl2-2.0-0:i386                                               2.0.10+dfsg1-2ubuntu5~ubuntu18.04.1~ppa1         i386         Simple DirectMedia Layer
ii  libsdl2-dev:amd64                                                2.0.10+dfsg1-2ubuntu5~ubuntu18.04.1~ppa1         amd64        Simple DirectMedia Layer development files
ii  libsdl2-image-2.0-0:amd64                                        2.0.3+dfsg1-1                                    amd64        Image loading library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-image-dev:amd64                                          2.0.3+dfsg1-1                                    amd64        Image loading library for Simple DirectMedia Layer 2, development files
ii  libsdl2-mixer-2.0-0:amd64                                        2.0.2+dfsg1-2                                    amd64        Mixer library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-mixer-dev:amd64                                          2.0.2+dfsg1-2                                    amd64        Mixer library for Simple DirectMedia Layer 2, development files
ii  libsdl2-ttf-2.0-0:amd64                                          2.0.14+dfsg1-2                                   amd64        TrueType Font library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-ttf-dev:amd64                                            2.0.14+dfsg1-2                                   amd64        TrueType Font library for Simple DirectMedia Layer 2, development files

The same error happens when trying to compile 1.15.1. Compiler versions I'm using for info:

gcc --version
gcc (Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ --version
g++ (Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

D.

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.