refactor: add 'const' qualifier for content units

This commit is contained in:
MihailRis 2024-08-20 22:00:30 +03:00
parent 2689e13cea
commit 333cbfe6f5
5 changed files with 7 additions and 15 deletions

View File

@ -65,14 +65,6 @@ public:
return defs[id];
}
[[deprecated]]
inline T* getWriteable(blockid_t id) const { // TODO: remove
if (id >= defs.size()) {
return nullptr;
}
return defs[id];
}
inline const T& require(blockid_t id) const {
return *defs.at(id);
}
@ -111,14 +103,14 @@ public:
ContentUnitDefs(UptrsMap<std::string, T> defs) : defs(std::move(defs)) {
}
T* find(const std::string& id) const {
const T* find(const std::string& id) const {
const auto& found = defs.find(id);
if (found == defs.end()) {
return nullptr;
}
return found->second.get();
}
T& require(const std::string& id) const {
const T& require(const std::string& id) const {
const auto& found = defs.find(id);
if (found == defs.end()) {
throw std::runtime_error("missing content unit " + id);

View File

@ -360,7 +360,7 @@ static int l_raycast(lua::State* L) {
for (int i = 0; i < addLen; i++) {
lua::rawgeti(L, i + 1, 5);
auto blockName = std::string(lua::tostring(L, -1));
Block* block = content->blocks.find(blockName);
const Block* block = content->blocks.find(blockName);
if (block != nullptr) {
filteredBlocks.insert(block->rt.id);
}

View File

@ -127,7 +127,7 @@ static int l_raycast(lua::State* L) {
for (int i = 0; i < addLen; i++) {
lua::rawgeti(L, i + 1, 6);
auto blockName = std::string(lua::tostring(L, -1));
Block* block = content->blocks.find(blockName);
const Block* block = content->blocks.find(blockName);
if (block != nullptr) {
filteredBlocks.insert(block->rt.id);
}

View File

@ -75,7 +75,7 @@ static sensorcallback create_sensor_callback(Entities* entities) {
}
static void initialize_body(
EntityDef& def, Rigidbody& body, entityid_t id, Entities* entities
const EntityDef& def, Rigidbody& body, entityid_t id, Entities* entities
) {
body.sensors.resize(def.radialSensors.size() + def.boxSensors.size());
for (auto& [i, box] : def.boxSensors) {
@ -111,7 +111,7 @@ static void initialize_body(
}
entityid_t Entities::spawn(
EntityDef& def,
const EntityDef& def,
glm::vec3 position,
dynamic::Map_sptr args,
dynamic::Map_sptr saved,

View File

@ -202,7 +202,7 @@ public:
);
entityid_t spawn(
EntityDef& def,
const EntityDef& def,
glm::vec3 position,
dynamic::Map_sptr args = nullptr,
dynamic::Map_sptr saved = nullptr,