Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSoC project: Tiled compatibility support Enigma #2302

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

KartikShrivastava
Copy link
Contributor

@KartikShrivastava KartikShrivastava commented Jun 5, 2022

In A Nutshell - This project implements two importers: .tmx/.tsx file importers in RadialGM and .egm file importer in Tiled

My GSoC project spans into three PRs in three different projects of two separate organizations. The two organizations involved are Enigma-dev and Tiled. fundies and Josh are my mentors from Enigma-dev and bjorn is my mentor from Tiled.

Requirement: You have to use Arch linux OS specifically, as Enigma-dev's RadialGM only compiles in Arch linux at the time of writing these steps. Compiling RadialGM can be tough, so feel free to ping in enigma-dev discord server.

Steps to test the project:

  1. Compile Enigma-dev's RadialGM project and Tiled projects. (Note that Enigma-dev's enigma-dev project is a submodule of RadialGM so it gets included with RadialGM)
  2. Open terminal and change directory to RadialGM, checkout to PR #228
  3. Change directory to RadialGM/Submodules/enigma-dev, checkout to PR #2302
  4. Setup a system environment variable named ENIGMA_PATH and set its value to RadialGM/Submodules/enigma-dev. This path will be used by Tiled editor's "enigma" plugin.
  5. Change directory to Tiled, checkout to PR #3435
  6. Compile RadialGM and Tiled projects separately
  7. Run RadialGM project to open RadialGM editor, test the TMX importer by importing some .tmx file
  8. Run Tiled project to open Tiled editor, enable "enigma" plugin by checking it in Edit-Preferences-Plugins tab and finally test the EGM importer by importing some .egm file

Short demo video of the final outcome: https://www.youtube.com/watch?v=ZUJd5VhqQo8
Weekly project work logs: https://kartikshrivastava.github.io/

Completed list of tasks in GSoC coding period:

Tiled TMX and TSX importer support status in RadialGM and enigma-dev:

  • Import individual TSX files
  • Replicate TSX Tileset to EGM Background
  • Import TMX file with external tileset
  • Replicate TMX Map to EGM Room
  • Replicate TMX object to EGM Room.tiles
  • Rotation, tint, horizontal/vertical flip and background color support
  • Import TMX file with internal tileset
  • Import TMX file with base64 zlib compressed tile data
  • Replicate TMX layer data to EGM Room.tiles
  • Import TMX file with base64 gzip compressed tile data
  • Import TMX file with base64 zstd compressed tile data
  • Import TMX file with CSV tile data
  • Add hexagonal map support
  • Add isometric map support
  • Add staggered isometric map support
  • Separate existing Room.proto into GameMaker based GMRoom.proto and EGM+Tiled based EGMRoom.proto
  • Add Tiled specific ObjectGroup, TileLayer and Tilesets in EGMRoom.proto
  • Update RoomView to support newly added fields of ObjectGroup, TileLayer
  • Add "merge" tmx project into egm project functionality
  • Add gtest for testing ObjectGroups correctness for importer .tmx file

Enigma's EGM importer support status in Tiled:

  • Add enigma plugin in Tiled
  • Update enigma plugin to depend on libEGM using qbs module
  • Add functionality to parse .egm file into protocol buffer
  • Add functionality to create a Tiled map using .egm based protocol buffer

Follow-up list of subtasks after GSoC:

  • Add proper separation of GameMaker resources between EGMRoom.proto and GMRoom.proto
  • Add translation routine to convert GMRoom to EGMRoom, after loading GameMaker based formats in GMRoom
  • Replicate Tiled animated tiles in RadialGM editor renderer and engine
  • Add parallax effect
  • Add more gtests
  • Add support to wangsets in TMX importer
  • Add support to rest of missing TMX features in EGMRoom (needs updates in RadialGM renderer and enigma enigne)
  • Fix Tiled ci which is breaking due to missing libEGM headers
  • Add support to missing features of internal tileset in EGMRoom

@codecov
Copy link

codecov bot commented Jun 5, 2022

Codecov Report

Merging #2302 (82cc729) into master (2ddad07) will increase coverage by 0.26%.
The diff coverage is n/a.

❗ Current head 82cc729 differs from pull request most recent head 411f672. Consider uploading reports for the commit 411f672 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2302      +/-   ##
==========================================
+ Coverage   35.27%   35.54%   +0.26%     
==========================================
  Files         213      215       +2     
  Lines       20474    20498      +24     
==========================================
+ Hits         7223     7286      +63     
+ Misses      13251    13212      -39     

see 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ddad07...411f672. Read the comment docs.

