Add ioOp functions for Point and Bounds
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
| @@ -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<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; | ||||
| } | ||||
|  | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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 <ox/std/types.hpp> | ||||
|  | ||||
| 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<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; | ||||
| } | ||||
|  | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -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) { | ||||
| } | ||||
|  | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -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() | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,6 @@ | ||||
| #include <QLineEdit> | ||||
| #include <QMenuBar> | ||||
| #include <QPluginLoader> | ||||
| #include <QTabBar> | ||||
| #include <QTextStream> | ||||
| #include <QVector> | ||||
|  | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -17,6 +17,7 @@ | ||||
| #include <QPointer> | ||||
| #include <QSharedPointer> | ||||
| #include <QString> | ||||
| #include <QTabBar> | ||||
| #include <QTreeView> | ||||
| #include <QVector> | ||||
|  | ||||
| @@ -90,6 +91,7 @@ class MainWindow: public QMainWindow { | ||||
| 		QTreeView *m_projectExplorer = nullptr; | ||||
| 		QVector<Plugin*> m_plugins; | ||||
| 		QPointer<OxFSModel> m_oxfsView = nullptr; | ||||
| 		QTabBar *m_tabbar; | ||||
|  | ||||
| 	public: | ||||
| 		MainWindow(QString profilePath); | ||||
|   | ||||
							
								
								
									
										13
									
								
								src/nostalgia/world/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/nostalgia/world/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
|  | ||||
| add_library( | ||||
| 	NostalgiaWorld | ||||
| 		world.cpp | ||||
| ) | ||||
|  | ||||
| #install(TARGETS NostalgiaCommon DESTINATION lib) | ||||
| install( | ||||
| 	FILES | ||||
| 		world.hpp | ||||
| 	DESTINATION | ||||
| 		include/nostalgia/world | ||||
| ) | ||||
							
								
								
									
										15
									
								
								src/nostalgia/world/world.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/nostalgia/world/world.cpp
									
									
									
									
									
										Normal 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 { | ||||
|  | ||||
| } | ||||
| } | ||||
							
								
								
									
										23
									
								
								src/nostalgia/world/world.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/nostalgia/world/world.hpp
									
									
									
									
									
										Normal 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; | ||||
| }; | ||||
|  | ||||
| } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user