Convert tilemap format in get_tile_data()

This commit is contained in:
Andrew Thomas 2017-12-09 10:44:26 -06:00
parent 5938466c84
commit c3a005011b
2 changed files with 11 additions and 9 deletions

View File

@ -968,14 +968,14 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
int c = p_data.size(); int c = p_data.size();
PoolVector<int>::Read r = p_data.read(); PoolVector<int>::Read r = p_data.read();
int offset = (format == FORMAT_2_1_5) ? 3 : 2; int offset = (format == FORMAT_2) ? 3 : 2;
clear(); clear();
for (int i = 0; i < c; i += offset) { for (int i = 0; i < c; i += offset) {
const uint8_t *ptr = (const uint8_t *)&r[i]; const uint8_t *ptr = (const uint8_t *)&r[i];
uint8_t local[12]; uint8_t local[12];
for (int j = 0; j < ((format == FORMAT_2_1_5) ? 12 : 8); j++) for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++)
local[j] = ptr[j]; local[j] = ptr[j];
#ifdef BIG_ENDIAN_ENABLED #ifdef BIG_ENDIAN_ENABLED
@ -985,7 +985,7 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
SWAP(local[4], local[7]); SWAP(local[4], local[7]);
SWAP(local[5], local[6]); SWAP(local[5], local[6]);
//TODO: ask someone to check this... //TODO: ask someone to check this...
if (FORMAT == FORMAT_2_1_5) { if (FORMAT == FORMAT_2) {
SWAP(local[8], local[11]); SWAP(local[8], local[11]);
SWAP(local[9], local[10]); SWAP(local[9], local[10]);
} }
@ -1000,7 +1000,7 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
v &= (1 << 29) - 1; v &= (1 << 29) - 1;
int16_t coord_x; int16_t coord_x;
int16_t coord_y; int16_t coord_y;
if (format == FORMAT_2_1_5) { if (format == FORMAT_2) {
coord_x = decode_uint16(&local[8]); coord_x = decode_uint16(&local[8]);
coord_y = decode_uint16(&local[10]); coord_y = decode_uint16(&local[10]);
} }
@ -1018,6 +1018,8 @@ PoolVector<int> TileMap::_get_tile_data() const {
data.resize(tile_map.size() * 3); data.resize(tile_map.size() * 3);
PoolVector<int>::Write w = data.write(); PoolVector<int>::Write w = data.write();
format = FORMAT_2;
int idx = 0; int idx = 0;
for (const Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { for (const Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
uint8_t *ptr = (uint8_t *)&w[idx]; uint8_t *ptr = (uint8_t *)&w[idx];
@ -1298,7 +1300,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
bool TileMap::_get(const StringName &p_name, Variant &r_ret) const { bool TileMap::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "format") { if (p_name == "format") {
r_ret = FORMAT_2_1_5; r_ret = FORMAT_2;
return true; return true;
} else if (p_name == "tile_data") { } else if (p_name == "tile_data") {
r_ret = _get_tile_data(); r_ret = _get_tile_data();
@ -1594,7 +1596,7 @@ TileMap::TileMap() {
y_sort_mode = false; y_sort_mode = false;
occluder_light_mask = 1; occluder_light_mask = 1;
clip_uv = false; clip_uv = false;
format = FORMAT_2_1_4; //Always initialize with the lowest format format = FORMAT_1; //Always initialize with the lowest format
fp_adjust = 0.00001; fp_adjust = 0.00001;
tile_origin = TILE_ORIGIN_TOP_LEFT; tile_origin = TILE_ORIGIN_TOP_LEFT;

View File

@ -61,8 +61,8 @@ public:
private: private:
enum DataFormat { enum DataFormat {
FORMAT_2_1_4 = 0, FORMAT_1 = 0,
FORMAT_2_1_5 FORMAT_2
}; };
Ref<TileSet> tile_set; Ref<TileSet> tile_set;
@ -178,7 +178,7 @@ private:
float bounce; float bounce;
uint32_t collision_layer; uint32_t collision_layer;
uint32_t collision_mask; uint32_t collision_mask;
DataFormat format; mutable DataFormat format;
TileOrigin tile_origin; TileOrigin tile_origin;