Ejemplo n.º 1
0
int parse_actor_script (xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, act_idx;
	actor_types *act;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	act_idx = get_property (cfg, "type", "actor type", actor_type_dict);
	if (act_idx < 0) return 0;
	
	act = &(actors_defs[act_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "ghost") == 0) {
				act->ghost = get_bool_value (item);
			} else if (xmlStrcasecmp (item->name, "skin") == 0) {
				get_string_value (act->skin_name, sizeof (act->skin_name), item);
			} else if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (act->file_name, sizeof (act->file_name), item);
			} else if (xmlStrcasecmp (item->name, "frames") == 0) {
				ok &= parse_actor_frames (act, item->children);
			} else if (xmlStrcasecmp (item->name, "shirt") == 0) {
				ok &= parse_actor_shirt (act, item);
			} else if (xmlStrcasecmp (item->name, "hskin") == 0) {
				ok &= parse_actor_skin (act, item);
			} else if (xmlStrcasecmp (item->name, "hair") == 0) {
				ok &= parse_actor_hair (act, item);
			} else if (xmlStrcasecmp (item->name, "boots") == 0) {
				ok &= parse_actor_boots (act, item);
			} else if (xmlStrcasecmp (item->name, "legs") == 0) {
				ok &= parse_actor_legs (act, item);
			} else if (xmlStrcasecmp (item->name, "cape") == 0) {
				ok &= parse_actor_cape (act, item);
			} else if (xmlStrcasecmp (item->name, "head") == 0) {
				ok &= parse_actor_head (act, item);
			} else if (xmlStrcasecmp (item->name, "shield") == 0) {
				ok &= parse_actor_shield (act, item);
			} else if (xmlStrcasecmp (item->name, "weapon") == 0) {
				ok &= parse_actor_weapon (act, item);
			} else if (xmlStrcasecmp (item->name, "helmet") == 0) {
				ok &= parse_actor_helmet (act, item);
			} else if (xmlStrcasecmp (item->name, "walk_speed") == 0) {
				act->walk_speed = get_float_value (item);
			} else if (xmlStrcasecmp (item->name, "run_speed") == 0) {
				act->run_speed = get_float_value (item);
			} else {
				snprintf (errmsg, sizeof (errmsg), "Unknown actor attribute \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
Ejemplo n.º 2
0
// sample the output pins to the current rb record
static inline void apply(const sample_t *s, const hal_delayline_t *hd)
{
    int i;
    for (i = 0; i < hd->nsamples; i++)	{
	// because of the union the values and pins must be properly
	// dereferenced against their type
	switch (hd->pintype[i])  {
	case HAL_BIT:
	    set_bit_value(hd->pins_out[i], get_bit_value(&s->value[i]));
	    break;
	case HAL_FLOAT:
	    set_float_value(hd->pins_out[i], get_float_value(&s->value[i]));
	    break;
	case HAL_S32:
	    set_s32_value(hd->pins_out[i], get_s32_value(&s->value[i]));
	    break;
	case HAL_U32:
	    set_u32_value(hd->pins_out[i], get_u32_value(&s->value[i]));
	    break;
	case HAL_S64:
	    set_s64_value(hd->pins_out[i], get_s64_value(&s->value[i]));
	    break;
	case HAL_U64:
	    set_u64_value(hd->pins_out[i], get_u64_value(&s->value[i]));
	    break;
	case HAL_TYPE_MAX:
	case HAL_TYPE_UNSPECIFIED:
	    // an error - should fail loudly TBD
	    ;
	}
    }
}
Ejemplo n.º 3
0
// write_sample_to_ring() will sample the pins and add them as a struct sample_t
// into the ring.
static void write_sample_to_ring(void *arg, long period)
{
    int j;
    ringbuffer_t *rb = (ringbuffer_t *) arg;
    hal_delayline_t *hd = rb->scratchpad;    // per-instance HAL data
    sample_t *s;

    // if pin_delay > max_delay then use max_delay, otherwise
    // use delay pin value

    // if time has increased, then take action by setting the input_ts to the
    // result of output_ts + delay. Otherwise do nothing. The situation of
    // decreasing the time will be acted upon in read_sample_to_ring()
    if ( *(hd->pin_delay) > (hal_u32_t)( hd->input_ts - hd->output_ts)) {
	if ( *(hd->pin_delay) > hd->max_delay) {
	    hd->delay = hd->max_delay;
	}
	else {
	    hd->delay = *(hd->pin_delay);
	}
	// set the new timestamp
	hd->input_ts = hd->output_ts + (__u64)(hd->delay);
    }

    if (!*(hd->enable)) {
	// skip if not sampling, just put the input
	// values into the output values
	for (j = 0; j < hd->nsamples; j++) {
	    switch (hd->pintype[j])
		{
		case HAL_BIT:
		    set_bit_value(hd->pins_out[j], get_bit_value(hd->pins_in[j]));
		    break;
		case HAL_FLOAT:
		    set_float_value(hd->pins_out[j], get_float_value(hd->pins_in[j]));
		    break;
		case HAL_S32:
		    set_s32_value(hd->pins_out[j], get_s32_value(hd->pins_in[j]));
		    break;
		case HAL_U32:
		    set_u32_value(hd->pins_out[j], get_u32_value(hd->pins_in[j]));
		    break;
		case HAL_S64:
		    set_s64_value(hd->pins_out[j], get_s64_value(hd->pins_in[j]));
		    break;
		case HAL_U64:
		    set_u64_value(hd->pins_out[j], get_u64_value(hd->pins_in[j]));
		    break;
		case HAL_TYPE_MAX:
		case HAL_TYPE_UNSPECIFIED:
		    // an error - should fail loudly TBD
		    ;
		}
	}
	goto DONE;
    }

    // use non-copying write:
    // allocate space in the ringbuffer and retrieve a pointer to it
    if (record_write_begin(rb, (void ** )&s, hd->sample_size)) {
	*(hd->write_fail) += 1;
	goto DONE;
    }

    // deposit record directly in rb memory
    s->timestamp = hd->input_ts;
    for (j = 0; j < hd->nsamples; j++) {
	switch (hd->pintype[j])
	    {
	    case HAL_BIT:
		set_bit_value(&s->value[j], get_bit_value(hd->pins_in[j]));
		break;
	    case HAL_FLOAT:
		set_float_value(&s->value[j], get_float_value(hd->pins_in[j]));
		break;
	    case HAL_S32:
		set_s32_value(&s->value[j], get_s32_value(hd->pins_in[j]));
		break;
	    case HAL_U32:
		set_u32_value(&s->value[j], get_u32_value(hd->pins_in[j]));
		break;
	    case HAL_S64:
		set_s64_value(&s->value[j], get_s64_value(hd->pins_in[j]));
		break;
	    case HAL_U64:
		set_u64_value(&s->value[j], get_u64_value(hd->pins_in[j]));
		break;
	    case HAL_TYPE_MAX:
	    case HAL_TYPE_UNSPECIFIED:
		// an error - should fail loudly TBD
		;
	    }
    }

    // commit the write given the actual write size (which is the same
    // as given in record_write_begin in our case). This makes the
    // record actually visible on the read side (advances pointer)
    if (record_write_end(rb, s, hd->sample_size))
	*(hd->write_fail) += 1;

 DONE:
    hd->input_ts++;
}
Ejemplo n.º 4
0
int weather_parse_effect(xmlNode *node)
{
	xmlNode *item;
	xmlAttr *attr;
	int ok = 1;
	int id = -1;

	for (attr = node->properties; attr; attr = attr->next)
	{
		if (attr->type == XML_ATTRIBUTE_NODE)
		{
			if (!xmlStrcasecmp (attr->name, (xmlChar*)"id"))
				id = atoi((char*)attr->children->content);
			else {
				LOG_ERROR_OLD("unknown attribute for effect: %s", (char*)attr->name);
				ok = 0;
			}
		}
	}

	if (id < 1)
	{
		LOG_ERROR_OLD("wrong or missing id for weather effect");
		return 0;
	}

	for(item = node->children; item; item = item->next) {
		if(item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp(item->name, (xmlChar*)"sprites") == 0) {
				weather_defs[id].use_sprites = get_bool_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"density") == 0) {
				weather_defs[id].density = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"color") == 0) {
				weather_defs[id].color[0] = 0.0;
				weather_defs[id].color[1] = 0.0;
				weather_defs[id].color[2] = 0.0;
				weather_defs[id].color[3] = 0.0;
				for (attr = item->properties; attr; attr = attr->next)
				{
					if (attr->type == XML_ATTRIBUTE_NODE)
					{
						if (!xmlStrcasecmp (attr->name, (xmlChar*)"r"))
							weather_defs[id].color[0] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"g"))
							weather_defs[id].color[1] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"b"))
							weather_defs[id].color[2] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"a"))
							weather_defs[id].color[3] = atof((char*)attr->children->content);
						else {
							LOG_ERROR_OLD("unknown attribute for weather effect color: %s", (char*)attr->name);
							ok = 0;
						}
					}
				}
				weather_defs[id].color[0] /= 255.0;
				weather_defs[id].color[1] /= 255.0;
				weather_defs[id].color[2] /= 255.0;
				weather_defs[id].color[3] /= 255.0;
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"size") == 0) {
				weather_defs[id].size = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"speed") == 0) {
				weather_defs[id].speed = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"wind_effect") == 0) {
				weather_defs[id].wind_effect = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"texture") == 0) {
#ifdef	NEW_TEXTURES
				weather_defs[id].texture = load_texture_cached((char*)item->children->content, tt_mesh);
#else	/* NEW_TEXTURES */
				weather_defs[id].texture = load_texture_cache((char*)item->children->content, 0);
#endif	/* NEW_TEXTURES */
			}
			else {
				LOG_ERROR_OLD("unknown node for weather effect: %s", item->name);
				ok = 0;
			}
		}
		else if (item->type == XML_ENTITY_REF_NODE) {
			ok &= weather_parse_effect(item->children);
		}
	}

	return ok;
}