Пример #1
0
int main(void)
{
	object *obj = object_create(64);
	assert(obj != NULL);

	/* Testing adding all of the types */
	assert(object_add(obj, "integer", 12345) == JSON11_ERR_OK);
	assert(object_add(obj, "double", -1.2345e4) == JSON11_ERR_OK);
	assert(object_add(obj, "string", "abcdef") == JSON11_ERR_OK);
	assert(object_add(obj, "true", (bool)true) == JSON11_ERR_OK);
	assert(object_add(obj, "false", (bool)false) == JSON11_ERR_OK);
	assert(object_add(obj, "null", NULL) == JSON11_ERR_OK);

	object *inner_object = object_create(32);
	array *inner_array = array_create(32);

	assert(inner_object != NULL);
	assert(inner_array != NULL);

	assert(object_add(obj, "object", inner_object) == JSON11_ERR_OK);
	assert(object_add(obj, "array", inner_array) == JSON11_ERR_OK);

//	object_destroy(&obj);
//	assert(obj == NULL);
}
Пример #2
0
static VALUE
frt_bv_alloc(VALUE klass)
{
    BitVector *bv = bv_new();
    VALUE rbv = Data_Wrap_Struct(klass, NULL, &frt_bv_free, bv);
    object_add(bv, rbv);
    return rbv;
}
Пример #3
0
VALUE
frt_get_bv(BitVector *bv)
{
    VALUE rbv;
    if ((rbv = object_get(bv)) == Qnil) {
        rbv = Data_Wrap_Struct(cBitVector, NULL, &frt_bv_free, bv);
        REF(bv);
        object_add(bv, rbv);
    }
    return rbv;
}
Пример #4
0
//Add a player in to the game
Object *
player_add(char player_name[], int frame_delay, int vector_size) {
	PLAYER_COUNT++;
	Object *p;
	bool error=false;
	switch(PLAYER_COUNT) {
		case 1:
			p = object_add(player, PLAYER_COUNT);
			p->img_delay = 0;
			p->img_i = 0;
			p->life = 3;
			p->height = al_get_bitmap_height(sprites[player][p->img_i]);
			p->width = al_get_bitmap_width(sprites[player][p->img_i]);
		break;
		case 2:
			p = object_add(player2, PLAYER_COUNT);
			p->img_delay = 0;
			p->img_i = 0;
			p->life = 3;
			p->height = al_get_bitmap_height(sprites[player2][p->img_i]);
			p->width = al_get_bitmap_width(sprites[player2][p->img_i]);
		break;
		default:
			printf("Player Illegal tentando acessar a partida\n");
			exit(EXIT_FAILURE);
			break;
	}


	p->frame_delay = frame_delay;
	p->vector_size = vector_size;

	strcpy_s(p->String, sizeof(p->String), player_name);
	p->vx = 0;
	p->vy = 0;
	p->x = DISPLAY_W / 2 - p->width / 2;
	p->y = DISPLAY_H / 2 - p->height / 2 + 200;

	return p;
}
Пример #5
0
/**
 * Creates a new object and inserts it into 'env'.
 * @param env
 * Which object to insert the created object into. Can be NULL
 * not to insert the created object anywhere.
 * @param tag
 * The object's ID.
 * @param bflag
 * If 1, the object will be added to the end of the
 * inventory instead of the start.
 * @return
 * The created object.
 */
object *object_create(object *env, tag_t tag, int bflag)
{
    object *op = mempool_get(pool_object);

    op->tag = tag;

    if (env != NULL) {
        object_add(env, op, bflag);
    }

    object_redraw(op);

    return op;
}
Пример #6
0
/**
 * Transfer the entire inventory of 'op' into 'to'.
 * @param op
 * Object to transfer the inventory of.
 * @param to
 * Object to receive the items.
 */
