Fixed threading issues & block definition props.
- Fixed deadlock when propagating light on chunk boundaries. - Fixed culls property on block definition not being set in RegisterBlocks.h - Properly snake_case tall_grass_* - Welcome back~master
parent
72adcec7a6
commit
d7382c2533
|
@ -3,9 +3,7 @@
|
|||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="CidrRootsConfiguration">
|
||||
<sourceRoots>
|
||||
<file path="$PROJECT_DIR$/assets" />
|
||||
<file path="$PROJECT_DIR$/src" />
|
||||
<file path="$PROJECT_DIR$/subgames" />
|
||||
<file path="$PROJECT_DIR$/test" />
|
||||
</sourceRoots>
|
||||
<libraryRoots>
|
||||
|
@ -15,6 +13,8 @@
|
|||
<file path="$PROJECT_DIR$/.idea" />
|
||||
<file path="$PROJECT_DIR$/Libraries" />
|
||||
<file path="$PROJECT_DIR$/cmake-build-install" />
|
||||
<file path="$PROJECT_DIR$/worlds" />
|
||||
<file path="$PROJECT_DIR$/worlds/world" />
|
||||
</excludeRoots>
|
||||
</component>
|
||||
<component name="GCoverageShowInEditor">
|
||||
|
@ -23,7 +23,4 @@
|
|||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectPlainTextFileTypeManager">
|
||||
<file url="file://$PROJECT_DIR$/src/util/Lock.cpp" />
|
||||
</component>
|
||||
</project>
|
|
@ -2,5 +2,6 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/lib/assimp" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -271,6 +271,7 @@ namespace RegisterBlocks {
|
|||
auto nameOpt = blockTable.get<sol::optional<std::string>>("name");
|
||||
if (!nameOpt) throw std::runtime_error(identifier + " is missing name property!");
|
||||
|
||||
bool culls = blockTable.get_or("culls", true);
|
||||
bool solid = blockTable.get_or("solid", true);
|
||||
bool lightPropagates = blockTable.get_or("light_propagates", false);
|
||||
auto maxStack = blockTable.get_or("stack", 64);
|
||||
|
@ -314,6 +315,7 @@ namespace RegisterBlocks {
|
|||
def->name = *nameOpt;
|
||||
def->index = defs.size();
|
||||
|
||||
def->culls = culls;
|
||||
def->solid = solid;
|
||||
def->lightSource = lightSource;
|
||||
def->lightPropagates = lightPropagates;
|
||||
|
|
|
@ -27,6 +27,7 @@ bool Dimension::setBlock(glm::ivec3 pos, unsigned int block) {
|
|||
if (newLight.x + newLight.y + newLight.z != 0) addBlockLight(pos, newLight);
|
||||
|
||||
if (def.lightPropagates) reflowLight(pos);
|
||||
|
||||
if (!def.lightPropagates && getLight(pos, chunk.get()).w != 0) removeSunlight(pos);
|
||||
|
||||
propogateRemoveNodes();
|
||||
|
@ -67,14 +68,15 @@ unsigned int Dimension::nextEntityInd() {
|
|||
//}
|
||||
|
||||
std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateAddNodes() {
|
||||
auto l = getWriteLock();
|
||||
|
||||
//TODO: Test if I need to do additional locking here (or shared ptring)
|
||||
std::unordered_set<glm::ivec3, Vec::ivec3> chunksUpdated {};
|
||||
|
||||
for (unsigned int channel = 0; channel < lightAddQueue.size(); channel++) {
|
||||
while (!lightAddQueue[channel].empty()) {
|
||||
LightAddNode& node = lightAddQueue[channel].front();
|
||||
for (unsigned int channel = 0; channel < 4; channel++) {
|
||||
while (true) {
|
||||
auto l = getWriteLock();
|
||||
if (lightAddQueue[channel].empty()) break;
|
||||
LightAddNode node = lightAddQueue[channel].front();
|
||||
lightAddQueue[channel].pop();
|
||||
l.unlock();
|
||||
|
||||
Chunk* chunk = node.chunk;
|
||||
if (!chunksUpdated.count(chunk->getPos())) chunksUpdated.insert(chunk->getPos());
|
||||
|
@ -100,11 +102,12 @@ std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateAddNodes() {
|
|||
if (game->getDefs().blockFromId(chunk->getBlock(ind)).lightPropagates && (sunDown || chunk->getLight(ind, channel) + 2 <= lightLevel)) {
|
||||
int subtract = sunDown ? 0 : 1;
|
||||
chunk->setLight(ind, channel, lightLevel - subtract);
|
||||
|
||||
auto l = getWriteLock();
|
||||
lightAddQueue[channel].emplace(ind, chunk);
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
lightAddQueue[channel].pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,13 +115,16 @@ std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateAddNodes() {
|
|||
}
|
||||
|
||||
std::unordered_set<glm::ivec3, Vec::ivec3> Dimension::propogateRemoveNodes() {
|
||||
auto l = getWriteLock();
|
||||
|
||||
std::unordered_set<glm::ivec3, Vec::ivec3> chunksUpdated {};
|
||||
|
||||
for (unsigned int channel = 0; channel < lightRemoveQueue.size(); channel++) {
|
||||
while (!lightRemoveQueue[channel].empty()) {
|
||||
LightRemoveNode& node = lightRemoveQueue[channel].front();
|
||||
for (unsigned int channel = 0; channel < 4; channel++) {
|
||||
while (true) {
|
||||
auto l = getWriteLock();
|
||||
if (lightRemoveQueue[channel].empty()) break;
|
||||
LightRemoveNode node = lightRemoveQueue[channel].front();
|
||||
lightRemoveQueue[channel].pop();
|
||||
l.unlock();
|
||||
|
||||
glm::ivec3 worldPos = node.chunk->getPos() * 16 + Space::Block::fromIndex(node.index);
|
||||
|
||||
for (const auto& i : Vec::TO_VEC) {
|
||||
|
@ -141,22 +147,23 @@ 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();
|
||||
if (replaceLight) lightAddQueue[channel].emplace(ind, chunk);
|
||||
lightRemoveQueue[channel].emplace(ind, checkLight, chunk);
|
||||
l.unlock();
|
||||
}
|
||||
else if (checkLight >= node.value) {
|
||||
auto chunk = containsWorldPos(node.chunk, check) ? node.chunk : getChunk(Space::Chunk::world::fromBlock(check)).get();
|
||||
if (!chunk) continue;
|
||||
|
||||
auto l = getWriteLock();
|
||||
lightAddQueue[channel].emplace(ind, chunk);
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
lightRemoveQueue[channel].pop();
|
||||
}
|
||||
}
|
||||
|
||||
l.unlock();
|
||||
|
||||
auto otherChunksUpdated = propogateAddNodes();
|
||||
chunksUpdated.insert(otherChunksUpdated.begin(), otherChunksUpdated.end());
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ 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;
|
||||
if (!regions.count(regionPosition)) return nullptr;
|
||||
return regions.at(regionPosition);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
for i = 1, 5, 1 do
|
||||
zepha.register_block(":tallgrass_" .. i, {
|
||||
zepha.register_block(":tall_grass_" .. i, {
|
||||
name = "Tall Grass",
|
||||
|
||||
culls = false,
|
||||
|
|
|
@ -1,41 +1,9 @@
|
|||
local identifier = "zeus:world:highlands"
|
||||
|
||||
-- local woo = "zeus:default:wood"
|
||||
-- local lea = "zeus:default:leaves"
|
||||
-- local inv = "invalid"
|
||||
--
|
||||
-- local shrub_layer_0 = {
|
||||
-- { inv, inv, inv },
|
||||
-- { inv, woo, inv },
|
||||
-- { inv, inv, inv }
|
||||
-- }
|
||||
--
|
||||
-- local shrub_layer_1 = {
|
||||
-- { inv, lea, inv },
|
||||
-- { lea, woo, lea },
|
||||
-- { inv, lea, inv }
|
||||
-- }
|
||||
--
|
||||
-- local shrub_layer_2 = {
|
||||
-- { inv, inv, inv },
|
||||
-- { inv, lea, inv },
|
||||
-- { inv, inv, inv }
|
||||
-- }
|
||||
--
|
||||
-- local shrub = zepha.create_structure({
|
||||
-- origin = V{1, 1, 1},
|
||||
-- schematic = {
|
||||
-- shrub_layer_0,
|
||||
-- shrub_layer_1,
|
||||
-- shrub_layer_2,
|
||||
-- }
|
||||
-- })
|
||||
|
||||
|
||||
local shrub = zepha.create_structure({
|
||||
local grass = zepha.create_structure({
|
||||
origin = V{1, 2, 3},
|
||||
schematic = {
|
||||
{{"zeus:default:tallgrass_4"}}
|
||||
{{"zeus:default:tall_grass_4"}}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -90,9 +58,7 @@ zepha.register_biome(identifier, {
|
|||
},
|
||||
biome_tint = "#c2fa61",
|
||||
noise = noise,
|
||||
structures = {
|
||||
shrub
|
||||
}
|
||||
structures = { grass }
|
||||
})
|
||||
|
||||
return identifier
|
|
@ -1,5 +1,36 @@
|
|||
local identifier = "zeus:world:plains"
|
||||
|
||||
local woo = "zeus:default:wood"
|
||||
local lea = "zeus:default:leaves"
|
||||
local inv = "invalid"
|
||||
|
||||
local shrub_layer_0 = {
|
||||
{ inv, inv, inv },
|
||||
{ inv, woo, inv },
|
||||
{ inv, inv, inv }
|
||||
}
|
||||
|
||||
local shrub_layer_1 = {
|
||||
{ inv, lea, inv },
|
||||
{ lea, woo, lea },
|
||||
{ inv, lea, inv }
|
||||
}
|
||||
|
||||
local shrub_layer_2 = {
|
||||
{ inv, inv, inv },
|
||||
{ inv, lea, inv },
|
||||
{ inv, inv, inv }
|
||||
}
|
||||
|
||||
local shrub = zepha.create_structure({
|
||||
origin = V{1, 1, 1},
|
||||
schematic = {
|
||||
shrub_layer_0,
|
||||
shrub_layer_1,
|
||||
shrub_layer_2,
|
||||
}
|
||||
})
|
||||
|
||||
local noise = {
|
||||
heightmap = {
|
||||
module = "add",
|
||||
|
@ -47,9 +78,7 @@ zepha.register_biome(identifier, {
|
|||
groups = { natural = 1 },
|
||||
biome_tint = "#aaed45",
|
||||
noise = noise,
|
||||
structures = {
|
||||
tree
|
||||
}
|
||||
structures = { shrub }
|
||||
})
|
||||
|
||||
return identifier
|
Loading…
Reference in New Issue