From eecc9da3ce6d4be981cbc5d125fb11a273f8585a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 21 Apr 2024 13:15:17 -0500 Subject: [PATCH] [jasper] Add missing files, update for Nostalgia changes --- .../include/jasper/world/objectcache.hpp | 52 +++++++++ .../world/include/jasper/world/worlddoc.hpp | 108 ++++++++++++++++++ .../studio/worldeditor/worldeditor-imgui.cpp | 2 +- .../studio/worldeditor/worldeditor-imgui.hpp | 2 +- .../worldobjectseteditor-imgui.cpp | 6 +- .../worldobjectseteditor-imgui.hpp | 2 +- 6 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 src/jasper/modules/world/include/jasper/world/objectcache.hpp create mode 100644 src/jasper/modules/world/include/jasper/world/worlddoc.hpp diff --git a/src/jasper/modules/world/include/jasper/world/objectcache.hpp b/src/jasper/modules/world/include/jasper/world/objectcache.hpp new file mode 100644 index 0000000..0bb9423 --- /dev/null +++ b/src/jasper/modules/world/include/jasper/world/objectcache.hpp @@ -0,0 +1,52 @@ +/* + * Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +#include + +#include +#include + +namespace jasper::world { + +class ObjectCache { + public: + struct Obj { + ObjectId id{}; + uint16_t palBank{}; + size_t tileIdx{}; + }; + private: + struct ObjSet { + uint64_t setId{}; + ox::Vector objects; + }; + ox::Vector m_tilesheets; + ox::Vector m_palettes; + size_t m_tileIdx{}; + size_t m_palBank{}; + ox::Vector m_objSets; + ncore::TileSheetSet m_tilesheetSet; + public: + void clear() noexcept; + ox::Error indexSet( + keel::Context &kctx, + uint64_t setId, + WorldObjectSet const&objSet) noexcept; + [[nodiscard]] + ox::Optional obj(uint64_t setId, ObjectId objId) const noexcept; + [[nodiscard]] + ncore::TileSheetSet const&tilesheets() const noexcept; + [[nodiscard]] + ox::Vector const&palettes() const noexcept; + private: + void addTileSheet(ox::FileAddress path, int32_t tiles) noexcept; +}; + +ox::Result buildObjCache(keel::Context &kctx, WorldDoc const&doc) noexcept; + +} \ No newline at end of file diff --git a/src/jasper/modules/world/include/jasper/world/worlddoc.hpp b/src/jasper/modules/world/include/jasper/world/worlddoc.hpp new file mode 100644 index 0000000..acdeb89 --- /dev/null +++ b/src/jasper/modules/world/include/jasper/world/worlddoc.hpp @@ -0,0 +1,108 @@ +/* + * Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include "worldobject.hpp" + +namespace jasper::world { + +namespace ncore = nostalgia::core; + +struct SpriteDoc { + constexpr static auto TypeName = "net.drinkingtea.jasper.world.SpriteDoc"; + constexpr static auto TypeVersion = 1; + constexpr static auto Preloadable = true; + ox::String tilesheetPath; + ox::Vector subsheetId; +}; + +struct DocObjRef { + constexpr static auto TypeName = "net.drinkingtea.jasper.world.DocObjRef"; + constexpr static auto TypeVersion = 1; + uint64_t worldObjectSetId{}; + ObjectId worldObjectId{}; +}; + +oxModelBegin(DocObjRef) + oxModelFieldRename(worldObjectSetId, world_object_set_id) + oxModelFieldRename(worldObjectId, world_object_id) +oxModelEnd() + +struct TileDoc { + constexpr static auto TypeName = "net.drinkingtea.jasper.world.TileDoc"; + constexpr static auto TypeVersion = 1; + DocObjRef obj; + uint8_t type = 0; + uint8_t palBank = 0; + uint8_t topLayerAttachment{}; + uint8_t bottomLayerAttachment{}; + uint8_t leftLayerAttachment{}; + uint8_t rightLayerAttachment{}; +}; + +oxModelBegin(TileDoc) + oxModelField(obj) + oxModelField(type) + oxModelFieldRename(palBank, pal_bank) + oxModelFieldRename(topLayerAttachment, top_layer_attachment) + oxModelFieldRename(bottomLayerAttachment, bottom_layer_attachment) + oxModelFieldRename(leftLayerAttachment, left_layer_attachment) + oxModelFieldRename(rightLayerAttachment, right_layer_attachment) +oxModelEnd() + + +struct ObjectSetEntry { + constexpr static auto TypeName = "net.drinkingtea.jasper.world.ObjectSetEntry"; + constexpr static auto TypeVersion = 1; + ox::String path; + uint64_t id{}; +}; + +oxModelBegin(ObjectSetEntry) + oxModelField(path) + oxModelField(id) +oxModelEnd() + + +struct WorldDoc { + using TileMapRow = ox::Vector; + using TileMapLayer = ox::Vector; + using TileMap = ox::Array; + constexpr static auto TypeName = "net.drinkingtea.jasper.world.WorldDoc"; + constexpr static auto TypeVersion = 1; + ox::Vector objSets; // paths + uint64_t objSetIdIdx{}; + int columns{}; + int rows{}; + TileMap tiles; +}; + +oxModelBegin(WorldDoc) + oxModelFieldRename(objSets, object_sets) + oxModelFieldRename(objSetIdIdx, object_set_id_idx) + oxModelField(columns) + oxModelField(rows) + oxModelField(tiles) +oxModelEnd() + +[[nodiscard]] +ObjectSetEntry const*objSetEntry(WorldDoc const&doc, size_t id) noexcept; + +[[nodiscard]] +auto &tile(ox::CommonRefWith auto &doc, size_t lyr, size_t col, size_t row) noexcept { + return doc.tiles[lyr][row][col]; +} + +void resize(WorldDoc &doc, ox::Size const&sz) noexcept; + +} diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp index 40c37d0..3b48ec8 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -59,7 +59,7 @@ WorldEditorImGui::WorldEditorImGui(studio::StudioContext &sctx, ox::StringView p m_sctx.project->fileUpdated.connect(this, &WorldEditorImGui::handleObjectSetUpdate); } -void WorldEditorImGui::draw(turbine::Context&) noexcept { +void WorldEditorImGui::draw(studio::StudioContext&) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); constexpr auto resourcesWidth = 300.f; { diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp index c0214be..248987c 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -36,7 +36,7 @@ class WorldEditorImGui: public studio::Editor { public: WorldEditorImGui(studio::StudioContext &ctx, ox::StringView path); - void draw(turbine::Context&) noexcept final; + void draw(studio::StudioContext&) noexcept final; void onActivated() noexcept override; diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp index 49b3a3f..338d2cd 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp @@ -36,7 +36,7 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui( buildPaletteDisplayNameList(); } -void WorldObjectSetEditorImGui::draw(turbine::Context&) noexcept { +void WorldObjectSetEditorImGui::draw(studio::StudioContext&) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); constexpr auto resourcesWidth = 300.f; ImGui::BeginChild("ObjEditor", ImVec2(paneSize.x - resourcesWidth, 0)); @@ -122,7 +122,7 @@ void WorldObjectSetEditorImGui::loadObj() noexcept { } auto const&obj = activeObj(); auto &nameBuff = m_objEditor.nameBuff; - ox_strncpy(nameBuff.data(), obj.name.data(), nameBuff.size()); + ox::strncpy(nameBuff.data(), obj.name.data(), nameBuff.size()); m_objEditor.palette = obj.palBank; m_subsheet = getSubsheet(*m_tileSheet, obj.subsheetId); int w = 0; @@ -159,7 +159,7 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept { undoStack()->push(ox::make_unique( m_doc, m_selectedObj, - ox::String(nameBuff.data(), ox_strnlen(nameBuff.data(), nameBuff.size())))); + ox::String(nameBuff.data(), ox::strnlen(nameBuff.data(), nameBuff.size())))); } // SubSheet Selector { diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp index 46473bf..c6eab01 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp @@ -42,7 +42,7 @@ class WorldObjectSetEditorImGui: public studio::Editor { public: WorldObjectSetEditorImGui(studio::StudioContext &ctx, ox::StringView path); - void draw(turbine::Context&) noexcept final; + void draw(studio::StudioContext&) noexcept final; void onActivated() noexcept override;