From 9c2e71045fe3aa9012aaaac29fb4fc88e58d9211 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 12 Oct 2017 16:09:36 -0500 Subject: [PATCH] Add ioOp functions for Point and Bounds --- src/nostalgia/CMakeLists.txt | 2 +- src/nostalgia/common/bounds.cpp | 10 ++--- src/nostalgia/common/bounds.hpp | 19 ++++++-- src/nostalgia/common/point.cpp | 68 ++++++++++++++--------------- src/nostalgia/common/point.hpp | 16 ++++++- src/nostalgia/core/gba/gfx.cpp | 14 ++++-- src/nostalgia/core/gfx.hpp | 2 + src/nostalgia/player/CMakeLists.txt | 12 ----- src/nostalgia/studio/mainwindow.cpp | 5 +-- src/nostalgia/studio/mainwindow.hpp | 2 + src/nostalgia/world/CMakeLists.txt | 13 ++++++ src/nostalgia/world/world.cpp | 15 +++++++ src/nostalgia/world/world.hpp | 23 ++++++++++ 13 files changed, 136 insertions(+), 65 deletions(-) create mode 100644 src/nostalgia/world/CMakeLists.txt create mode 100644 src/nostalgia/world/world.cpp create mode 100644 src/nostalgia/world/world.hpp diff --git a/src/nostalgia/CMakeLists.txt b/src/nostalgia/CMakeLists.txt index 85235145..e6b7c37b 100644 --- a/src/nostalgia/CMakeLists.txt +++ b/src/nostalgia/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required(VERSION 2.8.11) #setup libraries @@ -11,6 +10,7 @@ endif() add_subdirectory(core) add_subdirectory(common) add_subdirectory(player) +add_subdirectory(world) if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA") add_subdirectory(tools) diff --git a/src/nostalgia/common/bounds.cpp b/src/nostalgia/common/bounds.cpp index ebb43441..fb01cdba 100644 --- a/src/nostalgia/common/bounds.cpp +++ b/src/nostalgia/common/bounds.cpp @@ -14,23 +14,23 @@ Bounds::Bounds() { } bool Bounds::intersects(Bounds o) const { - return o.x2() >= X && x2() >= o.X && o.y2() >= Y && y2() >= o.Y; + return o.x2() >= x && x2() >= o.x && o.y2() >= y && y2() >= o.y; } bool Bounds::contains(int x, int y) const { - return x >= X && y >= Y && x <= x2() && y <= y2(); + return x >= this->x && y >= this->y && x <= x2() && y <= y2(); } int Bounds::x2() const { - return X + Width; + return x + width; } int Bounds::y2() const { - return Y + Height; + return y + height; } Point Bounds::pt1() { - return Point(X, Y); + return Point(x, y); } Point Bounds::pt2() { diff --git a/src/nostalgia/common/bounds.hpp b/src/nostalgia/common/bounds.hpp index adc9c230..4e3f8f07 100644 --- a/src/nostalgia/common/bounds.hpp +++ b/src/nostalgia/common/bounds.hpp @@ -14,10 +14,10 @@ namespace common { class Bounds { public: - int X = 0; - int Y = 0; - int Width = 0; - int Height = 0; + int x = 0; + int y = 0; + int width = 0; + int height = 0; /** * Constructor @@ -37,5 +37,16 @@ class Bounds { Point pt2(); }; +template +ox::Error ioOp(T *io, Bounds *obj) { + ox::Error err = 0; + io->setFields(4); + err |= io->op("x", &obj->x); + err |= io->op("y", &obj->y); + err |= io->op("width", &obj->width); + err |= io->op("height", &obj->height); + return err; +} + } } diff --git a/src/nostalgia/common/point.cpp b/src/nostalgia/common/point.cpp index 098942a5..de46dd4b 100644 --- a/src/nostalgia/common/point.cpp +++ b/src/nostalgia/common/point.cpp @@ -14,110 +14,110 @@ Point::Point() { } Point::Point(int x, int y) { - X = x; - Y = y; + this->x = x; + this->y = y; } Point Point::operator+(common::Point p) const { - p.X += X; - p.Y += Y; + p.x += x; + p.y += y; return p; } Point Point::operator-(common::Point p) const { auto out = *this; - out.X -= p.X; - out.Y -= p.Y; + out.x -= p.x; + out.y -= p.y; return out; } Point Point::operator*(common::Point p) const { - p.X *= X; - p.Y *= Y; + p.x *= x; + p.y *= y; return p; } Point Point::operator/(common::Point p) const { auto out = *this; - out.X /= p.X; - out.Y /= p.Y; + out.x /= p.x; + out.y /= p.y; return out; } Point Point::operator+=(common::Point p) { - X += p.X; - Y += p.Y; + x += p.x; + y += p.y; return *this; } Point Point::operator-=(common::Point p) { - X -= p.X; - Y -= p.Y; + x -= p.x; + y -= p.y; return *this; } Point Point::operator*=(common::Point p) { - X *= p.X; - Y *= p.Y; + x *= p.x; + y *= p.y; return *this; } Point Point::operator/=(common::Point p) { - X /= p.X; - Y /= p.Y; + x /= p.x; + y /= p.y; return *this; } Point Point::operator+(int i) const { auto out = *this; - out.X += i; - out.Y += i; + out.x += i; + out.y += i; return out; } Point Point::operator-(int i) const { auto out = *this; - out.X -= i; - out.Y -= i; + out.x -= i; + out.y -= i; return out; } Point Point::operator*(int i) const { auto out = *this; - out.X *= i; - out.Y *= i; + out.x *= i; + out.y *= i; return out; } Point Point::operator/(int i) const { auto out = *this; - out.X /= i; - out.Y /= i; + out.x /= i; + out.y /= i; return out; } Point Point::operator+=(int i) { - X += i; - Y += i; + x += i; + y += i; return *this; } Point Point::operator-=(int i) { - X -= i; - Y -= i; + x -= i; + y -= i; return *this; } Point Point::operator*=(int i) { - X *= i; - Y *= i; + x *= i; + y *= i; return *this; } Point Point::operator/=(int i) { - X /= i; - Y /= i; + x /= i; + y /= i; return *this; } diff --git a/src/nostalgia/common/point.hpp b/src/nostalgia/common/point.hpp index c7e89b74..08cf350a 100644 --- a/src/nostalgia/common/point.hpp +++ b/src/nostalgia/common/point.hpp @@ -5,15 +5,18 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #pragma once +#include + namespace nostalgia { namespace common { class Point { public: - int X = 0; - int Y = 0; + int x = 0; + int y = 0; Point(); @@ -55,5 +58,14 @@ class Point { Point operator/=(int i); }; +template +ox::Error ioOp(T *io, Point *obj) { + ox::Error err = 0; + io->setFields(2); + err |= io->op("x", &obj->x); + err |= io->op("y", &obj->y); + return err; +} + } } diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 9886b839..fe40fb8a 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -137,19 +137,22 @@ ox::Error initConsole(Context *ctx) { REG_BG0CNT = (28 << 8) | 1; if (fs) { + // load the header err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr); // load palette err |= fs->read(CharsetInode, PaletteStart, - 512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); + 512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); if (imgData.bpp == 4) { err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles), - sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr); - } else if (imgData.bpp == 4) { + sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr); + } else if (imgData.bpp == 8) { REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles), - sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr); + sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr); + } else { + err = 1; } } else { err = 1; @@ -163,5 +166,8 @@ void puts(Context *ctx, int loc, const char *str) { } } +void setTileMap(Context *ctx, int layer, int columns, int rows, uint16_t *buff) { +} + } } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index e86c264a..c8068757 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -20,5 +20,7 @@ ox::Error initConsole(Context *ctx); void puts(Context *ctx, int loc, const char *str); +void setTileMap(Context *ctx, int layer, int columns, int rows, uint16_t *buff); + } } diff --git a/src/nostalgia/player/CMakeLists.txt b/src/nostalgia/player/CMakeLists.txt index b4d2bf9e..c12201e5 100644 --- a/src/nostalgia/player/CMakeLists.txt +++ b/src/nostalgia/player/CMakeLists.txt @@ -1,6 +1,3 @@ -cmake_minimum_required(VERSION 2.8.11) - -project(nostalgia) add_executable( nostalgia @@ -34,12 +31,3 @@ install( bin ) -if (NOSTALGIA_BUILD_TYPE STREQUAL "GBA") - install( - FILES - nostalgia.bin - DESTINATION - bin - ) -endif() - diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 92ad0db1..e855dd9a 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -54,8 +53,8 @@ MainWindow::MainWindow(QString profilePath) { setWindowTitle(profile.appName); - auto tabbar = new QTabBar(this); - setCentralWidget(tabbar); + m_tabbar = new QTabBar(this); + setCentralWidget(m_tabbar); setupMenu(); setupProjectExplorer(); diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index 72f29268..71cfd166 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -90,6 +91,7 @@ class MainWindow: public QMainWindow { QTreeView *m_projectExplorer = nullptr; QVector m_plugins; QPointer m_oxfsView = nullptr; + QTabBar *m_tabbar; public: MainWindow(QString profilePath); diff --git a/src/nostalgia/world/CMakeLists.txt b/src/nostalgia/world/CMakeLists.txt new file mode 100644 index 00000000..6990a21b --- /dev/null +++ b/src/nostalgia/world/CMakeLists.txt @@ -0,0 +1,13 @@ + +add_library( + NostalgiaWorld + world.cpp +) + +#install(TARGETS NostalgiaCommon DESTINATION lib) +install( + FILES + world.hpp + DESTINATION + include/nostalgia/world +) diff --git a/src/nostalgia/world/world.cpp b/src/nostalgia/world/world.cpp new file mode 100644 index 00000000..fa9c7ac7 --- /dev/null +++ b/src/nostalgia/world/world.cpp @@ -0,0 +1,15 @@ +/* + * Copyright 2016-2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "world.hpp" + +namespace nostalgia { +namespace world { + +} +} diff --git a/src/nostalgia/world/world.hpp b/src/nostalgia/world/world.hpp new file mode 100644 index 00000000..ae899727 --- /dev/null +++ b/src/nostalgia/world/world.hpp @@ -0,0 +1,23 @@ +/* + * Copyright 2016-2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +namespace nostalgia { +namespace world { + +struct ZoneDef { + int width = 0; + int height = 0; + uint16_t tileMap; +}; + +} +}