Ejemplo n.º 1
0
uint32_t Array::hash() const {

	uint32_t h=hash_djb2_one_32(0);

	for (int i=0;i<_p->array.size();i++) {

		h = hash_djb2_one_32( _p->array[i].hash(), h);
	}
	return h;
}
Ejemplo n.º 2
0
uint32_t Dictionary::hash() const {

	uint32_t h = hash_djb2_one_32(Variant::DICTIONARY);

	List<Variant> keys;
	get_key_list(&keys);

	for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {

		h = hash_djb2_one_32(E->get().hash(), h);
		h = hash_djb2_one_32(operator[](E->get()).hash(), h);
	}

	return h;
}
Ejemplo n.º 3
0
uint32_t Resource::hash_edited_version() const {

	uint32_t hash = hash_djb2_one_32(get_edited_version());

	List<PropertyInfo> plist;
	get_property_list(&plist);

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
			RES res = get(E->get().name);
			if (res.is_valid()) {
				hash = hash_djb2_one_32(res->hash_edited_version(), hash);
			}
		}
	}

	return hash;
}
uint32_t NetworkedMultiplayerENet::_gen_unique_id() const {

	uint32_t hash = 0;

	while (hash==0 || hash==1) {

		hash = hash_djb2_one_32(
					(uint32_t)OS::get_singleton()->get_ticks_usec() );
		hash = hash_djb2_one_32(
					(uint32_t)OS::get_singleton()->get_unix_time(), hash );
		hash = hash_djb2_one_32(
					(uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash );
		//hash = hash_djb2_one_32(
		//			(uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash );
		hash = hash_djb2_one_32(
					(uint32_t)((uint64_t)this), hash ); //rely on aslr heap
		hash = hash_djb2_one_32(
					(uint32_t)((uint64_t)&hash), hash ); //rely on aslr stack

		hash=hash&0x7FFFFFFF; // make it compatible with unsigned, since negatie id is used for exclusion
	}

	return hash;
}
Ejemplo n.º 5
0
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;

}