Skip to content

Commit

Permalink
Remove default_idx parameter from load_mapgen_function.
Browse files Browse the repository at this point in the history
This feature is not available anymore.

It was added by 04e45ea without any explanation.
  • Loading branch information
BevapDin committed Feb 2, 2020
1 parent 0c650d1 commit 9b82a33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 41 deletions.
38 changes: 4 additions & 34 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ class mapgen_basic_container
mapgens_.push_back( ptr );
return mapgens_.size() - 1;
}
void erase( const size_t index ) {
if( index > mapgens_.size() ) {
return;
}
assert( mapgens_[index] );
// Can't actually erase it as this might invalid the index stored elsewhere
mapgens_[index]->weight = 0;
}
/**
* Pick a mapgen function randomly and call its generate function.
* This basically runs the mapgen functions with the given @ref mapgendata
Expand Down Expand Up @@ -328,10 +320,6 @@ class mapgen_factory
}
return iter->second.generate( dat, hardcoded_weight );
}
/// @see mapgen_basic_container::erase
void erase( const std::string &key, const size_t index ) {
mapgens_[key].erase( index );
}
};

static mapgen_factory oter_mapgen;
Expand Down Expand Up @@ -405,21 +393,11 @@ static void set_mapgen_defer( const JsonObject &jsi, const std::string &member,
* load a single mapgen json structure; this can be inside an overmap_terrain, or on it's own.
*/
std::shared_ptr<mapgen_function>
load_mapgen_function( const JsonObject &jio, const std::string &id_base,
int default_idx, const point &offset )
load_mapgen_function( const JsonObject &jio, const std::string &id_base, const point &offset )
{
int mgweight = jio.get_int( "weight", 1000 );
std::shared_ptr<mapgen_function> ret;
if( mgweight <= 0 || jio.get_bool( "disabled", false ) ) {
const std::string mgtype = jio.get_string( "method" );
if( default_idx != -1 && mgtype == "builtin" ) {
if( jio.has_string( "name" ) ) {
const std::string mgname = jio.get_string( "name" );
if( mgname == id_base ) {
oter_mapgen.erase( id_base, default_idx );
}
}
}
jio.allow_omitted_members();
return nullptr; // nothing
}
Expand Down Expand Up @@ -489,7 +467,7 @@ void load_mapgen( const JsonObject &jo )
point offset;
for( JsonArray row_items : ja ) {
for( const std::string mapgenid : row_items ) {
const auto mgfunc = load_mapgen_function( jo, mapgenid, -1, offset );
const auto mgfunc = load_mapgen_function( jo, mapgenid, offset );
if( mgfunc ) {
oter_mapgen.add( mapgenid, mgfunc );
}
Expand All @@ -505,7 +483,7 @@ void load_mapgen( const JsonObject &jo )
}
if( !mapgenid_list.empty() ) {
const std::string mapgenid = mapgenid_list[0];
const auto mgfunc = load_mapgen_function( jo, mapgenid, -1, point_zero );
const auto mgfunc = load_mapgen_function( jo, mapgenid, point_zero );
if( mgfunc ) {
for( auto &i : mapgenid_list ) {
oter_mapgen.add( i, mgfunc );
Expand All @@ -514,7 +492,7 @@ void load_mapgen( const JsonObject &jo )
}
}
} else if( jo.has_string( "om_terrain" ) ) {
load_mapgen_function( jo, jo.get_string( "om_terrain" ), -1, point_zero );
load_mapgen_function( jo, jo.get_string( "om_terrain" ), point_zero );
} else if( jo.has_string( "nested_mapgen_id" ) ) {
load_nested_mapgen( jo, jo.get_string( "nested_mapgen_id" ) );
} else if( jo.has_string( "update_mapgen_id" ) ) {
Expand Down Expand Up @@ -7346,14 +7324,6 @@ bool run_mapgen_func( const std::string &mapgen_id, mapgendata &dat )
return oter_mapgen.generate( dat, mapgen_id );
}

int register_mapgen_function( const std::string &key )
{
if( const auto ptr = get_mapgen_cfunction( key ) ) {
return oter_mapgen.add( key, std::make_shared<mapgen_function_builtin>( ptr ) );
}
return -1;
}

bool has_mapgen_for( const std::string &key )
{
return oter_mapgen.has( key );
Expand Down
2 changes: 1 addition & 1 deletion src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class mapgen_function_json_nested : public mapgen_function_json_base
* Load mapgen function of any type from a json object
*/
std::shared_ptr<mapgen_function> load_mapgen_function( const JsonObject &jio,
const std::string &id_base, int default_idx, const point &offset );
const std::string &id_base, const point &offset );
/*
* Load the above directly from a file via init, as opposed to riders attached to overmap_terrain. Added check
* for oter_mapgen key, multiple possible ( ie, [ "house", "house_base" ] )
Expand Down
8 changes: 2 additions & 6 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,10 @@ static void load_overmap_terrain_mapgens( const JsonObject &jo, const std::strin
{
const std::string fmapkey( id_base + suffix );
const std::string jsonkey( "mapgen" + suffix );
bool default_mapgen = jo.get_bool( "default_mapgen", true );
int default_idx = -1;
if( default_mapgen ) {
default_idx = register_mapgen_function( fmapkey );
}
register_mapgen_function( fmapkey );
if( jo.has_array( jsonkey ) ) {
for( JsonObject jio : jo.get_array( jsonkey ) ) {
load_mapgen_function( jio, fmapkey, default_idx, point_zero );
load_mapgen_function( jio, fmapkey, point_zero );
}
}
}
Expand Down

0 comments on commit 9b82a33

Please sign in to comment.