mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
command line arguments to platform module
This commit is contained in:
@@ -112,7 +112,7 @@ namespace e2d
|
||||
timer_parameters timer_params_;
|
||||
};
|
||||
public:
|
||||
engine(const parameters& params);
|
||||
engine(int argc, char *argv[], const parameters& params);
|
||||
~engine() noexcept final;
|
||||
|
||||
template < typename Application, typename... Args >
|
||||
|
||||
@@ -12,8 +12,11 @@ namespace e2d
|
||||
{
|
||||
class platform final : public module<platform> {
|
||||
public:
|
||||
platform();
|
||||
platform(int argc, char *argv[]);
|
||||
~platform() noexcept final;
|
||||
|
||||
std::size_t command_line_argument_count() const noexcept;
|
||||
const str& command_line_argument(std::size_t index) const noexcept;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
#include "math/_all.hpp"
|
||||
#include "utils/_all.hpp"
|
||||
|
||||
e2d::i32 e2d_main();
|
||||
e2d::i32 e2d_main(int argc, char *argv[]);
|
||||
|
||||
@@ -196,10 +196,10 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
int e2d_main() {
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_00", "enduro2d")
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(params).start<game>();
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -260,10 +260,10 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
int e2d_main() {
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_01", "enduro2d")
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(params).start<game>();
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -241,10 +241,10 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
int e2d_main() {
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_02", "enduro2d")
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(params).start<game>();
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <enduro2d/core/debug.hpp>
|
||||
#include <enduro2d/core/input.hpp>
|
||||
#include <enduro2d/core/platform.hpp>
|
||||
#include <enduro2d/core/render.hpp>
|
||||
#include <enduro2d/core/vfs.hpp>
|
||||
#include <enduro2d/core/window.hpp>
|
||||
@@ -304,9 +305,13 @@ namespace e2d
|
||||
// engine
|
||||
//
|
||||
|
||||
engine::engine(const parameters& params)
|
||||
engine::engine(int argc, char *argv[], const parameters& params)
|
||||
: state_(new internal_state(params))
|
||||
{
|
||||
// setup platform
|
||||
|
||||
safe_module_initialize<platform>(argc, argv);
|
||||
|
||||
// setup debug
|
||||
|
||||
safe_module_initialize<debug>();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2018 Matvey Cherevko
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/core/platform.hpp>
|
||||
#include "platform_impl/platform.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
@@ -14,15 +14,41 @@ namespace e2d
|
||||
|
||||
class platform::internal_state final : private e2d::noncopyable {
|
||||
public:
|
||||
internal_state() = default;
|
||||
internal_state(int argc, char *argv[])
|
||||
: impl_(platform_internal_state_impl::create())
|
||||
{
|
||||
if ( argc > 0 ) {
|
||||
command_line_arguments_.reserve(
|
||||
math::numeric_cast<std::size_t>(argc));
|
||||
for ( int i = 0; i < argc; ++i ) {
|
||||
command_line_arguments_.emplace_back(argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
~internal_state() noexcept = default;
|
||||
public:
|
||||
const vector<str>& command_line_arguments() const noexcept {
|
||||
return command_line_arguments_;
|
||||
}
|
||||
private:
|
||||
vector<str> command_line_arguments_;
|
||||
platform_internal_state_impl_uptr impl_;
|
||||
};
|
||||
|
||||
//
|
||||
// platform
|
||||
//
|
||||
|
||||
platform::platform()
|
||||
: state_(new internal_state()) {}
|
||||
platform::platform(int argc, char *argv[])
|
||||
: state_(new internal_state(argc, argv)) {}
|
||||
platform::~platform() noexcept = default;
|
||||
|
||||
std::size_t platform::command_line_argument_count() const noexcept {
|
||||
return state_->command_line_arguments().size();
|
||||
}
|
||||
|
||||
const str& platform::command_line_argument(std::size_t index) const noexcept {
|
||||
E2D_ASSERT(index < state_->command_line_arguments().size());
|
||||
return state_->command_line_arguments()[index];
|
||||
}
|
||||
}
|
||||
|
||||
44
sources/enduro2d/core/platform_impl/platform.hpp
Normal file
44
sources/enduro2d/core/platform_impl/platform.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* 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 <enduro2d/core/platform.hpp>
|
||||
|
||||
#define E2D_PLATFORM_MODE_NONE 1
|
||||
#define E2D_PLATFORM_MODE_IOS 2
|
||||
#define E2D_PLATFORM_MODE_LINUX 3
|
||||
#define E2D_PLATFORM_MODE_MACOSX 4
|
||||
#define E2D_PLATFORM_MODE_WINDOWS 5
|
||||
|
||||
#ifndef E2D_PLATFORM_MODE
|
||||
# if defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_IOS
|
||||
# define E2D_PLATFORM_MODE E2D_PLATFORM_MODE_IOS
|
||||
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_LINUX
|
||||
# define E2D_PLATFORM_MODE E2D_PLATFORM_MODE_LINUX
|
||||
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_MACOSX
|
||||
# define E2D_PLATFORM_MODE E2D_PLATFORM_MODE_MACOSX
|
||||
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_WINDOWS
|
||||
# define E2D_PLATFORM_MODE E2D_PLATFORM_MODE_WINDOWS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef E2D_PLATFORM_MODE
|
||||
# error E2D_PLATFORM_MODE not detected
|
||||
#endif
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class platform_internal_state_impl;
|
||||
using platform_internal_state_impl_uptr = std::unique_ptr<platform_internal_state_impl>;
|
||||
|
||||
class platform_internal_state_impl : private e2d::noncopyable {
|
||||
public:
|
||||
platform_internal_state_impl() = default;
|
||||
~platform_internal_state_impl() noexcept = default;
|
||||
static platform_internal_state_impl_uptr create();
|
||||
};
|
||||
}
|
||||
29
sources/enduro2d/core/platform_impl/platform_ios.cpp
Normal file
29
sources/enduro2d/core/platform_impl/platform_ios.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* 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 "platform.hpp"
|
||||
|
||||
#if defined(E2D_PLATFORM_MODE) && E2D_PLATFORM_MODE == E2D_PLATFORM_MODE_IOS
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
class platform_internal_state_impl_ios final : public platform_internal_state_impl {
|
||||
public:
|
||||
platform_internal_state_impl_ios() = default;
|
||||
~platform_internal_state_impl_ios() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
platform_internal_state_impl_uptr platform_internal_state_impl::create() {
|
||||
return std::make_unique<platform_internal_state_impl_ios>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
29
sources/enduro2d/core/platform_impl/platform_linux.cpp
Normal file
29
sources/enduro2d/core/platform_impl/platform_linux.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* 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 "platform.hpp"
|
||||
|
||||
#if defined(E2D_PLATFORM_MODE) && E2D_PLATFORM_MODE == E2D_PLATFORM_MODE_LINUX
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
class platform_internal_state_impl_linux final : public platform_internal_state_impl {
|
||||
public:
|
||||
platform_internal_state_impl_linux() = default;
|
||||
~platform_internal_state_impl_linux() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
platform_internal_state_impl_uptr platform_internal_state_impl::create() {
|
||||
return std::make_unique<platform_internal_state_impl_linux>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
29
sources/enduro2d/core/platform_impl/platform_macosx.cpp
Normal file
29
sources/enduro2d/core/platform_impl/platform_macosx.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* 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 "platform.hpp"
|
||||
|
||||
#if defined(E2D_PLATFORM_MODE) && E2D_PLATFORM_MODE == E2D_PLATFORM_MODE_MACOSX
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
class platform_internal_state_impl_macosx final : public platform_internal_state_impl {
|
||||
public:
|
||||
platform_internal_state_impl_macosx() = default;
|
||||
~platform_internal_state_impl_macosx() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
platform_internal_state_impl_uptr platform_internal_state_impl::create() {
|
||||
return std::make_unique<platform_internal_state_impl_macosx>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
29
sources/enduro2d/core/platform_impl/platform_none.cpp
Normal file
29
sources/enduro2d/core/platform_impl/platform_none.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* 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 "platform.hpp"
|
||||
|
||||
#if defined(E2D_PLATFORM_MODE) && E2D_PLATFORM_MODE == E2D_PLATFORM_MODE_NONE
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
class platform_internal_state_impl_none final : public platform_internal_state_impl {
|
||||
public:
|
||||
platform_internal_state_impl_none() = default;
|
||||
~platform_internal_state_impl_none() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
platform_internal_state_impl_uptr platform_internal_state_impl::create() {
|
||||
return std::make_unique<platform_internal_state_impl_none>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
29
sources/enduro2d/core/platform_impl/platform_windows.cpp
Normal file
29
sources/enduro2d/core/platform_impl/platform_windows.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* 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 "platform.hpp"
|
||||
|
||||
#if defined(E2D_PLATFORM_MODE) && E2D_PLATFORM_MODE == E2D_PLATFORM_MODE_WINDOWS
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
class platform_internal_state_impl_windows final : public platform_internal_state_impl {
|
||||
public:
|
||||
platform_internal_state_impl_windows() = default;
|
||||
~platform_internal_state_impl_windows() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
platform_internal_state_impl_uptr platform_internal_state_impl::create() {
|
||||
return std::make_unique<platform_internal_state_impl_windows>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,5 @@
|
||||
#include <enduro2d/enduro2d.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
E2D_UNUSED(argc, argv);
|
||||
return e2d_main();
|
||||
return e2d_main(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user