diff --git a/ADVect/ADVect.cpp b/ADVect/ADVect.cpp index b79e26e..8373258 100644 --- a/ADVect/ADVect.cpp +++ b/ADVect/ADVect.cpp @@ -7,13 +7,12 @@ #include #include -#include namespace { SDL_Window* window; std::string m_name; - volatile bool running = false; + bool running = false; u16 m_width = 1280; u16 m_height = 720; @@ -149,20 +148,19 @@ namespace ADVect { void Render() { bgfx::touch(0); -// ADVect::Graphics::DrawFunkyAhhShit(); for (auto& t : tracks_img) { if (t.current != nullptr) ADVect::Graphics::DrawTextureImage(*t.current, t.pos_x, t.pos_y); } - ADVect::Graphics::RenderString(speaker, 100, 150, 0xFFFFFFFF, ADVect::Graphics::TEXT_BOLD); + ADVect::Graphics::RenderString(speaker, 250, 150, 0xFFFFFFFF, ADVect::Graphics::TEXT_BOLD); ADVect::Graphics::RenderStringMarkup(m_text, 300, 90, 0xFFFFFFFF); bgfx::dbgTextClear(); - bgfx::dbgTextPrintf(0, 44, 0xF0, "NouVeL x ADVect :: %s :: %s %s", BX_COMPILER_NAME, __DATE__, __TIME__); - bgfx::dbgTextPrintf(0, 43, 0xF0, "SDL %i.%i.%2i :: bgfx 1.%i :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, bgfx::getRendererName(bgfx::getRendererType())); - bgfx::dbgTextPrintf(0, 42, 0xF0, "Current Position: %u", scene_pos); - bgfx::dbgTextPrintf(0, 41, 0xF0, "Current Scene: %s", NVL::to_std_string(scenes[current_scene].name).c_str()); + bgfx::dbgTextPrintf(0, 44, 0xF8, "NouVeL x ADVect :: %s :: %s %s", BX_COMPILER_NAME, __DATE__, __TIME__); + bgfx::dbgTextPrintf(0, 43, 0xF8, "SDL %i.%i.%2i :: bgfx 1.%i :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, bgfx::getRendererName(bgfx::getRendererType())); + bgfx::dbgTextPrintf(0, 42, 0xF8, "Current Position: %u", scene_pos); + bgfx::dbgTextPrintf(0, 41, 0xF8, "Current Scene: %s", NVL::to_std_string(scenes[current_scene].name).c_str()); bgfx::frame(); } @@ -193,34 +191,47 @@ namespace ADVect { int main(int argc, char* argv[]) { const std::string PJ_DIR = "..\\..\\..\\..\\NVL\\"; - NVL::Environment::ENVIRONMENT.enter(u"Say", NVL::Environment::Variable([](std::vector args) { - m_text = args; - return NVL::Environment::Type::Nil; - }, 2)); + NVL::Environment::ENVIRONMENT.enter({ + { + u"Say", + NVL::Environment::Variable([](std::vector args) { + m_text = args; + return NVL::Environment::Type::Nil; + }, 2) + }, + { + u"SwitchSpeaker", + NVL::Environment::Variable([](std::vector args) { + speaker = std::get(NVL::Environment::Variable(args[0]).value); + return NVL::Environment::Type::Nil; + }, 1) + }, + { + u"ImageTrack", + NVL::Environment::Variable([](std::vector args) { + add_image_track(NVL::to_std_string(std::get(NVL::Environment::Variable(args[0]).value))); + return NVL::Environment::Type::Nil; + }, 1) + }, + { + u"Show", + NVL::Environment::Variable([](std::vector args) { + std::string name = NVL::to_std_string(std::get(NVL::Environment::Variable(args[0]).value)); + ImageTrack* t = find_image_track(name); + if (t == nullptr) { + std::cerr << "ADV: Cannot find ImageTrack " << name << std::endl; + } + else { + auto s = std::get(NVL::Environment::Variable(args[1]).value); + auto s2 = NVL::to_std_string(s); + t->current = ADVect::Graphics::GetImageTextureFromFile(s2); + } + return NVL::Environment::Type::Nil; + }, 2) + } + }); - NVL::Environment::ENVIRONMENT.enter(u"SwitchSpeaker", NVL::Environment::Variable([](std::vector args) { - speaker = std::get(NVL::Environment::Variable(args[0]).value); - return NVL::Environment::Type::Nil; - }, 1)); - - NVL::Environment::ENVIRONMENT.enter(u"ImageTrack", NVL::Environment::Variable([](std::vector args) { - add_image_track(NVL::to_std_string(std::get(NVL::Environment::Variable(args[0]).value))); - return NVL::Environment::Type::Nil; - }, 1)); - - NVL::Environment::ENVIRONMENT.enter(u"Show", NVL::Environment::Variable([](std::vector args) { - std::string name = NVL::to_std_string(std::get(NVL::Environment::Variable(args[0]).value)); - ImageTrack* t = find_image_track(name); - if (t == nullptr) { - std::cerr << "ADV: Cannot find ImageTrack " << name << std::endl; - } - else { - t->current = ADVect::Graphics::GetImageTextureFromFile(NVL::to_std_string(std::get(NVL::Environment::Variable(args[1]).value))); - } - return NVL::Environment::Type::Nil; - }, 2)); - - std::vector SCENES = NVL::Parse::ParseFile(PJ_DIR + "dante_de.nvl"); + std::vector SCENES = NVL::Parse::ParseFile(PJ_DIR + "dialogue.nvl"); if (SCENES.empty()) return EXIT_FAILURE; if (!ADVect::Init("ADV", SCENES)) return EXIT_FAILURE; diff --git a/ADVect/Graphics.cpp b/ADVect/Graphics.cpp index d80488c..cc02605 100644 --- a/ADVect/Graphics.cpp +++ b/ADVect/Graphics.cpp @@ -133,7 +133,7 @@ namespace { std::optional get_image_texture(const std::string& file) { ImageTexture i; - i.buffer = stbi_load("image.png", &i.w, &i.h, &i.channels, 0); + i.buffer = stbi_load(file.c_str(), &i.w, &i.h, &i.channels, 0); if (i.buffer == NULL) { std::cerr << "ADV: STB IMAGE loading failed" << std::endl; return std::nullopt; @@ -144,7 +144,7 @@ namespace { i.h, false, 1, - bgfx::TextureFormat::RGBA8, + i.channels == 4 ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::RGB8, BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP, buf ); @@ -157,7 +157,6 @@ namespace { } Font regular, bold; - ImageTexture bg; bgfx::ProgramHandle a_program, img_program; bgfx::UniformHandle s_texColor; @@ -191,8 +190,6 @@ namespace ADVect::Graphics { s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); - if (auto i = get_image_texture("image.png")) bg = *i; else return false; - return true; } @@ -201,8 +198,6 @@ namespace ADVect::Graphics { destroy_font(bold); FT_Done_FreeType(library); - destroy_image_texture(bg); - for (auto it = imgs.begin(); it != imgs.end(); it++) { destroy_image_texture(it->second); } @@ -235,7 +230,7 @@ namespace ADVect::Graphics { } void DrawTextureImage(const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h) { - DrawTexture(tex, pos_x, pos_y, w, h, BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_NORMAL, img_program); + DrawTexture(tex, pos_x, pos_y, w, h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), img_program); } void DrawTextureImage(const ImageTexture& img, i32 pos_x, i32 pos_y) { @@ -336,8 +331,4 @@ namespace ADVect::Graphics { if (ms.back().end != str.length()) RenderString(str.substr(ms.back().end), pos_x, pos_y, col, TEXT_NONE); } - - void DrawFunkyAhhShit() { - DrawTextureImage(bg, 0, -40); - } } diff --git a/ADVect/Graphics.h b/ADVect/Graphics.h index 4b687b4..015959f 100644 --- a/ADVect/Graphics.h +++ b/ADVect/Graphics.h @@ -33,6 +33,4 @@ namespace ADVect::Graphics { void RenderString(const NVL::String& s, u32& pos_x, u32& pos_y, u32 col, u32 style_flags); void RenderString(const NVL::String& s, u32&& pos_x, u32&& pos_y, u32 col, u32 style_flags); void RenderStringMarkup(const std::vector& s, u32 pos_x, u32 pos_y, u32 col); - - void DrawFunkyAhhShit(); } diff --git a/NVL/Environment.cpp b/NVL/Environment.cpp index ada3e73..e04dd44 100644 --- a/NVL/Environment.cpp +++ b/NVL/Environment.cpp @@ -33,6 +33,11 @@ namespace NVL::Environment { throw std::runtime_error("Redefinition of symbol in environment"); } + void Environment::enter(std::initializer_list> p) { + for (auto& i : p) + enter(i.first, i.second); + } + void Environment::set(const String& name, Variable p) { if (env.find(name) == env.end()) throw std::runtime_error("Attempting to set undefined variable"); diff --git a/NVL/Environment.h b/NVL/Environment.h index d544950..7cbe3ca 100644 --- a/NVL/Environment.h +++ b/NVL/Environment.h @@ -27,6 +27,7 @@ namespace NVL::Environment { std::unordered_map env{}; public: void enter(const String& name, Variable p); + void enter(std::initializer_list> p); void set(const String& name, Variable p); Variable& get(const String& name); bool exists(const String& name); diff --git a/NVL/Parser.cpp b/NVL/Parser.cpp index aac6ff2..e83a501 100644 --- a/NVL/Parser.cpp +++ b/NVL/Parser.cpp @@ -117,7 +117,7 @@ namespace { if (a != (char)0xEF || b != (char)0xBB || c != (char)0xBF) f.seekg(0); else - std::cerr << "NVL Warning: Windows UTF-8 BOM skipped" << std::endl; + std::cerr << "NVL: Windows UTF-8 BOM skipped" << std::endl; } std::stringstream buffer; buffer << f.rdbuf(); diff --git a/NVL/dialogue.nvl b/NVL/dialogue.nvl index dfad26a..7786ac3 100644 --- a/NVL/dialogue.nvl +++ b/NVL/dialogue.nvl @@ -1,19 +1,25 @@ BEGIN Scene1 + +ImageTrack BG +ImageTrack Avatar +Show BG "image.png" + <<- +*!Show Avatar "mmaker.png" [MMaker] Hi I'm Electric [b, rb("Programmer")] {プログラマー} from Michigan. + +*! Show BG "image2.jpg" + Commencing JS hypnosis... -Enchanté ! -Advance + +*! Show BG "image3.png" + +*!Show Avatar "terrio.png" [Terrio] mesugaki -Thanks -[死大师] -他们肯定做炫酷的漫画[b] {静止系mad}。并拉扯运动曲线和使用[rb("思源宋体")] {Source Han Serif}作为主要的字体。 -[MajorMilk] -:)))) -fi -I draw Kirara girls doing cute things. +Flashes will be back soon! + ->> END