Archived
1
Fork 0

Reformat core module

This commit is contained in:
Joshua Goins 2022-08-15 11:04:11 -04:00
parent 924d60e99b
commit 100e1d7434
20 changed files with 702 additions and 662 deletions

View file

@ -29,10 +29,15 @@ namespace prism {
virtual void render([[maybe_unused]] GFXCommandBuffer* command_buffer) {} virtual void render([[maybe_unused]] GFXCommandBuffer* command_buffer) {}
virtual bool wants_no_scene_rendering() { return false; } virtual bool wants_no_scene_rendering() {
virtual bool is_multimodal() { return false; } return false;
};
} }
virtual bool is_multimodal() {
return false;
}
};
} // 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

@ -3,9 +3,9 @@
#include <vector> #include <vector>
#include "assetptr.hpp" #include "assetptr.hpp"
#include "matrix.hpp"
#include "object.hpp" #include "object.hpp"
#include "quaternion.hpp" #include "quaternion.hpp"
#include "matrix.hpp"
class btCollisionShape; class btCollisionShape;
class btRigidBody; class btRigidBody;
@ -63,11 +63,7 @@ struct Transform {
Matrix4x4 model; Matrix4x4 model;
[[nodiscard]] prism::float3 get_world_position() const { [[nodiscard]] prism::float3 get_world_position() const {
return { return {model[3][0], model[3][1], model[3][2]};
model[3][0],
model[3][1],
model[3][2]
};
} }
}; };

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <string_view>
#include <functional> #include <functional>
#include <vector>
#include <variant>
#include <string> #include <string>
#include <string_view>
#include <variant>
#include <vector>
#include "path.hpp" #include "path.hpp"
@ -59,8 +59,7 @@ namespace prism::console {
void load_cfg(const prism::path& path); void load_cfg(const prism::path& path);
void void register_command(std::string_view name, argument_format expected_format, function_ptr function);
register_command(std::string_view name, argument_format expected_format, function_ptr function);
void invoke_command(std::string_view name, arguments arguments); void invoke_command(std::string_view name, arguments arguments);
@ -70,4 +69,4 @@ namespace prism::console {
void register_variable(std::string_view name, float& variable); void register_variable(std::string_view name, float& variable);
void register_variable(std::string_view name, int& variable); void register_variable(std::string_view name, int& variable);
void register_variable(std::string_view name, double& variable); void register_variable(std::string_view name, double& variable);
} } // namespace prism::console

View file

