From a13a347a23b1288d8f5e022395f1015ab4be998d Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 5 Nov 2019 18:05:52 +0700 Subject: [PATCH] dummy sample 07 --- samples/CMakeLists.txt | 1 + samples/bin/library/scenes/sample_07.json | 30 ++++++++ samples/sources/sample_07/sample_07.cpp | 87 +++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 samples/bin/library/scenes/sample_07.json create mode 100644 samples/sources/sample_07/sample_07.cpp diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index ff26c8b8..6206d32f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -45,3 +45,4 @@ add_e2d_sample(03) add_e2d_sample(04) add_e2d_sample(05) add_e2d_sample(06) +add_e2d_sample(07) diff --git a/samples/bin/library/scenes/sample_07.json b/samples/bin/library/scenes/sample_07.json new file mode 100644 index 00000000..90f11ee8 --- /dev/null +++ b/samples/bin/library/scenes/sample_07.json @@ -0,0 +1,30 @@ +{ + "components" : { + "scene" : {} + }, + "children" : [{ + "prototype" : "../prefabs/camera_prefab.json" + },{ + "prototype" : "../prefabs/gnome_prefab.json", + "components" : { + "actor" : { + "translation" : [0,0,0], + "scale" : 20 + } + } + }, { + "prototype" : "../prefabs/label_sdf_prefab.json", + "components" : { + "label" : { + "text" : "Hello World!", + "valign" : "center", + "outline_width" : 0.5, + "outline_color" : [0,0,0,255] + }, + "actor" : { + "translation" : [0.5,-180.5,0], + "scale" : 2 + } + } + }] +} diff --git a/samples/sources/sample_07/sample_07.cpp b/samples/sources/sample_07/sample_07.cpp new file mode 100644 index 00000000..5347f222 --- /dev/null +++ b/samples/sources/sample_07/sample_07.cpp @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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 "../common.hpp" +using namespace e2d; + +namespace +{ + class game_system final : public systems::update_system { + public: + void process( + ecs::registry& owner, + const systems::update_event& event) override + { + E2D_UNUSED(owner, event); + const keyboard& k = the().keyboard(); + + if ( k.is_key_just_released(keyboard_key::f12) ) { + the().toggle_visible(!the().visible()); + } + + if ( k.is_key_just_released(keyboard_key::escape) ) { + the().set_should_close(true); + } + + if ( k.is_key_pressed(keyboard_key::lsuper) && k.is_key_just_released(keyboard_key::enter) ) { + the().toggle_fullscreen(!the().fullscreen()); + } + } + }; + + class camera_system final : public systems::render_system { + public: + void process( + ecs::registry& owner, + const systems::render_event& event) override + { + E2D_UNUSED(event); + owner.for_joined_components( + [](const ecs::const_entity&, camera& cam){ + if ( !cam.target() ) { + cam.viewport( + the().framebuffer_size()); + cam.projection(math::make_orthogonal_lh_matrix4( + the().real_size().cast_to(), 0.f, 1000.f)); + } + }); + } + }; + + class game final : public starter::application { + public: + bool initialize() final { + return create_scene() + && create_systems(); + } + private: + bool create_scene() { + auto scene_prefab_res = the().load_asset("scenes/sample_07.json"); + auto scene_go = scene_prefab_res + ? the().instantiate(scene_prefab_res->content()) + : gobject(); + return scene_go.valid(); + } + + bool create_systems() { + ecs::registry_filler(the().registry()) + .feature(ecs::feature() + .add_system() + .add_system()); + return true; + } + }; +} + +int e2d_main(int argc, char *argv[]) { + const auto starter_params = starter::parameters( + engine::parameters("sample_07", "enduro2d") + .timer_params(engine::timer_parameters() + .maximal_framerate(100))); + modules::initialize(argc, argv, starter_params).start(); + modules::shutdown(); + return 0; +}