Clean up some Codacy issues, make scope locks more clear by using _ as name.

master
Auri 2020-11-04 14:22:57 -08:00
parent 041636254a
commit 376593a9f1
8 changed files with 38 additions and 41 deletions

View File

@ -95,8 +95,7 @@ void ClientNetworkInterpreter::receivedPacket(std::unique_ptr<PacketView> p) {
case Packet::Type::INV_INVALID: {
std::string source = p->d.read<std::string>();
std::string list = p->d.read<std::string>();
throw std::runtime_error("Invalid inventory " + source + ":" + list + " was request by client.");
break; }
throw std::runtime_error("Invalid inventory " + source + ":" + list + " was request by client."); }
}
}

View File

@ -195,11 +195,11 @@ sol::protected_function_result MenuSandbox::errorCallback(sol::protected_functio
throw std::out_of_range("Error thrown outside of handled files. [2]");
}
catch (std::runtime_error e) {
catch (const std::runtime_error& e) {
std::cout << Log::err << e.what() << std::endl;
throw;
}
catch (std::out_of_range e) {
catch (const std::out_of_range& e) {
std::cout << Log::err << "Failed to format error, " << e.what() << Log::endl;
throw std::runtime_error(errString);
}

View File

@ -184,7 +184,7 @@ void MainMenuScene::findSubgames() {
subgames.push_back({icon, {name, description, version}, subgameFolder.path});
}
catch(const std::runtime_error e) {
catch(const std::runtime_error& e) {
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e.what() << Log::endl;
}

View File

@ -6,20 +6,20 @@
#include <shared_mutex>
using MutexType = std::shared_timed_mutex;
using ReadLock = std::shared_lock<MutexType>;
using WriteLock = std::unique_lock<MutexType>;
using mutex_type = std::shared_timed_mutex;
using read_lock = std::shared_lock<mutex_type>;
using write_lock = std::unique_lock<mutex_type>;
class Lockable {
public:
ReadLock getReadLock() const {
return ReadLock {const_cast<MutexType&>(mutex)};
read_lock getReadLock() const {
return read_lock {const_cast<mutex_type&>(mutex)};
};
WriteLock getWriteLock() {
return WriteLock {mutex};
write_lock getWriteLock() {
return write_lock {mutex};
};
private:
MutexType mutex;
mutex_type mutex;
};

View File

@ -36,7 +36,7 @@ bool Dimension::setBlock(glm::ivec3 pos, unsigned int block) {
}
unsigned int Dimension::nextEntityInd() {
auto l = getWriteLock();
auto _ = getWriteLock();
return entityInd++;
}
@ -103,7 +103,7 @@ std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateAddNodes() {
int subtract = sunDown ? 0 : 1;
chunk->setLight(ind, channel, lightLevel - subtract);
auto l = getWriteLock();
l.lock();
lightAddQueue[channel].emplace(ind, chunk);
l.unlock();
}
@ -147,7 +147,7 @@ std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateRemoveNodes() {
game->getDefs().blockFromId(chunk->getBlock(Space::Block::index(check))).lightSource[channel]);
chunk->setLight(ind, channel, replaceLight);
auto l = getWriteLock();
l.lock();
if (replaceLight) lightAddQueue[channel].emplace(ind, chunk);
lightRemoveQueue[channel].emplace(ind, checkLight, chunk);
l.unlock();
@ -156,7 +156,7 @@ std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateRemoveNodes() {
auto chunk = containsWorldPos(node.chunk, check) ? node.chunk : getChunk(Space::Chunk::world::fromBlock(check)).get();
if (!chunk) continue;
auto l = getWriteLock();
l.lock();
lightAddQueue[channel].emplace(ind, chunk);
l.unlock();
}
@ -219,7 +219,7 @@ void Dimension::addBlockLight(glm::ivec3 pos, glm::ivec3 light) {
startChunk->setLight(ind, 1, light.y);
startChunk->setLight(ind, 2, light.z);
auto l = getWriteLock();
auto _ = getWriteLock();
lightAddQueue[0].emplace(ind, startChunk.get());
lightAddQueue[1].emplace(ind, startChunk.get());
lightAddQueue[2].emplace(ind, startChunk.get());
@ -234,7 +234,7 @@ void Dimension::removeBlockLight(glm::ivec3 pos) {
startChunk->setLight(ind, 1, 0);
startChunk->setLight(ind, 2, 0);
auto l = getWriteLock();
auto _ = getWriteLock();
lightRemoveQueue[0].emplace(ind, val.x, startChunk.get());
lightRemoveQueue[1].emplace(ind, val.y, startChunk.get());
lightRemoveQueue[2].emplace(ind, val.z, startChunk.get());
@ -259,7 +259,7 @@ void Dimension::reflowLight(glm::ivec3 pos) {
chunk->setLight(ind, placeLight);
auto l = getWriteLock();
auto _ = getWriteLock();
lightAddQueue[0].emplace(ind, chunk.get());
lightAddQueue[1].emplace(ind, chunk.get());
lightAddQueue[2].emplace(ind, chunk.get());
@ -272,7 +272,7 @@ void Dimension::removeSunlight(glm::ivec3 pos) {
unsigned int light = chunk->getLight(ind, 3);
chunk->setLight(ind, 3, 0);
auto l = getWriteLock();
auto _ = getWriteLock();
lightRemoveQueue[SUNLIGHT_CHANNEL].emplace(ind, light, chunk.get());
}
@ -281,6 +281,6 @@ void Dimension::setAndReflowSunlight(glm::ivec3 pos, unsigned char level) {
unsigned int ind = Space::Block::index(pos);
chunk->setLight(ind, 3, level);
auto l = getWriteLock();
auto _ = getWriteLock();
lightAddQueue[SUNLIGHT_CHANNEL].emplace(ind, chunk.get());
}

View File

@ -23,15 +23,13 @@ unsigned int DimensionBase::getInd() {
}
std::shared_ptr<Region> DimensionBase::getRegion(glm::ivec3 regionPosition) const {
// std::cout << "region start" << std::endl;
auto l = getReadLock();
// std::cout << "region mid" << std::endl;
auto _ = getReadLock();
if (!regions.count(regionPosition)) return nullptr;
return regions.at(regionPosition);
}
void DimensionBase::removeRegion(glm::ivec3 pos) {
auto l = getWriteLock();
auto _ = getWriteLock();
regions.erase(pos);
}
@ -44,8 +42,8 @@ std::shared_ptr<MapBlock> DimensionBase::getMapBlock(glm::ivec3 mapBlockPosition
void DimensionBase::removeMapBlock(glm::ivec3 pos) {
auto region = getRegion(Space::Region::world::fromMapBlock(pos));
if (!region) return;
auto ind = Space::MapBlock::index(pos);
region->remove(ind);
auto i = Space::MapBlock::index(pos);
region->remove(i);
if (region->count == 0) removeRegion(Space::Region::world::fromMapBlock(pos));
}
@ -68,8 +66,8 @@ void DimensionBase::setChunk(std::shared_ptr<Chunk> chunk) {
void DimensionBase::removeChunk(glm::ivec3 pos){
auto mapBlock = getMapBlock(Space::MapBlock::world::fromChunk(pos));
if (!mapBlock) return;
auto ind = Space::Chunk::index(pos);
mapBlock->remove(ind);
auto i = Space::Chunk::index(pos);
mapBlock->remove(i);
if (mapBlock->count == 0) removeMapBlock(Space::MapBlock::world::fromChunk(pos));
}
@ -91,7 +89,7 @@ bool DimensionBase::setBlock(glm::ivec3 pos, unsigned int block) {
double DimensionBase::getBlockDamage(glm::ivec3 pos) const {
auto l = getReadLock();
auto _ = getReadLock();
return blockDamages.count(pos) ? blockDamages.at(pos).curr : 0;
}
@ -99,7 +97,7 @@ double DimensionBase::setBlockDamage(glm::ivec3 pos, double damage) {
if (blockDamages.count(pos)) blockDamages[pos].curr = damage;
else {
double health = game->getDefs().blockFromId(getBlock(pos)).health;
auto l = getWriteLock();
auto _ = getWriteLock();
blockDamages.insert({pos, Damage { damage, health }});
}
@ -121,7 +119,7 @@ bool DimensionBase::setBiome(glm::ivec3 pos, unsigned int biome) {
}
std::shared_ptr<Region> DimensionBase::getOrCreateRegion(glm::ivec3 pos) {
auto l = getWriteLock();
auto _ = getWriteLock();
if (regions[pos]) return regions[pos];
regions[pos] = std::make_shared<Region>(pos);
return regions[pos];

View File

@ -2,7 +2,7 @@
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License](https://creativecommons.org/licenses/by-sa/3.0/).
### File-specific attribution and Licenses
## File-specific attribution and Licenses
**zeus_button_extex.png**

View File

@ -1,6 +1,6 @@
# Item Collection
**By Aurailus**
**By Auri Collings (Aurailus)**
## Description
@ -12,9 +12,9 @@ Item Collection is a mod that enables blocks to yield zero or more items when br
Item Collection can be configured to yield items in multiple ways:
1) Adding blocks directly to the user's inventory. `"direct"`
2) Creating a dropped-item entity that can be picked up by a player standing nearby. `"ent_nearby"`
3) Creating a dropped-item entity that can be picked up by interacting with it. `"ent_interact"`
1. Adding blocks directly to the user's inventory. `"direct"`
2. Creating a dropped-item entity that can be picked up by a player standing nearby. `"ent_nearby"`
3. Creating a dropped-item entity that can be picked up by interacting with it. `"ent_interact"`
This can be configured using the `/item_collection:set_mode` chat command, or by setting the `mode` parameter inside of the config file. (UNIMPLEMENTED)
@ -27,17 +27,17 @@ Item Collection will, by default, attempt to add all items to a `main` list insi
Item Collection will look for a `yields` parameter in the definition of the block broken. This field can either be a string containing an item name, an item name followed by a number denoting how many of the item to yield, or a function which returns a string in one of the two previous formats. The following code blocks are examples of valid formats:
Drop a dirt block:
```
```lua
yields = "zeus:default:dirt"
```
Drop four dirt blocks:
```
```lua
yields = "zeus:default:dirt 4"
```
Drop a dirt block 50% of the time:
```
```lua
yields = function(pos)
if math.random() >= 0.5 then
return "zeus:default:dirt"