mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
starter module for starting high modules
This commit is contained in:
@@ -87,8 +87,8 @@ namespace e2d
|
|||||||
parameters() = delete;
|
parameters() = delete;
|
||||||
parameters(str_view game_name, str_view company_name);
|
parameters(str_view game_name, str_view company_name);
|
||||||
|
|
||||||
parameters& game_name(str_view value) noexcept;
|
parameters& game_name(str_view value);
|
||||||
parameters& company_name(str_view value) noexcept;
|
parameters& company_name(str_view value);
|
||||||
parameters& debug_params(const debug_parameters& value);
|
parameters& debug_params(const debug_parameters& value);
|
||||||
parameters& window_params(const window_parameters& value);
|
parameters& window_params(const window_parameters& value);
|
||||||
parameters& timer_params(const timer_parameters& value);
|
parameters& timer_params(const timer_parameters& value);
|
||||||
|
|||||||
@@ -11,3 +11,4 @@
|
|||||||
#include "assets.hpp"
|
#include "assets.hpp"
|
||||||
#include "library.hpp"
|
#include "library.hpp"
|
||||||
#include "library.inl"
|
#include "library.inl"
|
||||||
|
#include "starter.hpp"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace e2d
|
|||||||
{
|
{
|
||||||
class asset;
|
class asset;
|
||||||
class library;
|
class library;
|
||||||
|
class starter;
|
||||||
class text_asset;
|
class text_asset;
|
||||||
class mesh_asset;
|
class mesh_asset;
|
||||||
class image_asset;
|
class image_asset;
|
||||||
|
|||||||
48
headers/enduro2d/high/starter.hpp
Normal file
48
headers/enduro2d/high/starter.hpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of the "Enduro2D"
|
||||||
|
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||||
|
* Copyright (C) 2018 Matvey Cherevko
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "_high.hpp"
|
||||||
|
|
||||||
|
namespace e2d
|
||||||
|
{
|
||||||
|
class starter final : public module<starter> {
|
||||||
|
public:
|
||||||
|
class parameters {
|
||||||
|
public:
|
||||||
|
parameters() = delete;
|
||||||
|
parameters(const engine::parameters& engine_params);
|
||||||
|
|
||||||
|
parameters& library_root(const url& value);
|
||||||
|
parameters& engine_params(const engine::parameters& value);
|
||||||
|
|
||||||
|
url& library_root() noexcept;
|
||||||
|
engine::parameters& engine_params() noexcept;
|
||||||
|
|
||||||
|
const url& library_root() const noexcept;
|
||||||
|
const engine::parameters& engine_params() const noexcept;
|
||||||
|
private:
|
||||||
|
url library_root_{"resources://bin/library"};
|
||||||
|
engine::parameters engine_params_;
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
starter(int argc, char *argv[], const parameters& params);
|
||||||
|
~starter() noexcept final;
|
||||||
|
|
||||||
|
template < typename Application, typename... Args >
|
||||||
|
bool start(Args&&... args);
|
||||||
|
bool start(application_uptr app);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace e2d
|
||||||
|
{
|
||||||
|
template < typename Application, typename... Args >
|
||||||
|
bool starter::start(Args&&... args) {
|
||||||
|
return start(std::make_unique<Application>(std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,3 +46,4 @@ endfunction(add_e2d_sample)
|
|||||||
add_e2d_sample(00)
|
add_e2d_sample(00)
|
||||||
add_e2d_sample(01)
|
add_e2d_sample(01)
|
||||||
add_e2d_sample(02)
|
add_e2d_sample(02)
|
||||||
|
add_e2d_sample(03)
|
||||||
|
|||||||
42
samples/sources/sample_03/sample_03.cpp
Normal file
42
samples/sources/sample_03/sample_03.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of the "Enduro2D"
|
||||||
|
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||||
|
* Copyright (C) 2018 Matvey Cherevko
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "../common.hpp"
|
||||||
|
using namespace e2d;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class game final : public application {
|
||||||
|
public:
|
||||||
|
bool initialize() final {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool frame_tick() final {
|
||||||
|
const keyboard& k = the<input>().keyboard();
|
||||||
|
if ( the<window>().should_close() || k.is_key_just_released(keyboard_key::escape) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
the<render>().execute(render::command_block<64>()
|
||||||
|
.add_command(render::clear_command()
|
||||||
|
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
||||||
|
.add_command(render::swap_command(true)));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
int e2d_main(int argc, char *argv[]) {
|
||||||
|
const auto starter_params = starter::parameters(
|
||||||
|
engine::parameters("sample_03", "enduro3d")
|
||||||
|
.timer_params(engine::timer_parameters()
|
||||||
|
.maximal_framerate(100)));
|
||||||
|
modules::initialize<starter>(
|
||||||
|
argc, argv, starter_params).start<game>();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -145,12 +145,12 @@ namespace e2d
|
|||||||
: game_name_(game_name)
|
: game_name_(game_name)
|
||||||
, company_name_(company_name) {}
|
, company_name_(company_name) {}
|
||||||
|
|
||||||
engine::parameters& engine::parameters::game_name(str_view value) noexcept {
|
engine::parameters& engine::parameters::game_name(str_view value) {
|
||||||
game_name_ = value;
|
game_name_ = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::parameters& engine::parameters::company_name(str_view value) noexcept {
|
engine::parameters& engine::parameters::company_name(str_view value) {
|
||||||
company_name_ = value;
|
company_name_ = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
72
sources/enduro2d/high/starter.cpp
Normal file
72
sources/enduro2d/high/starter.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of the "Enduro2D"
|
||||||
|
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||||
|
* Copyright (C) 2018 Matvey Cherevko
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include <enduro2d/high/starter.hpp>
|
||||||
|
|
||||||
|
#include <enduro2d/high/library.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using namespace e2d;
|
||||||
|
|
||||||
|
template < typename Module, typename... Args >
|
||||||
|
void safe_module_initialize(Args&&... args) {
|
||||||
|
if ( !modules::is_initialized<Module>() ) {
|
||||||
|
modules::initialize<Module>(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace e2d
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// starter::parameters
|
||||||
|
//
|
||||||
|
|
||||||
|
starter::parameters::parameters(const engine::parameters& engine_params)
|
||||||
|
: engine_params_(engine_params) {}
|
||||||
|
|
||||||
|
starter::parameters& starter::parameters::library_root(const url& value) {
|
||||||
|
library_root_ = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
starter::parameters& starter::parameters::engine_params(const engine::parameters& value) {
|
||||||
|
engine_params_ = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
url& starter::parameters::library_root() noexcept {
|
||||||
|
return library_root_;
|
||||||
|
}
|
||||||
|
|
||||||
|
engine::parameters& starter::parameters::engine_params() noexcept {
|
||||||
|
return engine_params_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url& starter::parameters::library_root() const noexcept {
|
||||||
|
return library_root_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const engine::parameters& starter::parameters::engine_params() const noexcept {
|
||||||
|
return engine_params_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// starter
|
||||||
|
//
|
||||||
|
|
||||||
|
starter::starter(int argc, char *argv[], const parameters& params) {
|
||||||
|
safe_module_initialize<engine>(argc, argv, params.engine_params());
|
||||||
|
safe_module_initialize<library>(params.library_root());
|
||||||
|
}
|
||||||
|
|
||||||
|
starter::~starter() noexcept = default;
|
||||||
|
|
||||||
|
bool starter::start(application_uptr app) {
|
||||||
|
return the<engine>().start(std::move(app));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user