Archived
1
Fork 0

Begin work on converting to the new class naming scheme and the new prism namespace

This commit is contained in:
redstrate 2021-04-19 12:06:44 -04:00
parent 2552398aff
commit 744123763f
15 changed files with 429 additions and 421 deletions

View file

@ -1,10 +1,12 @@
#pragma once
class Engine;
class GFXCommandBuffer;
namespace prism {
class Engine;
/// The base class for any Prism application.
class App {
class app {
public:
/// Called when a render context is available.
virtual void initialize_render() {}
@ -29,6 +31,7 @@ public:
virtual bool wants_no_scene_rendering() { return false; }
};
}
/// This is an app's equivalent main(). You can check command line arguments through Engine::comand_line_arguments.
void app_main(Engine* engine);
/// 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);

View file

@ -15,7 +15,6 @@ namespace ui {
class Screen;
}
class App;
class Scene;
class Input;
class Renderer;
@ -24,16 +23,19 @@ class Physics;
class ImGuiLayer;
struct Timer;
namespace prism {
class app;
struct AnimationTarget {
float current_time = 0.0f;
float animation_speed_modifier = 1.0f;
bool looping = false;
Object target;
Object target = NullObject;
Animation animation;
};
/// An object that contains glue between App and systems such as the Renderer.
/// The glue between app and systems such as the Renderer.
class Engine {
public:
/**
@ -42,7 +44,7 @@ public:
@param argc Numer of arguments. Can be null.
@param argv Array of strings containing arguments. Can be null.
*/
Engine(const int argc, char* argv[]);
Engine(int argc, char* argv[]);
Engine(const Engine& other) = delete;
Engine(Engine&& other) = delete;
@ -55,27 +57,27 @@ public:
/** Sets the app object.
@param app The app object to set. Must not be null.
*/
void set_app(App* app);
void set_app(app* app);
/** Gets the current app object
@return The current app object. Can be null.
*/
App* get_app() const;
[[nodiscard]] app* get_app() const;
/** Call to begin the next frame.
@param delta_time Delta time in seconds.
*/
void begin_frame(const float delta_time);
void begin_frame(float delta_time);
/** Call to start updating the current frame.
@param delta_time Delta time in seconds.
*/
void update(const float delta_time);
void update(float delta_time);
/** Call to begin rendering for a window.
@param index The index of the window to begin rendering for.
*/
void render(const int index);
void render(int index);
void end_frame();
@ -88,7 +90,7 @@ public:
/** Query the current pause state.
@return Whether or not the engine is currently paused.
*/
bool is_paused() const;
[[nodiscard]] bool is_paused() const;
/// Request to begin quitting immediately. This is not forced, and can be canceled by the user, platform, or app.
void quit();
@ -97,7 +99,7 @@ public:
void prepare_quit();
/// Query whether or not the engine is in the process of quitting.
bool is_quitting() const;
[[nodiscard]] bool is_quitting() const;
/** Set the GFX api to use.
@param gfx The GFX object to use. Must not be null.
@ -132,18 +134,18 @@ public:
@param path The scene file path.
@return Returns a instance of the scene is successful, and nullptr on failure.
*/
Scene* load_scene(const file::Path path);
Scene* load_scene(file::Path path);
/** Save the current scene to disk.
@param path The absolute file path.
*/
void save_scene(const std::string_view path);
void save_scene(std::string_view path);
/** Load a UI screen from disk. This will not change the current screen.
@param path The screen file path.
@return Returns a instance of the screen if successful, and nullptr on failure.
*/
ui::Screen* load_screen(const file::Path path);
ui::Screen* load_screen(file::Path path);
/** Set the current screen.
@param screen The screen object to set as current. Can be null.
@ -153,20 +155,20 @@ public:
/** Gets the current screen.
@return The current screen. Can be null.
*/
ui::Screen* get_screen() const;
[[nodiscard]] ui::Screen* get_screen() const;
/** Load a prefab from disk.
@param scene The scene to add the prefab to.
@param path The prefab file path.
@param override_name If not empty, the root object's new name. Defaulted to a empty string.
*/
Object add_prefab(Scene& scene, const file::Path path, const std::string_view override_name = "");
Object add_prefab(Scene& scene, file::Path path, std::string_view override_name = "");
/** Save a tree of objects as a prefab to disk.
@param root The parent object to save as a prefab.
@param path The absolue file path.
*/
void save_prefab(const Object root, const std::string_view path);
void save_prefab(Object root, std::string_view path);
/** Deserializes a animation channel from JSON.
@param j The animation channel json to deserialize.
@ -178,81 +180,81 @@ public:
@param path The animation file path.
@return An animation.
*/
Animation load_animation(const file::Path path);
Animation load_animation(file::Path path);
/** Load a cutscene from disk. This changes the current cutscene.
@param path The cutscene file path.
*/
void load_cutscene(const file::Path path);
void load_cutscene(file::Path path);
/** Saves the current cutscene to disk.
@param path The absolute file path.
*/
void save_cutscene(const std::string_view path);
void save_cutscene(std::string_view path);
/** Adds the window for engine management.
@param native_handle The platform's native handle to it's window equivalent.
@param identifier The identifier of the new window.
@param extent The extent of the window.
*/
void add_window(void* native_handle, const int identifier, const prism::Extent extent);
void add_window(void* native_handle, int identifier, prism::Extent extent);
/** Removes the window from engine management. Should be called before the window is actually closed.
@param identifier The identifier of the window to remove.
*/
void remove_window(const int identifier);
void remove_window(int identifier);
/** Called when the window has changed size.
@param identifier The window that has been resized.
@param extent The new extent of the window.
*/
void resize(const int identifier, const prism::Extent extent);
void resize(int identifier, prism::Extent extent);
/** Called when a key has been pressed.
@param keyCode A platform-specific key code.
@note Use platform::get_keycode to get a InputButton equivalent if needed.
@note This function is only intended for debug purposes and all production code should be using the Input system instead.
*/
void process_key_down(const unsigned int keyCode);
void process_key_down(unsigned int keyCode);
/** Called when a key has been released.
@param keyCode A platform-specific key code.
@note Use platform::get_keycode to get a InputButton equivalent if needed.
@note This function is only intended for debug purposes and all production code should be using the Input system instead.
*/
void process_key_up(const unsigned int keyCode);
void process_key_up(unsigned int keyCode);
/** Called when a mouse button has been clicked..
@param button The mouse button.
@param offset The mouse position relative to the window where the click occured.
@note This function is only intended for debug purposes and all production code should be using the Input system instead.
*/
void process_mouse_down(const int button, const prism::Offset offset);
void process_mouse_down(int button, prism::Offset offset);
/** Pushes a UI event for the current screen. Does nothing if there is no screen set.
@param name The name of the event.
@param data Data for the event. Defaulted to an empty string.
*/
void push_event(const std::string_view name, const std::string_view data = "");
void push_event(std::string_view name, std::string_view data = "");
/** Load a localization file from disk. This will change the current localization.
@param path The localization file path.
*/
void load_localization(const std::string_view path);
void load_localization(std::string_view path);
/** Queries whether or not the current localization loaded has a key.
@param id The key to query.
@return Whether or not the locale has the key specified.
@note Having no localization loaded will always return false.
*/
bool has_localization(const std::string_view id) const;
[[nodiscard]] bool has_localization(std::string_view id) const;
/** Localizes a string.
@param id The locale key to use.
@return A localized string if the key is found, or an empty string if not found.
@note Having no localization loaded will always return a empty string.
*/
std::string localize(const std::string id);
std::string localize(std::string id);
/** Adds a timer to the list of timers.
@param timer The timer to add.
@ -269,7 +271,7 @@ public:
@param name The path to the scene file.
@return Returns a scene if it was previously loaded and found, or nullptr on failure.
*/
Scene* get_scene(const std::string_view name);
Scene* get_scene(std::string_view name);
/** Set the current scene.
@param scene The scene to set. Can be null.
@ -279,7 +281,7 @@ public:
/** Get the current scene's path.
@return If a scene is loaded, the path to the scene. Can be an empty string if there is no scene loaded, or if it's an empty scene.
*/
std::string_view get_scene_path() const;
[[nodiscard]] std::string_view get_scene_path() const;
/** Updates the Transform hierarchy for a scene.
@param scene The scene to update.
@ -300,18 +302,18 @@ public:
@param object The animation's target.
@param looping Whether or not the animation should loop or be discarded when finished. Default is false.
*/
void play_animation(const Animation animation, const Object target, const bool looping = false);
void play_animation(Animation animation, Object target, bool looping = false);
/** Sets the animation speed of an object.
@param target The object you want to change the animation speed of.
@param modifier The speed to play the object's animations at. A modifier of 2.0 would be 2x the speed, and 0.5 would be 1/2x the speed.
*/
void set_animation_speed_modifier(const Object target, const float modifier);
void set_animation_speed_modifier(Object target, float modifier);
/** Stops all animation for an object.
@param target The object you want the animations to stop for.
*/
void stop_animation(const Object target);
void stop_animation(Object target);
/// If there is a render context available. If this is false, avoid doing any GFX or Renderer work as it could crash or cause undefined behavior.
bool render_ready = false;
@ -358,15 +360,15 @@ private:
}
void calculate_bone(Mesh& mesh, const Mesh::Part& part, Bone& bone, const Bone* parent_bone = nullptr);
void calculate_object(Scene& scene, Object object, const Object parent_object = NullObject);
void calculate_object(Scene& scene, Object object, Object parent_object = NullObject);
Shot* get_shot(const float time);
void update_animation(const Animation& anim, const float time);
void update_cutscene(const float time);
Shot* get_shot(float time);
void update_animation(const Animation& anim, float time);
void update_cutscene(float time);
void update_animation_channel(Scene& scene, const AnimationChannel& channel, const float time);
void update_animation_channel(Scene& scene, const AnimationChannel& channel, float time);
App* _app = nullptr;
app* _app = nullptr;
GFX* _gfx = nullptr;
std::unique_ptr<Input> _input;
@ -387,5 +389,6 @@ private:
inline bool operator==(const AnimationTarget& a1, const AnimationTarget& a2) {
return a1.current_time == a2.current_time;
}
}
inline Engine* engine = nullptr;
inline prism::Engine* engine = nullptr;

View file

@ -23,6 +23,8 @@
#include "shadowpass.hpp"
#include "scenecapture.hpp"
using prism::Engine;
Engine::Engine(const int argc, char* argv[]) {
console::info(System::Core, "Prism Engine loading...");
@ -47,13 +49,13 @@ Engine::Engine(const int argc, char* argv[]) {
Engine::~Engine() {}
void Engine::set_app(App* app) {
void Engine::set_app(app* app) {
Expects(app != nullptr);
_app = app;
}
App* Engine::get_app() const {
prism::app* Engine::get_app() const {
return _app;
}

View file

@ -1354,7 +1354,7 @@ void GFXVulkan::createInstance(std::vector<const char*> layers, std::vector<cons
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Prism Engine App";
appInfo.pApplicationName = "Prism Engine app";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "Prism Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);

View file

@ -2,7 +2,7 @@
#include "app.hpp"
class ExampleApp : public App {
class ExampleApp : public app {
public:
};

View file

@ -55,19 +55,19 @@ Index of this file:
// - sub section: ShowDemoWindowMisc()
// [SECTION] About Window / ShowAboutWindow()
// [SECTION] Style Editor / ShowStyleEditor()
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
// [SECTION] Example App: Constrained Resize / ShowExampleAppConstrainedResize()
// [SECTION] Example App: Simple Overlay / ShowExampleAppSimpleOverlay()
// [SECTION] Example App: Manipulating Window Titles / ShowExampleAppWindowTitles()
// [SECTION] Example App: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
// [SECTION] Example App: Docking, DockSpace / ShowExampleAppDockSpace()
// [SECTION] Example App: Documents Handling / ShowExampleAppDocuments()
// [SECTION] Example app: Main Menu Bar / ShowExampleAppMainMenuBar()
// [SECTION] Example app: Debug Console / ShowExampleAppConsole()
// [SECTION] Example app: Debug Log / ShowExampleAppLog()
// [SECTION] Example app: Simple Layout / ShowExampleAppLayout()
// [SECTION] Example app: Property Editor / ShowExampleAppPropertyEditor()
// [SECTION] Example app: Long Text / ShowExampleAppLongText()
// [SECTION] Example app: Auto Resize / ShowExampleAppAutoResize()
// [SECTION] Example app: Constrained Resize / ShowExampleAppConstrainedResize()
// [SECTION] Example app: Simple Overlay / ShowExampleAppSimpleOverlay()
// [SECTION] Example app: Manipulating Window Titles / ShowExampleAppWindowTitles()
// [SECTION] Example app: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
// [SECTION] Example app: Docking, DockSpace / ShowExampleAppDockSpace()
// [SECTION] Example app: Documents Handling / ShowExampleAppDocuments()
*/
@ -6100,7 +6100,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
// [SECTION] Example app: Main Menu Bar / ShowExampleAppMainMenuBar()
//-----------------------------------------------------------------------------
// - ShowExampleAppMainMenuBar()
// - ShowExampleMenuFile()
@ -6212,7 +6212,7 @@ static void ShowExampleMenuFile()
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
// [SECTION] Example app: Debug Console / ShowExampleAppConsole()
//-----------------------------------------------------------------------------
// Demonstrate creating a simple console window, with scrolling, filtering, completion and history.
@ -6570,7 +6570,7 @@ static void ShowExampleAppConsole(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
// [SECTION] Example app: Debug Log / ShowExampleAppLog()
//-----------------------------------------------------------------------------
// Usage:
@ -6728,7 +6728,7 @@ static void ShowExampleAppLog(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
// [SECTION] Example app: Simple Layout / ShowExampleAppLayout()
//-----------------------------------------------------------------------------
// Demonstrate create a window with multiple child windows.
@ -6793,7 +6793,7 @@ static void ShowExampleAppLayout(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
// [SECTION] Example app: Property Editor / ShowExampleAppPropertyEditor()
//-----------------------------------------------------------------------------
static void ShowPlaceholderObject(const char* prefix, int uid)
@ -6875,7 +6875,7 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
// [SECTION] Example app: Long Text / ShowExampleAppLongText()
//-----------------------------------------------------------------------------
// Demonstrate/test rendering huge amount of text, and the incidence of clipping.
@ -6937,7 +6937,7 @@ static void ShowExampleAppLongText(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
// [SECTION] Example app: Auto Resize / ShowExampleAppAutoResize()
//-----------------------------------------------------------------------------
// Demonstrate creating a window which gets auto-resized according to its content.
@ -6961,7 +6961,7 @@ static void ShowExampleAppAutoResize(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Constrained Resize / ShowExampleAppConstrainedResize()
// [SECTION] Example app: Constrained Resize / ShowExampleAppConstrainedResize()
//-----------------------------------------------------------------------------
// Demonstrate creating a window with custom resize constraints.
@ -7016,7 +7016,7 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Simple Overlay / ShowExampleAppSimpleOverlay()
// [SECTION] Example app: Simple Overlay / ShowExampleAppSimpleOverlay()
//-----------------------------------------------------------------------------
// Demonstrate creating a simple static window with no decoration
@ -7063,7 +7063,7 @@ static void ShowExampleAppSimpleOverlay(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Manipulating Window Titles / ShowExampleAppWindowTitles()
// [SECTION] Example app: Manipulating Window Titles / ShowExampleAppWindowTitles()
//-----------------------------------------------------------------------------
// Demonstrate using "##" and "###" in identifiers to manipulate ID generation.
@ -7095,7 +7095,7 @@ static void ShowExampleAppWindowTitles(bool*)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
// [SECTION] Example app: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
//-----------------------------------------------------------------------------
// Demonstrate using the low-level ImDrawList to draw custom shapes.
@ -7337,7 +7337,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Docking, DockSpace / ShowExampleAppDockSpace()
// [SECTION] Example app: Docking, DockSpace / ShowExampleAppDockSpace()
//-----------------------------------------------------------------------------
// Demonstrate using DockSpace() to create an explicit docking node within an existing window.
@ -7453,7 +7453,7 @@ void ShowExampleAppDockSpace(bool* p_open)
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Documents Handling / ShowExampleAppDocuments()
// [SECTION] Example app: Documents Handling / ShowExampleAppDocuments()
//-----------------------------------------------------------------------------
// Simplified structure to mimic a Document model

View file

@ -127,7 +127,7 @@ int drawable_width, drawable_height;
drawable_width = [view frame].size.width * [view contentScaleFactor];
drawable_height = [view frame].size.height * [view contentScaleFactor];
engine = new Engine(0, nullptr);
engine = new prism::Engine(0, nullptr);
app = new @APP_CLASS@();
engine->set_app(app);

View file

@ -294,7 +294,7 @@ int main(int argc, char* argv[]) {
xcb_screen_next(&iter);
screen = iter.data;
engine = new Engine(argc, argv);
engine = new prism::Engine(argc, argv);
app = new @APP_CLASS@();
engine->set_app(app);

View file

@ -496,7 +496,7 @@ int main(int argc, char* argv[]) {
NSApp = [NSApplication sharedApplication];
engine = new Engine(argc, argv);
engine = new prism::Engine(argc, argv);
app = new @APP_CLASS@();
engine->set_app(app);

View file

@ -178,7 +178,7 @@ void platform::unmute_output() {
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
engine = new Engine(argc, argv);
engine = new prism::Engine(argc, argv);
app = new @APP_CLASS@();
engine->set_app(app);

View file

@ -98,7 +98,7 @@ int drawable_width, drawable_height;
drawable_width = [view frame].size.width * [view contentScaleFactor];
drawable_height = [view frame].size.height * [view contentScaleFactor];
engine = new Engine(0, nullptr);
engine = new prism::Engine(0, nullptr);
app = new @APP_CLASS@();
engine->set_app(app);

View file

@ -144,7 +144,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow
instance = hInstance;
cmdShow = nCmdShow;
engine = new Engine(0, nullptr);
engine = new prism::Engine(0, nullptr);
ginterface = new GFXVulkan();
if(ginterface->initialize(GFXCreateInfo())) {

View file

@ -102,7 +102,7 @@ AssetType get_asset_type() {
constexpr int thumbnail_resolution = 256;
class CommonEditor : public App {
class CommonEditor : public prism::app {
public:
CommonEditor(std::string id);

View file

@ -49,7 +49,7 @@ const std::map<ImGuiKey, InputButton> imToPl = {
CommonEditor::CommonEditor(std::string id) : id(id) {
#ifdef PLATFORM_MACOS
file::set_domain_path(file::Domain::App, "../../../data");
file::set_domain_path(file::Domain::app, "../../../data");
#else
file::set_domain_path(file::Domain::App, "data");
#endif

View file

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