Skip to content

Commit

Permalink
Basic Async Load refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuria-Shikibe committed Jun 9, 2024
1 parent 5dd75eb commit 1bf7d4c
Show file tree
Hide file tree
Showing 74 changed files with 3,343 additions and 1,401 deletions.
406 changes: 122 additions & 284 deletions main.cpp

Large diffs are not rendered by default.

82 changes: 73 additions & 9 deletions src/SideTemp.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,91 @@ export struct TestChamberFactory : Game::ChamberFactory<Game::SpaceCraft>{
}
};

REFL_REGISTER_CLASS_DEF(::TestChamberFactory::ChamberType<>)
export {
REFL_REGISTER_CLASS_DEF(::TestChamberFactory::ChamberType<>)
}


export namespace GameCtrl{
::Ctrl::Operation moveLeft{
"move-left", OS::KeyBind(::Ctrl::Key::A, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::left<float>);
})
};

::Ctrl::Operation moveRight{
"move-right", OS::KeyBind(::Ctrl::Key::D, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::right<float>);
})
};

::Ctrl::Operation moveForward{
"move-up", OS::KeyBind(::Ctrl::Key::W, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::up<float>);
})
};

::Ctrl::Operation moveBack{
"move-down", OS::KeyBind(::Ctrl::Key::S, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::down<float>);
})
};

::Ctrl::Operation shoot_rls{
"shoot-rls", OS::KeyBind(::Ctrl::Mouse::LMB, ::Ctrl::Act::Release, +[]{
if(Game::core->playerController){
Game::core->playerController->shoot = false;
}
})
};

::Ctrl::Operation shoot_prs{
"shoot-prs", OS::KeyBind(::Ctrl::Mouse::LMB, ::Ctrl::Act::Press, +[]{
if(Game::core->playerController && !Core::uiRoot->cursorCaptured()){
Game::core->playerController->shoot = true;
}
}),
{shoot_rls.name}
};


::Ctrl::Operation moveTrans_rls{
"move-trans-rls", OS::KeyBind(::Ctrl::Key::Left_Shift, ::Ctrl::Act::Release, +[]{
if(Game::core->playerController){
Game::core->playerController->moveCommand.translatory = false;
}
})
};

::Ctrl::Operation moveTrans_prs{
"move-trans-prs", OS::KeyBind(::Ctrl::Key::Left_Shift, ::Ctrl::Act::Press, +[]{
if(Game::core->playerController){
Game::core->playerController->moveCommand.translatory = true;
}
}),
{moveTrans_rls.name}
};
}

export
template <>
struct ::Core::IO::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>> : Game::ChamberGridData<Game::SpaceCraft>::JsonSrl{};
struct ::ext::json::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>> : Game::ChamberGridData<Game::SpaceCraft>::JsonSrl{};

export
template <>
struct ::Core::IO::JsonSerializator<Game::ChamberGrid<Game::SpaceCraft>>{
struct ::ext::json::JsonSerializator<Game::ChamberGrid<Game::SpaceCraft>>{
static void write(ext::json::JsonValue& jsonValue, const Game::ChamberGrid<Game::SpaceCraft>& data){
::Core::IO::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>>::write(jsonValue, data);
::ext::json::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>>::write(jsonValue, data);
}

static void read(const ext::json::JsonValue& jsonValue, Game::ChamberGrid<Game::SpaceCraft>& data){
::Core::IO::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>>::read(jsonValue, data);
::ext::json::JsonSerializator<Game::ChamberGridData<Game::SpaceCraft>>::read(jsonValue, data);
data.reTree();
}
};

export template<>
struct ::Core::IO::JsonSerializator<Game::ChamberTile<Game::SpaceCraft>> : Game::ChamberJsonSrl<Game::SpaceCraft>{};
struct ::ext::json::JsonSerializator<Game::ChamberTile<Game::SpaceCraft>> : Game::ChamberJsonSrl<Game::SpaceCraft>{};

export namespace Test{
std::unique_ptr<Game::ChamberGridTrans<Game::SpaceCraft>> chamberFrame{};
Expand All @@ -113,11 +177,11 @@ export namespace Test{

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

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

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

auto dur = std::chrono::high_resolution_clock::now() - cur;
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(dur) << std::endl;
Expand Down Expand Up @@ -351,7 +415,7 @@ void setupUITest_Old(){
});
});
// rt->add(new UI::Elem);
rt.lineFeed();
rt.endline();
rt.transferElem(new UI::Elem{});
rt.transferElem(new UI::Elem{});
});
Expand Down
4 changes: 2 additions & 2 deletions src/Test.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Game.Entity.Controller.Player;
import Game.Entity.Controller.AI;

import Core.IO.Specialized;
import Core.IO.JsonIO;
import ext.json.io;
import ext.Encoding;
import Image.Svg;

