Add ioOp functions for Point and Bounds

This commit is contained in:
Gary Talent 2017-10-12 16:09:36 -05:00
parent 507c894c15
commit 9c2e71045f
13 changed files with 136 additions and 65 deletions

View File

@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 2.8.11)
#setup libraries #setup libraries
@ -11,6 +10,7 @@ endif()
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(common) add_subdirectory(common)
add_subdirectory(player) add_subdirectory(player)
add_subdirectory(world)
if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA") if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA")
add_subdirectory(tools) add_subdirectory(tools)

View File

@ -14,23 +14,23 @@ Bounds::Bounds() {
} }
bool Bounds::intersects(Bounds o) const { 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 { 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 { int Bounds::x2() const {
return X + Width; return x + width;
} }
int Bounds::y2() const { int Bounds::y2() const {
return Y + Height; return y + height;
} }
Point Bounds::pt1() { Point Bounds::pt1() {
return Point(X, Y); return Point(x, y);
} }
Point Bounds::pt2() { Point Bounds::pt2() {

View File

@ -14,10 +14,10 @@ namespace common {
class Bounds { class Bounds {
public: public:
int X = 0; int x = 0;
int Y = 0; int y = 0;
int Width = 0; int width = 0;
int Height = 0; int height = 0;
/** /**
* Constructor * Constructor
@ -37,5 +37,16 @@ class Bounds {
Point pt2(); Point pt2();
}; };
template<typename T>
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;
}
} }
} }

View File

@ -14,110 +14,110 @@ Point::Point() {
} }
Point::Point(int x, int y) { Point::Point(int x, int y) {
X = x; this->x = x;
Y = y; this->y = y;
} }
Point Point::operator+(common::Point p) const { Point Point::operator+(common::Point p) const {
p.X += X; p.x += x;
p.Y += Y; p.y += y;
return p; return p;
} }
Point Point::operator-(common::Point p) const { Point Point::operator-(common::Point p) const {
auto out = *this; auto out = *this;
out.X -= p.X; out.x -= p.x;
out.Y -= p.Y; out.y -= p.y;
return out; return out;
} }
Point Point::operator*(common::Point p) const { Point Point::operator*(common::Point p) const {
p.X *= X; p.x *= x;
p.Y *= Y; p.y *= y;
return p; return p;
} }
Point Point::operator/(common::Point p) const { Point Point::operator/(common::Point p) const {
auto out = *this; auto out = *this;
out.X /= p.X; out.x /= p.x;
out.Y /= p.Y; out.y /= p.y;
return out; return out;
} }
Point Point::operator+=(common::Point p) { Point Point::operator+=(common::Point p) {
X += p.X; x += p.x;
Y += p.Y; y += p.y;
return *this; return *this;
} }
Point Point::operator-=(common::Point p) { Point Point::operator-=(common::Point p) {
X -= p.X; x -= p.x;
Y -= p.Y; y -= p.y;
return *this; return *this;
} }
Point Point::operator*=(common::Point p) { Point Point::operator*=(common::Point p) {
X *= p.X; x *= p.x;
Y *= p.Y; y *= p.y;
return *this; return *this;
} }
Point Point::operator/=(common::Point p) { Point Point::operator/=(common::Point p) {
X /= p.X; x /= p.x;
Y /= p.Y; y /= p.y;
return *this; return *this;
} }
Point Point::operator+(int i) const { Point Point::operator+(int i) const {
auto out = *this; auto out = *this;
out.X += i; out.x += i;
out.Y += i; out.y += i;
return out; return out;
} }
Point Point::operator-(int i) const { Point Point::operator-(int i) const {
auto out = *this; auto out = *this;
out.X -= i; out.x -= i;
out.Y -= i; out.y -= i;
return out; return out;
} }
Point Point::operator*(int i) const { Point Point::operator*(int i) const {
auto out = *this; auto out = *this;
out.X *= i; out.x *= i;
out.Y *= i; out.y *= i;
return out; return out;
} }
Point Point::operator/(int i) const { Point Point::operator/(int i) const {
auto out = *this; auto out = *this;
out.X /= i; out.x /= i;
out.Y /= i; out.y /= i;
return out; return out;
} }
Point Point::operator+=(int i) { Point Point::operator+=(int i) {
X += i; x += i;
Y += i; y += i;
return *this; return *this;
} }
Point Point::operator-=(int i) { Point Point::operator-=(int i) {
X -= i; x -= i;
Y -= i; y -= i;
return *this; return *this;
} }
Point Point::operator*=(int i) { Point Point::operator*=(int i) {
X *= i; x *= i;
Y *= i; y *= i;
return *this; return *this;
} }
Point Point::operator/=(int i) { Point Point::operator/=(int i) {
X /= i; x /= i;
Y /= i; y /= i;
return *this; return *this;
} }

View File

@ -5,15 +5,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#pragma once #pragma once
#include <ox/std/types.hpp>
namespace nostalgia { namespace nostalgia {
namespace common { namespace common {
class Point { class Point {
public: public:
int X = 0; int x = 0;
int Y = 0; int y = 0;
Point(); Point();
@ -55,5 +58,14 @@ class Point {
Point operator/=(int i); Point operator/=(int i);
}; };
template<typename T>
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;
}
} }
} }

View File

@ -137,19 +137,22 @@ ox::Error initConsole(Context *ctx) {
REG_BG0CNT = (28 << 8) | 1; REG_BG0CNT = (28 << 8) | 1;
if (fs) { if (fs) {
// load the header
err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr); err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr);
// load palette // load palette
err |= fs->read(CharsetInode, PaletteStart, 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) { if (imgData.bpp == 4) {
err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles), err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr); sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 4) { } else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles), 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 { } else {
err = 1; 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) {
}
} }
} }

View File

@ -20,5 +20,7 @@ ox::Error initConsole(Context *ctx);
void puts(Context *ctx, int loc, const char *str); void puts(Context *ctx, int loc, const char *str);
void setTileMap(Context *ctx, int layer, int columns, int rows, uint16_t *buff);
} }
} }

View File

@ -1,6 +1,3 @@
cmake_minimum_required(VERSION 2.8.11)
project(nostalgia)
add_executable( add_executable(
nostalgia nostalgia
@ -34,12 +31,3 @@ install(
bin bin
) )
if (NOSTALGIA_BUILD_TYPE STREQUAL "GBA")
install(
FILES
nostalgia.bin
DESTINATION
bin
)
endif()

View File

@ -17,7 +17,6 @@
#include <QLineEdit> #include <QLineEdit>
#include <QMenuBar> #include <QMenuBar>
#include <QPluginLoader> #include <QPluginLoader>
#include <QTabBar>
#include <QTextStream> #include <QTextStream>
#include <QVector> #include <QVector>
@ -54,8 +53,8 @@ MainWindow::MainWindow(QString profilePath) {
setWindowTitle(profile.appName); setWindowTitle(profile.appName);
auto tabbar = new QTabBar(this); m_tabbar = new QTabBar(this);
setCentralWidget(tabbar); setCentralWidget(m_tabbar);
setupMenu(); setupMenu();
setupProjectExplorer(); setupProjectExplorer();

View File

@ -17,6 +17,7 @@
#include <QPointer> #include <QPointer>
#include <QSharedPointer> #include <QSharedPointer>
#include <QString> #include <QString>
#include <QTabBar>
#include <QTreeView> #include <QTreeView>
#include <QVector> #include <QVector>
@ -90,6 +91,7 @@ class MainWindow: public QMainWindow {
QTreeView *m_projectExplorer = nullptr; QTreeView *m_projectExplorer = nullptr;
QVector<Plugin*> m_plugins; QVector<Plugin*> m_plugins;
QPointer<OxFSModel> m_oxfsView = nullptr; QPointer<OxFSModel> m_oxfsView = nullptr;
QTabBar *m_tabbar;
public: public:
MainWindow(QString profilePath); MainWindow(QString profilePath);

View File

@ -0,0 +1,13 @@
add_library(
NostalgiaWorld
world.cpp
)
#install(TARGETS NostalgiaCommon DESTINATION lib)
install(
FILES
world.hpp
DESTINATION
include/nostalgia/world
)

View File

@ -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 {
}
}

View File

@ -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 <ox/std/types.hpp>
namespace nostalgia {
namespace world {
struct ZoneDef {
int width = 0;
int height = 0;
uint16_t tileMap;
};
}
}