Skip to content

Commit

Permalink
Hitbox Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuria-Shikibe committed Jun 6, 2024
1 parent d4ae57a commit 5dd75eb
Show file tree
Hide file tree
Showing 61 changed files with 1,680 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <GLFW/glfw3.h>

#include "../src/code-gen/ReflectData_Builtin.hpp"
#include "src/arc/util/ReflectionUtil.hpp"
#include "src/ext/ReflectionUtil.hpp"

import std;
import std.compat;
Expand Down
375 changes: 374 additions & 1 deletion properties/resource/test.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/SideTemp.cppm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module;

#include "../src/code-gen/ReflectData_Builtin.hpp"
#include "../src/arc/util/ReflectionUtil.hpp"
#include "../src/ext/ReflectionUtil.hpp"

export module SideTemp;

Expand Down Expand Up @@ -104,7 +104,6 @@ export namespace Test{
OS::File fi{R"(D:\projects\GameEngine\properties\resource\test.json)"};
OS::File pixmap{R"(D:\projects\GameEngine\properties\resource\tiles.png)"};


if constexpr(false){
auto pixmap_ = Graphic::Pixmap{pixmap};
::Test::chamberFrame->getChambers() = Game::ChamberUtil::genFrameFromPixmap<Game::SpaceCraft>(
Expand All @@ -114,10 +113,18 @@ export namespace Test{

fi.writeString(std::format("{:nf0}", jval));
} else{
ext::json::Json json{fi.quickRead()};
auto str = fi.quickRead();

auto cur = std::chrono::high_resolution_clock::now();

ext::json::JsonValue jval{ext::json::Parser::parse(str)};

ext::json::getValueTo(::Test::chamberFrame->getChambers(), json.getData());
auto dur = std::chrono::high_resolution_clock::now() - cur;
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(dur) << std::endl;

ext::json::getValueTo(::Test::chamberFrame->getChambers(), jval);
}

}

void genRandomEntities(){
Expand Down
4 changes: 2 additions & 2 deletions src/Test.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export namespace Test{
Game::core = std::make_unique<Game::Core>();
Core::loopManager->setGameCore(Game::core.get());

ext::json::Json json{Assets::Dir::settings.subFile("ctrl.json").readString()};
ext::json::getValueTo(Assets::Ctrl::basicGroup, json.getData());
ext::json::JsonValue json{ext::json::Parser::parse(Assets::Dir::settings.subFile("ctrl.json").quickRead())};
ext::json::getValueTo(Assets::Ctrl::basicGroup, json);

Core::destructors.push_back([]{
Assets::Dir::settings.subFile("ctrl.json").writeString(std::format("{:1}", ext::json::getJsonOf(Assets::Ctrl::basicGroup)));
Expand Down
11 changes: 10 additions & 1 deletion src/arc-impl/ui/Elem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ bool UI::Elem::isCursorInbound() const noexcept{
return this->root->currentCursorFocus == this;
}

void UI::Elem::releaseAllFocus() const noexcept{
void UI::Elem::releaseRelativeRef() const noexcept{
if(!root)return;

dropTooltip();
unloadInputBinds();

if(isFocusedKeyInput())root->currentInputFocused = nullptr;
if(isFocusedScroll())root->currentScrollFocused = nullptr;
Expand Down Expand Up @@ -188,3 +189,11 @@ Assets::Bundle& UI::Elem::getBundles(const bool fromUICategory) const{
return Core::bundle;
}
}

void UI::Elem::loadInputBinds(OS::InputBindGroup& binds) const{
if(root)root->loadBinds(this, binds);
}

void UI::Elem::unloadInputBinds() const{
if(root)root->unloadBinds(this);
}
13 changes: 13 additions & 0 deletions src/arc-impl/ui/Root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ UI::Root::~Root(){
std::erase(Core::input.inputMouseListeners, this);
}

void UI::Root::loadBinds(const Elem* elem, OS::InputBindGroup& binds){
if(customeInputBinds.try_emplace(elem, &binds).second){
Core::input.registerSubInput(&binds);
}
}

void UI::Root::unloadBinds(const Elem* elem){
if(const auto itr = customeInputBinds.find(elem); itr != customeInputBinds.end()){
Core::input.eraseSubInput(itr->second);
customeInputBinds.erase(itr);
}
}


void UI::Root::drawCursor() const{
using namespace Graphic;
Expand Down
4 changes: 2 additions & 2 deletions src/arc-impl/ui/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void UI::Screen::drawContent() const{

GL::viewport(absoluteSrc.x, absoluteSrc.y, getWidth(), getHeight());

// GL::disable(GL::State::BLEND);
GL::disable(GL::State::BLEND);
Assets::Shaders::mask->bind();
Assets::Shaders::mask->applyDynamic([](const GL::ShaderProgram& shader){
shader.setColor("mixColor", Colors::CLEAR);
Expand All @@ -87,7 +87,7 @@ void UI::Screen::drawContent() const{

Frame::rawMesh->bind();
Frame::rawMesh->render(GL_TRIANGLE_FAN, 0, GL::ELEMENTS_QUAD_STRIP_LENGTH);
// GL::enable(GL::State::BLEND);
GL::enable(GL::State::BLEND);

if(cur)Core::renderer->frameBegin_Quiet(cur);
else{
Expand Down
3 changes: 1 addition & 2 deletions src/arc/asset/Bundle.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export namespace Assets{
}

static ext::json::JsonValue loadFile(const OS::File& file){
ext::json::Json jval{file.quickRead()};
return jval.getData();
return ext::json::Parser::parse(file.quickRead());
}

static std::optional<std::string_view> find(const std::vector<std::string_view>& dir, const ext::json::Object* last){
Expand Down
41 changes: 41 additions & 0 deletions src/arc/core/Unit.cppm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export module Core.Unit;

import std;
import Math;

export namespace Core{
using TickRatio = std::ratio<1, 60>;
Expand Down Expand Up @@ -53,6 +54,46 @@ export namespace Core{
this->operator--();
return t;
}

friend T operator%(DirectAccessTimeUnit l, const T val) noexcept{
return Math::mod<T>(T(l), val);
}

friend constexpr T operator+(DirectAccessTimeUnit l, const T val) noexcept{
return T(l) + val;
}

friend constexpr T operator-(DirectAccessTimeUnit l, const T val) noexcept{
return T(l) - val;
}

friend constexpr T operator*(DirectAccessTimeUnit l, const T val) noexcept{
return T(l) * val;
}

friend constexpr T operator/(DirectAccessTimeUnit l, const T val) noexcept{
return T(l) / val;
}

friend T operator%(const T val, DirectAccessTimeUnit l) noexcept{
return Math::mod<T>(val, T(l));
}

friend constexpr T operator+(const T val, DirectAccessTimeUnit l) noexcept{
return val + T(l);
}

friend constexpr T operator-(const T val, DirectAccessTimeUnit l) noexcept{
return val - T(l);
}

friend constexpr T operator*(const T val, DirectAccessTimeUnit l) noexcept{
return val * T(l);
}

friend constexpr T operator/(const T val, DirectAccessTimeUnit l) noexcept{
return val / T(l);
}
};

using Tick = DirectAccessTimeUnit<float, TickRatio>;
Expand Down
9 changes: 7 additions & 2 deletions src/arc/graphic/Pixmap.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module;

export module Graphic.Pixmap;

import Geom.Vector2D;
import ext.RuntimeException;
import GL.Texture.Texture2D;
import GL.Buffer.FrameBuffer;
Expand Down Expand Up @@ -41,6 +42,10 @@ export namespace Graphic{
return height;
}

[[nodiscard]] Geom::Point2 getSize() const{
return {width, height};
}

// [[nodiscard]] unsigned getBpp() const {
// return bpp;
// }
Expand Down Expand Up @@ -148,10 +153,10 @@ export namespace Graphic{
return bitmapData[index];
}

void mix(const Color color, const float t) const{
void mix(const Color color, const float alpha) const{
for(int i = 0; i < pixelSize(); ++i){
Color src = get(i);
set(i, src.lerpRGB(color, t));
set(i, src.lerpRGB(color, alpha));
}
}

Expand Down
Loading

0 comments on commit 5dd75eb

Please sign in to comment.