Archived
1
Fork 0

Rename Engine to engine

This commit is contained in:
redstrate 2021-04-19 12:23:18 -04:00
parent 744123763f
commit 4abf4b4ab8
4 changed files with 75 additions and 75 deletions

View file

@ -3,7 +3,7 @@
class GFXCommandBuffer; class GFXCommandBuffer;
namespace prism { namespace prism {
class Engine; class engine;
/// The base class for any Prism application. /// The base class for any Prism application.
class app { class app {
@ -34,4 +34,4 @@ namespace prism {
} }
/// This is an app's equivalent of main(). You can check command line arguments through Engine::command_line_arguments. /// This is an app's equivalent of main(). You can check command line arguments through Engine::command_line_arguments.
void app_main(prism::Engine* engine); void app_main(prism::engine* engine);

View file

@ -36,7 +36,7 @@ namespace prism {
}; };
/// The glue between app and systems such as the Renderer. /// The glue between app and systems such as the Renderer.
class Engine { class engine {
public: public:
/** /**
Constructs an Engine with command line arguments. Can be accessed later from command_line_arguments. Constructs an Engine with command line arguments. Can be accessed later from command_line_arguments.
@ -44,12 +44,12 @@ namespace prism {
@param argc Numer of arguments. Can be null. @param argc Numer of arguments. Can be null.
@param argv Array of strings containing arguments. Can be null. @param argv Array of strings containing arguments. Can be null.
*/ */
Engine(int argc, char* argv[]); engine(int argc, char* argv[]);
Engine(const Engine& other) = delete; engine(const engine& other) = delete;
Engine(Engine&& other) = delete; engine(engine&& other) = delete;
~Engine(); ~engine();
/// Command line arguments, can be empty. /// Command line arguments, can be empty.
std::vector<std::string_view> command_line_arguments; std::vector<std::string_view> command_line_arguments;
@ -391,4 +391,4 @@ namespace prism {
} }
} }
inline prism::Engine* engine = nullptr; inline prism::engine* engine = nullptr;

View file

@ -23,9 +23,9 @@
#include "shadowpass.hpp" #include "shadowpass.hpp"
#include "scenecapture.hpp" #include "scenecapture.hpp"
using prism::Engine; using prism::engine;
Engine::Engine(const int argc, char* argv[]) { engine::engine(const int argc, char* argv[]) {
console::info(System::Core, "Prism Engine loading..."); console::info(System::Core, "Prism Engine loading...");
console::register_command("test_cmd", console::ArgumentFormat(0), [](const console::Arguments) { console::register_command("test_cmd", console::ArgumentFormat(0), [](const console::Arguments) {
@ -47,19 +47,19 @@ Engine::Engine(const int argc, char* argv[]) {
assetm = std::make_unique<AssetManager>(); assetm = std::make_unique<AssetManager>();
} }
Engine::~Engine() {} engine::~engine() {}
void Engine::set_app(app* app) { void engine::set_app(app* app) {
Expects(app != nullptr); Expects(app != nullptr);
_app = app; _app = app;
} }
prism::app* Engine::get_app() const { prism::app* engine::get_app() const {
return _app; return _app;
} }
void Engine::load_localization(const std::string_view path) { void engine::load_localization(const std::string_view path) {
Expects(!path.empty()); Expects(!path.empty());
auto file = file::open(file::app_domain / path); auto file = file::open(file::app_domain / path);
@ -71,53 +71,53 @@ void Engine::load_localization(const std::string_view path) {
} }
} }
void Engine::pause() { void engine::pause() {
_paused = true; _paused = true;
push_event("engine_pause"); push_event("engine_pause");
} }
void Engine::unpause() { void engine::unpause() {
_paused = false; _paused = false;
push_event("engine_unpause"); push_event("engine_unpause");
} }
bool Engine::is_paused() const { bool engine::is_paused() const {
return _paused; return _paused;
} }
void Engine::quit() { void engine::quit() {
_windows[0]->quitRequested = true; _windows[0]->quitRequested = true;
} }
bool Engine::is_quitting() const { bool engine::is_quitting() const {
return _windows[0]->quitRequested; return _windows[0]->quitRequested;
} }
void Engine::prepare_quit() { void engine::prepare_quit() {
_app->prepare_quit(); _app->prepare_quit();
} }
void Engine::set_gfx(GFX* gfx) { void engine::set_gfx(GFX* gfx) {
_gfx = gfx; _gfx = gfx;
} }
GFX* Engine::get_gfx() { GFX* engine::get_gfx() {
return _gfx; return _gfx;
} }
Input* Engine::get_input() { Input* engine::get_input() {
return _input.get(); return _input.get();
} }
Renderer* Engine::get_renderer() { Renderer* engine::get_renderer() {
return _renderer.get(); return _renderer.get();
} }
Physics* Engine::get_physics() { Physics* engine::get_physics() {
return _physics.get(); return _physics.get();
} }
void Engine::create_empty_scene() { void engine::create_empty_scene() {
auto scene = std::make_unique<Scene>(); auto scene = std::make_unique<Scene>();
setup_scene(*scene); setup_scene(*scene);
@ -126,7 +126,7 @@ void Engine::create_empty_scene() {
_current_scene = _scenes.back().get(); _current_scene = _scenes.back().get();
} }
Scene* Engine::load_scene(const file::Path path) { Scene* engine::load_scene(const file::Path path) {
Expects(!path.empty()); Expects(!path.empty());
auto file = file::open(path); auto file = file::open(path);
@ -172,7 +172,7 @@ Scene* Engine::load_scene(const file::Path path) {
return _scenes.back().get(); return _scenes.back().get();
} }
void Engine::save_scene(const std::string_view path) { void engine::save_scene(const std::string_view path) {
Expects(!path.empty()); Expects(!path.empty());
nlohmann::json j; nlohmann::json j;
@ -186,13 +186,13 @@ void Engine::save_scene(const std::string_view path) {
out << j; out << j;
} }
ui::Screen* Engine::load_screen(const file::Path path) { ui::Screen* engine::load_screen(const file::Path path) {
Expects(!path.empty()); Expects(!path.empty());
return new ui::Screen(path); return new ui::Screen(path);
} }
void Engine::set_screen(ui::Screen* screen) { void engine::set_screen(ui::Screen* screen) {
_current_screen = screen; _current_screen = screen;
screen->extent = _windows[0]->extent; screen->extent = _windows[0]->extent;
@ -201,11 +201,11 @@ void Engine::set_screen(ui::Screen* screen) {
get_renderer()->set_screen(screen); get_renderer()->set_screen(screen);
} }
ui::Screen* Engine::get_screen() const { ui::Screen* engine::get_screen() const {
return _current_screen; return _current_screen;
} }
AnimationChannel Engine::load_animation(nlohmann::json a) { AnimationChannel engine::load_animation(nlohmann::json a) {
AnimationChannel animation; AnimationChannel animation;
for(auto& kf : a["frames"]) { for(auto& kf : a["frames"]) {
@ -219,7 +219,7 @@ AnimationChannel Engine::load_animation(nlohmann::json a) {
return animation; return animation;
} }
Animation Engine::load_animation(const file::Path path) { Animation engine::load_animation(const file::Path path) {
Expects(!path.empty()); Expects(!path.empty());
auto file = file::open(path, true); auto file = file::open(path, true);
@ -277,7 +277,7 @@ Animation Engine::load_animation(const file::Path path) {
return anim; return anim;
} }
void Engine::load_cutscene(const file::Path path) { void engine::load_cutscene(const file::Path path) {
Expects(!path.empty()); Expects(!path.empty());
cutscene = std::make_unique<Cutscene>(); cutscene = std::make_unique<Cutscene>();
@ -313,11 +313,11 @@ void Engine::load_cutscene(const file::Path path) {
} else { } else {
load_scene(file::root_path(path) / s["scene"].get<std::string_view>()); load_scene(file::root_path(path) / s["scene"].get<std::string_view>());
if(engine->get_scene() == nullptr) if(get_scene() == nullptr)
engine->create_empty_scene(); create_empty_scene();
auto cameraObj = engine->get_scene()->add_object(); auto cameraObj = get_scene()->add_object();
engine->get_scene()->add<Camera>(cameraObj); get_scene()->add<Camera>(cameraObj);
for(auto& anim : shot.channels) { for(auto& anim : shot.channels) {
if(anim.target == NullObject) if(anim.target == NullObject)
@ -332,12 +332,12 @@ void Engine::load_cutscene(const file::Path path) {
} }
} }
void Engine::save_cutscene(const std::string_view path) { void engine::save_cutscene(const std::string_view path) {
Expects(!path.empty()); Expects(!path.empty());
nlohmann::json j; nlohmann::json j;
for(auto& shot : engine->cutscene->shots) { for(auto& shot : cutscene->shots) {
nlohmann::json s; nlohmann::json s;
s["begin"] = shot.begin; s["begin"] = shot.begin;
s["end"] = shot.length; s["end"] = shot.length;
@ -354,7 +354,7 @@ void Engine::save_cutscene(const std::string_view path) {
out << j; out << j;
} }
Object Engine::add_prefab(Scene& scene, const file::Path path, const std::string_view override_name) { Object engine::add_prefab(Scene& scene, const file::Path path, const std::string_view override_name) {
Expects(!path.empty()); Expects(!path.empty());
auto file = file::open(path); auto file = file::open(path);
@ -389,7 +389,7 @@ Object Engine::add_prefab(Scene& scene, const file::Path path, const std::string
return root_node; return root_node;
} }
void Engine::save_prefab(const Object root, const std::string_view path) { void engine::save_prefab(const Object root, const std::string_view path) {
Expects(root != NullObject); Expects(root != NullObject);
Expects(!path.empty()); Expects(!path.empty());
@ -404,7 +404,7 @@ void Engine::save_prefab(const Object root, const std::string_view path) {
out << j; out << j;
} }
void Engine::add_window(void* native_handle, const int identifier, const prism::Extent extent) { void engine::add_window(void* native_handle, const int identifier, const prism::Extent extent) {
Expects(native_handle != nullptr); Expects(native_handle != nullptr);
Expects(identifier >= 0); Expects(identifier >= 0);
@ -426,7 +426,7 @@ void Engine::add_window(void* native_handle, const int identifier, const prism::
render_ready = true; render_ready = true;
} }
void Engine::remove_window(const int identifier) { void engine::remove_window(const int identifier) {
Expects(identifier >= 0); Expects(identifier >= 0);
utility::erase_if(_windows, [identifier](Window*& w) { utility::erase_if(_windows, [identifier](Window*& w) {
@ -434,7 +434,7 @@ void Engine::remove_window(const int identifier) {
}); });
} }
void Engine::resize(const int identifier, const prism::Extent extent) { void engine::resize(const int identifier, const prism::Extent extent) {
Expects(identifier >= 0); Expects(identifier >= 0);
auto window = get_window(identifier); auto window = get_window(identifier);
@ -456,7 +456,7 @@ void Engine::resize(const int identifier, const prism::Extent extent) {
} }
} }
void Engine::process_key_down(const unsigned int keyCode) { void engine::process_key_down(const unsigned int keyCode) {
Expects(keyCode >= 0); Expects(keyCode >= 0);
_imgui->process_key_down(keyCode); _imgui->process_key_down(keyCode);
@ -465,37 +465,37 @@ void Engine::process_key_down(const unsigned int keyCode) {
debug_enabled = !debug_enabled; debug_enabled = !debug_enabled;
} }
void Engine::process_key_up(const unsigned int keyCode) { void engine::process_key_up(const unsigned int keyCode) {
Expects(keyCode >= 0); Expects(keyCode >= 0);
_imgui->process_key_up(keyCode); _imgui->process_key_up(keyCode);
} }
void Engine::process_mouse_down(const int button, const prism::Offset offset) { void engine::process_mouse_down(const int button, const prism::Offset offset) {
if(_current_screen != nullptr && button == 0) if(_current_screen != nullptr && button == 0)
_current_screen->process_mouse(offset.x, offset.y); _current_screen->process_mouse(offset.x, offset.y);
} }
void Engine::push_event(const std::string_view name, const std::string_view data) { void engine::push_event(const std::string_view name, const std::string_view data) {
Expects(!name.empty()); Expects(!name.empty());
if(_current_screen != nullptr) if(_current_screen != nullptr)
_current_screen->process_event(name.data(), data.data()); _current_screen->process_event(name.data(), data.data());
} }
bool Engine::has_localization(const std::string_view id) const { bool engine::has_localization(const std::string_view id) const {
Expects(!id.empty()); Expects(!id.empty());
return _strings.count(id.data()); return _strings.count(id.data());
} }
std::string Engine::localize(const std::string id) { std::string engine::localize(const std::string id) {
Expects(!id.empty()); Expects(!id.empty());
return _strings[id]; return _strings[id];
} }
void Engine::calculate_bone(Mesh& mesh, const Mesh::Part& part, Bone& bone, const Bone* parent_bone) { void engine::calculate_bone(Mesh& mesh, const Mesh::Part& part, Bone& bone, const Bone* parent_bone) {
if(part.offset_matrices.empty()) if(part.offset_matrices.empty())
return; return;
@ -517,7 +517,7 @@ void Engine::calculate_bone(Mesh& mesh, const Mesh::Part& part, Bone& bone, cons
} }
} }
void Engine::calculate_object(Scene& scene, Object object, const Object parent_object) { void engine::calculate_object(Scene& scene, Object object, const Object parent_object) {
Matrix4x4 parent_matrix; Matrix4x4 parent_matrix;
if(parent_object != NullObject) if(parent_object != NullObject)
parent_matrix = scene.get<Transform>(parent_object).model; parent_matrix = scene.get<Transform>(parent_object).model;
@ -552,7 +552,7 @@ void Engine::calculate_object(Scene& scene, Object object, const Object parent_o
mesh.temp_bone_data[i] = mesh.mesh->bones[i].final_transform; mesh.temp_bone_data[i] = mesh.mesh->bones[i].final_transform;
} }
engine->get_gfx()->copy_buffer(part.bone_batrix_buffer, mesh.temp_bone_data.data(), 0, mesh.temp_bone_data.size() * sizeof(Matrix4x4)); _gfx->copy_buffer(part.bone_batrix_buffer, mesh.temp_bone_data.data(), 0, mesh.temp_bone_data.size() * sizeof(Matrix4x4));
} }
} }
} }
@ -561,8 +561,8 @@ void Engine::calculate_object(Scene& scene, Object object, const Object parent_o
calculate_object(scene, child, object); calculate_object(scene, child, object);
} }
Shot* Engine::get_shot(const float time) { Shot* engine::get_shot(const float time) {
for(auto& shot : engine->cutscene->shots) { for(auto& shot : cutscene->shots) {
if(time >= shot.begin && time <= (shot.begin + shot.length)) if(time >= shot.begin && time <= (shot.begin + shot.length))
return &shot; return &shot;
} }
@ -570,7 +570,7 @@ Shot* Engine::get_shot(const float time) {
return nullptr; return nullptr;
} }
void Engine::update_animation_channel(Scene& scene, const AnimationChannel& channel, const float time) { void engine::update_animation_channel(Scene& scene, const AnimationChannel& channel, const float time) {
{ {
int keyframeIndex = -1; int keyframeIndex = -1;
int i = 0; int i = 0;
@ -635,7 +635,7 @@ void Engine::update_animation_channel(Scene& scene, const AnimationChannel& chan
} }
} }
void Engine::update_cutscene(const float time) { void engine::update_cutscene(const float time) {
Shot* currentShot = get_shot(time); Shot* currentShot = get_shot(time);
if(currentShot != nullptr) { if(currentShot != nullptr) {
_current_scene = currentShot->scene; _current_scene = currentShot->scene;
@ -647,12 +647,12 @@ void Engine::update_cutscene(const float time) {
} }
} }
void Engine::update_animation(const Animation& anim, const float time) { void engine::update_animation(const Animation& anim, const float time) {
for(const auto& channel : anim.channels) for(const auto& channel : anim.channels)
update_animation_channel(*_current_scene, channel, time); update_animation_channel(*_current_scene, channel, time);
} }
void Engine::begin_frame(const float delta_time) { void engine::begin_frame(const float delta_time) {
_imgui->begin_frame(delta_time); _imgui->begin_frame(delta_time);
if(debug_enabled) if(debug_enabled)
@ -662,14 +662,14 @@ void Engine::begin_frame(const float delta_time) {
_app->begin_frame(); _app->begin_frame();
} }
void Engine::end_frame() { void engine::end_frame() {
ImGui::UpdatePlatformWindows(); ImGui::UpdatePlatformWindows();
} }
int frame_delay = 0; int frame_delay = 0;
const int frame_delay_between_resolution_change = 60; const int frame_delay_between_resolution_change = 60;
void Engine::update(const float delta_time) { void engine::update(const float delta_time) {
const float ideal_delta_time = 0.01667f; const float ideal_delta_time = 0.01667f;
if(render_options.dynamic_resolution) { if(render_options.dynamic_resolution) {
@ -743,14 +743,14 @@ void Engine::update(const float delta_time) {
assetm->perform_cleanup(); assetm->perform_cleanup();
} }
void Engine::update_scene(Scene& scene) { void engine::update_scene(Scene& scene) {
for(auto& obj : scene.get_objects()) { for(auto& obj : scene.get_objects()) {
if(scene.get(obj).parent == NullObject) if(scene.get(obj).parent == NullObject)
calculate_object(scene, obj); calculate_object(scene, obj);
} }
} }
void Engine::render(const int index) { void engine::render(const int index) {
Expects(index >= 0); Expects(index >= 0);
auto window = get_window(index); auto window = get_window(index);
@ -776,25 +776,25 @@ void Engine::render(const int index) {
_gfx->submit(commandbuffer, index); _gfx->submit(commandbuffer, index);
} }
void Engine::add_timer(Timer& timer) { void engine::add_timer(Timer& timer) {
_timers.push_back(&timer); _timers.push_back(&timer);
} }
Scene* Engine::get_scene() { Scene* engine::get_scene() {
return _current_scene; return _current_scene;
} }
Scene* Engine::get_scene(const std::string_view name) { Scene* engine::get_scene(const std::string_view name) {
Expects(!name.empty()); Expects(!name.empty());
return _path_to_scene[name.data()]; return _path_to_scene[name.data()];
} }
void Engine::set_current_scene(Scene* scene) { void engine::set_current_scene(Scene* scene) {
_current_scene = scene; _current_scene = scene;
} }
std::string_view Engine::get_scene_path() const { std::string_view engine::get_scene_path() const {
for(auto& [path, scene] : _path_to_scene) { for(auto& [path, scene] : _path_to_scene) {
if(scene == this->_current_scene) if(scene == this->_current_scene)
return path; return path;
@ -803,13 +803,13 @@ std::string_view Engine::get_scene_path() const {
return ""; return "";
} }
void Engine::on_remove(Object object) { void engine::on_remove(Object object) {
Expects(object != NullObject); Expects(object != NullObject);
_physics->remove_object(object); _physics->remove_object(object);
} }
void Engine::play_animation(Animation animation, Object object, bool looping) { void engine::play_animation(Animation animation, Object object, bool looping) {
Expects(object != NullObject); Expects(object != NullObject);
if(!_current_scene->has<Renderable>(object)) if(!_current_scene->has<Renderable>(object))
@ -830,21 +830,21 @@ void Engine::play_animation(Animation animation, Object object, bool looping) {
_animation_targets.push_back(target); _animation_targets.push_back(target);
} }
void Engine::set_animation_speed_modifier(Object target, float modifier) { void engine::set_animation_speed_modifier(Object target, float modifier) {
for(auto& animation : _animation_targets) { for(auto& animation : _animation_targets) {
if(animation.target == target) if(animation.target == target)
animation.animation_speed_modifier = modifier; animation.animation_speed_modifier = modifier;
} }
} }
void Engine::stop_animation(Object target) { void engine::stop_animation(Object target) {
for(auto& animation : _animation_targets) { for(auto& animation : _animation_targets) {
if(animation.target == target) if(animation.target == target)
utility::erase(_animation_targets, animation); utility::erase(_animation_targets, animation);
} }
} }
void Engine::setup_scene(Scene& scene) { void engine::setup_scene(Scene& scene) {
_physics->reset(); _physics->reset();
scene.on_remove = [this](Object obj) { scene.on_remove = [this](Object obj) {

View file

@ -24,7 +24,7 @@ std::string get_filename(const std::string path) {
std::vector<Editor*> editors; std::vector<Editor*> editors;
void app_main(prism::Engine* engine) { void app_main(prism::engine* engine) {
CommonEditor* editor = (CommonEditor*)engine->get_app(); CommonEditor* editor = (CommonEditor*)engine->get_app();
platform::open_window("Prism Editor", platform::open_window("Prism Editor",