Skip to content

Commit

Permalink
increased file buffer size
Browse files Browse the repository at this point in the history
also moved file buffer onto the heap to reduce stack consumption
  • Loading branch information
cyanskies committed Aug 14, 2023
1 parent 2b41001 commit 41513fb
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 46 deletions.
9 changes: 0 additions & 9 deletions hades/include/hades/yaml_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@

#include "hades/parser.hpp"

//TODO: remove
namespace YAML
{
class Node;
}

namespace hades::data
{
using yaml_parse_exception = parser_exception;

class parser_node;
//NOTE: throws yaml_parse_exception on error
std::unique_ptr<parser_node> make_yaml_parser(std::string_view src);
std::unique_ptr<parser_node> make_yaml_parser(std::istream& in);
//TODO: remove
[[deprecated]] std::unique_ptr<parser_node> make_yaml_parser(const YAML::Node &src);
}

#endif //HADES_YAML_PARSER_HPP
4 changes: 3 additions & 1 deletion hades/source/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace hades

data::set_default_parser(data::make_parser_f{ data::make_yaml_parser });
data::set_default_parser(data::make_parser2_f{ data::make_yaml_parser });
data::set_parser(data::make_parser_f{ data::make_yaml_parser }, ".yaml");
data::set_parser(data::make_parser2_f{ data::make_yaml_parser }, ".yaml");
data::set_default_writer(data::make_writer_f{ data::make_yaml_writer });

if (app_resources)
Expand Down Expand Up @@ -383,7 +385,7 @@ namespace hades

#ifndef NDEBUG
//check for floating point exceptions
assert_floating_point_exceptions();
//assert_floating_point_exceptions();
#endif
}

Expand Down
11 changes: 6 additions & 5 deletions hades/source/data_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ namespace hades::data
return out.first->second;
}

// TODO: redo this func
// TODO: redo this func, see parseYaml
template<typename YAMLPARSER>
static void parseInclude(unique_id mod, std::string_view file, const data::mod& mod_info, YAMLPARSER &&yamlParser)
static void parseInclude(unique_id mod, const std::filesystem::path &file, const data::mod& mod_info, YAMLPARSER &&yamlParser)
{
try
{
auto include_yaml = files::stream_resource(mod_info, file);
const auto parser = data::make_parser(include_yaml);
const auto parser = data::make_parser(include_yaml, file.extension());
std::invoke(std::forward<YAMLPARSER>(yamlParser), mod, *parser);
}
catch (const files::file_error& f)
Expand All @@ -330,7 +330,7 @@ namespace hades::data
}
catch (const parser_exception& e)
{
const auto message = to_string(e.what()) + " while parsing: " + mod_info.name + "/" + to_string(file);
const auto message = to_string(e.what()) + " while parsing: "s + mod_info.name + "/"s + file.string();
LOGERROR(message);
}

Expand Down Expand Up @@ -392,6 +392,7 @@ namespace hades::data
return;
}

// TODO: doesn't parse yaml, restructure this and the loose parseInclude
void data_system::parseYaml(unique_id mod, const data::parser_node& root)
{
//loop though each of the root level nodes and pass them off
Expand Down Expand Up @@ -420,7 +421,7 @@ namespace hades::data
continue;
mod_res.includes.emplace_back(s);
_data_file = s;
parseInclude(mod, s, mod_res, yaml_parser);
parseInclude(mod, _data_file, mod_res, yaml_parser);
}

_data_file = data_source;
Expand Down
30 changes: 22 additions & 8 deletions libs/basic/include/hades/archive_streams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@
namespace hades
{
//buffer of bytes
// TODO: deprecate
using buffer = std::vector<std::byte>;
//NOTE: consider moving to 8kb(8192)
constexpr auto default_buffer_size = std::size_t{ 4096 }; //4kb buffer
//NOTE: buffer sizes:
// 16kb(16384)
// 8kb(8192)
// 4kb(4096)
// 2kb(2048)
constexpr auto default_buffer_size = std::size_t{ 8192 };

namespace detail
{
template<typename CharT>
constexpr std::vector<CharT> make_default_buffer()
{
return std::vector<CharT>(default_buffer_size, CharT{});
}
}
}