@ -2,10 +2,10 @@
#include <vector> #include <vector>
#include "vector.hpp"
#include "quaternion.hpp"
#include "math.hpp" #include "math.hpp"
#include "object.hpp" #include "object.hpp"
#include "quaternion.hpp"
#include "vector.hpp"
struct PositionKeyFrame { struct PositionKeyFrame {
float time; float time;
@ -73,7 +73,6 @@ public:
for (auto& shot : shots) { for (auto& shot : shots) {
if ((shot.begin + shot.length) >= end) if ((shot.begin + shot.length) >= end)
end = shot.begin + shot.length; end = shot.begin + shot.length;
} }
return end; return end;

View file

@ -2,12 +2,12 @@
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
#include "object.hpp"
#include "cutscene.hpp"
#include "common.hpp"
#include "asset_types.hpp" #include "asset_types.hpp"
#include "platform.hpp" #include "common.hpp"
#include "cutscene.hpp"
#include "object.hpp"
#include "path.hpp" #include "path.hpp"
#include "platform.hpp"
class GFX; class GFX;
class Scene; class Scene;
@ -87,10 +87,12 @@ namespace prism {
*/ */
[[nodiscard]] 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. /// Request to begin quitting immediately. This is not forced, and can be canceled by the user, platform, or
/// app.
void quit(); void quit();
/// Call right before the platform is about to quit the application, and requests the app or other systems to save work. /// Call right before the platform is about to quit the application, and requests the app or other systems to
/// save work.
void prepare_quit(); void prepare_quit();
/// Query whether or not the engine is in the process of quitting. /// Query whether or not the engine is in the process of quitting.
@ -203,21 +205,24 @@ namespace prism {
/** Called when a key has been pressed. /** Called when a key has been pressed.
@param keyCode A platform-specific key code. @param keyCode A platform-specific key code.
@note Use platform::get_keycode to get a InputButton equivalent if needed. @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. @note This function is only intended for debug purposes and all production code should be using the Input
system instead.
*/ */
void process_key_down(unsigned int keyCode); void process_key_down(unsigned int keyCode);
/** Called when a key has been released. /** Called when a key has been released.
@param keyCode A platform-specific key code. @param keyCode A platform-specific key code.
@note Use platform::get_keycode to get a InputButton equivalent if needed. @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. @note This function is only intended for debug purposes and all production code should be using the Input
system instead.
*/ */
void process_key_up(unsigned int keyCode); void process_key_up(unsigned int keyCode);
/** Called when a mouse button has been clicked.. /** Called when a mouse button has been clicked..
@param button The mouse button. @param button The mouse button.
@param offset The mouse position relative to the window where the click occured. @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. @note This function is only intended for debug purposes and all production code should be using the Input
system instead.
*/ */
void process_mouse_down(int button, prism::Offset offset); void process_mouse_down(int button, prism::Offset offset);
@ -229,7 +234,8 @@ namespace prism {
/** Adds a timer to the list of timers. /** Adds a timer to the list of timers.
@param timer The timer to add. @param timer The timer to add.
@note The timer instance is passed by reference. Use this to keep track of your timers without having to query it's state back. @note The timer instance is passed by reference. Use this to keep track of your timers without having to query
it's state back.
*/ */
void add_timer(Timer& timer); void add_timer(Timer& timer);
@ -250,7 +256,8 @@ namespace prism {
void set_current_scene(Scene* scene); void set_current_scene(Scene* scene);
/** Get the current scene's path. /** 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. @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.
*/ */
[[nodiscard]] std::string_view get_scene_path() const; [[nodiscard]] std::string_view get_scene_path() const;
@ -281,7 +288,8 @@ namespace prism {
/** Sets the animation speed of an object. /** Sets the animation speed of an object.
@param target The object you want to change the animation speed of. @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. @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(Object target, float modifier); void set_animation_speed_modifier(Object target, float modifier);
@ -290,7 +298,8 @@ namespace prism {
*/ */
void stop_animation(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. /// 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; bool render_ready = false;
/// If physics should upate. This is a control indepentent of the pause state. /// If physics should upate. This is a control indepentent of the pause state.
@ -366,6 +375,6 @@ namespace prism {
inline bool operator==(const AnimationTarget& a1, const AnimationTarget& a2) { inline bool operator==(const AnimationTarget& a1, const AnimationTarget& a2) {
return a1.current_time == a2.current_time; return a1.current_time == a2.current_time;
} }
} } // namespace prism
inline prism::engine* engine = nullptr; inline prism::engine* engine = nullptr;

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <string_view>
#include <filesystem> #include <filesystem>
#include <functional> #include <functional>
#include <string_view>
#include "platform.hpp" #include "platform.hpp"
@ -27,13 +27,15 @@ namespace prism {
/**Opens a file dialog to select a file. This will not block. /**Opens a file dialog to select a file. This will not block.
@param existing Whether or not to limit to existing files. @param existing Whether or not to limit to existing files.
@param returnFunction The callback function when a file is selected or the dialog is cancelled. An empy string is returned when cancelled. @param returnFunction The callback function when a file is selected or the dialog is cancelled. An empy string
is returned when cancelled.
@param openDirectory Whether or not to allow selecting directories as well. @param openDirectory Whether or not to allow selecting directories as well.
*/ */
void open_dialog(bool existing, std::function<void(std::string)> returnFunction, bool openDirectory = false); void open_dialog(bool existing, std::function<void(std::string)> returnFunction, bool openDirectory = false);
/**Opens a file dialog to select a save location for a file. This will not block. /**Opens a file dialog to select a save location for a file. This will not block.
@param returnFunction The callback function when a file is selected or the dialog is cancelled. An empy string is returned when cancelled. @param returnFunction The callback function when a file is selected or the dialog is cancelled. An empy string
is returned when cancelled.
*/ */
void save_dialog(std::function<void(std::string)> returnFunction); void save_dialog(std::function<void(std::string)> returnFunction);
@ -53,4 +55,4 @@ namespace prism {
dialog_data open_dialog_data; dialog_data open_dialog_data;
dialog_data save_dialog_data; dialog_data save_dialog_data;
}; };
} } // namespace prism

View file

@ -2,12 +2,11 @@
#include <imgui.h> #include <imgui.h>
#include "utility.hpp"
#include "math.hpp" #include "math.hpp"
#include "utility.hpp"
namespace ImGui { namespace ImGui {
template<typename T> template<typename T> inline bool ComboEnum(const char* label, T* t) {
inline bool ComboEnum(const char* label, T* t) {
bool result = false; bool result = false;
const auto preview_value = utility::enum_to_string(*t); const auto preview_value = utility::enum_to_string(*t);
@ -28,8 +27,7 @@ namespace ImGui {
return result; return result;
} }
template<typename T, typename TMax> template<typename T, typename TMax> void ProgressBar(const char* label, const T value, const TMax max) {
void ProgressBar(const char* label, const T value, const TMax max) {
const float progress_saturated = value / static_cast<float>(max); const float progress_saturated = value / static_cast<float>(max);
char buf[32] = {}; char buf[32] = {};
@ -61,4 +59,4 @@ namespace ImGui {
return result; return result;
} }
} } // namespace ImGui

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <vector>
#include <map> #include <map>
#include <vector>
#include "platform.hpp" #include "platform.hpp"
@ -67,14 +67,17 @@ namespace prism {
/** Gets whether or not the binding is pressed. /** Gets whether or not the binding is pressed.
@param name The binding name. @param name The binding name.
@param repeating If true, return a correct value regardless if it was identical for multiple frames. If false, any continued input past the first frame of being pressed is ignored and the input is considered released. @param repeating If true, return a correct value regardless if it was identical for multiple frames. If false,
@return If the binding is found, return true if the binding value is 1.0. If no binding is found or if the binding has continued pressing and repeating is turned off, returns false. any continued input past the first frame of being pressed is ignored and the input is considered released.
@return If the binding is found, return true if the binding value is 1.0. If no binding is found or if the
binding has continued pressing and repeating is turned off, returns false.
*/ */
bool is_pressed(const std::string& name, bool repeating = false); bool is_pressed(const std::string& name, bool repeating = false);
/** Queries if the binding is repeating it's input. /** Queries if the binding is repeating it's input.
@param name The binding name. @param name The binding name.
@return If the binding is found, returns true if the binding's values have been identical for multiple frames. Returns false if the binding is not found. @return If the binding is found, returns true if the binding's values have been identical for multiple frames.
Returns false if the binding is not found.
*/ */
bool is_repeating(const std::string& name); bool is_repeating(const std::string& name);
@ -93,4 +96,4 @@ namespace prism {
bool _in_text_input = false; bool _in_text_input = false;
}; };
} } // namespace prism

View file

@ -5,4 +5,4 @@
namespace prism { namespace prism {
using Object = uint64_t; using Object = uint64_t;
constexpr Object NullObject = 0; constexpr Object NullObject = 0;
} } // namespace prism

View file

@ -2,8 +2,8 @@
#include <memory> #include <memory>
#include "vector.hpp"
#include "object.hpp" #include "object.hpp"
#include "vector.hpp"
class btBroadphaseInterface; class btBroadphaseInterface;
class btDefaultCollisionConfiguration; class btDefaultCollisionConfiguration;

View file

@ -1,18 +1,16 @@
#pragma once #pragma once
#include <unordered_map>
#include <nlohmann/json_fwd.hpp>
#include <functional> #include <functional>
#include <nlohmann/json_fwd.hpp>
#include <unordered_map>
#include "object.hpp"
#include "components.hpp" #include "components.hpp"
#include "object.hpp"
#include "utility.hpp" #include "utility.hpp"
template<class Component> template<class Component> using Pool = std::unordered_map<prism::Object, Component>;
using Pool = std::unordered_map<prism::Object, Component>;
template<class... Components> template<class... Components> class ObjectComponents : Pool<Components>... {
class ObjectComponents : Pool<Components>... {
public: public:
/** Adds a new object. /** Adds a new object.
@param parent The object to parent the new object to. Default is null. @param parent The object to parent the new object to. Default is null.
@ -95,32 +93,27 @@ public:
} }
/// Adds a component. /// Adds a component.
template<class Component> template<class Component> Component& add(const prism::Object object) {
Component& add(const prism::Object object) {
return Pool<Component>::emplace(object, Component()).first->second; return Pool<Component>::emplace(object, Component()).first->second;
} }
/// Returns a component. /// Returns a component.
template<class Component = Data> template<class Component = Data> Component& get(const prism::Object object) {
Component& get(const prism::Object object) {
return Pool<Component>::at(object); return Pool<Component>::at(object);
} }
/// Returns a component. /// Returns a component.
template<class Component = Data> template<class Component = Data> Component get(const prism::Object object) const {
Component get(const prism::Object object) const {
return Pool<Component>::at(object); return Pool<Component>::at(object);
} }
/// Checks whether or not an object has a certain component. /// Checks whether or not an object has a certain component.
template<class Component> template<class Component> [[nodiscard]] bool has(const prism::Object object) const {
[[nodiscard]] bool has(const prism::Object object) const {
return Pool<Component>::count(object); return Pool<Component>::count(object);
} }
/// Removes a component from an object. Is a no-op if the component wasn't attached. /// Removes a component from an object. Is a no-op if the component wasn't attached.
template<class Component> template<class Component> bool remove(const prism::Object object) {
bool remove(const prism::Object object) {
if (has<Component>(object)) { if (has<Component>(object)) {
Pool<Component>::erase(object); Pool<Component>::erase(object);
return true; return true;
@ -130,8 +123,7 @@ public:
} }
/// Returns all instances of a component. /// Returns all instances of a component.
template<class Component> template<class Component> std::vector<std::tuple<prism::Object, Component&>> get_all() {
std::vector<std::tuple<prism::Object, Component&>> get_all() {
std::vector<std::tuple<prism::Object, Component&>> comps; std::vector<std::tuple<prism::Object, Component&>> comps;
for (auto it = Pool<Component>::begin(); it != Pool<Component>::end(); it++) for (auto it = Pool<Component>::begin(); it != Pool<Component>::end(); it++)
@ -172,8 +164,7 @@ private:
check_prefab_parent(get(obj).parent, p); check_prefab_parent(get(obj).parent, p);
} }
template<class Component> template<class Component> void add_duplicate_component(const prism::Object from, const prism::Object to) {
void add_duplicate_component(const prism::Object from, const prism::Object to) {
if (Pool<Component>::count(from)) if (Pool<Component>::count(from))
Pool<Component>::emplace(to, Pool<Component>::at(from)); Pool<Component>::emplace(to, Pool<Component>::at(from));
} }
@ -201,12 +192,14 @@ class GFXFramebuffer;
class GFXTexture; class GFXTexture;
/// Represents a scene consisting of Objects with varying Components. /// Represents a scene consisting of Objects with varying Components.
class Scene : public ObjectComponents<Data, Transform, Renderable, Light, Camera, Collision, Rigidbody, EnvironmentProbe> { class Scene
: public ObjectComponents<Data, Transform, Renderable, Light, Camera, Collision, Rigidbody, EnvironmentProbe> {
public: public:
/// If loaded from disk, the path to the scene file this originated from. /// If loaded from disk, the path to the scene file this originated from.
std::string path; std::string path;
/// Invalidates the current shadow data for all shadowed lights. This may cause stuttering while the data is regenerated. /// Invalidates the current shadow data for all shadowed lights. This may cause stuttering while the data is
/// regenerated.
void reset_shadows() { void reset_shadows() {
sun_light_dirty = true; sun_light_dirty = true;
@ -251,7 +244,8 @@ public:
@param cam The camera object. @param cam The camera object.
@param pos The position the camera will be viewing the target from. @param pos The position the camera will be viewing the target from.
@param target The position to be centered in the camera's view. @param target The position to be centered in the camera's view.
@note Although this is a look at function, it applies no special attribute to the camera and simply changes it's position and rotation. @note Although this is a look at function, it applies no special attribute to the camera and simply changes it's
position and rotation.
*/ */
void camera_look_at(Scene& scene, prism::Object cam, prism::float3 pos, prism::float3 target); void camera_look_at(Scene& scene, prism::Object cam, prism::float3 pos, prism::float3 target);

View file

@ -1,15 +1,16 @@
#include "console.hpp" #include "console.hpp"
#include <unordered_map>
#include <string>
#include <optional> #include <optional>
#include <string>
#include <unordered_map>
#include "file.hpp"
#include "log.hpp" #include "log.hpp"
#include "string_utils.hpp" #include "string_utils.hpp"
#include "file.hpp"
struct registered_command { struct registered_command {
registered_command(const prism::console::argument_format format, const prism::console::function_ptr function) : expected_format(format), function(function) {} registered_command(const prism::console::argument_format format, const prism::console::function_ptr function)
: expected_format(format), function(function) {}
prism::console::argument_format expected_format; prism::console::argument_format expected_format;
std::function<void(prism::console::arguments)> function; std::function<void(prism::console::arguments)> function;
@ -19,8 +20,11 @@ static std::unordered_map<std::string, registered_command> registered_commands;
struct RegisteredVariable { struct RegisteredVariable {
RegisteredVariable(bool& data) : type(prism::console::argument_type::Boolean), data(&data) {} RegisteredVariable(bool& data) : type(prism::console::argument_type::Boolean), data(&data) {}
RegisteredVariable(float& data) : type(prism::console::argument_type::Float), data(&data) {} RegisteredVariable(float& data) : type(prism::console::argument_type::Float), data(&data) {}
RegisteredVariable(int& data) : type(prism::console::argument_type::Integer), data(&data) {} RegisteredVariable(int& data) : type(prism::console::argument_type::Integer), data(&data) {}
RegisteredVariable(double& data) : type(prism::console::argument_type::Double), data(&data) {} RegisteredVariable(double& data) : type(prism::console::argument_type::Double), data(&data) {}
prism::console::argument_type type; prism::console::argument_type type;
@ -38,7 +42,10 @@ void prism::console::load_cfg(const prism::path& path) {
} }
} }
void prism::console::register_command(const std::string_view name, const prism::console::argument_format expected_format, const prism::console::function_ptr function) { void prism::console::register_command(
const std::string_view name,
const prism::console::argument_format expected_format,
const prism::console::function_ptr function) {
registered_commands.try_emplace(name.data(), registered_command(expected_format, function)); registered_commands.try_emplace(name.data(), registered_command(expected_format, function));
} }

View file

@ -3,17 +3,17 @@
#include <imgui.h> #include <imgui.h>
#include <imgui_stdlib.h> #include <imgui_stdlib.h>
#include "engine.hpp"
#include "shadowpass.hpp"
#include "scenecapture.hpp"
#include "gfx.hpp"
#include "asset.hpp" #include "asset.hpp"
#include "imgui_utility.hpp"
#include "scene.hpp"
#include "renderer.hpp"
#include "file.hpp"
#include "console.hpp" #include "console.hpp"
#include "engine.hpp"
#include "file.hpp"
#include "gfx.hpp"
#include "imgui_backend.hpp" #include "imgui_backend.hpp"
#include "imgui_utility.hpp"
#include "renderer.hpp"
#include "scene.hpp"
#include "scenecapture.hpp"
#include "shadowpass.hpp"
struct Options { struct Options {
std::string shader_source_path; std::string shader_source_path;
@ -174,8 +174,7 @@ void draw_renderer() {
ImGui::Checkbox("Enable Dynamic Resolution", &render_options.dynamic_resolution); ImGui::Checkbox("Enable Dynamic Resolution", &render_options.dynamic_resolution);
float render_scale = render_options.render_scale; float render_scale = render_options.render_scale;
if (ImGui::DragFloat("Render Scale", &render_scale, 0.1f, 1.0f, 0.1f) if (ImGui::DragFloat("Render Scale", &render_scale, 0.1f, 1.0f, 0.1f) && render_scale > 0.0f) {
&& render_scale > 0.0f) {
render_options.render_scale = render_scale; render_options.render_scale = render_scale;
engine->get_renderer()->recreate_all_render_targets(); engine->get_renderer()->recreate_all_render_targets();
} }
@ -236,7 +235,8 @@ void draw_shader_editor() {
prism::path shader_path = prism::path(selected_shader); prism::path shader_path = prism::path(selected_shader);
auto file = prism::open_file(base_shader_path / shader_path.replace_extension(shader_path.extension().string() + ".glsl")); auto file = prism::open_file(
base_shader_path / shader_path.replace_extension(shader_path.extension().string() + ".glsl"));
loaded_shader_string = file->read_as_string(); loaded_shader_string = file->read_as_string();
} }

View file

@ -1,27 +1,27 @@
#include "engine.hpp" #include "engine.hpp"
#include <imgui.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <utility> #include <utility>
#include <imgui.h>
#include "scene.hpp"
#include "console.hpp"
#include "log.hpp"
#include "asset.hpp"
#include "json_conversions.hpp"
#include "app.hpp" #include "app.hpp"
#include "assertions.hpp" #include "assertions.hpp"
#include "renderer.hpp" #include "asset.hpp"
#include "console.hpp"
#include "debug.hpp"
#include "gfx.hpp" #include "gfx.hpp"
#include "imgui_backend.hpp" #include "imgui_backend.hpp"
#include "debug.hpp"
#include "timer.hpp"
#include "physics.hpp"
#include "input.hpp" #include "input.hpp"
#include "json_conversions.hpp"
#include "log.hpp"
#include "physics.hpp"
#include "renderer.hpp"
#include "scene.hpp"
#include "timer.hpp"
// TODO: remove these in the future // TODO: remove these in the future
#include "shadowpass.hpp"
#include "scenecapture.hpp" #include "scenecapture.hpp"
#include "shadowpass.hpp"
using prism::engine; using prism::engine;
@ -530,11 +530,14 @@ void engine::calculate_object(Scene& scene, Object object, const Object parent_o
mesh.temp_bone_data.resize(mesh.mesh->bones.size()); mesh.temp_bone_data.resize(mesh.mesh->bones.size());
for (auto& part : mesh.mesh->parts) { for (auto& part : mesh.mesh->parts) {
if(scene.get(object).parent != NullObject && scene.has<Renderable>(scene.get(object).parent) && !scene.get<Renderable>(scene.get(object).parent).mesh->bones.empty()) { if (scene.get(object).parent != NullObject && scene.has<Renderable>(scene.get(object).parent) &&
!scene.get<Renderable>(scene.get(object).parent).mesh->bones.empty()) {
for (auto [i, ourBone] : utility::enumerate(mesh.mesh->bones)) { for (auto [i, ourBone] : utility::enumerate(mesh.mesh->bones)) {
for (auto& theirBone : scene.get<Renderable>(scene.get(object).parent).mesh->bones) { for (auto& theirBone : scene.get<Renderable>(scene.get(object).parent).mesh->bones) {
if (ourBone.name == theirBone.name) if (ourBone.name == theirBone.name)
mesh.temp_bone_data[i] = mesh.mesh->global_inverse_transformation * theirBone.local_transform * part.offset_matrices[ourBone.index]; mesh.temp_bone_data[i] = mesh.mesh->global_inverse_transformation *
theirBone.local_transform *
part.offset_matrices[ourBone.index];
} }
} }
} else { } else {
@ -544,7 +547,11 @@ 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));
} }
} }
} }
@ -591,7 +598,10 @@ void engine::update_animation_channel(Scene& scene, const AnimationChannel& chan
auto& endFrame = channel.positions[endFrameIndex]; auto& endFrame = channel.positions[endFrameIndex];
if (targetVec != nullptr) if (targetVec != nullptr)
*targetVec = lerp(startFrame.value, endFrame.value, (float)(time - startFrame.time) / (float)(endFrame.time - startFrame.time)); *targetVec = lerp(
startFrame.value,
endFrame.value,
(float)(time - startFrame.time) / (float)(endFrame.time - startFrame.time));
} }
} }
} }
@ -621,7 +631,10 @@ void engine::update_animation_channel(Scene& scene, const AnimationChannel& chan
auto& endFrame = channel.rotations[endFrameIndex]; auto& endFrame = channel.rotations[endFrameIndex];
if (targetVec != nullptr) if (targetVec != nullptr)
*targetVec = lerp(startFrame.value, endFrame.value, (float)(time - startFrame.time) / (float)(endFrame.time - startFrame.time)); *targetVec = lerp(
startFrame.value,
endFrame.value,
(float)(time - startFrame.time) / (float)(endFrame.time - startFrame.time));
} }
} }
} }
@ -761,7 +774,11 @@ void engine::render(const platform::window_ptr index) {
} }
if (current_renderer != nullptr) if (current_renderer != nullptr)
current_renderer->render(commandbuffer, current_app->wants_no_scene_rendering() ? nullptr : current_scene, *window->render_target, index); current_renderer->render(
commandbuffer,
current_app->wants_no_scene_rendering() ? nullptr : current_scene,
*window->render_target,
index);
gfx->submit(commandbuffer, index); gfx->submit(commandbuffer, index);
} }

