Exemplo n.º 1
0
Arquivo: map.c Projeto: janisz/unix
void setRooms(Map *m)
{
	for (int i=0; i<MAP_SIZE(*m); i++) {
		if (m->map[i] == ROOM) {
			int *p = (int*)malloc(sizeof(int));
			*p = i;
			arraylist_add(m->rooms, (void*)p);
		}
	}
}
Exemplo n.º 2
0
Arquivo: map.c Projeto: janisz/unix
void deleteMap(Map *map)
{
	for (int i=0; i<MAP_SIZE(*map); i++) {
		pthread_mutex_destroy(&map->mutexs[i]);
	}
	map->width = map->height = 0;
	free(map->map);
	map = NULL;
	free(map->mutexs);
	map->mutexs = NULL;
	arraylist_destroy(map->rooms);
}
Exemplo n.º 3
0
Arquivo: map.c Projeto: janisz/unix
Map createMap(int width, int height, char *map)
{
	Map m;
	m.width = width;
	m.height = height;
	m.map = (char*)malloc(sizeof(char)*MAP_SIZE(m));
	assert(m.map);
	m.mutexs = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)*MAP_SIZE(m));
	assert(m.mutexs);
	m.rooms = arraylist_create();

	for (int i=0; i<MAP_SIZE(m); i++) {
		pthread_mutex_init(&m.mutexs[i], NULL);
	}

	strncpy(m.map, map, MAP_SIZE(m));

	setRooms(&m);

	return m;
}
Exemplo n.º 4
0
struct Map * map_create(int width, int height)
{
    struct Map *map;
    int size;

    map = malloc(sizeof(struct Map));
    memset(map, 0, sizeof(struct Map));
    map->width = width;
    map->height = height;
    size = MAP_SIZE(map);
    map->map = malloc(sizeof(struct Point)*size);
    memset(map->map, 0, sizeof(struct Point)*size);

    return map;
}
Exemplo n.º 5
0
struct Point * map_find_longest_path(struct Map *map)
{
    struct Point *point, *best = NULL;
    int i, mapsize;

    mapsize = MAP_SIZE(map);
    for( i = 0 ; i < mapsize ; i++ ) {
        point = MAP_POINT_INDEX(map, i);
        if( !point->path_found ) {
            map_find_path(map, point->x, point->y);
            if( !best || POINT_PATH_GT(point, best) )
                best = point;
        }
    }

    return best;
}
Exemplo n.º 6
0
Arquivo: map.c Projeto: janisz/unix
void printMap(Map map)
{
	if (MAP_SIZE(map) < 1) {
		printf("Map is not loaded\n");
		return;
	}
	printf("%d %d\n", map.width, map.height);
	for (int j=0; j<map.height; j++) {
		for (int i=0; i<map.width; i++) {
			printf("%c", map.map[indexOnMap(map, i, j)]);
		}
		printf("\n");
	}

	printf("Rooms:\n");

	printRooms(&map);
}
Exemplo n.º 7
0
static int map_count_elements(zval *obj, zend_long *count)
{
    *count = MAP_SIZE(Z_MAP_P(obj));
    return SUCCESS;
}
Exemplo n.º 8
0
svalue_t *
f_psyc_render(svalue_t *sp) {
    uint8_t i;
    vector_t *v;
    string_t *out;
    char *meth, *body;
    size_t mlen, blen;
    mapping_t *map;

    psycPacket packet;
    psycHeader headers[2];

    // unless (sp->type == T_POINTER) return sp;
    v = sp->u.vec;
    if (VEC_SIZE(v) == PACKET_BODY + 1) {
	for (i = PACKET_ROUTING; i <= PACKET_ENTITY; i++) {
	    headers[i].lines = 0;
	    if (v->item[i].type == T_MAPPING) {
		map = v->item[i].u.map;
		if (!MAP_SIZE(map)) continue;

		headers[i].modifiers = malloc(sizeof(psycModifier) * MAP_SIZE(v->item[i].u.map));
		if (!headers[i].modifiers) {
		    errorf("Out of memory in psyc_render for modifier table.\n");
		    return sp; // not reached
		}

		walk_mapping(map, &fill_header_from_mapping,
		             &(psyc_modifier_t) {
		                 &headers[i], map->num_values,
		                 i == PACKET_ROUTING ?
		                     PSYC_MODIFIER_ROUTING :
		                     PSYC_MODIFIER_CHECK_LENGTH
		             });
	    }
	    // else ... ignoring possibly invalid args
	}
    } else {
	errorf("Wrong number of elements (%" PRIdMPINT ") "
	       "in array argument to psyc_render()\n", VEC_SIZE(v));
	return sp; // not reached
    }

    if (v->item[PACKET_METHOD].type == T_STRING) {
	meth = get_txt(v->item[PACKET_METHOD].u.str);
	mlen = mstrsize(v->item[PACKET_METHOD].u.str);
    } else {
	meth = NULL;
	mlen = 0;
    }

    if (v->item[PACKET_BODY].type == T_STRING) {
	body = get_txt(v->item[PACKET_BODY].u.str);
	blen = mstrsize(v->item[PACKET_BODY].u.str);
    } else {
	body = NULL;
	blen = 0;
    }

    packet = psyc_newPacket2(headers[PACKET_ROUTING].modifiers,
                             headers[PACKET_ROUTING].lines,
                             headers[PACKET_ENTITY].modifiers,
                             headers[PACKET_ENTITY].lines,
                             meth, mlen, body, blen,
                             PSYC_PACKET_CHECK_LENGTH);

#ifdef DEBUG
    printf("rendering... packet.length = %ld\n", packet.length);
#endif
    // alloc_mstring creates an *untabled* string suitable for tmp data 
    memsafe(out = alloc_mstring(packet.length), packet.length, "f_psyc_render");
    psyc_render(&packet, get_txt(out), packet.length);

    free_svalue(sp);
    put_string(sp, out);
    // stack should take care of freeing the string after use
    return sp;

} /* f_psyc_render */