-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move large header lines to cpp
- Loading branch information
Showing
28 changed files
with
1,637 additions
and
1,314 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "cellular_automata.h" | ||
|
||
int CellularAutomata::neighbor_count( const std::vector<std::vector<int>> &cells, | ||
const point &size, | ||
const point &p ) | ||
{ | ||
int neighbors = 0; | ||
for( int ni = -1; ni <= 1; ni++ ) { | ||
for( int nj = -1; nj <= 1; nj++ ) { | ||
const point n( p + point( ni, nj ) ); | ||
|
||
// These neighbors are outside the bounds, so they can't contribute. | ||
if( n.x < 0 || n.x >= size.x || n.y < 0 || n.y >= size.y ) { | ||
continue; | ||
} | ||
|
||
neighbors += cells[n.x][n.y]; | ||
} | ||
} | ||
// Because we included ourself in the loop above, subtract ourselves back out. | ||
neighbors -= cells[p.x][p.y]; | ||
|
||
return neighbors; | ||
} | ||
std::vector<std::vector<int>> CellularAutomata::generate_cellular_automaton( | ||
const point &size, | ||
const int alive, | ||
const int iterations, | ||
const int birth_limit, | ||
const int stasis_limit ) | ||
{ | ||
std::vector<std::vector<int>> current( size.x, std::vector<int>( size.y, 0 ) ); | ||
std::vector<std::vector<int>> next( size.x, std::vector<int>( size.y, 0 ) ); | ||
|
||
// Initialize our initial set of cells. | ||
for( int i = 0; i < size.x; i++ ) { | ||
for( int j = 0; j < size.y; j++ ) { | ||
current[i][j] = x_in_y( alive, 100 ); | ||
} | ||
} | ||
|
||
for( int iteration = 0; iteration < iterations; iteration++ ) { | ||
for( int i = 0; i < size.x; i++ ) { | ||
for( int j = 0; j < size.y; j++ ) { | ||
// Skip the edges--no need to complicate this with more complex neighbor | ||
// calculations, just keep them constant. | ||
if( i == 0 || i == size.x - 1 || j == 0 || j == size.y - 1 ) { | ||
next[i][j] = 0; | ||
continue; | ||
} | ||
|
||
// Count our neighors. | ||
const int neighbors = neighbor_count( current, size, point( i, j ) ); | ||
|
||
// Dead and > birth_limit neighbors, so become alive. | ||
if( ( current[i][j] == 0 ) && ( neighbors > birth_limit ) ) { | ||
next[i][j] = 1; | ||
} | ||
// Alive and > statis_limit neighbors, so stay alive. | ||
else if( ( current[i][j] == 1 ) && ( neighbors > stasis_limit ) ) { | ||
next[i][j] = 1; | ||
} | ||
// Else, die. | ||
else { | ||
next[i][j] = 0; | ||
} | ||
} | ||
} | ||
|
||
// Swap our current and next vectors and repeat. | ||
std::swap( current, next ); | ||
} | ||
|
||
return current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "coordinates.h" | ||
|
||
void real_coords::fromabs( const point &abs ) | ||
{ | ||
const point norm( std::abs( abs.x ), std::abs( abs.y ) ); | ||
abs_pos = abs; | ||
|
||
if( abs.x < 0 ) { | ||
abs_sub.x = ( abs.x - SEEX + 1 ) / SEEX; | ||
sub_pos.x = SEEX - 1 - ( ( norm.x - 1 ) % SEEX ); | ||
abs_om.x = ( abs_sub.x - subs_in_om_n ) / subs_in_om; | ||
om_sub.x = subs_in_om_n - ( ( ( norm.x - 1 ) / SEEX ) % subs_in_om ); | ||
} else { | ||
abs_sub.x = norm.x / SEEX; | ||
sub_pos.x = abs.x % SEEX; | ||
abs_om.x = abs_sub.x / subs_in_om; | ||
om_sub.x = abs_sub.x % subs_in_om; | ||
} | ||
om_pos.x = om_sub.x / 2; | ||
|
||
if( abs.y < 0 ) { | ||
abs_sub.y = ( abs.y - SEEY + 1 ) / SEEY; | ||
sub_pos.y = SEEY - 1 - ( ( norm.y - 1 ) % SEEY ); | ||
abs_om.y = ( abs_sub.y - subs_in_om_n ) / subs_in_om; | ||
om_sub.y = subs_in_om_n - ( ( ( norm.y - 1 ) / SEEY ) % subs_in_om ); | ||
} else { | ||
abs_sub.y = norm.y / SEEY; | ||
sub_pos.y = abs.y % SEEY; | ||
abs_om.y = abs_sub.y / subs_in_om; | ||
om_sub.y = abs_sub.y % subs_in_om; | ||
} | ||
om_pos.y = om_sub.y / 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "font_loader.h" | ||
|
||
void ensure_unifont_loaded( std::vector<std::string> &font_list ) | ||
{ | ||
if( std::find( std::begin( font_list ), std::end( font_list ), "unifont" ) == font_list.end() ) { | ||
font_list.emplace_back( PATH_INFO::fontdir() + "unifont.ttf" ); | ||
} | ||
} | ||
|
||
void font_loader::load_throws( const std::string &path ) | ||
{ | ||
try { | ||
cata_ifstream stream = std::move( cata_ifstream().mode( cata_ios_mode::binary ).open( path ) ); | ||
JsonIn json( *stream ); | ||
JsonObject config = json.get_object(); | ||
if( config.has_string( "typeface" ) ) { | ||
typeface.emplace_back( config.get_string( "typeface" ) ); | ||
} else { | ||
config.read( "typeface", typeface ); | ||
} | ||
if( config.has_string( "map_typeface" ) ) { | ||
map_typeface.emplace_back( config.get_string( "map_typeface" ) ); | ||
} else { | ||
config.read( "map_typeface", map_typeface ); | ||
} | ||
if( config.has_string( "overmap_typeface" ) ) { | ||
overmap_typeface.emplace_back( config.get_string( "overmap_typeface" ) ); | ||
} else { | ||
config.read( "overmap_typeface", overmap_typeface ); | ||
} | ||
|
||
ensure_unifont_loaded( typeface ); | ||
ensure_unifont_loaded( map_typeface ); | ||
ensure_unifont_loaded( overmap_typeface ); | ||
|
||
} catch( const std::exception &err ) { | ||
throw std::runtime_error( std::string( "loading font settings from " ) + path + " failed: " + | ||
err.what() ); | ||
} | ||
} | ||
|
||
void font_loader::load() | ||
{ | ||
const std::string user_fontconfig = PATH_INFO::user_fontconfig(); | ||
const std::string fontconfig = PATH_INFO::fontconfig(); | ||
bool try_user = true; | ||
if( !file_exist( user_fontconfig ) ) { | ||
if( !copy_file( fontconfig, user_fontconfig ) ) { | ||
try_user = false; | ||
DebugLog( DL::Error, DC::SDL ) << "failed to create user font config file " | ||
<< user_fontconfig; | ||
} | ||
} | ||
if( try_user ) { | ||
font_loader copy = *this; | ||
try { | ||
load_throws( user_fontconfig ); | ||
return; | ||
} catch( const std::exception &e ) { | ||
DebugLog( DL::Error, DC::SDL ) << e.what(); | ||
} | ||
*this = copy; | ||
} | ||
try { | ||
load_throws( fontconfig ); | ||
} catch( const std::exception &e ) { | ||
DebugLog( DL::Error, DC::SDL ) << e.what(); | ||
abort(); | ||
} | ||
} |
Oops, something went wrong.