Reformat code with clang-format's Webkit brace wrapping
This commit is contained in:
parent
202fbf2868
commit
07fa34dd36
@ -12,26 +12,30 @@ AlwaysBreakAfterReturnType: None
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
ContinuationIndentWidth: 4
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: MultiLine
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: false
|
||||
|
||||
BeforeCatch: true
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
|
||||
BreakBeforeBraces: WebKit
|
||||
#BraceWrapping:
|
||||
# AfterCaseLabel: false
|
||||
# AfterClass: true
|
||||
# AfterControlStatement: MultiLine
|
||||
# AfterEnum: false
|
||||
# AfterFunction: true
|
||||
# AfterNamespace: false
|
||||
# AfterObjCDeclaration: false
|
||||
# AfterStruct: true
|
||||
# AfterUnion: true
|
||||
# AfterExternBlock: false
|
||||
#
|
||||
# BeforeCatch: true
|
||||
# BeforeElse: false
|
||||
# BeforeLambdaBody: false
|
||||
# BeforeWhile: false
|
||||
# IndentBraces: false
|
||||
# SplitEmptyFunction: true
|
||||
# SplitEmptyRecord: false
|
||||
# SplitEmptyNamespace: true
|
||||
#
|
||||
---
|
||||
|
@ -29,10 +29,10 @@ using QW::GameEngine::ComponentStore;
|
||||
static ComponentStore* components = nullptr;
|
||||
|
||||
EntityEditor::EntityEditor(QWidget* parent, const QString& filepath)
|
||||
: QWidget(parent)
|
||||
, filepath(filepath)
|
||||
, available_components(this)
|
||||
, ui(*(new Ui::EntityEditor()))
|
||||
: QWidget(parent)
|
||||
, filepath(filepath)
|
||||
, available_components(this)
|
||||
, ui(*(new Ui::EntityEditor()))
|
||||
{
|
||||
if (!components) {
|
||||
components = &(ComponentStore::GetInstance());
|
||||
@ -46,20 +46,26 @@ EntityEditor::EntityEditor(QWidget* parent, const QString& filepath)
|
||||
}
|
||||
this->load_file(filepath);
|
||||
|
||||
connect(ui.selectPushButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(selectButtonClicked(bool)));
|
||||
connect(
|
||||
ui.selectPushButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(selectButtonClicked(bool))
|
||||
);
|
||||
|
||||
connect(ui.deselectPushButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(deselectButtonClicked(bool)));
|
||||
connect(
|
||||
ui.deselectPushButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(deselectButtonClicked(bool))
|
||||
);
|
||||
|
||||
connect(ui.saveButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(saveButtonClicked(bool)));
|
||||
connect(
|
||||
ui.saveButton,
|
||||
SIGNAL(clicked(bool)),
|
||||
this,
|
||||
SLOT(saveButtonClicked(bool))
|
||||
);
|
||||
}
|
||||
|
||||
EntityEditor::~EntityEditor()
|
||||
@ -90,7 +96,8 @@ void
|
||||
EntityEditor::saveButtonClicked(bool checked)
|
||||
{
|
||||
QString file_name = QFileDialog::getSaveFileName(
|
||||
(QWidget*)this, "Save as .json", QDir::current().dirName());
|
||||
(QWidget*)this, "Save as .json", QDir::current().dirName()
|
||||
);
|
||||
|
||||
this->save_file(file_name);
|
||||
}
|
||||
@ -130,8 +137,10 @@ EntityEditor::load_file(const QString& file_name)
|
||||
json components = json_data["components"];
|
||||
// Store the key-value pairs in the entity_components map
|
||||
for (auto& [key, value] : components.items()) {
|
||||
QListWidgetItem listItem(ui.selectedComponentsListWidget,
|
||||
QListWidgetItem::ItemType::UserType);
|
||||
QListWidgetItem listItem(
|
||||
ui.selectedComponentsListWidget,
|
||||
QListWidgetItem::ItemType::UserType
|
||||
);
|
||||
listItem.setText(key.c_str());
|
||||
ui.selectedComponentsListWidget->addItem(listItem.text());
|
||||
}
|
||||
|
@ -19,13 +19,13 @@ namespace Ui {
|
||||
class EntityEditor;
|
||||
}
|
||||
|
||||
class EntityEditor : public QWidget
|
||||
{
|
||||
class EntityEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EntityEditor(QWidget* parent = nullptr,
|
||||
const QString& filepath = "");
|
||||
explicit EntityEditor(
|
||||
QWidget* parent = nullptr, const QString& filepath = ""
|
||||
);
|
||||
~EntityEditor();
|
||||
|
||||
const QString& GetFileName() { return this->filepath; }
|
||||
|
@ -43,9 +43,9 @@ using GameEngine::ComponentStore;
|
||||
using namespace Qt;
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(*(new Ui::MainWindow()))
|
||||
, component_store(ComponentStore::GetInstance())
|
||||
: QMainWindow(parent)
|
||||
, ui(*(new Ui::MainWindow()))
|
||||
, component_store(ComponentStore::GetInstance())
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
@ -70,8 +70,10 @@ void
|
||||
MainWindow::moveToCenter()
|
||||
{
|
||||
auto screenRect = QApplication::primaryScreen()->availableGeometry();
|
||||
auto centerPoint = QPoint(screenRect.x() + (screenRect.width() / 2),
|
||||
screenRect.y() + (screenRect.height() / 2));
|
||||
auto centerPoint = QPoint(
|
||||
screenRect.x() + (screenRect.width() / 2),
|
||||
screenRect.y() + (screenRect.height() / 2)
|
||||
);
|
||||
|
||||
centerPoint.setX(centerPoint.x() - (this->width() / 2));
|
||||
centerPoint.setY(centerPoint.y() - (this->height() / 2));
|
||||
@ -84,7 +86,8 @@ MainWindow::open()
|
||||
{
|
||||
QString filter = "JSON File (*.json)";
|
||||
QString file_name = QFileDialog::getOpenFileName(
|
||||
(QWidget*)this, "open a file", QDir::current().dirName());
|
||||
(QWidget*)this, "open a file", QDir::current().dirName()
|
||||
);
|
||||
|
||||
this->loadFile(file_name);
|
||||
/* std::cout << "current selected_file:"
|
||||
@ -96,8 +99,9 @@ MainWindow::loadFile(const QString& file_path)
|
||||
QMdiSubWindow* document_to_open = findDocumentWindow(file_path);
|
||||
|
||||
if (document_to_open) {
|
||||
statusBar()->showMessage(tr("Document was already loaded"),
|
||||
1000);
|
||||
statusBar()->showMessage(
|
||||
tr("Document was already loaded"), 1000
|
||||
);
|
||||
} else {
|
||||
document_to_open = createDocumentWindow(file_path);
|
||||
|
||||
@ -105,7 +109,8 @@ MainWindow::loadFile(const QString& file_path)
|
||||
statusBar()->showMessage(tr("File loaded"), 1000);
|
||||
} else {
|
||||
THROW_EXCEPTION(
|
||||
std::runtime_error("The file could not be loaded!"));
|
||||
std::runtime_error("The file could not be loaded!")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,7 @@
|
||||
|
||||
class QMdiSubWindow;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -13,8 +13,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <typeinfo>
|
||||
|
||||
class QwApplication : public QApplication
|
||||
{
|
||||
class QwApplication : public QApplication {
|
||||
public:
|
||||
QwApplication(int argc, char* argv[]) : QApplication(argc, argv) {}
|
||||
|
||||
@ -23,21 +22,21 @@ class QwApplication : public QApplication
|
||||
|
||||
try {
|
||||
return QApplication::notify(receiver, e);
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
} catch (std::exception& ex) {
|
||||
QMessageBox messageBox;
|
||||
messageBox.setWindowTitle("Uncaught Exception");
|
||||
messageBox.setIcon(QMessageBox::Critical);
|
||||
messageBox.setWindowFlag(Qt::WindowType::Dialog);
|
||||
messageBox.setText(ex.what());
|
||||
messageBox.exec();
|
||||
qFatal("Error %s sending event %s to object %s (%s)",
|
||||
ex.what(),
|
||||
typeid(*e).name(),
|
||||
qPrintable(receiver->objectName()),
|
||||
typeid(*receiver).name());
|
||||
}
|
||||
catch (...) {
|
||||
qFatal(
|
||||
"Error %s sending event %s to object %s (%s)",
|
||||
ex.what(),
|
||||
typeid(*e).name(),
|
||||
qPrintable(receiver->objectName()),
|
||||
typeid(*receiver).name()
|
||||
);
|
||||
} catch (...) {
|
||||
QMessageBox messageBox;
|
||||
messageBox.setWindowTitle("Uncaught Exception");
|
||||
messageBox.setWindowFlag(Qt::WindowType::Dialog);
|
||||
@ -48,7 +47,8 @@ class QwApplication : public QApplication
|
||||
"Error <unknown> sending event %s to object %s (%s)",
|
||||
typeid(*e).name(),
|
||||
qPrintable(receiver->objectName()),
|
||||
typeid(*receiver).name());
|
||||
typeid(*receiver).name()
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -14,8 +14,7 @@
|
||||
|
||||
namespace QW::Core {
|
||||
|
||||
class IBehavior
|
||||
{
|
||||
class IBehavior {
|
||||
protected:
|
||||
IBehavior() = default;
|
||||
|
||||
|
@ -18,13 +18,12 @@ namespace QW::Core {
|
||||
|
||||
using namespace QW::Core;
|
||||
|
||||
class IDrawable
|
||||
{
|
||||
class IDrawable {
|
||||
public:
|
||||
using PositionData = Components::PositionAttribute;
|
||||
|
||||
virtual void Draw(System::Video::rendering_ctx&,
|
||||
const PositionData&) = 0;
|
||||
virtual void
|
||||
Draw(System::Video::rendering_ctx&, const PositionData&) = 0;
|
||||
|
||||
protected:
|
||||
IDrawable() {}
|
||||
|
@ -13,8 +13,7 @@
|
||||
#include <any>
|
||||
|
||||
namespace QW::Core {
|
||||
class IGame : INonCopyable
|
||||
{
|
||||
class IGame : INonCopyable {
|
||||
public:
|
||||
virtual ~IGame(){};
|
||||
|
||||
|
@ -10,8 +10,7 @@
|
||||
#pragma once
|
||||
namespace QW::Core {
|
||||
|
||||
class INonCopyable
|
||||
{
|
||||
class INonCopyable {
|
||||
protected:
|
||||
INonCopyable() = default;
|
||||
|
||||
|
@ -15,11 +15,11 @@ namespace QW::Core {
|
||||
|
||||
class Observable;
|
||||
|
||||
class IObserver : INonCopyable
|
||||
{
|
||||
class IObserver : INonCopyable {
|
||||
public:
|
||||
virtual void OnNotice(const Observable& sender,
|
||||
std::any message = std::any()) = 0;
|
||||
virtual void OnNotice(
|
||||
const Observable& sender, std::any message = std::any()
|
||||
) = 0;
|
||||
|
||||
virtual ~IObserver() = default;
|
||||
|
||||
|
@ -17,8 +17,7 @@ namespace QW::Core {
|
||||
|
||||
class IObserver;
|
||||
|
||||
class Observable
|
||||
{
|
||||
class Observable {
|
||||
public:
|
||||
typedef std::reference_wrapper<IObserver> observer_ref;
|
||||
typedef std::list<observer_ref> observer_list;
|
||||
|
@ -24,8 +24,7 @@
|
||||
#define COMPONENT_SERIALIZERS(ClassName) \
|
||||
namespace nlohmann { \
|
||||
template<> \
|
||||
struct adl_serializer<ClassName> \
|
||||
{ \
|
||||
struct adl_serializer<ClassName> { \
|
||||
static void to_json(json& json_out, ClassName obj) \
|
||||
{ \
|
||||
obj.to_json(json_out); \
|
||||
|
@ -51,8 +51,7 @@ namespace {
|
||||
inline constexpr const char* nullstr = "(null)";
|
||||
}
|
||||
namespace QW::Core::Components {
|
||||
class BaseComponent : private QW::Core::INonCopyable
|
||||
{
|
||||
class BaseComponent : private QW::Core::INonCopyable {
|
||||
public:
|
||||
BaseComponent(BaseComponent&& other) noexcept
|
||||
{
|
||||
|
@ -59,7 +59,8 @@ Entity::Remove(const TypeInfo& type)
|
||||
};
|
||||
|
||||
auto result = std::find_if(
|
||||
component_table.begin(), component_table.end(), condition);
|
||||
component_table.begin(), component_table.end(), condition
|
||||
);
|
||||
if (result != component_table.end()) {
|
||||
component_table.erase(result);
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ namespace QW::Core::Components {
|
||||
|
||||
using namespace Types;
|
||||
|
||||
class Entity
|
||||
{
|
||||
class Entity {
|
||||
public:
|
||||
using ComponentReference = std::reference_wrapper<BaseComponent>;
|
||||
using ComponentTable = std::unordered_map<TypeInfo, ComponentReference>;
|
||||
@ -48,8 +47,8 @@ class Entity
|
||||
{ // #region
|
||||
std::list<Components::Metadata> component_list;
|
||||
for (auto& pair : component_table) {
|
||||
component_list.push_back(
|
||||
pair.second.get().GetMetadata());
|
||||
component_list.push_back(pair.second.get().GetMetadata()
|
||||
);
|
||||
}
|
||||
/*
|
||||
archive(CEREAL_NVP(instance_id));
|
||||
|
@ -20,7 +20,8 @@ namespace QW::Core::Components {
|
||||
static std::unordered_map<InstanceId, Entity> entity_table;
|
||||
|
||||
Entity&
|
||||
EntityManager::NewEntity(const InstanceId& id) {
|
||||
EntityManager::NewEntity(const InstanceId& id)
|
||||
{
|
||||
auto result = entity_table.emplace(id, id);
|
||||
if (result.second) {
|
||||
return result.first->second;
|
||||
@ -33,7 +34,8 @@ EntityManager::NewEntity(const InstanceId& id) {
|
||||
}
|
||||
|
||||
Entity&
|
||||
EntityManager::LoadEntity(const char* filename) {
|
||||
EntityManager::LoadEntity(const char* filename)
|
||||
{
|
||||
try {
|
||||
Entity& resulting_entity = this->NewEntity(0x5000);
|
||||
resulting_entity.load(filename);
|
||||
|
@ -29,8 +29,7 @@ class Entity;
|
||||
template<typename TComponent>
|
||||
using ComponentDictionary = std::unordered_map<InstanceId, TComponent>;
|
||||
|
||||
class EntityManager : INonCopyable
|
||||
{
|
||||
class EntityManager : INonCopyable {
|
||||
template<typename TComponent>
|
||||
using TDictionary = ComponentDictionary<TComponent>;
|
||||
|
||||
|
@ -25,20 +25,17 @@ class BaseComponent;
|
||||
using TypeId = size_t;
|
||||
using InstanceId = id_t;
|
||||
|
||||
struct TypeInfo
|
||||
{
|
||||
struct TypeInfo {
|
||||
TypeId id;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct InstanceInfo
|
||||
{
|
||||
struct InstanceInfo {
|
||||
InstanceId id;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct Metadata
|
||||
{
|
||||
struct Metadata {
|
||||
TypeInfo type;
|
||||
InstanceInfo instance;
|
||||
};
|
||||
@ -97,8 +94,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Metadata, type, instance)
|
||||
} // namespace QW::::Components
|
||||
using QW::Core::Components::TypeInfo;
|
||||
template<>
|
||||
struct std::hash<TypeInfo>
|
||||
{
|
||||
struct std::hash<TypeInfo> {
|
||||
inline size_t operator()(const TypeInfo& data) const noexcept
|
||||
{
|
||||
return data.id;
|
||||
|
@ -22,13 +22,14 @@ namespace QW::Core {
|
||||
using namespace Types;
|
||||
|
||||
namespace Components {
|
||||
class PhysicalProperties : public Components::BaseComponent
|
||||
class PhysicalProperties
|
||||
: public Components::BaseComponent
|
||||
// , public Core::Observable
|
||||
{
|
||||
COMPONENT(PhysicalProperties)
|
||||
public:
|
||||
PhysicalProperties(InstanceId id)
|
||||
: BaseComponent(id), velocity(), position(nullptr)
|
||||
: BaseComponent(id), velocity(), position(nullptr)
|
||||
{
|
||||
static auto& components = EntityManager::GetInstance();
|
||||
position = &(components.GetComponent<PositionAttribute>(id));
|
||||
|
@ -42,14 +42,15 @@ static GameEngine::ComponentStore& entities =
|
||||
GameEngine::ComponentStore::GetInstance();
|
||||
|
||||
PlayerBehavior::PlayerBehavior(InstanceId id)
|
||||
: IBehavior()
|
||||
, BaseComponent(id)
|
||||
, IObserver()
|
||||
, position_ptr(nullptr)
|
||||
, properties_ptr(nullptr)
|
||||
: IBehavior()
|
||||
, BaseComponent(id)
|
||||
, IObserver()
|
||||
, position_ptr(nullptr)
|
||||
, properties_ptr(nullptr)
|
||||
{
|
||||
auto eventHandler = std::function<void()>(
|
||||
std::bind(&PlayerBehavior::handleArrowKeys, this));
|
||||
std::bind(&PlayerBehavior::handleArrowKeys, this)
|
||||
);
|
||||
|
||||
/* If we can't map one of these inputs, the game should crash.
|
||||
* -- Saul 30.11.21 ☕️ */
|
||||
@ -58,8 +59,7 @@ PlayerBehavior::PlayerBehavior(InstanceId id)
|
||||
(inputMapper.RegisterMapping(SDL_SCANCODE_UP, eventHandler) ||
|
||||
inputMapper.RegisterMapping(SDL_SCANCODE_DOWN, eventHandler) ||
|
||||
inputMapper.RegisterMapping(SDL_SCANCODE_LEFT, eventHandler) ||
|
||||
inputMapper.RegisterMapping(SDL_SCANCODE_RIGHT, eventHandler)))
|
||||
{
|
||||
inputMapper.RegisterMapping(SDL_SCANCODE_RIGHT, eventHandler))) {
|
||||
THROW_EXCEPTION(std::runtime_error("Could not bind controls"));
|
||||
}
|
||||
|
||||
@ -75,16 +75,15 @@ PlayerBehavior::PlayerBehavior(InstanceId id)
|
||||
properties_ptr =
|
||||
&(entities.GetComponent<PhysicalProperties>(id));
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
} catch (std::exception& ex) {
|
||||
THROW_EXCEPTION(ex);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerBehavior::PlayerBehavior(PlayerBehavior&& other) noexcept
|
||||
: BaseComponent(std::move(other))
|
||||
, position_ptr(std::move(other.position_ptr))
|
||||
, properties_ptr(std::move(other.properties_ptr))
|
||||
: BaseComponent(std::move(other))
|
||||
, position_ptr(std::move(other.position_ptr))
|
||||
, properties_ptr(std::move(other.properties_ptr))
|
||||
{
|
||||
}
|
||||
|
||||
@ -109,7 +108,8 @@ PlayerBehavior::handleArrowKeys()
|
||||
} */
|
||||
if (!properties_ptr) {
|
||||
properties_ptr = &(entities.GetComponent<PhysicalProperties>(
|
||||
this->component_info.instance.id));
|
||||
this->component_info.instance.id
|
||||
));
|
||||
}
|
||||
PhysicalProperties& properties = *properties_ptr;
|
||||
|
||||
@ -165,8 +165,7 @@ PlayerBehavior::OnNotice(const Core::Observable& sender, std::any message)
|
||||
auto sdlEvent = std::any_cast<SDL_Event>(message);
|
||||
|
||||
if (sdlEvent.type == SDL_JOYAXISMOTION ||
|
||||
sdlEvent.type == SDL_KEYDOWN)
|
||||
{
|
||||
sdlEvent.type == SDL_KEYDOWN) {
|
||||
auto& eventHandler = this->inputMapper[sdlEvent];
|
||||
return eventHandler();
|
||||
}
|
||||
@ -190,7 +189,8 @@ PlayerBehavior::from_json(const json& json_object)
|
||||
|
||||
if (metadata != this->component_info) {
|
||||
THROW_EXCEPTION(std::runtime_error(
|
||||
"Mismatched component metdata in jSON deserialization!"));
|
||||
"Mismatched component metdata in jSON deserialization!"
|
||||
));
|
||||
}
|
||||
|
||||
/// @todo: move this to a new component type like PhysicalProperties
|
||||
@ -200,13 +200,15 @@ PlayerBehavior::from_json(const json& json_object)
|
||||
auto position_metadata =
|
||||
json_object["position"]["metadata"].get<Metadata>();
|
||||
auto& position = entities.GetComponent<PositionAttribute>(
|
||||
position_metadata.instance.id);
|
||||
position_metadata.instance.id
|
||||
);
|
||||
this->position_ptr = &position;
|
||||
|
||||
auto properties_metadata =
|
||||
json_object["properties"]["metadata"].get<Metadata>();
|
||||
auto& properties = entities.GetComponent<PhysicalProperties>(
|
||||
properties_metadata.instance.id);
|
||||
properties_metadata.instance.id
|
||||
);
|
||||
this->properties_ptr = &properties;
|
||||
}
|
||||
// #endregion
|
||||
@ -240,7 +242,8 @@ PlayerBehavior::Update()
|
||||
"PositionAttribute" };
|
||||
success = false;
|
||||
THROW_EXCEPTION(
|
||||
std::runtime_error(this->current_error.value().msg));
|
||||
std::runtime_error(this->current_error.value().msg)
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
@ -249,8 +252,8 @@ PlayerBehavior::Update()
|
||||
error_info
|
||||
PlayerBehavior::GetError()
|
||||
{
|
||||
return this->current_error.value_or(
|
||||
error_info{ Result::SUCCESS, "Success" });
|
||||
return this->current_error.value_or(error_info{ Result::SUCCESS,
|
||||
"Success" });
|
||||
}
|
||||
/* #endregion */
|
||||
}
|
||||
|
@ -41,10 +41,9 @@ using Types::decimal;
|
||||
class PositionAttribute;
|
||||
|
||||
class PlayerBehavior
|
||||
: public IBehavior
|
||||
, public BaseComponent
|
||||
, public Core::IObserver
|
||||
{
|
||||
: public IBehavior
|
||||
, public BaseComponent
|
||||
, public Core::IObserver {
|
||||
COMPONENT(PlayerBehavior)
|
||||
|
||||
public:
|
||||
|
@ -19,8 +19,8 @@ using nlohmann::json;
|
||||
using namespace QW::Core::Components;
|
||||
|
||||
PositionAttribute::PositionAttribute(PositionAttribute&& other) noexcept
|
||||
: BaseComponent(std::move(other))
|
||||
, data_dictionary(std::move(other.data_dictionary))
|
||||
: BaseComponent(std::move(other))
|
||||
, data_dictionary(std::move(other.data_dictionary))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,7 @@ namespace QW::Core::Components {
|
||||
using nlohmann::json;
|
||||
using Types::decimal;
|
||||
|
||||
class PositionAttribute : public BaseComponent
|
||||
{
|
||||
class PositionAttribute : public BaseComponent {
|
||||
COMPONENT(PositionAttribute)
|
||||
|
||||
template<typename T>
|
||||
@ -38,7 +37,7 @@ class PositionAttribute : public BaseComponent
|
||||
decimal yPosition;
|
||||
|
||||
PositionAttribute(InstanceId id)
|
||||
: BaseComponent(id), xPosition(0.0), yPosition(0.0)
|
||||
: BaseComponent(id), xPosition(0.0), yPosition(0.0)
|
||||
{
|
||||
initialize_metadata(id);
|
||||
}
|
||||
|
@ -22,34 +22,38 @@
|
||||
namespace QW::Core::Components {
|
||||
|
||||
class RenderedCircle
|
||||
: public BaseComponent
|
||||
, public IDrawable
|
||||
{
|
||||
: public BaseComponent
|
||||
, public IDrawable {
|
||||
const int DEFAULT_RADIUS = 10;
|
||||
|
||||
COMPONENT(RenderedCircle)
|
||||
|
||||
public:
|
||||
RenderedCircle(InstanceId id) noexcept
|
||||
: BaseComponent(id), IDrawable(), radius(DEFAULT_RADIUS)
|
||||
: BaseComponent(id), IDrawable(), radius(DEFAULT_RADIUS)
|
||||
{
|
||||
this->initialize_metadata(id);
|
||||
}
|
||||
|
||||
void Draw(System::Video::rendering_ctx& rendererInfo,
|
||||
const IDrawable::PositionData& position) override
|
||||
void Draw(
|
||||
System::Video::rendering_ctx& rendererInfo,
|
||||
const IDrawable::PositionData& position
|
||||
) override
|
||||
{
|
||||
if (filledCircleRGBA(rendererInfo.renderer,
|
||||
position.xPosition,
|
||||
position.yPosition,
|
||||
radius,
|
||||
0x0,
|
||||
0xa,
|
||||
0xa0,
|
||||
0xff)) // color
|
||||
if (filledCircleRGBA(
|
||||
rendererInfo.renderer,
|
||||
position.xPosition,
|
||||
position.yPosition,
|
||||
radius,
|
||||
0x0,
|
||||
0xa,
|
||||
0xa0,
|
||||
0xff
|
||||
)) // color
|
||||
{
|
||||
THROW_EXCEPTION(
|
||||
std::runtime_error("Couldn't render a circle"));
|
||||
std::runtime_error("Couldn't render a circle")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,15 +28,18 @@ template<typename TComponent>
|
||||
BoolResult
|
||||
EntityManager::RegisterPool(ComponentDictionary<TComponent>& pool)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent");
|
||||
static_assert(
|
||||
std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent"
|
||||
);
|
||||
|
||||
const auto& poolTypeInfo = TComponent::GetType();
|
||||
auto result = BoolResult::ERROR;
|
||||
|
||||
if (!pool_exists(poolTypeInfo)) {
|
||||
this->pool_table.emplace(poolTypeInfo,
|
||||
static_cast<void*>(&pool));
|
||||
this->pool_table.emplace(
|
||||
poolTypeInfo, static_cast<void*>(&pool)
|
||||
);
|
||||
result = BoolResult::SUCCESS;
|
||||
} else {
|
||||
std::stringstream buffer;
|
||||
@ -59,8 +62,10 @@ template<typename TComponent, typename... TArgs>
|
||||
TComponent&
|
||||
EntityManager::ConstructComponent(const InstanceId& id, TArgs... args)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent");
|
||||
static_assert(
|
||||
std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent"
|
||||
);
|
||||
|
||||
using DictPtr = ComponentDictionary<TComponent>*;
|
||||
|
||||
@ -82,13 +87,13 @@ EntityManager::ConstructComponent(const InstanceId& id, TArgs... args)
|
||||
|
||||
if (!emplace_result.second) {
|
||||
|
||||
THROW_EXCEPTION(std::runtime_error(
|
||||
"unknown emplace error occurred"));
|
||||
THROW_EXCEPTION(
|
||||
std::runtime_error("unknown emplace error occurred")
|
||||
);
|
||||
}
|
||||
|
||||
return emplace_result.first->second;
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
} catch (std::exception& exc) {
|
||||
/// @todo: add some logging here...
|
||||
/// Since multiple things can go wrong.
|
||||
THROW_EXCEPTION(exc);
|
||||
@ -99,8 +104,10 @@ TComponent&
|
||||
EntityManager::GetComponent(const InstanceId& id)
|
||||
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent");
|
||||
static_assert(
|
||||
std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent"
|
||||
);
|
||||
using DictPtr = ComponentDictionary<TComponent>*;
|
||||
|
||||
std::optional<std::reference_wrapper<TComponent>> result;
|
||||
@ -111,15 +118,13 @@ EntityManager::GetComponent(const InstanceId& id)
|
||||
|
||||
try {
|
||||
result = pool.at(id);
|
||||
}
|
||||
catch (std::out_of_range& exc) {
|
||||
} catch (std::out_of_range& exc) {
|
||||
pool.emplace(id, id);
|
||||
result = pool.at(id);
|
||||
}
|
||||
|
||||
return result.value();
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
} catch (std::exception& exc) {
|
||||
/// @todo: add some logging here...
|
||||
/// Since multiple things can go wrong.
|
||||
THROW_EXCEPTION(exc);
|
||||
@ -130,8 +135,10 @@ template<typename TComponent>
|
||||
Adapters::Sequential<ComponentDictionary<TComponent>>
|
||||
EntityManager::AsSequential()
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent");
|
||||
static_assert(
|
||||
std::is_base_of<BaseComponent, TComponent>(),
|
||||
"Template type must be derived from BaseComponent"
|
||||
);
|
||||
|
||||
using ComponentsDict = ComponentDictionary<TComponent>;
|
||||
const auto& poolType = TComponent::GetType();
|
||||
@ -164,8 +171,7 @@ EntityManager::get_pool(const TypeInfo& poolType)
|
||||
{
|
||||
try {
|
||||
return this->pool_table.at(poolType);
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
} catch (std::exception& exc) {
|
||||
THROW_EXCEPTION(exc);
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include "framework/core/IObserver.hpp"
|
||||
#include "framework/core/Observable.hpp"
|
||||
|
||||
//#include <vector>
|
||||
// #include <vector>
|
||||
#include <queue>
|
||||
//#include <any>
|
||||
//#include <memory>
|
||||
// #include <any>
|
||||
// #include <memory>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
@ -54,8 +54,9 @@ EventDispatcher::InitJoysticks()
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
if (SDL_NumJoysticks() > 0) {
|
||||
joydev = SDL_JoystickDevice_ptr(SDL_JoystickOpen(0),
|
||||
SDL_JoystickClose);
|
||||
joydev = SDL_JoystickDevice_ptr(
|
||||
SDL_JoystickOpen(0), SDL_JoystickClose
|
||||
);
|
||||
std::cout << "Opened Joystick 0" << std::endl;
|
||||
std::cout << "Name: " << SDL_JoystickNameForIndex(0)
|
||||
<< std::endl;
|
||||
@ -97,7 +98,7 @@ EventDispatcher::Notify()
|
||||
}
|
||||
|
||||
EventDispatcher::EventDispatcher(const EventDispatcher& other)
|
||||
: joydev(nullptr, nullptr)
|
||||
: joydev(nullptr, nullptr)
|
||||
{
|
||||
this->eventBuffer = other.eventBuffer;
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ namespace QW::Core::Input {
|
||||
|
||||
using namespace QW::Core;
|
||||
|
||||
class EventDispatcher : public Observable
|
||||
{
|
||||
class EventDispatcher : public Observable {
|
||||
public:
|
||||
EventDispatcher();
|
||||
~EventDispatcher();
|
||||
|
@ -16,22 +16,23 @@
|
||||
#include "framework/core/types/utility/operators/SDL_Event.hpp"
|
||||
|
||||
namespace QW::Core::Input {
|
||||
class InputMapper : INonCopyable
|
||||
{
|
||||
class InputMapper : INonCopyable {
|
||||
public:
|
||||
using EventHandler = std::function<void(void)>;
|
||||
|
||||
InputMapper() : nullHandler([]() { ; }) {}
|
||||
|
||||
inline bool RegisterMapping(const SDL_Scancode& scancode,
|
||||
EventHandler& handler)
|
||||
inline bool RegisterMapping(
|
||||
const SDL_Scancode& scancode, EventHandler& handler
|
||||
)
|
||||
{
|
||||
auto event = this->createEventFromScancode(scancode);
|
||||
return RegisterMapping(event, handler);
|
||||
}
|
||||
|
||||
inline bool RegisterMapping(const SDL_Event& event,
|
||||
EventHandler& handler)
|
||||
inline bool RegisterMapping(
|
||||
const SDL_Event& event, EventHandler& handler
|
||||
)
|
||||
{
|
||||
if (eventHandlers.find(event) == eventHandlers.end()) {
|
||||
eventHandlers[event] = handler;
|
||||
|
@ -20,8 +20,7 @@ namespace QW::Core::Types::Adapters {
|
||||
* ::value_type of std::pair<key_type,mapped_type>, and a defined ::mapped_type
|
||||
*/
|
||||
template<typename Dictionary>
|
||||
class Sequential
|
||||
{
|
||||
class Sequential {
|
||||
using key_type = typename Dictionary::key_type;
|
||||
using value_type = typename Dictionary::mapped_type;
|
||||
|
||||
@ -55,8 +54,9 @@ class Sequential
|
||||
using reference = value_type&;
|
||||
|
||||
iterator_base(typename Dictionary::iterator other)
|
||||
: foreign_iterator(other)
|
||||
{}
|
||||
: foreign_iterator(other)
|
||||
{
|
||||
}
|
||||
~iterator_base() = default;
|
||||
|
||||
reference operator*() const
|
||||
@ -113,7 +113,7 @@ class Sequential
|
||||
auto finish = data.cend();
|
||||
return const_iterator(finish);
|
||||
}
|
||||
//#endregion
|
||||
// #endregion
|
||||
|
||||
private:
|
||||
Dictionary& data;
|
||||
|
@ -32,8 +32,7 @@ enum Result {
|
||||
UNKNOWN_ERROR = INT_MAX,
|
||||
};
|
||||
|
||||
struct error_info
|
||||
{
|
||||
struct error_info {
|
||||
Result code;
|
||||
const_string msg;
|
||||
};
|
||||
|
@ -16,8 +16,7 @@
|
||||
#include "framework/core/INonCopyable.hpp"
|
||||
|
||||
namespace QW::Core::Types::Util {
|
||||
struct Demangler : INonCopyable
|
||||
{
|
||||
struct Demangler : INonCopyable {
|
||||
std::string mangled;
|
||||
|
||||
Demangler(const std::type_info& type) : mangled(type.name()) {}
|
||||
@ -40,7 +39,8 @@ struct Demangler : INonCopyable
|
||||
int conversion_status = 0;
|
||||
|
||||
buffer = abi::__cxa_demangle(
|
||||
token, nullptr, nullptr, &conversion_status);
|
||||
token, nullptr, nullptr, &conversion_status
|
||||
);
|
||||
result = (buffer);
|
||||
free(buffer);
|
||||
|
||||
|
@ -29,8 +29,8 @@ operator==(const SDL_Event& lhs, const SDL_Event& rhs)
|
||||
switch (lhs.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
ret &= (lhs.key.keysym.scancode ==
|
||||
rhs.key.keysym.scancode);
|
||||
ret &=
|
||||
(lhs.key.keysym.scancode == rhs.key.keysym.scancode);
|
||||
ret &= (lhs.key.keysym.mod == rhs.key.keysym.mod);
|
||||
break;
|
||||
default:
|
||||
@ -42,8 +42,7 @@ operator==(const SDL_Event& lhs, const SDL_Event& rhs)
|
||||
}
|
||||
|
||||
template<>
|
||||
struct std::hash<SDL_Event>
|
||||
{
|
||||
struct std::hash<SDL_Event> {
|
||||
inline size_t operator()(const SDL_Event& event) const noexcept
|
||||
{
|
||||
|
||||
@ -68,18 +67,19 @@ struct std::hash<SDL_Event>
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
hash_combine<uint32_t>(
|
||||
ret, event.key.keysym.scancode);
|
||||
hash_combine<uint32_t>(ret,
|
||||
event.key.keysym.mod);
|
||||
ret, event.key.keysym.scancode
|
||||
);
|
||||
hash_combine<uint32_t>(
|
||||
ret, event.key.keysym.mod
|
||||
);
|
||||
break;
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
hash_combine<uint32_t>(ret,
|
||||
event.cbutton.button);
|
||||
hash_combine<uint32_t>(ret,
|
||||
event.cbutton.which);
|
||||
hash_combine<uint32_t>(ret,
|
||||
event.cbutton.state);
|
||||
hash_combine<uint32_t>(
|
||||
ret, event.cbutton.button
|
||||
);
|
||||
hash_combine<uint32_t>(ret, event.cbutton.which);
|
||||
hash_combine<uint32_t>(ret, event.cbutton.state);
|
||||
break;
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
hash_combine<uint32_t>(ret, event.caxis.axis);
|
||||
|
@ -16,12 +16,12 @@
|
||||
#include "framework/system/debuginfo.hpp"
|
||||
|
||||
namespace QW::Core::Types {
|
||||
class QWException : public std::exception
|
||||
{
|
||||
class QWException : public std::exception {
|
||||
public:
|
||||
QWException(const std::exception& innerException,
|
||||
const std::string& stacktrace)
|
||||
: stacktrace(stacktrace), innerException(innerException)
|
||||
QWException(
|
||||
const std::exception& innerException, const std::string& stacktrace
|
||||
)
|
||||
: stacktrace(stacktrace), innerException(innerException)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
* obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "framework/core/types.hpp"
|
||||
#include "framework/system/sdl.hpp"
|
||||
#include "framework/core/types.hpp"
|
||||
|
||||
using namespace QW::Core::Types;
|
||||
using namespace QW::System;
|
||||
@ -38,8 +38,9 @@ Video::initialize_renderer(Video::rendering_ctx& rendererInfo)
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("SDL Could not initialize; SDL_Error: %s\n",
|
||||
SDL_GetError());
|
||||
printf(
|
||||
"SDL Could not initialize; SDL_Error: %s\n", SDL_GetError()
|
||||
);
|
||||
return Result::ERR_SDLINIT_FAILURE;
|
||||
}
|
||||
IMG_Init(IMG_INIT_JPG);
|
||||
@ -47,8 +48,10 @@ Video::initialize_renderer(Video::rendering_ctx& rendererInfo)
|
||||
rendererInfo.window =
|
||||
SDL_CreateWindow("SDL Tutorial", 0, 0, 1024, 768, SDL_WINDOW_SHOWN);
|
||||
if (rendererInfo.window == nullptr) {
|
||||
printf("Window could not be created! SDL_Error: %s\n",
|
||||
SDL_GetError());
|
||||
printf(
|
||||
"Window could not be created! SDL_Error: %s\n",
|
||||
SDL_GetError()
|
||||
);
|
||||
rendererInfo.error.code = Result::ERR_SDLWINDOW_CREATION;
|
||||
return rendererInfo.error.code;
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ using namespace QW::Core::Types;
|
||||
|
||||
namespace QW::System {
|
||||
namespace Video {
|
||||
struct rendering_ctx
|
||||
{
|
||||
struct rendering_ctx {
|
||||
error_info error;
|
||||
|
||||
SDL_Window* window;
|
||||
|
@ -23,8 +23,7 @@
|
||||
using namespace QW::Core::Components;
|
||||
|
||||
namespace QW::GameEngine {
|
||||
class ComponentStore : public EntityManager
|
||||
{
|
||||
class ComponentStore : public EntityManager {
|
||||
public:
|
||||
static ComponentStore& GetInstance()
|
||||
{
|
||||
@ -50,7 +49,7 @@ class ComponentStore : public EntityManager
|
||||
|
||||
protected:
|
||||
ComponentStore()
|
||||
: EntityManager(), positions(), players(), views(), properties()
|
||||
: EntityManager(), positions(), players(), views(), properties()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -14,8 +14,7 @@
|
||||
/// subysystems using a .config file or something?
|
||||
|
||||
namespace QW::GameEngine {
|
||||
class GameConfiguration
|
||||
{};
|
||||
class GameConfiguration {};
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
@ -18,15 +18,15 @@
|
||||
using namespace QW::Core::Components;
|
||||
|
||||
namespace QW::GameEngine {
|
||||
class GameConfiguration
|
||||
{
|
||||
class GameConfiguration {
|
||||
public:
|
||||
GameConfiguration()
|
||||
: component_registry(EntityManager::GetInstance())
|
||||
, position()
|
||||
, players()
|
||||
, views()
|
||||
{}
|
||||
: component_registry(EntityManager::GetInstance())
|
||||
, position()
|
||||
, players()
|
||||
, views()
|
||||
{
|
||||
}
|
||||
|
||||
EntityManager& component_registry;
|
||||
ComponentDictionary<PositionAttribute> position;
|
||||
|
@ -31,10 +31,10 @@ using namespace QW::GameEngine;
|
||||
using mutex_lock = std::unique_lock<std::mutex>;
|
||||
|
||||
QuartzWarriors::QuartzWarriors()
|
||||
: IGame()
|
||||
, is_running(false)
|
||||
, ticks(0)
|
||||
, component_pools(ComponentStore::GetInstance())
|
||||
: IGame()
|
||||
, is_running(false)
|
||||
, ticks(0)
|
||||
, component_pools(ComponentStore::GetInstance())
|
||||
{
|
||||
|
||||
this->renderer = System::Video::new_renderer();
|
||||
@ -123,8 +123,7 @@ QuartzWarriors::ProcessSystemEvents()
|
||||
input_state inputStatus;
|
||||
|
||||
while (input_state::NO_EVENTS !=
|
||||
(inputStatus = System::Input::get_input(&e)))
|
||||
{
|
||||
(inputStatus = System::Input::get_input(&e))) {
|
||||
|
||||
if (input_state::ABORT == inputStatus) {
|
||||
this->Stop();
|
||||
@ -143,8 +142,8 @@ QuartzWarriors::UpdateModel()
|
||||
auto component_list =
|
||||
Adapters::Sequential<TDictionary>(component_pools.players);
|
||||
|
||||
for (auto it = component_list.begin(); it != component_list.end(); it++)
|
||||
{
|
||||
for (auto it = component_list.begin(); it != component_list.end();
|
||||
it++) {
|
||||
auto& object = *it;
|
||||
object.Update();
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ using Components::InstanceId;
|
||||
|
||||
using Input::EventDispatcher;
|
||||
|
||||
class QuartzWarriors : public Core::IGame
|
||||
{
|
||||
class QuartzWarriors : public Core::IGame {
|
||||
public:
|
||||
QuartzWarriors();
|
||||
|
||||
|
@ -26,8 +26,7 @@ main(int argc, char* argv[])
|
||||
try {
|
||||
game->Init(argc, argv);
|
||||
return game->Run();
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
} catch (std::exception& ex) {
|
||||
print_backtrace(ex);
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,7 @@ struct SdlEventSimulator // #region
|
||||
}
|
||||
}; // #endregion
|
||||
|
||||
struct Sdl2TestFixture
|
||||
{
|
||||
struct Sdl2TestFixture {
|
||||
|
||||
using sstream = std::stringstream;
|
||||
|
||||
@ -104,8 +103,8 @@ struct Sdl2TestFixture
|
||||
<< "SDL Could not initialize; SDL_Error: "
|
||||
<< SDL_GetError();
|
||||
std::cerr << errorMsgStream.str() << std::endl;
|
||||
THROW_EXCEPTION(
|
||||
std::runtime_error(errorMsgStream.str()));
|
||||
THROW_EXCEPTION(std::runtime_error(errorMsgStream.str())
|
||||
);
|
||||
}
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
@ -27,18 +27,19 @@ using fakeit::When;
|
||||
namespace {
|
||||
const char* TEST_SUITE_NAME = "[class:Observable]";
|
||||
|
||||
class ObservableSubject : public QW::Core::Observable //#region
|
||||
class ObservableSubject
|
||||
: public QW::Core::Observable // #region
|
||||
{
|
||||
public:
|
||||
ObservableSubject() : Observable() {}
|
||||
|
||||
virtual void Notify() override { this->NotifyAll(); }
|
||||
const size_t GetObserverCount() const { return observers.size(); }
|
||||
}; //#endregion
|
||||
}; // #endregion
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Register IObservers", TEST_SUITE_NAME) //#region
|
||||
TEST_CASE("Register IObservers", TEST_SUITE_NAME) // #region
|
||||
{
|
||||
Mock<IObserver> observerType1;
|
||||
Mock<IObserver> observerType2;
|
||||
@ -51,8 +52,8 @@ TEST_CASE("Register IObservers", TEST_SUITE_NAME) //#region
|
||||
subject.RegisterObserver(observer2);
|
||||
|
||||
REQUIRE(2 == subject.GetObserverCount());
|
||||
} //#endregion
|
||||
TEST_CASE("Can notify observers", TEST_SUITE_NAME) //#region
|
||||
} // #endregion
|
||||
TEST_CASE("Can notify observers", TEST_SUITE_NAME) // #region
|
||||
{
|
||||
Mock<IObserver> observerType1;
|
||||
Mock<IObserver> observerType2;
|
||||
|
@ -25,20 +25,19 @@ BEGIN_TEST_SUITE("class::Entity")
|
||||
|
||||
static const InstanceId PLAYER_ID = 0xc0ffee;
|
||||
|
||||
class TestFixture
|
||||
{
|
||||
class TestFixture {
|
||||
public:
|
||||
TestFixture()
|
||||
: test_subject(PLAYER_ID)
|
||||
, registry(EntityManager::GetInstance())
|
||||
: test_subject(PLAYER_ID)
|
||||
, registry(EntityManager::GetInstance())
|
||||
{
|
||||
|
||||
registry.RegisterPool(test_pool1);
|
||||
registry.RegisterPool(test_pool2);
|
||||
|
||||
registry.ConstructComponent<SomeComponent>(PLAYER_ID);
|
||||
registry.ConstructComponent<SomeOtherComponent>(
|
||||
PLAYER_ID);
|
||||
registry.ConstructComponent<SomeOtherComponent>(PLAYER_ID
|
||||
);
|
||||
}
|
||||
virtual ~TestFixture()
|
||||
{
|
||||
@ -59,7 +58,8 @@ BEGIN_TEST_SUITE("class::Entity")
|
||||
}
|
||||
|
||||
TEST_SUITE_CASE(
|
||||
"GetComponentList returns the internal object, not a copy")
|
||||
"GetComponentList returns the internal object, not a copy"
|
||||
)
|
||||
{
|
||||
auto& result = test_subject.GetComponentList();
|
||||
auto& expected = test_subject.component_table;
|
||||
@ -90,8 +90,10 @@ BEGIN_TEST_SUITE("class::Entity")
|
||||
|
||||
/* Here I check the memory addresses of the result and the
|
||||
* object. to verify that its the same object */
|
||||
REQUIRE(static_cast<BaseComponent*>(&inserted_object) ==
|
||||
static_cast<BaseComponent*>(&test_component));
|
||||
REQUIRE(
|
||||
static_cast<BaseComponent*>(&inserted_object) ==
|
||||
static_cast<BaseComponent*>(&test_component)
|
||||
);
|
||||
|
||||
// Case 2: The object already exists. ::Insert(...) should throw
|
||||
// an exception
|
||||
@ -116,8 +118,9 @@ BEGIN_TEST_SUITE("class::Entity")
|
||||
/* Case 2: There is already data in the table.
|
||||
* Still, no exceptions should be thrown, and nothing should be
|
||||
* removed */
|
||||
test_subject.component_table.emplace(type_info,
|
||||
std::ref(test_component));
|
||||
test_subject.component_table.emplace(
|
||||
type_info, std::ref(test_component)
|
||||
);
|
||||
|
||||
REQUIRE(test_subject.component_table.size() == 1);
|
||||
REQUIRE_NOTHROW(test_subject.Remove(type_info));
|
||||
|
@ -19,8 +19,7 @@ BEGIN_TEST_SUITE("class:EntityManager")
|
||||
{
|
||||
|
||||
// #region Test Fixtures
|
||||
struct TestFixture
|
||||
{
|
||||
struct TestFixture {
|
||||
TestFixture() : registry(EntityManager::GetInstance())
|
||||
{
|
||||
registry.RegisterPool(test_table);
|
||||
@ -95,23 +94,27 @@ TEST_CASE_METHOD(TestFixture, "EntityManager::GetIterable", TEST_SUITE_NAME)
|
||||
REQUIRE(start != finish);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TestFixture, "EntityManager::GetRegisteredTypes",
|
||||
TEST_SUITE_NAME)
|
||||
TEST_CASE_METHOD(
|
||||
TestFixture, "EntityManager::GetRegisteredTypes", TEST_SUITE_NAME
|
||||
)
|
||||
{
|
||||
auto type_list = registry.GetRegisteredTypes();
|
||||
REQUIRE(type_list.size() == 2);
|
||||
|
||||
auto result_iter = std::find(
|
||||
type_list.begin(), type_list.end(), SomeComponent::GetType());
|
||||
type_list.begin(), type_list.end(), SomeComponent::GetType()
|
||||
);
|
||||
REQUIRE(result_iter != type_list.end());
|
||||
|
||||
result_iter = std::find(
|
||||
type_list.begin(), type_list.end(), SomeOtherComponent::GetType());
|
||||
type_list.begin(), type_list.end(), SomeOtherComponent::GetType()
|
||||
);
|
||||
REQUIRE(result_iter != type_list.end());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TestFixture, "EntityManager::ConstructComponent",
|
||||
TEST_SUITE_NAME)
|
||||
TEST_CASE_METHOD(
|
||||
TestFixture, "EntityManager::ConstructComponent", TEST_SUITE_NAME
|
||||
)
|
||||
{
|
||||
registry.ConstructComponent<SomeOtherComponent>(0xc0ffee);
|
||||
|
||||
|
@ -17,8 +17,9 @@ BEGIN_TEST_SUITE("PhysicalProperties")
|
||||
using Components::PhysicalProperties;
|
||||
|
||||
namespace {
|
||||
bool operator==(const PhysicalProperties& left,
|
||||
const PhysicalProperties& right)
|
||||
bool operator==(
|
||||
const PhysicalProperties& left, const PhysicalProperties& right
|
||||
)
|
||||
{
|
||||
auto& left_metadata = left.GetMetadata();
|
||||
auto& right_metadata = right.GetMetadata();
|
||||
|
@ -37,7 +37,8 @@ BEGIN_TEST_SUITE("class:PlayerBehavior")
|
||||
using namespace QW::Core::Types;
|
||||
// #endregion
|
||||
|
||||
struct SDL_EventGenerator : public Core::Observable // #region
|
||||
struct SDL_EventGenerator
|
||||
: public Core::Observable // #region
|
||||
{
|
||||
SDL_EventGenerator() : Core::Observable() {}
|
||||
|
||||
@ -52,34 +53,38 @@ BEGIN_TEST_SUITE("class:PlayerBehavior")
|
||||
auto event = SdlEventSimulator::specificArrowKey(dir);
|
||||
this->NotifyAll(event);
|
||||
}
|
||||
}; // #endregion
|
||||
struct PlayerBehaviorTestFixture : public Sdl2TestFixture // #region
|
||||
}; // #endregion
|
||||
struct PlayerBehaviorTestFixture
|
||||
: public Sdl2TestFixture // #region
|
||||
{
|
||||
SDL_EventGenerator eventSource;
|
||||
PositionAttribute playerPosition;
|
||||
PlayerBehavior playerBehavior;
|
||||
|
||||
PlayerBehaviorTestFixture()
|
||||
: Sdl2TestFixture()
|
||||
, eventSource()
|
||||
, playerPosition(0x00)
|
||||
, playerBehavior(0x00)
|
||||
: Sdl2TestFixture()
|
||||
, eventSource()
|
||||
, playerPosition(0x00)
|
||||
, playerBehavior(0x00)
|
||||
{
|
||||
playerBehavior.setPosition(&playerPosition);
|
||||
eventSource.RegisterObserver(playerBehavior);
|
||||
}
|
||||
}; // #endregion
|
||||
|
||||
FIXTURE_CASE(PlayerBehaviorTestFixture,
|
||||
"PlayerBehavior responds to key events")
|
||||
FIXTURE_CASE(
|
||||
PlayerBehaviorTestFixture, "PlayerBehavior responds to key events"
|
||||
)
|
||||
{
|
||||
for (unsigned i = 0; i < 10; ++i) {
|
||||
eventSource.Notify();
|
||||
}
|
||||
}
|
||||
|
||||
FIXTURE_CASE(PlayerBehaviorTestFixture,
|
||||
"PlayerBehavior responds correctly to key events")
|
||||
FIXTURE_CASE(
|
||||
PlayerBehaviorTestFixture,
|
||||
"PlayerBehavior responds correctly to key events"
|
||||
)
|
||||
{
|
||||
using keydir_t = Sdl2Testing::SdlEventSimulator::KEY_DIR;
|
||||
|
||||
|
@ -29,8 +29,9 @@ operator==(const PositionAttribute& left, const PositionAttribute& right)
|
||||
auto& right_metadata = right.GetMetadata();
|
||||
|
||||
bool metadata_match = (left_metadata == right_metadata);
|
||||
bool value_match = ((left.xPosition == right.xPosition) &&
|
||||
(left.yPosition == right.yPosition));
|
||||
bool value_match =
|
||||
((left.xPosition == right.xPosition) &&
|
||||
(left.yPosition == right.yPosition));
|
||||
|
||||
return (metadata_match && value_match);
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ using Sdl2Testing::SdlEventSimulator;
|
||||
|
||||
BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
{
|
||||
class EventRecorder : public IObserver // #region
|
||||
class EventRecorder
|
||||
: public IObserver // #region
|
||||
{
|
||||
public:
|
||||
EventRecorder() : IObserver() {}
|
||||
@ -43,12 +44,13 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
}
|
||||
virtual ~EventRecorder() = default;
|
||||
std::vector<SDL_Event> received;
|
||||
}; // #endregion
|
||||
class EventDispatcherInspector : public EventDispatcher // #region
|
||||
}; // #endregion
|
||||
class EventDispatcherInspector
|
||||
: public EventDispatcher // #region
|
||||
{
|
||||
public:
|
||||
explicit EventDispatcherInspector(EventDispatcher& other)
|
||||
: EventDispatcher(other)
|
||||
: EventDispatcher(other)
|
||||
{
|
||||
}
|
||||
|
||||
@ -56,11 +58,12 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
{
|
||||
return this->getEventBuffer();
|
||||
}
|
||||
}; // #endregion
|
||||
struct EventDispatcherFixture : public Sdl2TestFixture // #region
|
||||
}; // #endregion
|
||||
struct EventDispatcherFixture
|
||||
: public Sdl2TestFixture // #region
|
||||
{
|
||||
EventDispatcherFixture()
|
||||
: Sdl2TestFixture(), eventSource(), recorder()
|
||||
: Sdl2TestFixture(), eventSource(), recorder()
|
||||
{
|
||||
eventSource.RegisterObserver(recorder);
|
||||
}
|
||||
@ -75,15 +78,19 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
REQUIRE_NOTHROW([]() { EventDispatcherFixture object2; }());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(EventDispatcherFixture,
|
||||
"EventDispatcher::InitJoysticks() sanity check",
|
||||
TEST_SUITE_NAME)
|
||||
TEST_CASE_METHOD(
|
||||
EventDispatcherFixture,
|
||||
"EventDispatcher::InitJoysticks() sanity check",
|
||||
TEST_SUITE_NAME
|
||||
)
|
||||
{
|
||||
REQUIRE_NOTHROW([this]() { eventSource.InitJoysticks(); }());
|
||||
}
|
||||
|
||||
FIXTURE_CASE(EventDispatcherFixture,
|
||||
"EventDispatcher::Enqueue stores events in order")
|
||||
FIXTURE_CASE(
|
||||
EventDispatcherFixture,
|
||||
"EventDispatcher::Enqueue stores events in order"
|
||||
)
|
||||
{
|
||||
const int MAX_EVENTS = 5;
|
||||
SDL_Event testInput[MAX_EVENTS];
|
||||
@ -102,13 +109,16 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
auto event = eventBuffer.front();
|
||||
eventBuffer.pop();
|
||||
|
||||
REQUIRE(event.key.keysym.sym ==
|
||||
testInput[i].key.keysym.sym);
|
||||
REQUIRE(
|
||||
event.key.keysym.sym == testInput[i].key.keysym.sym
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FIXTURE_CASE(EventDispatcherFixture,
|
||||
"EventDispatcher::Notify sends out events in order")
|
||||
FIXTURE_CASE(
|
||||
EventDispatcherFixture,
|
||||
"EventDispatcher::Notify sends out events in order"
|
||||
)
|
||||
{
|
||||
const int MAX_EVENTS = 5;
|
||||
SDL_Event testInput[MAX_EVENTS];
|
||||
@ -125,8 +135,9 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
for (unsigned i = 0; i < MAX_EVENTS; ++i) {
|
||||
auto& event = recorder.received[i];
|
||||
|
||||
REQUIRE(event.key.keysym.sym ==
|
||||
testInput[i].key.keysym.sym);
|
||||
REQUIRE(
|
||||
event.key.keysym.sym == testInput[i].key.keysym.sym
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ using Sdl2Testing::SdlEventSimulator;
|
||||
|
||||
BEGIN_TEST_SUITE("class:InputMapper")
|
||||
{
|
||||
struct TransparentInputMapper : public InputMapper // #region
|
||||
struct TransparentInputMapper
|
||||
: public InputMapper // #region
|
||||
{
|
||||
|
||||
virtual std::unordered_map<SDL_Event, EventHandler>&
|
||||
@ -37,11 +38,14 @@ BEGIN_TEST_SUITE("class:InputMapper")
|
||||
{
|
||||
return InputMapper::getEventHandlerMap();
|
||||
}
|
||||
}; // #endregion
|
||||
struct TestFixture : public Sdl2TestFixture // #region
|
||||
}; // #endregion
|
||||
struct TestFixture
|
||||
: public Sdl2TestFixture // #region
|
||||
{
|
||||
TestFixture()
|
||||
: Sdl2TestFixture(), testSubject(), testInterface(testSubject)
|
||||
: Sdl2TestFixture()
|
||||
, testSubject()
|
||||
, testInterface(testSubject)
|
||||
{
|
||||
}
|
||||
|
||||
@ -85,8 +89,9 @@ BEGIN_TEST_SUITE("class:InputMapper")
|
||||
"SDL_SCANCODE_X detectedSDL_SCANCODE_X detected";
|
||||
static std::stringstream output;
|
||||
|
||||
auto handler = InputMapper::EventHandler(
|
||||
[expected_msg]() { output << expected_msg << std::flush; });
|
||||
auto handler = InputMapper::EventHandler([expected_msg]() {
|
||||
output << expected_msg << std::flush;
|
||||
});
|
||||
auto event =
|
||||
SdlEventSimulator::eventFromScancode(SDL_SCANCODE_X);
|
||||
testInterface.RegisterMapping(event, handler);
|
||||
@ -112,8 +117,9 @@ BEGIN_TEST_SUITE("class:InputMapper")
|
||||
"SDL_SCANCODE_Y detectedSDL_SCANCODE_Y detected";
|
||||
static std::stringstream output;
|
||||
|
||||
auto handler = InputMapper::EventHandler(
|
||||
[expected_msg]() { output << expected_msg << std::flush; });
|
||||
auto handler = InputMapper::EventHandler([expected_msg]() {
|
||||
output << expected_msg << std::flush;
|
||||
});
|
||||
auto event =
|
||||
SdlEventSimulator::eventFromScancode(SDL_SCANCODE_X);
|
||||
testInterface.RegisterMapping(event, handler);
|
||||
|
@ -26,8 +26,7 @@ BEGIN_TEST_SUITE("class:Adadpter::Sequential")
|
||||
using namespace QW::Core::Components;
|
||||
using namespace QW::Core::Types;
|
||||
|
||||
class TestComponent : public SomeComponent
|
||||
{
|
||||
class TestComponent : public SomeComponent {
|
||||
COMPONENT(TestComponent)
|
||||
public:
|
||||
TestComponent(InstanceId id) : SomeComponent(id) {}
|
||||
@ -82,8 +81,9 @@ TEST_CASE("can iterate using c++11 foreach syntax", TEST_SUITE_NAME)
|
||||
//}
|
||||
auto special_iterator = iterableView.begin();
|
||||
for (unsigned i = 0; i < expected_results.size(); ++i) {
|
||||
REQUIRE(expected_results[i] ==
|
||||
special_iterator->GetInstanceInfo().id);
|
||||
REQUIRE(
|
||||
expected_results[i] == special_iterator->GetInstanceInfo().id
|
||||
);
|
||||
special_iterator++;
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ const char* TEST_SUITE_NAME = "[class:RenderedCircle]";
|
||||
|
||||
using QW::View::RenderedCircle;
|
||||
|
||||
TEST_CASE_METHOD(Sdl2TestFixture, "RenderedCircle::Constructor cannot throw",
|
||||
TEST_SUITE_NAME)
|
||||
TEST_CASE_METHOD(
|
||||
Sdl2TestFixture, "RenderedCircle::Constructor cannot throw", TEST_SUITE_NAME
|
||||
)
|
||||
{
|
||||
|
||||
REQUIRE_NOTHROW([this]() { RenderedCircle circle(0x001); });
|
||||
|
@ -22,8 +22,7 @@ using fakeit::When;
|
||||
|
||||
using namespace QW::Core::Types;
|
||||
|
||||
class SomeInterface
|
||||
{
|
||||
class SomeInterface {
|
||||
public:
|
||||
virtual int foo(int) = 0;
|
||||
virtual int bar(c_string) = 0;
|
||||
@ -49,8 +48,7 @@ TEST_CASE("Catch2 works with Fakeit", "[integrity-check]")
|
||||
}
|
||||
|
||||
// #region seraization test setup
|
||||
struct DataRecord
|
||||
{
|
||||
struct DataRecord {
|
||||
id_t id;
|
||||
std::string name;
|
||||
|
||||
@ -61,8 +59,7 @@ struct DataRecord
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DataRecord, id, name)
|
||||
};
|
||||
struct DataRecordCollection
|
||||
{
|
||||
struct DataRecordCollection {
|
||||
std::unordered_map<id_t, DataRecord> collection;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DataRecordCollection, collection)
|
||||
|
@ -15,8 +15,7 @@
|
||||
using namespace QW;
|
||||
using namespace QW::Core::Components;
|
||||
|
||||
struct SomeComponent : public BaseComponent
|
||||
{
|
||||
struct SomeComponent : public BaseComponent {
|
||||
COMPONENT(SomeComponent)
|
||||
|
||||
public:
|
||||
@ -33,8 +32,7 @@ struct SomeComponent : public BaseComponent
|
||||
}
|
||||
};
|
||||
|
||||
class SomeOtherComponent : public BaseComponent
|
||||
{
|
||||
class SomeOtherComponent : public BaseComponent {
|
||||
COMPONENT(SomeOtherComponent)
|
||||
public:
|
||||
SomeOtherComponent(InstanceId id) : BaseComponent(id)
|
||||
|
Loading…
Reference in New Issue
Block a user