add particles.emit(...) (WIP)

This commit is contained in:
MihailRis
2024-11-03 16:01:07 +03:00
parent 9728c674fc
commit c8187c5f25
14 changed files with 125 additions and 47 deletions
+1
View File
@@ -31,6 +31,7 @@ extern const luaL_Reg itemlib[];
extern const luaL_Reg jsonlib[];
extern const luaL_Reg mat4lib[];
extern const luaL_Reg packlib[];
extern const luaL_Reg particleslib[];
extern const luaL_Reg playerlib[];
extern const luaL_Reg quatlib[]; // quat.cpp
extern const luaL_Reg timelib[];
@@ -0,0 +1,44 @@
#include "api_lua.hpp"
#include "logic/scripting/scripting_hud.hpp"
#include "graphics/render/WorldRenderer.hpp"
#include "graphics/render/Emitter.hpp"
#include "assets/assets_util.hpp"
#include "engine.hpp"
using namespace scripting;
static int l_emit(lua::State* L) {
EmitterOrigin origin;
if (lua::istable(L, 1)) {
origin = lua::tovec3(L, 1);
} else {
origin = static_cast<entityid_t>(lua::tointeger(L, 1));
}
int count = lua::tointeger(L, 2);
auto preset = lua::tovalue(L, 3);
auto extension = lua::tovalue(L, 4);
ParticlesPreset particlesPreset {};
particlesPreset.deserialize(preset);
if (extension != nullptr) {
particlesPreset.deserialize(extension);
}
auto& assets = *engine->getAssets();
auto region = util::get_texture_region(assets, particlesPreset.texture, "");
auto emitter = std::make_unique<Emitter>(
*level,
std::move(origin),
std::move(particlesPreset),
region.texture,
region.region,
count
);
renderer->addEmitter(std::move(emitter));
return 0;
}
const luaL_Reg particleslib[] = {
{"emit", lua::wrap<l_emit>},
{NULL, NULL}
};
+6 -1
View File
@@ -4,6 +4,7 @@
#include "engine.hpp"
#include "files/files.hpp"
#include "frontend/hud.hpp"
#include "graphics/render/WorldRenderer.hpp"
#include "objects/Player.hpp"
#include "lua/libs/api_lua.hpp"
#include "lua/lua_engine.hpp"
@@ -14,10 +15,14 @@ using namespace scripting;
static debug::Logger logger("scripting-hud");
Hud* scripting::hud = nullptr;
WorldRenderer* scripting::renderer = nullptr;
void scripting::on_frontend_init(Hud* hud) {
void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
scripting::hud = hud;
scripting::renderer = renderer;
lua::openlib(lua::get_main_state(), "hud", hudlib);
lua::openlib(lua::get_main_state(), "particles", particleslib);
for (auto& pack : engine->getContentPacks()) {
lua::emit_event(
+7 -7
View File
@@ -8,20 +8,20 @@
namespace fs = std::filesystem;
class Hud;
class WorldRenderer;
namespace scripting {
extern Hud *hud;
extern WorldRenderer* renderer;
void on_frontend_init(Hud *hud);
void on_frontend_init(Hud* hud, WorldRenderer* renderer);
void on_frontend_render();
void on_frontend_close();
/**
* Load package-specific hud script
* @param env environment id
* @param packid content-pack id
* @param file script file path
*/
/// @brief Load package-specific hud script
/// @param env environment id
/// @param packid content-pack id
/// @param file script file path
void load_hud_script(
const scriptenv &env, const std::string &packid, const fs::path &file
);