示例#1
0
static void rna_Controller_unlink(bController *cont, bSensor *sens, bActuator *act)
{
	if(sens)
		unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
	if(act)
		unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
}
示例#2
0
文件: sca.c 项目: mgschwan/blensor
void unlink_actuator(bActuator *act)
{
	bController *cont;
	Object *ob;
	
	/* check for actuator pointers in controllers */
	ob= G.main->object.first;
	while (ob) {
		cont= ob->controllers.first;
		while (cont) {
			unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
			cont= cont->next;
		}
		ob= ob->id.next;
	}
}
示例#3
0
文件: sca.c 项目: mgschwan/blensor
void unlink_controller(bController *cont)
{
	bSensor *sens;
	Object *ob;
	
	/* check for controller pointers in sensors */
	ob= G.main->object.first;
	while (ob) {
		sens= ob->sensors.first;
		while (sens) {
			unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
			sens= sens->next;
		}
		ob= ob->id.next;
	}
}
示例#4
0
static void rna_Sensor_unlink(bSensor *sens, bController *cont)
{
	unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
}
示例#5
0
文件: sca.c 项目: mgschwan/blensor
/* 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);
	}
}
示例#6
0
static void rna_Actuator_unlink(bActuator *act, bController *cont)
{
	unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
}