Add a TileProperty struct so one can store info about tiles.
This commit is contained in:
parent
5a8c3fcac0
commit
cb8654ac7e
6 changed files with 65 additions and 0 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <fstream>
|
||||
#include <ciso646>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
|
@ -47,6 +48,7 @@ namespace curry {
|
|||
//auto csv_parser = *((qi::int_ % ',') >> -qi::eol) >> qi::eoi;
|
||||
CSVJointData out_csv;
|
||||
std::size_t row_count = 0;
|
||||
TileIndex largest_tile_idx = 0;
|
||||
|
||||
for (auto& csv_path : parCsvPath) {
|
||||
std::ifstream f_map(csv_path);
|
||||
|
@ -66,6 +68,9 @@ namespace curry {
|
|||
oss << "Error parsing csv \"" << csv_path << "\"";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
if (not curr_data.empty()) {
|
||||
largest_tile_idx = std::max(*std::max_element(curr_data.begin(), curr_data.end()), largest_tile_idx);
|
||||
}
|
||||
out_csv.tables.emplace_back(std::move(curr_data));
|
||||
}
|
||||
|
||||
|
@ -76,6 +81,17 @@ namespace curry {
|
|||
else {
|
||||
out_csv.height = out_csv.width = 0;
|
||||
}
|
||||
|
||||
out_csv.tile_properties.resize(static_cast<size_t>(largest_tile_idx) + 1);
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
for (const auto& table : out_csv.tables) {
|
||||
for (const auto& val : table) {
|
||||
const auto casted_val = static_cast<size_t>(val);
|
||||
assert(val < 0 or casted_val < out_csv.tile_properties.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return out_csv;
|
||||
}
|
||||
} //namespace curry
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "tileindextype.hpp"
|
||||
#include "tileproperty.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
@ -31,6 +32,7 @@ namespace curry {
|
|||
CSVJointData (const CSVJointData&) = delete;
|
||||
|
||||
std::vector<std::vector<TileIndex>> tables;
|
||||
std::vector<TileProperty> tile_properties; //not filled in with real values
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
};
|
||||
|
|
|
@ -85,6 +85,7 @@ namespace curry {
|
|||
|
||||
vec2us world_size(tiles.width, tiles.height);
|
||||
m_local_data->world.set_layers(world_size, tiles.tables);
|
||||
m_local_data->world.set_tile_properties(tiles.tile_properties);
|
||||
#if !defined(NDEBUG)
|
||||
std::cout << "World size set to " << world_size << '\n';
|
||||
#endif
|
||||
|
|
31
src/tileproperty.hpp
Normal file
31
src/tileproperty.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright 2016, 2017 Michele "King_DuckZ" Santullo
|
||||
|
||||
This file is part of MyCurry.
|
||||
|
||||
MyCurry is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
MyCurry is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with MyCurry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace curry {
|
||||
struct TileProperty {
|
||||
TileProperty() :
|
||||
walkable(true)
|
||||
{
|
||||
}
|
||||
|
||||
bool walkable;
|
||||
};
|
||||
} //namespace curry
|
|
@ -118,6 +118,17 @@ namespace curry {
|
|||
m_world_size_watchers.Remove(parTicket);
|
||||
}
|
||||
|
||||
void WorldGrid::set_tile_properties (const std::vector<TileProperty>& parProperties) {
|
||||
m_tile_properties.resize(parProperties.size());
|
||||
std::copy(parProperties.begin(), parProperties.end(), m_tile_properties.begin());
|
||||
}
|
||||
|
||||
const TileProperty& WorldGrid::tile_property (const TileIndex* parIndex) {
|
||||
assert(parIndex);
|
||||
assert(static_cast<size_t>(*parIndex) < m_tile_properties.size());
|
||||
return m_tile_properties[static_cast<size_t>(*parIndex)];
|
||||
}
|
||||
|
||||
vec2i world_size_pixel (const WorldGrid& parWorld) {
|
||||
return parWorld.tile_size() * parWorld.world_size();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "vector.hpp"
|
||||
#include "tileindextype.hpp"
|
||||
#include "observersmanager.hpp"
|
||||
#include "tileproperty.hpp"
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -40,6 +41,8 @@ namespace curry {
|
|||
const TileIndex* tile (const vec2us& parIndex) const;
|
||||
void add_layer (vec2us parWorldSize, const std::vector<TileIndex>& parLayer);
|
||||
void set_layers (vec2us parWorldSize, const std::vector<std::vector<TileIndex>>& parLayers);
|
||||
void set_tile_properties (const std::vector<TileProperty>& parProperties);
|
||||
const TileProperty& tile_property (const TileIndex* parIndex);
|
||||
void unload_layers();
|
||||
WorldSizeWatcherTicket register_observer (WorldSizeNotifiable* parWatcher);
|
||||
void unregister_observer (WorldSizeWatcherTicket parTicket);
|
||||
|
@ -51,6 +54,7 @@ namespace curry {
|
|||
|
||||
cloonel::ObserversManager<WorldSizeNotifiable*> m_world_size_watchers;
|
||||
std::vector<TileIndex> m_layers;
|
||||
std::vector<TileProperty> m_tile_properties;
|
||||
vec2us m_tile_size;
|
||||
vec2us m_world_size;
|
||||
uint16_t m_layer_count;
|
||||
|
|
Loading…
Reference in a new issue