void object_transfer_inventory(object *op, object *to)
{
    for (object *tmp = op->inv, *next; tmp != NULL; tmp = next) {
        next = tmp->next;

        if (tmp->prev != NULL) {
            tmp->prev->next = tmp->next;
        } else if (tmp->env != NULL) {
            tmp->env->inv = tmp->next;
        }

        if (tmp->next != NULL) {
            tmp->next->prev = tmp->prev;
        }

        object_add(to, tmp, 1);
    }
}
Пример #7
0
//Add a bullet in to the game, based on its previous defined type
Object *
bullet_add(Object bullet_type_, Object *p) {
	Object *bllt;

	bllt = object_add(bullet, -1);
	bllt->img_delay = 0;
	bllt->img_i = 0;
	bllt->height = bullet_type_.height; //al_get_bitmap_height(bllt->img);
	bllt->width = bullet_type_.width; //al_get_bitmap_width(bllt->img);
	bllt->x = p->x + p->width / 2 - bllt->width / 2;
	bllt->vx = bullet_type_.vx + (0.35 - (float) (rand() % 70) / 100.0); // Uncertainty principle
	bllt->vy = bullet_type_.vy; // +(0.35 - (float)(rand() % 36) / 10.0); // Uncertainty principle
	bllt->y = p->y + ((bllt->vy > 0) ? p->height : -bllt->height);
	bllt->frame_delay = bullet_type_.frame_delay;
	bllt->vector_size = bullet_type_.vector_size;
	bllt->life = bullet_type_.life;

	return bllt;
}
Пример #8
0
Object *
background_add(int x, int y) {
	int tag = -3;

	Object *bg;
	bg = object_add(background, tag);
	bg->img_delay = 0;
	bg->img_i = 0;
	bg->height = al_get_bitmap_height(sprites[background][bg->img_i]);
	bg->width = al_get_bitmap_width(sprites[background][bg->img_i]);
	bg->x = x;
	bg->vx = 0;
	bg->vy = 8;
	bg->y = y;
	bg->frame_delay = 0;
	bg->vector_size = 1;
	bg->life = -1;

	return bg;
}
Пример #9
0
//Add an enemy in to the game, based on its previous defined type
Object *
enemy_add(Object enemy_type, int x, int y) {
	int tag = -2;

	Object *e; // e for enemy!!!! If this dont work I gonna kill my sister!!!!
	e = object_add(enemy_type.type, tag);
	e->img_delay = 0;
	e->img_i = 0;
	e->height = enemy_type.height; //al_get_bitmap_height(e->img);
	e->width = enemy_type.width; //al_get_bitmap_width(e->img);
	e->x = x;
	e->vx = enemy_type.vx; //+ (1 - (rand() % 2)); // Uncertainty principle
	e->vy = enemy_type.vy; //+ (1 - (rand() % 2)); // Uncertainty principle
	e->y = y;
	e->frame_delay = enemy_type.frame_delay;
	e->vector_size = enemy_type.vector_size;
	e->life = enemy_type.life;
	//strcpy(e->String, enemy_type.String);
	strcpy_s(e->String, sizeof(e->String), enemy_type.String);
	return e;
}
Пример #10
0
/* 
 *  call-seq:
 *     QueryParser.new(options = {}) -> QueryParser
 *
 *  Create a new QueryParser. The QueryParser is used to convert string
 *  queries into Query objects. The options are;
 *
 *  === Options
 *
 *  :default_field::        Default: "*" (all fields). The default field to
 *                          search when no field is specified in the search
 *                          string. It can also be an array of fields.
 *  :analyzer::             Default: StandardAnalyzer. Analyzer used by the
 *                          query parser to parse query terms
 *  :wild_card_downcase::   Default: true. Specifies whether wild-card queries
 *                          should be downcased or not since they are not
 *                          passed through the parser
 *  :fields::               Default: []. Lets the query parser know what
 *                          fields are available for searching, particularly
 *                          when the "*" is specified as the search field
 *  :tokenized_fields::     Default: :fields. Lets the query parser know which
 *                          fields are tokenized so it knows which fields to
 *                          run the analyzer over.
 *  :validate_fields::      Default: false. Set to true if you want an
 *                          exception to be raised if there is an attempt to
 *                          search a non-existent field
 *  :or_default::           Default: true. Use "OR" as the default boolean
 *                          operator
 *  :default_slop::         Default: 0. Default slop to use in PhraseQuery
 *  :handle_parser_errors:: Default: true. QueryParser will quietly handle all
 *                          parsing errors internally. If you'd like to handle
 *                          them yourself, set this parameter to false.
 *  :clean_string::         Default: true. QueryParser will do a quick
 *                          once-over the query string make sure that quotes
 *                          and brackets match up and special characters are
 *                          escaped
 *  :max_clauses::          Default: 512. the maximum number of clauses
 *                          allowed in boolean queries and the maximum number
 *                          of terms allowed in multi, prefix, wild-card or
 *                          fuzzy queries when those queries are generated by
 *                          rewriting other queries
 */                   
