Пример #1
0
PRODUCTION * production_create (const char l, const char * exp) {
  PRODUCTION * p = xph_alloc (sizeof (PRODUCTION));
  p->l = l;
  p->exp = dynarr_create (2, sizeof (char *));
  production_addRule (p, exp);
  return p;
}
Пример #2
0
int main(void) {
    DynArr dynarr;
    int i;

    dynarr_create(&dynarr);

    printf("Enter numbers! Stop input by entering not a number.\n");
    for (;;) {
        int num;
        printf("Enter number: ");
        if (scanf("%d", &num) == 1) {
            if (dynarr_append(&dynarr, num) == 0) {
                printf("\n\nError!\n");
                return 1;
            }
        } else {
            break;
        }
    }

    printf("You have entered:");
    for (i = 0; i < dynarr_length(&dynarr); ++i) {
        printf(" %d", dynarr_get(&dynarr, i));
    }
    printf("\n");

    dynarr_destroy(&dynarr);

    return 0;
}
Пример #3
0
static void chaser_create (EntComponent comp, EntSpeech speech)
{
    Chaser
    chaser = xph_alloc (sizeof (struct xph_chaser));
    chaser->targets = dynarr_create (2, sizeof (struct chase_target_info *));

    component_setData (comp, chaser);
}
Пример #4
0
// FIXME: we have to set the gui dimensions before creating the optlayout because there's not a good place to put the continue/cancel init aside from here. this is part of a general problem of not really being able to resize anything
void optlayout_create (EntComponent comp, EntSpeech speech)
{
	struct optlayout
		* layout = xph_alloc (sizeof (struct optlayout));
	layout->options = dynarr_create (2, sizeof (Entity));

	component_setData (comp, layout);

	Entity
		this = component_entityAttached (comp);
	int
		x, y,
		w, h,
		hm, vm,
		fontHeight;

	gui_xy (this, &x, &y);
	gui_wh (this, &w, &h);
	gui_vhMargin (this, &hm, &vm);
	fontHeight = fontLineHeight ();

	layout->confirm = entity_create ();
	component_instantiate ("gui", layout->confirm);
	component_instantiate ("clickable", layout->confirm);
	component_instantiate ("input", layout->confirm);
	component_instantiate ("textlabel", layout->confirm);
	entity_refresh (layout->confirm);
	gui_place (layout->confirm, x, y + h - (vm * 2 + fontHeight), w / 2, fontHeight + vm);
	gui_setFrame (layout->confirm, this);
	clickable_setClickCallback (layout->confirm, NULL);
	textlabel_set (layout->confirm, "Continue", ALIGN_CENTRE, x, y + h - (vm * 2 + fontHeight), w / 2);

	layout->cancel = entity_create ();
	component_instantiate ("gui", layout->cancel);
	component_instantiate ("clickable", layout->cancel);
	component_instantiate ("input", layout->cancel);
	component_instantiate ("textlabel", layout->cancel);
	entity_refresh (layout->cancel);
	gui_place (layout->cancel, x + w / 2, y + h - (vm * 2 + fontHeight), w / 2, fontHeight + vm);
	gui_setFrame (layout->cancel, this);
	clickable_setClickCallback (layout->cancel, optlayout_cancelCallback);
	textlabel_set (layout->cancel, "Cancel", ALIGN_CENTRE, x + w / 2, y + h - (vm * 2 + fontHeight), w / 2);
}
Пример #5
0
LSYSTEM * lsystem_create () {
  LSYSTEM * l = xph_alloc (sizeof (LSYSTEM));
  l->p = dynarr_create (4, sizeof (PRODUCTION *));
  return l;
}
Пример #6
0
void textureFloodFill (TEXTURE t, signed int startX, signed int startY)
{
	unsigned char
		replaceColor[4] = {0, 0, 0, 0};
	struct txpx {
		signed int
			x,y;
	} * current,
	  * next;
	VECTOR3
		loc;
	Dynarr
		affectedPixels;

	if (TextureColor[3] == 0x00)
	{
		ERROR ("Can't flood fill with a transparent color.");
		return;
	}

	loc = vectorCreate (startX, startY, 0);
	
	if (textureOOB (t, loc))
	{
		INFO ("Can't centre flood at %d, %d; it's out of bounds of image (%dx%d)", startX, startY, t->width, t->height);
		return;
	}
	affectedPixels = dynarr_create (64, sizeof (struct txpx *));
	memcpy (replaceColor, textureColorAt (t, loc), t->mode);

	current = xph_alloc (sizeof (struct txpx));
	current->x = startX;
	current->y = startY;
	dynarr_queue (affectedPixels, current);

	while (!dynarr_isEmpty (affectedPixels))
	{
		current = *(struct txpx **)dynarr_dequeue (affectedPixels);
		//printf ("got: %d, %d\n", current->x, current->y);
		loc = vectorCreate (current->x, current->y, 0);
		if (textureOOB (t, loc))
		{
		}
		else if (memcmp (replaceColor, textureColorAt (t, loc), t->mode) == 0)
		{
			textureDrawPixel (t, loc);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x + 1;
			next->y = current->y;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x;
			next->y = current->y + 1;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x - 1;
			next->y = current->y;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x;
			next->y = current->y - 1;
			dynarr_queue (affectedPixels, next);
		}
		xph_free (current);
	}

	INFO ("FINAL SIZE: %d ENTRIES", dynarr_capacity (affectedPixels));
	dynarr_destroy (affectedPixels);
}