Expand Down Expand Up @@ -115,7 +115,7 @@ export namespace Test{
Game::core = std::make_unique<Game::Core>();
Core::loopManager->setGameCore(Game::core.get());

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

Core::destructors.push_back([]{
Expand Down
4 changes: 2 additions & 2 deletions src/arc-impl/AssetsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Font;
import OS.File;
import Font.GlyphArrangement;
import OS;
import Event;
import ext.Event;

void Assets::Manager::pullRequest() {
loadEvents.fire(AssetsLoadInit{this});
Expand Down Expand Up @@ -86,7 +86,7 @@ void Assets::Manager::loadPost() {
Assets::loadAfter();

Font::defGlyphParser->context.defaultFont = Assets::Fonts::telegrama;
Font::defGlyphParser->fontLib = fonts.atlas.get();
Font::defGlyphParser->loadedFonts = fonts.atlas.get();
}

void Assets::Manager::loadEnd() {
Expand Down
6 changes: 3 additions & 3 deletions src/arc-impl/GlyphArrangement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Font::GlyphLayout::render(const float alphaMask, float progress) const {
}
}

Font::TypesettingContext::TypesettingContext(const FontFlags* const font): defaultFont(font), currentFont(font),
Font::TypesettingContext::TypesettingContext(const FontFace* const font): defaultFont(font), currentFont(font),
fallbackFont(font) {
if(!currentFont) throw ext::NullPointerException{};
lineSpacing = currentFont->data->lineSpacingDef * 1.8f;
Expand Down Expand Up @@ -223,7 +223,7 @@ void Font::GlyphParser::parse(const std::shared_ptr<GlyphLayout>& layout) const
layout->updateDrawbound();
}

void Font::initParser(const FontFlags* const defFont) {
void Font::initParser(const FontFace* const defFont) {
defGlyphParser = std::make_unique<GlyphParser>(defFont);

defGlyphParser->charParser->registerDefParser();
Expand Down Expand Up @@ -253,7 +253,7 @@ void Font::initParser(const FontFlags* const defFont) {
} else {
data.context.fallbackFont = data.context.currentFont;
try {
data.context.currentFont = defGlyphParser->fontLib->obtain(std::stoi(static_cast<Font::TextString>(sub)));
data.context.currentFont = defGlyphParser->loadedFonts->obtain(std::stoi(static_cast<Font::TextString>(sub)));
} catch([[maybe_unused]] std::invalid_argument& e) {
//TODO throw maybe ?
}
Expand Down
32 changes: 19 additions & 13 deletions src/arc-impl/ui/Cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,52 @@ module UI.Cell;
bool UI::LayoutCell::applySizeToItem(){ // NOLINT(*-make-member-function-const)
const Geom::Vec2 originalSize = allocatedBound.getSize();

Geom::Vec2 exportSize{};

if(hasDefWidth()){
item->setWidth(defSize.x);
exportSize.x = defSize.x;
}

if(hasDefHeight()){
item->setHeight(defSize.y);
exportSize.y = defSize.y;
}

//Apply Expansion
if(modifyParentX) {
const float width = Math::max(allocatedBound.getWidth(), item->getWidth());
const float width = Math::max(allocatedBound.getWidth(), exportSize.x);
allocatedBound.setWidth(width * getHoriScale());
}else{
// allocatedBound.setShorterWidth(item->getWidth());
}

if(modifyParentY) {
const float height = Math::max(allocatedBound.getHeight(), item->getHeight());
const float height = Math::max(allocatedBound.getHeight(), exportSize.y);
allocatedBound.setHeight(height * getVertScale());
}else{
// allocatedBound.setShorterHeight(item->getHeight());
}

if(scaleRelativeToParentX){
item->setWidth(allocatedBound.getWidth() * getHoriScale());
exportSize.x = allocatedBound.getWidth() * getHoriScale();
}

if(scaleRelativeToParentY){
item->setHeight(allocatedBound.getHeight() * getVertScale());
exportSize.y = allocatedBound.getHeight() * getVertScale();
}

if(hasRatioFromWidth()){
exportSize.y = exportSize.x * getRatio_W2H();
}

if(hasRatioFromHeight()){
exportSize.x = exportSize.y * getRatio_H2W();
}

//TODO uses validsize instead
item->setSize(
Math::clampPositive(item->getWidth() - getMarginHori()),
Math::clampPositive(item->getHeight() - getMarginVert())
);
item->setWidth_Quiet(Math::clampPositive(exportSize.x - getMarginHori()));
item->setHeight_Quiet(Math::clampPositive(exportSize.y - getMarginVert()));

Geom::Vec2 currentSize = item->bound.getSize();
if(currentSize == Geom::Vec2{std::numeric_limits<float>::max(), std::numeric_limits<float>::max()}){
const Geom::Vec2 currentSize = item->bound.getSize();
if(currentSize == Geom::maxVec2<float>){
item->setMaximumSize(allocatedBound.getSize());
}

Expand Down
5 changes: 3 additions & 2 deletions src/arc-impl/ui/Root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UI.Drawer;
import std;
import Core;
import OS.ApplicationListenerSetter;
import ext.algorithm;

void UI::Root::setRootOf(Elem* widget){
widget->setRoot(this);
Expand Down Expand Up @@ -39,8 +40,8 @@ UI::Root::Root(): tooltipManager{this}{
UI::Root::~Root(){
Core::input.eraseSubInput(&uiInput);

std::erase(Core::input.inputKeyListeners, this);
std::erase(Core::input.inputMouseListeners, this);
ext::algo::erase_unique_unstable(Core::input.inputKeyListeners, this);
ext::algo::erase_unique_unstable(Core::input.inputMouseListeners, this);
}

void UI::Root::loadBinds(const Elem* elem, OS::InputBindGroup& binds){
Expand Down
Loading

0 comments on commit 1bf7d4c

Please sign in to comment.