Squashed 'deps/nostalgia/' changes from eed115b2..7d9f363b
7d9f363b [nostalgia/core/studio] Show color names in TileSheetEditor ababc2a7 [nostalgia/core/studio] Add Name to colors table in PaletteEditor bfd4bc3c [nostalgia/core] Revise Palette system, give TileSheetEditor a config file 8826d51e [studio] Add configio.hpp to studio.hpp c021e5e7 [ox/oc] Fix OC not dealing with certain int types properly 7d8a8e0e [keel] Cleanup 95a69b72 [ox/std] Fix String::c_str to always retrun a valid C str e4c38660 [nostalgia/core] Fix subsheet resize not to read garbage 67cf3ae8 [ox/std] Ensure ox::String always has at least a null terminator 2761f23d [nostalgia/developer-handbook] Update serialization notes 6c170d31 [nostalgia/developer-handbook] Update serialization notes d20bfc77 [nostalgia/developer-handbook] Update serialization notes 07ecbde1 [nostalgia/developer-handbook] Update notes on error handling fbe2fcd3 [nostalgia/developer-handbook] Update notes on error handling a8bb99b6 [turbine] Remove ClipboardObject::typeMatches 667dd21a [turbine] Make ClipboardObject::typId return a StringView 5d89370c [turbine] Rework getClipboardObject to use ox::ModelTypeId_v b968ec8a [keel] Remove redundant move ec45ffb7 [studio] Fix build error 97dc0274 [nostalgia/core/studio] Add acceptsClipboardPayload to TileSheetEditor a138f60f [studio] Add acceptsClipboardPayload to Editor 791d1950 [turbine] Make ClipboardObject use ox::ModelTypeId_v for typeId 78eb8fca [keel] Cleanup pack logging 0b8051b6 [ox/preloader] Fix alignment issue 5a426829 [nostalgia/core/studio] Cleanup TileSheet selection, fix copy/paste bug 9d2fe0e8 [studio] Add size function to Selection f1894699 [keel] Remove setAsset 27b38ed2 [keel,studio] Fix hotloading for files that get loaded as multiple types 2bb7c514 [studio/modlib] Fix type desc writing logic inversion 5177cfb0 [studio/modlib] Make Project::mkdir only mkdir if dir does not exist f9a14433 [studio/modlib] Add variant of ComboBox that takes callback e62426b0 [keel] Ensure consistent asset IDs in AssetManager af634bd4 [ox/fs] Add FileSystem::exists 49b859ec [studio/modlib] Give Selection constructors 19a41201 [studio/modlib] Make iterateSelection return errors properly f69b8afa [nostalgia] Remove use of deleted function 9c98b5e2 [studio/modlib] Remove color.hpp 1f87216d [nostalgia/core] Add applySelectionColor 94c59604 [nostalgia/core/opengl] Fix for Ox changes 8ee016c1 [studio/modlib] Add SelectionTracker dc20c667 [ox/std] Add conversion functions for geo types, cleanup 407e5424 [ox/std] Remove SmallMap dtor, replace timing code with steady_clock 3b188696 [ox/claw] Remove enum type from ClawFormat 0fab6c7c [ox/preloader] Remove debug code a72b865d [studio/modlib] Add function for exporting selection color c0479604 [studio,nostalgia/studio] Make executing UndoCommands report errors a1c89906 [nostalgia/studio] Make UndoCommand undo/redo return ox::Error 7fb0549c [nostalgia/core] Revert some auto formatting done by CLion... 37e65ab0 [nostalgia/core/studio] Fix Subsheet width to update properly 9105b1ec [ox/std] Fix Linux build fbeb0815 [ox/model] Fix type params in buildTypeId b882a47e [ox/std] Fix resize to set null terminator 660f2f56 [ox/std] Rework FileReader into StreamReader aa83c2a6 [nostalgia/core/studio] Remove some unnecessary copying 4a2b1fd7 [studio,keel] Make fileChanged emit UUID as well as path, add uuidUrlToUuid 08f958fb [ox/std] Add IntegerRange_c a651d45a [ox/std] Fix Vector insert functions 9e9f317c [studio] Make UndoCommand::mergeWith take a reference f5a02ce9 [nostalgia/core/gba] Fix build 6971c310 [studio] Add NoChangeException c47f48eb [keel] Add/cleanup UUID/path lookup functions 76771e7b [nostalgia/core] Add tileColumns and tileRows functions f6a0ae20 [ox/std] Fix some Windows warnings 752c8c1d [glutils] Fix type conversion that happened on Windows af3bff1a [glutils] Add FrameBuffer::sizef 87416e13 [ox/std] Make MallocaPtr call destructor 047b4396 [ox/std] Make Point and Size members int32_t 40b8da4d [studio/modlib] Cleanup 123c4125 [ox/std] Add SmallMap::pairs(), SmallMap model 963ec5d3 [ox/std] Add operator-> to SpanIterator 6df77a23 [glutils] Add size function to FrameBuffer df412cf8 [ox/std] Add missing typenames ae30ef36 Merge commit 'b66cef7127e97269fc6072a6f66ccc08990f6d2e' 095a1135 Merge commit 'f48824793cfce315971fe2e699ece198c7a79407' ce1836ab Merge commit '1e041bd2ebfe5ace7bed3906faf60345aa98a8bc' 7d1641fa Merge commit '420fa96463f59c4a4a7cd66b16b0ad01ab0d55e6' 423212b2 [studio] Add missing include 60da1063 Merge commit 'bd416f82e25f1b710ab2b7890274571dd3fcd53d' 60d1996f [keel] Minor optimization git-subtree-dir: deps/nostalgia git-subtree-split: 7d9f363bfa7a2c64f5c4bcfd0b6686f3f5678119
This commit is contained in:
17
deps/glutils/include/glutils/glutils.hpp
vendored
17
deps/glutils/include/glutils/glutils.hpp
vendored
@ -13,6 +13,7 @@
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/vec.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
namespace glutils {
|
||||
@ -137,6 +138,22 @@ struct FrameBuffer {
|
||||
constexpr operator const GLuint&() const noexcept {
|
||||
return fbo.id;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Vec2 sizef() const noexcept {
|
||||
return {
|
||||
static_cast<float>(width),
|
||||
static_cast<float>(height),
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Size size() const noexcept {
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
class FrameBufferBind {
|
||||
|
2
deps/glutils/src/glutils.cpp
vendored
2
deps/glutils/src/glutils.cpp
vendored
@ -102,7 +102,7 @@ void setupShaderParams(
|
||||
ox::Vector<ShaderVarSet> const&vars,
|
||||
GLsizei vertexRowLen) noexcept {
|
||||
// setup vars
|
||||
for (auto lenWritten = 0LU; auto const&v : vars) {
|
||||
for (size_t lenWritten = 0; auto const&v : vars) {
|
||||
auto const attr = static_cast<GLuint>(glGetAttribLocation(shader, v.name.c_str()));
|
||||
glEnableVertexAttribArray(attr);
|
||||
glVertexAttribPointer(
|
||||
|
2
deps/ox/src/ox/claw/format.hpp
vendored
2
deps/ox/src/ox/claw/format.hpp
vendored
@ -10,7 +10,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
enum class ClawFormat: int {
|
||||
enum class ClawFormat {
|
||||
None,
|
||||
Metal,
|
||||
Organic,
|
||||
|
15
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
15
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -99,6 +99,21 @@ class FileSystem {
|
||||
|
||||
Result<FileStat> stat(const FileAddress &addr) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(uint64_t inode) const noexcept {
|
||||
return statInode(inode).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(ox::StringView path) const noexcept {
|
||||
return statPath(path).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(FileAddress const&addr) const noexcept {
|
||||
return stat(addr).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual uint64_t spaceNeeded(uint64_t size) const noexcept = 0;
|
||||
|
||||
|
7
deps/ox/src/ox/model/desctypes.hpp
vendored
7
deps/ox/src/ox/model/desctypes.hpp
vendored
@ -34,15 +34,16 @@ constexpr auto buildTypeId() noexcept {
|
||||
return ox::sfmt("{};{}", name, version);
|
||||
}
|
||||
|
||||
static constexpr auto buildTypeId(CRStringView name, int version,
|
||||
const TypeParamPack &typeParams = {}) noexcept {
|
||||
static constexpr auto buildTypeId(
|
||||
CRStringView name, int version,
|
||||
const TypeParamPack &typeParams = {}) noexcept {
|
||||
String tp;
|
||||
if (!typeParams.empty()) {
|
||||
tp = "#";
|
||||
for (const auto &p : typeParams) {
|
||||
tp += p + ",";
|
||||
}
|
||||
tp.resize(tp.len() - 1);
|
||||
tp.resize(tp.len());
|
||||
tp += "#";
|
||||
}
|
||||
return ox::sfmt("{}{};{}", name, tp, version);
|
||||
|
129
deps/ox/src/ox/oc/read.cpp
vendored
129
deps/ox/src/ox/oc/read.cpp
vendored
@ -36,135 +36,6 @@ OrganicClawReader::OrganicClawReader(Json::Value json, int unionIdx) noexcept:
|
||||
m_unionIdx(unionIdx) {
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, int8_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isInt()) {
|
||||
*val = static_cast<int8_t>(jv.asInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, int16_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isInt()) {
|
||||
*val = static_cast<int16_t>(jv.asInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, int32_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isInt()) {
|
||||
*val = static_cast<int32_t>(jv.asInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, int64_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isInt() || jv.isInt64()) {
|
||||
*val = static_cast<int64_t>(jv.asInt64());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
Error OrganicClawReader::field(const char *key, uint8_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isUInt()) {
|
||||
*val = static_cast<uint8_t>(jv.asUInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, uint16_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isUInt()) {
|
||||
*val = static_cast<uint16_t>(jv.asUInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, uint32_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isUInt()) {
|
||||
*val = static_cast<uint32_t>(jv.asUInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, uint64_t *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (jv.isUInt() || jv.isUInt64()) {
|
||||
*val = static_cast<uint64_t>(jv.asUInt64());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, bool *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
|
68
deps/ox/src/ox/oc/read.hpp
vendored
68
deps/ox/src/ox/oc/read.hpp
vendored
@ -41,16 +41,6 @@ class OrganicClawReader {
|
||||
|
||||
explicit OrganicClawReader(Json::Value json, int unionIdx = -1) noexcept;
|
||||
|
||||
Error field(const char *key, int8_t *val) noexcept;
|
||||
Error field(const char *key, int16_t *val) noexcept;
|
||||
Error field(const char *key, int32_t *val) noexcept;
|
||||
Error field(const char *key, int64_t *val) noexcept;
|
||||
|
||||
Error field(const char *key, uint8_t *val) noexcept;
|
||||
Error field(const char *key, uint16_t *val) noexcept;
|
||||
Error field(const char *key, uint32_t *val) noexcept;
|
||||
Error field(const char *key, uint64_t *val) noexcept;
|
||||
|
||||
Error field(const char *key, bool *val) noexcept;
|
||||
|
||||
// array handler
|
||||
@ -144,28 +134,46 @@ class OrganicClawReader {
|
||||
template<typename T>
|
||||
Error OrganicClawReader::field(const char *key, T *val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if constexpr(isVector_v<T>) {
|
||||
const auto &srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
oxReturnError(ox::resizeVector(*val, srcSize));
|
||||
err = field(key, val->data(), val->size());
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
const auto &srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
if (srcSize > val->size()) {
|
||||
err = OxError(1, "Input array is too long");
|
||||
} else {
|
||||
try {
|
||||
if constexpr (is_integer_v<T>) {
|
||||
if (targetValid()) {
|
||||
auto const&jv = value(key);
|
||||
auto const rightType = sizeof(T) == 8 ?
|
||||
(ox::is_signed_v<T> ? jv.isInt64() : jv.isUInt64()) :
|
||||
(ox::is_signed_v<T> ? jv.isInt() : jv.isUInt());
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
} else if (rightType) {
|
||||
*val = static_cast<T>(jv.asUInt());
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
} else if constexpr (isVector_v<T>) {
|
||||
const auto&srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
oxReturnError(ox::resizeVector(*val, srcSize));
|
||||
err = field(key, val->data(), val->size());
|
||||
} else if constexpr (isArray_v<T>) {
|
||||
const auto&srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
if (srcSize > val->size()) {
|
||||
err = OxError(1, "Input array is too long");
|
||||
} else {
|
||||
err = field(key, val->data(), val->size());
|
||||
}
|
||||
} else if (targetValid()) {
|
||||
const auto&jv = value(key);
|
||||
if (jv.empty() || jv.isObject()) {
|
||||
auto reader = child(key);
|
||||
ModelHandlerInterface handler(&reader);
|
||||
err = model(&handler, val);
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
} else if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty() || jv.isObject()) {
|
||||
auto reader = child(key);
|
||||
ModelHandlerInterface handler(&reader);
|
||||
err = model(&handler, val);
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
} catch (Json::LogicError const&) {
|
||||
err = OxError(1, "error reading JSON data");
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
|
12
deps/ox/src/ox/oc/write.hpp
vendored
12
deps/ox/src/ox/oc/write.hpp
vendored
@ -209,7 +209,17 @@ Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) n
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, const T *val) noexcept {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
if constexpr(is_integer_v<T>) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
// the int type needs to be normalized because jsoncpp doesn't
|
||||
// factor in every permutation unsigned long, etc.
|
||||
if constexpr(ox::is_signed_v<T>) {
|
||||
value(key) = static_cast<ox::Int<8 * sizeof(*val)>>(*val);
|
||||
} else {
|
||||
value(key) = static_cast<ox::Uint<8 * sizeof(*val)>>(*val);
|
||||
}
|
||||
}
|
||||
} else if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(key, val->data(), val->size());
|
||||
} else if (val && targetValid()) {
|
||||
OrganicClawWriter w;
|
||||
|
19
deps/ox/src/ox/preloader/preloader.hpp
vendored
19
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -94,7 +94,7 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
}
|
||||
|
||||
template<typename U, bool force>
|
||||
constexpr ox::Error field(CRStringView, const ox::UnionView<U, force> val) noexcept;
|
||||
constexpr ox::Error field(CRStringView, ox::UnionView<U, force> val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
constexpr ox::Error field(CRStringView, const T *val) noexcept;
|
||||
@ -135,6 +135,9 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
constexpr ox::Error fieldArray(CRStringView name, ox::ModelValueArray const*val) noexcept;
|
||||
|
||||
constexpr bool unionCheckAndIt() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr size_t calcPadding(size_t align) const noexcept;
|
||||
};
|
||||
|
||||
template<typename PlatSpec>
|
||||
@ -265,7 +268,7 @@ template<typename PlatSpec>
|
||||
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(size_t sz, size_t align) noexcept {
|
||||
m_allocStack.emplace_back(static_cast<typename PlatSpec::PtrType>(m_writer.tellp()));
|
||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
||||
const auto padding = m_writer.tellp() % align;
|
||||
auto const padding = calcPadding(align);
|
||||
oxRequireM(a, ox::allocate(m_writer, sz + padding));
|
||||
a += padding;
|
||||
oxReturnError(m_writer.seekp(a));
|
||||
@ -278,7 +281,7 @@ constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(
|
||||
std::size_t sz, size_t align, std::size_t restore) noexcept {
|
||||
m_allocStack.emplace_back(restore, ox::ios_base::beg);
|
||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
||||
const auto padding = m_writer.tellp() % align;
|
||||
auto const padding = calcPadding(align);
|
||||
oxRequireM(a, ox::allocate(m_writer, sz + padding));
|
||||
a += padding;
|
||||
oxReturnError(m_writer.seekp(a));
|
||||
@ -358,7 +361,7 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(
|
||||
const auto sz = sizeOf<PlatSpec>(&(*val)[0]) * val->size();
|
||||
const auto align = alignOf<PlatSpec>((*val)[0]);
|
||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
||||
const auto padding = m_writer.tellp() % align;
|
||||
auto const padding = calcPadding(align);
|
||||
oxRequireM(p, ox::allocate(m_writer, sz + padding));
|
||||
p += padding;
|
||||
oxReturnError(m_writer.seekp(p));
|
||||
@ -381,8 +384,6 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(
|
||||
|
||||
template<typename PlatSpec>
|
||||
constexpr ox::Error Preloader<PlatSpec>::fieldArray(CRStringView, ox::ModelValueArray const*val) noexcept {
|
||||
oxDebugf("array size: {}", val->size());
|
||||
oxDebugf("array sizeOf: {}", sizeOf<PlatSpec>(val));
|
||||
oxReturnError(pad(&(*val)[0]));
|
||||
for (auto const&v : *val) {
|
||||
oxReturnError(this->interface()->field({}, &v));
|
||||
@ -396,6 +397,12 @@ constexpr bool Preloader<PlatSpec>::unionCheckAndIt() noexcept {
|
||||
return u.checkAndIterate();
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
constexpr size_t Preloader<PlatSpec>::calcPadding(size_t align) const noexcept {
|
||||
auto const excess = m_writer.tellp() % align;
|
||||
return (align * (excess != 0)) - excess;
|
||||
}
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *obj) noexcept {
|
||||
oxReturnError(model(pl->interface(), obj));
|
||||
|
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@ -96,6 +96,7 @@ install(
|
||||
buildinfo.hpp
|
||||
byteswap.hpp
|
||||
concepts.hpp
|
||||
conv.hpp
|
||||
def.hpp
|
||||
defer.hpp
|
||||
defines.hpp
|
||||
|
2
deps/ox/src/ox/std/bit.hpp
vendored
2
deps/ox/src/ox/std/bit.hpp
vendored
@ -32,7 +32,7 @@ constexpr To bit_cast(const From &src) noexcept requires(sizeof(To) == sizeof(Fr
|
||||
namespace ox {
|
||||
|
||||
template<typename To, typename From>
|
||||
constexpr typename enable_if<sizeof(To) == sizeof(From), To>::type cbit_cast(From src) noexcept {
|
||||
constexpr To cbit_cast(From src) noexcept requires(sizeof(To) == sizeof(From)) {
|
||||
To dst = {};
|
||||
ox::memcpy(&dst, &src, sizeof(src));
|
||||
return dst;
|
||||
|
3
deps/ox/src/ox/std/concepts.hpp
vendored
3
deps/ox/src/ox/std/concepts.hpp
vendored
@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bit.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
namespace ox {
|
||||
@ -29,4 +30,6 @@ concept OxString_c = isOxString_v<T>;
|
||||
template<typename T>
|
||||
concept Integral_c = ox::is_integral_v<T>;
|
||||
|
||||
template<typename T, size_t max>
|
||||
concept IntegerRange_c = ox::is_integer_v<T> && ox::MaxValue<T> >= max;
|
||||
}
|
||||
|
45
deps/ox/src/ox/std/conv.hpp
vendored
Normal file
45
deps/ox/src/ox/std/conv.hpp
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2015 - 2024 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "point.hpp"
|
||||
#include "size.hpp"
|
||||
#include "vec.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
constexpr Vec2::operator Point() const noexcept {
|
||||
return {
|
||||
static_cast<int32_t>(x),
|
||||
static_cast<int32_t>(y),
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Vec2::operator Size() const noexcept {
|
||||
return {
|
||||
static_cast<int32_t>(x),
|
||||
static_cast<int32_t>(y),
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Point::operator Vec2() const noexcept {
|
||||
return {
|
||||
static_cast<float>(x),
|
||||
static_cast<float>(y),
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Size::operator Vec2() const noexcept {
|
||||
return {
|
||||
static_cast<float>(width),
|
||||
static_cast<float>(height),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
4
deps/ox/src/ox/std/iterator.hpp
vendored
4
deps/ox/src/ox/std/iterator.hpp
vendored
@ -128,6 +128,10 @@ struct SpanIterator {
|
||||
return operator-=(1);
|
||||
}
|
||||
|
||||
constexpr PtrType operator->() const noexcept {
|
||||
return &m_t[m_offset];
|
||||
}
|
||||
|
||||
constexpr RefType operator*() const noexcept {
|
||||
return m_t[m_offset];
|
||||
}
|
||||
|
1
deps/ox/src/ox/std/new.hpp
vendored
1
deps/ox/src/ox/std/new.hpp
vendored
@ -102,6 +102,7 @@ class MallocaPtr {
|
||||
}
|
||||
|
||||
constexpr ~MallocaPtr() noexcept {
|
||||
m_val->~T();
|
||||
if (m_onHeap && m_val) {
|
||||
delete[] reinterpret_cast<uint8_t*>(m_val);
|
||||
}
|
||||
|
5
deps/ox/src/ox/std/point.hpp
vendored
5
deps/ox/src/ox/std/point.hpp
vendored
@ -17,8 +17,8 @@ class Point {
|
||||
public:
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.Point";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
|
||||
constexpr Point() noexcept = default;
|
||||
|
||||
@ -64,6 +64,7 @@ class Point {
|
||||
|
||||
constexpr bool operator!=(const Point&) const noexcept;
|
||||
|
||||
explicit constexpr operator class Vec2() const noexcept;
|
||||
};
|
||||
|
||||
constexpr Point::Point(int x, int y) noexcept {
|
||||
|
55
deps/ox/src/ox/std/reader.cpp
vendored
55
deps/ox/src/ox/std/reader.cpp
vendored
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <cstdio>
|
||||
#include <istream>
|
||||
|
||||
#include "array.hpp"
|
||||
#include "reader.hpp"
|
||||
@ -16,41 +16,56 @@
|
||||
namespace ox {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int sdMap(ox::ios_base::seekdir in) noexcept {
|
||||
constexpr std::ios_base::seekdir sdMap(ox::ios_base::seekdir in) noexcept {
|
||||
switch (in) {
|
||||
case ox::ios_base::beg:
|
||||
return SEEK_SET;
|
||||
return std::ios_base::beg;
|
||||
case ox::ios_base::end:
|
||||
return SEEK_END;
|
||||
return std::ios_base::end;
|
||||
case ox::ios_base::cur:
|
||||
return SEEK_CUR;
|
||||
return std::ios_base::cur;
|
||||
}
|
||||
return -1;
|
||||
return std::ios_base::beg;
|
||||
}
|
||||
|
||||
ox::Result<char> FileReader::peek() const noexcept {
|
||||
auto const c = fgetc(m_file);
|
||||
auto const ok = c != EOF;
|
||||
if (ok && ungetc(c, m_file)) [[unlikely]] {
|
||||
return OxError(1, "Unable to unget character");
|
||||
ox::Result<char> StreamReader::peek() const noexcept {
|
||||
try {
|
||||
char c{};
|
||||
m_strm.get(c);
|
||||
auto const ok = c != EOF;
|
||||
if (ok && m_strm.unget()) [[unlikely]] {
|
||||
return OxError(1, "Unable to unget character");
|
||||
}
|
||||
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "peek failed");
|
||||
}
|
||||
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> FileReader::read(char *v, std::size_t cnt) noexcept {
|
||||
return fread(v, 1, cnt, m_file);
|
||||
ox::Result<std::size_t> StreamReader::read(char *v, std::size_t cnt) noexcept {
|
||||
return static_cast<size_t>(m_strm.read(v, static_cast<std::streamsize>(cnt)).gcount());
|
||||
}
|
||||
|
||||
ox::Error FileReader::seekg(std::size_t p) noexcept {
|
||||
return OxError(fseek(m_file, static_cast<int64_t>(p), SEEK_CUR) != 0);
|
||||
ox::Error StreamReader::seekg(std::size_t p) noexcept {
|
||||
try {
|
||||
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error FileReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
|
||||
return OxError(fseek(m_file, p, sdMap(sd)) != 0);
|
||||
ox::Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
|
||||
try {
|
||||
m_strm.seekg(p, sdMap(sd));
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> FileReader::tellg() noexcept {
|
||||
const auto sz = ftell(m_file);
|
||||
ox::Result<std::size_t> StreamReader::tellg() noexcept {
|
||||
const auto sz = m_strm.tellg();
|
||||
return {static_cast<std::size_t>(sz), OxError(sz == -1)};
|
||||
}
|
||||
|
||||
|
8
deps/ox/src/ox/std/reader.hpp
vendored
8
deps/ox/src/ox/std/reader.hpp
vendored
@ -9,7 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <cstdio>
|
||||
#include <istream>
|
||||
#endif
|
||||
|
||||
#include "concepts.hpp"
|
||||
@ -65,11 +65,11 @@ class ReaderT: public Reader_v {
|
||||
};
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
class FileReader: public Reader_v {
|
||||
class StreamReader: public Reader_v {
|
||||
private:
|
||||
FILE *m_file = nullptr;
|
||||
std::istream &m_strm;
|
||||
public:
|
||||
constexpr explicit FileReader(FILE *file) noexcept: m_file(file) {}
|
||||
constexpr explicit StreamReader(std::istream &stream) noexcept: m_strm(stream) {}
|
||||
ox::Result<char> peek() const noexcept override;
|
||||
ox::Result<std::size_t> read(char *v, std::size_t cnt) noexcept override;
|
||||
ox::Error seekg(std::size_t p) noexcept override;
|
||||
|
5
deps/ox/src/ox/std/size.hpp
vendored
5
deps/ox/src/ox/std/size.hpp
vendored
@ -17,8 +17,8 @@ class Size {
|
||||
public:
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.Size";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
|
||||
constexpr Size() noexcept = default;
|
||||
|
||||
@ -64,6 +64,7 @@ class Size {
|
||||
|
||||
constexpr bool operator!=(const Size&) const noexcept;
|
||||
|
||||
explicit constexpr operator class Vec2() const noexcept;
|
||||
};
|
||||
|
||||
constexpr Size::Size(int width, int height) noexcept {
|
||||
|
28
deps/ox/src/ox/std/smallmap.hpp
vendored
28
deps/ox/src/ox/std/smallmap.hpp
vendored
@ -8,7 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "algorithm.hpp"
|
||||
#include "def.hpp"
|
||||
#include "hash.hpp"
|
||||
#include "ignore.hpp"
|
||||
#include "stringview.hpp"
|
||||
@ -28,7 +28,7 @@ class SmallMap {
|
||||
T value{};
|
||||
};
|
||||
|
||||
private:
|
||||
protected:
|
||||
using PairVector = Vector<Pair, SmallSz>;
|
||||
PairVector m_pairs;
|
||||
|
||||
@ -39,8 +39,6 @@ class SmallMap {
|
||||
|
||||
constexpr SmallMap(SmallMap &&other) noexcept;
|
||||
|
||||
constexpr ~SmallMap();
|
||||
|
||||
constexpr bool operator==(SmallMap const&other) const;
|
||||
|
||||
constexpr SmallMap &operator=(SmallMap const&other);
|
||||
@ -79,6 +77,11 @@ class SmallMap {
|
||||
[[nodiscard]]
|
||||
constexpr Pair &get(size_t i) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::SpanView<Pair> pairs() const noexcept {
|
||||
return m_pairs;
|
||||
}
|
||||
|
||||
constexpr void clear();
|
||||
|
||||
private:
|
||||
@ -100,11 +103,6 @@ constexpr SmallMap<K, T, SmallSz>::SmallMap(SmallMap<K, T, SmallSz> &&other) noe
|
||||
m_pairs = std::move(other.m_pairs);
|
||||
}
|
||||
|
||||
template<typename K, typename T, size_t SmallSz>
|
||||
constexpr SmallMap<K, T, SmallSz>::~SmallMap() {
|
||||
clear();
|
||||
}
|
||||
|
||||
template<typename K, typename T, size_t SmallSz>
|
||||
constexpr bool SmallMap<K, T, SmallSz>::operator==(SmallMap const&other) const {
|
||||
return m_pairs == other.m_pairs;
|
||||
@ -204,12 +202,12 @@ constexpr T &SmallMap<K, T, SmallSz>::value(size_t i) noexcept {
|
||||
}
|
||||
|
||||
template<typename K, typename T, size_t SmallSz>
|
||||
constexpr SmallMap<K, T, SmallSz>::Pair const&SmallMap<K, T, SmallSz>::get(size_t i) const noexcept {
|
||||
constexpr typename SmallMap<K, T, SmallSz>::Pair const&SmallMap<K, T, SmallSz>::get(size_t i) const noexcept {
|
||||
return m_pairs[i];
|
||||
}
|
||||
|
||||
template<typename K, typename T, size_t SmallSz>
|
||||
constexpr SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::get(size_t i) noexcept {
|
||||
constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::get(size_t i) noexcept {
|
||||
return m_pairs[i];
|
||||
}
|
||||
|
||||
@ -246,4 +244,12 @@ constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::acces
|
||||
return pairs.emplace_back();
|
||||
}
|
||||
|
||||
template<typename T, typename K, typename V, size_t SmallSz>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<SmallMap<K, V, SmallSz>> auto *obj) noexcept {
|
||||
using Map = SmallMap<K, V, SmallSz>;
|
||||
oxReturnError(io->template setTypeInfo<Map>());
|
||||
oxReturnError(io->field("pairs", &obj->m_pairs));
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
2
deps/ox/src/ox/std/stacktrace.cpp
vendored
2
deps/ox/src/ox/std/stacktrace.cpp
vendored
@ -26,7 +26,7 @@
|
||||
namespace ox {
|
||||
|
||||
#if defined(OX_USE_STDLIB) && __has_include(<unistd.h>)
|
||||
[[nodiscard]]
|
||||
[[nodiscard]] [[maybe_unused]]
|
||||
static auto symbolicate([[maybe_unused]]void **frames,
|
||||
[[maybe_unused]]std::size_t frameCnt,
|
||||
[[maybe_unused]]const char *linePrefix) {
|
||||
|
1
deps/ox/src/ox/std/std.hpp
vendored
1
deps/ox/src/ox/std/std.hpp
vendored
@ -16,6 +16,7 @@
|
||||
#include "istring.hpp"
|
||||
#include "byteswap.hpp"
|
||||
#include "concepts.hpp"
|
||||
#include "conv.hpp"
|
||||
#include "cstringview.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "def.hpp"
|
||||
|
1
deps/ox/src/ox/std/string.cpp
vendored
1
deps/ox/src/ox/std/string.cpp
vendored
@ -13,6 +13,7 @@ namespace ox {
|
||||
template class BasicString<8>;
|
||||
|
||||
static_assert(StringView("Write") != String(""));
|
||||
static_assert(ox::strcmp(String{}.c_str(), "\0") == 0);
|
||||
static_assert(String("Write") != StringView(""));
|
||||
static_assert(String("Write") == StringView("Write"));
|
||||
static_assert(String(StringView("Write")) == StringView("Write"));
|
||||
|
37
deps/ox/src/ox/std/string.hpp
vendored
37
deps/ox/src/ox/std/string.hpp
vendored
@ -193,7 +193,9 @@ class BasicString {
|
||||
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
|
||||
|
||||
constexpr void resize(size_t sz) noexcept {
|
||||
++sz;
|
||||
m_buff.resize(sz);
|
||||
m_buff[sz - 1] = 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -248,38 +250,19 @@ class BasicString {
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString() noexcept {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
}
|
||||
m_buff.resize(1);
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {
|
||||
// GCC complains if you don't do this pretty unnecessary size check
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
}
|
||||
}
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
}
|
||||
set(str);
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexcept {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
}
|
||||
set(str);
|
||||
}
|
||||
|
||||
@ -287,21 +270,15 @@ template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size_t size) noexcept {
|
||||
m_buff.resize(size + 1);
|
||||
ox::listcpy(m_buff.data(), str, size);
|
||||
m_buff[size] = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
|
||||
BasicString(StringView{str.data(), str.bytes()}) {
|
||||
BasicString(StringView{str.data(), str.len()}) {
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
|
||||
if (m_buff.empty()) {
|
||||
m_buff.push_back(0);
|
||||
} else {
|
||||
m_buff[0] = 0;
|
||||
}
|
||||
set(str);
|
||||
}
|
||||
|
||||
@ -312,6 +289,8 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const BasicString &other)
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(BasicString &&other) noexcept: m_buff(std::move(other.m_buff)) {
|
||||
other.m_buff.resize(1);
|
||||
other.m_buff[0] = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
@ -357,6 +336,8 @@ template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(BasicString &&src) noexcept {
|
||||
if (this != &src) {
|
||||
m_buff = std::move(src.m_buff);
|
||||
src.m_buff.resize(1);
|
||||
src.m_buff[0] = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
14
deps/ox/src/ox/std/test/tests.cpp
vendored
14
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -18,12 +18,12 @@
|
||||
#include <ox/std/std.hpp>
|
||||
|
||||
[[nodiscard]]
|
||||
static uint64_t nowMs() {
|
||||
static uint64_t steadyNowMs() {
|
||||
#if __has_include(<chrono>)
|
||||
using namespace std::chrono;
|
||||
return static_cast<uint64_t>(
|
||||
duration_cast<milliseconds>(
|
||||
system_clock::now().time_since_epoch()).count());
|
||||
steady_clock::now().time_since_epoch()).count());
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
@ -41,13 +41,13 @@ uint64_t timeMapStrToUuid(int elemCnt, int lookups, uint64_t seed = 4321) noexce
|
||||
auto const keys = map.keys();
|
||||
ox::Random rand;
|
||||
// start
|
||||
auto const startTime = nowMs();
|
||||
auto const startTime = steadyNowMs();
|
||||
for (int i = 0; i < lookups; ++i) {
|
||||
auto const&k = keys[rand.gen() % keys.size()];
|
||||
map[k];
|
||||
oxExpect(map[k], ox::UUID::fromString(k).unwrap());
|
||||
}
|
||||
return nowMs() - startTime;
|
||||
return steadyNowMs() - startTime;
|
||||
}
|
||||
|
||||
template<typename Map = ox::SmallMap<ox::UUID, ox::String>>
|
||||
@ -62,16 +62,16 @@ uint64_t timeMapUuidToStr(int elemCnt, int lookups, uint64_t seed = 4321) noexce
|
||||
auto const keys = map.keys();
|
||||
ox::Random rand;
|
||||
// start
|
||||
auto const startTime = nowMs();
|
||||
auto const startTime = steadyNowMs();
|
||||
for (int i = 0; i < lookups; ++i) {
|
||||
auto const&k = keys[rand.gen() % keys.size()];
|
||||
oxExpect(map[k], k.toString());
|
||||
}
|
||||
return nowMs() - startTime;
|
||||
return steadyNowMs() - startTime;
|
||||
}
|
||||
|
||||
static ox::Error compareMaps(int lookupCnt = 1'000'000) {
|
||||
auto const seed = nowMs();
|
||||
auto const seed = steadyNowMs();
|
||||
uint64_t hashTime{};
|
||||
uint64_t smallTime{};
|
||||
int elemCnt = 1;
|
||||
|
2
deps/ox/src/ox/std/typetraits.hpp
vendored
2
deps/ox/src/ox/std/typetraits.hpp
vendored
@ -185,6 +185,8 @@ struct enable_if<true, T> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<bool B, typename T>
|
||||
using enable_if_t = typename enable_if<B, T>::type;
|
||||
|
||||
template<typename T>
|
||||
struct is_pointer {
|
||||
|
71
deps/ox/src/ox/std/vec.hpp
vendored
71
deps/ox/src/ox/std/vec.hpp
vendored
@ -23,17 +23,16 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename T>
|
||||
struct Vec {
|
||||
class Vec2 {
|
||||
public:
|
||||
using value_type = T;
|
||||
using value_type = float;
|
||||
using size_type = std::size_t;
|
||||
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.Point";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
|
||||
template<typename RefType = value_type&, typename PtrType = value_type*, bool reverse = false>
|
||||
struct iterator: public ox::Iterator<std::bidirectional_iterator_tag, value_type> {
|
||||
@ -141,14 +140,14 @@ struct Vec {
|
||||
|
||||
};
|
||||
|
||||
constexpr Vec() noexcept = default;
|
||||
constexpr Vec2() noexcept = default;
|
||||
|
||||
template<typename ...Args>
|
||||
constexpr Vec(T pX, T pY) noexcept: x(pX), y(pY) {
|
||||
constexpr Vec2(float pX, float pY) noexcept: x(pX), y(pY) {
|
||||
}
|
||||
|
||||
#if __has_include(<imgui.h>)
|
||||
explicit constexpr Vec(const ImVec2 &v) noexcept: Vec(v.x, v.y) {
|
||||
explicit constexpr Vec2(const ImVec2 &v) noexcept: Vec2(v.x, v.y) {
|
||||
}
|
||||
|
||||
explicit inline operator ImVec2() const noexcept {
|
||||
@ -228,7 +227,7 @@ struct Vec {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr auto operator==(const Vec &v) const noexcept {
|
||||
constexpr auto operator==(const Vec2 &v) const noexcept {
|
||||
for (auto i = 0u; i < v.size(); ++i) {
|
||||
if ((*this)[i] != v[i]) {
|
||||
return false;
|
||||
@ -237,29 +236,71 @@ struct Vec {
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr auto operator!=(const Vec &v) const noexcept {
|
||||
constexpr auto operator!=(const Vec2 &v) const noexcept {
|
||||
return !operator==(v);
|
||||
}
|
||||
|
||||
explicit constexpr operator class Point() const noexcept;
|
||||
|
||||
explicit constexpr operator class Size() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return 2;
|
||||
}
|
||||
|
||||
constexpr Vec2 operator+(float i) const noexcept {
|
||||
return {x + i, y + i};
|
||||
}
|
||||
|
||||
constexpr Vec2 operator+=(float i) noexcept {
|
||||
x += i;
|
||||
y += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2 operator-(float i) const noexcept {
|
||||
return {x - i, y - i};
|
||||
}
|
||||
|
||||
constexpr Vec2 operator-=(float i) noexcept {
|
||||
x -= i;
|
||||
y -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2 operator*(float i) const noexcept {
|
||||
return {x * i, y * i};
|
||||
}
|
||||
|
||||
constexpr Vec2 operator*=(float i) noexcept {
|
||||
x *= i;
|
||||
y *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2 operator/(float i) const noexcept {
|
||||
return {x / i, y / i};
|
||||
}
|
||||
|
||||
constexpr Vec2 operator/=(float i) noexcept {
|
||||
x /= i;
|
||||
y /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
[[nodiscard]]
|
||||
constexpr T *start() noexcept {
|
||||
return &x;
|
||||
constexpr float *start() noexcept {
|
||||
return&x;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T *start() const noexcept {
|
||||
constexpr const float *start() const noexcept {
|
||||
return &x;
|
||||
}
|
||||
};
|
||||
|
||||
using Vec2 = Vec<float>;
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<Vec2> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<Vec2>());
|
||||
|
48
deps/ox/src/ox/std/vector.hpp
vendored
48
deps/ox/src/ox/std/vector.hpp
vendored
@ -271,7 +271,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
constexpr bool contains(MaybeView_t<T> const&) const noexcept;
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept);
|
||||
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, T val) noexcept(useNoexcept);
|
||||
|
||||
@ -531,29 +531,23 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> co
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept) {
|
||||
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
if (pos < m_size) {
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
}
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size + cnt - 1; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
|
||||
}
|
||||
for (auto i = pos; i < pos + cnt; ++i) {
|
||||
m_items[i] = val;
|
||||
}
|
||||
} else {
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size + cnt - 1; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
}
|
||||
++m_size;
|
||||
m_size += cnt;
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
@ -562,20 +556,14 @@ constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&,
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, T val) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
if (pos < m_size) {
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
std::construct_at(&m_items[pos], m_items[pos]);
|
||||
}
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
std::construct_at(&m_items[pos], m_items[pos]);
|
||||
}
|
||||
std::construct_at(&m_items[pos], std::move(val));
|
||||
}
|
||||
++m_size;
|
||||
return begin() + pos;
|
||||
|
Reference in New Issue
Block a user