[keel,nostalgia,studio] Fix implicit conversions

This commit is contained in:
2023-06-07 00:41:31 -05:00
parent 3fdfee33a9
commit aa19cdf535
18 changed files with 162 additions and 117 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ if(TURBINE_BUILD_TYPE STREQUAL "Native")
target_link_libraries(
NostalgiaStudioModules PUBLIC
StudioAppLib
NostalgiaCore-Studio
NostalgiaCore-Studio-ImGui
NostalgiaScene-Studio
)
if(NOT MSVC)
+1
View File
@@ -13,6 +13,7 @@ endif()
if(NOT MSVC)
target_compile_options(NostalgiaCore PUBLIC -Wsign-conversion)
target_compile_options(NostalgiaCore PRIVATE -Wconversion)
endif()
target_link_libraries(
+14 -3
View File
@@ -46,7 +46,7 @@ constexpr uint8_t blue16(Color16 c) noexcept {
[[nodiscard]]
constexpr uint8_t alpha16(Color16 c) noexcept {
return c >> 15;
return static_cast<uint8_t>(c >> 15);
}
[[nodiscard]]
@@ -66,7 +66,7 @@ constexpr uint8_t blue32(Color16 c) noexcept {
[[nodiscard]]
constexpr uint8_t alpha32(Color16 c) noexcept {
return (c >> 15) * 255;
return static_cast<uint8_t>((c >> 15) * 255);
}
@@ -128,9 +128,20 @@ constexpr float bluef(Color32 c) noexcept {
}
[[nodiscard]]
constexpr Color16 color16(int r, int g, int b, int a = 0) noexcept {
return static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(r), 31))
| static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(g), 31) << 5)
| static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(b), 31) << 10)
| static_cast<Color16>(a << 15);
}
[[nodiscard]]
constexpr Color16 color16(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0) noexcept {
return ox::min<uint8_t>(r, 31) | (ox::min<uint8_t>(g, 31) << 5) | (ox::min<uint8_t>(b, 31) << 10) | (a << 15);
return static_cast<Color16>(ox::min<uint8_t>(r, 31))
| static_cast<Color16>(ox::min<uint8_t>(g, 31) << 5)
| static_cast<Color16>(ox::min<uint8_t>(b, 31) << 10)
| static_cast<Color16>(a << 15);
}
static_assert(color16(0, 31, 0) == 992);
+14 -12
View File
@@ -138,12 +138,12 @@ ox::Error loadBgTileSheet(Context *ctx,
target.pal.palette = MEM_BG_PALETTE;
target.cbbData = &g_cbbData[cbb];
target.tileMap = MEM_BG_TILES[cbb].data();
oxReturnError(ox::readMC(ts, tsStat.size, &target));
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
// load external palette if available
if (paletteAddr) {
oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
}
// update bpp of all bgs with the updated cbb
const auto bpp = g_cbbData[cbb].bpp;
@@ -164,12 +164,12 @@ ox::Error loadSpriteTileSheet(Context *ctx,
GbaTileMapTarget target;
target.pal.palette = MEM_SPRITE_PALETTE;
target.tileMap = MEM_SPRITE_TILES;
oxReturnError(ox::readMC(ts, tsStat.size, &target));
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
// load external palette if available
if (paletteAddr) {
oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
}
return {};
}
@@ -180,7 +180,7 @@ ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAd
target.palette = MEM_BG_PALETTE;
oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target));
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
return {};
}
@@ -190,7 +190,7 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p
target.palette = &MEM_SPRITE_PALETTE[cbb];
oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target));
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
return {};
}
@@ -217,7 +217,7 @@ void hideSprite(Context*, unsigned idx) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::GbaSpriteAttrUpdate oa;
oa.attr0 = 2 << 8;
oa.idx = idx;
oa.idx = static_cast<uint16_t>(idx);
teagba::addSpriteUpdate(oa);
}
@@ -231,14 +231,16 @@ void setSprite(Context*,
unsigned flipX) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::GbaSpriteAttrUpdate oa;
oa.attr0 = static_cast<uint16_t>(y & ox::onMask<uint8_t>(0b111'1111))
oa.attr0 = static_cast<uint16_t>(
static_cast<uint16_t>(y & ox::onMask<uint8_t>(0b111'1111))
| (static_cast<uint16_t>(1) << 10) // enable alpha
| (static_cast<uint16_t>(spriteShape) << 14);
oa.attr1 = (static_cast<uint16_t>(x) & ox::onMask<uint8_t>(8))
| (static_cast<uint16_t>(spriteShape) << 14));
oa.attr1 = static_cast<uint16_t>(
(static_cast<uint16_t>(x) & ox::onMask<uint8_t>(8))
| (static_cast<uint16_t>(flipX) << 12)
| (static_cast<uint16_t>(spriteSize) << 14);
| (static_cast<uint16_t>(spriteSize) << 14));
oa.attr2 = static_cast<uint16_t>(tileIdx & ox::onMask<uint16_t>(8));
oa.idx = idx;
oa.idx = static_cast<uint16_t>(idx);
teagba::addSpriteUpdate(oa);
}
+17 -5
View File
@@ -1,23 +1,34 @@
add_library(
NostalgiaCore-Studio OBJECT
studiomodule.cpp
NostalgiaCore-Studio
paletteeditor.cpp
paletteeditor-imgui.cpp
tilesheeteditor-imgui.cpp
tilesheeteditorview.cpp
tilesheeteditormodel.cpp
tilesheetpixelgrid.cpp
tilesheetpixels.cpp
)
add_library(
NostalgiaCore-Studio-ImGui OBJECT
studiomodule.cpp
paletteeditor-imgui.cpp
tilesheeteditor-imgui.cpp
)
if(NOT MSVC)
target_compile_options(NostalgiaCore-Studio PRIVATE -Wsign-conversion)
target_compile_options(NostalgiaCore-Studio-ImGui PRIVATE -Wsign-conversion)
endif()
target_link_libraries(
NostalgiaCore-Studio PUBLIC
Studio
NostalgiaCore
Studio
)
target_link_libraries(
NostalgiaCore-Studio-ImGui PUBLIC
NostalgiaCore-Studio
Studio
lodepng
)
@@ -25,6 +36,7 @@ target_link_libraries(
install(
TARGETS
NostalgiaCore-Studio-ImGui
NostalgiaCore-Studio
LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE}
@@ -53,7 +53,8 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
const auto sz = ImVec2(70, 24);
if (ImGui::Button("Add", sz)) {
const auto colorSz = static_cast<int>(m_pal.colors.size());
undoStack()->push(ox::make<AddColorCommand>(&m_pal, 0, colorSz));
constexpr Color16 c = 0;
undoStack()->push(ox::make<AddColorCommand>(&m_pal, c, colorSz));
}
ImGui::SameLine();
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
@@ -35,7 +35,7 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const
++idx;
}
constexpr auto fmt = alpha ? LCT_RGBA : LCT_RGB;
return OxError(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8));
return OxError(static_cast<ox::ErrorCode>(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path): m_tileSheetEditor(ctx, path) {
@@ -361,8 +361,8 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
}
// header
if (ImGui::BeginTable("PaletteTable", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) {
ImGui::TableSetupColumn("No.", 0, 0.45);
ImGui::TableSetupColumn("", 0, 0.22);
ImGui::TableSetupColumn("No.", 0, 0.45f);
ImGui::TableSetupColumn("", 0, 0.22f);
ImGui::TableSetupColumn("Color16", 0, 3);
ImGui::TableHeadersRow();
if (auto pal = m_tileSheetEditor.pal()) {
@@ -130,7 +130,7 @@ class DrawCommand: public TileSheetCommand {
});
if (existing == m_changes.cend()) {
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
subsheet.setPixel(m_img->bpp, idx, m_palIdx);
subsheet.setPixel(m_img->bpp, idx, static_cast<uint8_t>(m_palIdx));
return true;
}
}
@@ -148,14 +148,14 @@ class DrawCommand: public TileSheetCommand {
void redo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, m_palIdx);
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(m_palIdx));
}
}
void undo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx);
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
}
}
@@ -205,14 +205,14 @@ class CutPasteCommand: public TileSheetCommand {
void redo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.newPalIdx);
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.newPalIdx));
}
}
void undo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx);
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
}
}
+9 -8
View File
@@ -138,8 +138,8 @@ struct TileSheet {
} else {
if (pBpp == 4) {
for (auto p: this->pixels) {
pPixels->emplace_back(p & 0b1111);
pPixels->emplace_back(p >> 4);
pPixels->emplace_back(static_cast<uint8_t>(p & 0b1111));
pPixels->emplace_back(static_cast<uint8_t>(p >> 4));
}
} else {
for (auto p: this->pixels) {
@@ -226,14 +226,15 @@ struct TileSheet {
pixels.size());
//oxAssert(pixels.size() == pixelCnt, "Pixel count does not match rows and columns");
for (std::size_t i = 0; i < pixelCnt; ++i) {
const auto colorIdx1 = pixels[i] & 0xF;
const auto colorIdx2 = pixels[i] >> 4;
const auto colorIdx1 = static_cast<uint8_t>(pixels[i] & 0xF);
const auto colorIdx2 = static_cast<uint8_t>(pixels[i] >> 4);
callback(i * 2 + 0, colorIdx1);
callback(i * 2 + 1, colorIdx2);
}
} else {
const auto pixelCnt = ox::min<std::size_t>(static_cast<std::size_t>(columns * rows * PixelsPerTile),
pixels.size());
const auto pixelCnt = ox::min<std::size_t>(
static_cast<std::size_t>(columns * rows * PixelsPerTile),
pixels.size());
for (std::size_t i = 0; i < pixelCnt; ++i) {
const auto p = pixels[i];
callback(i, p);
@@ -242,10 +243,10 @@ struct TileSheet {
}
constexpr void setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
auto &pixel = this->pixels[idx / 2];
auto &pixel = this->pixels[static_cast<std::size_t>(idx / 2)];
if (pBpp == 4) {
if (idx & 1) {
pixel = (pixel & 0b0000'1111) | (palIdx << 4);
pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
} else {
pixel = (pixel & 0b1111'0000) | (palIdx);
}
+5 -4
View File
@@ -28,10 +28,11 @@ ox::Error Scene::setupDisplay(core::Context *ctx) noexcept {
auto y = 0;
auto width = m_sceneStatic.rows[layerNo];
for (const auto &tile : layer) {
core::setTile(ctx, layerNo, x, y, tile);
core::setTile(ctx, layerNo, x + 1, y, tile + 1);
core::setTile(ctx, layerNo, x, y + 1, tile + 2);
core::setTile(ctx, layerNo, x + 1, y + 1, tile + 3);
auto tile8 = static_cast<uint8_t >(tile);
core::setTile(ctx, layerNo, x, y, tile8);
core::setTile(ctx, layerNo, x + 1, y, tile8 + 1);
core::setTile(ctx, layerNo, x, y + 1, tile8 + 2);
core::setTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
x += 2;
if (x >= width * 2) {
x = 0;
+10 -6
View File
@@ -102,16 +102,20 @@ oxModelEnd()
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11111100) | val;
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11111100) | val8;
}
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11110011) | (val << 2);
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
}
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11001111) | (val << 4);
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
}
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b00111111) | (val << 6);
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
}
[[nodiscard]]
@@ -171,8 +175,8 @@ struct SceneStatic {
return {tileMapIdx[i], tileType[i], layerAttachments[i]};
}
constexpr auto setDimensions(ox::Size dim) noexcept {
columns = dim.width;
rows = dim.height;
columns = static_cast<uint16_t>(dim.width);
rows = static_cast<uint16_t>(dim.height);
const auto tileCnt = static_cast<unsigned>(columns * rows);
tileMapIdx.resize(tileCnt);
tileType.resize(tileCnt);