[nostalgia] Address CLion recommendations

This commit is contained in:
Gary Talent 2021-02-26 08:55:40 -06:00
parent d50551cc74
commit 44f4d67c80
14 changed files with 53 additions and 78 deletions

View File

@ -112,13 +112,13 @@ int main() {
```
The code base where this was observed actually got away with this for the most
part, as the std::vector implementation used evidentally waited until the
part, as the std::vector implementation used evidently waited until the
internal array was needed before initializing and the memory was zeroed out
because the allocation occurred early in the program's execution. While the
std::vector implementation in queston worked with this code and the memory leak
is not noticable because the std::vector was meant to exist for the entire life
std::vector implementation in question worked with this code and the memory leak
is not noticeable because the std::vector was meant to exist for the entire life
of the process, other classes likely will not get away with it due to more
substantial constructors and more frequent instatiations of the classes in
substantial constructors and more frequent instantiations of the classes in
question.
### Pointers vs References
@ -140,7 +140,7 @@ one of the main reasons why many embedded developers prefer C to C++.
Instead throwing exceptions, all engine code must return error codes. Nostalgia
and Ox both use ```ox::Error``` to report errors. ```ox::Error``` is a struct
that has overloaded operators to behave like an integer error code, plus some
extra fields to enhance debugability. If instantiated through the ```OxError(x)```
extra fields to enhance debuggability. If instantiated through the ```OxError(x)```
macro, it will also include the file and line of the error. The ```OxError(x)```
macro should only be used for the initial instantiation of an ```ox::Error```.
@ -186,7 +186,7 @@ back up the call stack, ```oxReturnError``` and ```oxThrowError```.
will return an ```ox::Error``` if it is not 0 and ```oxThrowError``` will throw
an ```ox::Error``` if it is not 0. Because exceptions are disabled for GBA
builds and thus cannot be used in the engine, ```oxThrowError``` is only really
useful at the boundry between engine libraries and Nostalgia Studio.
useful at the boundary between engine libraries and Nostalgia Studio.
```cpp
void studioCode() {
@ -223,7 +223,7 @@ ox::Error engineCode() {
### File I/O
All engine file I/O should go through nostalgia::core::Context, which should go
through ox::FileSystem. Similarly, all studio file I/O should go throuh
through ox::FileSystem. Similarly, all studio file I/O should go thorough
nostalgia::studio::Project, which should go through ox::FileSystem.
ox::FileSystem abstracts away differences between conventional storage devices

View File

@ -9,9 +9,11 @@ import sys
from pybb import mkdir, rm
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--target', help='Platform target ({OS}-{Arch},gba)', default='{:s}-{:s}'.format(sys.platform, platform.machine()))
parser.add_argument('--target', help='Platform target ({OS}-{Arch},gba)',
default='{:s}-{:s}'.format(sys.platform, platform.machine()))
parser.add_argument('--build_type', help='Build type (asan,debug,release)', default='release')
parser.add_argument('--build_tool', help='Build tool (default,xcode)', default='')
parser.add_argument('--vcpkg_dir', help='Path to VCPKG')
@ -33,6 +35,9 @@ def main():
elif args.build_type == 'release':
build_type_arg = 'Release'
sanitizer_status = 'OFF'
else:
print('Error: Invalid build tool')
sys.exit(1)
if args.build_tool == 'xcode':
build_config = '{:s}-{:s}'.format(args.target, args.build_tool)
@ -45,27 +50,30 @@ def main():
qt_path = ''
if args.build_tool == '' or args.build_tool == 'default':
if shutil.which('ninja') == None:
if shutil.which('ninja') is None:
build_tool = ''
else:
build_tool = '-GNinja'
elif args.build_tool == 'xcode':
build_tool = '-GXcode'
else:
print('Error: Invalid build tool')
sys.exit(1)
project_dir = os.getcwd()
build_dir = '{:s}/build/{:s}'.format(project_dir, build_config)
rm(build_dir)
mkdir(build_dir)
subprocess.run(['cmake', '-S', project_dir, '-B', build_dir, build_tool,
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
'-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg),
'-DUSE_ASAN={:s}'.format(sanitizer_status),
'-DNOSTALGIA_IDE_BUILD=OFF',
'-DNOSTALGIA_BUILD_CONFIG={:s}'.format(build_config),
'-DNOSTALGIA_BUILD_TYPE={:s}'.format(nostalgia_build_type),
qt_path,
toolchain,
])
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
'-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg),
'-DUSE_ASAN={:s}'.format(sanitizer_status),
'-DNOSTALGIA_IDE_BUILD=OFF',
'-DNOSTALGIA_BUILD_CONFIG={:s}'.format(build_config),
'-DNOSTALGIA_BUILD_TYPE={:s}'.format(nostalgia_build_type),
qt_path,
toolchain,
])
mkdir('dist')
if args.target != 'gba':
@ -77,9 +85,9 @@ def main():
if platform.system() != 'Windows':
os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(1)

View File

@ -22,17 +22,17 @@ class Bounds {
Bounds(int x, int y, int w, int h);
bool intersects(Bounds other) const;
[[nodiscard]] bool intersects(Bounds other) const;
bool contains(int x, int y) const;
[[nodiscard]] bool contains(int x, int y) const;
int x2() const;
[[nodiscard]] int x2() const;
int y2() const;
[[nodiscard]] int y2() const;
Point pt1();
[[nodiscard]] Point pt1();
Point pt2();
[[nodiscard]] Point pt2();
};
template<typename T>

View File

@ -32,7 +32,6 @@ install(
gfx.hpp
input.hpp
media.hpp
mem.hpp
DESTINATION
include/nostalgia/core
)

View File

@ -219,7 +219,7 @@ void clearTileLayer(Context*, int layer) {
memset(&MEM_BG_MAP[layer], 0, GbaTileRows * GbaTileColumns);
}
void hideSprite(Context*, unsigned idx) {
[[maybe_unused]] void hideSprite(Context*, unsigned idx) {
oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
GbaSpriteAttrUpdate oa;
oa.attr0 = 2 << 8;

View File

@ -139,7 +139,7 @@ void setTile(Context *ctx, int layer, int column, int row, uint8_t tile);
void clearTileLayer(Context*, int layer);
void hideSprite(Context*, unsigned);
[[maybe_unused]] void hideSprite(Context*, unsigned);
void setSprite(Context*, unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0);

View File

@ -1,13 +0,0 @@
/*
* Copyright 2016 - 2021 gary@drinkingtea.net
*
* 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/.
*/
namespace nostalgia::core {
void initHeap();
}

View File

@ -50,7 +50,7 @@ void setEventHandler(event_handler h) {
}
uint64_t ticksMs() {
return SDL_GetTicks();;
return SDL_GetTicks();
}
bool buttonDown(Key) {

View File

@ -7,7 +7,6 @@
*/
#include <array>
#include <vector>
#ifdef NOST_FPS_PRINT
#include <iostream>
#endif
@ -196,7 +195,7 @@ void draw(Context *ctx) {
void puts(Context *ctx, int column, int row, const char *str) {
for (int i = 0; str[i]; i++) {
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(charMap[static_cast<int>(str[i])]));
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
}
}
@ -208,6 +207,7 @@ void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) {
id->bgTileMaps[z][y][x] = tile;
}
[[maybe_unused]]
void hideSprite(Context*, unsigned) {
}

View File

@ -29,18 +29,6 @@ namespace nostalgia::core {
return colStart + colOffset + rowStart + rowOffset;
}
template<typename T>
ox::Result<std::vector<uint8_t>> toBuffer(T *data, std::size_t buffSize = ox::units::MB) {
std::vector<uint8_t> buff(buffSize);
std::size_t sz = 0;
oxReturnError(ox::writeMC(buff.data(), buff.size(), data, &sz));
if (sz > buffSize) {
return OxError(1);
}
buff.resize(sz);
return buff;
}
[[nodiscard]] std::unique_ptr<core::NostalgiaGraphic> imgToNg(QString argInPath, int argBpp = -1);
[[nodiscard]] std::unique_ptr<core::NostalgiaGraphic> imgToNg(QString argInPath, int argBpp = -1);
}

View File

@ -8,7 +8,6 @@
#include <QBuffer>
#include <QDebug>
#include <QFile>
#include <nostalgia/core/consts.hpp>
#include <nostalgia/core/gfx.hpp>

View File

@ -31,22 +31,22 @@ enum class PaletteEditorCommandId {
class ColorChannelValidator: public QValidator {
public:
ColorChannelValidator(QLineEdit *parent);
explicit ColorChannelValidator(QLineEdit *parent);
QValidator::State validate(QString &input, int&) const override;
private:
QString convert(const QString &input) const;
[[nodiscard]] static QString convert(const QString &input);
};
ColorChannelValidator::ColorChannelValidator(QLineEdit *parent): QValidator(parent) {
connect(parent, &QLineEdit::editingFinished, [this, parent] {
connect(parent, &QLineEdit::editingFinished, [parent] {
parent->setText(convert(parent->text()));
});
}
QString ColorChannelValidator::convert(const QString &input) const {
QString ColorChannelValidator::convert(const QString &input) {
int num = 0;
if (input[0] == '_') {
num = input.mid(1).toInt() >> 3;
@ -86,9 +86,9 @@ class AddColorCommand: public QUndoCommand {
m_idx = idx;
}
virtual ~AddColorCommand() = default;
~AddColorCommand() override = default;
int id() const override {
[[nodiscard]] int id() const override {
return static_cast<int>(PaletteEditorCommandId::AddColor);
}
@ -115,9 +115,9 @@ class RemoveColorCommand: public QUndoCommand {
m_idx = idx;
}
virtual ~RemoveColorCommand() = default;
~RemoveColorCommand() override = default;
int id() const override {
[[nodiscard]] int id() const override {
return static_cast<int>(PaletteEditorCommandId::RemoveColor);
}
@ -147,9 +147,9 @@ class UpdateColorCommand: public QUndoCommand {
setObsolete(m_oldColor == m_newColor);
}
virtual ~UpdateColorCommand() = default;
~UpdateColorCommand() override = default;
int id() const override {
[[nodiscard]] int id() const override {
return static_cast<int>(PaletteEditorCommandId::UpdateColor);
}
@ -176,9 +176,9 @@ class MoveColorCommand: public QUndoCommand {
m_offset = offset;
}
virtual ~MoveColorCommand() = default;
~MoveColorCommand() override = default;
int id() const override {
[[nodiscard]] int id() const override {
return static_cast<int>(PaletteEditorCommandId::MoveColor);
}
@ -212,7 +212,7 @@ void PaletteEditorColorTableDelegate::paint(QPainter *painter, const QStyleOptio
}
static QTableWidgetItem *mkCell(QString v, bool editable = true) {
static QTableWidgetItem *mkCell(const QString& v, bool editable = true) {
auto c = new QTableWidgetItem;
c->setText(v);
c->setFont(QFont("monospace"));
@ -345,7 +345,7 @@ Color16 PaletteEditor::rowColor(int row) const {
void PaletteEditor::colorSelected() {
auto selIdxs = m_table->selectionModel()->selectedIndexes();
auto row = selIdxs.size() ? selIdxs[0].row() : -1;
auto row = !selIdxs.empty() ? selIdxs[0].row() : -1;
if (row > -1) {
m_rmBtn->setEnabled(true);
m_moveUpBtn->setEnabled(row > 0);

View File

@ -10,7 +10,6 @@
#include <QDialog>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QPainter>
#include <QPointer>
@ -18,15 +17,12 @@
#include <QQmlContext>
#include <QQuickItem>
#include <QQuickWidget>
#include <QSet>
#include <QSettings>
#include <QSpinBox>
#include <QSplitter>
#include <QTableWidget>
#include <QToolBar>
#include <QUndoCommand>
#include <QVBoxLayout>
#include <qnamespace.h>
#include <nostalgia/core/consts.hpp>
#include <nostalgia/common/point.hpp>

View File

@ -7,10 +7,8 @@
*/
#include <ox/fs/fs.hpp>
#include <ox/std/units.hpp>
#include <nostalgia/core/core.hpp>
#include <nostalgia/core/input.hpp>
#include <nostalgia/world/world.hpp>
using namespace nostalgia;