Archived
1
Fork 0

Some minor code refactoring

This commit is contained in:
redstrate 2021-10-14 08:51:58 -04:00
parent c6d699a130
commit e79a98c7d2
57 changed files with 147 additions and 192 deletions

View file

@ -19,10 +19,10 @@ namespace std {
} }
template<typename T> template<typename T>
std::unique_ptr<T> load_asset(const prism::path p); std::unique_ptr<T> load_asset(const prism::path& p);
template<typename T> template<typename T>
bool can_load_asset(const prism::path p); bool can_load_asset(const prism::path& p);
template<class AssetType> template<class AssetType>
using AssetStore = std::unordered_map<prism::path, std::unique_ptr<AssetType>>; using AssetStore = std::unordered_map<prism::path, std::unique_ptr<AssetType>>;
@ -91,7 +91,7 @@ public:
std::unordered_map<prism::path, std::unique_ptr<ReferenceBlock>> reference_blocks; std::unordered_map<prism::path, std::unique_ptr<ReferenceBlock>> reference_blocks;
private: private:
ReferenceBlock* get_reference_block(const prism::path path) { ReferenceBlock* get_reference_block(const prism::path& path) {
if(!reference_blocks.count(path)) if(!reference_blocks.count(path))
reference_blocks.try_emplace(path, std::make_unique<ReferenceBlock>()); reference_blocks.try_emplace(path, std::make_unique<ReferenceBlock>());
@ -99,7 +99,7 @@ private:
} }
template<typename T> template<typename T>
void load_asset_generic(const prism::path path, Asset*& at, ReferenceBlock*& block) { void load_asset_generic(const prism::path& path, Asset*& at, ReferenceBlock*& block) {
if(can_load_asset<T>(path)) { if(can_load_asset<T>(path)) {
if(!AssetStore<T>::count(path)) if(!AssetStore<T>::count(path))
AssetStore<T>::try_emplace(path, load_asset<T>(path)); AssetStore<T>::try_emplace(path, load_asset<T>(path));
@ -126,14 +126,14 @@ using AssetManager = AssetPool<Mesh, Material, Texture>;
inline std::unique_ptr<AssetManager> assetm; inline std::unique_ptr<AssetManager> assetm;
std::unique_ptr<Mesh> load_mesh(const prism::path path); std::unique_ptr<Mesh> load_mesh(prism::path path);
std::unique_ptr<Material> load_material(const prism::path path); std::unique_ptr<Material> load_material(prism::path path);
std::unique_ptr<Texture> load_texture(const prism::path path); std::unique_ptr<Texture> load_texture(prism::path path);
void save_material(Material* material, const prism::path path); void save_material(Material* material, prism::path path);
template<typename T> template<typename T>
std::unique_ptr<T> load_asset(const prism::path path) { std::unique_ptr<T> load_asset(const prism::path& path) {
if constexpr (std::is_same_v<T, Mesh>) { if constexpr (std::is_same_v<T, Mesh>) {
return load_mesh(path); return load_mesh(path);
} else if constexpr(std::is_same_v<T, Material>) { } else if constexpr(std::is_same_v<T, Material>) {
@ -144,7 +144,7 @@ std::unique_ptr<T> load_asset(const prism::path path) {
} }
template<typename T> template<typename T>
bool can_load_asset(const prism::path path) { bool can_load_asset(const prism::path& path) {
if constexpr(std::is_same_v<T, Mesh>) { if constexpr(std::is_same_v<T, Mesh>) {
return path.extension() == ".model"; return path.extension() == ".model";
} else if constexpr(std::is_same_v<T, Material>) { } else if constexpr(std::is_same_v<T, Material>) {

View file

@ -14,7 +14,7 @@ public:
template<class T> template<class T>
struct AssetPtr { struct AssetPtr {
AssetPtr() {} AssetPtr() = default;
AssetPtr(T* ptr, ReferenceBlock* block) : handle(ptr), block(block) { AssetPtr(T* ptr, ReferenceBlock* block) : handle(ptr), block(block) {
block->references++; block->references++;
@ -54,7 +54,7 @@ struct AssetPtr {
T* handle = nullptr; T* handle = nullptr;
ReferenceBlock* block = nullptr; ReferenceBlock* block = nullptr;
operator bool() const{ explicit operator bool() const{
return handle != nullptr; return handle != nullptr;
} }

View file

@ -104,21 +104,12 @@ public:
std::string get_property_value(MaterialProperty& property) { std::string get_property_value(MaterialProperty& property) {
switch(property.type) { switch(property.type) {
case DataType::Vector3: case DataType::Vector3:
{
return "vec3(" + std::to_string(property.value.x) + ", " + std::to_string(property.value.y) + ", " + std::to_string(property.value.z) + ")"; return "vec3(" + std::to_string(property.value.x) + ", " + std::to_string(property.value.y) + ", " + std::to_string(property.value.z) + ")";
}
break;
case DataType::Float: case DataType::Float:
{
return std::to_string(property.float_value); return std::to_string(property.float_value);
}
break;
case DataType::AssetTexture: case DataType::AssetTexture:
{
return "texture(" + get_property_variable_name(property) + ", in_uv).rgb"; return "texture(" + get_property_variable_name(property) + ", in_uv).rgb";
} }
break;
}
} }
MaterialConnector* find_connector(std::string name) { MaterialConnector* find_connector(std::string name) {

View file

@ -356,7 +356,7 @@ void save_material(Material* material, const prism::path path) {
n["properties"].push_back(p); n["properties"].push_back(p);
} }
for(auto output : node->outputs) { for(const auto& output : node->outputs) {
if(output.connected_connector != nullptr) { if(output.connected_connector != nullptr) {
nlohmann::json c; nlohmann::json c;
c["name"] = output.name; c["name"] = output.name;

View file

@ -8,5 +8,5 @@
namespace audio { namespace audio {
void initialize(); void initialize();
void play_file(const prism::path path, const float gain = 1.0f); void play_file(const prism::path& path, float gain = 1.0f);
} }

View file

@ -71,7 +71,7 @@ void audio::initialize() {
Pa_StartStream(stream); Pa_StartStream(stream);
} }
void audio::play_file(const prism::path path, const float gain) { void audio::play_file(const prism::path& path, const float gain) {
auto audio_file = prism::open_file(path); auto audio_file = prism::open_file(path);
if(audio_file == std::nullopt) if(audio_file == std::nullopt)
return; return;

View file

@ -27,6 +27,8 @@ namespace prism::console {
return argument_type::Integer; return argument_type::Integer;
else if (std::holds_alternative<bool>(data)) else if (std::holds_alternative<bool>(data))
return argument_type::Boolean; return argument_type::Boolean;
return argument_type::String; // fallback??
} }
std::variant<std::string, int, bool> data; std::variant<std::string, int, bool> data;

View file

@ -17,12 +17,12 @@ inline bool operator==(const PositionKeyFrame& lhs, const PositionKeyFrame& rhs)
} }
struct RotationKeyFrame { struct RotationKeyFrame {
float time; float time = 0.0f;
Quaternion value; Quaternion value;
}; };
struct ScaleKeyFrame { struct ScaleKeyFrame {
float time; float time = 0.0f;
prism::float3 value; prism::float3 value;
}; };

View file

@ -223,7 +223,7 @@ namespace prism {
* Called when text has been inputted. This is only emitted when text input is enabled thru input system * Called when text has been inputted. This is only emitted when text input is enabled thru input system
* @param string * @param string
*/ */
void process_text_input(const std::string_view string); void process_text_input(std::string_view string);
/** 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.

View file

@ -255,5 +255,5 @@ public:
*/ */
void camera_look_at(Scene& scene, Object cam, prism::float3 pos, prism::float3 target); void camera_look_at(Scene& scene, Object cam, prism::float3 pos, prism::float3 target);
Object load_object(Scene& scene, const nlohmann::json obj); Object load_object(Scene& scene, const nlohmann::json& obj);
nlohmann::json save_object(Object obj); nlohmann::json save_object(Object obj);

View file

@ -66,6 +66,8 @@ void prism::console::invoke_command(const std::string_view name, const prism::co
case console::argument_type::Boolean: case console::argument_type::Boolean:
*std::get<bool*>(variable_data.data) = std::get<bool>(argument.data); *std::get<bool*>(variable_data.data) = std::get<bool>(argument.data);
break; break;
default: // non-bool types are not handled yet.
break;
} }
} }
@ -91,8 +93,6 @@ void prism::console::parse_and_invoke_command(const std::string_view command) {
} else { } else {
return console_argument(arg); return console_argument(arg);
} }
return std::nullopt;
}; };
std::vector<console_argument> arguments; std::vector<console_argument> arguments;

View file

@ -36,7 +36,7 @@ void draw_asset() {
for(auto& [path, block] : assetm->reference_blocks) { for(auto& [path, block] : assetm->reference_blocks) {
ImGui::PushID(&block); ImGui::PushID(&block);
ImGui::Text("- %s has %llu reference(s)", path.string().c_str(), block->references); ImGui::Text("- %s has %lu reference(s)", path.string().c_str(), block->references);
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(200, 0, 0)); ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(200, 0, 0));

View file

@ -324,9 +324,9 @@ 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& [scene_path, scene] : path_to_scene) {
if(shot.scene == scene) if(shot.scene == scene)
s["scene"] = path; s["scene"] = scene_path;
} }
j["shots"].push_back(s); j["shots"].push_back(s);
@ -352,7 +352,7 @@ Object engine::add_prefab(Scene& scene, const prism::path& path, const std::stri
std::map<Object, std::string> parent_queue; std::map<Object, std::string> parent_queue;
for(const auto obj : j["objects"]) { for(const auto& obj : j["objects"]) {
auto o = load_object(scene, obj); auto o = load_object(scene, obj);
if(obj.contains("parent")) { if(obj.contains("parent")) {
@ -457,7 +457,7 @@ void engine::process_key_up(const unsigned int keyCode) {
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) {
imgui->process_mouse_down(button); imgui->process_mouse_down(button);
} }

View file

@ -2,11 +2,10 @@
#include <cstdio> #include <cstdio>
#include "string_utils.hpp"
#include "log.hpp" #include "log.hpp"
#include "assertions.hpp" #include "assertions.hpp"
prism::path prism::root_path(const path path) { prism::path prism::root_path(const path& path) {
auto p = path; auto p = path;
while(p.parent_path() != p && p.parent_path() != "/") { while(p.parent_path() != p && p.parent_path() != "/") {
p = p.parent_path(); p = p.parent_path();
@ -15,7 +14,7 @@ prism::path prism::root_path(const path path) {
return p; return p;
} }
std::optional<prism::file> prism::open_file(const prism::path path, const bool binary_mode) { std::optional<prism::file> prism::open_file(const prism::path& path, const bool binary_mode) {
Expects(!path.empty()); Expects(!path.empty());
auto str = get_file_path(path).string(); auto str = get_file_path(path).string();
@ -48,7 +47,7 @@ prism::path parent_domain(const prism::path& path) {
return path; return path;
} }
prism::path prism::get_relative_path(const domain domain, const path path) { prism::path prism::get_relative_path(const domain, const path& path) {
// unimplemented // unimplemented
return path; return path;
} }

View file

@ -228,7 +228,7 @@ void imgui_backend::begin_frame(const float delta_time) {
if(ImGui::Selectable("..", false, ImGuiSelectableFlags_DontClosePopups)) if(ImGui::Selectable("..", false, ImGuiSelectableFlags_DontClosePopups))
data.current_path = data.current_path.parent_path(); data.current_path = data.current_path.parent_path();
for(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().c_str(), data.selected_path == dir_ent.path(), ImGuiSelectableFlags_DontClosePopups)) { if(ImGui::Selectable(dir_ent.path().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();
@ -291,7 +291,7 @@ 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 existing, std::function<void(std::string)> returnFunction, bool openDirectory) { void prism::imgui_backend::open_dialog(const bool, std::function<void(std::string)> returnFunction, bool) {
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

@ -3,7 +3,6 @@
#include <string> #include <string>
#include "engine.hpp" #include "engine.hpp"
#include "log.hpp"
using prism::input_system; using prism::input_system;
@ -139,7 +138,7 @@ float input_system::get_value(const std::string& name) {
} }
bool input_system::is_pressed(const std::string &name, bool repeating) { bool input_system::is_pressed(const std::string &name, bool repeating) {
return get_value(name) == 1.0 && (repeating ? true : !is_repeating(name)); return get_value(name) == 1.0 && (repeating || !is_repeating(name));
} }
bool input_system::is_repeating(const std::string& name) { bool input_system::is_repeating(const std::string& name) {

View file

@ -129,7 +129,7 @@ Physics::RayResult Physics::raycast(prism::float3 from, prism::float3 to) {
if(closestCollisionObject != NullObject) { if(closestCollisionObject != NullObject) {
result.hasHit = true; result.hasHit = true;
auto vec = res.m_hitPointWorld[closestCollisionObject];; auto vec = res.m_hitPointWorld[closestCollisionObject];
result.location = prism::float3(vec.x(), vec.y(), vec.z()); result.location = prism::float3(vec.x(), vec.y(), vec.z());
} }

View file

@ -76,7 +76,7 @@ void load_probe_component(nlohmann::json j, EnvironmentProbe& probe) {
probe.intensity = j["intensity"]; probe.intensity = j["intensity"];
} }
Object load_object(Scene& scene, const nlohmann::json obj) { Object load_object(Scene& scene, const nlohmann::json& obj) {
Object o = scene.add_object(); Object o = scene.add_object();
auto& data = scene.get(o); auto& data = scene.get(o);

View file

@ -161,7 +161,7 @@ struct GFXDrawCommand {
} insert_label; } insert_label;
struct DispatchData { struct DispatchData {
uint32_t group_count_x, group_count_y, group_count_z; uint32_t group_count_x = 0, group_count_y = 0, group_count_z = 0;
} dispatch; } dispatch;
} data; } data;
}; };

View file

@ -2,5 +2,5 @@
class GFXObject { class GFXObject {
public: public:
virtual ~GFXObject() {} virtual ~GFXObject() = default;
}; };

View file

@ -1970,22 +1970,22 @@ void GFXVulkan::createSwapchain(NativeSurface* native_surface, VkSwapchainKHR ol
native_surface->swapchainImageViews.resize(native_surface->swapchainImages.size()); native_surface->swapchainImageViews.resize(native_surface->swapchainImages.size());
for (size_t i = 0; i < native_surface->swapchainImages.size(); i++) { for (size_t i = 0; i < native_surface->swapchainImages.size(); i++) {
VkImageViewCreateInfo createInfo = {}; VkImageViewCreateInfo view_create_info = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = native_surface->swapchainImages[i]; view_create_info.image = native_surface->swapchainImages[i];
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
createInfo.format = swapchainSurfaceFormat.format; view_create_info.format = swapchainSurfaceFormat.format;
createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; view_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; view_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; view_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; view_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
createInfo.subresourceRange.baseMipLevel = 0; view_create_info.subresourceRange.baseMipLevel = 0;
createInfo.subresourceRange.levelCount = 1; view_create_info.subresourceRange.levelCount = 1;
createInfo.subresourceRange.baseArrayLayer = 0; view_create_info.subresourceRange.baseArrayLayer = 0;
createInfo.subresourceRange.layerCount = 1; view_create_info.subresourceRange.layerCount = 1;
vkCreateImageView(device, &createInfo, nullptr, &native_surface->swapchainImageViews[i]); vkCreateImageView(device, &view_create_info, nullptr, &native_surface->swapchainImageViews[i]);
} }
// create render pass // create render pass

View file

@ -7,9 +7,9 @@
class GFXVulkanBuffer : public GFXBuffer { class GFXVulkanBuffer : public GFXBuffer {
public: public:
VkBuffer handle; VkBuffer handle = VK_NULL_HANDLE;
VkDeviceMemory memory; VkDeviceMemory memory = VK_NULL_HANDLE;
VkDeviceSize size; VkDeviceSize size = 0;
uint32_t frame_index = 0; uint32_t frame_index = 0;
}; };

View file

@ -6,7 +6,7 @@
class GFXVulkanFramebuffer : public GFXFramebuffer { class GFXVulkanFramebuffer : public GFXFramebuffer {
public: public:
VkFramebuffer handle; VkFramebuffer handle = VK_NULL_HANDLE;
int width = 0, height = 0; int width = 0, height = 0;
}; };

View file

@ -10,10 +10,10 @@ class GFXVulkanPipeline : public GFXPipeline {
public: public:
std::string label; std::string label;
VkPipeline handle; VkPipeline handle = VK_NULL_HANDLE;
VkPipelineLayout layout; VkPipelineLayout layout = VK_NULL_HANDLE;
VkDescriptorSetLayout descriptorLayout; VkDescriptorSetLayout descriptorLayout = VK_NULL_HANDLE;
std::vector<int> bindings_marked_as_normal_images; std::vector<int> bindings_marked_as_normal_images;
std::vector<int> bindings_marked_as_storage_images; std::vector<int> bindings_marked_as_storage_images;

View file

@ -6,5 +6,5 @@
class GFXVulkanSampler: public GFXSampler { class GFXVulkanSampler: public GFXSampler {
public: public:
VkSampler sampler; VkSampler sampler = VK_NULL_HANDLE;
}; };

View file

@ -6,14 +6,14 @@
class GFXVulkanTexture : public GFXTexture { class GFXVulkanTexture : public GFXTexture {
public: public:
VkImage handle; VkImage handle = VK_NULL_HANDLE;
VkDeviceMemory memory; VkDeviceMemory memory = VK_NULL_HANDLE;
VkImageView view; VkImageView view = VK_NULL_HANDLE;
VkSampler sampler; VkSampler sampler = VK_NULL_HANDLE;
int width, height; int width = 0, height = 0;
VkFormat format; VkFormat format = VK_FORMAT_UNDEFINED;
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
VkImageLayout current_layout = VK_IMAGE_LAYOUT_UNDEFINED; VkImageLayout current_layout = VK_IMAGE_LAYOUT_UNDEFINED;
VkImageAspectFlagBits aspect; VkImageAspectFlagBits aspect;

View file

@ -8,7 +8,7 @@
template<class T, std::size_t M, std::size_t N> template<class T, std::size_t M, std::size_t N>
class Matrix { class Matrix {
public: public:
constexpr Matrix(const T diagonal = T(1)) { constexpr explicit Matrix(const T diagonal = T(1)) {
for(std::size_t i = 0; i < (M * N); i++) for(std::size_t i = 0; i < (M * N); i++)
unordered_data[i] = ((i / M) == (i % N) ? diagonal : T(0)); unordered_data[i] = ((i / M) == (i % N) ? diagonal : T(0));
} }
@ -20,7 +20,7 @@ public:
columns[3] = m4_; columns[3] = m4_;
} }
constexpr inline void operator*=(const Matrix rhs); constexpr inline void operator*=(Matrix rhs);
using VectorType = prism::Vector<N, T>; using VectorType = prism::Vector<N, T>;

View file

@ -55,13 +55,15 @@ Quaternion quat_from_matrix(const Matrix3x3 m) {
switch(biggestIndex) { switch(biggestIndex) {
case 0: case 0:
return Quaternion((m[1][2] - m[2][1]) * mult, (m[2][0] - m[0][2]) * mult, (m[0][1] - m[1][0]) * mult, biggestVal); return {(m[1][2] - m[2][1]) * mult, (m[2][0] - m[0][2]) * mult, (m[0][1] - m[1][0]) * mult, biggestVal};
case 1: case 1:
return Quaternion(biggestVal, (m[0][1] + m[1][0]) * mult, (m[2][0] + m[0][2]) * mult, (m[1][2] - m[2][1]) * mult); return {biggestVal, (m[0][1] + m[1][0]) * mult, (m[2][0] + m[0][2]) * mult, (m[1][2] - m[2][1]) * mult};
case 2: case 2:
return Quaternion((m[0][1] + m[1][0]) * mult, biggestVal, (m[1][2] + m[2][1]) * mult, (m[2][0] - m[0][2]) * mult); return {(m[0][1] + m[1][0]) * mult, biggestVal, (m[1][2] + m[2][1]) * mult, (m[2][0] - m[0][2]) * mult};
case 3: case 3:
return Quaternion((m[2][0] + m[0][2]) * mult, (m[1][2] + m[2][1]) * mult, biggestVal, (m[0][1] - m[1][0]) * mult); return {(m[2][0] + m[0][2]) * mult, (m[1][2] + m[2][1]) * mult, biggestVal, (m[0][1] - m[1][0]) * mult};
default:
return {};
} }
} }
@ -97,7 +99,7 @@ prism::float3 quat_to_euler(const Quaternion q) {
const float yaw = asinf(-2.0f * (q.x * q.z - q.w * q.y)); const float yaw = asinf(-2.0f * (q.x * q.z - q.w * q.y));
return prism::float3(pitch, yaw, roll); return {pitch, yaw, roll};
} }
Matrix4x4 inverse(const Matrix4x4 m) { Matrix4x4 inverse(const Matrix4x4 m) {

View file

@ -77,8 +77,7 @@ namespace prism {
/// Reads the entire file as a string. /// Reads the entire file as a string.
std::string read_as_string() { std::string read_as_string() {
auto s = read_as_stream(); auto s = read_as_stream();
return std::string((std::istreambuf_iterator<char>(s)), return {(std::istreambuf_iterator<char>(s)), std::istreambuf_iterator<char>()};
std::istreambuf_iterator<char>());
} }
/// Reads the entire file as a ifstream, useful for JSON deserialization. /// Reads the entire file as a ifstream, useful for JSON deserialization.
@ -109,11 +108,11 @@ namespace prism {
@param mode The access mode. @param mode The access mode.
@param path The absolute file path. @param path The absolute file path.
*/ */
void set_domain_path(domain domain, path domain_path); void set_domain_path(domain domain, const path& domain_path);
path get_domain_path(domain domain); path get_domain_path(domain domain);
/// Converts an absolute path to a domain relative path. /// Converts an absolute path to a domain relative path.
path get_relative_path(domain domain, path domain_relative_path); path get_relative_path(domain domain, const path& domain_relative_path);
/// Returns the path to a writeable directory. /// Returns the path to a writeable directory.
path get_writeable_directory(); path get_writeable_directory();
@ -125,9 +124,9 @@ namespace prism {
@param binary_mode Whether or not to open the file as binary or ASCII. Defaults to false. @param binary_mode Whether or not to open the file as binary or ASCII. Defaults to false.
@return An optional with a value if the file was loaded correctly, otherwise it's empty. @return An optional with a value if the file was loaded correctly, otherwise it's empty.
*/ */
std::optional<file> open_file(path file_path, bool binary_mode = false); std::optional<file> open_file(const path& file_path, bool binary_mode = false);
path root_path(path path); path root_path(const path& path);
path get_file_path(const path& path); path get_file_path(const path& path);
inline path internal_domain = "/internal", app_domain = "/app"; inline path internal_domain = "/internal", app_domain = "/app";

View file

@ -14,7 +14,7 @@ namespace prism {
class DoFPass { class DoFPass {
public: public:
DoFPass(GFX* gfx, prism::renderer* renderer); DoFPass(GFX* gfx);
void render(GFXCommandBuffer* command_buffer, Scene& scene); void render(GFXCommandBuffer* command_buffer, Scene& scene);
@ -27,7 +27,5 @@ public:
GFXRenderPass* renderpass = nullptr; GFXRenderPass* renderpass = nullptr;
private: private:
prism::renderer* renderer = nullptr;
GFXPipeline* pipeline = nullptr; GFXPipeline* pipeline = nullptr;
}; };

View file

@ -17,10 +17,10 @@ public:
void create_render_target_resources(RenderTarget& target) override; void create_render_target_resources(RenderTarget& target) override;
void render_post(GFXCommandBuffer* command_buffer, RenderTarget& target, const platform::window_ptr index) override; void render_post(GFXCommandBuffer* command_buffer, RenderTarget& target, platform::window_ptr index) override;
private: private:
void load_font(const std::string_view filename); void load_font(std::string_view filename);
void create_font_texture(); void create_font_texture();
void update_buffers(RenderTarget& target, const ImDrawData& draw_data); void update_buffers(RenderTarget& target, const ImDrawData& draw_data);

View file

@ -15,7 +15,7 @@ class RenderTarget;
class Pass { class Pass {
public: public:
virtual ~Pass() {} virtual ~Pass() = default;
virtual void initialize() {} virtual void initialize() {}

View file

@ -16,7 +16,7 @@ const int irradiance_cubemap_resolution = 32;
class SceneCapture { class SceneCapture {
public: public:
SceneCapture(GFX* gfx); explicit SceneCapture(GFX* gfx);
void create_scene_resources(Scene& scene); void create_scene_resources(Scene& scene);

View file

@ -17,7 +17,7 @@ namespace prism {
class SMAAPass { class SMAAPass {
public: public:
SMAAPass(GFX* gfx, prism::renderer* renderer); SMAAPass(GFX* gfx);
void create_render_target_resources(RenderTarget& target); void create_render_target_resources(RenderTarget& target);
@ -28,8 +28,6 @@ private:
void create_render_pass(); void create_render_pass();
void create_pipelines(); void create_pipelines();
prism::renderer* renderer = nullptr;
GFXTexture* area_image = nullptr; GFXTexture* area_image = nullptr;
GFXTexture* search_image = nullptr; GFXTexture* search_image = nullptr;

View file

@ -8,7 +8,7 @@
AssetPtr<Texture> aperture_texture; AssetPtr<Texture> aperture_texture;
DoFPass::DoFPass(GFX* gfx, prism::renderer* renderer) : renderer(renderer) { DoFPass::DoFPass(GFX* gfx) {
aperture_texture = assetm->get<Texture>(prism::app_domain / "textures/aperture.png"); aperture_texture = assetm->get<Texture>(prism::app_domain / "textures/aperture.png");
GFXRenderPassCreateInfo renderPassInfo = {}; GFXRenderPassCreateInfo renderPassInfo = {};

View file

@ -10,7 +10,7 @@
#include "material_nodes.hpp" #include "material_nodes.hpp"
#include "renderer.hpp" #include "renderer.hpp"
ShaderSource get_shader(std::string filename, bool skinned, bool cubemap) { ShaderSource get_shader(const std::string& filename, bool skinned, bool cubemap) {
auto shader_file = prism::open_file(prism::internal_domain / filename); auto shader_file = prism::open_file(prism::internal_domain / filename);
if(!shader_file.has_value()) { if(!shader_file.has_value()) {
prism::log("Failed to open shader file {}!", filename); prism::log("Failed to open shader file {}!", filename);

View file

@ -1,7 +1,5 @@
#include "renderer.hpp" #include "renderer.hpp"
#include <array>
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "math.hpp" #include "math.hpp"
#include "file.hpp" #include "file.hpp"
@ -90,7 +88,7 @@ renderer::renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) {
shadow_pass = std::make_unique<ShadowPass>(gfx); shadow_pass = std::make_unique<ShadowPass>(gfx);
scene_capture = std::make_unique<SceneCapture>(gfx); scene_capture = std::make_unique<SceneCapture>(gfx);
smaa_pass = std::make_unique<SMAAPass>(gfx, this); smaa_pass = std::make_unique<SMAAPass>(gfx);
if(enable_imgui) if(enable_imgui)
addPass<ImGuiPass>(); addPass<ImGuiPass>();

View file

@ -3,7 +3,6 @@
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "gfx.hpp" #include "gfx.hpp"
#include "log.hpp"
#include "engine.hpp" #include "engine.hpp"
#include "renderer.hpp" #include "renderer.hpp"
#include "shadowpass.hpp" #include "shadowpass.hpp"

View file

@ -3,7 +3,6 @@
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "gfx.hpp" #include "gfx.hpp"
#include "log.hpp"
#include "engine.hpp" #include "engine.hpp"
#include "materialcompiler.hpp" #include "materialcompiler.hpp"
#include "assertions.hpp" #include "assertions.hpp"
@ -113,7 +112,7 @@ void ShadowPass::render(GFXCommandBuffer* command_buffer, Scene& scene) {
} }
} }
void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const prism::float3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance) { void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const prism::float3, const Light::Type type, const CameraFrustum& frustum, const int base_instance) {
for(auto [obj, mesh] : scene.get_all<Renderable>()) { for(auto [obj, mesh] : scene.get_all<Renderable>()) {
if(!mesh.mesh) if(!mesh.mesh)
continue; continue;

View file

@ -9,9 +9,8 @@
#include <AreaTex.h> #include <AreaTex.h>
#include <SearchTex.h> #include <SearchTex.h>
SMAAPass::SMAAPass(GFX* gfx, prism::renderer* renderer) : renderer(renderer) { SMAAPass::SMAAPass(GFX* gfx) {
Expects(gfx != nullptr); Expects(gfx != nullptr);
Expects(renderer != nullptr);
create_textures(); create_textures();
create_render_pass(); create_render_pass();

View file

@ -50,14 +50,14 @@ class DirStackFileIncluder : public glslang::TShader::Includer {
public: public:
DirStackFileIncluder() : externalLocalDirectoryCount(0) { } DirStackFileIncluder() : externalLocalDirectoryCount(0) { }
virtual IncludeResult* includeLocal(const char* headerName, IncludeResult* includeLocal(const char* headerName,
const char* includerName, const char* includerName,
size_t inclusionDepth) override size_t inclusionDepth) override
{ {
return readLocalPath(headerName, includerName, (int)inclusionDepth); return readLocalPath(headerName, includerName, (int)inclusionDepth);
} }
virtual IncludeResult* includeSystem(const char* headerName, IncludeResult* includeSystem(const char* headerName,
const char* /*includerName*/, const char* /*includerName*/,
size_t /*inclusionDepth*/) override size_t /*inclusionDepth*/) override
{ {
@ -76,7 +76,7 @@ public:
externalLocalDirectoryCount = (int)directoryStack.size(); externalLocalDirectoryCount = (int)directoryStack.size();
} }
virtual void releaseInclude(IncludeResult* result) override void releaseInclude(IncludeResult* result) override
{ {
if (result != nullptr) { if (result != nullptr) {
delete [] static_cast<tUserDataElement*>(result->userData); delete [] static_cast<tUserDataElement*>(result->userData);
@ -84,7 +84,7 @@ public:
} }
} }
virtual ~DirStackFileIncluder() override { } ~DirStackFileIncluder() override = default;
protected: protected:
typedef char tUserDataElement; typedef char tUserDataElement;

View file

@ -1,6 +1,5 @@
#include "shadercompiler.hpp" #include "shadercompiler.hpp"
#include <spirv_cpp.hpp>
#include <spirv_msl.hpp> #include <spirv_msl.hpp>
#include <SPIRV/GlslangToSpv.h> #include <SPIRV/GlslangToSpv.h>

View file

@ -21,7 +21,7 @@ namespace prism {
/// A 2D rectangle defined by a offset and an etent. /// A 2D rectangle defined by a offset and an etent.
struct Rectangle { struct Rectangle {
Rectangle() {} Rectangle() = default;
Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {} Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {}
Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {} Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {}

View file

@ -7,7 +7,7 @@
#include "asset.hpp" #include "asset.hpp"
#include "path.hpp" #include "path.hpp"
void app_main(prism::engine* engine) { void app_main(prism::engine*) {
prism::set_domain_path(prism::domain::app, "{resource_dir}/data"); prism::set_domain_path(prism::domain::app, "{resource_dir}/data");
prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders"); prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders");

View file

@ -2,7 +2,7 @@
#include "string_utils.hpp" #include "string_utils.hpp"
void prism::set_domain_path(const prism::domain domain, const prism::path path) { void prism::set_domain_path(const prism::domain domain, const prism::path& path) {
#ifdef PLATFORM_MACOS #ifdef PLATFORM_MACOS
domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", "../Resources/"); domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", "../Resources/");
#else #else

View file

@ -108,7 +108,7 @@ constexpr int thumbnail_resolution = 256;
class CommonEditor : public prism::app { class CommonEditor : public prism::app {
public: public:
CommonEditor(std::string id); explicit CommonEditor(std::string_view id);
void initialize_render() override; void initialize_render() override;
@ -130,7 +130,7 @@ public:
virtual void updateEditor([[maybe_unused]] float deltaTime) {} virtual void updateEditor([[maybe_unused]] float deltaTime) {}
virtual void object_selected([[maybe_unused]] Object object) {} virtual void object_selected([[maybe_unused]] Object object) {}
virtual void asset_selected([[maybe_unused]] std::filesystem::path path, [[maybe_unused]] AssetType type) {} virtual void asset_selected([[maybe_unused]] const std::filesystem::path& path, [[maybe_unused]] AssetType type) {}
bool wants_no_scene_rendering() override { return true; } bool wants_no_scene_rendering() override { return true; }
bool is_multimodal() override { return true; } bool is_multimodal() override { return true; }
@ -145,7 +145,7 @@ public:
int getDefaultWidth() const; int getDefaultWidth() const;
int getDefaultHeight() const; int getDefaultHeight() const;
void addOpenedFile(std::string path); void addOpenedFile(std::string_view path);
void clearOpenedFiles(); void clearOpenedFiles();
std::vector<std::string> getOpenedFiles() const; std::vector<std::string> getOpenedFiles() const;
@ -160,7 +160,7 @@ public:
GFXTexture* get_material_preview(Material& material); GFXTexture* get_material_preview(Material& material);
GFXTexture* get_mesh_preview(Mesh& mesh); GFXTexture* get_mesh_preview(Mesh& mesh);
GFXTexture* get_texture_preview(Texture& texture); GFXTexture* get_texture_preview(Texture& texture);
GFXTexture* generate_common_preview(Scene& scene, const prism::float3 camera_position); GFXTexture* generate_common_preview(Scene& scene, prism::float3 camera_position);
template<typename T> template<typename T>
GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) { GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) {
@ -193,7 +193,7 @@ public:
} }
} }
GFXTexture* get_asset_thumbnail(const prism::path path) { GFXTexture* get_asset_thumbnail(const prism::path& path) {
if(asset_thumbnails.count(path.string())) { if(asset_thumbnails.count(path.string())) {
return asset_thumbnails[path.string()]; return asset_thumbnails[path.string()];
} else { } else {
@ -303,7 +303,7 @@ public:
} }
template<class T> template<class T>
void open_asset(const AssetType type, const std::function<void(prism::path path)> func_ptr) { void open_asset(const AssetType type, const std::function<void(prism::path)>& func_ptr) {
current_asset_type = type; current_asset_type = type;
open_asset_popup = true; open_asset_popup = true;
on_asset_select = func_ptr; on_asset_select = func_ptr;
@ -353,10 +353,6 @@ private:
void editTransform(Object object, Transform transform); void editTransform(Object object, Transform transform);
void editRenderable(Renderable& mesh); void editRenderable(Renderable& mesh);
void edit_asset_mesh(const char* name, AssetPtr<Mesh>& asset);
void edit_asset_texture(const char* name, AssetPtr<Texture>& asset);
void edit_asset_material(const char* name, AssetPtr<Material>& asset);
}; };
inline void editPath(const char* label, std::string& path, bool editable = true, const std::function<void()> on_selected = nullptr) { inline void editPath(const char* label, std::string& path, bool editable = true, const std::function<void()> on_selected = nullptr) {

View file

@ -6,15 +6,11 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "engine.hpp" #include "engine.hpp"
#include "imguipass.hpp"
#include "file.hpp" #include "file.hpp"
#include "json_conversions.hpp"
#include "platform.hpp" #include "platform.hpp"
#include "transform.hpp" #include "transform.hpp"
#include "log.hpp" #include "log.hpp"
#include "shadowpass.hpp" #include "shadowpass.hpp"
#include "string_utils.hpp"
#include "assertions.hpp"
#include "gfx.hpp" #include "gfx.hpp"
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "imgui_utility.hpp" #include "imgui_utility.hpp"
@ -46,7 +42,7 @@ const std::map<ImGuiKey, InputButton> imToPl = {
{ImGuiKey_Z, InputButton::Z} {ImGuiKey_Z, InputButton::Z}
}; };
CommonEditor::CommonEditor(std::string id) : id(id) { CommonEditor::CommonEditor(const std::string_view id) : id(id) {
prism::set_domain_path(prism::domain::app, "{resource_dir}/data"); prism::set_domain_path(prism::domain::app, "{resource_dir}/data");
prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders"); prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders");
@ -265,7 +261,7 @@ void CommonEditor::begin_frame() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::Text(p.c_str()); ImGui::Text("%s", p.c_str());
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
@ -303,8 +299,8 @@ int CommonEditor::getDefaultHeight() const {
return defaultHeight; return defaultHeight;
} }
void CommonEditor::addOpenedFile(std::string path) { void CommonEditor::addOpenedFile(const std::string_view path) {
lastOpenedFiles.push_back(path); lastOpenedFiles.emplace_back(path.data());
} }
void CommonEditor::clearOpenedFiles() { void CommonEditor::clearOpenedFiles() {
@ -430,7 +426,7 @@ void CommonEditor::editRenderable(Renderable& mesh) {
} }
if(ImGui::Button("Add material")) if(ImGui::Button("Add material"))
mesh.materials.push_back({}); mesh.materials.emplace_back();
} }
void editLight(Light& light) { void editLight(Light& light) {
@ -706,7 +702,7 @@ void CommonEditor::set_undo_stack(UndoStack *stack) {
current_stack = stack; current_stack = stack;
} }
bool mesh_readable(const prism::path path) { bool mesh_readable(const prism::path& path) {
auto file = prism::open_file(path); auto file = prism::open_file(path);
if(!file.has_value()) { if(!file.has_value()) {
prism::log("Failed to load mesh from {}!", path.string()); prism::log("Failed to load mesh from {}!", path.string());
@ -719,7 +715,7 @@ bool mesh_readable(const prism::path path) {
return version == 5 || version == 6; return version == 5 || version == 6;
} }
bool material_readable(const prism::path path) { bool material_readable(const prism::path& path) {
auto file = prism::open_file(path); auto file = prism::open_file(path);
if(!file.has_value()) { if(!file.has_value()) {
prism::log("Failed to load material from {}!", path.string()); prism::log("Failed to load material from {}!", path.string());

View file

@ -7,8 +7,6 @@
#include "file.hpp" #include "file.hpp"
#include "gfx.hpp" #include "gfx.hpp"
#include "asset.hpp" #include "asset.hpp"
#include "log.hpp"
#include "materialcompiler.hpp"
#include "renderer.hpp" #include "renderer.hpp"
struct BillPushConstant { struct BillPushConstant {
@ -261,7 +259,7 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
struct DebugBillboard { struct DebugBillboard {
prism::float3 position; prism::float3 position;
GFXTexture* texture; GFXTexture* texture = nullptr;
prism::float4 color; prism::float4 color;
}; };
@ -561,7 +559,7 @@ void DebugPass::get_selected_object(int x, int y, std::function<void(SelectableO
engine->get_gfx()->copy_texture(selectTexture, selectBuffer); engine->get_gfx()->copy_texture(selectTexture, selectBuffer);
uint8_t* mapped_texture = reinterpret_cast<uint8_t*>(engine->get_gfx()->get_buffer_contents(selectBuffer)); auto mapped_texture = reinterpret_cast<uint8_t*>(engine->get_gfx()->get_buffer_contents(selectBuffer));
const int buffer_position = 4 * (y * extent.width + x); const int buffer_position = 4 * (y * extent.width + x);

View file

@ -9,7 +9,6 @@
#include "file.hpp" #include "file.hpp"
#include "json_conversions.hpp" #include "json_conversions.hpp"
#include "platform.hpp" #include "platform.hpp"
#include "screen.hpp"
#include "cutscene.hpp" #include "cutscene.hpp"
Shot* currentShot = nullptr; Shot* currentShot = nullptr;
@ -19,7 +18,7 @@ PositionKeyFrame* currentFrame = nullptr;
std::string currentPath; std::string currentPath;
void app_main(prism::engine* engine) { void app_main(prism::engine* engine) {
CommonEditor* editor = (CommonEditor*)engine->get_app(); auto editor = (CommonEditor*)engine->get_app();
platform::open_window("Cutscene Editor", platform::open_window("Cutscene Editor",
{editor->getDefaultX(), {editor->getDefaultX(),
@ -80,16 +79,16 @@ void CutsceneEditor::drawUI() {
if(ImGui::MenuItem("New", "CTRL+N")) { if(ImGui::MenuItem("New", "CTRL+N")) {
engine->cutscene = std::make_unique<Cutscene>(); engine->cutscene = std::make_unique<Cutscene>();
platform::set_window_title(0, "Cutscene Editor"); platform::set_window_title(engine->get_main_window(), "Cutscene Editor");
} }
if(ImGui::MenuItem("Open", "CTRL+O")) { if(ImGui::MenuItem("Open", "CTRL+O")) {
platform::open_dialog(true, [this](std::string path){ engine->get_imgui().open_dialog(true, [this](std::string path){
currentPath = path; currentPath = path;
engine->load_cutscene(path); engine->load_cutscene(path);
platform::set_window_title(0, ("Cutscene Editor - " + path).c_str()); platform::set_window_title(engine->get_main_window(), ("Cutscene Editor - " + path).c_str());
addOpenedFile(path); addOpenedFile(path);
}); });
@ -200,7 +199,7 @@ void CutsceneEditor::drawUI() {
if(ImGui::Begin("Timeline")) { if(ImGui::Begin("Timeline")) {
if(engine->cutscene != nullptr) { if(engine->cutscene != nullptr) {
if(ImGui::Button("Add Shot")) { if(ImGui::Button("Add Shot")) {
engine->cutscene->shots.push_back(Shot()); engine->cutscene->shots.emplace_back();
currentShot = &engine->cutscene->shots.back(); currentShot = &engine->cutscene->shots.back();
} }
@ -279,7 +278,7 @@ void CutsceneEditor::drawUI() {
ImGui::BeginChild("animations", ImVec2(150, -1), true); ImGui::BeginChild("animations", ImVec2(150, -1), true);
if(ImGui::Button("Add Channel")) { if(ImGui::Button("Add Channel")) {
currentShot->channels.push_back(AnimationChannel()); currentShot->channels.emplace_back();
currentChannel = &currentShot->channels.back(); currentChannel = &currentShot->channels.back();
} }
@ -303,7 +302,7 @@ void CutsceneEditor::drawUI() {
if(currentChannel != nullptr) { if(currentChannel != nullptr) {
if(ImGui::Button("Add Position Frame")) { if(ImGui::Button("Add Position Frame")) {
currentChannel->positions.push_back(PositionKeyFrame()); currentChannel->positions.emplace_back();
currentFrame = &currentChannel->positions.back(); currentFrame = &currentChannel->positions.back();
} }
@ -383,8 +382,8 @@ void CutsceneEditor::drawUI() {
ImVec2 a = ImVec2(p.x + (keyframe.time * 5) - 5, p.y - 5); ImVec2 a = ImVec2(p.x + (keyframe.time * 5) - 5, p.y - 5);
ImVec2 b = ImVec2(p.x + (keyframe.time * 5) + 5, p.y + 5); ImVec2 b = ImVec2(p.x + (keyframe.time * 5) + 5, p.y + 5);
auto c = ImGui::GetMousePos(); auto mouse_pos = ImGui::GetMousePos();
if(c.x > a.x && c.x < b.x && c.y > a.y && c.y < b.y) { if(mouse_pos.x > a.x && mouse_pos.x < b.x && mouse_pos.y > a.y && mouse_pos.y < b.y) {
if(currentFrame == &keyframe) { if(currentFrame == &keyframe) {
currentFrame = nullptr; currentFrame = nullptr;
} else { } else {

View file

@ -58,11 +58,11 @@ public:
void updateEditor(float deltaTime) override; void updateEditor(float deltaTime) override;
void object_selected(Object object) override; void object_selected(Object object) override;
void asset_selected(std::filesystem::path path, AssetType type) override; void asset_selected(const std::filesystem::path& path, AssetType type) override;
private: private:
void open_asset(const prism::path path); void open_asset(prism::path path);
void setup_editor(Editor* editor); void setup_editor(Editor* editor);
}; };
std::string get_filename(const std::string path); std::string get_filename(std::string path);

View file

@ -179,12 +179,12 @@ void MaterialEditor::draw(CommonEditor* editor) {
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
Scene* scene = engine->get_scene(); auto viewport_scene = engine->get_scene();
if(scene != nullptr) { if(viewport_scene != nullptr) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
if(begin("Viewport")) if(begin("Viewport"))
editor->drawViewport(scene); editor->drawViewport(viewport_scene);
ImGui::End(); ImGui::End();
@ -223,12 +223,6 @@ void MaterialEditor::draw(CommonEditor* editor) {
ImGui::ItemAdd(input_rect, ImGui::GetID(node.get())); ImGui::ItemAdd(input_rect, ImGui::GetID(node.get()));
bool might_connect = false;
if(dragging_connector && ImGui::IsItemHovered()) {
might_connect = true;
}
if(dragging_connector && ImGui::IsItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { if(dragging_connector && ImGui::IsItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
input.connected_connector = drag_connector; input.connected_connector = drag_connector;
input.connected_node = dragging_node; input.connected_node = dragging_node;
@ -331,8 +325,8 @@ void MaterialEditor::draw(CommonEditor* editor) {
ImGui::EndChild(); ImGui::EndChild();
for(auto& node : deferred_deletions) { for(auto& node_to_delete : deferred_deletions) {
material->delete_node(node); material->delete_node(node_to_delete);
changed = true; changed = true;
} }

View file

@ -65,9 +65,9 @@ void PrefabEditor::draw(CommonEditor* editor) {
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
Scene* scene = engine->get_scene(); auto viewport_scene = engine->get_scene();
if(scene != nullptr) { if(viewport_scene != nullptr) {
auto window_class = get_window_class(); auto window_class = get_window_class();
if(showOutliner) { if(showOutliner) {
@ -92,7 +92,7 @@ void PrefabEditor::draw(CommonEditor* editor) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
if(begin("Viewport")) if(begin("Viewport"))
editor->drawViewport(scene); editor->drawViewport(viewport_scene);
ImGui::End(); ImGui::End();

View file

@ -117,9 +117,7 @@ struct OpenAssetRequest {
std::vector<OpenAssetRequest> open_requests; std::vector<OpenAssetRequest> open_requests;
void PrismEditor::setup_editor(Editor* editor) { void PrismEditor::setup_editor(Editor*) {}
}
void PrismEditor::open_asset(const prism::path path) { void PrismEditor::open_asset(const prism::path path) {
if(path.extension() == ".prefab") { if(path.extension() == ".prefab") {
@ -315,7 +313,7 @@ void PrismEditor::object_selected(Object object) {
selected_object = object; selected_object = object;
} }
void PrismEditor::asset_selected(std::filesystem::path path, AssetType) { void PrismEditor::asset_selected(const std::filesystem::path& path, AssetType) {
open_requests.emplace_back(path.string(), true); open_requests.emplace_back(path.string(), true);
} }

View file

@ -129,8 +129,8 @@ void SceneEditor::draw(CommonEditor* editor) {
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
Scene* scene = engine->get_scene(); auto viewport_scene = engine->get_scene();
if(scene != nullptr) { if(viewport_scene != nullptr) {
if(showSceneSettings) { if(showSceneSettings) {
if(begin("Scene Settings", &showSceneSettings)) { if(begin("Scene Settings", &showSceneSettings)) {
@ -156,7 +156,7 @@ void SceneEditor::draw(CommonEditor* editor) {
if(showViewport) { if(showViewport) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
if(begin("Viewport", &showViewport)) if(begin("Viewport", &showViewport))
editor->drawViewport(scene); editor->drawViewport(viewport_scene);
ImGui::PopStyleVar(); ImGui::PopStyleVar();

View file

@ -4,7 +4,6 @@
#include <array> #include <array>
#include <iostream> #include <iostream>
#include <stb_rect_pack.h>
#include <stb_truetype.h> #include <stb_truetype.h>
constexpr std::array sizes_to_pack = { constexpr std::array sizes_to_pack = {
@ -74,11 +73,11 @@ int main(int argc, char* argv[]) {
fwrite(&descent, sizeof(int), 1, file); fwrite(&descent, sizeof(int), 1, file);
fwrite(&gap, sizeof(int), 1, file); fwrite(&gap, sizeof(int), 1, file);
for(int i = 0; i < sizes_to_pack.size(); i++) for(auto& packed_char : packed_chars)
fwrite(&packed_chars[i], sizeof(packed_chars[i]), 1, file); fwrite(&packed_char, sizeof(packed_char), 1, file);
for(int i = 0; i < sizes_to_pack.size(); i++) { for(auto& range : ranges) {
const float f = (ascent + descent) * stbtt_ScaleForPixelHeight(&font_info, ranges[i].font_size); const float f = (ascent + descent) * stbtt_ScaleForPixelHeight(&font_info, range.font_size);
fwrite(&f, sizeof(float), 1, file); fwrite(&f, sizeof(float), 1, file);
} }

View file

@ -18,7 +18,7 @@
#include "platform.hpp" #include "platform.hpp"
#include "utility.hpp" #include "utility.hpp"
void app_main(Engine* engine) { void app_main(prism::engine* engine) {
ModelEditor* editor = (ModelEditor*)engine->get_app(); ModelEditor* editor = (ModelEditor*)engine->get_app();
if(utility::contains(engine->command_line_arguments, "--no_ui")) if(utility::contains(engine->command_line_arguments, "--no_ui"))

View file

@ -1,4 +1,3 @@
#include <fstream>
#include <sstream> #include <sstream>
#include <filesystem> #include <filesystem>
@ -6,7 +5,7 @@
#include "log.hpp" #include "log.hpp"
#include "string_utils.hpp" #include "string_utils.hpp"
bool has_extension(const std::filesystem::path path, const std::string_view extension) { bool has_extension(const std::filesystem::path& path, const std::string_view extension) {
return string_contains(path.filename().string(), extension); return string_contains(path.filename().string(), extension);
} }
@ -58,12 +57,6 @@ int main(int argc, char* argv[]) {
out.write((char*)spirv.data(), spirv.size() * sizeof(uint32_t)); out.write((char*)spirv.data(), spirv.size() * sizeof(uint32_t));
} }
break; break;
case ShaderLanguage::MSL:
{
std::ofstream out(destination_path); // remove .glsl
out << compiled_source->as_string();
}
break;
default: default:
break; break;
} }