Example #1
0
/* OB_DUPLIVERTS - FONT */
static Object *find_family_object(const char *family, size_t family_len, unsigned int ch, GHash *family_gh)
{
	Object **ob_pt;
	Object *ob;
	void *ch_key = SET_UINT_IN_POINTER(ch);

	if ((ob_pt = (Object **)BLI_ghash_lookup_p(family_gh, ch_key))) {
		ob = *ob_pt;
	}
	else {
		char ch_utf8[7];
		size_t ch_utf8_len;

		ch_utf8_len = BLI_str_utf8_from_unicode(ch, ch_utf8);
		ch_utf8[ch_utf8_len] = '\0';
		ch_utf8_len += 1;  /* compare with null terminator */

		for (ob = G.main->object.first; ob; ob = ob->id.next) {
			if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) {
				if (STREQLEN(ob->id.name + 2, family, family_len)) {
					break;
				}
			}
		}

		/* inserted value can be NULL, just to save searches in future */
		BLI_ghash_insert(family_gh, ch_key, ob);
	}

	return ob;
}
Example #2
0
/**
 * Generate a PreviewImage from given file path, using thumbnails management, if not yet existing.
 */
PreviewImage *BKE_previewimg_cached_thumbnail_read(
        const char *name, const char *path, const int source, bool force_update)
{
	PreviewImage *prv = NULL;
	void **prv_p;

	prv_p = BLI_ghash_lookup_p(gCachedPreviews, name);

	if (prv_p) {
		prv = *prv_p;
		BLI_assert(prv);
	}

	if (prv && force_update) {
		const char *prv_deferred_data = PRV_DEFERRED_DATA(prv);
		if (((int)prv_deferred_data[0] == source) && STREQ(&prv_deferred_data[1], path)) {
			/* If same path, no need to re-allocate preview, just clear it up. */
			BKE_previewimg_clear(prv);
		}
		else {
			BKE_previewimg_free(&prv);
		}
	}

	if (!prv) {
		/* We pack needed data for lazy loading (source type, in a single char, and path). */
		const size_t deferred_data_size = strlen(path) + 2;
		char *deferred_data;

		prv = previewimg_create_ex(deferred_data_size);
		deferred_data = PRV_DEFERRED_DATA(prv);
		deferred_data[0] = source;
		memcpy(&deferred_data[1], path, deferred_data_size - 1);

		force_update = true;
	}

	if (force_update) {
		if (prv_p) {
			*prv_p = prv;
		}
		else {
			BLI_ghash_insert(gCachedPreviews, BLI_strdup(name), prv);
		}
	}

	return prv;
}
Example #3
0
/**
 * Returns the index of the struct info for the struct with the specified name.
 */
int DNA_struct_find_nr_ex(const SDNA *sdna, const char *str, unsigned int *index_last)
{
	const short *sp = NULL;

	if (*index_last < sdna->nr_structs) {
		sp = sdna->structs[*index_last];
		if (strcmp(sdna->types[sp[0]], str) == 0) {
			return *index_last;
		}
	}

#ifdef WITH_DNA_GHASH
	{
		void **index_p;
		int a;

		index_p = BLI_ghash_lookup_p(sdna->structs_map, str);

		if (index_p) {
			a = GET_INT_FROM_POINTER(*index_p);
			*index_last = a;
		}
		else {
			a = -1;
		}
		return a;
	}
#else
	{
		int a;

		for (a = 0; a < sdna->nr_structs; a++) {

			sp = sdna->structs[a];

			if (strcmp(sdna->types[sp[0]], str) == 0) {
				*index_last = a;
				return a;
			}
		}
	}
	return -1;
#endif
}
Example #4
0
/* XXX Logick bricks... I don't have words to say what I think about this behavior.
 *     They have silent hidden ugly inter-objects dependencies (a sensor can link into any other
 *     object's controllers, and same between controllers and actuators, without *any* explicit reference
 *     to data-block involved).
 *     This is bad, bad, bad!!!
 *     ...and forces us to add yet another very ugly hack to get remapping with logic bricks working. */
