diff --git a/ADVect/ADVect.cpp b/ADVect/ADVect.cpp index 7ae4852..ab8b586 100644 --- a/ADVect/ADVect.cpp +++ b/ADVect/ADVect.cpp @@ -32,9 +32,14 @@ namespace ADVect { if (SDL_Init(SDL_INIT_VIDEO)) { std::cerr << "Failed to init SDL: " << SDL_GetError() << std::endl; + return; } window = SDL_CreateWindow(m_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_height, SDL_WINDOW_SHOWN); + if (window == NULL) { + std::cerr << "Failed to create window: " << SDL_GetError() << std::endl; + return; + } bgfx::Init bgfxInit; bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer. bgfxInit.resolution.width = m_width; @@ -59,8 +64,11 @@ namespace ADVect { bgfxInit.platformData.nwh = (void*)"#canvas"; #endif - bgfx::init(bgfxInit); - bgfx::setDebug(BGFX_DEBUG_TEXT); + if (!bgfx::init(bgfxInit)) { + std::cerr << "Failed bgfx initialization" << std::endl; + return; + }; + bgfx::setDebug(BGFX_DEBUG_TEXT | BGFX_DEBUG_STATS); bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355ff, 1.0f, 0); bgfx::setViewRect(0, 0, 0, m_width, m_height); @@ -80,12 +88,14 @@ namespace ADVect { } void Shutdown() { + Graphics::Shutdown(); + bgfx::shutdown(); SDL_DestroyWindow(window); SDL_Quit(); } void Advance() { - int curr_size = scenes[current_scene].get().size(); + size_t curr_size = scenes[current_scene].get().size(); while (scene_pos < curr_size) { if (std::get(scenes[current_scene].get()[scene_pos][0].value) == L"Say") { NVL::Environment::Apply(scenes[current_scene].get()[scene_pos]); @@ -128,7 +138,7 @@ namespace ADVect { bgfx::touch(0); ADVect::Graphics::RenderString(speaker, 50, 630, 0xFFFFFFFF); - ADVect::Graphics::RenderStringMarkup(m_text, 50, 600, 0xFFFFFFFF); + ADVect::Graphics::RenderStringMarkup(m_text, 50, 580, 0xFFFFFFFF); bgfx::dbgTextClear(); diff --git a/ADVect/Graphics.cpp b/ADVect/Graphics.cpp index f72d884..837cee7 100644 --- a/ADVect/Graphics.cpp +++ b/ADVect/Graphics.cpp @@ -29,11 +29,6 @@ namespace { { 1.f, 1.f, 0.0f, 1.0f, 1.0f } }; - PosUVVertex* get_quad_posUV_verts(f32 L, f32 B, f32 W, f32 H) { - - return quad_vert; - } - static const uint16_t quad_indices[] = { 0, 2, 1, @@ -84,23 +79,27 @@ namespace { } namespace ADVect::Graphics { - void Init(u16 width, u16 height) { + i16 Init(u16 width, u16 height) { error = FT_Init_FreeType(&library); if (error) { std::cerr << "FreeType init error: " << error << std::endl; + return -1; } error = FT_New_Face(library, "SourceHanSerif-Heavy.ttc", 0, &face); if (error == FT_Err_Unknown_File_Format) { std::cerr << "FreeType Unknown_File_Format: " << error << std::endl; + return -1; } else if (error) { std::cerr << "FreeType font loading error: " << error << std::endl; + return -1; } error = FT_Set_Char_Size(face, 0, 20 * 64, 72, 72); if (error == FT_Err_Unknown_File_Format) { std::cerr << "FreeType Set_Char_Size error: " << error << std::endl; + return -1; } float view[16]; @@ -121,9 +120,10 @@ namespace ADVect::Graphics { program = bgfx::createProgram(vsh, fsh, true); s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); + return 0; } - void Destroy() { + void Shutdown() { FT_Done_Face(face); FT_Done_FreeType(library); @@ -136,9 +136,7 @@ namespace ADVect::Graphics { bgfx::destroy(s_texColor); for (auto it = cache.begin(); it != cache.end(); it++) { bgfx::destroy(it->second); - cache.erase(it); } - bgfx::shutdown(); } void RenderString(const NVL::String& s, u32& pos_x, u32& pos_y, u32 col) { @@ -191,29 +189,86 @@ namespace ADVect::Graphics { u32 x = pos_x, y = pos_y; RenderString(s, x, y, col); } + + // Check ParseMarkup for more information + struct Markup { + u32 begin, end; + std::vector>> efs; + } UnpackMarkupVariable(const NVL::Environment::Variable& m) { + const auto& range = std::get>(std::get>(m.value)[0].value); + const u32 begin = std::get(range[0].value), end = std::get(range[1].value); + + std::vector>> efs; + for (const NVL::Environment::Variable& combination : std::get>(std::get>(m.value)[1].value)) { + if (combination.type == NVL::Environment::Type::String) { + const NVL::String ef = std::get(combination.value); + efs.push_back({ ef, {} }); + } + else if (combination.type == NVL::Environment::Type::Array) { + const std::vector& ef_t = std::get>(combination.value); + const NVL::String& ef = std::get(ef_t[0].value); + const std::vector& args = std::get>(ef_t[1].value); + std::vector ss{}; + for (const auto& s : args) { ss.push_back(std::get(s.value)); } + efs.push_back({ ef, ss }); + } + } + return { begin, end, efs }; + } + void RenderStringMarkup(const std::vector& s, u32 pos_x, u32 pos_y, u32 col) { const NVL::String& str = std::get(s[0].value); - // Check ParseMarkup for more information + std::vector ms{}; for (const NVL::Environment::Variable& markup : std::get>(s[1].value)) { - const auto& range = std::get>(std::get>(markup.value)[0].value); - const NVL::Number& begin = std::get(range[0].value), end = std::get(range[1].value); - for (const NVL::Environment::Variable& combination : std::get>(std::get>(markup.value)[1].value)) { - if (combination.type == NVL::Environment::Type::String) { - const NVL::String& ef = std::get(combination.value); - RenderString(str.substr(begin, end - begin + 1), pos_x, pos_y, col); - } - else if (combination.type == NVL::Environment::Type::Array) { - const std::vector& ef_t = std::get>(combination.value); - const NVL::String& ef = std::get(ef_t[0].value); - const std::vector& args = std::get>(ef_t[1].value); - RenderString(str.substr(begin, end - begin + 1), pos_x, pos_y, col); - } - } - + ms.push_back(UnpackMarkupVariable(markup)); } - // NVL::String str = std::get(s.value); - // RenderString(str, pos_x, pos_y, col); + if (ms.empty()) { + RenderString(str, pos_x, pos_y, col); + return; + } + + if (ms[0].begin != 0) + RenderString(str.substr(0, ms[0].begin), pos_x, pos_y, col); + + // We assume markups are already sorted + for (size_t i = 0; i < ms.size(); i++) { + bool bold = false, + italic = false; + const NVL::String* ruby = nullptr; + for (const auto& e : ms[i].efs) { + if (e.first == L"b") { bold = true; } + else if (e.first == L"i") { italic = true; } + else if (e.first == L"rb") { ruby = &e.second[0]; } + } + + if (ruby != nullptr) { + u32 temp_x = pos_x, temp_y = pos_y + 20; + RenderString(*ruby, temp_x, temp_y, col); + } + if (bold && italic) { + + } + else if (bold) { + u32 temp_x = pos_x, temp_y = pos_y; + RenderString(str.substr(ms[i].begin, ms[i].end - ms[i].begin), pos_x, pos_y, col); + RenderString(str.substr(ms[i].begin, ms[i].end - ms[i].begin), temp_x + 2, temp_y - 1, col); + } + else if (italic) { + + } + else { + RenderString(str.substr(ms[i].begin, ms[i].end - ms[i].begin), pos_x, pos_y, col); + } + + if (i != ms.size() - 1 && ms[i + 1].begin - 1 != ms[i].end) { + RenderString(str.substr(ms[i].end, ms[i + 1].begin - ms[i].end), pos_x, pos_y, col); + } + + } + + if (ms.back().end != str.length()) + RenderString(str.substr(ms.back().end), pos_x, pos_y, col); } } \ No newline at end of file diff --git a/ADVect/Graphics.h b/ADVect/Graphics.h index 149b3a4..c8157b1 100644 --- a/ADVect/Graphics.h +++ b/ADVect/Graphics.h @@ -4,8 +4,8 @@ #include namespace ADVect::Graphics { - void Init(u16 width, u16 height); - void Destroy(); + i16 Init(u16 width, u16 height); + void Shutdown(); void RenderString(const NVL::String& s, u32& pos_x, u32& pos_y, u32 col); void RenderString(const NVL::String& s, u32&& pos_x, u32&& pos_y, u32 col); void RenderStringMarkup(const std::vector& s, u32 pos_x, u32 pos_y, u32 col); diff --git a/ADVect/shader.py b/ADVect/shader.py index 956f11e..f0eb8e0 100644 --- a/ADVect/shader.py +++ b/ADVect/shader.py @@ -1,20 +1,28 @@ import subprocess, os +plats = [ + { 'location': 'glsl', 'frag': '440', 'vert': '440' }, + { 'location': 'dx11', 'frag': 'ps_5_0', 'vert': 'vs_5_0' }, + { 'location': 'spirv', 'frag': 'spirv', 'vert': 'spirv' } +] + for root, dirs, _ in os.walk('shaders'): for name in dirs: - subprocess.run(["..\\out\\install\\x64-Debug\\bin\\shaderc", "-f", os.path.join(root, name, name + '.frag'), - "--type", "fragment" - "--platform", "windows", - "--profile", "ps_5_0", - "--varyingdef", os.path.join(root, name, "varying.def.sc"), - "-i", "ext\\bgfx\\bgfx\\examples\\common", - "-i", "ext\\bgfx\\bgfx\\src", - "-o", "..\\out\\build\\x64-Debug\\ADVect\\shaders\\dx11\\" + name + ".frag.bin"]) - subprocess.run(["..\\out\\install\\x64-Debug\\bin\\shaderc", "-f", os.path.join(root, name, name + '.vert'), - "--type", "vertex" - "--platform", "windows", - "--profile", "vs_5_0", - "--varyingdef", os.path.join(root, name, "varying.def.sc"), - "-i", "ext\\bgfx\\bgfx\\examples\\common", - "-i", "ext\\bgfx\\bgfx\\src", - "-o", "..\\out\\build\\x64-Debug\\ADVect\\shaders\\dx11\\" + name + ".vert.bin"]) \ No newline at end of file + for config in plats: + subprocess.run(["..\\out\\install\\x64-Debug\\bin\\shaderc", "-f", os.path.join(root, name, name + '.frag'), + "--type", "fragment" + "--platform", "windows", + "--profile", config['frag'], + "--varyingdef", os.path.join(root, name, "varying.def.sc"), + "-i", "ext\\bgfx\\bgfx\\examples\\common", + "-i", "ext\\bgfx\\bgfx\\src", + "-o", "..\\out\\build\\x64-Debug\\ADVect\\shaders\\" + config['location'] + "\\" + name + ".frag.bin"]) + subprocess.run(["..\\out\\install\\x64-Debug\\bin\\shaderc", "-f", os.path.join(root, name, name + '.vert'), + "--type", "vertex" + "--platform", "windows", + "--profile", config['vert'], + "--varyingdef", os.path.join(root, name, "varying.def.sc"), + "-i", "ext\\bgfx\\bgfx\\examples\\common", + "-i", "ext\\bgfx\\bgfx\\src", + "-o", "..\\out\\build\\x64-Debug\\ADVect\\shaders\\" + config['location'] + "\\" + name + ".vert.bin"]) + \ No newline at end of file diff --git a/NVL/Parser.cpp b/NVL/Parser.cpp index 8b76f87..ad362c2 100644 --- a/NVL/Parser.cpp +++ b/NVL/Parser.cpp @@ -337,7 +337,7 @@ namespace { * | | * | - Num: Markup end * | - * - Vec:2 - Str: T of Markup + * - Vec:N - Str: T of Markup * | * OR * | @@ -362,6 +362,7 @@ namespace { bool has_markup{}; + // Match tags String::const_iterator tags_start(s.cbegin()); while (std::regex_search(tags_start, s.cend(), tags_match, typer)) { has_markup = true; @@ -380,6 +381,7 @@ namespace { std::vector effects{}; + // Match markup options String::const_iterator effects_start(tags_match[1].first); while (std::regex_search(effects_start, tags_match[1].second, effects_match, effect)) { if (effects_match[3].matched) { diff --git a/NVL/Parser.h b/NVL/Parser.h index f4df0e5..dba8ebe 100644 --- a/NVL/Parser.h +++ b/NVL/Parser.h @@ -2,8 +2,10 @@ #include #include #include +#include #include "Common.h" + namespace NVL::Parse { enum class Type { Symbol, Number, String, Array, Subexpression }; diff --git a/NVL/dialogue.nvl b/NVL/dialogue.nvl index 785421f..39633b5 100644 --- a/NVL/dialogue.nvl +++ b/NVL/dialogue.nvl @@ -1,14 +1,16 @@ BEGIN Scene1 <<- [MMaker] -Hi I'm Electric [b, i, ruby("Programmer")] {プログラマー} from Michigan. +Hi I'm Electric [b, rb("Programmer")] {プログラマー} from Michigan. Commencing JS hypnosis... Enchanté ! Advance Thanks +[死大师] +他们肯定做炫酷的漫画[b] {静止系mad}。并拉扯运动曲线和使用[rb("思源宋体")] {Source Han Serif}作为主要的字体。 +[MajorMilk] :)))) fi -[MajorMilk] I draw Kirara girls doing cute things. ->>