Skip to content

Commit

Permalink
Merge pull request #19 from AnotherCraft/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
CZDanol authored Jun 6, 2023
2 parents b5172d4 + 397f7c5 commit 0548067
Show file tree
Hide file tree
Showing 20 changed files with 5,819 additions and 4,959 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
cmake_minimum_required(VERSION 3.20)
include(ExternalProject)

project(ac_worldgen_master VERSION 0.0.3 LANGUAGES CXX)
project(ac_worldgen_master VERSION 1.0.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -103,7 +103,7 @@ target_precompile_headers(x_ac_worldgen_dummy PRIVATE "${PROJECT_BASE_DIR}/src/p
target_include_directories(x_ac_worldgen_dummy PRIVATE "${PROJECT_BASE_DIR}/src")
target_include_directories(x_ac_worldgen_dummy SYSTEM PRIVATE
"${PROJECT_BASE_DIR}/include"
"${PROJECT_BASE_DIR}/deps/tracy"
"${CMAKE_BASE_DIR}/install/tracy/include"
"${CMAKE_BASE_DIR}/install/antlr/include"
"${CMAKE_BASE_DIR}/install/fastNoise2/include"
)
2 changes: 1 addition & 1 deletion deps/tracy
Submodule tracy updated 377 files
4 changes: 2 additions & 2 deletions docs/woglac_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,13 @@ In certain situations, for example when you have even block count wide corridors
Rules define... well rules of what component will actually be spawned. The used terminology is that rules *expand* into components. A rule can have multiple possible expansions, each with different priority and probability.

### Rule pragmas
<center>``
<center>

| Pragma | Type | Default value | Description |
| --- | --- | --- | --- |
`depthFirstProbability` | `Float` | `1` | Probability that the rule will expand depth-first (will put current rule expansions to the top of the queue) opposed to breadth-frist (would add current rule expansions to the end of the queue)

``</center>
</center>

### Rule expansions
> ```g4
Expand Down
15 changes: 10 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
#include "util/forit.h"
#include "util/iterators.h"
#include "util/tracyutils.h"

#include "worldgen/base/worldgenapi.h"

#include "worldgen/cpu/worldgenapi_cpu.h"
#include "worldgen/cpu/supp/wga_valuewrapper_cpu.h"
#include "woglac/wglcompiler.h"
#include "worldgen/cpu/supp/worldgen_cpu_utils.h"

std::mutex stdoutMutex;

std::mutex jobsMutex;
std::condition_variable jobEndCondition, newJobCondition;
TracyLockable(std::mutex, jobsMutex);
std::condition_variable_any jobEndCondition, newJobCondition;
std::queue<std::function<void()>> jobs;
size_t runningJobs = 0;

Expand Down Expand Up @@ -192,8 +191,12 @@ Compiles the source files and prints out the list of exports.
}

for(size_t i = 0; i < threadCount; i++) {
pool.push_back(std::thread([] {
pool.push_back(std::thread([i] {
WorldGenAPI_CPU::createLocalCache();

while(true) {
std::srand(std::time(0) ^ WorldGen_CPU_Utils::scramble(i));

std::function<void()> job;

{
Expand All @@ -218,6 +221,8 @@ Compiles the source files and prints out the list of exports.
jobEndCondition.notify_all();
}
}

WorldGenAPI_CPU::destroyLocalCache();
}));
}

Expand Down
14 changes: 14 additions & 0 deletions src/util/containerutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <cstdlib>

#include "worldgen/cpu/supp/worldgen_cpu_utils.h"

class ContainerUtils {

public:
Expand Down Expand Up @@ -31,4 +33,16 @@ class ContainerUtils {
return bestIx;
}

/// Pseudo-randomly shuffles the order of the items using Fisher-Yates shuffle
template<typename I>
static void randomShuffle(I begin, I end, uint32_t seed) {
const size_t sz = end - begin;
size_t ix = 0;
for(auto i = begin; i < end; i++) {
const auto j = i + (WorldGen_CPU_Utils::hash(ix, seed) % (sz - ix));
std::swap(*i, *j);
ix++;
}
}

};
43 changes: 22 additions & 21 deletions src/worldgen/base/autogen/wga_funcs.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// This file was automatically generated by /supp/autogen.

#include "../worldgenapi.h"

const WorldGenAPI::Functions &WorldGenAPI::functions() {
static const Functions fs = [] {
Functions fs;
Function f;

const auto finalize = [&]() {
f.prototype = Function::composePrototype(f.name, iterator(f.arguments).mapx(x.type).toList());
fs.list.push_back(f);
fs.prototypeMapping[f.prototype] = f.id;
if(!fs.nameSet.contains(f.name))
fs.nameList.push_back(f.name);
fs.nameSet.insert(f.name);
fs.nameMapping[f.name].push_back(f.id);
};

f.section = "Utility functions";
#include "../worldgenapi.h"

const WorldGenAPI::Functions &WorldGenAPI::functions() {
static const Functions fs = [] {
Functions fs;
Function f;

const auto finalize = [&]() {
f.prototype = Function::composePrototype(f.name, iterator(f.arguments).mapx(x.type).toList());
fs.list.push_back(f);
fs.prototypeMapping[f.prototype] = f.id;
if(!fs.nameSet.contains(f.name))
fs.nameList.push_back(f.name);
fs.nameSet.insert(f.name);
fs.nameMapping[f.name].push_back(f.id);
};

f.section = "Utility functions";
f.name = "worldPos";
f.returnValue.name = "pos";
f.arguments.resize(0);
Expand Down Expand Up @@ -1613,7 +1613,8 @@ f.id = 203;
finalize();


return fs;
} ();
return fs;
} ();
return fs;
}
}

3 changes: 2 additions & 1 deletion src/worldgen/base/supp/wga_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pch.h"
#include "wga_grammarsymbol.h"
#include "util/tracyutils.h"

class WGA_Rule : public WGA_GrammarSymbol {

Expand Down Expand Up @@ -43,7 +44,7 @@ class WGA_Rule : public WGA_GrammarSymbol {
std::vector<WGA_RuleExpansion *> expansions_;
CompiledExpansionList compiledExpansions_;
bool compiledReady_ = false;
std::mutex compilingMutex_;
TracyLockable(std::mutex, compilingMutex_);

};

Loading

0 comments on commit 0548067

Please sign in to comment.