Archived
1
Fork 0

Renames engine member variables to fix bad naming conventions

This commit is contained in:
redstrate 2021-04-19 12:29:49 -04:00
parent 4abf4b4ab8
commit 3827bede6d
2 changed files with 118 additions and 118 deletions

View file

@ -332,26 +332,26 @@ namespace prism {
void on_remove(Object object); void on_remove(Object object);
bool _paused = false; bool paused = false;
ui::Screen* _current_screen = nullptr; ui::Screen* current_screen = nullptr;
Scene* _current_scene = nullptr; Scene* current_scene = nullptr;
std::vector<std::unique_ptr<Scene>> _scenes; std::vector<std::unique_ptr<Scene>> scenes;
std::map<std::string, Scene*> _path_to_scene; std::map<std::string, Scene*> path_to_scene;
struct Window { struct Window {
int identifier = -1; int identifier = -1;
prism::Extent extent; prism::Extent extent;
bool quitRequested = false; bool quit_requested = false;
RenderTarget* render_target = nullptr; RenderTarget* render_target = nullptr;
}; };
std::vector<Window*> _windows; std::vector<Window*> windows;
Window* get_window(const int identifier) { Window* get_window(const int identifier) {
for(auto& window : _windows) { for(auto& window : windows) {
if(window->identifier == identifier) if(window->identifier == identifier)
return window; return window;
} }
@ -368,20 +368,20 @@ namespace prism {
void update_animation_channel(Scene& scene, const AnimationChannel& channel, float time); void update_animation_channel(Scene& scene, const AnimationChannel& channel, float time);
app* _app = nullptr; app* app = nullptr;
GFX* _gfx = nullptr; GFX* gfx = nullptr;
std::unique_ptr<Input> _input; std::unique_ptr<Input> input;
std::unique_ptr<Physics> _physics; std::unique_ptr<Physics> physics;
std::unique_ptr<Renderer> _renderer; std::unique_ptr<Renderer> renderer;
std::vector<Timer*> _timers, _timersToRemove; std::vector<Timer*> timers, timers_to_remove;
std::map<std::string, std::string> _strings; std::map<std::string, std::string> strings;
std::vector<AnimationTarget> _animation_targets; std::vector<AnimationTarget> animation_targets;
std::unique_ptr<ImGuiLayer> _imgui; std::unique_ptr<ImGuiLayer> imgui;
const InputButton debug_button = InputButton::Q; const InputButton debug_button = InputButton::Q;
}; };

View file

@ -41,22 +41,22 @@ engine::engine(const int argc, char* argv[]) {
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++)
command_line_arguments.push_back(argv[i]); command_line_arguments.push_back(argv[i]);
_input = std::make_unique<Input>(); input = std::make_unique<Input>();
_physics = std::make_unique<Physics>(); physics = std::make_unique<Physics>();
_imgui = std::make_unique<ImGuiLayer>(); imgui = std::make_unique<ImGuiLayer>();
assetm = std::make_unique<AssetManager>(); assetm = std::make_unique<AssetManager>();
} }
engine::~engine() {} engine::~engine() {}
void engine::set_app(app* app) { void engine::set_app(prism::app* app) {
Expects(app != nullptr); Expects(app != nullptr);
_app = app; this->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) {
@ -67,54 +67,54 @@ void engine::load_localization(const std::string_view path) {
nlohmann::json j; nlohmann::json j;
file->read_as_stream() >> j; file->read_as_stream() >> j;
_strings = j["strings"].get<std::map<std::string, std::string>>(); strings = j["strings"].get<std::map<std::string, std::string>>();
} }
} }
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]->quit_requested = true;
} }
bool engine::is_quitting() const { bool engine::is_quitting() const {
return _windows[0]->quitRequested; return windows[0]->quit_requested;
} }
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; this->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() {
@ -122,8 +122,8 @@ void engine::create_empty_scene() {
setup_scene(*scene); setup_scene(*scene);
_scenes.push_back(std::move(scene)); scenes.push_back(std::move(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) {
@ -165,11 +165,11 @@ Scene* engine::load_scene(const file::Path path) {
setup_scene(*scene); setup_scene(*scene);
_scenes.push_back(std::move(scene)); scenes.push_back(std::move(scene));
_current_scene = _scenes.back().get(); current_scene = scenes.back().get();
_path_to_scene[path.string()] = _scenes.back().get(); path_to_scene[path.string()] = scenes.back().get();
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) {
@ -177,8 +177,8 @@ void engine::save_scene(const std::string_view path) {
nlohmann::json j; nlohmann::json j;
for(auto& obj : _current_scene->get_objects()) { for(auto& obj : current_scene->get_objects()) {
if(!_current_scene->get(obj).editor_object) if(!current_scene->get(obj).editor_object)
j["objects"].push_back(save_object(obj)); j["objects"].push_back(save_object(obj));
} }
@ -193,16 +193,16 @@ ui::Screen* engine::load_screen(const file::Path 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;
screen->calculate_sizes(); screen->calculate_sizes();
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) {
@ -300,8 +300,8 @@ void engine::load_cutscene(const file::Path path) {
shot.channels.push_back(load_animation(animation)); shot.channels.push_back(load_animation(animation));
} }
if(_path_to_scene.count(s["scene"])) { if(path_to_scene.count(s["scene"])) {
shot.scene = _path_to_scene[s["scene"]]; shot.scene = path_to_scene[s["scene"]];
// try to find main camera // try to find main camera
auto [obj, cam] = shot.scene->get_all<Camera>()[0]; auto [obj, cam] = shot.scene->get_all<Camera>()[0];
@ -324,8 +324,8 @@ void engine::load_cutscene(const file::Path path) {
anim.target = cameraObj; anim.target = cameraObj;
} }
_path_to_scene[s["scene"]] = _current_scene; path_to_scene[s["scene"]] = current_scene;
shot.scene = _current_scene; shot.scene = current_scene;
} }
cutscene->shots.push_back(shot); cutscene->shots.push_back(shot);
@ -342,7 +342,7 @@ void engine::save_cutscene(const std::string_view path) {
s["begin"] = shot.begin; s["begin"] = shot.begin;
s["end"] = shot.length; s["end"] = shot.length;
for(auto& [path, scene] : _path_to_scene) { for(auto& [path, scene] : path_to_scene) {
if(shot.scene == scene) if(shot.scene == scene)
s["scene"] = path; s["scene"] = path;
} }
@ -395,8 +395,8 @@ void engine::save_prefab(const Object root, const std::string_view path) {
nlohmann::json j; nlohmann::json j;
for(auto& obj : _current_scene->get_objects()) { for(auto& obj : current_scene->get_objects()) {
if(!_current_scene->get(obj).editor_object) if(!current_scene->get(obj).editor_object)
j["objects"].push_back(save_object(obj)); j["objects"].push_back(save_object(obj));
} }
@ -409,19 +409,19 @@ void engine::add_window(void* native_handle, const int identifier, const prism::
Expects(identifier >= 0); Expects(identifier >= 0);
if(identifier == 0) { if(identifier == 0) {
_renderer = std::make_unique<Renderer>(_gfx); renderer = std::make_unique<Renderer>(gfx);
} }
const auto drawable_extent = platform::get_window_drawable_size(identifier); const auto drawable_extent = platform::get_window_drawable_size(identifier);
_gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height); gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height);
Window* window = new Window(); Window* window = new Window();
_windows.push_back(window); windows.push_back(window);
window->identifier = identifier; window->identifier = identifier;
window->extent = extent; window->extent = extent;
window->render_target = _renderer->allocate_render_target(drawable_extent); window->render_target = renderer->allocate_render_target(drawable_extent);
render_ready = true; render_ready = true;
} }
@ -429,7 +429,7 @@ void engine::add_window(void* native_handle, const int identifier, const prism::
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) {
return w->identifier == identifier; return w->identifier == identifier;
}); });
} }
@ -445,13 +445,13 @@ void engine::resize(const int identifier, const prism::Extent extent) {
const auto drawable_extent = platform::get_window_drawable_size(identifier); const auto drawable_extent = platform::get_window_drawable_size(identifier);
_gfx->recreate_view(identifier, drawable_extent.width, drawable_extent.height); gfx->recreate_view(identifier, drawable_extent.width, drawable_extent.height);
_renderer->resize_render_target(*window->render_target, drawable_extent); renderer->resize_render_target(*window->render_target, drawable_extent);
if(identifier == 0) { if(identifier == 0) {
if(_current_screen != nullptr) { if(current_screen != nullptr) {
_current_screen->extent = extent; current_screen->extent = extent;
_current_screen->calculate_sizes(); current_screen->calculate_sizes();
} }
} }
} }
@ -459,7 +459,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);
if(keyCode == platform::get_keycode(debug_button) && !ImGui::GetIO().WantTextInput) if(keyCode == platform::get_keycode(debug_button) && !ImGui::GetIO().WantTextInput)
debug_enabled = !debug_enabled; debug_enabled = !debug_enabled;
@ -468,31 +468,31 @@ void engine::process_key_down(const unsigned int keyCode) {
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) {
@ -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;
} }
_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));
} }
} }
} }
@ -638,28 +638,28 @@ 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;
for(auto& channel : currentShot->channels) for(auto& channel : currentShot->channels)
update_animation_channel(*_current_scene, channel, time); update_animation_channel(*current_scene, channel, time);
} else { } else {
_current_scene = nullptr; current_scene = nullptr;
} }
} }
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)
draw_debug_ui(); draw_debug_ui();
if(_app != nullptr) if(app != nullptr)
_app->begin_frame(); app->begin_frame();
} }
void engine::end_frame() { void engine::end_frame() {
@ -690,8 +690,8 @@ void engine::update(const float delta_time) {
} }
} }
for(auto& timer : _timers) { for(auto& timer : timers) {
if(!_paused || (_paused && timer->continue_during_pause)) if(!paused || (paused && timer->continue_during_pause))
timer->current_time += delta_time; timer->current_time += delta_time;
if(timer->current_time >= timer->duration) { if(timer->current_time >= timer->duration) {
@ -700,35 +700,35 @@ void engine::update(const float delta_time) {
timer->current_time = 0.0f; timer->current_time = 0.0f;
if(timer->remove_on_trigger) if(timer->remove_on_trigger)
_timersToRemove.push_back(timer); timers_to_remove.push_back(timer);
} }
} }
for(auto& timer : _timersToRemove) for(auto& timer : timers_to_remove)
utility::erase(_timers, timer); utility::erase(timers, timer);
_timersToRemove.clear(); timers_to_remove.clear();
_input->update(); input->update();
_app->update(delta_time); app->update(delta_time);
if(_current_scene != nullptr) { if(current_scene != nullptr) {
if(update_physics && !_paused) if(update_physics && !paused)
_physics->update(delta_time); physics->update(delta_time);
if(cutscene != nullptr && play_cutscene && !_paused) { if(cutscene != nullptr && play_cutscene && !paused) {
update_cutscene(current_cutscene_time); update_cutscene(current_cutscene_time);
current_cutscene_time += delta_time; current_cutscene_time += delta_time;
} }
for(auto& target : _animation_targets) { for(auto& target : animation_targets) {
if((target.current_time * target.animation.ticks_per_second) > target.animation.duration) { if((target.current_time * target.animation.ticks_per_second) > target.animation.duration) {
if(target.looping) { if(target.looping) {
target.current_time = 0.0f; target.current_time = 0.0f;
} else { } else {
utility::erase(_animation_targets, target); utility::erase(animation_targets, target);
} }
} else { } else {
update_animation(target.animation, target.current_time * target.animation.ticks_per_second); update_animation(target.animation, target.current_time * target.animation.ticks_per_second);
@ -737,7 +737,7 @@ void engine::update(const float delta_time) {
} }
} }
update_scene(*_current_scene); update_scene(*current_scene);
} }
assetm->perform_cleanup(); assetm->perform_cleanup();
@ -757,46 +757,46 @@ void engine::render(const int index) {
if(window == nullptr) if(window == nullptr)
return; return;
GFXCommandBuffer* commandbuffer = _gfx->acquire_command_buffer(true); GFXCommandBuffer* commandbuffer = gfx->acquire_command_buffer(true);
if(index == 0) { if(index == 0) {
if(_current_screen != nullptr && _current_screen->view_changed) { if(current_screen != nullptr && current_screen->view_changed) {
_renderer->update_screen(); renderer->update_screen();
_current_screen->view_changed = false; current_screen->view_changed = false;
} }
_imgui->render(0); imgui->render(0);
_app->render(commandbuffer); app->render(commandbuffer);
} }
if(_renderer != nullptr) if(renderer != nullptr)
_renderer->render(commandbuffer, _app->wants_no_scene_rendering() ? nullptr : _current_scene, *window->render_target, index); renderer->render(commandbuffer, app->wants_no_scene_rendering() ? nullptr : current_scene, *window->render_target, 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;
} }
@ -806,13 +806,13 @@ std::string_view engine::get_scene_path() const {
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))
return; return;
AnimationTarget target; AnimationTarget target;
@ -821,31 +821,31 @@ void engine::play_animation(Animation animation, Object object, bool looping) {
target.looping = looping; target.looping = looping;
for(auto& channel : target.animation.channels) { for(auto& channel : target.animation.channels) {
for(auto& bone : _current_scene->get<Renderable>(object).mesh->bones) { for(auto& bone : current_scene->get<Renderable>(object).mesh->bones) {
if(channel.id == bone.name) if(channel.id == bone.name)
channel.bone = &bone; channel.bone = &bone;
} }
} }
_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) {
on_remove(obj); on_remove(obj);