void BKE_sca_logic_links_remap(Main *bmain, Object *ob_old, Object *ob_new)
{
	if (ob_new == NULL || (ob_old->controllers.first == NULL && ob_old->actuators.first == NULL)) {
		/* Nothing to do here... */
		return;
	}

	GHash *controllers_map = ob_old->controllers.first ?
	                             BLI_ghash_ptr_new_ex(__func__, BLI_listbase_count(&ob_old->controllers)) : NULL;
	GHash *actuators_map = ob_old->actuators.first ?
	                           BLI_ghash_ptr_new_ex(__func__, BLI_listbase_count(&ob_old->actuators)) : NULL;

	/* We try to remap old controllers/actuators to new ones - in a very basic way. */
	for (bController *cont_old = ob_old->controllers.first, *cont_new = ob_new->controllers.first;
	     cont_old;
	     cont_old = cont_old->next)
	{
		bController *cont_new2 = cont_new;

		if (cont_old->mynew != NULL) {
			cont_new2 = cont_old->mynew;
			if (!(cont_new2 == cont_new || BLI_findindex(&ob_new->controllers, cont_new2) >= 0)) {
				cont_new2 = NULL;
			}
		}
		else if (cont_new && cont_old->type != cont_new->type) {
			cont_new2 = NULL;
		}

		BLI_ghash_insert(controllers_map, cont_old, cont_new2);

		if (cont_new) {
			cont_new = cont_new->next;
		}
	}

	for (bActuator *act_old = ob_old->actuators.first, *act_new = ob_new->actuators.first;
	     act_old;
	     act_old = act_old->next)
	{
		bActuator *act_new2 = act_new;

		if (act_old->mynew != NULL) {
			act_new2 = act_old->mynew;
			if (!(act_new2 == act_new || BLI_findindex(&ob_new->actuators, act_new2) >= 0)) {
				act_new2 = NULL;
			}
		}
		else if (act_new && act_old->type != act_new->type) {
			act_new2 = NULL;
		}

		BLI_ghash_insert(actuators_map, act_old, act_new2);

		if (act_new) {
			act_new = act_new->next;
		}
	}

	for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
		if (controllers_map != NULL) {
			for (bSensor *sens = ob->sensors.first; sens; sens = sens->next) {
				for (int a = 0; a < sens->totlinks; a++) {
					if (sens->links[a]) {
						bController *old_link = sens->links[a];
						bController **new_link_p = (bController **)BLI_ghash_lookup_p(controllers_map, old_link);

						if (new_link_p == NULL) {
							/* old_link is *not* in map's keys (i.e. not to any ob_old->controllers),
							 * which means we ignore it totally here. */
						}
						else if (*new_link_p == NULL) {
							unlink_logicbricks((void **)&old_link, (void ***)&(sens->links), &sens->totlinks);
							a--;
						}
						else {
							sens->links[a] = *new_link_p;
						}
					}
				}
			}
		}

		if (actuators_map != NULL) {
			for (bController *cont = ob->controllers.first; cont; cont = cont->next) {
				for (int a = 0; a < cont->totlinks; a++) {
					if (cont->links[a]) {
						bActuator *old_link = cont->links[a];
						bActuator **new_link_p = (bActuator **)BLI_ghash_lookup_p(actuators_map, old_link);

						if (new_link_p == NULL) {
							/* old_link is *not* in map's keys (i.e. not to any ob_old->actuators),
							 * which means we ignore it totally here. */
						}
						else if (*new_link_p == NULL) {
							unlink_logicbricks((void **)&old_link, (void ***)&(cont->links), &cont->totlinks);
							a--;
						}
						else {
							cont->links[a] = *new_link_p;
						}
					}
				}
			}
		}
	}

	if (controllers_map) {
		BLI_ghash_free(controllers_map, NULL, NULL);
	}
	if (actuators_map) {
		BLI_ghash_free(actuators_map, NULL, NULL);
	}
}