Skip to content

Commit

Permalink
smooth borders, better border textures
Browse files Browse the repository at this point in the history
  • Loading branch information
ineveraskedforthis committed Jan 21, 2025
1 parent 249a7a1 commit d94d341
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Binary file modified assets/imp_border.dds
Binary file not shown.
Binary file modified assets/prov_border.dds
Binary file not shown.
2 changes: 1 addition & 1 deletion src/economy/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ void presimulate(sys::state& state) {
#ifdef NDEBUG
uint32_t steps = 365;
#else
uint32_t steps = 20;
uint32_t steps = 2;
#endif
for(uint32_t i = 0; i < steps; i++) {
update_factory_employment(state);
Expand Down
4 changes: 2 additions & 2 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void display_data::render(sys::state& state, glm::vec2 screen_size, glm::vec2 of
glBindTexture(GL_TEXTURE_2D, textures[texture_province_fow]);
if(zoom > map::zoom_close) {
if(zoom > map::zoom_very_close) { // Render province borders
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.0001f); // width
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.0003f); // width
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textures[texture_prov_border]);

Expand Down Expand Up @@ -766,7 +766,7 @@ void display_data::render(sys::state& state, glm::vec2 screen_size, glm::vec2 of
}
// coasts
{
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.0004f); // width
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.0006f); // width
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textures[texture_coastal_border]);
glBindVertexArray(vao_array[vo_coastal]);
Expand Down
29 changes: 29 additions & 0 deletions src/map/map_borders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ bool extend_if_possible(uint32_t x, int32_t border_id, direction dir, std::vecto
return true;
};

void smooth_points(std::vector<glm::vec2>& vertices) {
std::vector<glm::vec2> vertices_copy = vertices;

auto start = int(0);
auto end = start + int(vertices.size());
for(int i = start + 1; i < end - 1; i++) {
glm::vec2 new_position{ 0.f, 0.f };
float count = 0.f;
bool smooth = true;
for(int shift = -2; shift <= 2; shift++) {
if(i + shift < start) {
continue;
};
if(i + shift >= end) {
continue;
};
count += 1.f / (float(std::abs(shift)) + 1.f);
new_position += (vertices_copy[i + shift]) * 1.f / (float(std::abs(shift)) + 1.f);
}
if((count > 0) && smooth) {
vertices[i] = new_position / count;
}
}
}

// Get the index of the border from the province ids and create a new one if one doesn't exist
int32_t get_border_index(uint16_t map_province_id1, uint16_t map_province_id2, parsers::scenario_building_context& context) {
auto province_id1 = province::from_map_id(map_province_id1);
Expand Down Expand Up @@ -547,6 +572,7 @@ void display_data::make_borders(sys::state& state, std::vector<bool>& visited) {
borders[border_index].start_index = int32_t(border_vertices.size());

auto res = make_border_section(*this, state, visited, province::to_map_id(prim), province::to_map_id(sec), i, j * 2);
smooth_points(res);
add_border_segment_vertices(*this, res);

borders[border_index].count = int32_t(border_vertices.size() - borders[border_index].start_index);
Expand All @@ -572,6 +598,7 @@ void display_data::make_borders(sys::state& state, std::vector<bool>& visited) {
borders[border_index].start_index = int32_t(border_vertices.size());

auto res = make_border_section(*this, state, visited, province::to_map_id(prim), province::to_map_id(sec), i, j * 2 + 1);
smooth_points(res);
add_border_segment_vertices(*this, res);

borders[border_index].count = int32_t(border_vertices.size() - borders[border_index].start_index);
Expand Down Expand Up @@ -793,6 +820,7 @@ void display_data::make_coastal_borders(sys::state& state, std::vector<bool>& vi
bool was_visited = visited[i + (j * 2) * size_x];
if(!was_visited && coastal_point(state, safe_get_province(glm::ivec2(i, j)), safe_get_province(glm::ivec2(i - 1, j)))) {
auto res = make_coastal_loop(*this, state, visited, i, j * 2);
smooth_points(res);
add_coastal_loop_vertices(*this, res);
}
}
Expand All @@ -802,6 +830,7 @@ void display_data::make_coastal_borders(sys::state& state, std::vector<bool>& vi
bool was_visited = visited[i + (j * 2 + 1) * size_x];
if(!was_visited && coastal_point(state, safe_get_province(glm::ivec2(i, j)), safe_get_province(glm::ivec2(i, j + 1)))) {
auto res = make_coastal_loop(*this, state, visited, i, j * 2 + 1);
smooth_points(res);
add_coastal_loop_vertices(*this, res);
}
}
Expand Down

0 comments on commit d94d341

Please sign in to comment.