refactor: add 'const' qualifier for content units
This commit is contained in:
+2
-10
@@ -65,14 +65,6 @@ public:
|
|||||||
return defs[id];
|
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 {
|
inline const T& require(blockid_t id) const {
|
||||||
return *defs.at(id);
|
return *defs.at(id);
|
||||||
}
|
}
|
||||||
@@ -111,14 +103,14 @@ public:
|
|||||||
ContentUnitDefs(UptrsMap<std::string, T> defs) : defs(std::move(defs)) {
|
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);
|
const auto& found = defs.find(id);
|
||||||
if (found == defs.end()) {
|
if (found == defs.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return found->second.get();
|
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);
|
const auto& found = defs.find(id);
|
||||||
if (found == defs.end()) {
|
if (found == defs.end()) {
|
||||||
throw std::runtime_error("missing content unit " + id);
|
throw std::runtime_error("missing content unit " + id);
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ static int l_raycast(lua::State* L) {
|
|||||||
for (int i = 0; i < addLen; i++) {
|
for (int i = 0; i < addLen; i++) {
|
||||||
lua::rawgeti(L, i + 1, 5);
|
lua::rawgeti(L, i + 1, 5);
|
||||||
auto blockName = std::string(lua::tostring(L, -1));
|
auto blockName = std::string(lua::tostring(L, -1));
|
||||||
Block* block = content->blocks.find(blockName);
|
const Block* block = content->blocks.find(blockName);
|
||||||
if (block != nullptr) {
|
if (block != nullptr) {
|
||||||
filteredBlocks.insert(block->rt.id);
|
filteredBlocks.insert(block->rt.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ static int l_raycast(lua::State* L) {
|
|||||||
for (int i = 0; i < addLen; i++) {
|
for (int i = 0; i < addLen; i++) {
|
||||||
lua::rawgeti(L, i + 1, 6);
|
lua::rawgeti(L, i + 1, 6);
|
||||||
auto blockName = std::string(lua::tostring(L, -1));
|
auto blockName = std::string(lua::tostring(L, -1));
|
||||||
Block* block = content->blocks.find(blockName);
|
const Block* block = content->blocks.find(blockName);
|
||||||
if (block != nullptr) {
|
if (block != nullptr) {
|
||||||
filteredBlocks.insert(block->rt.id);
|
filteredBlocks.insert(block->rt.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ static sensorcallback create_sensor_callback(Entities* entities) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void initialize_body(
|
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());
|
body.sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
||||||
for (auto& [i, box] : def.boxSensors) {
|
for (auto& [i, box] : def.boxSensors) {
|
||||||
@@ -111,7 +111,7 @@ static void initialize_body(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entityid_t Entities::spawn(
|
entityid_t Entities::spawn(
|
||||||
EntityDef& def,
|
const EntityDef& def,
|
||||||
glm::vec3 position,
|
glm::vec3 position,
|
||||||
dynamic::Map_sptr args,
|
dynamic::Map_sptr args,
|
||||||
dynamic::Map_sptr saved,
|
dynamic::Map_sptr saved,
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
entityid_t spawn(
|
entityid_t spawn(
|
||||||
EntityDef& def,
|
const EntityDef& def,
|
||||||
glm::vec3 position,
|
glm::vec3 position,
|
||||||
dynamic::Map_sptr args = nullptr,
|
dynamic::Map_sptr args = nullptr,
|
||||||
dynamic::Map_sptr saved = nullptr,
|
dynamic::Map_sptr saved = nullptr,
|
||||||
|
|||||||
Reference in New Issue
Block a user