コード例 #1
0
ファイル: deque.c プロジェクト: atroel/basics
static int del_after()
{
	B6_DEQUE_DEFINE(deque);
	struct b6_sref sref[3];
	int i;

	for (i = 0; i < b6_card_of(sref); i += 1)
		if (&sref[i] != b6_deque_add_last(&deque, &sref[i]))
			return 0;

	for (i = 0; i < b6_card_of(sref); i += 1) {
		if (&sref[b6_card_of(sref) - 1] != b6_deque_last(&deque))
			return 0;

		if (&sref[i] != b6_deque_del_after(&deque, b6_deque_head(&deque)))
			return 0;
	}

	if (b6_deque_head(&deque) != b6_deque_last(&deque))
		return 0;

	if (!b6_deque_empty(&deque))
		return 0;

	return 1;
}
コード例 #2
0
ファイル: deque.c プロジェクト: atroel/basics
static int walk()
{
	B6_DEQUE_DEFINE(deque);
	struct b6_sref sref[16];
	struct b6_sref *iter;
	int i;

	for (i = 0; i < b6_card_of(sref); i += 1)
		if (&sref[i] != b6_deque_add_last(&deque, &sref[i]))
			return 0;

	for (i = 0, iter = b6_deque_first(&deque); iter != b6_deque_tail(&deque);
	     iter = b6_deque_walk(&deque, iter, B6_NEXT), i += 1)
		if (iter != &sref[i])
			return 0;

	if (i != b6_card_of(sref))
		return 0;

	for (i = 0, iter = b6_deque_last(&deque); iter != b6_deque_head(&deque);
	     iter = b6_deque_walk(&deque, iter, B6_PREV), i += 1)
		if (iter != &sref[b6_card_of(sref) - 1 - i])
			return 0;

	if (i != b6_card_of(sref))
		return 0;

	return 1;
}
コード例 #3
0
ファイル: list.c プロジェクト: atroel/basics
static int walk()
{
	B6_LIST_DEFINE(list);
	struct b6_dref dref[16];
	struct b6_dref *iter;
	int i;

	for (i = 0; i < b6_card_of(dref); i += 1)
		if (&dref[i] != b6_list_add_last(&list, &dref[i]))
			return 0;

	for (i = 0, iter = b6_list_first(&list); iter != b6_list_tail(&list);
	     iter = b6_list_walk(iter, B6_NEXT), i += 1)
		if (iter != &dref[i])
			return 0;

	if (i != b6_card_of(dref))
		return 0;

	for (i = 0, iter = b6_list_last(&list); iter != b6_list_head(&list);
	     iter = b6_list_walk(iter, B6_PREV), i += 1)
		if (iter != &dref[b6_card_of(dref) - 1 - i])
			return 0;

	if (i != b6_card_of(dref))
		return 0;

	return 1;
}
コード例 #4
0
ファイル: list.c プロジェクト: atroel/basics
static int del()
{
	B6_LIST_DEFINE(list);
	struct b6_dref dref[3];
	int i;

	for (i = 0; i < b6_card_of(dref); i += 1)
		if (&dref[i] != b6_list_add_last(&list, &dref[i]))
			return 0;

	for (i = 0; i < b6_card_of(dref); i += 1) {
		if (&dref[b6_card_of(dref) - 1] != b6_list_last(&list))
			return 0;

		if (&dref[i] != b6_list_del(&dref[i]))
			return 0;
	}

	if (b6_list_head(&list) != b6_list_last(&list))
		return 0;

	if (!b6_list_empty(&list))
		return 0;

	return 1;
}
コード例 #5
0
ファイル: level.c プロジェクト: cmatsuoka/open-greedy
int __open_level(struct level *self, struct layout *layout)
{
	int i;
	struct place* places[2];
	for (i = 0; i < b6_card_of(self->places); i += 1) {
		struct place *place = &self->places[i];
		initialize_place(self, layout, place);
		self->nplaces += !!place->item;
	}
	places[0] = self->items->teleport[0].place;
	places[1] = self->items->teleport[1].place;
	if (places[0] && places[1]) {
		self->items->teleport[0].place = places[1];
		self->items->teleport[1].place = places[0];
		if (places[0]->item != &self->items->teleport[0].item)
			dispose_item(&self->items->teleport[0].item);
		if (places[1]->item != &self->items->teleport[1].item)
			dispose_item(&self->items->teleport[1].item);
	} else if (places[0]) {
		int x, y;
		place_location(self, places[0], &x, &y);
		log_w("ignored single teleport at (%d,%d).", x, y);
		dispose_item(places[0]->item);
		places[0]->item = clone_empty(self->items);
	}
	b6_assert(!places[1] || (places[1] && places[0]));
	recover_ghosts_den(self, layout);
	if (self->pacman_home)
		return 0;
	__close_level(self);
	return -1;
}
コード例 #6
0
static void hall_of_fame_phase_exit(struct phase *up)
{
	struct hall_of_fame_phase *self =
		b6_cast_of(up, struct hall_of_fame_phase, up);
	int i;
	finalize_fade_io(&self->fade_io);
	if (self->entry) {
		save_hall_of_fame(&up->engine->hall_of_fame);
		self->entry = NULL;
	}
	if (self->music) {
		stop_music(up->engine->mixer);
		unload_music(up->engine->mixer);
	}
	del_controller_observer(&self->controller_observer);
	del_renderer_observer(&self->renderer_observer);
	if (self->cursor_base) {
		finalize_toolkit_label(&self->cursor_label);
		destroy_renderer_base(self->cursor_base);
	}
	for (i = 0; i < b6_card_of(self->label); i += 1)
		finalize_toolkit_label(&self->label[i]);
	if (self->panel) {
		destroy_renderer_texture(self->panel->texture);
		destroy_renderer_tile(self->panel);
	}
	if (self->background) {
		destroy_renderer_texture(self->background->texture);
		destroy_renderer_tile(self->background);
	}
	finalize_fixed_font(&self->font);
	close_hall_of_fame(self->array);
}
コード例 #7
0
ファイル: list.c プロジェクト: atroel/basics
static int add()
{
	B6_LIST_DEFINE(list);
	struct b6_dref dref[3];
	struct b6_dref temp;
	struct b6_dref *iter;
	int i;

	for (i = 0, iter = b6_list_tail(&list); i < b6_card_of(dref); i += 1) {
		iter = b6_list_add(iter, &dref[i]);

		if (iter != &dref[i])
			return 0;

		if (b6_list_empty(&list))
			return 0;
	}

	iter = b6_list_add(&dref[0], &temp);

	if (iter != &temp)
		return 0;

	if (b6_list_empty(&list))
		return 0;

	return 1;
}
コード例 #8
0
ファイル: level.c プロジェクト: cmatsuoka/open-greedy
void __close_level(struct level *self)
{
	int i;
	for (i = 0; i < b6_card_of(self->places); i += 1)
		if (self->places[i].item)
			dispose_item(self->places[i].item);
	mark_level_as_closed(self);
}
コード例 #9
0
void initialize_fixed_font(struct fixed_font *self, const struct rgba *rgba,
			   unsigned short int *x, unsigned short int *y,
			   unsigned short int w, unsigned short int h)
{
	int i;
	for (i = 0; i < b6_card_of(self->rgba); i += 1) {
		initialize_rgba(&self->rgba[i], w, h);
		copy_rgba(rgba, x[i], y[i], w, h, &self->rgba[i], 0, 0);
	}
}
コード例 #10
0
ファイル: io.c プロジェクト: atroel/open-greedy
static FILE *platform_fopen(const char *path, const char *mode)
{
#ifndef _WIN32
	return fopen(path, mode);
#else
	wchar_t w_path[MAX_PATH];
	wchar_t w_mode[128];
	size_t len;
	len = strlen(path);
	len = MultiByteToWideChar(CP_UTF8, 0, path, len, w_path, len);
	if (!len || len >= b6_card_of(w_path))
		return NULL;
	w_path[len] = L'\0';
	len = strlen(mode);
	len = MultiByteToWideChar(CP_UTF8, 0, mode, len, w_mode, len);
	if (!len || len >= b6_card_of(w_mode))
		return NULL;
	w_mode[len] = L'\0';
	return _wfopen(w_path, w_mode);
#endif
}
コード例 #11
0
static unsigned short int get_fixed_font_text_width(const struct fixed_font *f,
						    const struct b6_utf8 *utf8)
{
	unsigned short int w = 0;
	struct b6_utf8_iterator iter;
	b6_setup_utf8_iterator(&iter, utf8);
	while (b6_utf8_iterator_has_next(&iter)) {
		const int i = b6_utf8_iterator_get_next(&iter) - ' ';
		if (i < 0 || i >= b6_card_of(f->rgba))
			continue;
		w += f->rgba[i].w;
	}
	return w;
}
コード例 #12
0
void render_fixed_font(const struct fixed_font *self,
		       const struct b6_utf8 *utf8, struct rgba *rgba,
		       unsigned short int x, unsigned short int y)
{
	struct b6_utf8_iterator iter;
	b6_setup_utf8_iterator(&iter, utf8);
	while (b6_utf8_iterator_has_next(&iter)) {
		int i = b6_utf8_iterator_get_next(&iter) - ' ';
		const struct rgba *from;
		if (i < 0 || i >= b6_card_of(self->rgba))
			continue;
		from = &self->rgba[i];
		copy_rgba(from, 0, 0, from->w, from->h, rgba, x, y);
		x += from->w;
	}
}
コード例 #13
0
ファイル: list.c プロジェクト: atroel/basics
static int add_last()
{
	B6_LIST_DEFINE(list);
	struct b6_dref dref[2];
	int i;

	for (i = 0; i < b6_card_of(dref); i += 1) {
		if (&dref[i] != b6_list_add_last(&list, &dref[i]))
			return 0;

		if (&dref[i] != b6_list_last(&list))
			return 0;

		if (b6_list_empty(&list))
			return 0;
	}

	return 1;
}
コード例 #14
0
void finalize_fixed_font(struct fixed_font *self)
{
	int i;
	for (i = 0; i < b6_card_of(self->rgba); i += 1)
		finalize_rgba(&self->rgba[i]);
}
コード例 #15
0
static int hall_of_fame_phase_init(struct phase *up, const struct phase *prev)
{
	static const struct controller_observer_ops controller_observer_ops = {
		.on_key_pressed = on_key_pressed,
		.on_text_input = on_text_input,
	};
	static const struct renderer_observer_ops renderer_observer_ops = {
		.on_render = on_render,
	};
	struct hall_of_fame_phase *self =
		b6_cast_of(up, struct hall_of_fame_phase, up);
	struct renderer *renderer = get_engine_renderer(up->engine);
	struct renderer_base *root;
	unsigned short int font_w, font_h;
	struct hall_of_fame_iterator iter;
	struct data_entry *entry;
	struct istream *is;
	const char *skin_id = hof_skin ? hof_skin : get_skin_id();
	int i;
	self->array = open_hall_of_fame(&up->engine->hall_of_fame,
					up->engine->layout_provider->id,
					up->engine->game_config->entry.id);
	if (!self->array)
		return -1;
	if (b6_utf8_is_empty(&self->name.utf8)) {
		struct b6_utf8 utf8;
		if (user || (user = get_user_name()))
			b6_utf8_from_ascii(&utf8, user);
		else
			b6_clone_utf8(&utf8, B6_UTF8("PLAYER"));
		b6_clear_utf8_string(&self->name);
		b6_extend_utf8_string(&self->name, &utf8);
	}
	self->entry = NULL;
	self->quit = 0;
	if (prev == lookup_phase(B6_UTF8("game"))) {
		struct game_result game_result;
		get_last_game_result(up->engine, &game_result);
		self->entry = amend_hall_of_fame(self->array,
						 game_result.level + 1,
						 game_result.score);
		if (!self->entry)
			self->quit = 1;
		else
			alter_hall_of_fame_entry(self->entry, &self->name.utf8);
	}
	root = get_renderer_base(renderer);
	if (make_font(&self->font, skin_id, HOF_FONT_DATA_ID))
		return -1;
	font_w = get_fixed_font_width(&self->font);
	font_h = get_fixed_font_height(&self->font);

	if ((self->background = create_renderer_tile(renderer, root, 0, 0,
						     640, 480, NULL)))
		set_renderer_tile_texture(self->background, make_texture(
				renderer, skin_id, HOF_BACKGROUND_DATA_ID));
	if ((self->panel = create_renderer_tile(renderer, root, 0, 0, 112, 480,
						NULL)))
		set_renderer_tile_texture(self->panel, make_texture(
				renderer, skin_id, HOF_PANEL_DATA_ID));
	for (i = 0; i < b6_card_of(self->label); i += 1) {
		const unsigned short int u = 2 + 32 * font_w, v = 2 + font_h;
		const float x = 96, y = 50 + i * 40;
		const float w = 2 + 32 * 16, h = 2 + 16;
		initialize_toolkit_label(&self->label[i], renderer,
					 &self->font, u, v, root, x, y, w, h);
		enable_toolkit_label_shadow(&self->label[i]);
	}
	reset_hall_of_fame_iterator(&iter, self->array);
	for (i = 0; i < b6_card_of(self->label); i += 1) {
		struct b6_json_object *entry;
		if (!hall_of_fame_iterator_has_next(&iter))
			break;
		entry = hall_of_fame_iterator_get_next(&iter);
		if (entry == self->entry)
			self->rank = i;
		setup_label(self, i, entry);
	}
	for (; i < b6_card_of(self->label); i += 1)
		hide_toolkit_label(&self->label[i]);
	if (self->entry) {
		float x = self->label[self->rank].image[0].tile->x +
			(16 + self->name.utf8.nchars) * 16;
		float y = self->label[self->rank].image[0].tile->y;
		self->cursor_base = create_renderer_base_or_die(renderer, root,
								"cursor", x, y);
		initialize_toolkit_label(&self->cursor_label, renderer,
					 &self->font, 16, 16,
					 self->cursor_base, 1, 1, 16, 16);
		enable_toolkit_label_shadow(&self->cursor_label);
		set_toolkit_label(&self->cursor_label, &b6_utf8_char['#']);
	} else
		self->cursor_base = NULL;
	add_renderer_observer(renderer, setup_renderer_observer(
			&self->renderer_observer, "hof",
			&renderer_observer_ops));
	add_controller_observer(get_engine_controller(up->engine),
				setup_controller_observer(
					&self->controller_observer,
					&controller_observer_ops));
	self->music = 0;
	initialize_fade_io(&self->fade_io, "hof_fade_io", renderer,
			   up->engine->clock, 0., 1., 5e-6);
	if (self->quit) {
		set_fade_io_target(&self->fade_io, 0.);
		return 0;
	}
	if ((entry = lookup_data(skin_id, audio_data_type,
				 HOF_MUSIC_DATA_ID)) &&
	    (is = get_data(entry))) {
		int retval = up->engine->mixer->ops->load_music_from_stream(
			up->engine->mixer, is);
		if (!retval) {
			play_music(up->engine->mixer);
			self->music = 1;
		} else
			log_w(_s("could not load background music"));
		put_data(entry, is);
	} else
		log_w(_s("cannot find background music"));
	return 0;
}