This commit is contained in:
lachrymaL 2022-08-27 04:40:06 -04:00
parent ee42a08fb8
commit 324ff7e7b5
No known key found for this signature in database
GPG key ID: F3640ACFA174B1C1
7 changed files with 71 additions and 59 deletions

View file

@ -7,13 +7,12 @@
#include <bx/math.h>
#include <iostream>
#include <map>
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<NVL::Environment::Variable> args) {
NVL::Environment::ENVIRONMENT.enter({
{
u"Say",
NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
m_text = args;
return NVL::Environment::Type::Nil;
}, 2));
NVL::Environment::ENVIRONMENT.enter(u"SwitchSpeaker", NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
}, 2)
},
{
u"SwitchSpeaker",
NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
speaker = std::get<NVL::String>(NVL::Environment::Variable(args[0]).value);
return NVL::Environment::Type::Nil;
}, 1));
NVL::Environment::ENVIRONMENT.enter(u"ImageTrack", NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
}, 1)
},
{
u"ImageTrack",
NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
add_image_track(NVL::to_std_string(std::get<NVL::String>(NVL::Environment::Variable(args[0]).value)));
return NVL::Environment::Type::Nil;
}, 1));
NVL::Environment::ENVIRONMENT.enter(u"Show", NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
}, 1)
},
{
u"Show",
NVL::Environment::Variable([](std::vector<NVL::Environment::Variable> args) {
std::string name = NVL::to_std_string(std::get<NVL::String>(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::String>(NVL::Environment::Variable(args[1]).value)));
auto s = std::get<NVL::String>(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));
}, 2)
}
});
std::vector<NVL::Parse::Scene> SCENES = NVL::Parse::ParseFile(PJ_DIR + "dante_de.nvl");
std::vector<NVL::Parse::Scene> SCENES = NVL::Parse::ParseFile(PJ_DIR + "dialogue.nvl");
if (SCENES.empty()) return EXIT_FAILURE;
if (!ADVect::Init("ADV", SCENES)) return EXIT_FAILURE;

View file

@ -133,7 +133,7 @@ namespace {
std::optional<ImageTexture> 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);
}
}

View file

@ -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<NVL::Environment::Variable>& s, u32 pos_x, u32 pos_y, u32 col);
void DrawFunkyAhhShit();
}

View file

@ -33,6 +33,11 @@ namespace NVL::Environment {
throw std::runtime_error("Redefinition of symbol in environment");
}
void Environment::enter(std::initializer_list<std::pair<String, Variable>> 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");

View file

@ -27,6 +27,7 @@ namespace NVL::Environment {
std::unordered_map<String, Variable> env{};
public:
void enter(const String& name, Variable p);
void enter(std::initializer_list<std::pair<String, Variable>> p);
void set(const String& name, Variable p);
Variable& get(const String& name);
bool exists(const String& name);

View file

@ -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();

View file

@ -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