static VALUE
frt_qp_init(int argc, VALUE *argv, VALUE self)
{
    VALUE roptions;
    VALUE rval;
    Analyzer *analyzer = NULL;
    bool has_options = false;

    HashSet *all_fields = NULL;
    HashSet *tkz_fields = NULL;
    HashSet *def_fields = NULL;
    QParser *qp;

    if (rb_scan_args(argc, argv, "01", &roptions) > 0) {
        if (TYPE(roptions) == T_HASH) {
            has_options = true;
            if (Qnil != (rval = rb_hash_aref(roptions, sym_default_field))) {
                def_fields = frt_get_fields(rval);
            }
            if (Qnil != (rval = rb_hash_aref(roptions, sym_analyzer))) {
                analyzer = frt_get_cwrapped_analyzer(rval);
            }
            if (Qnil != (rval = rb_hash_aref(roptions, sym_all_fields))) {
                all_fields = frt_get_fields(rval);
            }
            if (Qnil != (rval = rb_hash_aref(roptions, sym_fields))) {
                all_fields = frt_get_fields(rval);
            }
            if (Qnil != (rval = rb_hash_aref(roptions, sym_tkz_fields))) {
                tkz_fields = frt_get_fields(rval);
            }
        } else {
            def_fields = frt_get_fields(roptions);
        }
    }
    if (all_fields == NULL) {
        all_fields = hs_new_str(&free);
    }

    if (!analyzer) {
        analyzer = mb_standard_analyzer_new(true);
    }

    qp = qp_new(all_fields, def_fields, tkz_fields, analyzer);
    qp->allow_any_fields = true;
    qp->clean_str = true;
    /* handle options */
    if (argc > 0) {
        if (Qnil != (rval = rb_hash_aref(roptions, sym_handle_parse_errors))) {
            qp->handle_parse_errors = RTEST(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_validate_fields))) {
            qp->allow_any_fields = !RTEST(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_wild_card_downcase))) {
            qp->wild_lower = RTEST(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_or_default))) {
            qp->or_default = RTEST(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_default_slop))) {
            qp->def_slop = FIX2INT(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_clean_string))) {
            qp->clean_str = RTEST(rval);
        }
        if (Qnil != (rval = rb_hash_aref(roptions, sym_max_clauses))) {
            qp->max_clauses = FIX2INT(rval);
        }
    }
    Frt_Wrap_Struct(self, frt_qp_mark, frt_qp_free, qp);
    object_add(qp, self);
    return self;
}
Пример #11
0
void _op_obj_import(void)
{
	t_context *C=ctx_get();
	char *filename=C->event->standby_string;

	if(filename)
	{
		// init list
		OBJECTS=lst_new("lst");

		// parse file
		t_file *file = file_new(filename);

		free(C->event->standby_string);
		//C->event->standby_function=NULL;
		C->event->callback=NULL;

		file_read(file);
		file_read_lines(file);

		//parse words
		t_link *link;
		t_link *l;
		t_word *word;

		for(link=file->lines->first;link;link=link->next)
		{
			t_line *line = link->data;
			line_read_words(line);
		}

		// parse tokens
		int object_start;
		int line_object;
		int is_face;
		//int tot_object;
		int tot_vert;
		int tot_face;
		int tot_tri;
		int tot_quad;
		int tot_indice;

		char *object_name;

		//tot_object=0;
		tot_face=0;
		tot_quad=0;
		tot_tri=0;
		object_start=0;
		
		for(link=file->lines->first;link;link=link->next)
		{
			// LINE
			t_line *line = link->data;

			// RESET
			is_face=0;

			for(l=line->words->first;l;l=l->next)
			{
				// WORD

				word=l->data;

				if(word_equal(word,"o"))
				{
					if(object_start)
					{
						obj_add(object_name,tot_vert,tot_face,tot_quad,tot_tri);

						tot_vert=0;
						tot_face=0;
						tot_quad=0;
						tot_tri=0;
					
						free(object_name);
					}
					else
					{
						object_start=1;
					}

					tot_vert=0;
					line_object=1;
				}
				else if(line_object)
				{
					object_name=(char *)malloc(sizeof(char)*(strlen(word->data)+1));
					strcpy(object_name,word->data);
					line_object=0;
				}
				else if(word_equal(word,"v"))
				{
					tot_vert++;
				}
				else if(word_equal(word,"f"))
				{
					tot_face++;
					is_face=1;
					tot_indice=0;
				}
				else if(is_face)
				{
					tot_indice++;
				}
				else if(word_equal(word,"usemtl"))
				{
				}
				else if(word_equal(word,"s"))
				{
				}
			}

			if(is_face)
			{
				if(tot_indice==4)
				{
					tot_quad++;
				}
				else
				{
					tot_tri++;
				}
			}
		}

		// add last object
		obj_add(object_name,tot_vert,tot_face,tot_quad,tot_tri);

		// vars
		int is_data=0;
		int indice_vertex=0;
		int indice_face=0;
		int cursor_tri=0;
		int cursor_quad=0;
		int global_cursor=0;
		int tmp_global_cursor=0;
		int face[4];

		object_start=0;

		t_token_type token;
		t_link *link_object;
		t_obj *obj;

		for(link=file->lines->first;link;link=link->next)
		{
			// LINE

			t_line *line = link->data;
			
			// reset
			is_data=0;
			indice_face=0;

			for(l=line->words->first;l;l=l->next)
			{
				// WORD

				word=l->data;

				if(word_equal(word,"o"))
				{
					token=token_object;

					if(object_start)
					{
						if(link_object->next) link_object=link_object->next;
						obj=link_object->data;
						// global cursor
						global_cursor+=tmp_global_cursor;
						tmp_global_cursor=obj->tot_vert;
					}
					//first
					else
					{
						link_object=OBJECTS->first;
						obj=link_object->data;
						object_start=1;
						tmp_global_cursor=obj->tot_vert;
					}

					indice_vertex=0;
					indice_face=0;
					cursor_tri=0;
					cursor_quad=0;
				}
				else if(word_equal(word,"v"))
				{
					token=token_vertex;
				}
				else if(word_equal(word,"f"))
				{
					token=token_face;
				}
				else if(word_equal(word,"usemtl"))
				{
					token=token_material;
				}
				else if(word_equal(word,"s"))
				{
					token=token_unknown;
				}
				else
				{
					is_data=1;
				}

				if(is_data)
				{
					if(token==token_vertex)
					{
						obj->verts[indice_vertex]=atof(word->data);
						indice_vertex++;
					}
					else if(token==token_face)
					{
						face[indice_face]=atoi(word->data);
						indice_face++;
					}
				}
			}

			// store face indice
			if(token==token_face)
			{
				int i;
				if(indice_face==3)
				{
					for(i=0;i<3;i++)
					{
						obj->tris[cursor_tri]=face[i]-global_cursor-1;
						cursor_tri++;
					}
				}
				else
				{
					for(i=0;i<4;i++)
					{
						obj->quads[cursor_quad]=face[i]-global_cursor-1;
						cursor_quad++;
					}
				}
			}
		}

		
		// add objects to scene

		C->scene->store=1;

		for(link=OBJECTS->first;link;link=link->next)
		{
			t_obj *obj = link->data;

			// new mesh
			t_node *node_mesh=mesh_make(
						obj->name,
						//"me_obj",
						obj->tot_vert,
						obj->tot_face,
						obj->tot_quad,
						obj->tot_tri,
						obj->verts,
						obj->quads,
						obj->tris);


			// new object
			t_node *node_object=object_add("mesh",obj->name);

			// link
			t_object *object=node_object->data;
			object->cls->link(object,node_mesh);
		}

		C->scene->store=0;

		// free obj

		for(link=OBJECTS->first;link;link=link->next)
		{
			t_obj *obj = link->data;
			obj_free(obj);
		}
	}
}