Skip to content

Commit

Permalink
apparently its 2024?
Browse files Browse the repository at this point in the history
 - vk::throwResultException got moved to vk::detail::throwResultException
    - not sure why, it's convenient so I'm gonna keep using it anyway
 - update fmtlib to latest release
    - clean up Logging and make it use vformat to improve compile times and code bloat
    - added a format_consteval function to Strings.hpp that formats a stack string at compile time
 - update imgui to a merged version of docking/string_view
    - FINALLY I could remove most of the string_view wrappers as ImStrv makes them redundant
    - CStrView is gone, the few remaining functions that take c strings are still re-implemented
    - merged HoverTooltip and HoverTooltipFixed, pass dir=None for automatic placement
       - added a "delay" param to handle the new delay feature in imgui
       - added a "dir" param that specifies where the tooltip should appear
       - take format str and args as params so that the format string can be lazily evaluated
    - added a new function "AutoArrange" that automatically arranges widgets over one or more lines
    - added "if_Table" helper for BeginTable/EndTable
    - added IMPLUS_WITH macro for use with Scope/Style helpers
       - automatically generates a variable name so you don't need to come up with one
 - update miniaudio, update sound file loading to match new api
 - removed lean mean cpp option parser, which I don't think I ever used
    - there are much better newer libs to use for when I eventually need option parsing
 - update catch, update the tests
    - Approx was depreciated, replaced sq::Approx with new Matchers
 - added tl::expected to redist, a std::expected implementation for c++20
 - added *_config.hpp files for miniaudio, stb_image, and yyjson with defines for each lib
 - print out basic platform/compiler info when running an Application
 - rework ResourceCache/Handle
    - renamed try_acquire to acquire_safe for consistency with other sqee functions
    - added an error string member to Resource
    - instead of returning a null handle on failure, an error resource is created
    - error resources have no value, instead they have an error string
 - added basic support for c++ class inheritence to WrenPlus
    - current implementation just dynamic_casts to every type listed until something works
    - no support for multiple inheritence or multiple levels of inheritence
    - changed Exception to just inherit from runtime_error instead of storing a std::string
 - new features for DrawItem
    - added a check_visibility method, along with visDataType and visSampleOffset fields
       - this allows animations to disable items completely
    - added ConstPackedBits as a new ParamType
       - this is intended for use with "ubershaders", like the one for brawl effects in STS
    - added ConstTexTransform as a new ParamType
       - so far only used for identity transforms to reduce shader permutations
    - added an order field that can be used to explicitly sort items within a pass
 - Pipeline now checks that push constants with the same name or offset match between stages
 - cleaned up maths code and made a bunch more things constexpr
    - finally removed the non-standard anonymous structs
    - fixed maths::srgb_to_linear
    - didn't touch Culling or Volumes coz that stuff needs a lot more work
 - added split_string utility function to Parsing that takes delimiters as template args
 - added acquire_safe method to ResourceCache that returns an expected
 - replace nlohmann json with yyjson + custom c++ wrappers
    - parsing is now much, much faster, and the api is also more convenient
    - PipelineCache now uses a minified string as a key rather than a json value
 - added three new core headers, TypeAliases, TypeTraits, and TypeNames
    - TypeAliases is similar to the old Types.hpp, except:
       - where possible, things are forward declarations instead of full includes
       - does not include random non-alias types like std::vector or std::map
       - I do want phase out Types.hpp, but don't want to bloat this commit even more
    - TypeTraits.hpp is a centralised place for concepts and variable templates
    - TypeNames.hpp replaces the old type_to_string functions that were all over the place
       - uses format_consteval to support arbitary template params
 - greatly simplified SQEE_ENUM_HELPER
    - added new generic SQEE_COUNT_ARGS and SQEE_STRINGIFY_ARGS macros to Macros.hpp
    - with these + cpp20 using enum it's possible to get rid of the EnumTraits struct completely
    - replaced has_enum_traits_v with a HasEnumHelper concept
 - fixed building with clang/libc++
 - build sqee with -wpedantic now that the anonymous structs are gone
 - added support to Application for reducing update rate after a period of inactivity
    - currently very basic and a bit smelly, but solves the immediate issue of my laptop overheating
  • Loading branch information
