Save work for now

This commit is contained in:
Pyrex 2023-09-19 19:41:42 -07:00
parent bc6a7cd5a7
commit ed57ba18ed
4 changed files with 3 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 B

After

Width:  |  Height:  |  Size: 586 B

View File

@ -30,7 +30,7 @@ void main() async {
var H = 16; var H = 16;
var wfc = Wfc(template, W, H); var wfc = Wfc(template, W, H);
wfc.run(0, -1); wfc.run(1, -1);
var output = wfc.extractPartial(); var output = wfc.extractPartial();
for (var y = 0; y < W; y++) { for (var y = 0; y < W; y++) {
for (var x = 0; x < H; x++) { for (var x = 0; x < H; x++) {

View File

@ -24,14 +24,7 @@ class Wfc<T> {
List<int?> _observed = []; List<int?> _observed = [];
// computationally expensive stuff that we keep in an incremental way // computationally expensive stuff that we keep in an incremental way
List<double> _weightLogWeights = [];
double _sumOfWeights = 0.0, _sumOfWeightLogWeights = 0.0;
double _startingEntropy = 0.0;
List<int> _sumsOfOnes = []; List<int> _sumsOfOnes = [];
List<double> _sumsOfWeights = [];
List<double> _sumsOfWeightLogWeights = [];
List<double> _entropies = [];
// temporaries // temporaries
List<double> _distribution = []; List<double> _distribution = [];
@ -53,22 +46,7 @@ class Wfc<T> {
_distribution = [for (var t = 0; t < _nShingles; t++) 0.0]; _distribution = [for (var t = 0; t < _nShingles; t++) 0.0];
_observed = [for (var r = 0; r < _n; r++) null]; _observed = [for (var r = 0; r < _n; r++) null];
_weightLogWeights = [
for (var t = 0; t < _nShingles; t++) _weight(t) * math.log(_weight(t))
];
_sumOfWeights = 0.0;
_sumOfWeightLogWeights = 0.0;
for (var t = 0; t < _nShingles; t++) {
_sumOfWeights += _weight(t);
_sumOfWeightLogWeights += _weightLogWeights[t];
}
_startingEntropy =
math.log(_sumOfWeights) - _sumOfWeightLogWeights / _sumOfWeights;
_sumsOfOnes = [for (var r = 0; r < _n; r++) 0]; _sumsOfOnes = [for (var r = 0; r < _n; r++) 0];
_sumsOfWeights = [for (var r = 0; r < _n; r++) 0.0];
_sumsOfWeightLogWeights = [for (var r = 0; r < _n; r++) 0.0];
_entropies = [for (var r = 0; r < _n; r++) 0.0];
_stack = [for (var r = 0; r < _n * _nShingles; r++) (0, 0)]; _stack = [for (var r = 0; r < _n * _nShingles; r++) (0, 0)];
_stacksize = 0; _stacksize = 0;
@ -85,9 +63,6 @@ class Wfc<T> {
} }
_sumsOfOnes[i] = _nShingles; _sumsOfOnes[i] = _nShingles;
_sumsOfWeights[i] = _sumOfWeights;
_sumsOfWeightLogWeights[i] = _sumOfWeightLogWeights;
_entropies[i] = _startingEntropy;
_observed[i] = null; _observed[i] = null;
} }
} }
@ -164,7 +139,7 @@ class Wfc<T> {
continue; continue;
} }
var remainingValues = _sumsOfOnes[i]; var remainingValues = _sumsOfOnes[i];
double entropy = remainingValues.toDouble(); // _entropies[i]; double entropy = remainingValues.toDouble();
if (remainingValues > 1 && entropy <= min) { if (remainingValues > 1 && entropy <= min) {
double noise = 1E-6 * random.nextDouble(); double noise = 1E-6 * random.nextDouble();
if (entropy + noise < min) { if (entropy + noise < min) {
@ -235,11 +210,6 @@ class Wfc<T> {
_stacksize++; _stacksize++;
_sumsOfOnes[i] -= 1; _sumsOfOnes[i] -= 1;
_sumsOfWeights[i] -= _weight(t);
_sumsOfWeightLogWeights[i] -= _weightLogWeights[t];
var sum = _sumsOfWeights[i];
_entropies[i] = math.log(sum) - _sumsOfWeightLogWeights[i] / sum;
} }
} }
@ -266,7 +236,6 @@ class WfcTemplate<T> {
final List<T> bitmap = []; final List<T> bitmap = [];
for (var i = 0; i < sx * sy; i++) { for (var i = 0; i < sx * sy; i++) {
var pixel = bytedata.getUint32(i * 4, Endian.little); var pixel = bytedata.getUint32(i * 4, Endian.little);
log("pixel: $pixel");
bitmap.add(cb(pixel)); bitmap.add(cb(pixel));
} }

View File

@ -12,7 +12,7 @@ class Level {
} }
Future<WfcTemplate<LevelTile>> loadLevelWfcAsync(String name) async { Future<WfcTemplate<LevelTile>> loadLevelWfcAsync(String name) async {
return WfcTemplate.loadAsync(name, 2, (c) { return WfcTemplate.loadAsync(name, 3, (c) {
switch (c) { switch (c) {
// ABGR // ABGR
case 0xFF000000: case 0xFF000000: