Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuria-Shikibe committed May 16, 2024
1 parent e48b8d0 commit f4aac97
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 119 deletions.
164 changes: 95 additions & 69 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,51 +191,69 @@ std::stringstream sstream{};
std::unique_ptr<Game::ChamberFrameTrans<Game::SpaceCraft>> chamberFrame{};
std::unique_ptr<Game::ChamberFactory<Game::SpaceCraft>> testFactory{std::make_unique<TestChamberFactory>()};

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

::Ctrl::Operation moveBack{"move-down", OS::KeyBind(::Ctrl::Key::S, ::Ctrl::Act::Continuous, +[] {
Game::core->sendPlayerMoveAct(Geom::down<float>);
})};
::Ctrl::Operation moveRight{
"move-right", OS::KeyBind(::Ctrl::Key::D, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::right<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 moveForward{
"move-up", OS::KeyBind(::Ctrl::Key::W, ::Ctrl::Act::Continuous, +[]{
Game::core->sendPlayerMoveAct(Geom::up<float>);
})
};

::Ctrl::Operation shoot_prs{"shoot-prs", OS::KeyBind(::Ctrl::Mouse::LMB, ::Ctrl::Act::Press, +[] {
if(Game::core->playerController){
Game::core->playerController->shoot = true;
}
}), {shoot_rls.name}};
::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 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 shoot_prs{
"shoot-prs", OS::KeyBind(::Ctrl::Mouse::LMB, ::Ctrl::Act::Press, +[]{
if(Game::core->playerController){
Game::core->playerController->shoot = true;
}
}),
{shoot_rls.name}
};

::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}};

::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}
};
}