jagoly committed Mar 4, 2024
1 parent 714e4fa commit 0fc21f2
Show file tree
Hide file tree
Showing 96 changed files with 126,654 additions and 98,122 deletions.
6 changes: 5 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
[submodule "libs/fmt"]
path = libs/fmt
url = https://github.com/fmtlib/fmt
branch = 9.0.0
branch = 10.1.1
[submodule "libs/yyjson"]
path = libs/yyjson
url = https://github.com/ibireme/yyjson.git
branch = master
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ endif ()

if (SQEE_GNU OR SQEE_CLANG)

target_compile_options(sqee PRIVATE -Wall -Wextra)
#target_compile_options(sqee PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(sqee PRIVATE -Wall -Wextra -Wpedantic)

if (SQEE_GNU)
target_compile_options(sqee PRIVATE -fconcepts-diagnostics-depth=2)
endif ()

if (NOT SQEE_STATIC_LIB)
target_compile_options(sqee PRIVATE -fvisibility=hidden)
Expand Down
12 changes: 12 additions & 0 deletions include/sqee/app/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SQEE_API Application
/// Close the application.
void quit() { mReturnCode = 0; }

/// Reset timer for going into inactive mode.
void reset_inactivity() { mElapsedSinceActivity = 0.0; }

protected: //=================================================//

/// Called once before the main loop starts.
Expand All @@ -41,6 +44,15 @@ class SQEE_API Application

//--------------------------------------------------------//

/// How long to go without user input before limiting update rate.
double mMaxInactivePeriod = INFINITY;

/// How often should we update when inactive.
double mMinSleepUpdatePeriod = 0.0;

/// Set to zero when the user interacts with the application.
double mElapsedSinceActivity = 0.0;

/// Set to a non-negative value to quit.
int mReturnCode = -1;

Expand Down
435 changes: 165 additions & 270 deletions include/sqee/app/GuiWidgets.hpp

Large diffs are not rendered by default.

36 changes: 33 additions & 3 deletions include/sqee/app/WrenForward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class WrenPlusVM;
#define WRENPLUS_TRAITS_HEADER(Type) \
template<> struct wren::Traits<Type> : std::true_type \
{ \
static const char* const module; \
static const char* const className; \
static const size_t index; \
static const char* const module; \
static const char* const className; \
static const size_t index; \
};

#define WRENPLUS_TRAITS_DEFINITION(Type, Module, ClassName) \
Expand All @@ -61,6 +61,36 @@ const size_t wren::Traits<Type>::index = wren::detail::generate_type_index();

//============================================================================//

#define WRENPLUS_BASE_CLASS_HEADER(BaseType) \
template <> \
struct wren::SlotHelper<BaseType*> \
{ \
static BaseType* get(WrenVM* vm, int slot, WrenType slotType); \
static void set(WrenVM* vm, int slot, BaseType* ptr); \
};

#define WRENPLUS_BASE_CLASS_DEFINITION(BaseType, ...) \
BaseType* wren::SlotHelper<BaseType*>::get(WrenVM* vm, int slot, WrenType slotType) \
{ \
if (slotType == WREN_TYPE_FOREIGN) \
{ \
const auto& data = *static_cast<detail::TaggedPointer*>(wrenGetSlotForeign(vm, slot)); \
return detail::base_class_slot_helper_get_inner<BaseType, __VA_ARGS__>(data); \
} \
if (slotType == WREN_TYPE_NULL) \
return nullptr; \
throw Exception("slot does not hold Object*"); \
} \
void wren::SlotHelper<BaseType*>::set(WrenVM* vm, int slot, BaseType* ptr) \
{ \
if (ptr != nullptr) \
detail::base_class_slot_helper_set_inner<BaseType, __VA_ARGS__>(vm, slot, ptr); \
else \
wrenSetSlotNull(vm, slot); \
}

//============================================================================//

#define WRENPLUS_ADD_METHOD(Pvm, Class, Method, Signature) \
Pvm.register_method<&Class::Method, Class>(Signature)

