Compare commits
11 Commits
c0479604aa
...
19a4120113
Author | SHA1 | Date | |
---|---|---|---|
19a4120113 | |||
f69b8afa62 | |||
9c98b5e2c2 | |||
1f87216da4 | |||
94c59604ee | |||
8ee016c130 | |||
dc20c66797 | |||
407e54246f | |||
3b18869665 | |||
0fab6c7c20 | |||
a72b865dc9 |
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,
|
||||
|
2
deps/ox/src/ox/preloader/preloader.hpp
vendored
2
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -381,8 +381,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));
|
||||
|
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;
|
||||
|
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),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
1
deps/ox/src/ox/std/point.hpp
vendored
1
deps/ox/src/ox/std/point.hpp
vendored
@ -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 {
|
||||
|
1
deps/ox/src/ox/std/size.hpp
vendored
1
deps/ox/src/ox/std/size.hpp
vendored
@ -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 {
|
||||
|
7
deps/ox/src/ox/std/smallmap.hpp
vendored
7
deps/ox/src/ox/std/smallmap.hpp
vendored
@ -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);
|
||||
@ -105,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;
|
||||
|
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"
|
||||
|
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 {
|
||||
|
69
deps/ox/src/ox/std/vec.hpp
vendored
69
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 {
|
||||
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>());
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/math.hpp>
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
@ -151,4 +152,13 @@ static_assert(color16(16, 31, 0) == 1008);
|
||||
static_assert(color16(16, 31, 8) == 9200);
|
||||
static_assert(color16(16, 32, 8) == 9200);
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Color16 applySelectionColor(Color16 const color) noexcept {
|
||||
namespace core = nostalgia::core;
|
||||
auto const r = core::red16(color) / 2;
|
||||
auto const g = (core::green16(color) + 20) / 2;
|
||||
auto const b = (core::blue16(color) + 31) / 2;
|
||||
return core::color16(r, g, b);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -385,7 +385,8 @@ static void setSprite(
|
||||
uint_t const idx,
|
||||
Sprite const&s) noexcept {
|
||||
// Tonc Table 8.4
|
||||
static constexpr ox::Array<ox::Vec<uint_t>, 12> dimensions{
|
||||
struct Sz { uint_t x{}, y{}; };
|
||||
static constexpr ox::Array<Sz, 12> dimensions{
|
||||
// col 0
|
||||
{1, 1}, // 0, 0
|
||||
{2, 2}, // 0, 1
|
||||
|
@ -139,10 +139,7 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
return;
|
||||
}
|
||||
if (m_model.pixelSelected(i)) {
|
||||
auto const r = red16(color) / 2;
|
||||
auto const g = (green16(color) + 20) / 2;
|
||||
auto const b = (blue16(color) + 31) / 2;
|
||||
color = color16(r, g, b);
|
||||
color = applySelectionColor(color);
|
||||
}
|
||||
setPixelBufferObject(paneSize, static_cast<unsigned>(i * VertexVboRows), fx, fy, color, vbo, ebo);
|
||||
});
|
||||
|
@ -0,0 +1,94 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <ox/std/math.hpp>
|
||||
#include <ox/std/point.hpp>
|
||||
#include <ox/std/typetraits.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
struct Selection {ox::Point a, b;};
|
||||
|
||||
constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
|
||||
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
|
||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||
if constexpr(retErr) {
|
||||
oxReturnError(cb(x, y));
|
||||
} else {
|
||||
cb(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr(retErr) {
|
||||
return ox::Error{};
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionTracker {
|
||||
private:
|
||||
bool m_selectionOngoing{};
|
||||
ox::Point m_pointA;
|
||||
ox::Point m_pointB;
|
||||
public:
|
||||
[[nodiscard]]
|
||||
constexpr bool selectionOngoing() const noexcept {
|
||||
return m_selectionOngoing;
|
||||
}
|
||||
|
||||
constexpr void startSelection(ox::Point cursor) noexcept {
|
||||
m_pointA = cursor;
|
||||
m_pointB = cursor;
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ox::Point cursor, bool allowStart = true) noexcept {
|
||||
if (!m_selectionOngoing && allowStart) {
|
||||
m_pointA = cursor;
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
if (m_selectionOngoing) {
|
||||
m_pointB = cursor;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ox::Vec2 cursor, bool allowStart = true) noexcept {
|
||||
updateCursorPoint(
|
||||
ox::Point{
|
||||
static_cast<int32_t>(cursor.x),
|
||||
static_cast<int32_t>(cursor.y),
|
||||
},
|
||||
allowStart);
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ImVec2 cursor, bool allowStart = true) noexcept {
|
||||
updateCursorPoint(
|
||||
ox::Point{
|
||||
static_cast<int32_t>(cursor.x),
|
||||
static_cast<int32_t>(cursor.y),
|
||||
},
|
||||
allowStart);
|
||||
}
|
||||
|
||||
constexpr void finishSelection() noexcept {
|
||||
m_selectionOngoing = {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Selection selection() const noexcept {
|
||||
return {
|
||||
{
|
||||
ox::min(m_pointA.x, m_pointB.x),
|
||||
ox::min(m_pointA.y, m_pointB.y),
|
||||
},
|
||||
{
|
||||
ox::max(m_pointA.x, m_pointB.x),
|
||||
ox::max(m_pointA.y, m_pointB.y),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
#include <studio/itemmaker.hpp>
|
||||
#include <studio/popup.hpp>
|
||||
#include <studio/project.hpp>
|
||||
#include <studio/selectiontracker.hpp>
|
||||
#include <studio/task.hpp>
|
||||
#include <studio/undocommand.hpp>
|
||||
#include <studio/undostack.hpp>
|
||||
|
Loading…
x
Reference in New Issue
Block a user