This commit is contained in:
MihailRis 2024-12-21 13:11:23 +03:00
parent 17161e5981
commit c3f22c6854
7 changed files with 30 additions and 30 deletions

View File

@ -95,7 +95,7 @@ struct ContentPackStats {
} }
}; };
struct world_funcs_set { struct WorldFuncsSet {
bool onblockplaced : 1; bool onblockplaced : 1;
bool onblockreplaced : 1; bool onblockreplaced : 1;
bool onblockbroken : 1; bool onblockbroken : 1;
@ -108,7 +108,7 @@ class ContentPackRuntime {
ContentPackStats stats {}; ContentPackStats stats {};
scriptenv env; scriptenv env;
public: public:
world_funcs_set worldfuncsset {}; WorldFuncsSet worldfuncsset {};
ContentPackRuntime(ContentPack info, scriptenv env); ContentPackRuntime(ContentPack info, scriptenv env);
~ContentPackRuntime(); ~ContentPackRuntime();

View File

@ -6,7 +6,7 @@
#include "data/dv.hpp" #include "data/dv.hpp"
#include "typedefs.hpp" #include "typedefs.hpp"
struct item_funcs_set { struct ItemFuncsSet {
bool init : 1; bool init : 1;
bool on_use : 1; bool on_use : 1;
bool on_use_on_block : 1; bool on_use_on_block : 1;
@ -43,7 +43,7 @@ struct ItemDef {
struct { struct {
itemid_t id; itemid_t id;
blockid_t placingBlock; blockid_t placingBlock;
item_funcs_set funcsset {}; ItemFuncsSet funcsset {};
bool emissive = false; bool emissive = false;
} rt {}; } rt {};

View File

@ -599,7 +599,7 @@ static void process_entity_callback(
static void process_entity_callback( static void process_entity_callback(
const Entity& entity, const Entity& entity,
const std::string& name, const std::string& name,
bool entity_funcs_set::*flag, bool EntityFuncsSet::*flag,
std::function<int(lua::State*)> args std::function<int(lua::State*)> args
) { ) {
const auto& script = entity.getScripting(); const auto& script = entity.getScripting();
@ -612,7 +612,7 @@ static void process_entity_callback(
void scripting::on_entity_despawn(const Entity& entity) { void scripting::on_entity_despawn(const Entity& entity) {
process_entity_callback( process_entity_callback(
entity, "on_despawn", &entity_funcs_set::on_despawn, nullptr entity, "on_despawn", &EntityFuncsSet::on_despawn, nullptr
); );
auto L = lua::get_main_state(); auto L = lua::get_main_state();
lua::get_from(L, "stdcomp", "remove_Entity", true); lua::get_from(L, "stdcomp", "remove_Entity", true);
@ -624,20 +624,20 @@ void scripting::on_entity_grounded(const Entity& entity, float force) {
process_entity_callback( process_entity_callback(
entity, entity,
"on_grounded", "on_grounded",
&entity_funcs_set::on_grounded, &EntityFuncsSet::on_grounded,
[force](auto L) { return lua::pushnumber(L, force); } [force](auto L) { return lua::pushnumber(L, force); }
); );
} }
void scripting::on_entity_fall(const Entity& entity) { void scripting::on_entity_fall(const Entity& entity) {
process_entity_callback( process_entity_callback(
entity, "on_fall", &entity_funcs_set::on_fall, nullptr entity, "on_fall", &EntityFuncsSet::on_fall, nullptr
); );
} }
void scripting::on_entity_save(const Entity& entity) { void scripting::on_entity_save(const Entity& entity) {
process_entity_callback( process_entity_callback(
entity, "on_save", &entity_funcs_set::on_save, nullptr entity, "on_save", &EntityFuncsSet::on_save, nullptr
); );
} }
@ -647,7 +647,7 @@ void scripting::on_sensor_enter(
process_entity_callback( process_entity_callback(
entity, entity,
"on_sensor_enter", "on_sensor_enter",
&entity_funcs_set::on_sensor_enter, &EntityFuncsSet::on_sensor_enter,
[index, oid](auto L) { [index, oid](auto L) {
lua::pushinteger(L, index); lua::pushinteger(L, index);
lua::pushinteger(L, oid); lua::pushinteger(L, oid);
@ -662,7 +662,7 @@ void scripting::on_sensor_exit(
process_entity_callback( process_entity_callback(
entity, entity,
"on_sensor_exit", "on_sensor_exit",
&entity_funcs_set::on_sensor_exit, &EntityFuncsSet::on_sensor_exit,
[index, oid](auto L) { [index, oid](auto L) {
lua::pushinteger(L, index); lua::pushinteger(L, index);
lua::pushinteger(L, oid); lua::pushinteger(L, oid);
@ -675,7 +675,7 @@ void scripting::on_aim_on(const Entity& entity, Player* player) {
process_entity_callback( process_entity_callback(
entity, entity,
"on_aim_on", "on_aim_on",
&entity_funcs_set::on_aim_on, &EntityFuncsSet::on_aim_on,
[player](auto L) { return lua::pushinteger(L, player->getId()); } [player](auto L) { return lua::pushinteger(L, player->getId()); }
); );
} }
@ -684,7 +684,7 @@ void scripting::on_aim_off(const Entity& entity, Player* player) {
process_entity_callback( process_entity_callback(
entity, entity,
"on_aim_off", "on_aim_off",
&entity_funcs_set::on_aim_off, &EntityFuncsSet::on_aim_off,
[player](auto L) { return lua::pushinteger(L, player->getId()); } [player](auto L) { return lua::pushinteger(L, player->getId()); }
); );
} }
@ -695,7 +695,7 @@ void scripting::on_attacked(
process_entity_callback( process_entity_callback(
entity, entity,
"on_attacked", "on_attacked",
&entity_funcs_set::on_attacked, &EntityFuncsSet::on_attacked,
[player, attacker](auto L) { [player, attacker](auto L) {
lua::pushinteger(L, attacker); lua::pushinteger(L, attacker);
lua::pushinteger(L, player->getId()); lua::pushinteger(L, player->getId());
@ -708,7 +708,7 @@ void scripting::on_entity_used(const Entity& entity, Player* player) {
process_entity_callback( process_entity_callback(
entity, entity,
"on_used", "on_used",
&entity_funcs_set::on_used, &EntityFuncsSet::on_used,
[player](auto L) { return lua::pushinteger(L, player->getId()); } [player](auto L) { return lua::pushinteger(L, player->getId()); }
); );
} }
@ -796,7 +796,7 @@ void scripting::load_content_script(
const std::string& prefix, const std::string& prefix,
const fs::path& file, const fs::path& file,
const std::string& fileName, const std::string& fileName,
block_funcs_set& funcsset BlockFuncsSet& funcsset
) { ) {
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));
@ -819,7 +819,7 @@ void scripting::load_content_script(
const std::string& prefix, const std::string& prefix,
const fs::path& file, const fs::path& file,
const std::string& fileName, const std::string& fileName,
item_funcs_set& funcsset ItemFuncsSet& funcsset
) { ) {
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));
@ -846,7 +846,7 @@ void scripting::load_world_script(
const std::string& prefix, const std::string& prefix,
const fs::path& file, const fs::path& file,
const std::string& fileName, const std::string& fileName,
world_funcs_set& funcsset WorldFuncsSet& funcsset
) { ) {
int env = *senv; int env = *senv;
lua::pop(lua::get_main_state(), load_script(env, "world", file, fileName)); lua::pop(lua::get_main_state(), load_script(env, "world", file, fileName));

View File

@ -21,9 +21,9 @@ class Player;
struct ItemDef; struct ItemDef;
class Inventory; class Inventory;
class UiDocument; class UiDocument;
struct block_funcs_set; struct BlockFuncsSet;
struct item_funcs_set; struct ItemFuncsSet;
struct world_funcs_set; struct WorldFuncsSet;
struct UserComponent; struct UserComponent;
struct uidocscript; struct uidocscript;
class BlocksController; class BlocksController;
@ -141,7 +141,7 @@ namespace scripting {
const std::string& prefix, const std::string& prefix,
const std::filesystem::path& file, const std::filesystem::path& file,
const std::string& fileName, const std::string& fileName,
block_funcs_set& funcsset BlockFuncsSet& funcsset
); );
/// @brief Load script associated with an Item /// @brief Load script associated with an Item
@ -155,7 +155,7 @@ namespace scripting {
const std::string& prefix, const std::string& prefix,
const std::filesystem::path& file, const std::filesystem::path& file,
const std::string& fileName, const std::string& fileName,
item_funcs_set& funcsset ItemFuncsSet& funcsset
); );
/// @brief Load component script /// @brief Load component script
@ -184,7 +184,7 @@ namespace scripting {
const std::string& packid, const std::string& packid,
const std::filesystem::path& file, const std::filesystem::path& file,
const std::string& fileName, const std::string& fileName,
world_funcs_set& funcsset WorldFuncsSet& funcsset
); );
/// @brief Load script associated with an UiDocument /// @brief Load script associated with an UiDocument

View File

@ -162,7 +162,7 @@ entityid_t Entities::spawn(
for (auto& componentName : def.components) { for (auto& componentName : def.components) {
auto component = std::make_unique<UserComponent>( auto component = std::make_unique<UserComponent>(
componentName, entity_funcs_set {}, nullptr componentName, EntityFuncsSet {}, nullptr
); );
scripting.components.emplace_back(std::move(component)); scripting.components.emplace_back(std::move(component));
} }

View File

@ -14,7 +14,7 @@
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
#include <unordered_map> #include <unordered_map>
struct entity_funcs_set { struct EntityFuncsSet {
bool init; bool init;
bool on_despawn; bool on_despawn;
bool on_grounded; bool on_grounded;
@ -77,11 +77,11 @@ struct Rigidbody {
struct UserComponent { struct UserComponent {
std::string name; std::string name;
entity_funcs_set funcsset; EntityFuncsSet funcsset;
scriptenv env; scriptenv env;
UserComponent( UserComponent(
const std::string& name, entity_funcs_set funcsset, scriptenv env const std::string& name, EntityFuncsSet funcsset, scriptenv env
) )
: name(name), funcsset(funcsset), env(env) { : name(name), funcsset(funcsset), env(env) {
} }

View File

@ -34,7 +34,7 @@ inline constexpr size_t MAX_USER_BLOCK_FIELDS_SIZE = 240;
inline std::string DEFAULT_MATERIAL = "base:stone"; inline std::string DEFAULT_MATERIAL = "base:stone";
struct block_funcs_set { struct BlockFuncsSet {
bool init : 1; bool init : 1;
bool update : 1; bool update : 1;
bool onplaced : 1; bool onplaced : 1;
@ -241,7 +241,7 @@ public:
std::vector<AABB> hitboxes[BlockRotProfile::MAX_COUNT]; std::vector<AABB> hitboxes[BlockRotProfile::MAX_COUNT];
/// @brief set of block callbacks flags /// @brief set of block callbacks flags
block_funcs_set funcsset {}; BlockFuncsSet funcsset {};
/// @brief picking item integer id /// @brief picking item integer id
itemid_t pickingItem = 0; itemid_t pickingItem = 0;