From b4bd5879acb52557b708bdcd7c4a55cbf63a30c1 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 13 Jun 2019 04:47:30 +0700 Subject: [PATCH] add dummy script asset --- headers/enduro2d/high/_all.hpp | 2 + headers/enduro2d/high/_high.hpp | 2 + headers/enduro2d/high/assets/script_asset.hpp | 21 ++++++ headers/enduro2d/high/script.hpp | 34 ++++++++++ sources/enduro2d/high/assets/script_asset.cpp | 32 ++++++++++ sources/enduro2d/high/script.cpp | 64 +++++++++++++++++++ 6 files changed, 155 insertions(+) create mode 100644 headers/enduro2d/high/assets/script_asset.hpp create mode 100644 headers/enduro2d/high/script.hpp create mode 100644 sources/enduro2d/high/assets/script_asset.cpp create mode 100644 sources/enduro2d/high/script.cpp diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index b9fb71ec..45b64dd5 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -17,6 +17,7 @@ #include "assets/mesh_asset.hpp" #include "assets/model_asset.hpp" #include "assets/prefab_asset.hpp" +#include "assets/script_asset.hpp" #include "assets/shader_asset.hpp" #include "assets/shape_asset.hpp" #include "assets/sprite_asset.hpp" @@ -51,6 +52,7 @@ #include "node.hpp" #include "node.inl" #include "prefab.hpp" +#include "script.hpp" #include "sprite.hpp" #include "starter.hpp" #include "world.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 480f88ff..a946040c 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -29,6 +29,7 @@ namespace e2d class mesh_asset; class model_asset; class prefab_asset; + class script_asset; class shader_asset; class shape_asset; class sprite_asset; @@ -65,6 +66,7 @@ namespace e2d class model; class node; class prefab; + class script; class sprite; class starter; class world; diff --git a/headers/enduro2d/high/assets/script_asset.hpp b/headers/enduro2d/high/assets/script_asset.hpp new file mode 100644 index 00000000..4414587d --- /dev/null +++ b/headers/enduro2d/high/assets/script_asset.hpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../_high.hpp" + +#include "../library.hpp" +#include "../script.hpp" + +namespace e2d +{ + class script_asset final : public content_asset { + public: + static const char* type_name() noexcept { return "script_asset"; } + static load_async_result load_async(const library& library, str_view address); + }; +} diff --git a/headers/enduro2d/high/script.hpp b/headers/enduro2d/high/script.hpp new file mode 100644 index 00000000..0353b1cf --- /dev/null +++ b/headers/enduro2d/high/script.hpp @@ -0,0 +1,34 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "_high.hpp" + +namespace e2d +{ + class script final { + public: + script() = default; + ~script() noexcept = default; + + script(script&& other) noexcept; + script& operator=(script&& other) noexcept; + + script(const script& other); + script& operator=(const script& other); + + void clear() noexcept; + void swap(script& other) noexcept; + + script& assign(script&& other) noexcept; + script& assign(const script& other); + }; + + void swap(script& l, script& r) noexcept; + bool operator==(const script& l, const script& r) noexcept; + bool operator!=(const script& l, const script& r) noexcept; +} diff --git a/sources/enduro2d/high/assets/script_asset.cpp b/sources/enduro2d/high/assets/script_asset.cpp new file mode 100644 index 00000000..6806df1a --- /dev/null +++ b/sources/enduro2d/high/assets/script_asset.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include +#include + +namespace +{ + using namespace e2d; + + class script_asset_loading_exception final : public asset_loading_exception { + const char* what() const noexcept final { + return "script asset loading exception"; + } + }; +} + +namespace e2d +{ + script_asset::load_async_result script_asset::load_async( + const library& library, str_view address) + { + return library.load_asset_async(address) + .then([](const binary_asset::load_result& script_data){ + script content; + return script_asset::create(std::move(content)); + }); + } +} diff --git a/sources/enduro2d/high/script.cpp b/sources/enduro2d/high/script.cpp new file mode 100644 index 00000000..8c8d56d6 --- /dev/null +++ b/sources/enduro2d/high/script.cpp @@ -0,0 +1,64 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +namespace e2d +{ + script::script(script&& other) noexcept { + assign(std::move(other)); + } + + script& script::operator=(script&& other) noexcept { + return assign(std::move(other)); + } + + script::script(const script& other) { + assign(other); + } + + script& script::operator=(const script& other) { + return assign(other); + } + + void script::clear() noexcept { + } + + void script::swap(script& other) noexcept { + using std::swap; + } + + script& script::assign(script&& other) noexcept { + if ( this != &other ) { + swap(other); + other.clear(); + } + return *this; + } + + script& script::assign(const script& other) { + if ( this != &other ) { + script s; + swap(s); + } + return *this; + } +} + +namespace e2d +{ + void swap(script& l, script& r) noexcept { + l.swap(r); + } + + bool operator==(const script& l, const script& r) noexcept { + return true; + } + + bool operator!=(const script& l, const script& r) noexcept { + return !(l == r); + } +}