Esempio n. 1
0
 void wallet_db::store_setting(const string& name, const variant& value)
 {
     auto orec = lookup_setting(name);
     if (orec.valid())
     {
         orec->value = value;
         settings[name] = *orec;
         store_record( *orec );
     }
     else
     {
         auto rec = wallet_setting_record( setting(name, value), new_wallet_record_index() );
         settings[name] = rec;
         store_record( rec );
     }
 }
Esempio n. 2
0
 void WalletDb::store_setting(const string& name, const variant& value)
 {
     auto orec = lookup_setting(name);
     if (orec.valid())
     {
         orec->value = value;
         settings[name] = *orec;
         store_and_reload_entry( *orec );
     }
     else
     {
         auto rec = WalletSettingEntry( Setting(name, value), new_wallet_entry_index() );
         settings[name] = rec;
         store_and_reload_entry( rec );
     }
 }
Esempio n. 3
0
int _handle_setting(char *text){

	int token;
	struct myrt_setting *s = lookup_setting(text);

	if ( ! s )
		return -1;
	
	/* See if the next token matches the type on the setting. */
	token = yylex();
	switch ( s->type ){

	case TYPE_VECTOR:
		if ( token != TOKEN_VECTOR ){
			myrt_printf(ERROR, "(%d) Token misamtch: %s\n",
				    __line_no, __parsed_text);
			myrt_printf(ERROR, "  Expected vector.\n");
			return -1;
		}
		myrt_strtovec(__parsed_text, &s->data.vec);
		break;

	case TYPE_INTEGER:
		if ( token != TOKEN_INTEGER ){
			myrt_printf(ERROR, "(%d) Token misamtch: %s\n",
				    __line_no, __parsed_text);
			myrt_printf(ERROR, "  Expected integer.\n");
			return -1;
		}
		s->data.num_i = atoi(__parsed_text);
		break;

	case TYPE_FLOAT:
		if ( token != TOKEN_FLOAT && token != TOKEN_INTEGER ){
			myrt_printf(ERROR, "(%d) Token misamtch: %s\n",
				    __line_no, __parsed_text);
			myrt_printf(ERROR, "  Expected float.\n");
			return -1;
		}
		s->data.num_f = atof(__parsed_text);
		break;
	}

	return 0;

}
Esempio n. 4
0
/*
 * Parse a shape directive. Use the callback functions!!!
 */
int _handle_shape(struct scene_graph *graph, char *shape){

	int ret;
	int offset;
	struct object *obj;

	/* First, is it a legit shape? */
	offset = _lookup_object(shape);
	if ( offset < 0 ){
		myrt_printf(ERROR, "(%d) Unknown object definition: %s\n",
			    __line_no, shape);
		return -1;
	}

	/* Assuming a legit shape, we can access the object array. */
	obj = (struct object *)malloc(sizeof(struct object));
	if ( ! obj ){
		myrt_printf(ERROR, "Internal: out of memory.\n");
		return -1;
	}

	/* And init the shape, etc, etc. */
	memcpy(obj, &known_objects[offset], sizeof(struct object));
	obj->reflectance = lookup_setting("reflectance")->data.num_f;
	obj->diffusion = 1 - obj->reflectance;
	myrt_msg("Setting reflectance: %f, diffusion %f\n",
		 obj->reflectance, obj->diffusion);
	obj->light = 0;
	ret = obj->init(obj);
	if ( ret < 0 )
		return ret;

	/* Shape is inited; now allow the shape's parser to parse the fields. */
	ret = obj->parse(obj);
	if ( ! ret )
		myrt_objlist_add(&graph->objs, obj);

	return ret;

}