uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) { uint32_t h = hash_djb2_buffer((const uint8_t *)&p_vtx.vertex, sizeof(real_t) * 3); h = hash_djb2_buffer((const uint8_t *)&p_vtx.normal, sizeof(real_t) * 3, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.binormal, sizeof(real_t) * 3, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.tangent, sizeof(real_t) * 3, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv, sizeof(real_t) * 2, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv2, sizeof(real_t) * 2, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.color, sizeof(real_t) * 4, h); h = hash_djb2_buffer((const uint8_t *)p_vtx.bones.ptr(), p_vtx.bones.size() * sizeof(int), h); h = hash_djb2_buffer((const uint8_t *)p_vtx.weights.ptr(), p_vtx.weights.size() * sizeof(float), h); return h; }
uint32_t Variant::hash() const { switch( type ) { case NIL: { return 0; } break; case BOOL: { return _data._bool?1:0; } break; case INT: { return _data._int; } break; case REAL: { MarshallFloat mf; mf.f=_data._real; return mf.i; } break; case STRING: { return reinterpret_cast<const String*>(_data._mem)->hash(); } break; // math types case VECTOR2: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2*>(_data._mem)->x); return hash_djb2_one_float(reinterpret_cast<const Vector2*>(_data._mem)->y,hash); } break; case RECT2: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->pos.x); hash = hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->pos.y,hash); hash = hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->size.x,hash); return hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->size.y,hash); } break; case MATRIX32: { uint32_t hash = 5831; for(int i=0;i<3;i++) { for(int j=0;j<2;j++) { hash = hash_djb2_one_float(_data._matrix32->elements[i][j],hash); } } return hash; } break; case VECTOR3: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector3*>(_data._mem)->x); hash = hash_djb2_one_float(reinterpret_cast<const Vector3*>(_data._mem)->y,hash); return hash_djb2_one_float(reinterpret_cast<const Vector3*>(_data._mem)->z,hash); } break; case PLANE: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane*>(_data._mem)->normal.x); hash = hash_djb2_one_float(reinterpret_cast<const Plane*>(_data._mem)->normal.y,hash); hash = hash_djb2_one_float(reinterpret_cast<const Plane*>(_data._mem)->normal.z,hash); return hash_djb2_one_float(reinterpret_cast<const Plane*>(_data._mem)->d,hash); } break; /* case QUAT: { } break;*/ case _AABB: { uint32_t hash = 5831; for(int i=0;i<3;i++) { hash = hash_djb2_one_float(_data._aabb->pos[i],hash); hash = hash_djb2_one_float(_data._aabb->size[i],hash); } return hash; } break; case QUAT: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Quat*>(_data._mem)->x); hash = hash_djb2_one_float(reinterpret_cast<const Quat*>(_data._mem)->y,hash); hash = hash_djb2_one_float(reinterpret_cast<const Quat*>(_data._mem)->z,hash); return hash_djb2_one_float(reinterpret_cast<const Quat*>(_data._mem)->w,hash); } break; case MATRIX3: { uint32_t hash = 5831; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { hash = hash_djb2_one_float(_data._matrix3->elements[i][j],hash); } } return hash; } break; case TRANSFORM: { uint32_t hash = 5831; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { hash = hash_djb2_one_float(_data._transform->basis.elements[i][j],hash); } hash = hash_djb2_one_float(_data._transform->origin[i],hash); } return hash; } break; // misc types case COLOR: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Color*>(_data._mem)->r); hash = hash_djb2_one_float(reinterpret_cast<const Color*>(_data._mem)->g,hash); hash = hash_djb2_one_float(reinterpret_cast<const Color*>(_data._mem)->b,hash); return hash_djb2_one_float(reinterpret_cast<const Color*>(_data._mem)->a,hash); } break; case IMAGE: { return 0; } break; case _RID: { return hash_djb2_one_64(reinterpret_cast<const RID*>(_data._mem)->get_id()); } break; case OBJECT: { return hash_djb2_one_64(make_uint64_t(_get_obj().obj)); } break; case NODE_PATH: { return reinterpret_cast<const NodePath*>(_data._mem)->hash(); } break; case INPUT_EVENT: { return hash_djb2_buffer((uint8_t*)_data._input_event,sizeof(InputEvent)); } break; case DICTIONARY: { return reinterpret_cast<const Dictionary*>(_data._mem)->hash(); } break; case ARRAY: { const Array& arr = *reinterpret_cast<const Array* >(_data._mem); return arr.hash(); } break; case RAW_ARRAY: { const DVector<uint8_t>& arr = *reinterpret_cast<const DVector<uint8_t>* >(_data._mem); int len = arr.size(); DVector<uint8_t>::Read r = arr.read(); return hash_djb2_buffer((uint8_t*)&r[0],len); } break; case INT_ARRAY: { const DVector<int>& arr = *reinterpret_cast<const DVector<int>* >(_data._mem); int len = arr.size(); DVector<int>::Read r = arr.read(); return hash_djb2_buffer((uint8_t*)&r[0],len*sizeof(int)); } break; case REAL_ARRAY: { const DVector<real_t>& arr = *reinterpret_cast<const DVector<real_t>* >(_data._mem); int len = arr.size(); DVector<real_t>::Read r = arr.read(); return hash_djb2_buffer((uint8_t*)&r[0],len*sizeof(real_t)); } break; case STRING_ARRAY: { uint32_t hash=5831; const DVector<String>& arr = *reinterpret_cast<const DVector<String>* >(_data._mem); int len = arr.size(); DVector<String>::Read r = arr.read(); for(int i=0;i<len;i++) { hash = hash_djb2_one_32(r[i].hash(),hash); } return hash; } break; case VECTOR2_ARRAY: { uint32_t hash=5831; const DVector<Vector2>& arr = *reinterpret_cast<const DVector<Vector2>* >(_data._mem); int len = arr.size(); DVector<Vector2>::Read r = arr.read(); for(int i=0;i<len;i++) { hash = hash_djb2_one_float(r[i].x,hash); hash = hash_djb2_one_float(r[i].y,hash); } return hash; } break; case VECTOR3_ARRAY: { uint32_t hash=5831; const DVector<Vector3>& arr = *reinterpret_cast<const DVector<Vector3>* >(_data._mem); int len = arr.size(); DVector<Vector3>::Read r = arr.read(); for(int i=0;i<len;i++) { hash = hash_djb2_one_float(r[i].x,hash); hash = hash_djb2_one_float(r[i].y,hash); hash = hash_djb2_one_float(r[i].z,hash); } return hash; } break; case COLOR_ARRAY: { uint32_t hash=5831; const DVector<Color>& arr = *reinterpret_cast<const DVector<Color>* >(_data._mem); int len = arr.size(); DVector<Color>::Read r = arr.read(); for(int i=0;i<len;i++) { hash = hash_djb2_one_float(r[i].r,hash); hash = hash_djb2_one_float(r[i].g,hash); hash = hash_djb2_one_float(r[i].b,hash); hash = hash_djb2_one_float(r[i].a,hash); } return hash; } break; default: {} } return 0; }