void setupUITest(){
const auto HUD = new UI::Table{};

Expand Down Expand Up @@ -394,7 +412,9 @@ void setupUITest(){
button.add<UI::Label>([](UI::Label& label){
label.setTextAlign(Align::Mode::center);
label.setEmptyDrawer();
label.setTextScl(0.75f);
label.setTextScl(0.65f);
label.setFillparentX();
label.setWrap();

label.setText(label.getBundleEntry("sync-camera"));
}).setHeight(60);
Expand All @@ -410,7 +430,9 @@ void setupUITest(){
button.add<UI::Label>([](UI::Label& label){
label.setTextAlign(Align::Mode::center);
label.setEmptyDrawer();
label.setTextScl(0.75f);
label.setTextScl(0.65f);
label.setFillparentX();
label.setWrap();

label.setText(label.getBundleEntry("draw-debug"));
}).setHeight(60);
Expand Down Expand Up @@ -498,17 +520,19 @@ void setupUITest(){
}

void setupCtrl(){
Assets::Ctrl::gameGroup = Ctrl::OperationGroup{Assets::Ctrl::gameGroup.getName(), {
GameCtrl::moveLeft,
GameCtrl::moveRight,
GameCtrl::moveForward,
GameCtrl::moveBack,

GameCtrl::shoot_prs,
GameCtrl::shoot_rls,
GameCtrl::moveTrans_prs,
GameCtrl::moveTrans_rls,
}};
Assets::Ctrl::gameGroup = Ctrl::OperationGroup{
Assets::Ctrl::gameGroup.getName(), {
GameCtrl::moveLeft,
GameCtrl::moveRight,
GameCtrl::moveForward,
GameCtrl::moveBack,

GameCtrl::shoot_prs,
GameCtrl::shoot_rls,
GameCtrl::moveTrans_prs,
GameCtrl::moveTrans_rls,
}
};
//TODO unsafe
Assets::Ctrl::gameGroup.loadInstruction(Core::bundle);
Assets::Ctrl::gameGroup.targetGroup = &Game::core->gameBinds;
Expand Down Expand Up @@ -634,27 +658,29 @@ int main(const int argc, char* argv[]){
Game::core->overlayManager->deactivate();
}

auto loadChamber = []{
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};
chamberFrame->getChambers() = Game::ChamberUtil::genFrameFromPixmap<Game::SpaceCraft>(
pixmap_, {-pixmap_.getWidth() / 2, -pixmap_.getHeight() / 2});

ext::json::JsonValue jval = ext::json::getJsonOf(chamberFrame->getChambers());

fi.writeString(std::format("{:nf0}", jval));
} else{
ext::json::Json json{fi.readString()};

ext::json::getValueTo(chamberFrame->getChambers(), json.getData());
}
};
// auto loadChamber = []{
// 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};
// chamberFrame->getChambers() = Game::ChamberUtil::genFrameFromPixmap<Game::SpaceCraft>(
// pixmap_, {-pixmap_.getWidth() / 2, -pixmap_.getHeight() / 2});
//
// ext::json::JsonValue jval = ext::json::getJsonOf(chamberFrame->getChambers());
//
// fi.writeString(std::format("{:nf0}", jval));
// } else{
// auto str = fi.quickRead();
//
// ext::json::Json json{fi.readString()};
//
// ext::json::getValueTo(chamberFrame->getChambers(), json.getData());
// }
// };

loadChamber();
// loadChamber();

// UI Test
setupUITest();
Expand All @@ -669,7 +695,7 @@ int main(const int argc, char* argv[]){


chamberFrame = std::make_unique<Game::ChamberFrameTrans<Game::SpaceCraft>>();
loadChamber();
// loadChamber();

GL::MultiSampleFrameBuffer multiSample{Core::renderer->getWidth(), Core::renderer->getHeight()};
GL::FrameBuffer frameBuffer{Core::renderer->getWidth(), Core::renderer->getHeight()};
Expand Down Expand Up @@ -720,7 +746,7 @@ int main(const int argc, char* argv[]){


Core::renderer->getListener().on<Event::Draw_After>([&](const Event::Draw_After& event){
if(!drawDebug)return;
if(!drawDebug) return;
// event.renderer->effectBuffer.bind();
event.renderer->frameBegin(&frameBuffer);

Expand Down
8 changes: 4 additions & 4 deletions properties/resource/data/settings/ctrl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
{
"$k" : "cmove-up",
"$v" : {
"full" : 196873,
"full" : 196695,
"ignore" : true
}
},
{
"$k" : "cmove-left",
"$v" : {
"full" : 196871,
"full" : 196673,
"ignore" : true
}
},
{
"$k" : "cmove-right",
"$v" : {
"full" : 196870,
"full" : 196676,
"ignore" : true
}
},
{
"$k" : "cmove-down",
"$v" : {
"full" : 196872,
"full" : 196691,
"ignore" : true
}
},
Expand Down
9 changes: 2 additions & 7 deletions src/arc/asset/Bundle.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ export namespace Assets{
}

static ext::json::JsonValue loadFile(const OS::File& file){
const auto str = file.readString([](std::string& line){
return std::erase_if(line, std::not_fn(ext::json::notIgnore));
});

ext::json::JsonValue jval{};
jval.parseObject(str);
return jval;
ext::json::Json jval{file.quickRead()};
return jval.getData();
}

static std::optional<std::string_view> find(const std::vector<std::string_view>& dir, const ext::json::Object* last){
Expand Down
82 changes: 60 additions & 22 deletions src/arc/asset/effect/Effects.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export namespace Assets::Effects{
void operator()(Graphic::Effect& effect) const override{
const auto& [trail] = std::any_cast<Data&>(effect.additionalData);

trail.each<Graphic::Trail::DefDraw, false>(effect.trans.rot, Graphic::Trail::DefDraw{effect.color}, trail.size() * effect.progress.get());
trail.each<Graphic::Trail::DefDraw, false>(effect.trans.rot, Graphic::Trail::DefDraw{effect.color},
trail.size() * effect.progress.get());
}
};

Expand All @@ -52,7 +53,8 @@ export namespace Assets::Effects{
void operator()(Graphic::Effect& effect) const override{
const auto& [trail, endColor] = std::any_cast<Data&>(effect.additionalData);

trail.each(effect.trans.rot, Graphic::Trail::DefDraw_WithLerp{effect.color, endColor}, trail.size() * effect.progress.get());
trail.each(effect.trans.rot, Graphic::Trail::DefDraw_WithLerp{effect.color, endColor},
trail.size() * effect.progress.get());
}
};

Expand All @@ -65,7 +67,8 @@ export namespace Assets::Effects{
return effect;
}

Graphic::Effect* genTrailFade(Graphic::EffectManager* manager, Graphic::Trail&& points, const float width = 1.0f, const Graphic::Color& endColor = Graphic::Colors::GRAY){
Graphic::Effect* genTrailFade(Graphic::EffectManager* manager, Graphic::Trail&& points, const float width = 1.0f,
const Graphic::Color& endColor = Graphic::Colors::GRAY){
static constexpr EffectDrawer_TrailFade_WithLerp drawer{60.0f};
const auto effect = drawer.suspendOn(manager);
effect->trans.rot = width;
Expand All @@ -76,31 +79,66 @@ export namespace Assets::Effects{

std::unique_ptr<Graphic::EffectDrawer>
circleOut = Graphic::makeEffect(60.0f, [](const Graphic::Effect& effect){
Graphic::Draw::color(Graphic::Colors::WHITE, effect.color, effect.progress.getMargin(0.35f));
Graphic::Draw::Line::setLineStroke(effect.progress.getInv() * 4.5f);
Graphic::Draw::Line::circle(effect.trans.vec.x, effect.trans.vec.y, effect.progress.get(Math::Interp::pow2Out) * 120.0f);
using namespace Graphic;

Draw::color(Colors::WHITE, effect.color, effect.progress.getMargin(0.35f));
Draw::Line::setLineStroke(effect.progress.getInv() * 4.5f);
Draw::Line::circle(effect.trans.vec.x, effect.trans.vec.y,
effect.progress.get(Math::Interp::pow2Out) * 120.0f);
}),

squareOut = Graphic::makeEffect(60.0f, [](const Graphic::Effect& effect){
Graphic::Draw::color(Graphic::Colors::WHITE, effect.color, effect.progress.getMargin(0.35f));
Graphic::Draw::Line::setLineStroke(effect.progress.getInv() * 4.5f);
Graphic::Draw::Line::square(effect.trans.vec.x, effect.trans.vec.y, effect.progress.get(Math::Interp::pow2Out) * 120.0f, 45);
using namespace Graphic;

Draw::color(Colors::WHITE, effect.color, effect.progress.getMargin(0.35f));
Draw::Line::setLineStroke(effect.progress.getInv() * 4.5f);
Draw::Line::square(effect.trans.vec.x, effect.trans.vec.y,
effect.progress.get(Math::Interp::pow2Out) * 120.0f, 45);
}),

sparkLarge = Graphic::makeEffect(60.0f, [](const Graphic::Effect& e){
Graphic::Draw::color(e.color, Graphic::Colors::WHITE, e.progress.getInv() * 0.3f);
Graphic::Draw::Line::setLineStroke(e.progress.getInv() * 8.6f);

Graphic::Draw::setTexture(Graphic::Draw::globalState.defaultLightTexture);
Graphic::Draw::setZ(e.zOffset);
Graphic::splashVec(e.handle, {.count = 18, .progress = e.progress.get(Math::Interp::pow2Out) * 27.0f, .radius = {3, 15}},
[vecSrc = e.trans.vec, progress = e.progress.getInv()](const auto vec2, auto& rand){
Graphic::Draw::Line::lineAngle<Graphic::BatchWorld>(
{vecSrc + vec2, vec2.angle()},
progress * rand.random(12.0f, 33.0f) + 2.0f
);
});
Graphic::Draw::setTexture();
using namespace Graphic;

Draw::color(e.color, Colors::WHITE, e.progress.getInv() * 0.3f);
Draw::Line::setLineStroke(e.progress.getInv() * 8.6f);

Draw::setTexture(Draw::globalState.defaultLightTexture);
Draw::setZ(e.zOffset);
splashVec(e.handle, {
.count = 18, .progress = e.progress.get(Math::Interp::pow2Out) * 27.0f,
.radius = {3, 15}
},
[vecSrc = e.trans.vec, progress = e.progress.getInv()](const auto vec2, auto& rand){
Draw::Line::lineAngle<BatchWorld>(
{vecSrc + vec2, vec2.angle()},
progress * rand.random(12.0f, 33.0f) + 2.0f
);
});
Draw::setTexture();
}),

explode = Graphic::makeEffect(120.0f, [](const Graphic::Effect& e){
using Math::Interp::operator|;
using namespace Graphic;
Draw::setTexture(Draw::globalState.defaultLightTexture);

Draw::color(e.color, Colors::WHITE, e.progress.getInv() * 0.3f);
Draw::setZ(e.zOffset);

Draw::Line::setLineStroke(e.progress.getInv() * 7.f);
Draw::Line::circle<BatchWorld>(e.trans.vec.x, e.trans.vec.y,
e.progress.get(Math::Interp::pow3Out) * e.trans.rot * 1.4f);

splashVec(e.handle, {
.count = 18, .progress = e.progress.get(Math::Interp::pow2Out),
.radius = {e.trans.rot * 0.3f, e.trans.rot * 1.25f}
},
[&e](const Geom::Vec2 vec2, Math::Rand& rand){
const auto pos = e.trans.vec + vec2;
Draw::color(Colors::DARK_GRAY, Colors::GRAY, rand.random(0.1f, 0.5f));
Draw::Fill::circle<BatchWorld>(pos.x, pos.y, (e.progress.getInv() | Math::Interp::pow2In) * rand.random(e.trans.rot * 0.2f, e.trans.rot * 0.6f) + 2.0f);
});
Draw::setTexture();
});

// EffectDrawer_Func<[](const Graphic::Effect& effect){
Expand Down
2 changes: 1 addition & 1 deletion src/arc/asset/font/UnicodeRefParser.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OS.File;

export namespace Font{
std::vector<unsigned> genRefTable(const OS::File& reference){
const std::string src = reference.readString();
const std::string src = reference.quickRead();
std::vector<unsigned> dest{};
dest.reserve(src.size() * 4);

Expand Down
Loading

0 comments on commit f4aac97

Please sign in to comment.