namespace hades::files
Expand Down Expand Up @@ -300,8 +314,8 @@ namespace hades::zip
void _seek_beg() noexcept;
bool _start_zlib() noexcept;

std::array<char_type, default_buffer_size> _get_area;
std::array<std::byte, default_buffer_size> _device_buffer;
std::vector<char_type> _get_area = hades::detail::make_default_buffer<char_type>();
std::vector<std::byte> _device_buffer = hades::detail::make_default_buffer<std::byte>();
detail::z_stream_p _zip_stream = detail::make_z_stream();
detail::file_ptr _file;
std::streamsize _pos = {};
Expand Down Expand Up @@ -378,8 +392,8 @@ namespace hades::zip
void _empty_device_buffer();
bool _start_zlib() noexcept;

std::array<char_type, default_buffer_size> _put_area;
std::array<std::byte, default_buffer_size> _device_buffer;
std::vector<char_type> _put_area = hades::detail::make_default_buffer<char_type>();
std::vector<std::byte> _device_buffer = hades::detail::make_default_buffer<std::byte>();
detail::z_stream_p _zip_stream = detail::make_z_stream();
detail::file_ptr _file;
};
Expand Down Expand Up @@ -583,7 +597,7 @@ namespace hades::zip
int_type _readsome();
std::size_t _pos() const noexcept;

std::array<char_type, default_buffer_size> _get_area;
std::vector<char_type> _get_area = hades::detail::make_default_buffer<char_type>();
unarchive _archive;
};

Expand Down Expand Up @@ -703,7 +717,7 @@ namespace hades::zip
private:
void _consume_buffer();

std::array<char_type, default_buffer_size> _put_area = {};
std::vector<char_type> _put_area = hades::detail::make_default_buffer<char_type>();
toarchive _archive;
};

Expand Down
13 changes: 10 additions & 3 deletions libs/basic/include/hades/parser.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef HADES_PARSER_HPP
#define HADES_PARSER_HPP

#include <filesystem>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -83,9 +84,15 @@ namespace hades::data
void set_default_parser(make_parser_f);
void set_default_parser(make_parser2_f);

//NOTE: can throw parser_exception on error
std::unique_ptr<parser_node> make_parser(std::string_view);
std::unique_ptr<parser_node> make_parser(std::istream&);
// ext = ".yaml"
void set_parser(make_parser_f, std::filesystem::path ext);
void set_parser(make_parser2_f, std::filesystem::path ext);

// Create a parser bound to the source input
// Provide an extension to select a parser dynamically
// NOTE: can throw parser_exception on error
std::unique_ptr<parser_node> make_parser(std::string_view, std::filesystem::path ext = {});
std::unique_ptr<parser_node> make_parser(std::istream&, std::filesystem::path ext = {});

namespace parse_tools
{
Expand Down
53 changes: 47 additions & 6 deletions libs/basic/source/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "hades/parser.hpp"

using namespace std::string_literals;

namespace hades::data
{
// default parsers
static make_parser_f make_parser_ptr = {};
static make_parser2_f make_parser2_ptr = {};

// per-ext parsers
static std::map<std::filesystem::path, make_parser_f> make_parser_table;
static std::map<std::filesystem::path, make_parser2_f> make_parser2_table;

void set_default_parser(make_parser_f f)
{
make_parser_ptr = f;
Expand All @@ -15,15 +22,49 @@ namespace hades::data
make_parser2_ptr = f;
}

std::unique_ptr<parser_node> make_parser(std::string_view s)
void set_parser(make_parser_f f, std::filesystem::path ext)
{
make_parser_table.emplace(std::move(ext), std::move(f));
return;
}

void set_parser(make_parser2_f f, std::filesystem::path ext)
{
make_parser2_table.emplace(std::move(ext), std::move(f));
return;
}

std::unique_ptr<parser_node> make_parser(std::string_view s, std::filesystem::path ext)
{
assert(make_parser_ptr);
return std::invoke(make_parser_ptr, s);
if (ext.empty())
{
// default parser
assert(make_parser_ptr);
return std::invoke(make_parser_ptr, s);
}

// parser for ext
const auto iter = make_parser_table.find(ext);
if (iter != end(make_parser_table))
return std::invoke(iter->second, s);

throw parser_exception{ "unable to find parser for ext: "s + ext.string() };
}

std::unique_ptr<parser_node> make_parser(std::istream& s)
std::unique_ptr<parser_node> make_parser(std::istream& s, std::filesystem::path ext)
{
assert(make_parser2_ptr);
return std::invoke(make_parser2_ptr, s);
if (ext.empty())
{
// default parser
assert(make_parser2_ptr);
return std::invoke(make_parser2_ptr, s);
}

// parser for ext
const auto iter = make_parser2_table.find(ext);
if (iter != end(make_parser2_table))
return std::invoke(iter->second, s);

throw parser_exception{ "unable to find parser for ext: "s + ext.string() };
}
}
18 changes: 9 additions & 9 deletions libs/gui/include/hades/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ namespace hades
const ImGuiPayload* _payload;
};

namespace details
namespace detail
{
template<typename Enum>
concept EnumFlag = requires(Enum a, Enum b)
Expand All @@ -957,41 +957,41 @@ namespace hades

constexpr inline gui::window_flags operator|(gui::window_flags lhs, gui::window_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

//TODO: selectable, combo, etc...
constexpr inline gui::colour_edit_flags operator|(gui::colour_edit_flags lhs, gui::colour_edit_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline gui::input_text_flags operator|(gui::input_text_flags lhs, gui::input_text_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline gui::tree_node_flags operator|(gui::tree_node_flags lhs, gui::tree_node_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline gui::table_flags operator|(gui::table_flags lhs, gui::table_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline gui::table_column_flags operator|(gui::table_column_flags lhs, gui::table_column_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline gui::dragdrop_flags operator|(gui::dragdrop_flags lhs, gui::dragdrop_flags rhs) noexcept
{
return details::enum_or(lhs, rhs);
return detail::enum_or(lhs, rhs);
}

constexpr inline details::EnumFlag auto operator|=(details::EnumFlag auto& a, const details::EnumFlag auto b) noexcept
constexpr inline detail::EnumFlag auto operator|=(detail::EnumFlag auto& a, const detail::EnumFlag auto b) noexcept
{
return a = a | b;
}
Expand Down
11 changes: 6 additions & 5 deletions libs/gui/source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace hades
_main_toolbar_info.width = size.x;
}

constexpr ImGuiKey to_imgui_key(sf::Keyboard::Key k) noexcept
static constexpr ImGuiKey to_imgui_key(sf::Keyboard::Key k) noexcept
{
switch(k)
{
Expand Down Expand Up @@ -442,7 +442,7 @@ namespace hades
}

template<typename Colour>
ImVec4 to_imvec4(const Colour &c) noexcept
static inline ImVec4 to_imvec4(const Colour &c) noexcept
{
return { c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f };
}
Expand Down Expand Up @@ -1298,7 +1298,7 @@ namespace hades
return { v.x, v.y };
}

inline sf::Vertex to_vertex(ImDrawVert vert, vector_float tex_size = { 1.f, 1.f }) noexcept
static inline constexpr sf::Vertex to_vertex(ImDrawVert vert, vector_float tex_size = { 1.f, 1.f }) noexcept
{
const auto col = ImColor{ vert.col }.Value;

Expand Down Expand Up @@ -1332,8 +1332,8 @@ namespace hades
};
}

//NOTE:mixing gl commands in order to get clip clipping scissor glscissor
// this is done through the draw_clamp_window helper
//NOTE: mixing gl commands in order to get clip clipping scissor glscissor
// this is done through the draw_clamp_region helper
void gui::draw(sf::RenderTarget & target, const sf::RenderStates &states) const
{
namespace tex = resources::texture_functions;
Expand Down Expand Up @@ -1361,6 +1361,7 @@ namespace hades
else
{
//get the info needed to denormalise the tex coords.
// used in to_vertex
vector_float texture_size = { 1.f, 1.f };
if (cmd.TextureId)
{
Expand Down

0 comments on commit 41513fb

Please sign in to comment.