Expand Down
98 changes: 57 additions & 41 deletions include/sqee/app/WrenPlus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,14 @@ namespace wren {
//============================================================================//

/// General exception to throw from functions bound to wren.
struct Exception final : public std::exception
struct Exception final : public std::runtime_error
{
Exception(std::string str) : message(std::move(str)) {}
Exception(const char* cstr) : std::runtime_error(cstr) {}
Exception(const std::string& str) : std::runtime_error(str) {}

template <class... Args>
// todo: temporary workaround for an internal compiler error
#ifdef SQEE_MSVC
Exception(std::string_view str, Args&&... args) : message(fmt::format(fmt::runtime(str), std::forward<Args>(args)...)) {}
#else
Exception(fmt::format_string<Args...> str, Args&&... args) : message(fmt::format(str, std::forward<Args>(args)...)) {}
#endif

const char* what() const noexcept override { return message.c_str(); }

std::string message;
Exception(fmt::format_string<Args...> fstr, Args&&... args)
: std::runtime_error(fmt::vformat(fstr, fmt::make_format_args(args...))) {}
};

/// Minimal either type used for returning errors as strings.
Expand Down Expand Up @@ -238,7 +231,7 @@ class WRENPLUS_API WrenPlusVM
mErrorString.clear();

if (wrenCall(mWrenVM, method) != WREN_RESULT_SUCCESS)
throw Exception(std::move(mErrorString));
throw Exception(mErrorString);

return get_slot<Result>(mWrenVM, 0);
}
Expand All @@ -251,14 +244,14 @@ class WRENPLUS_API WrenPlusVM
mErrorString.clear();

if (wrenCall(mWrenVM, method) != WREN_RESULT_SUCCESS)
throw Exception(std::move(mErrorString));
throw Exception(mErrorString);
}

//--------------------------------------------------------//

/// Call a wren method with the given arguments and return the result or any errors.
template <class Result, class Receiver, class... Args>
SafeResult<Result> safe_call[[nodiscard]](WrenHandle* method, Receiver receiver, const Args&... args) noexcept
[[nodiscard]] SafeResult<Result> safe_call(WrenHandle* method, Receiver receiver, const Args&... args) noexcept
{
set_call_slots<Receiver, Args...>(mWrenVM, receiver, args...);
mErrorString.clear();
Expand All @@ -276,7 +269,7 @@ class WRENPLUS_API WrenPlusVM

/// Call a wren method with the given arguments and return any errors.
template <class Receiver, class... Args>
std::string safe_call_void[[nodiscard]](WrenHandle* method, Receiver receiver, const Args&... args) noexcept
[[nodiscard]] std::string safe_call_void(WrenHandle* method, Receiver receiver, const Args&... args) noexcept
{
set_call_slots<Receiver, Args...>(mWrenVM, receiver, args...);
mErrorString.clear();
Expand All @@ -293,33 +286,21 @@ class WRENPLUS_API WrenPlusVM
void interpret(const char* module, const char* source);

/// Same as interpret, but return errors as a string.
std::string safe_interpret[[nodiscard]](const char* module, const char* source);
[[nodiscard]] std::string safe_interpret(const char* module, const char* source);

/// Interpret a module from file, as if using import.
void load_module(const char* module);

/// Same as load_module, but return errors as a string.
std::string safe_load_module(const char* module);
[[nodiscard]] std::string safe_load_module(const char* module);

/// Makes sure that no foreign class indices are missing.
void validate_class_handle_cache();

//--------------------------------------------------------//

/// Lookup a variable that is known to exist.
WrenHandle* get_variable(const char* module, const char* variable);

//--------------------------------------------------------//

/// Abort the current wren fiber with a formatted error message.
//template <class... Args>
//void abort(fmt::format_string<Args...> str, Args&&... args) noexcept
//{
// const std::string message = fmt::format(str, std::forward<Args>(args)...);
// wrenEnsureSlots(mWrenVM, 1);
// wrenSetSlotBytes(mWrenVM, 0, message.data(), message.length());
// wrenAbortFiber(mWrenVM, 0);
//}
[[nodiscard]] WrenHandle* get_variable(const char* module, const char* variable);

private: //===================================================//

Expand Down Expand Up @@ -351,7 +332,7 @@ class WRENPLUS_API WrenPlusVM

std::vector<std::string> mModuleImportDirs;

std::map<std::string, WrenForeignMethodFn> mForiegnMethods;
std::map<std::string, WrenForeignMethodFn> mForeignMethods;

std::vector<WrenHandle*> mForeignClassHandles;

Expand Down Expand Up @@ -406,6 +387,41 @@ struct MethodWrapper<Result(*)(Object*, Args...), FnPtr>
}
};