CommandLine/libEGM/tsx.cpp Outdated Show resolved Hide resolved
CommandLine/libEGM/tsx.cpp Outdated Show resolved Hide resolved
CommandLine/libEGM/file-format.h Show resolved Hide resolved
// PackRes(resMap, dir, ids, child, msg, depth + 1);
break;
}
case CppType::CPPTYPE_INT32: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same between the xml-based readers. Feel free to abstract this and use an include rather than copy-pasting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright will try

Copy link
Member

@JoshDreamland JoshDreamland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still have to look over the actual TSX logic in good detail, but here's some initial comments. Looking good so far; thank you!

@@ -86,17 +86,18 @@ message Room {
optional string name = 1;
optional int32 id = 2 [(id_start) = 10000001];
optional string background_name = 3 [(resource_ref)="background", (gmx) = "bgName"];
optional double x = 4;
optional double y = 5;
optional double x = 4 [(tmx) = "x"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this property when the tmx field has the same name? You'll notice we omit the gmx attributes when the name is he same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only loading the values of those fields which has tmx extension, rest are ignored. I also realized that number of fields not directly corresponding to tmx attributes >> number of fields which have direct link. So I decided to keep tmx for same name fields as well.

optional int32 vertical_spacing = 10 [(gmx) = "tilevsep"];
optional int32 tile_width = 5 [(gmx) = "tilewidth", (tmx) = "tilewidth"];
optional int32 tile_height = 6 [(gmx) = "tileheight", (tmx) = "tileheight"];
optional int32 horizontal_offset = 7 [(gmx) = "tilexoff", (tmx) = "margin"]; // tiled use single integer for both...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't seen the rest of the PR, yet, but are these annotations useful? Are we able to sort by tag number (in this case, 7 and 8) and just comma-separate, in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get that. Like sorting and comma-separate thing? Are you talking about proto fields extension, then it loads automatically. Here is loading logic https://github.com/KartikShrivastava/enigma-dev/blob/5614cfbd6d67e668d1170ce7a52f6ffb9f89d2f6/CommandLine/libEGM/General/tiled_util.cpp#L36

shared/libbase64_util/libbase64_util.cpp Show resolved Hide resolved
namespace enigma_user {

bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
return ::is_base64(c);
}

string base64_encode(string const& str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the header, you can just put using ::base64_encode; (etc) instead of declaring them as wrapper impls, here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did that but is not it less readable and more confusing?

@@ -0,0 +1,389 @@
#include "zlib_util.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did Robert write this? Or is this Zlib-licensed Zlib code? We should include a license header either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if its zlib-licensed code, I copied it from gmk so copied its license.

libpng_encode32_file(rgba.data(), w, h, write_fname.u8string().c_str());
}

void writeTempBGRAFile(const std::filesystem::path& write_fname, std::unique_ptr<char[]> bytes, size_t width, size_t height) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this logic go? Was it unused...? It does look a little hacky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it to zlib_util.cpp where its used, just didn't put it in Decoder class, as it wasn't there previously as well. Its static right now.

Copy link

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments based on browsing the latest changes.

CommandLine/libEGM/tmx.h Outdated Show resolved Hide resolved
tile->set_x(currX * (mapTileWidth - (hexMapUtil->hexSideLength / 2)));

if((currX%2 == 0 && hexMapUtil->staggerIndex == "odd") || (currX%2 != 0 && hexMapUtil->staggerIndex == "even"))
if((currX%2 == 0 && hexMapUtil->staggerUtil.staggerIndex == "odd") ||
(currX%2 != 0 && hexMapUtil->staggerUtil.staggerIndex == "even"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do these comparisons a lot (like, for each tile), it could be a good idea to avoid doing string comparisons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced string staggerIndex and staggerAxis with enum class members

CommandLine/libEGM/tmx.h Outdated Show resolved Hide resolved
/**
* @brief Hex map is a staggered map
*/
StaggerUtil staggerUtil;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be reasons to prefer aggregation, but in this case I would be inclined to derive HexMapUtil from StaggerUtil instead.

Regarding the naming, I'm a bit confused about the choice of "Util", since at least personally I expect a utility to do something rather than just store some data. Maybe "Info", "Parameters" or "Properties" would be more suitable (or shorter versions, if you prefer).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly I'm pretty bad at naming, updated those structs with Info suffix and inherited StaggerInfo from HexMapInfo

@KartikShrivastava KartikShrivastava changed the title WIP: Tiled compatibility support Enigma GSoC project: Tiled compatibility support Enigma Sep 8, 2022
@KartikShrivastava KartikShrivastava force-pushed the kash/tiled-comp-enigma branch 4 times, most recently from e8e7edd to 411f672 Compare July 8, 2023 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants