diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f492537..44afdc29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,6 @@ add_definitions( -nostdlib -fno-exceptions -fno-rtti - #-g - #-fcolor-diagnostics - #--analyze - #-Os # GCC size optimization flag ) if (CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/Dockerfile b/Dockerfile index e64167e6..7dbdd897 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ -FROM wombatant/devenv +FROM wombatant/devenv:latest ENV DEVKITPRO /opt/devkitPro ENV DEVKITARM ${DEVKITPRO}/devkitARM +RUN dnf install -y qt5-devel + ############################################################################### # Install Ox diff --git a/scripts/newcpp b/scripts/newcpp index fabe54bd..73620a2f 100755 --- a/scripts/newcpp +++ b/scripts/newcpp @@ -7,7 +7,7 @@ if len(sys.argv) < 3: pkg = sys.argv[1] name = sys.argv[2] -namespace = "namespace wombat {\nnamespace %s {\n\n}\n}" % pkg +namespace = "namespace nostalgia {\nnamespace %s {\n\n}\n}" % pkg hpp = "#pragma once\n" cpp = "#include \"%s.hpp\"\n\n%s" % (name, namespace) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b9110e1..045aa9cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8.11) #setup libraries @@ -20,4 +20,5 @@ add_subdirectory(player) if(NOT WOMBAT_BUILD_TYPE STREQUAL "GBA") add_subdirectory(tools) + add_subdirectory(studio) endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 8ed84437..13a73697 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8.11) add_library( NostalgiaCommon diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7f94f0ef..20e2755e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8.11) if(WOMBAT_BUILD_TYPE STREQUAL "GBA") enable_language(C ASM) @@ -8,6 +8,9 @@ if(WOMBAT_BUILD_TYPE STREQUAL "GBA") gba/media.cpp ) elseif(WOMBAT_BUILD_TYPE STREQUAL "Native") + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(CMAKE_AUTOMOC ON) + set( CPP qt/gfx.cpp diff --git a/src/player/CMakeLists.txt b/src/player/CMakeLists.txt index 45dbdf24..63fb5de7 100644 --- a/src/player/CMakeLists.txt +++ b/src/player/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8.11) project(nostalgia) diff --git a/src/player/main.cpp b/src/player/main.cpp index 1c5378bc..f405b349 100644 --- a/src/player/main.cpp +++ b/src/player/main.cpp @@ -13,7 +13,7 @@ using namespace nostalgia; int main() { core::init(); core::initConsole(); - core::puts(9 * 32 + 8, "HELLO, WORLD!"); + core::puts(9 * 32 + 8, "HELLO,WORLD!"); core::puts(10 * 32 + 8, "01234 56789"); while (1); return 0; diff --git a/src/studio/CMakeLists.txt b/src/studio/CMakeLists.txt new file mode 100644 index 00000000..29ed79f9 --- /dev/null +++ b/src/studio/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(nostalgia-studio) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +add_executable( + nostalgia-studio + main.cpp + mainwindow.cpp +) + +target_link_libraries( + nostalgia-studio + Qt5::Core + Qt5::Widgets + ${OxClArgs_LIBRARY} + ${OxFS_LIBRARY} + ${OxStd_LIBRARY} + NostalgiaCommon + NostalgiaCore + NostalgiaStudioJson +) + +install( + TARGETS + nostalgia-studio + RUNTIME DESTINATION + bin +) + +add_subdirectory(json) diff --git a/src/studio/json/CMakeLists.txt b/src/studio/json/CMakeLists.txt new file mode 100644 index 00000000..3a5e3d1a --- /dev/null +++ b/src/studio/json/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(NostalgiaStudioJson) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +add_library( + NostalgiaStudioJson + json_read.cpp + json_write.cpp +) + +target_link_libraries( + NostalgiaStudioJson + Qt5::Core + Qt5::Widgets +) + +install( + FILES + json.hpp + json_read.hpp + json_write.hpp + DESTINATION + include/nostalgia/studio/json +) + + +add_executable( + NostalgiaStudioJsonTest + test.cpp +) + +target_link_libraries( + NostalgiaStudioJsonTest + NostalgiaStudioJson +) + +add_test("Test\\ NostalgiaStudioJson" NostalgiaStudioJsonTest) diff --git a/src/studio/json/json.hpp b/src/studio/json/json.hpp new file mode 100644 index 00000000..d9c75f67 --- /dev/null +++ b/src/studio/json/json.hpp @@ -0,0 +1,31 @@ +/* + * 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 "json_read.hpp" +#include "json_write.hpp" + +namespace nostalgia { +namespace studio { + +class JsonOperator { + + public: + virtual int op(QString fieldName, int *dest) = 0; + + virtual int op(QString fieldName, bool *dest) = 0; + + virtual int op(QString fieldName, double *dest) = 0; + + virtual int op(QString fieldName, QString *dest) = 0; + +}; + +} +} diff --git a/src/studio/json/json_operator.hpp b/src/studio/json/json_operator.hpp new file mode 100644 index 00000000..eef33c62 --- /dev/null +++ b/src/studio/json/json_operator.hpp @@ -0,0 +1,18 @@ +/* + * 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 +#include + +namespace nostalgia { +namespace studio { + +} +} diff --git a/src/studio/json/json_read.cpp b/src/studio/json/json_read.cpp new file mode 100644 index 00000000..13481afc --- /dev/null +++ b/src/studio/json/json_read.cpp @@ -0,0 +1,89 @@ +/* + * 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 "json_read.hpp" + +namespace nostalgia { +namespace studio { + +JsonReader::JsonReader(QJsonObject &obj): m_src(obj) { +} + +ox::Error JsonReader::op(QString fieldName, int *dest) { + if (m_src.contains(fieldName)) { + return op(m_src[fieldName], dest); + } else { + return JSON_ERR_FIELD_MISSING; + } +} + +ox::Error JsonReader::op(QString fieldName, bool *dest) { + if (m_src.contains(fieldName)) { + return op(m_src[fieldName], dest); + } else { + return JSON_ERR_FIELD_MISSING; + } +} + +ox::Error JsonReader::op(QString fieldName, double *dest) { + if (m_src.contains(fieldName)) { + return op(m_src[fieldName], dest); + } else { + return JSON_ERR_FIELD_MISSING; + } +} + +ox::Error JsonReader::op(QString fieldName, QString *dest) { + if (m_src.contains(fieldName)) { + return op(m_src[fieldName], dest); + } else { + return JSON_ERR_FIELD_MISSING; + } +} + + + +ox::Error JsonReader::op(QJsonValueRef src, int *dest) { + if (src.isDouble()) { + *dest = src.toInt(); + return 0; + } else { + return JSON_ERR_UNEXPECTED_TYPE; + } +} + +ox::Error JsonReader::op(QJsonValueRef src, bool *dest) { + if (src.isBool()) { + *dest = src.toBool(); + return 0; + } else { + return JSON_ERR_UNEXPECTED_TYPE; + } +} + +ox::Error JsonReader::op(QJsonValueRef src, double *dest) { + if (src.isDouble()) { + *dest = src.toDouble(); + return 0; + } else { + return JSON_ERR_UNEXPECTED_TYPE; + } +} + +ox::Error JsonReader::op(QJsonValueRef src, QString *dest) { + if (src.isString()) { + *dest = src.toString(); + return 0; + } else { + return JSON_ERR_UNEXPECTED_TYPE; + } +} + + +} +} diff --git a/src/studio/json/json_read.hpp b/src/studio/json/json_read.hpp new file mode 100644 index 00000000..892b7808 --- /dev/null +++ b/src/studio/json/json_read.hpp @@ -0,0 +1,83 @@ +/* + * 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 +#include +#include +#include "json_operator.hpp" + +namespace nostalgia { +namespace studio { + +enum { + JSON_ERR_FIELD_MISSING, + JSON_ERR_UNEXPECTED_TYPE, +}; + +class JsonReader { + + private: + QJsonObject &m_src; + + public: + JsonReader(QJsonObject &obj); + + ox::Error op(QString fieldName, int *dest); + + ox::Error op(QString fieldName, bool *dest); + + ox::Error op(QString fieldName, double *dest); + + ox::Error op(QString fieldName, QString *dest); + + template + ox::Error op(QString fieldName, T *dest); + + template + ox::Error op(QString fieldName, QVector *dest); + + private: + ox::Error op(QJsonValueRef src, int *dest); + + ox::Error op(QJsonValueRef src, bool *dest); + + ox::Error op(QJsonValueRef src, double *dest); + + ox::Error op(QJsonValueRef src, QString *dest); + +}; + +template +ox::Error JsonReader::op(QString fieldName, T *dest) { + auto obj = m_src[fieldName].toObject(); + auto reader = JsonReader(obj); + return ioOp(&reader, dest); +}; + +template +ox::Error JsonReader::op(QString fieldName, QVector *dest) { + ox::Error err = 0; + auto a = m_src[fieldName].toArray(); + dest->resize(a.size()); + for (int i = 0; i < dest->size(); i++) { + err |= op(a[i], &dest->at(i)); + } + return err; +}; + +template +int read(QString json, T *dest) { + auto obj = QJsonDocument::fromJson(json.toUtf8()).object(); + JsonReader rdr(obj); + return ioOp(&rdr, dest); +} + +} +} diff --git a/src/studio/json/json_write.cpp b/src/studio/json/json_write.cpp new file mode 100644 index 00000000..5ab43270 --- /dev/null +++ b/src/studio/json/json_write.cpp @@ -0,0 +1,16 @@ +/* + * 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 "json_write.hpp" + +namespace nostalgia { +namespace studio { + + +} +} diff --git a/src/studio/json/json_write.hpp b/src/studio/json/json_write.hpp new file mode 100644 index 00000000..20b56572 --- /dev/null +++ b/src/studio/json/json_write.hpp @@ -0,0 +1,16 @@ +/* + * 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 + +namespace nostalgia { +namespace studio { + + +} +} diff --git a/src/studio/json/test.cpp b/src/studio/json/test.cpp new file mode 100644 index 00000000..1c3d2f6b --- /dev/null +++ b/src/studio/json/test.cpp @@ -0,0 +1,86 @@ +/* + * 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 +#include "json.hpp" + +using namespace std; +using namespace ox; +using namespace nostalgia::studio; + +struct TestStructNest { + bool Bool; + int Int; + double Double; + QString String; +}; + +template +int ioOp(T *io, TestStructNest *obj) { + Error err = 0; + err |= io->op("Bool", &obj->Bool); + err |= io->op("Int", &obj->Int); + err |= io->op("Double", &obj->Double); + err |= io->op("String", &obj->String); + return err; +} + +struct TestStruct { + bool Bool; + int Int; + double Double; + QString String; + TestStructNest Struct; +}; + +template +int ioOp(T *io, TestStruct *obj) { + Error err = 0; + err |= io->op("Bool", &obj->Bool); + err |= io->op("Int", &obj->Int); + err |= io->op("Double", &obj->Double); + err |= io->op("String", &obj->String); + err |= io->op("Struct", &obj->Struct); + return err; +} + +int main(int argc, char **args) { + int err = 0; + auto json = + "{" + " \"Bool\": true," + " \"Int\": 42," + " \"Double\": 42.42," + " \"String\": \"Test String\"," + " \"Struct\": {" + " \"Bool\": true," + " \"Int\": 42," + " \"Double\": 42.42," + " \"String\": \"Test String\"" + " }" + "}"; + TestStruct ts; + read(json, &ts); + + cout << ts.Bool << endl; + cout << ts.Int << endl; + cout << ts.Double << endl; + cout << ts.String.toStdString() << endl; + + err |= !(ts.Bool) << 0; + err |= !(ts.Int == 42) << 1; + err |= !(ts.Double == 42.42) << 2; + err |= !(ts.String == "Test String") << 3; + + err |= !(ts.Struct.Bool) << 4; + err |= !(ts.Struct.Int == 42) << 5; + err |= !(ts.Struct.Double == 42.42) << 6; + err |= !(ts.Struct.String == "Test String") << 7; + + return err; +} diff --git a/src/studio/main.cpp b/src/studio/main.cpp new file mode 100644 index 00000000..652f88d9 --- /dev/null +++ b/src/studio/main.cpp @@ -0,0 +1,21 @@ +/* + * 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 +#include "studio/mainwindow.hpp" + +using namespace nostalgia::studio; + +int main(int argc, char **argv) { + QApplication app(argc, argv); + + MainWindow w; + w.show(); + + return app.exec(); +} diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp new file mode 100644 index 00000000..04bcaabf --- /dev/null +++ b/src/studio/mainwindow.cpp @@ -0,0 +1,32 @@ +/* + * 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 +#include +#include "studio/mainwindow.hpp" + +namespace nostalgia { +namespace studio { + +MainWindow::MainWindow(QWidget *parent) { + auto screenSize = QApplication::desktop()->screenGeometry(); + + // set window to 70% of screen width, and center it + auto sizePct = 0.7; + resize(screenSize.width() * sizePct, screenSize.height() * sizePct); + move(-x(), -y()); + move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2); + + setWindowTitle("Nostalgia Studio"); +} + +MainWindow::~MainWindow() { +} + +} +} diff --git a/src/studio/mainwindow.hpp b/src/studio/mainwindow.hpp new file mode 100644 index 00000000..7be3c5f1 --- /dev/null +++ b/src/studio/mainwindow.hpp @@ -0,0 +1,42 @@ +/* + * 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 +#include +#include +#include + +namespace nostalgia { +namespace studio { + +class MainWindow: public QMainWindow { + Q_OBJECT + public: + static const QString EditorSettings; + static const QString AppTitle; + + private: + QString m_projectPath; + + public: + explicit MainWindow(QWidget *parent = 0); + virtual ~MainWindow(); + + void openProject(QString); + + private: + void setupDockWidgets(); + int readSettings(QString path); + int writeSettings(QString path); + + public slots: +}; + +} +} diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3e69dc97..b3ef7c1c 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8.11) project(nost-pack) @@ -23,7 +23,3 @@ install( RUNTIME DESTINATION bin ) - -set(CMAKE_INCLUDE_CURRENT_DIR OFF) -set(CMAKE_AUTOMOC OFF) -