/// Internal data for foreign objects.
struct TaggedPointer
{
void* ptr;
size_t index;
};

template <class BaseType, class Type, class... Types>
inline BaseType* base_class_slot_helper_get_inner(const TaggedPointer& data)
{
if (data.index == Traits<Type>::index)
return static_cast<BaseType*>(data.ptr);

if constexpr (sizeof...(Types) != 0)
return base_class_slot_helper_get_inner<BaseType, Types...>(data);

throw Exception("slot holds different type of Object");
}

template <class BaseType, class Type, class... Types>
inline void base_class_slot_helper_set_inner(WrenVM* vm, int slot, BaseType* ptr)
{
if (dynamic_cast<Type*>(ptr) != nullptr)
{
wrenSetSlotHandle(vm, slot, WrenPlusVM::access(vm).get_class_handle<Type>());
auto& data = *static_cast<TaggedPointer*>(wrenSetSlotNewForeign(vm, slot, slot, sizeof(TaggedPointer)));
data = { ptr, Traits<Type>::index };
}

else if constexpr (sizeof...(Types) != 0)
base_class_slot_helper_set_inner<BaseType, Types...>(vm, slot, ptr);

else throw Exception("dynamic_cast failed for base ptr");
}

} // namespace detail

} // namespace wren
Expand All @@ -426,16 +442,16 @@ struct wren::SlotHelper<std::nullptr_t>
template <class Object>
struct wren::SlotHelper<Object*, std::enable_if_t<wren::has_traits_v<Object>>>
{
struct TaggedPointer { Object* ptr; size_t index; };

static Object* get(WrenVM* vm, int slot, WrenType slotType)
{
if (slotType == WREN_TYPE_FOREIGN)
{
const auto& data = *static_cast<TaggedPointer*>(wrenGetSlotForeign(vm, slot));
if (data.index != Traits<Object>::index)
throw Exception("slot holds different type of Object");
return data.ptr;
const auto& data = *static_cast<detail::TaggedPointer*>(wrenGetSlotForeign(vm, slot));

if (data.index == Traits<Object>::index)
return static_cast<Object*>(data.ptr);

throw Exception("slot holds different type of Object");
}

if (slotType == WREN_TYPE_NULL)
Expand All @@ -449,7 +465,7 @@ struct wren::SlotHelper<Object*, std::enable_if_t<wren::has_traits_v<Object>>>
if (ptr != nullptr)
{
wrenSetSlotHandle(vm, slot, WrenPlusVM::access(vm).get_class_handle<Object>());
auto& data = *static_cast<TaggedPointer*>(wrenSetSlotNewForeign(vm, slot, slot, sizeof(TaggedPointer)));
auto& data = *static_cast<detail::TaggedPointer*>(wrenSetSlotNewForeign(vm, slot, slot, sizeof(detail::TaggedPointer)));
data = { ptr, Traits<Object>::index };
}
else wrenSetSlotNull(vm, slot);
Expand Down Expand Up @@ -656,8 +672,8 @@ struct wren::SlotHelper<std::vector<Type>>
#include <sqee/core/EnumHelper.hpp>

/// Specialisation for the sqee enum helper.
template <class Enum>
struct wren::SlotHelper<Enum, std::enable_if_t<sq::has_enum_traits_v<Enum>>>
template <sq::HasEnumHelper Enum>
struct wren::SlotHelper<Enum>
{
static Enum get(WrenVM* vm, int slot, WrenType slotType)
{
Expand Down
Loading

0 comments on commit 0fc21f2

Please sign in to comment.