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

Big tilemap/map rework #861

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4bbc897
Make case consistent in TileMap related enums
Daft-Freak Sep 20, 2024
4161047
Store load flags in TileMap and free data if we copied it
Daft-Freak Sep 20, 2024
a2a9530
Add a new TiledMap class that wraps TileMap and handles layers
Daft-Freak Sep 20, 2024
e6e7c6d
Move LoadFlags out and dedup
Daft-Freak Sep 21, 2024
2fbd568
Split a TileLayer base class out of TileMap
Daft-Freak Sep 21, 2024
aca6018
Add "simple" tile layer that doesn't do any of the per-scanline trans…
Daft-Freak Sep 21, 2024
68f6d97
Rename TileMap -> TransformedTileLayer
Daft-Freak Sep 21, 2024
58a62c6
Adjust SimpleTileLayer range for negative repeat
Daft-Freak Sep 21, 2024
fadfc48
Copy optimised offset to TransformedTileLayer, de-optimise and remove…
Daft-Freak Sep 21, 2024
bf2035e
Prepare load_tmx for 16-bit tiles
Daft-Freak Sep 21, 2024
e318e78
Handle 16-bit tile ids
Daft-Freak Sep 22, 2024
eee976f
Uncomment and fix TransformedTileLayer::mipmap_texture_span
Daft-Freak Sep 23, 2024
4309427
Hide texture_span 8/16-bit template selection
Daft-Freak Sep 23, 2024
a0aa2d6
Optimise mipmap_texture_span slightly
Daft-Freak Sep 23, 2024
0557086
Dedup most of load_tmx
Daft-Freak Sep 23, 2024
bacf6dc
Support loading maps from files
Daft-Freak Sep 23, 2024
0e3f1e9
Load TiledMap layer names
Daft-Freak Sep 24, 2024
abffb47
Add helpers to get tiled map layer by name
Daft-Freak Sep 24, 2024
2ffd0db
Avoid circular include issue with mode7/tilemap
Daft-Freak Jan 6, 2022
1ddabbb
Trailing whitespace cleanup in tilemap
Daft-Freak Sep 24, 2024
17104cb
Remove unimplemented world_to_scale declaration
Daft-Freak Sep 24, 2024
13b4dc5
Port mode7 to TransformedTileLayer
Daft-Freak Sep 24, 2024
2735331
Add flags code similar to the Map class
Daft-Freak Sep 24, 2024
1245849
Add method to set layer tiles
Daft-Freak Sep 25, 2024
5915a9c
Remove Map class
Daft-Freak Sep 25, 2024
7433f19
Rework mippmap index calculation
Daft-Freak Sep 25, 2024
3996646
WIP: ci: point at examples branch so things build
Daft-Freak Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/Emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: 32blit/32blit-examples
ref: one-map-to-tile-them-all #FIXME
path: 32blit-examples

- name: Install deps
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Visual Studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: 32blit/32blit-examples
ref: one-map-to-tile-them-all #FIXME
path: examples

- name: Install deps
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: 32blit/32blit-examples
ref: one-map-to-tile-them-all #FIXME
path: examples

# pico sdk/extras for some builds
Expand Down
1 change: 0 additions & 1 deletion 32blit/32blit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "graphics/tilemap.hpp"
#include "math/constants.hpp"
#include "math/interpolation.hpp"
#include "types/map.hpp"
#include "types/mat3.hpp"
#include "types/mat4.hpp"
#include "types/point.hpp"
Expand Down
1 change: 0 additions & 1 deletion 32blit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ set(SOURCES
graphics/tilemap.cpp
math/geometry.cpp
math/interpolation.cpp
types/map.cpp
types/mat3.cpp
types/mat4.cpp
types/vec2.cpp
Expand Down
21 changes: 10 additions & 11 deletions 32blit/graphics/mode7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "../graphics/font.hpp"

namespace blit {


// TODO: Provide method to return scale for world coordinate

/**
* TODO: Document
*
*
* \param[in] w
* \param[in] fov
* \param[in] angle
Expand All @@ -29,7 +29,7 @@ namespace blit {
* \param[in] viewport
*/
Vec2 world_to_screen(Vec2 w, float fov, float angle, Vec2 pos, float near, float far, Rect viewport) {
float hfov = fov / 2.0f;
float hfov = fov / 2.0f;

Vec2 v(w - pos);
v.normalize();
Expand All @@ -46,7 +46,7 @@ namespace blit {
float pd = ctd / cosf(hfov);

float theta_sign = std::copysign(1.0f, theta);

float hsl = sqrtf((pd * pd) - (ctd * ctd));
float so = hsl + (sqrtf((wd * wd) - (ctd * ctd)) * theta_sign);
float r = so / (hsl * 2.0f);
Expand All @@ -55,13 +55,13 @@ namespace blit {
r * viewport.w,
((far - near) / (pd - near)) + viewport.y
);

return s;
}

/**
* Convert a screen coordinate to a mode7 world-space coordinate.
*
*
* \param[in] s vec2 describing the screen coordinate
* \param[in] fov Current camera field-of-view
* \param[in] angle Current camera z-angle in mode7 world-space
Expand All @@ -81,7 +81,7 @@ namespace blit {
right *= Mat3::rotation((fov / 2.0f));

float distance = ((far - near) / float(s.y - viewport.y)) + near;

Vec2 swc = pos + (left * distance);
Vec2 ewc = pos + (right * distance);

Expand All @@ -93,7 +93,7 @@ namespace blit {

/**
* TODO: Document
*
*
* \param[in] dest
* \param[in] sprites
* \param[in] layer
Expand All @@ -104,7 +104,7 @@ namespace blit {
* \param[in] far
* \param[in] viewport
*/
void mode7(Surface *dest, Surface *sprites, MapLayer *layer, float fov, float angle, Vec2 pos, float near, float far, Rect viewport) {
void mode7(Surface *dest, TransformedTileLayer *layer, float fov, float angle, Vec2 pos, float near, float far, Rect viewport) {
for (int y = viewport.y; y < viewport.y + viewport.h; y++) {
Vec2 swc = screen_to_world(Vec2(viewport.x, y), fov, angle, pos, near, far, viewport);
Vec2 ewc = screen_to_world(Vec2(viewport.x + viewport.w, y), fov, angle, pos, near, far, viewport);
Expand All @@ -113,7 +113,6 @@ namespace blit {
dest,
Point(viewport.x, y),
viewport.w,
sprites,
swc,
ewc);
}
Expand All @@ -122,5 +121,5 @@ namespace blit {
dest->pen = Pen(255, 0, 255);
dest->pixel(s);
}

}
7 changes: 3 additions & 4 deletions 32blit/graphics/mode7.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include <cstdint>

#include "surface.hpp"
#include "../types/map.hpp"
#include "tilemap.hpp"

namespace blit {

void mode7(Surface *dest, Surface *tiles, MapLayer *layer, float fov, float angle, Vec2 pos, float near, float far, Rect viewport);
void mode7(Surface *dest, TransformedTileLayer *layer, float fov, float angle, Vec2 pos, float near, float far, Rect viewport);
Vec2 world_to_screen(Vec2 w, float fov, float angle, Vec2 pos, float near, float far, Rect viewport);
float world_to_scale(Vec2 w, float fov, float angle, Vec2 pos, float near, float far, Rect viewport);

}
}
Loading
Loading