diff --git a/.mailmap b/.mailmap index dd04a90071..38c0988cfd 100644 --- a/.mailmap +++ b/.mailmap @@ -10,3 +10,4 @@ Jonathan Remnant Henry Snoek coop shell (Michael Enßlin, Jonas Jelten, Andre Kupka) Franz-Niclas Muschter +Jens Feodor Nielsen diff --git a/assets/shaders/minimap.frag.glsl b/assets/shaders/minimap.frag.glsl new file mode 100644 index 0000000000..c26f961755 --- /dev/null +++ b/assets/shaders/minimap.frag.glsl @@ -0,0 +1,20 @@ +#version 120 + +uniform ivec2 minimap_orig; +uniform ivec2 minimap_size; + +varying vec4 out_vertex_position; +varying vec3 out_color; + +void main(void) { + ivec2 center = ivec2(minimap_size.x/2, minimap_size.y/2); + ivec2 vpos = minimap_orig + center - ivec2(out_vertex_position.x, out_vertex_position.y); + vec3 color; + + if (!(abs(vpos.x) * center.y + abs(vpos.y) * center.x <= center.x * center.y)) + discard; + else + color = out_color; + + gl_FragColor = vec4(color, 1.0); +} diff --git a/assets/shaders/minimap.vert.glsl b/assets/shaders/minimap.vert.glsl new file mode 100644 index 0000000000..6a0c80bb6e --- /dev/null +++ b/assets/shaders/minimap.vert.glsl @@ -0,0 +1,13 @@ +#version 120 + +attribute vec4 vertex_position; +attribute vec3 color; + +varying vec4 out_vertex_position; +varying vec3 out_color; + +void main() { + out_vertex_position = vertex_position; + out_color = color; + gl_Position = gl_ModelViewProjectionMatrix * vertex_position; +} diff --git a/libopenage/CMakeLists.txt b/libopenage/CMakeLists.txt index bfbf0b0bd8..efc68a85eb 100644 --- a/libopenage/CMakeLists.txt +++ b/libopenage/CMakeLists.txt @@ -23,7 +23,7 @@ add_sources(libopenage player.cpp screenshot.cpp texture.cpp - + minimap.cpp config.cpp ) diff --git a/libopenage/game_main.cpp b/libopenage/game_main.cpp index 0297441549..a3069889a1 100644 --- a/libopenage/game_main.cpp +++ b/libopenage/game_main.cpp @@ -3,6 +3,8 @@ #include "game_main.h" #include "game_spec.h" #include "generator.h" +#include "engine.h" +#include "minimap.h" namespace openage { diff --git a/libopenage/game_renderer.cpp b/libopenage/game_renderer.cpp index 5b5294c233..c1eb65521e 100644 --- a/libopenage/game_renderer.cpp +++ b/libopenage/game_renderer.cpp @@ -51,7 +51,7 @@ GameRenderer::GameRenderer(openage::Engine *e) // load textures and stuff gaben = new Texture{data_dir->join("gaben.png")}; - std::vector player_color_lines; + std::vector player_color_lines, general_color_lines; util::read_csv_file(asset_dir.join("player_palette.docx"), player_color_lines); GLfloat *playercolors = new GLfloat[player_color_lines.size() * 4]; @@ -91,6 +91,15 @@ GameRenderer::GameRenderer(openage::Engine *e) auto alphamask_frag = new shader::Shader(GL_FRAGMENT_SHADER, alphamask_frag_code); delete[] alphamask_frag_code; + char *minimap_vert_code; + util::read_whole_file(&minimap_vert_code, data_dir->join("shaders/minimap.vert.glsl")); + auto minimap_vert = new shader::Shader(GL_VERTEX_SHADER, minimap_vert_code); + delete[] minimap_vert_code; + + char *minimap_frag_code; + util::read_whole_file(&minimap_frag_code, data_dir->join("shaders/minimap.frag.glsl")); + auto minimap_frag = new shader::Shader(GL_FRAGMENT_SHADER, minimap_frag_code); + delete[] minimap_frag_code; // create program for rendering simple textures @@ -134,12 +143,23 @@ GameRenderer::GameRenderer(openage::Engine *e) glUniform1i(alphamask_shader::mask_texture, 1); alphamask_shader::program->stopusing(); + + // create program for rendering within the minimap + minimap_shader::program = new shader::Program(minimap_vert, minimap_frag); + minimap_shader::program->link(); + minimap_shader::size = minimap_shader::program->get_uniform_id("minimap_size"); + minimap_shader::orig = minimap_shader::program->get_uniform_id("minimap_orig"); + minimap_shader::color = minimap_shader::program->get_attribute_id("color"); + + // after linking, the shaders are no longer necessary delete plaintexture_vert; delete plaintexture_frag; delete teamcolor_frag; delete alphamask_vert; delete alphamask_frag; + delete minimap_vert; + delete minimap_frag; // Renderer keybinds // TODO: a renderer settings struct @@ -165,6 +185,7 @@ GameRenderer::~GameRenderer() { delete texture_shader::program; delete teamcolor_shader::program; delete alphamask_shader::program; + delete minimap_shader::program; } bool GameRenderer::on_draw() { diff --git a/libopenage/game_renderer.h b/libopenage/game_renderer.h index 7a22931f8b..47d7ae3f7a 100644 --- a/libopenage/game_renderer.h +++ b/libopenage/game_renderer.h @@ -15,7 +15,13 @@ #include "options.h" #include "player.h" +#include "minimap.h" + namespace openage { +/* namespace minimap_shader { */ +/* extern shader::Program *program; */ +/* extern GLint size, orig, color; */ +/* } */ /** diff --git a/libopenage/game_spec.cpp b/libopenage/game_spec.cpp index 2bdd452c5d..356ffafbba 100644 --- a/libopenage/game_spec.cpp +++ b/libopenage/game_spec.cpp @@ -328,6 +328,9 @@ void GameSpec::load_terrain(AssetManager &am) { terrain_data.blending_masks.reserve(terrain_data.blendmode_count); terrain_data.terrain_id_priority_map = std::make_unique(terrain_data.terrain_id_count); terrain_data.terrain_id_blendmode_map = std::make_unique(terrain_data.terrain_id_count); + terrain_data.terrain_id_map_color_hi_map = std::make_unique(terrain_data.terrain_id_count); + terrain_data.terrain_id_map_color_med_map = std::make_unique(terrain_data.terrain_id_count); + terrain_data.terrain_id_map_color_low_map = std::make_unique(terrain_data.terrain_id_count); terrain_data.influences_buf = std::make_unique(terrain_data.terrain_id_count); @@ -345,6 +348,9 @@ void GameSpec::load_terrain(AssetManager &am) { // TODO: terrain double-define check? terrain_data.terrain_id_priority_map[terrain_id] = line->blend_priority; terrain_data.terrain_id_blendmode_map[terrain_id] = line->blend_mode; + terrain_data.terrain_id_map_color_hi_map[terrain_id] = line->map_color_hi; + terrain_data.terrain_id_map_color_med_map[terrain_id] = line->map_color_med; + terrain_data.terrain_id_map_color_low_map[terrain_id] = line->map_color_low; // TODO: remove hardcoding and rely on nyan data auto terraintex_filename = util::sformat("%s/%d.slp.png", this->terrain_path.c_str(), line->slp_id); diff --git a/libopenage/main.cpp b/libopenage/main.cpp index 99c598ee7b..88d59ee32d 100644 --- a/libopenage/main.cpp +++ b/libopenage/main.cpp @@ -42,6 +42,8 @@ int run_game(const main_arguments &args) { GameRenderer renderer{&engine}; GameControl control{&engine}; Generator generator{&engine}; + Minimap minimap = Minimap(coord::camhud_delta{200, 100}, coord::camhud{5, 5}); + engine.register_drawhud_action(&minimap); log::log(MSG(info).fmt("Loading time [game]: %5.3f s", timer.getval() / 1.0e9)); diff --git a/libopenage/minimap.cpp b/libopenage/minimap.cpp new file mode 100644 index 0000000000..7242d8f0ae --- /dev/null +++ b/libopenage/minimap.cpp @@ -0,0 +1,336 @@ +// Copyright 2013-2015 the openage authors. See copying.md for legal info. + +#include "minimap.h" + +#include + +#include "log/log.h" +#include "coord/window.h" +#include "coord/chunk.h" +#include "terrain/terrain.h" +#include "unit/unit.h" + +#include "player.h" +#include "engine.h" + + +namespace openage { +namespace minimap_shader { +shader::Program *program; +GLint size, orig, color; +} // namespace minimap_shader + + +Minimap::Minimap(coord::camhud_delta size, coord::camhud hudpos) + : + size(size), + hudpos(hudpos) { + + // Initial update to setup the minimap resolution, etc + // TODO: Change this + this->set_mapping(coord::chunk{-1, -1}, 3); + + // Setup minimap dimensions for rendering + this->left = this->hudpos.x; + this->right = this->hudpos.x + this->size.x; + this->bottom = this->hudpos.y; + this->top = this->hudpos.y + this->size.y; + this->center_vertical = (float)(this->bottom + this->top) / 2; + this->center_horizontal = (float)(this->left + this->right) / 2; + + // TODO: this could be gotten from game_renderer? + util::Dir *data_dir = Engine::get().get_data_dir(); + util::Dir asset_dir = data_dir->append("converted"); + util::read_csv_file(asset_dir.join("player_palette.docx"), this->player_palette); + util::read_csv_file(asset_dir.join("general_palette.docx"), this->palette); + + glGenBuffers(1, &this->terrain_vertbuf); + glGenBuffers(1, &this->view_vertbuf); + glGenBuffers(1, &this->unit_vertbuf); + + // Generate minimap terrain texture + glGenTextures(1, &this->terrain_tex); + glBindTexture(GL_TEXTURE_2D, this->terrain_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glBindTexture(GL_TEXTURE_2D, 0); + + minimap_shader::program->use(); + glUniform2i(minimap_shader::orig, (GLint)this->left, (GLint)this->bottom); + glUniform2i(minimap_shader::size, (GLint)this->size.x, (GLint)this->size.y); + minimap_shader::program->stopusing(); +} + + +Minimap::~Minimap() {} + + +void Minimap::auto_mapping() { + GameMain *game = Engine::get().get_game(); + if (game == nullptr) { + return; + } + std::vector used = game->terrain->used_chunks(); + coord::chunk ne_least, ne_most, se_least, se_most; + ne_least = ne_most = se_least = se_most = {0, 0}; + + for (coord::chunk c : used) { + if (c.ne < ne_least.ne) ne_least = c; + if (c.se < se_least.se) se_least = c; + if (c.ne > ne_most.ne) ne_most = c; + if (c.se > se_most.se) se_most = c; + } + + int ne_res = ne_most.ne - ne_least.ne; + int se_res = se_most.se - se_least.se; + + if (ne_res < se_res) { + this->set_mapping({ne_least.ne, se_least.se}, se_res + 1); + } else { + this->set_mapping({ne_least.ne, se_least.se}, ne_res + 1); + } +} + + +void Minimap::set_mapping(coord::chunk west, int resolution) { + if (resolution < 1) { + resolution = 1; + } + this->resolution = resolution * 16; + this->west = west; + this->east = west + coord::chunk_delta{resolution - 1, resolution - 1}; + this->north = west + coord::chunk_delta{resolution - 1, 0}; + this->south = west + coord::chunk_delta{0, resolution - 1}; + + coord::camhud_delta north_rel = this->north.to_tile({16, 0}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + coord::camhud_delta east_rel = this->east.to_tile({16, 16}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + coord::camhud_delta south_rel = this->south.to_tile({0, 16}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + coord::camhud_delta west_rel = this->west.to_tile({0, 0}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + + this->ratio_horizontal = (float)this->size.x / (float)(east_rel.x - west_rel.x); + this->ratio_vertical = (float)this->size.y / (float)(north_rel.y - south_rel.y); +} + + +void Minimap::generate_background() { + GameMain *game = Engine::get().get_game(); + if (game == nullptr) { + return; + } + std::shared_ptr &terrain = game->terrain; + // Generate terrain texture + uint8_t *pixels = new uint8_t[this->resolution * this->resolution * 3]; + for (int i = 0; i < this->resolution; i++){ + for (int j = 0; j < this->resolution; j++) { + coord::tile tile_pos{i + this->west.ne * 16, j + this->west.se * 16}; + TileContent *tile_data = terrain->get_data(tile_pos); + + if (tile_data == nullptr) { + pixels[i * this->resolution * 3 + j * 3 + 0] = 0; + pixels[i * this->resolution * 3 + j * 3 + 1] = 0; + pixels[i * this->resolution * 3 + j * 3 + 2] = 0; + } else { + uint8_t pal_idx = terrain->map_color_hi(tile_data->terrain_id); + gamedata::palette_color hi_color = this->palette[pal_idx]; + pixels[i * this->resolution * 3 + j * 3 + 0] = hi_color.r; + pixels[i * this->resolution * 3 + j * 3 + 1] = hi_color.g; + pixels[i * this->resolution * 3 + j * 3 + 2] = hi_color.b; + } + } + } + + glBindTexture(GL_TEXTURE_2D, this->terrain_tex); + + glTexImage2D( + GL_TEXTURE_2D, 0, + GL_RGB, this->resolution, this->resolution, 0, + GL_RGB, GL_UNSIGNED_BYTE, pixels + ); + + delete pixels; +} + + +coord::camhud Minimap::from_phys(coord::phys3 coord) { + coord::camhud_delta west_rel = this->west.to_tile({0, 0}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + coord::camhud_delta coord_rel = coord.to_camgame().to_window().to_camhud().as_relative() - west_rel; + coord_rel.x = coord_rel.x * this->ratio_horizontal; + coord_rel.y = coord_rel.y * this->ratio_vertical; + + return (coord_rel + coord::camhud{(coord::pixel_t)this->left, (coord::pixel_t)this->center_vertical}); +} + + +coord::phys3 Minimap::to_phys(coord::camhud coord) { + coord::camhud_delta coord_rel{(coord::pixel_t)((float)(coord.x - (coord::pixel_t)this->left)/this->ratio_horizontal), + (coord::pixel_t)((float)(coord.y - (coord::pixel_t)this->center_vertical)/this->ratio_vertical)}; + coord::camhud_delta west_rel = this->west.to_tile({0, 0}).to_tile3(0).to_phys3({0, 0, 0}).to_camgame().to_window().to_camhud().as_relative(); + return (coord_rel + west_rel).as_absolute().to_window().to_camgame().to_phys3();; +} + + +bool Minimap::is_within(coord::camhud coord) { + coord::camhud_delta center = this->size/2; + coord::camhud rel = this->hudpos + center - coord.as_relative(); + + if (abs(rel.x) * center.y + abs(rel.y) * center.x <= center.x * center.y) + return true; + else + return false; +} + + +void Minimap::draw_unit(Unit *unit) { + int *color, *pos_id; + minimap_shader::program->use(); + color = &minimap_shader::color; + pos_id = &minimap_shader::program->pos_id; + + coord::camhud unit_pos = this->from_phys(unit->location.get()->pos.draw); + + // player color + GLfloat rgb[3]; + rgb[0] = 0.0; rgb[1] = 0.0; rgb[2] = 0.0; + + // TODO: fix resource colors + if (unit->selected) { + rgb[0] = 1.0; rgb[1] = 1.0; rgb[2] = 1.0; + } else if (unit->has_attribute(attr_type::resource)) { + return; // ignore resources + } else if (unit->has_attribute(attr_type::owner)) { + int player_color_index = (unit->get_attribute().player.color - 1) * 8; + gamedata::palette_color player_color = this->player_palette[player_color_index]; + rgb[0] = player_color.r; rgb[1] = player_color.g; rgb[2] = player_color.b; + } + + GLfloat unit_vdata[] { + (GLfloat)unit_pos.x, (GLfloat)unit_pos.y, + rgb[0], rgb[1], rgb[2] + }; + + glBindBuffer(GL_ARRAY_BUFFER, this->view_vertbuf); + glVertexAttribPointer(*pos_id, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0); + glEnableVertexAttribArray(*pos_id); + glVertexAttribPointer(*color, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)(2*sizeof(GLfloat))); + glEnableVertexAttribArray(*color); + + glPointSize(4); + glBufferData(GL_ARRAY_BUFFER, sizeof(unit_vdata), unit_vdata, GL_STATIC_DRAW); + glDrawArrays(GL_POINTS, 0, 1); + + // unbind buffer + glBindBuffer(GL_ARRAY_BUFFER, 0); + + minimap_shader::program->stopusing(); +} + + +bool Minimap::on_drawhud() { + Engine &engine = Engine::get(); + + if (engine.get_game() == nullptr) { + return true; + } + + this->generate_background(); + GLint terrain_vdata[] { + // vertices + this->left, this->center_vertical, + this->center_horizontal, this->top, + this->right, this->center_vertical, + this->center_horizontal, this->bottom, + // tex coords + 0, 0, + 0, 1, + 1, 1, + 1, 0 + }; + + int *pos_id, *tex_coord; + + glBindTexture(GL_TEXTURE_2D, this->terrain_tex); + texture_shader::program->use(); + pos_id = &texture_shader::program->pos_id; + tex_coord = &texture_shader::tex_coord; + + // store vertex buffer data, TODO: prepare this sometime earlier. + glBindBuffer(GL_ARRAY_BUFFER, this->terrain_vertbuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(terrain_vdata), terrain_vdata, GL_STATIC_DRAW); + glVertexAttribPointer(*pos_id, 2, GL_INT, GL_FALSE, 2 * sizeof(GLint), (GLvoid*)0); + glEnableVertexAttribArray(*pos_id); + glVertexAttribPointer(*tex_coord, 2, GL_INT, GL_FALSE, 2 * sizeof(GLint), (GLvoid*)(8*sizeof(GLint))); + glEnableVertexAttribArray(*tex_coord); + + // draw the vertex array + glDrawArrays(GL_QUADS, 0, 4); + + // unbind the current buffer + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + texture_shader::program->stopusing(); + + coord::window view_size{(coord::pixel_t)(engine.get_coord_data()->window_size.x / 2 * this->ratio_horizontal), + (coord::pixel_t)(engine.get_coord_data()->window_size.y / 2 * this->ratio_vertical)}; + coord::camhud view = this->from_phys(engine.get_coord_data()->camgame_phys); + + // Draw units + std::vector units = engine.get_game()->placed_units.all_units(); + for (Unit *u : units) { + this->draw_unit(u); + } + + // Draw minimap view box + int *color; + minimap_shader::program->use(); + color = &minimap_shader::color; + pos_id = &minimap_shader::program->pos_id; + + GLint view_bg_vdata[] { + // black border + view.x + view_size.x + 1, view.y + view_size.y - 1, + view.x - view_size.x + 1, view.y + view_size.y - 1, + view.x - view_size.x + 1, view.y - view_size.y - 1, + view.x + view_size.x + 1, view.y - view_size.y - 1, + // colors + 0, 0, 0, + 0, 0, 0, + 0, 0, 0, + 0, 0, 0, + }; + + GLint view_fg_vdata[] { + // white border + view.x + view_size.x, view.y + view_size.y, + view.x - view_size.x, view.y + view_size.y, + view.x - view_size.x, view.y - view_size.y, + view.x + view_size.x, view.y - view_size.y, + // colors + 1, 1, 1, + 1, 1, 1, + 1, 1, 1, + 1, 1, 1, + }; + + glBindBuffer(GL_ARRAY_BUFFER, this->view_vertbuf); + glVertexAttribPointer(*pos_id, 2, GL_INT, GL_FALSE, 2 * sizeof(GLint), (GLvoid*)0); + glEnableVertexAttribArray(*pos_id); + glVertexAttribPointer(*color, 3, GL_INT, GL_FALSE, 3 * sizeof(GLint), (GLvoid*)(8*sizeof(GLint))); + glEnableVertexAttribArray(*color); + + glLineWidth(1); + glBufferData(GL_ARRAY_BUFFER, sizeof(view_bg_vdata), view_bg_vdata, GL_STATIC_DRAW); + glDrawArrays(GL_LINE_LOOP, 0, 4); + glBufferData(GL_ARRAY_BUFFER, sizeof(view_fg_vdata), view_fg_vdata, GL_STATIC_DRAW); + glDrawArrays(GL_LINE_LOOP, 0, 4); + + // unbind view box buffer + glBindBuffer(GL_ARRAY_BUFFER, 0); + minimap_shader::program->stopusing(); + + return true; +} + + +} // namespace openage diff --git a/libopenage/minimap.h b/libopenage/minimap.h new file mode 100644 index 0000000000..6c812ebf73 --- /dev/null +++ b/libopenage/minimap.h @@ -0,0 +1,112 @@ +// Copyright 2013-2015 the openage authors. See copying.md for legal info. + +#ifndef OPENAGE_MINIMAP_H_ +#define OPENAGE_MINIMAP_H_ + +#include "epoxy/gl.h" +#include +#include + +#include "handlers.h" + +#include "shader/program.h" +#include "coord/camhud.h" +#include "coord/chunk.h" +#include "gamedata/color.gen.h" + + +namespace openage { +namespace minimap_shader { +extern shader::Program *program; +extern GLint size, orig, color; +} // namespace minimap_shader +namespace texture_shader { +extern shader::Program *program; +} + +class Unit; + +/** + * Implements a minimap, as a HudHandler. + * + * Supports dynamic terrain sizes, changing terrain, and displays units. + */ +class Minimap: public HudHandler { +public: + /** + * Creates the minimap. + */ + Minimap(coord::camhud_delta size, coord::camhud hudpos); + ~Minimap(); + + bool on_drawhud() override; + void draw_unit(Unit *unit); + void generate_background(); + + /** + * Updates various variables crucial to the function of the minimap, including + * the minimap resolution and the minimap corner position. + */ + void auto_mapping(); + void set_mapping(coord::chunk, int resolution); + + /** + * Converts a phys3 coordinate to a camhud coordinate, that corresponds to the + * given position on the minimap. + * + * @param coord: The phys3 coordinate to be converted. + * @returns The given coordinate position in minimap camhud. + */ + coord::camhud from_phys(coord::phys3 coord); + + /** + * Converts a camhud coordinate to a phys3 coordinate, assuming that the + * camhud coordinate refers to a position on the minimap. + * + * @param coord: The minimap camhud coordinate to be converted. + * @returns The given coordinate position in phys3. + */ + coord::phys3 to_phys(coord::camhud coord); + + /** + * Check if a camhud coordinate is within the drawing area of the minimap. + * + * @param coord: The camhud coordinate to be checked. + * @returns True if the coordinate is within the minimap. + */ + bool is_within(coord::camhud coord); + +private: + coord::camhud_delta size; + coord::camhud hudpos; + std::vector palette, player_palette; + + GLint left, right, bottom, top, center_vertical, center_horizontal; + coord::chunk north, east, south, west; + GLuint terrain_vertbuf; + GLuint terrain_tex; + GLuint view_vertbuf; + GLuint unit_vertbuf; + + /** + * The ratio of distance between eastern and western minimap corners + * (NOT terrain corners!) in camhud game to camhud minimap. + */ + float ratio_horizontal; + + /** + * The ratio of distance between nortern and southern minimap corners + * (NOT terrain corners!) in camhud game to camhud minimap. + */ + float ratio_vertical; + + /** + * The minimap side length in tiles + */ + int resolution; +}; + + +} // namespace openage + +#endif diff --git a/libopenage/terrain/terrain.cpp b/libopenage/terrain/terrain.cpp index 6eeaf5f59d..a0d5d5daea 100644 --- a/libopenage/terrain/terrain.cpp +++ b/libopenage/terrain/terrain.cpp @@ -39,7 +39,6 @@ Terrain::Terrain(terrain_meta *meta, bool is_infinite) // maps chunk position to chunks this->chunks = std::unordered_map{}; - } Terrain::~Terrain() { @@ -190,6 +189,21 @@ int Terrain::blendmode(terrain_t terrain_id) { return this->meta->terrain_id_blendmode_map[terrain_id]; } +uint8_t Terrain::map_color_hi(terrain_t terrain_id) { + this->validate_terrain(terrain_id); + return this->meta->terrain_id_map_color_hi_map[terrain_id]; +} + +uint8_t Terrain::map_color_med(terrain_t terrain_id) { + this->validate_terrain(terrain_id); + return this->meta->terrain_id_map_color_med_map[terrain_id]; +} + +uint8_t Terrain::map_color_low(terrain_t terrain_id) { + this->validate_terrain(terrain_id); + return this->meta->terrain_id_map_color_low_map[terrain_id]; +} + Texture *Terrain::texture(terrain_t terrain_id) { this->validate_terrain(terrain_id); return this->meta->textures[terrain_id]; diff --git a/libopenage/terrain/terrain.h b/libopenage/terrain/terrain.h index 68dae130a5..2759e16166 100644 --- a/libopenage/terrain/terrain.h +++ b/libopenage/terrain/terrain.h @@ -13,8 +13,8 @@ #include "terrain_chunk.h" #include "terrain_object.h" #include "../assetmanager.h" -#include "../game_renderer.h" #include "../texture.h" +#include "../game_renderer.h" #include "../coord/camgame.h" #include "../coord/chunk.h" #include "../util/dir.h" @@ -162,6 +162,10 @@ struct terrain_meta { std::unique_ptr terrain_id_priority_map; std::unique_ptr terrain_id_blendmode_map; + std::unique_ptr terrain_id_map_color_hi_map; + std::unique_ptr terrain_id_map_color_med_map; + std::unique_ptr terrain_id_map_color_low_map; + std::unique_ptr influences_buf; }; @@ -307,6 +311,22 @@ class Terrain { */ int blendmode(terrain_t terrain_id); + /** + * get the red color component for a given terrain id. + */ + uint8_t map_color_hi(terrain_t terrain_id); + + /** + * get the red color component for a given terrain id. + */ + uint8_t map_color_med(terrain_t terrain_id); + + /** + * get the red color component for a given terrain id. + */ + uint8_t map_color_low(terrain_t terrain_id); + + /** * get the terrain texture for a given terrain id. */ @@ -397,7 +417,6 @@ class Terrain { * maps chunk coordinates to chunks. */ std::unordered_map chunks; - }; } // namespace openage diff --git a/openage/convert/driver.py b/openage/convert/driver.py index 2d570a67d5..a7359fedc4 100644 --- a/openage/convert/driver.py +++ b/openage/convert/driver.py @@ -150,6 +150,9 @@ def convert_metadata(args): termcolortable = ColorTable(URXVTCOLS) data_formatter.add_data(termcolortable.dump("termcolors")) + yield "general color palette" + data_formatter.add_data(palette.dump("general_palette")) + yield "string resources" stringres = get_string_resources(args.srcdir) data_formatter.add_data(stringres.dump("string_resources"))