Skip to content

Commit

Permalink
fixed linux build & some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Redcrafter committed May 31, 2024
1 parent 5ab773d commit faff8e1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

build/
build_linux/
.vscode/
11 changes: 7 additions & 4 deletions src/glStuff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ struct Texture {
}

void LoadSubImage(int x, int y, std::span<const uint8_t> data) {
int width, height, n;
auto* dat = stbi_load_from_memory(data.data(), data.size(), &width, &height, &n, 4);
int w, h, n;
auto* dat = stbi_load_from_memory(data.data(), data.size(), &w, &h, &n, 4);
if(dat == nullptr) {
throw std::runtime_error("failed to load texture");
}

glBindTexture(GL_TEXTURE_2D, id);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dat);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, dat);

stbi_image_free(dat);
}
Expand Down Expand Up @@ -280,6 +280,9 @@ struct Vertex {
glm::vec2 position;
glm::vec2 uv;
uint32_t color;

Vertex(glm::vec2 position, glm::vec2 uv, uint32_t color) : position(position), uv(uv), color(color) {}
Vertex(glm::vec2 position, glm::vec2 uv) : position(position), uv(uv), color(IM_COL32_WHITE) {}
};

struct Mesh {
Expand Down Expand Up @@ -320,7 +323,7 @@ struct Mesh {

for(int i = 0; i < steps; ++i) {
auto n = p1 + delta;
AddLine(p1, n);
AddLine(p1, n, col, thickness);
p1 = n + delta;
}
// todo: draw last fractional segment
Expand Down
40 changes: 20 additions & 20 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static void ImGui_draw_sprite(const SpriteData& sprite, int frame, glm::u16vec2
const ImVec2 p = ImGui::GetCursorScreenPos();
auto pos = glm::vec2(p.x, p.y);

for(int j = 0; j < sprite.layers.size(); ++j) {
for(size_t j = 0; j < sprite.layers.size(); ++j) {
auto subsprite_id = sprite.compositions[frame * sprite.layers.size() + j];
if(subsprite_id >= sprite.sub_sprites.size())
continue;
Expand Down Expand Up @@ -516,8 +516,8 @@ class {
auto& uv = uvs[tile_id];

ImGui::Text("Composite size %i %i", sprite.size.x, sprite.size.y);
ImGui::Text("Layer count %i", sprite.layers.size());
ImGui::Text("Subsprite count %i", sprite.sub_sprites.size());
ImGui::Text("Layer count %zu", sprite.layers.size());
ImGui::Text("Subsprite count %zu", sprite.sub_sprites.size());

if(!sprite.animations.empty()) {
ImGui::NewLine();
Expand Down Expand Up @@ -666,7 +666,7 @@ class {
// Otherwise by default the table will fit all available space, like a BeginChild() call.
ImVec2 outer_size = ImVec2(0.0f, TEXT_BASE_HEIGHT * 8);

ImGui::Text("%i results", results.size());
ImGui::Text("%zu results", results.size());
if(ImGui::BeginTable("search_results", 3, flags, outer_size)) {
ImGui::TableSetupScrollFreeze(0, 1); // Make top row always visible
ImGui::TableSetupColumn("x", ImGuiTableColumnFlags_None);
Expand Down Expand Up @@ -725,7 +725,7 @@ class {
if(tiles_.empty()) {
auto atlas_size = glm::vec2(atlas->width, atlas->height);

for(int i = 0; i < uvs.size(); ++i) {
for(size_t i = 0; i < uvs.size(); ++i) {
auto uv = uvs[i];
if(uv.size == glm::u16vec2(0)) {
continue;
Expand Down Expand Up @@ -776,7 +776,7 @@ static void dump_assets() {

std::vector<uint8_t> decrypted;

for(int i = 0; i < assets.size(); ++i) {
for(size_t i = 0; i < assets.size(); ++i) {
auto& item = assets[i];

std::string ext = ".bin";
Expand Down Expand Up @@ -1143,8 +1143,8 @@ static void HelpMarker(const char* desc) {
}
}

glm::ivec2 get_mouse_world(glm::vec2 mousePos) {
auto mp = glm::vec4((mousePos / screenSize) * 2.0f - 1.0f, 0, 1);
glm::ivec2 screen_to_world(glm::vec2 pos) {
auto mp = glm::vec4((pos / screenSize) * 2.0f - 1.0f, 0, 1);
mp.y = -mp.y;
return glm::ivec2(glm::inverse(MVP) * mp) / 8;
}
Expand All @@ -1169,7 +1169,7 @@ static void handle_input() {
ImGuiIO& io = ImGui::GetIO();

const auto delta = lastMousePos - mousePos;
auto lastWorldPos = get_mouse_world(lastMousePos);
auto lastWorldPos = screen_to_world(lastMousePos);
lastMousePos = mousePos;

if(io.WantCaptureMouse) return;
Expand All @@ -1179,13 +1179,13 @@ static void handle_input() {
view = glm::translate(view, glm::vec3(-delta / gScale, 0));
}
if(GetKey(ImGuiKey_MouseRight)) {
mode0_selection = get_mouse_world(mousePos);
mode0_selection = screen_to_world(mousePos);
}
if(GetKey(ImGuiKey_Escape)) {
mode0_selection = glm::ivec2(-1, -1);
}
} else if(mouse_mode == 1) {
auto mouse_world_pos = get_mouse_world(mousePos);
auto mouse_world_pos = screen_to_world(mousePos);

const auto holding = selection_handler.holding();
auto selecting = selection_handler.selecting();
Expand Down Expand Up @@ -1260,7 +1260,7 @@ static void DrawPreviewWindow() {
if(io.WantCaptureMouse) {
asdasd = glm::ivec2(-1, -1);
} else {
asdasd = get_mouse_world(mousePos);
asdasd = screen_to_world(mousePos);
}
}

Expand Down Expand Up @@ -1346,7 +1346,7 @@ static void DrawPreviewWindow() {
} else if(mouse_mode == 1) {
static MapTile placing;

auto mouse_world_pos = get_mouse_world(mousePos);
auto mouse_world_pos = screen_to_world(mousePos);

ImGui::SameLine();
HelpMarker("Middle click to copy a tile.\n\
Expand Down Expand Up @@ -1463,7 +1463,7 @@ static void draw_overlay() {
if(io.WantCaptureMouse) {
asdasd = glm::ivec2(-1, -1);
} else {
asdasd = get_mouse_world(mousePos);
asdasd = screen_to_world(mousePos);
}
}

Expand All @@ -1488,7 +1488,7 @@ static void draw_overlay() {
auto bb_max = pos + glm::vec2(8, 8);

int composition_id = 0;
for(int j = 0; j < sprite.layers.size(); ++j) {
for(size_t j = 0; j < sprite.layers.size(); ++j) {
auto subsprite_id = sprite.compositions[composition_id * sprite.layers.size() + j];
if(subsprite_id >= sprite.sub_sprites.size())
continue;
Expand Down Expand Up @@ -1522,7 +1522,7 @@ static void draw_overlay() {
overlay->AddRect(room_pos * room_size * 8, room_pos * room_size * 8 + glm::ivec2(40, 22) * 8, IM_COL32(255, 255, 255, 127), 1);
}
} else if(mouse_mode == 1) {
auto mouse_world_pos = get_mouse_world(mousePos);
auto mouse_world_pos = screen_to_world(mousePos);
auto room_pos = mouse_world_pos / room_size;
auto room = maps[selectedMap].getRoom(room_pos.x, room_pos.y);

Expand All @@ -1534,7 +1534,7 @@ static void draw_overlay() {

if(selection_handler.holding()) {
auto end = start + selection_handler.size();
overlay->AddRectDashed(start * 8, end * 8, IM_COL32(255, 0, 0, 255), 1, 4);
overlay->AddRectDashed(start * 8, end * 8, IM_COL32_WHITE, 1, 4);
} else if(selection_handler.selecting()) {
auto end = mouse_world_pos;
if(end.x < start.x) {
Expand All @@ -1543,19 +1543,19 @@ static void draw_overlay() {
if(end.y < start.y) {
std::swap(start.y, end.y);
}
overlay->AddRectDashed(start * 8, end * 8 + 8, IM_COL32(255, 0, 0, 255), 1, 4);
overlay->AddRectDashed(start * 8, end * 8 + 8, IM_COL32_WHITE, 1, 4);
}
}
}

if(room_grid) {
const auto& map = maps[selectedMap];

for(size_t i = 0; i <= map.size.x; i++) {
for(int i = 0; i <= map.size.x; i++) {
auto x = (map.offset.x + i) * 40 * 8;
overlay->AddLine({x, map.offset.y * 22 * 8}, {x, (map.offset.y + map.size.y) * 22 * 8}, IM_COL32(255, 255, 255, 191), 1 / gScale);
}
for(size_t i = 0; i <= map.size.y; i++) {
for(int i = 0; i <= map.size.y; i++) {
auto y = (map.offset.y + i) * 22 * 8;
overlay->AddLine({map.offset.x * 40 * 8, y}, {(map.offset.x + map.size.x) * 40 * 8, y}, IM_COL32(255, 255, 255, 191), 1 / gScale);
}
Expand Down
2 changes: 1 addition & 1 deletion src/map_slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MapSlice {
data.reserve(size.x * size.y);
this->_size = size;

for(size_t i = 0; i < size.x * size.y; i++) {
for(int i = 0; i < size.x * size.y; i++) {
data.push_back(tile);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ void renderMap(const Map& map, std::span<const uv_data> uvs, std::unordered_map<

int composition_id = 0;

for(int j = 0; j < sprite.layers.size(); ++j) {
for(size_t j = 0; j < sprite.layers.size(); ++j) {
auto subsprite_id = sprite.compositions[composition_id * sprite.layers.size() + j];
if(subsprite_id >= sprite.sub_sprites.size()) continue;

auto& layer = sprite.layers[j];
if(layer.is_normals1 || layer.is_normals2 || !layer.is_visible) continue;
auto& sprite_layer = sprite.layers[j];
if(sprite_layer.is_normals1 || sprite_layer.is_normals2 || !sprite_layer.is_visible) continue;

auto& subsprite = sprite.sub_sprites[subsprite_id];

Expand Down
10 changes: 5 additions & 5 deletions src/structures/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ class Map {
if(data.size() < sizeof(MapHeader) + head.roomCount * sizeof(Room)) {
throw std::runtime_error("Error parsing map: invalid size");
}
Room* rooms = (Room*)(data.data() + sizeof(MapHeader));
Room* rooms_ = (Room*)(data.data() + sizeof(MapHeader));

world_wrap_x_start = head.world_wrap_x_start;
world_wrap_x_end = head.world_wrap_x_end;
this->rooms = {rooms, rooms + head.roomCount};
rooms = {rooms_, rooms_ + head.roomCount};

int x_min = 65535, x_max = 0;
int y_min = 65535, y_max = 0;

for(int i = 0; i < head.roomCount; i++) {
auto& room = this->rooms[i];
auto& room = rooms[i];
x_min = std::min(x_min, (int)room.x);
x_max = std::max(x_max, (int)room.x);
y_min = std::min(y_min, (int)room.y);
Expand Down Expand Up @@ -143,8 +143,8 @@ class Map {
}

auto save() const {
auto size = sizeof(MapHeader) + rooms.size() * sizeof(Room);
std::vector<uint8_t> data(size);
auto bytes = sizeof(MapHeader) + rooms.size() * sizeof(Room);
std::vector<uint8_t> data(bytes);

*(MapHeader*)data.data() = {
0xF00DCAFE,
Expand Down
2 changes: 1 addition & 1 deletion src/structures/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline std::vector<uv_data> parse_uvs(std::span<const uint8_t> data) {
throw std::runtime_error("invalid uv header");
}
auto count = *(uint32_t *)(data.data() + 4);
auto unused = *(uint32_t *)(data.data() + 8); // null in the given asset
assert(*(uint32_t *)(data.data() + 8) == 0); // null in the given asset

if(data.size() < 0xC + count * sizeof(uv_data)) {
throw std::runtime_error("invalid uv data size");
Expand Down
2 changes: 1 addition & 1 deletion src/windows/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class {
ImGui::Text("Errors:");
for(auto& e : errors) {
ImGui::Indent();
ImGui::Text(e.c_str());
ImGui::Text("%s", e.c_str());
ImGui::Unindent();
}
}
Expand Down

0 comments on commit faff8e1

Please sign in to comment.