View file

@ -2,8 +2,8 @@
#include <cstdio> #include <cstdio>
#include "log.hpp"
#include "assertions.hpp" #include "assertions.hpp"
#include "log.hpp"
prism::path prism::root_path(const path& path) { prism::path prism::root_path(const path& path) {
auto p = path; auto p = path;

View file

@ -3,11 +3,11 @@
#include <imgui.h> #include <imgui.h>
#include <imgui_stdlib.h> #include <imgui_stdlib.h>
#include "engine.hpp"
#include "platform.hpp"
#include "assertions.hpp"
#include "input.hpp"
#include "app.hpp" #include "app.hpp"
#include "assertions.hpp"
#include "engine.hpp"
#include "input.hpp"
#include "platform.hpp"
using prism::imgui_backend; using prism::imgui_backend;
@ -32,8 +32,7 @@ const std::map<ImGuiKey, InputButton> imToPl = {
{ImGuiKey_V, InputButton::V}, {ImGuiKey_V, InputButton::V},
{ImGuiKey_X, InputButton::X}, {ImGuiKey_X, InputButton::X},
{ImGuiKey_Y, InputButton::Y}, {ImGuiKey_Y, InputButton::Y},
{ImGuiKey_Z, InputButton::Z} {ImGuiKey_Z, InputButton::Z}};
};
imgui_backend::imgui_backend() { imgui_backend::imgui_backend() {
ImGui::CreateContext(); ImGui::CreateContext();
@ -53,8 +52,7 @@ imgui_backend::imgui_backend() {
case PlatformTheme::Light: case PlatformTheme::Light:
ImGui::StyleColorsLight(); ImGui::StyleColorsLight();
break; break;
case PlatformTheme::Dark: case PlatformTheme::Dark: {
{
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
auto& style = ImGui::GetStyle(); auto& style = ImGui::GetStyle();
@ -88,8 +86,7 @@ imgui_backend::imgui_backend() {
colors[ImGuiCol_Tab] = ImVec4(0.22f, 0.27f, 0.33f, 0.86f); colors[ImGuiCol_Tab] = ImVec4(0.22f, 0.27f, 0.33f, 0.86f);
colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.51f, 0.75f, 1.00f); colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.51f, 0.75f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.30f, 0.33f, 0.38f, 1.00f); colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.30f, 0.33f, 0.38f, 1.00f);
} } break;
break;
} }
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
@ -109,7 +106,8 @@ imgui_backend::imgui_backend() {
platform_io.Monitors.push_back(monitor); platform_io.Monitors.push_back(monitor);
platform_io.Platform_CreateWindow = [](ImGuiViewport* viewport) { platform_io.Platform_CreateWindow = [](ImGuiViewport* viewport) {
viewport->PlatformHandle = platform::open_window("", {viewport->Pos, viewport->Size}, WindowFlags::Borderless | WindowFlags::Hidden); viewport->PlatformHandle =
platform::open_window("", {viewport->Pos, viewport->Size}, WindowFlags::Borderless | WindowFlags::Hidden);
}; };
platform_io.Platform_DestroyWindow = [](ImGuiViewport* viewport) { platform_io.Platform_DestroyWindow = [](ImGuiViewport* viewport) {
@ -184,7 +182,8 @@ void imgui_backend::begin_frame(const float delta_time) {
const auto drawableSize = platform::get_window_drawable_size(::engine->get_main_window()); const auto drawableSize = platform::get_window_drawable_size(::engine->get_main_window());
io.DisplaySize = size; io.DisplaySize = size;
io.DisplayFramebufferScale = ImVec2(static_cast<float>(drawableSize.width) / static_cast<float>(size.width), io.DisplayFramebufferScale = ImVec2(
static_cast<float>(drawableSize.width) / static_cast<float>(size.width),
static_cast<float>(drawableSize.height) / static_cast<float>(size.height)); static_cast<float>(drawableSize.height) / static_cast<float>(size.height));
io.DeltaTime = delta_time; io.DeltaTime = delta_time;
io.KeyCtrl = platform::get_key_down(InputButton::Ctrl); io.KeyCtrl = platform::get_key_down(InputButton::Ctrl);
@ -234,7 +233,10 @@ void imgui_backend::begin_frame(const float delta_time) {
} }
for (const auto& dir_ent : std::filesystem::directory_iterator(data.current_path)) { for (const auto& dir_ent : std::filesystem::directory_iterator(data.current_path)) {
if(ImGui::Selectable(dir_ent.path().string().c_str(), data.selected_path == dir_ent.path(), ImGuiSelectableFlags_DontClosePopups)) { if (ImGui::Selectable(
dir_ent.path().string().c_str(),
data.selected_path == dir_ent.path(),
ImGuiSelectableFlags_DontClosePopups)) {
if (dir_ent.is_directory()) if (dir_ent.is_directory())
data.current_path = dir_ent.path(); data.current_path = dir_ent.path();
else else
@ -294,7 +296,10 @@ void prism::imgui_backend::process_text_input(const std::string_view string) {
io.AddInputCharactersUTF8(string.data()); io.AddInputCharactersUTF8(string.data());
} }
void prism::imgui_backend::open_dialog(const bool, std::function<void(std::string)> returnFunction, bool openDirectory) { void prism::imgui_backend::open_dialog(
const bool,
std::function<void(std::string)> returnFunction,
bool openDirectory) {
open_dialog_next_frame = true; open_dialog_next_frame = true;
open_dialog_data.current_path = std::filesystem::current_path(); open_dialog_data.current_path = std::filesystem::current_path();
open_dialog_data.return_function = returnFunction; open_dialog_data.return_function = returnFunction;

View file

@ -17,8 +17,7 @@ void input_system::update() {
const auto& [x, y] = platform::get_cursor_position(); const auto& [x, y] = platform::get_cursor_position();
auto& [oldX, oldY] = _last_cursor_position; auto& [oldX, oldY] = _last_cursor_position;
const auto [width, height] = const auto [width, height] = platform::get_window_size(::engine->get_main_window());
platform::get_window_size(::engine->get_main_window());
float xDelta = (x - oldX) / (float)width; float xDelta = (x - oldX) / (float)width;
float yDelta = (y - oldY) / (float)height; float yDelta = (y - oldY) / (float)height;
@ -112,8 +111,7 @@ void input_system::add_binding(const std::string& name) {
_input_bindings.push_back(data); _input_bindings.push_back(data);
} }
void input_system::add_binding_button(const std::string& name, InputButton key, void input_system::add_binding_button(const std::string& name, InputButton key, float value) {
float value) {
for (auto& binding : _input_bindings) { for (auto& binding : _input_bindings) {
if (binding.name == name) if (binding.name == name)
binding.buttons[key] = value; binding.buttons[key] = value;
@ -166,7 +164,9 @@ void input_system::end_text_input() {
platform::end_text_input(); platform::end_text_input();
} }
bool input_system::is_text_input() const { return _in_text_input; } bool input_system::is_text_input() const {
return _in_text_input;
}
bool input_system::get_allowable_text_button(unsigned int keycode) const { bool input_system::get_allowable_text_button(unsigned int keycode) const {
if (platform::get_keycode(InputButton::Backspace) == keycode) if (platform::get_keycode(InputButton::Backspace) == keycode)

View file

@ -19,7 +19,8 @@ void Physics::update(float deltaTime) {
if (rigidbody.body != nullptr) { if (rigidbody.body != nullptr) {
if (rigidbody.type == Rigidbody::Type::Dynamic) { if (rigidbody.type == Rigidbody::Type::Dynamic) {
if (rigidbody.stored_force != prism::float3(0.0f)) { if (rigidbody.stored_force != prism::float3(0.0f)) {
rigidbody.body->setLinearVelocity(btVector3(rigidbody.stored_force.x, rigidbody.stored_force.y, rigidbody.stored_force.z)); rigidbody.body->setLinearVelocity(
btVector3(rigidbody.stored_force.x, rigidbody.stored_force.y, rigidbody.stored_force.z));
rigidbody.stored_force = prism::float3(0.0f); rigidbody.stored_force = prism::float3(0.0f);
} }
} }
@ -32,7 +33,8 @@ void Physics::update(float deltaTime) {
if (collision.shape == nullptr && !collision.is_trigger) { if (collision.shape == nullptr && !collision.is_trigger) {
switch (collision.type) { switch (collision.type) {
case Collision::Type::Cube: case Collision::Type::Cube:
collision.shape = new btBoxShape(btVector3(collision.size.x / 2.0f, collision.size.y / 2.0f, collision.size.z / 2.0f)); collision.shape = new btBoxShape(
btVector3(collision.size.x / 2.0f, collision.size.y / 2.0f, collision.size.z / 2.0f));
break; break;
case Collision::Type::Capsule: case Collision::Type::Capsule:
collision.shape = new btCapsuleShape(0.5f, collision.size.y); collision.shape = new btCapsuleShape(0.5f, collision.size.y);
@ -49,7 +51,8 @@ void Physics::update(float deltaTime) {
t.setIdentity(); t.setIdentity();
t.setOrigin(btVector3(transform.position.x, transform.position.y, transform.position.z)); t.setOrigin(btVector3(transform.position.x, transform.position.y, transform.position.z));
t.setRotation(btQuaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w)); t.setRotation(
btQuaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w));
btDefaultMotionState* motionState = new btDefaultMotionState(t); btDefaultMotionState* motionState = new btDefaultMotionState(t);
@ -59,7 +62,8 @@ void Physics::update(float deltaTime) {
if (rigidbody.mass != 0) if (rigidbody.mass != 0)
engine->get_scene()->get<Collision>(obj).shape->calculateLocalInertia(bodyMass, bodyInertia); engine->get_scene()->get<Collision>(obj).shape->calculateLocalInertia(bodyMass, bodyInertia);
btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, motionState, engine->get_scene()->get<Collision>(obj).shape, bodyInertia); btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(
bodyMass, motionState, engine->get_scene()->get<Collision>(obj).shape, bodyInertia);
bodyCI.m_friction = rigidbody.friction; bodyCI.m_friction = rigidbody.friction;
@ -84,7 +88,8 @@ void Physics::update(float deltaTime) {
t.setIdentity(); t.setIdentity();
t.setOrigin(btVector3(transform.position.x, transform.position.y, transform.position.z)); t.setOrigin(btVector3(transform.position.x, transform.position.y, transform.position.z));
t.setRotation(btQuaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w)); t.setRotation(
btQuaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w));
rigidbody.body->setWorldTransform(t); rigidbody.body->setWorldTransform(t);
} }
@ -148,6 +153,7 @@ void Physics::reset() {
solver = std::make_unique<btSequentialImpulseConstraintSolver>(); solver = std::make_unique<btSequentialImpulseConstraintSolver>();
world = std::make_unique<btDiscreteDynamicsWorld>(dispatcher.get(), broadphase.get(), solver.get(), collisionConfiguration.get()); world = std::make_unique<btDiscreteDynamicsWorld>(
dispatcher.get(), broadphase.get(), solver.get(), collisionConfiguration.get());
world->setGravity(btVector3(0.0f, -9.8f, 0.0f)); world->setGravity(btVector3(0.0f, -9.8f, 0.0f));
} }

View file

@ -1,10 +1,10 @@
#include "scene.hpp" #include "scene.hpp"
#include "json_conversions.hpp"
#include "file.hpp"
#include "engine.hpp"
#include "transform.hpp"
#include "asset.hpp" #include "asset.hpp"
#include "engine.hpp"
#include "file.hpp"
#include "json_conversions.hpp"
#include "transform.hpp"
void camera_look_at(Scene& scene, prism::Object cam, prism::float3 pos, prism::float3 target) { void camera_look_at(Scene& scene, prism::Object cam, prism::float3 pos, prism::float3 target) {
scene.get<Transform>(cam).position = pos; scene.get<Transform>(cam).position = pos;