mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 15:31:49 +00:00
test content events names cache
This commit is contained in:
parent
bf7732f68a
commit
0012419651
5 changed files with 34 additions and 12 deletions
|
|
@ -441,7 +441,8 @@ static void load_script(const Content& content, T& def) {
|
||||||
def.name,
|
def.name,
|
||||||
scriptfile,
|
scriptfile,
|
||||||
def.scriptFile,
|
def.scriptFile,
|
||||||
def.rt.funcsset
|
def.rt.funcsset,
|
||||||
|
def.rt.eventNames
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ struct ItemFuncsSet {
|
||||||
bool on_block_break_by : 1;
|
bool on_block_break_by : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ItemFuncNamesCache {
|
||||||
|
};
|
||||||
|
|
||||||
enum class ItemIconType {
|
enum class ItemIconType {
|
||||||
NONE, // invisible (core:empty) must not be rendered
|
NONE, // invisible (core:empty) must not be rendered
|
||||||
SPRITE, // textured quad: icon is `atlas_name:texture_name`
|
SPRITE, // textured quad: icon is `atlas_name:texture_name`
|
||||||
|
|
@ -75,6 +78,8 @@ struct ItemDef {
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
|
|
||||||
std::set<int> tags;
|
std::set<int> tags;
|
||||||
|
|
||||||
|
ItemFuncNamesCache eventNames;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
ItemDef(const std::string& name);
|
ItemDef(const std::string& name);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
#include "scripting.hpp"
|
#include "scripting.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "scripting_commons.hpp"
|
#include "scripting_commons.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
|
|
@ -28,6 +25,9 @@
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
#include "interfaces/Process.hpp"
|
#include "interfaces/Process.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
static debug::Logger logger("scripting");
|
static debug::Logger logger("scripting");
|
||||||
|
|
@ -391,15 +391,15 @@ void scripting::on_blocks_tick(const Block& block, int tps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::update_block(const Block& block, const glm::ivec3& pos) {
|
void scripting::update_block(const Block& block, const glm::ivec3& pos) {
|
||||||
std::string name = block.name + ".update";
|
lua::emit_event(lua::get_main_state(), block.rt.eventNames.update,
|
||||||
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
|
[pos](auto L) {
|
||||||
return lua::pushivec_stack(L, pos);
|
return lua::pushivec_stack(L, pos);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::random_update_block(const Block& block, const glm::ivec3& pos) {
|
void scripting::random_update_block(const Block& block, const glm::ivec3& pos) {
|
||||||
std::string name = block.name + ".randupdate";
|
lua::emit_event(lua::get_main_state(), block.rt.eventNames.randomUpdate,
|
||||||
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
|
[pos](auto L) {
|
||||||
return lua::pushivec_stack(L, pos);
|
return lua::pushivec_stack(L, pos);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -660,7 +660,8 @@ void scripting::load_content_script(
|
||||||
const std::string& prefix,
|
const std::string& prefix,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
BlockFuncsSet& funcsset
|
BlockFuncsSet& funcsset,
|
||||||
|
BlockFuncNamesCache& namesCache
|
||||||
) {
|
) {
|
||||||
int env = *senv;
|
int env = *senv;
|
||||||
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
|
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
|
||||||
|
|
@ -686,6 +687,9 @@ void scripting::load_content_script(
|
||||||
register_event(env, "on_block_present", prefix + ".blockpresent");
|
register_event(env, "on_block_present", prefix + ".blockpresent");
|
||||||
funcsset.onblockremoved =
|
funcsset.onblockremoved =
|
||||||
register_event(env, "on_block_removed", prefix + ".blockremoved");
|
register_event(env, "on_block_removed", prefix + ".blockremoved");
|
||||||
|
|
||||||
|
namesCache.randomUpdate = prefix + ".update";
|
||||||
|
namesCache.randomUpdate = prefix + ".randupdate";
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_content_script(
|
void scripting::load_content_script(
|
||||||
|
|
@ -693,7 +697,8 @@ void scripting::load_content_script(
|
||||||
const std::string& prefix,
|
const std::string& prefix,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
ItemFuncsSet& funcsset
|
ItemFuncsSet& funcsset,
|
||||||
|
ItemFuncNamesCache& namesCache
|
||||||
) {
|
) {
|
||||||
int env = *senv;
|
int env = *senv;
|
||||||
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));
|
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ struct ItemDef;
|
||||||
class Inventory;
|
class Inventory;
|
||||||
class UiDocument;
|
class UiDocument;
|
||||||
struct BlockFuncsSet;
|
struct BlockFuncsSet;
|
||||||
|
struct BlockFuncNamesCache;
|
||||||
struct ItemFuncsSet;
|
struct ItemFuncsSet;
|
||||||
|
struct ItemFuncNamesCache;
|
||||||
struct WorldFuncsSet;
|
struct WorldFuncsSet;
|
||||||
struct UserComponent;
|
struct UserComponent;
|
||||||
struct uidocscript;
|
struct uidocscript;
|
||||||
|
|
@ -168,7 +170,8 @@ namespace scripting {
|
||||||
const std::string& prefix,
|
const std::string& prefix,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
BlockFuncsSet& funcsset
|
BlockFuncsSet& funcsset,
|
||||||
|
BlockFuncNamesCache& namesCache
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Load script associated with an Item
|
/// @brief Load script associated with an Item
|
||||||
|
|
@ -182,7 +185,8 @@ namespace scripting {
|
||||||
const std::string& prefix,
|
const std::string& prefix,
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
ItemFuncsSet& funcsset
|
ItemFuncsSet& funcsset,
|
||||||
|
ItemFuncNamesCache& namesCache
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Load component script
|
/// @brief Load component script
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,11 @@ struct BlockFuncsSet {
|
||||||
bool onblockremoved : 1;
|
bool onblockremoved : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BlockFuncNamesCache {
|
||||||
|
std::string update;
|
||||||
|
std::string randomUpdate;
|
||||||
|
};
|
||||||
|
|
||||||
struct CoordSystem {
|
struct CoordSystem {
|
||||||
std::array<glm::ivec3, 3> axes;
|
std::array<glm::ivec3, 3> axes;
|
||||||
/// @brief Grid 3d position fix offset (for negative vectors)
|
/// @brief Grid 3d position fix offset (for negative vectors)
|
||||||
|
|
@ -296,6 +301,8 @@ public:
|
||||||
blockid_t surfaceReplacement = 0;
|
blockid_t surfaceReplacement = 0;
|
||||||
|
|
||||||
std::set<int> tags;
|
std::set<int> tags;
|
||||||
|
|
||||||
|
BlockFuncNamesCache eventNames;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
Block(const std::string& name);
|
Block(const std::string& name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue