Skip to content

Commit

Permalink
use higher quality region map.
Browse files Browse the repository at this point in the history
need to find a way to optimize this at some point so the initial load
doesn't take ten seconds.
  • Loading branch information
BenLubar committed Apr 1, 2020
1 parent cc45c3a commit b5a8d44
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = thirdparty/embed-resource
url = ../../CogentEmbedded/embed-resource.git
branch = cpp_11_compatibility
[submodule "thirdparty/lodepng"]
path = thirdparty/lodepng
url = ../../lvandeve/lodepng.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ endforeach()

file(WRITE events.h "${EVENT_HEADER_1}${EVENT_HEADER_2}\n")

include_directories(thirdparty/lodepng)

add_subdirectory(thirdparty/embed-resource EXCLUDE_FROM_ALL)

SET(PROJECT_SRCS
Expand All @@ -72,6 +74,7 @@ SET(PROJECT_SRCS
render_layer.cpp
render_list.cpp
debug.cpp
thirdparty/lodepng/lodepng.cpp
)

SET(PROJECT_HDRS
Expand All @@ -82,6 +85,7 @@ SET(PROJECT_HDRS
events.h
weblegends-plugin.h
weblegends-git-describe.h
thirdparty/lodepng/lodepng.h
)

FILE(GLOB EVENT_SRCS events/*.cpp)
Expand Down
2 changes: 1 addition & 1 deletion events/hist_figure_travel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ void do_event(std::ostream & s, const event_context & context, df::history_event
BREAK(reason);
}
AFTER_SWITCH(reason, stl_sprintf("event-%d (HIST_FIGURE_TRAVEL)", event->id));
do_location_2(s, context, event, prefix);
do_location_2(s, context, event, prefix, true);
}
104 changes: 55 additions & 49 deletions faux-wikipedia.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,33 @@ main::after {
content: '';
}

.home-links th {
text-align: left;
padding: 2px 4px 2px 8px;
}
.home-links td {
text-align: right;
padding: 2px 8px 2px 4px;
}
.home-links tr:hover {
background-color: var(--off-background-color);
}

svg {
shape-rendering: geometricprecision;
}

.map {
width: 100%;
height: auto;
max-width: 300px;
border: 1px solid var(--border-color);
float: right;
fill: var(--text-color);
background-color: var(--off-background-color);
}

.map path {
.map path, #region path {
fill-rule: evenodd;
}

Expand All @@ -182,54 +200,42 @@ main::after {
fill-opacity: 0.75;
}

.biome-mountain { fill: #777; }
.biome-glacier { fill: #fff; }
.biome-tundra { fill: #fff; }
.biome-swamp_temperate_freshwater { fill: #470; }
.biome-swamp_temperate_saltwater { fill: #470; }
.biome-marsh_temperate_freshwater { fill: #470; }
.biome-marsh_temperate_saltwater { fill: #470; }
.biome-swamp_tropical_freshwater { fill: #470; }
.biome-swamp_tropical_saltwater { fill: #470; }
.biome-swamp_mangrove { fill: #470; }
.biome-marsh_tropical_freshwater { fill: #470; }
.biome-marsh_tropical_saltwater { fill: #470; }
.biome-forest_taiga { fill: #070; }
.biome-forest_temperate_conifer { fill: #070; }
.biome-forest_temperate_broadleaf { fill: #070; }
.biome-forest_tropical_conifer { fill: #070; }
.biome-forest_tropical_dry_broadleaf { fill: #070; }
.biome-forest_tropical_moist_broadleaf { fill: #070; }
.biome-grassland_temperate { fill: #7c0; }
.biome-savanna_temperate { fill: #7c0; }
.biome-shrubland_temperate { fill: #7c0; }
.biome-grassland_tropical { fill: #7c0; }
.biome-savanna_tropical { fill: #7c0; }
.biome-shrubland_tropical { fill: #7c0; }
.biome-desert_badland { fill: #ff0; }
.biome-desert_rock { fill: #ff0; }
.biome-desert_sand { fill: #ff0; }
.biome-ocean_tropical { fill: #07c; }
.biome-ocean_temperate { fill: #07c; }
.biome-ocean_arctic { fill: #07c; }
.biome-pool_temperate_freshwater { fill: #07c; }
.biome-pool_temperate_brackishwater { fill: #07c; }
.biome-pool_temperate_saltwater { fill: #07c; }
.biome-pool_tropical_freshwater { fill: #07c; }
.biome-pool_tropical_brackishwater { fill: #07c; }
.biome-pool_tropical_saltwater { fill: #07c; }
.biome-lake_temperate_freshwater { fill: #07c; }
.biome-lake_temperate_brackishwater { fill: #07c; }
.biome-lake_temperate_saltwater { fill: #07c; }
.biome-lake_tropical_freshwater { fill: #07c; }
.biome-lake_tropical_brackishwater { fill: #07c; }
.biome-lake_tropical_saltwater { fill: #07c; }
.biome-river_temperate_freshwater { fill: #07c; }
.biome-river_temperate_brackishwater { fill: #07c; }
.biome-river_temperate_saltwater { fill: #07c; }
.biome-river_tropical_freshwater { fill: #07c; }
.biome-river_tropical_brackishwater { fill: #07c; }
.biome-river_tropical_saltwater { fill: #07c; }
.biome-mountain { fill: #808080; }
.biome-glacier { fill: #40ffff; }
.biome-tundra { fill: #80ffff; }
.biome-swamp_temperate_freshwater { fill: #60c080; }
.biome-swamp_temperate_saltwater { fill: #40c080; }
.biome-marsh_temperate_freshwater { fill: #60ff80; }
.biome-marsh_temperate_saltwater { fill: #40ff80; }
.biome-swamp_tropical_freshwater { fill: #60c040; }
.biome-swamp_tropical_saltwater { fill: #40c040; }
.biome-swamp_mangrove { fill: #40ff60; }
.biome-marsh_tropical_freshwater { fill: #60ff40; }
.biome-marsh_tropical_saltwater { fill: #40ff40; }
.biome-forest_taiga { fill: #006040; }
.biome-forest_temperate_conifer { fill: #006020; }
.biome-forest_temperate_broadleaf { fill: #00a020; }
.biome-forest_tropical_conifer { fill: #006000; }
.biome-forest_tropical_dry_broadleaf { fill: #008000; }
.biome-forest_tropical_moist_broadleaf { fill: #00a000; }
.biome-grassland_temperate { fill: #00ff20; }
.biome-savanna_temperate { fill: #00e020; }
.biome-shrubland_temperate { fill: #00c020; }
.biome-grassland_tropical { fill: #ffa000; }
.biome-savanna_tropical { fill: #ffb000; }
.biome-shrubland_tropical { fill: #ffc000; }
.biome-desert_badland { fill: #ff6020; }
.biome-desert_rock { fill: #ff8040; }
.biome-desert_sand { fill: #ffff00; }
.biome-ocean_tropical { fill: #0000ff; }
.biome-ocean_temperate { fill: #0080ff; }
.biome-ocean_arctic { fill: #00ffff; }
.biome-lake_temperate_freshwater { fill: #00e0ff; }
.biome-lake_temperate_brackishwater { fill: #00c0ff; }
.biome-lake_temperate_saltwater { fill: #00a0ff; }
.biome-lake_tropical_freshwater { fill: #0060ff; }
.biome-lake_tropical_brackishwater { fill: #0040ff; }
.biome-lake_tropical_saltwater { fill: #0020ff; }

@media (prefers-color-scheme: dark) {
html {
Expand Down
36 changes: 35 additions & 1 deletion helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ void simple_header_impl(Layout & l, T subject, bool sub = false)
categorize(title, subject, true, true);
}
l.set_title(title.str());
l.set_base_path(sub ? ".." : ".");
l.set_base_path(sub ? "../" : "./");

if (name.has_name)
{
Expand Down Expand Up @@ -1297,6 +1297,40 @@ void pagination(std::ostream & s, const std::string & base, const std::string &
}
}

std::string format_number(uint64_t number)
{
if (!number)
{
return "0";
}

// UINT64_MAX (for correct capacity)
char buf[] = "18,446,744,073,709,551,615";
// start pointing at null terminator
char *ptr = &buf[sizeof(buf) - 1];
while (number)
{
ptr--;
if (*ptr == ',')
{
ptr--;
}
*ptr = '0' + (number % 10);
number /= 10;
}

return ptr;
}

std::string format_number(int64_t number)
{
if (number < 0)
{
return "-" + format_number(uint64_t(-number));
}
return format_number(uint64_t(number));
}

void spheres(std::ostream & s, df::historical_figure *hf)
{
if (hf->info && hf->info->spheres && !hf->info->spheres->empty())
Expand Down
2 changes: 2 additions & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ bool history(std::ostream & s, const event_context & context, int32_t page, int3
void event(std::ostream & s, const event_context & context, df::history_event *event, int32_t & last_year, int32_t & last_seconds);
void event_reverse(std::ostream & s, const event_context & context, df::history_event *event);
void pagination(std::ostream & s, const std::string & base, const std::string & page_0, const std::string & page_prefix, int32_t current_page, int32_t last_page);
std::string format_number(uint64_t number);
std::string format_number(int64_t number);

void spheres(std::ostream & s, df::historical_figure *hf);
void year(std::ostream & s, int32_t year, int32_t tick);
Expand Down
8 changes: 8 additions & 0 deletions http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ bool WebLegends::request(weblegends_handler_v1 & response, const std::string & u
return true;
}

if (url == "/region.png")
{
void render_region_map(std::ostream & s);
response.headers()["Content-Type"] = "image/png";
render_region_map(response.raw_out());
return true;
}

size_t pos = url.find_first_of("/?", 1);

std::string prefix, rest;
Expand Down
Loading

0 comments on commit b5a8d44

Please sign in to comment.