Exemplo n.º 1
0
func (m *Map) Tiles(x, y int) []*MapTile {
	var length C.int
	c_tiles := C.al_get_tiles((*C.ALLEGRO_MAP)(m), C.int(x), C.int(y), &length)
	ptr := uintptr(unsafe.Pointer(c_tiles))

	tiles := make([]*MapTile, int(length))
	for i := range tiles {
		tiles[i] = (*MapTile)(unsafe.Pointer(ptr + uintptr(i)))
	}

	// When the list of tiles is garbage-collected, make sure the C list
	// backing it is freed.
	runtime.SetFinalizer(tiles, func(x []*MapTile) {
		C._al_free(unsafe.Pointer(c_tiles))
	})

	return tiles
}
Exemplo n.º 2
0
func (l MapLayer) Objects() []*MapObject {
	var length C.int
	c_objects := C.al_get_objects((*C.ALLEGRO_MAP_LAYER)(l.raw), &length)
	ptr := uintptr(unsafe.Pointer(c_objects))

	objects := make([]*MapObject, int(length))
	for i := range objects {
		objects[i] = (*MapObject)(unsafe.Pointer(ptr + uintptr(i)))
	}

	// When the list of objects is garbage-collected, make sure the C list
	// backing it is freed.
	runtime.SetFinalizer(objects, func(x []*MapObject) {
		C._al_free(unsafe.Pointer(c_objects))
	})

	return objects
}