madour / ldtkloader Goto Github PK
View Code? Open in Web Editor NEWA C++11 loader for levels and tile maps created with LDtk (Level Designer ToolKit)
License: Other
A C++11 loader for levels and tile maps created with LDtk (Level Designer ToolKit)
License: Other
First of all, thanks for sharing this lib :)
For my project I set -fno-exceptions to avoid the use of noexception keyword in all functions,
I am getting this error when I try to compile LdtkLoader in my project.
to make it work I must eliminate all the throws in the optional.hpp file
Is there any possibility to remove the throws and replace them with something else without having to modify the original code?
Thanks!
nlohmann json recently got updated to 3.11.3, breaking compat with this library due to outdated included header.
Suggest either removing header or updating.
cmake --build .
[14/17] Building CXX object examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o
FAILED: examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o
/usr/bin/clang++ -I../examples/SDL/../../include -I../include -isystem /usr/include/SDL2 -MD -MT examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o -MF examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o.d -o examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o -c ../examples/SDL/main.cpp
../examples/SDL/main.cpp:10:17: error: no matching constructor for initialization of 'ldtk::World'
ldtk::World world;
^
../examples/SDL/../../include/LDtkLoader/World.hpp:22:9: note: candidate constructor not viable: requires 1 argument, but 0 were provided
World(const World&) = delete;
^
../examples/SDL/../../include/LDtkLoader/World.hpp:23:9: note: candidate constructor not viable: requires 1 argument, but 0 were provided
World(World&&) = default;
^
../examples/SDL/../../include/LDtkLoader/World.hpp:56:9: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
World(const nlohmann::json& j, Project* p, const FileLoader& file_loader, bool external_levels);
^
../examples/SDL/main.cpp:14:15: error: no member named 'loadFromFile' in 'ldtk::World'
world.loadFromFile("assets/level.ldtk");
~~~~~ ^
../examples/SDL/main.cpp:51:18: error: no member named 'position' in 'ldtk::Tile'
tile.position.x, tile.position.y,
~~~~ ^
../examples/SDL/main.cpp:51:35: error: no member named 'position' in 'ldtk::Tile'
tile.position.x, tile.position.y,
~~~~ ^
../examples/SDL/main.cpp:56:18: error: no member named 'texture_position' in 'ldtk::Tile'
tile.texture_position.x, tile.texture_position.y,
~~~~ ^
../examples/SDL/main.cpp:56:43: error: no member named 'texture_position' in 'ldtk::Tile'
tile.texture_position.x, tile.texture_position.y,
~~~~ ^
6 errors generated.
[15/17] Building CXX object CMakeFiles/LDtkLoader.dir/src/World.cpp.o
ninja: build stopped: subcommand failed.
Hey - cool library! I use it as a static library to keep the compile time of my main project small. Looking at the vcperf traces, it's still a bit of a sore spot in that regard. But I think it can be improved quite a bit:
An include of World.hpp
takes ~800ms on my machine, 69% of which is json.hpp
for example. That could be avoided with the use of its forward declarations for the necessary parameter I think. I'm sure there are other unnecessary includes but I didn't look into it in detail.
Thanks for writing this library.
I see that there are calls to get entities by id/name in a layer and also the entity defs can be gotten by id/name.
But it seems like I would need to already know all the entities I need beforehand.
So if I get a ldtk file without prior knowledge of the entities it can have, there's no way to know what id/names to call.
This method is supposed to take a position in grid coordinates, but right now the calculation is done like if the position is in pixels
World files with external levels stores paths to those levels that are relative to the world file itself. However, the current level loader simply passes the path as is, which means that trying to load any world with external levels that is not in the current working for the process directory will fail.
Looking through examples and source code and theres not alot of documentation especially around autolayer and int grids.
Any chance of some documentation updates for it?
Using any other size tileset (for example, 32x32 tiles) will cause textures to be rendered incorrectly.
hi there! in all the examples, the tilemaps are rendered on a render texture, which is then blown up to the screen's size.
but, why is it done like that?
why not just blow up the textures themselves in code, rather than drawing everything to a render texture, and then drawing that to the screen. im quite confused by this, and would love an explanation! thanks :D
I'm currently developing a game using sfml. While compiling the project, I get the following error:
g++ -g -I ../include -L ../lib ../src/*.cpp -lsfml-graphics -lsfml-window -lsfml-system -o main
C:\Users\Admin\AppData\Local\Temp\ccP5UqED.o: In function `main':
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:12: undefined reference to `ldtk::Project::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:20: undefined reference to `ldtk::Project::getWorld() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:23: undefined reference to `ldtk::World::getLevel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:24: undefined reference to `ldtk::Level::getLayer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:26: undefined reference to `ldtk::Layer::allTiles() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:30: undefined reference to `ldtk::Layer::getTileset() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:39: undefined reference to `ldtk::Tile::getVertices() const'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1
For testing purposes I copied the example code (below) for sfml and I got the same error.
#include <SFML/Graphics.hpp>
#include <LDtkLoader/Project.hpp>
#include <iostream>
int main() {
// declare a LDtk World
ldtk::Project ldtk_project;
// load the LDtk World from file
try {
ldtk_project.loadFromFile("assets/level.ldtk");
}
catch (std::exception& ex) {
std::cerr << ex.what() << std::endl;
return 1;
}
// get the world
const auto& world = ldtk_project.getWorld();
// get the level and the layer we want to render
const auto& level = world.getLevel("Level");
const auto& layer = level.getLayer("Ground");
// get all the tiles in the Ground layer
const auto& tiles_vector = layer.allTiles();
// load the tileset texture
sf::Texture tileset_texture;
tileset_texture.loadFromFile("assets/"+layer.getTileset().path);
// create the VertexArray that will store all the tiles
sf::VertexArray tilemap;
tilemap.resize(tiles_vector.size()*4); // each tile has 4 vertices
tilemap.setPrimitiveType(sf::PrimitiveType::Quads);
int i = 0;
for (const auto& tile : tiles_vector) {
auto vertices = tile.getVertices();
for (int j = 0; j < 4 ; ++j) {
// set the position and texture coordinate of each vertex
// flips are already done, you don't have to do it manually
tilemap[i*4+j].position.x = vertices[j].pos.x;
tilemap[i*4+j].position.y = vertices[j].pos.y;
tilemap[i*4+j].texCoords.x = static_cast<float>(vertices[j].tex.x);
tilemap[i*4+j].texCoords.y = static_cast<float>(vertices[j].tex.y);
}
i++;
}
// create the window and start the game loop
sf::RenderWindow window;
window.create(sf::VideoMode(level.size.x*4, level.size.y*4), "LDtkLoader - SFML");
window.setFramerateLimit(60);
sf::Event event{};
while(window.isOpen()) {
while(window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear();
// draw the tile map scaled x4
sf::RenderStates states;
states.transform.scale(4, 4);
states.texture = &tileset_texture;
window.draw(tilemap, states);
window.display();
}
return 0;
}
How can I fix this?
Note
I'm compiling my project with make and g++, c++17.g++ -g -I ../include -L ../lib ../src/*.cpp -lsfml-graphics -lsfml-window -lsfml-system -o main
Need to rewrite the way EntityFields are stored to allow null fields
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.