Skip to content

Commit

Permalink
[ScriptEngine] Code splitted into multiple files, improving compilati…
Browse files Browse the repository at this point in the history
…on speed.
  • Loading branch information
Unarelith committed May 22, 2020
1 parent 82c52bc commit b789fc3
Show file tree
Hide file tree
Showing 33 changed files with 261 additions and 131 deletions.
24 changes: 24 additions & 0 deletions source/common/core/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,27 @@ void Registry::clear() {
m_entityRegistry.clear();
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Registry::initUsertype(sol::state &lua) {
lua.new_usertype<Registry>("Registry",
"get_block", &Registry::getBlock,
"get_item", &Registry::getItem,
"get_sky", &Registry::getSky,
"get_tree", &Registry::getTree,
"get_biome", &Registry::getBiome,
"get_recipe", &Registry::getRecipe,

"get_block_from_string", &Registry::getBlockFromStringID,
"get_item_from_string", &Registry::getItemFromStringID,
"get_sky_from_string", &Registry::getSkyFromStringID,
"get_tree_from_string", &Registry::getTreeFromStringID,
"get_biome_from_string", &Registry::getBiomeFromStringID,

"blocks", &Registry::blocks,
"items", &Registry::items,
"trees", &Registry::trees,
"biomes", &Registry::biomes,
"dimensions", &Registry::dimensions
);
}

2 changes: 2 additions & 0 deletions source/common/core/Registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Registry : public ISerializable {

void clear();

static void initUsertype(sol::state &lua);

const std::vector<std::unique_ptr<Block>> &blocks() const { return m_blocks; }
const std::vector<Item> &items() const { return m_items; }
const std::vector<Tree> &trees() const { return m_trees; }
Expand Down
9 changes: 9 additions & 0 deletions source/common/inventory/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ void Inventory::deserialize(sf::Packet &packet) {
}
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Inventory::initUsertype(sol::state &lua) {
lua.new_usertype<Inventory>("Inventory",
"add_stack", sol::overload(&Inventory::addStack, &Inventory::addStack2),
"get_stack", &Inventory::getStack,
"set_stack", &Inventory::setStack
);
}

2 changes: 2 additions & 0 deletions source/common/inventory/Inventory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Inventory : public ISerializable {
bool isUnlimited() const { return m_isUnlimited; }
void setUnlimited(bool isUnlimited) { m_isUnlimited = isUnlimited; }

static void initUsertype(sol::state &lua);

private:
std::string m_name;

Expand Down
10 changes: 10 additions & 0 deletions source/common/inventory/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ void Item::deserialize(sf::Packet &packet) {
>> m_miningSpeed >> m_harvestCapability >> m_groups;
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Item::initUsertype(sol::state &lua) {
lua.new_usertype<Item>("Item",
"id", &Item::id,
"string_id", &Item::stringID,
"has_group", &Item::hasGroup,
"get_group_value", &Item::getGroupValue
);
}

2 changes: 2 additions & 0 deletions source/common/inventory/Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Item : public ISerializable {
return it->second;
}

static void initUsertype(sol::state &lua);

protected:
bool m_isBlock = false;

Expand Down
8 changes: 8 additions & 0 deletions source/common/inventory/ItemStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const Item &ItemStack::item() const {
return Registry::getInstance().getItemFromStringID(m_stringID);
}

// Please update 'docs/lua-api-cpp.md' if you change this
void ItemStack::initUsertype(sol::state &lua) {
lua.new_usertype<ItemStack>("ItemStack",
"amount", &ItemStack::amount,
"item", &ItemStack::item
);
}

sf::Packet &operator<<(sf::Packet &packet, const ItemStack &itemStack) {
return packet << itemStack.item().stringID() << itemStack.amount();
}
Expand Down
2 changes: 2 additions & 0 deletions source/common/inventory/ItemStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ItemStack {
u16 amount() const { return m_amount; }
void setAmount(u16 amount) { m_amount = amount; }

static void initUsertype(sol::state &lua);

private:
std::string m_stringID;

Expand Down
13 changes: 13 additions & 0 deletions source/common/world/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ void Block::deserialize(sf::Packet &packet) {
m_drawType = BlockDrawType(drawType);
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Block::initUsertype(sol::state &lua) {
lua.new_usertype<Block>("Block",
"id", &Block::id,
"data", &Block::data,
"string_id", &Block::stringID,
"label", &Block::label,
"mod_name", &Block::modName,
"is_opaque", &Block::isOpaque,
"get_item_drop", &Block::getItemDrop
);
}

2 changes: 2 additions & 0 deletions source/common/world/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class Block : public ISerializable {
return it->second;
}

static void initUsertype(sol::state &lua);

protected:
glm::vec4 getTexCoordsFromID(int textureID) const;

Expand Down
14 changes: 14 additions & 0 deletions source/common/world/BlockMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ void BlockMetadata::deserialize(sf::Packet &packet) {
}
}

// Please update 'docs/lua-api-cpp.md' if you change this
void BlockMetadata::initUsertype(sol::state &lua) {
lua.new_usertype<BlockMetadata>("BlockMetadata",
"get_string", &BlockMetadata::getLuaObject<std::string>,
"set_string", &BlockMetadata::setString,

"get_int", &BlockMetadata::getLuaObject<int>,
"set_int", &BlockMetadata::setInt,

"get_bool", &BlockMetadata::getLuaObject<bool>,
"set_bool", &BlockMetadata::setBool
);
}

2 changes: 2 additions & 0 deletions source/common/world/BlockMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class BlockMetadata : public ISerializable {
void serialize(sf::Packet &packet) const override;
void deserialize(sf::Packet &packet) override;

static void initUsertype(sol::state &lua);

private:
std::unordered_map<std::string, BlockMetadataValue> m_data;
};
Expand Down
14 changes: 14 additions & 0 deletions source/common/world/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,17 @@ bool Chunk::areAllNeighboursInitialized() const {
&& m_surroundingChunks[Chunk::Top] && m_surroundingChunks[Chunk::Top]->isInitialized();
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Chunk::initUsertype(sol::state &lua) {
lua.new_usertype<Chunk>("Chunk",
"get_block", &Chunk::getBlock,
"set_block", &Chunk::setBlock,

"get_data", &Chunk::getData,
"set_data", &Chunk::setData,

"get_block_data", &Chunk::getBlockData,
"add_block_data", &Chunk::addBlockData
);
}

2 changes: 2 additions & 0 deletions source/common/world/Chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class Chunk : public gk::NonCopyable {

u32 data(int x, int y, int z) const { return m_data[z][y][x]; }

static void initUsertype(sol::state &lua);

protected:
s32 m_x;
s32 m_y;
Expand Down
7 changes: 7 additions & 0 deletions source/common/world/Dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ void Dimension::deserialize(sf::Packet &packet) {
packet >> m_id >> m_stringID >> m_name >> m_biomes >> m_sky;
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Dimension::initUsertype(sol::state &lua) {
lua.new_usertype<Dimension>("Dimension",
"id", &Dimension::id
);
}

4 changes: 4 additions & 0 deletions source/common/world/Dimension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include <gk/core/IntTypes.hpp>

#include <sol.hpp>

#include "ISerializable.hpp"

class Dimension : public ISerializable {
Expand All @@ -52,6 +54,8 @@ class Dimension : public ISerializable {
const std::string &sky() const { return m_sky; }
void setSky(const std::string &sky) { m_sky = sky; }

static void initUsertype(sol::state &lua);

private:
u16 m_id = 0;

Expand Down
17 changes: 17 additions & 0 deletions source/common/world/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ void Player::deserialize(sf::Packet &packet) {
packet >> m_x >> m_y >> m_z >> m_dimension >> m_inventory;
}

// Please update 'docs/lua-api-cpp.md' if you change this
void Player::initUsertype(sol::state &lua) {
lua.new_usertype<Player>("Player",
"inventory", &Player::inventory,

"x", &Player::x,
"y", &Player::y,
"z", &Player::z,
"set_position", &Player::setPosition,

"dimension", &Player::dimension,
"set_dimension", &Player::setDimension,

"client_id", &Player::clientID
);
}

2 changes: 2 additions & 0 deletions source/common/world/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Player : public ISerializable {

const gk::FloatBox &hitbox() const { return m_hitbox; }

static void initUsertype(sol::state &lua);

protected:
double m_x = 0;
double m_y = 0;
Expand Down
15 changes: 15 additions & 0 deletions source/common/world/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,18 @@ void World::setData(int x, int y, int z, u16 data) const {
if (chunk)
chunk->setData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), data);
}

// Please update 'docs/lua-api-cpp.md' if you change this
void World::initUsertype(sol::state &lua) {
lua.new_usertype<World>("World",
"get_block", &World::getBlock,
"set_block", &World::setBlock,

"get_data", &World::getData,
"set_data", &World::setData,

"get_block_data", &World::getBlockData,
"add_block_data", &World::addBlockData
);
}

2 changes: 2 additions & 0 deletions source/common/world/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class World {

virtual void onBlockPlaced(int, int, int, const Block &) {}

static void initUsertype(sol::state &lua);

static bool isReloadRequested;
};

Expand Down
Loading

0 comments on commit b789fc3

Please sign in to comment.