Commit 9fafe10d authored by frankie's avatar frankie 💬

int to uint32_t everywhere possible to ensure data consistency in cache and mesh

parent 88870406
......@@ -505,7 +505,7 @@ void SkinMesh::skinify() {
// std::cout << nindex << std::endl;
for (int i = 0; i < imax; ++i) {
std::vector<int>& eindices = _face_edges[nf.faces[i]];
ss_unique_vec& eindices = _face_edges[nf.faces[i]];
two_edge te;
for (int j = 0, jmax = eindices.size(); j < jmax; ++j) {
edge_ref& ef = _unique_edges[ eindices[j] ];
......@@ -524,7 +524,7 @@ void SkinMesh::skinify() {
if (te.edge0 != -1 && te.edge1 != -1) {
// swapping the edge to match CULL_BACK
std::vector<int>& indices = _face_all_verts[nf.faces[i]];
ss_unique_vec& indices = _face_all_verts[nf.faces[i]];
// where is the current index in the list?
int p = 0;
if (indices[1] == nindex) {
......@@ -600,8 +600,8 @@ void SkinMesh::skinify() {
// }
// }
// std::map<int, std::vector<int> >::iterator fi = _face_edges.begin();
// std::map<int, std::vector<int> >::iterator fe = _face_edges.end();
// ss_face_map::iterator fi = _face_edges.begin();
// ss_face_map::iterator fe = _face_edges.end();
// for (; fi != fe; ++fi) {
// std::cout << "face " << fi->first << ":" << std::endl;
// for (int i = 0; i < fi->second.size(); ++i) {
......
......@@ -354,11 +354,11 @@ private:
// temporary data, purged at the end of skinify()
PoolVector<Vector3> _all_vertices;
PoolVector<Vector3> _all_normals;
std::map<int, int> _all2unique;
ss_unique_map _all2unique;
std::vector<v3_ref> _unique_vertices;
std::vector<edge_ref> _unique_edges;
std::map<int, std::vector<int> > _face_all_verts;
std::map<int, std::vector<int> > _face_edges;
ss_face_map _face_all_verts;
ss_face_map _face_edges;
std::vector< normal_ref > _unique_normals;
// data
......
......@@ -271,7 +271,7 @@ void Softskin::generate_skinmesh() {
// let's generate the hell of a memory
PoolVector<Vector3>& _all_vertices = ca->_surfaces[SURF_ID]->verts;
PoolVector<Vector3>& _all_normals = ca->_surfaces[SURF_ID]->normals;
std::map<int, int>& _all2unique = ca->_all2unique;
ss_unique_map& _all2unique = ca->_all2unique;
std::vector<v3_ref>& _unique_vertices = ca->_unique_dots;
std::vector<edge_ref>& _unique_edges = ca->_unique_fibers;
std::vector< normal_ref >& _unique_normals = ca->_unique_normals;
......@@ -326,7 +326,7 @@ void Softskin::generate_skinmesh() {
for (uint32_t i = 0; i < _data.normals_num; ++i) {
normal_ref& nr = _unique_normals[i];
if (nr.dot_id == -1) {
if (nr.dot_id == UINT_MAX) {
std::cout << "WOW! too bad, this will explode!" << std::endl;
continue;
}
......@@ -342,7 +342,7 @@ void Softskin::generate_skinmesh() {
for (; it2e != it2ee; ++it2e) {
two_edge& te = (*it2e);
if (te.buffer_id == -1) {
if (te.buffer_id == UINT_MAX) {
std::cout << "BOOM!" << std::endl;
continue;
}
......
This diff is collapsed.
......@@ -52,7 +52,7 @@ public:
};
// analysis
std::map<int, int> _all2unique;
ss_unique_map _all2unique;
std::vector<v3_ref> _unique_dots;
std::vector<v3_ref> _unique_anchors;
std::vector<edge_ref> _unique_fibers;
......@@ -64,8 +64,8 @@ public:
std::vector<group_ref> _groups;
// no need to save, temporary data!
std::map<int, std::vector<int> > _face_all_verts;
std::map<int, std::vector<int> > _face_fibers;
ss_face_map _face_all_verts;
ss_face_map _face_fibers;
// mesh surfaces data
std::vector<MeshArray*> _surfaces;
......@@ -117,7 +117,7 @@ protected:
void save_unique_anchors(FileAccess* f);
void save_unique_fibers(FileAccess* f);
void save_unique_ligaments(FileAccess* f);
void save_face_map(FileAccess* f, std::map<int, std::vector<int> >&);
void save_face_map(FileAccess* f, ss_face_map&);
void save_unique_normals(FileAccess* f);
void save_anchors(FileAccess* f);
void save_groups(FileAccess* f);
......@@ -129,7 +129,7 @@ protected:
bool load_unique_anchors(FileAccess* f);
bool load_unique_fibers(FileAccess* f);
bool load_unique_ligaments(FileAccess* f);
bool load_face_map(FileAccess* f, std::map<int, std::vector<int> >&);
bool load_face_map(FileAccess* f, ss_face_map&);
bool load_unique_normals(FileAccess* f);
bool load_anchors(FileAccess* f);
bool load_groups(FileAccess* f);
......
......@@ -47,6 +47,7 @@
#define SOFTSKINCOMMON_H
#include <iostream>
#include <climits>
#include <limits>
#include <vector>
#include <map>
......@@ -129,57 +130,84 @@
#define __ss_int32_size sizeof(int32_t)
#define __ss_str_size 255
typedef std::map<uint32_t, uint32_t> ss_unique_map;
typedef std::vector<uint32_t> ss_unique_vec;
typedef std::map<uint32_t, std::vector<uint32_t> > ss_face_map;
enum softskin_type_t {
sf_UNDEFINED = 0, // the name is explicit: undefined type
sf_DOT = 1, // used to flag objects related to SkinDot
sf_ANCHOR = 2, // used to flag objects related to SkinAnchor
sf_EDGE = 3, // edge default type, connecting 2 dots
sf_FIBER = 4, // edge connecting 2 dots, passive behaviour
sf_TENSOR = 5, // edge connecting 2 dots, able to contract
sf_LIGAMENT = 6, // edge connecting 1 dots to 1 anchor, passive behaviour
sf_MUSCLE = 7 // edge connecting 1 dots to 1 anchor, able to contract
sf_UNDEFINED = 0, // the name is explicit: undefined type
sf_DOT = 1, // used to flag objects related to SkinDot
sf_ANCHOR = 2, // used to flag objects related to SkinAnchor
sf_EDGE = 3, // edge default type, connecting 2 dots
sf_FIBER = 4, // edge connecting 2 dots, passive behaviour
sf_TENSOR = 5, // edge connecting 2 dots, able to contract
sf_LIGAMENT = 6, // edge connecting 1 dots to 1 anchor, passive behaviour
sf_MUSCLE = 7 // edge connecting 1 dots to 1 anchor, able to contract
};
union ss_float_uint8 {
float v;
uint8_t* bytes;
ss_float_uint8() { bytes = new uint8_t[__ss_float_size]; }
ss_float_uint8() {
bytes = new uint8_t[__ss_float_size];
}
};
union ss_size_uint8 {
size_t v;
uint8_t* bytes;
ss_size_uint8() { bytes = new uint8_t[__ss_size_t_size]; }
ss_size_uint8() {
bytes = new uint8_t[__ss_size_t_size];
}
};
union ss_uint32_uint8 {
uint32_t v;
uint8_t* bytes;
ss_uint32_uint8() { bytes = new uint8_t[__ss_uint32_size]; }
ss_uint32_uint8() {
bytes = new uint8_t[__ss_uint32_size];
}
};
union ss_int32_uint8 {
int32_t v;
uint8_t* bytes;
ss_int32_uint8() { bytes = new uint8_t[__ss_int32_size]; }
ss_int32_uint8() {
bytes = new uint8_t[__ss_int32_size];
}
};
union ss_int_uint8 {
int v;
uint8_t* bytes;
ss_int_uint8() { bytes = new uint8_t[__ss_int_size]; }
ss_int_uint8() {
bytes = new uint8_t[__ss_int_size];
}
};
union ss_string_uint8 {
char* v;
uint8_t* bytes;
ss_string_uint8() { v = new char[__ss_str_size]; bytes = new uint8_t[__ss_str_size]; }
ss_string_uint8() {
v = new char[__ss_str_size];
bytes = new uint8_t[__ss_str_size];
}
};
union ss_marker_uint8 {
char* v;
uint8_t* bytes;
ss_marker_uint8() { v = new char[SSC_MARKER_SIZE]; bytes = new uint8_t[SSC_MARKER_SIZE]; }
ss_marker_uint8() {
v = new char[SSC_MARKER_SIZE];
bytes = new uint8_t[SSC_MARKER_SIZE];
}
};
#endif // SOFTSKINCOMMON_H
......@@ -15,23 +15,23 @@
v3_ref::v3_ref() :
belong_2_face(false),
local_id(-1) {
local_id(UINT_MAX) {
}
int v3_ref::find_mirror(int i) const {
int v3_ref::find_mirror(uint32_t i) const {
return mirrors.find(i);
}
two_edge::two_edge() :
buffer_id(-1),
edge0(-1),
edge1(-1),
buffer_id(UINT_MAX),
edge0(UINT_MAX),
edge1(UINT_MAX),
flip0(false),
flip1(false) {
}
void two_edge::swap() {
int tmpi = edge0;
uint32_t tmpi = edge0;
bool tmpb = flip0;
edge0 = edge1;
flip0 = flip1;
......@@ -43,19 +43,19 @@ normal_ref::normal_ref() :
dot_id(-1) {
}
void normal_ref::push_face(int i) {
void normal_ref::push_face(uint32_t i) {
if (faces.find(i) == -1) {
faces.push_back(i);
}
}
edge_ref::edge_ref() :
v3_ref_0(-1),
v3_ref_1(-1),
v3_ref_0(UINT_MAX),
v3_ref_1(UINT_MAX),
ligament(false) {
}
bool edge_ref::set(int v0, int v1) {
bool edge_ref::set(uint32_t v0, uint32_t v1) {
if (v0 < v1) {
v3_ref_0 = v0;
v3_ref_1 = v1;
......@@ -68,7 +68,7 @@ bool edge_ref::set(int v0, int v1) {
return true;
}
int edge_ref::contains(int vid) {
int edge_ref::contains(uint32_t vid) {
if (vid == v3_ref_0) {
return 0;
} else if (vid == v3_ref_1) {
......@@ -78,7 +78,7 @@ int edge_ref::contains(int vid) {
}
}
void edge_ref::push_face(int i) {
void edge_ref::push_face(uint32_t i) {
if (faces.find(i) == -1) {
faces.push_back(i);
}
......
......@@ -23,13 +23,13 @@ class v3_ref {
public:
bool belong_2_face;
int local_id;
uint32_t local_id;
Vector3 xyz;
Vector<int> mirrors; // similar indices in _all_vertices
Vector<uint32_t> mirrors; // similar indices in _all_vertices
v3_ref();
int find_mirror(int i) const;
int find_mirror(uint32_t i) const;
_FORCE_INLINE_ void operator=(const Vector3 & src) {
xyz = src;
......@@ -40,9 +40,9 @@ public:
class two_edge {
public:
int buffer_id;
int edge0;
int edge1;
uint32_t buffer_id;
uint32_t edge0;
uint32_t edge1;
bool flip0;
bool flip1;
......@@ -63,13 +63,13 @@ public:
class normal_ref {
public:
int dot_id;
Vector<int> faces; // indices of faces using the normal
uint32_t dot_id;
Vector<uint32_t> faces; // indices of faces using the normal
std::vector<two_edge> edges; // pair of edges to use face per face
normal_ref();
void push_face(int i);
void push_face(uint32_t i);
_FORCE_INLINE_ void operator=(const normal_ref& src) {
dot_id = src.dot_id;
......@@ -80,18 +80,18 @@ public:
};
struct edge_ref {
int v3_ref_0;
int v3_ref_1;
uint32_t v3_ref_0;
uint32_t v3_ref_1;
bool ligament;
Vector<int> faces;
Vector<uint32_t> faces;
edge_ref();
bool set(int v0, int v1);
bool set(uint32_t v0, uint32_t v1);
int contains(int vid);
int contains(uint32_t vid);
void push_face(int i);
void push_face(uint32_t i);
_FORCE_INLINE_ bool operator==(const edge_ref& src) const {
return v3_ref_0 == src.v3_ref_0 &&
......
......@@ -56,7 +56,7 @@ Error SoftskinMesh::load_file(const String &p_path) {
int imarker;
load_value(f, smarker);
load_value(f, imarker);
bool valid = true;
if (smarker.compare(SSM_EXT) == -1) {
......@@ -296,7 +296,7 @@ bool SoftskinMesh::deserialise(FileAccess* f) {
}
load_value(f, size);
std::vector<int> norm_edges;
ss_unique_vec norm_edges;
_unique_normals.resize(size);
int32_t normedge_num;
......
......@@ -225,7 +225,7 @@ void SoftskinProxy::analyse_cache() {
std::vector<normal_ref>::iterator ni;
ni = _cache->_unique_normals.begin();
std::vector<normal_ref>::iterator ne = _cache->_unique_normals.end();
int nindex = 0;
uint32_t nindex = 0;
for (; ni != ne; ++ni, ++nindex) {
......@@ -236,14 +236,14 @@ void SoftskinProxy::analyse_cache() {
nr.edges.resize(imax);
for (int i = 0; i < imax; ++i) {
std::vector<int>& eindices = _cache->_face_fibers[nr.faces[i]];
ss_unique_vec& eindices = _cache->_face_fibers[nr.faces[i]];
two_edge te;
te.buffer_id = nindex;
for (int j = 0, jmax = eindices.size(); j < jmax; ++j) {
edge_ref& ef = _cache->_unique_fibers[ eindices[j] ];
int contain = ef.contains(uindex);
if (contain != -1) {
if (te.edge0 == -1) {
if (te.edge0 == UINT_MAX) {
te.edge0 = eindices[j];
te.flip0 = contain == 1;
} else {
......@@ -253,9 +253,9 @@ void SoftskinProxy::analyse_cache() {
}
}
}
if (te.edge0 != -1 && te.edge1 != -1) {
if (te.edge0 != UINT_MAX && te.edge1 != UINT_MAX) {
// swapping the edge to match CULL_BACK
std::vector<int>& indices = _cache->_face_all_verts[nr.faces[i]];
ss_unique_vec& indices = _cache->_face_all_verts[nr.faces[i]];
// where is the current index in the list?
int p = 0;
if (indices[1] == nindex) {
......
......@@ -26,7 +26,7 @@ bool SkinResource::compare(PoolVector<Vector3>& local, const PoolVector<Vector3>
if (local.size() != foreign.size()) {
return false;
}
for (int j = 0, jmax = local.size(); j < jmax; ++j) {
for (uint32_t j = 0, jmax = uint32_t(local.size()); j < jmax; ++j) {
if (local[j] != foreign[j]) {
return false;
}
......@@ -38,7 +38,7 @@ bool SkinResource::compare(PoolVector<float>& local, const PoolVector<float>& fo
if (local.size() != foreign.size()) {
return false;
}
for (int j = 0, jmax = local.size(); j < jmax; ++j) {
for (uint32_t j = 0, jmax = uint32_t(local.size()); j < jmax; ++j) {
if (local[j] != foreign[j]) {
return false;
}
......@@ -50,7 +50,7 @@ bool SkinResource::compare(PoolVector<int>& local, const PoolVector<int>& foreig
if (local.size() != foreign.size()) {
return false;
}
for (int j = 0, jmax = local.size(); j < jmax; ++j) {
for (uint32_t j = 0, jmax = uint32_t(local.size()); j < jmax; ++j) {
if (local[j] != foreign[j]) {
return false;
}
......@@ -59,8 +59,7 @@ bool SkinResource::compare(PoolVector<int>& local, const PoolVector<int>& foreig
}
void SkinResource::save_marker(FileAccess* f, const char* s) {
memcpy( st10u.v, s, SSC_MARKER_SIZE );
//std::strcpy(st10u.v, std::string(s).c_str());
memcpy(st10u.v, s, SSC_MARKER_SIZE);
f->store_buffer(st10u.bytes, SSC_MARKER_SIZE);
}
......@@ -70,8 +69,7 @@ void SkinResource::load_marker(FileAccess* f, std::string& s) {
}
void SkinResource::save_value(FileAccess* f, const char* s) {
memcpy( st2u.v, s, 255 );
//std::strcpy(st2u.v, std::string(s).c_str());
memcpy(st2u.v, s, 255);
f->store_buffer(st2u.bytes, __ss_str_size);
}
......@@ -81,81 +79,74 @@ void SkinResource::load_value(FileAccess* f, std::string& s) {
}
void SkinResource::save_value(FileAccess* f, const float& v) {
f2u.v = v;
f->store_buffer(f2u.bytes, __ss_float_size);
f->store_float(v);
}
void SkinResource::load_value(FileAccess* f, float& v) {
f->get_buffer(f2u.bytes, __ss_float_size);
v = f2u.v;
v = f->get_float();
}
void SkinResource::save_value(FileAccess* f, const size_t& v) {
sz2u.v = v;
f->store_buffer(sz2u.bytes, __ss_size_t_size);
void SkinResource::save_value(FileAccess* f, const int& v) {
assert(v >= 0);
f->store_32(v);
}
void SkinResource::load_value(FileAccess* f, size_t& v) {
f->get_buffer(sz2u.bytes, __ss_size_t_size);
v = sz2u.v;
void SkinResource::load_value(FileAccess* f, int& v) {
v = f->get_32();
}
void SkinResource::save_value(FileAccess* f, const uint32_t& v) {
ui32u.v = v;
f->store_buffer(ui32u.bytes, __ss_uint32_size);
void SkinResource::save_value(FileAccess* f, const size_t& v) {
f->store_32(v);
}
void SkinResource::save_value(FileAccess* f, const int32_t& v) {
i32u.v = v;
f->store_buffer(i32u.bytes, __ss_int32_size);
void SkinResource::load_value(FileAccess* f, size_t& v) {
v = f->get_32();
}
void SkinResource::load_value(FileAccess* f, uint32_t& v) {
f->get_buffer(ui32u.bytes, __ss_uint32_size);
v = ui32u.v;
void SkinResource::save_value(FileAccess* f, const uint32_t& v) {
f->store_32(v);
}
void SkinResource::load_value(FileAccess* f, int32_t& v) {
f->get_buffer(i32u.bytes, __ss_int32_size);
v = i32u.v;
void SkinResource::load_value(FileAccess* f, uint32_t& v) {
v = f->get_32();
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<uint8_t>& pv) {
uint8_t* buff = new uint8_t[pv.size()];
for (int i = 0, imax = pv.size(); i < imax; ++i) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
buff[i] = pv[i];
}
f->store_buffer(buff, pv.size());
delete[] buff;
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<uint8_t>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<uint8_t>& pv) {
if (num == 0) return;
uint8_t* buff = new uint8_t[num];
f->get_buffer(buff, num);
pv.resize(num);
PoolVector<uint8_t>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
w[i] = buff[i];
}
delete[] buff;
delete[] buff;
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<Vector3>& pv) {
for (int i = 0, imax = pv.size(); i < imax; ++i) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
save_value(f, pv[i].x);
save_value(f, pv[i].y);
save_value(f, pv[i].z);
}
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<Vector3>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<Vector3>& pv) {
if (num == 0) return;
pv.resize(num);
PoolVector<Vector3>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
load_value(f, w[i].x);
load_value(f, w[i].y);
load_value(f, w[i].z);
......@@ -163,25 +154,25 @@ void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<Vec
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<Vector2>& pv) {
for (int i = 0, imax = pv.size(); i < imax; ++i) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
save_value(f, pv[i].x);
save_value(f, pv[i].y);
}
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<Vector2>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<Vector2>& pv) {
if (num == 0) return;
pv.resize(num);
PoolVector<Vector2>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
load_value(f, w[i].x);
load_value(f, w[i].y);
}
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<Color>& pv) {
for (int i = 0, imax = pv.size(); i < imax; ++i) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
save_value(f, pv[i].r);
save_value(f, pv[i].g);
save_value(f, pv[i].b);
......@@ -189,12 +180,12 @@ void SkinResource::save_poolvector(FileAccess* f, PoolVector<Color>& pv) {
}
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<Color>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<Color>& pv) {
if (num == 0) return;
pv.resize(num);
PoolVector<Color>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
load_value(f, w[i].r);
load_value(f, w[i].g);
load_value(f, w[i].b);
......@@ -203,46 +194,46 @@ void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<Col
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<float>& pv) {
for (int i = 0, imax = pv.size(); i < imax; ++i) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
save_value(f, pv[i]);
}
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<float>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<float>& pv) {
if (num == 0) return;
pv.resize(num);
PoolVector<float>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
load_value(f, w[i]);
}
}
void SkinResource::save_poolvector(FileAccess* f, PoolVector<int32_t>& pv) {
for (int i = 0, imax = pv.size(); i < imax; ++i) {
void SkinResource::save_poolvector(FileAccess* f, PoolVector<int>& pv) {
for (uint32_t i = 0, imax = uint32_t(pv.size()); i < imax; ++i) {
save_value(f, pv[i]);
}
}
void SkinResource::load_poolvector(FileAccess* f, const int& num, PoolVector<int32_t>& pv) {
void SkinResource::load_poolvector(FileAccess* f, const size_t& num, PoolVector<int>& pv) {
if (num == 0) return;
pv.resize(num);
PoolVector<int>::Write w = pv.write();
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
load_value(f, w[i]);
}
}
void SkinResource::save_stdvector(FileAccess* f, std::vector<int>& v) {
std::vector<int>::iterator it = v.begin();
std::vector<int>::iterator ite = v.end();
void SkinResource::save_stdvector(FileAccess* f, ss_unique_vec& v) {