Skip to content

Commit

Permalink
Draw Refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuria-Shikibe committed May 27, 2024
1 parent c44f4df commit de3ac1b
Show file tree
Hide file tree
Showing 53 changed files with 2,201 additions and 2,048 deletions.
48 changes: 22 additions & 26 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <glad/glad.h>

#include "src/application_head.h"
Expand Down Expand Up @@ -587,14 +586,14 @@ REFL_REGISTER_CLASS_DEF(::TestChamberFactory::ChamberType<>)

void setupBaseDraw(){
::Core::renderer->getListener().on<Event::Draw_Overlay>([](const auto& e){
Graphic::Batch::flush();
Graphic::Draw::Overlay::getBatch().flush();
Core::uiRoot->drawCursor();
Graphic::Batch::flush();
Graphic::Draw::Overlay::getBatch().flush();
});

::Core::renderer->getListener().on<Event::Draw_After>([]([[maybe_unused]] const auto& e){
Game::core->drawBeneathUI(e.renderer);
Graphic::Batch::flush();
Graphic::Draw::Overlay::getBatch().flush();
});
}

Expand All @@ -609,7 +608,7 @@ int main(const int argc, char* argv[]){

Core::audio->engine->setSoundVolume(0.5f);

::Test::chamberFrame = std::make_unique<Game::ChamberFrameTrans<Game::SpaceCraft>>();
::Test::chamberFrame = std::make_unique<Game::ChamberGridTrans<Game::SpaceCraft>>();

if(true){
Game::core->overlayManager->activate();
Expand All @@ -630,7 +629,7 @@ int main(const int argc, char* argv[]){
setupBaseDraw();


::Test::chamberFrame = std::make_unique<Game::ChamberFrameTrans<Game::SpaceCraft>>();
::Test::chamberFrame = std::make_unique<Game::ChamberGridTrans<Game::SpaceCraft>>();
::Test::loadChamberTest();

Core::uiRoot->registerScene<Game::Scenes::MainMenu>(UI::Menu_Main);
Expand All @@ -649,7 +648,7 @@ int main(const int argc, char* argv[]){
Assets::PostProcessors::blurX_World.get(), Assets::PostProcessors::blurY_World.get(),
Assets::Shaders::merge
};
// merger.blur.setScale(0.5f);
merger.blur.setScale(0.5f);
merger.blur.setProcessTimes(4);
merger.setTargetState(GL::State::BLEND, true);

Expand All @@ -672,10 +671,10 @@ int main(const int argc, char* argv[]){
// event.renderer->effectBuffer.bind();
event.renderer->frameBegin(&frameBuffer);

Draw::Line::setLineStroke(5);
Draw::color(Colors::GRAY);
Draw::Overlay::Line::setLineStroke(5);
Draw::Overlay::color(Colors::GRAY);
Game::EntityManage::realEntities.quadTree->each([](decltype(Game::EntityManage::realEntities)::TreeType* t){
Draw::Line::rectOrtho(t->getBoundary());
Draw::Overlay::Line::rectOrtho(t->getBoundary());
});

Game::EntityManage::renderDebug();
Expand Down Expand Up @@ -712,7 +711,7 @@ int main(const int argc, char* argv[]){

Game::core->effectManager->render(Core::camera->getViewport());

Graphic::Batch::flush<BatchWorld>();
Graphic::Draw::World::getBatch().flush();

GL::disable(GL::Test::DEPTH);
GL::setDepthMask(false);
Expand All @@ -729,11 +728,11 @@ int main(const int argc, char* argv[]){
::Test::chamberFrame->getLocalToWorld().scale(10.0f, 10.0f);

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

Graphic::Batch::blend<>();
Graphic::Draw::Overlay::getBatch().flush();
/*//
chamberFrame->updateDrawTarget(Core::camera->getViewportRect());
::Game::Draw::chamberFrameTile(*chamberFrame, Core::renderer, true);
Expand Down Expand Up @@ -763,29 +762,26 @@ int main(const int argc, char* argv[]){
}
*/

Graphic::Batch::blend();

Draw::Line::setLineStroke(4);
Graphic::Draw::Overlay::getBatch().switchBlending();

{
static Geom::Matrix3D mat{};

Graphic::Batch::beginPorj(mat.setOrthogonal(Core::renderer->getSize()));
Draw::color();
Core::BatchGuard_Proj _{Graphic::Draw::Overlay::getBatch()};
_.current.setOrthogonal(Core::renderer->getSize());

auto [x, y] = Core::renderer->getSize().scl(0.5f);
Draw::Line::square(x, y, 50, 45);
Draw::Line::poly(x, y, 64, 160, 0, Math::clamp(fmod(OS::updateTime() / 5.0f, 1.0f)),

using Graphic::Draw::Overlay;

Overlay::color(Graphic::Colors::PALE_GREEN);
Overlay::Line::setLineStroke(4.f);
Overlay::Line::square(x, y, 50, 45);
Overlay::Line::poly(x, y, 64, 160, 0, Math::clamp(fmod(OS::updateTime() / 5.0f, 1.0f)),
Colors::SKY.copy().setA(0.55f), Colors::ROYAL.copy().setA(0.55f),
Colors::SKY.copy().setA(0.55f), Colors::WHITE.copy().setA(0.55f),
Colors::ROYAL.copy().setA(0.55f), Colors::SKY.copy().setA(0.55f)
);

Graphic::Batch::endPorj();
}

Graphic::Batch::flush();

e.renderer->frameEnd(Assets::PostProcessors::blendMulti.get());
e.renderer->frameEnd(Assets::PostProcessors::bloom.get());
});
Expand Down
22 changes: 11 additions & 11 deletions src/SideTemp.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export struct TestChamberFactory : Game::ChamberFactory<Game::SpaceCraft>{
}

void draw(const Game::Chamber<EntityType>* chamber, const EntityType& entity, const TraitDataType& data) const{
Graphic::Draw::setZ(entity.zLayer);
Graphic::Draw::rectOrtho<&Core::BatchGroup::world>(Graphic::Draw::globalState.defaultSolidTexture,
chamber->getChamberBound());
Graphic::Draw::World::setZ(entity.zLayer);
Graphic::Draw::World::Fill::rectOrtho(Graphic::Draw::World::defaultSolidTexture,
chamber->getEntityBound());
}
} baseTraitTest;

Expand All @@ -78,17 +78,17 @@ REFL_REGISTER_CLASS_DEF(::TestChamberFactory::ChamberType<>)

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

export
template <>
struct ::Core::IO::JsonSerializator<Game::ChamberFrame<Game::SpaceCraft>>{
static void write(ext::json::JsonValue& jsonValue, const Game::ChamberFrame<Game::SpaceCraft>& data){
::Core::IO::JsonSerializator<Game::ChamberFrameData<Game::SpaceCraft>>::write(jsonValue, data);
struct ::Core::IO::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);
}

static void read(const ext::json::JsonValue& jsonValue, Game::ChamberFrame<Game::SpaceCraft>& data){
::Core::IO::JsonSerializator<Game::ChamberFrameData<Game::SpaceCraft>>::read(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);
data.reTree();
}
};
Expand All @@ -97,7 +97,7 @@ export template<>
struct ::Core::IO::JsonSerializator<Game::ChamberTile<Game::SpaceCraft>> : Game::ChamberJsonSrl<Game::SpaceCraft>{};

export namespace Test{
std::unique_ptr<Game::ChamberFrameTrans<Game::SpaceCraft>> chamberFrame{};
std::unique_ptr<Game::ChamberGridTrans<Game::SpaceCraft>> chamberFrame{};
std::unique_ptr<Game::ChamberFactory<Game::SpaceCraft>> testFactory{std::make_unique<TestChamberFactory>()};

void loadChamberTest(){
Expand Down Expand Up @@ -174,7 +174,7 @@ export namespace Test{
ptr->chambers.operator=(std::move(*chamberFrame));
ptr->chamberTrans.vec.x = 85;
ptr->physicsBody.inertialMass = 4000;
chamberFrame = std::make_unique<Game::ChamberFrameTrans<Game::SpaceCraft>>();
chamberFrame = std::make_unique<Game::ChamberGridTrans<Game::SpaceCraft>>();
ptr->controller.reset(new Game::PlayerController{ptr.get()});

}
Expand Down
18 changes: 11 additions & 7 deletions src/Test.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export namespace Test{
Core::renderer->registerSynchronizedResizableObject(Core::camera);
});

Graphic::Draw::setDefTexture(&Assets::Textures::whiteRegion);
Graphic::Draw::setTexture();
Graphic::Draw::World::setDefTexture(&Assets::Textures::whiteRegion);
Graphic::Draw::Overlay::setDefTexture(&Assets::Textures::whiteRegion);

Graphic::Frame::rawMesh = Assets::Meshes::raw.get();
Graphic::Frame::blitter = Assets::Shaders::blit;

Expand Down Expand Up @@ -198,12 +199,18 @@ export namespace Test{
texture2D->setScale(GL::TexParams::mipmap_linear_linear);
}


Assets::Textures::whiteRegion = *event.manager->getAtlas().find("base-white-solid");
Assets::Textures::whiteRegion.shrinkEdge(15.0f);
Graphic::Draw::globalState.defaultSolidTexture = Graphic::Draw::getDefaultTexture();

auto lightRegion = event.manager->getAtlas().find("base-white-light");
Graphic::Draw::globalState.defaultLightTexture = lightRegion;

Graphic::Draw::Overlay::setDefTexture(&Assets::Textures::whiteRegion);

Graphic::Draw::World::defaultSolidTexture = Graphic::Draw::Overlay::getDefaultTexture();
Graphic::Draw::World::defaultLightTexture = lightRegion;
Graphic::Draw::World::setDefTexture(lightRegion);

const_cast<GL::TextureRegionRect*>(lightRegion)->shrinkEdge(15.0f);

for(auto& texture : event.manager->getAtlas().getPage("ui").getTextures()){
Expand All @@ -214,9 +221,6 @@ export namespace Test{
texture->setScale(GL::TexParams::mipmap_linear_nearest, GL::TexParams::nearest);
}

Graphic::Draw::setDefTexture(&Assets::Textures::whiteRegion);
Graphic::Draw::setTexture();

UI::Styles::load(event.manager->getAtlas());

{
Expand Down
4 changes: 2 additions & 2 deletions src/arc-impl/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Graphic::Effect* Graphic::EffectShake::create(EffectManager* manager, Core::Came
auto* eff = suspendOn(manager);
fadeSpeed = fadeSpeed > 0 ? fadeSpeed : intensity / 32.f;
eff->set({pos, intensity}, Graphic::Colors::CLEAR, intensity / fadeSpeed, camera);
eff->zOffset = fadeSpeed;
eff->zLayer = fadeSpeed;

return eff;
}
Expand All @@ -32,6 +32,6 @@ Graphic::Effect* Graphic::EffectShake::create(const Geom::Vec2 pos, const float
void Graphic::EffectShake::operator()(Effect& effect) const{
if(auto* camera = std::any_cast<Core::Camera2D*>(effect.additionalData)){
const float dst = effect.trans.vec.dst(camera->getPosition());
camera->shake(getIntensity(dst) * effect.trans.rot, effect.zOffset);
camera->shake(getIntensity(dst) * effect.trans.rot, effect.zLayer);
}
}
10 changes: 5 additions & 5 deletions src/arc-impl/GlyphArrangement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void Font::GlyphLayout::render(const float alphaMask) const {
if(empty()) return;
const Geom::Vec2 off = getDrawOffset();
for (auto& glyph : glyphs){
Graphic::Draw::color(glyph.fontColor, glyph.fontColor.a * alphaMask);
Graphic::Draw::quad(
Graphic::Draw::Overlay::color(glyph.fontColor, glyph.fontColor.a * alphaMask);
Graphic::Draw::Overlay::Fill::quad(
glyph.region,
glyph.v00().scl(scale) + off,
glyph.v10().scl(scale) + off,
Expand All @@ -49,9 +49,9 @@ void Font::GlyphLayout::render(const float alphaMask, float progress) const {

const Geom::Vec2 off = getDrawOffset();
for (auto& glyph : this->glyphs | std::ranges::views::take(static_cast<size_t>(progress * static_cast<float>(glyphs.size())))){
Graphic::Draw::color(glyph.fontColor, glyph.fontColor.a * alphaMask);
Graphic::Draw::Overlay::color(glyph.fontColor, glyph.fontColor.a * alphaMask);

Graphic::Draw::quad(
Graphic::Draw::Overlay::Fill::quad(
glyph.region,
glyph.v00().scl(scale) + off,
glyph.v10().scl(scale) + off,
Expand All @@ -64,7 +64,7 @@ void Font::GlyphLayout::render(const float alphaMask, float progress) const {
Font::TypesettingContext::TypesettingContext(const FontFlags* const font): defaultFont(font), currentFont(font),
fallbackFont(font) {
if(!currentFont) throw ext::NullPointerException{};
lineSpacing = currentFont->data->lineSpacingMin * 1.8f;
lineSpacing = currentFont->data->lineSpacingDef * 1.8f;
paragraphSpacing = lineSpacing * 1.1f;
}

Expand Down
36 changes: 18 additions & 18 deletions src/arc-impl/TextureNineRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ void GL::TextureNineRegion::render_RelativeExter(const float x, const float y, c
tempEdge.top -= remain * 0.5f;
}

Draw::rectOrtho(&regions[ID_center], x + tempEdge.left, y + tempEdge.bottom, width - tempEdge.getWidth(), height - tempEdge.getHeight());
Draw::Overlay::Fill::rectOrtho(&regions[ID_center], x + tempEdge.left, y + tempEdge.bottom, width - tempEdge.getWidth(), height - tempEdge.getHeight());

Draw::rectOrtho(&regions[ID_right], x + width - tempEdge.right, y + tempEdge.bottom, tempEdge.right, height - tempEdge.bottom - tempEdge.top);
Draw::rectOrtho(&regions[ID_top], x + tempEdge.left, y + height - tempEdge.top, width - tempEdge.left - tempEdge.right, tempEdge.top);
Draw::rectOrtho(&regions[ID_left], x, y + tempEdge.bottom, tempEdge.left, height - tempEdge.bottom - tempEdge.top);
Draw::rectOrtho(&regions[ID_bottom], x + tempEdge.left, y, width - tempEdge.left - tempEdge.right, tempEdge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_right], x + width - tempEdge.right, y + tempEdge.bottom, tempEdge.right, height - tempEdge.bottom - tempEdge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_top], x + tempEdge.left, y + height - tempEdge.top, width - tempEdge.left - tempEdge.right, tempEdge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_left], x, y + tempEdge.bottom, tempEdge.left, height - tempEdge.bottom - tempEdge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottom], x + tempEdge.left, y, width - tempEdge.left - tempEdge.right, tempEdge.bottom);

Draw::rectOrtho(&regions[ID_topRight], x + width - tempEdge.right, y + height - tempEdge.top, tempEdge.right, tempEdge.top);
Draw::rectOrtho(&regions[ID_topLeft], x, y + height - tempEdge.top, tempEdge.left, tempEdge.top);
Draw::rectOrtho(&regions[ID_bottomLeft], x, y, tempEdge.left, tempEdge.bottom);
Draw::rectOrtho(&regions[ID_bottomRight], x + width - tempEdge.right, y, tempEdge.right, tempEdge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_topRight], x + width - tempEdge.right, y + height - tempEdge.top, tempEdge.right, tempEdge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_topLeft], x, y + height - tempEdge.top, tempEdge.left, tempEdge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottomLeft], x, y, tempEdge.left, tempEdge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottomRight], x + width - tempEdge.right, y, tempEdge.right, tempEdge.bottom);
}

void GL::TextureNineRegion::render_RelativeInner(const float x, const float y, const float width,
const float height) const {
Draw::rectOrtho(&regions[ID_center], x, y, width, height);
Draw::Overlay::Fill::rectOrtho(&regions[ID_center], x, y, width, height);

Draw::rectOrtho(&regions[ID_right], x + width, y, edge.right, height);
Draw::rectOrtho(&regions[ID_top], x, y + height, width, edge.top);
Draw::rectOrtho(&regions[ID_left], x - edge.left, y, edge.left, height);
Draw::rectOrtho(&regions[ID_bottom], x, y - edge.bottom, width, edge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_right], x + width, y, edge.right, height);
Draw::Overlay::Fill::rectOrtho(&regions[ID_top], x, y + height, width, edge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_left], x - edge.left, y, edge.left, height);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottom], x, y - edge.bottom, width, edge.bottom);

Draw::rectOrtho(&regions[ID_topRight], x + width, y + height, edge.right, edge.top);
Draw::rectOrtho(&regions[ID_topLeft], x - edge.left, y + height, edge.left, edge.top);
Draw::rectOrtho(&regions[ID_bottomLeft], x - edge.left, y - edge.bottom, edge.left, edge.bottom);
Draw::rectOrtho(&regions[ID_bottomRight], x + width, y - edge.bottom, edge.right, edge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_topRight], x + width, y + height, edge.right, edge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_topLeft], x - edge.left, y + height, edge.left, edge.top);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottomLeft], x - edge.left, y - edge.bottom, edge.left, edge.bottom);
Draw::Overlay::Fill::rectOrtho(&regions[ID_bottomRight], x + width, y - edge.bottom, edge.right, edge.bottom);
}
Loading

0 comments on commit de3ac1b

Please sign in to comment.