-
Notifications
You must be signed in to change notification settings - Fork 280
/
overmap_noise_test.cpp
70 lines (59 loc) · 2.02 KB
/
overmap_noise_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "catch/catch.hpp"
#include <fstream>
#include <string>
#include "game_constants.h"
#include "overmap_noise.h"
#include "point.h"
static void export_raw_noise( const std::string &filename, const om_noise::om_noise_layer &noise,
int width, int height )
{
std::ofstream testfile;
testfile.open( filename, std::ofstream::trunc );
testfile << "P2" << '\n';
testfile << width << " " << height << '\n';
testfile << "255" << '\n';
for( int x = 0; x < width; x++ ) {
for( int y = 0; y < height; y++ ) {
testfile << static_cast<int>( noise.noise_at( {x, y} ) * 255 ) << " ";
}
testfile << '\n';
}
testfile.close();
}
static void export_interpreted_noise(
const std::string &filename, const om_noise::om_noise_layer &noise, int width, int height,
float threshold )
{
std::ofstream testfile;
testfile.open( filename, std::ofstream::trunc );
testfile << "P2" << '\n';
testfile << width << " " << height << '\n';
testfile << "255" << '\n';
for( int x = 0; x < width; x++ ) {
for( int y = 0; y < height; y++ ) {
if( noise.noise_at( {x, y} ) > threshold ) {
testfile << 255 << " ";
} else {
testfile << 0 << " ";
}
}
testfile << '\n';
}
testfile.close();
}
TEST_CASE( "om_noise_layer_forest_export", "[.]" )
{
const om_noise::om_noise_layer_forest f( point_abs_omt(), 1920237457 );
export_raw_noise( "forest-map-raw.pgm", f, OMAPX, OMAPY );
}
TEST_CASE( "om_noise_layer_floodplain_export", "[.]" )
{
const om_noise::om_noise_layer_floodplain f( point_abs_omt(), 1920237457 );
export_raw_noise( "floodplain-map-raw.pgm", f, OMAPX, OMAPY );
}
TEST_CASE( "om_noise_layer_lake_export", "[.]" )
{
const om_noise::om_noise_layer_lake f( point_abs_omt(), 1920237457 );
export_raw_noise( "lake-map-raw.pgm", f, OMAPX * 5, OMAPY * 5 );
export_interpreted_noise( "lake-map-interp.pgm", f, OMAPX * 5, OMAPY * 5, 0.25 );
}