コード例 #1
0
ファイル: plane.test.c プロジェクト: ennorehling/eressea
static void test_plane(CuTest *tc) {
    struct region *r;
    plane *pl;

    test_setup();
    r = test_create_region(0, 0, NULL);
    CuAssertPtrEquals(tc, NULL, findplane(0, 0));
    CuAssertPtrEquals(tc, NULL, getplane(r));
    CuAssertIntEquals(tc, 0, getplaneid(r));
    CuAssertPtrEquals(tc, NULL, getplanebyid(0));
    CuAssertIntEquals(tc, 0, plane_center_x(0));
    CuAssertIntEquals(tc, 0, plane_center_y(0));
    CuAssertIntEquals(tc, 0, plane_width(0));
    CuAssertIntEquals(tc, 0, plane_height(0));
    CuAssertPtrEquals(tc, NULL, get_homeplane());

    pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15);
    r = test_create_region(4, 40, 0);
    CuAssertIntEquals(tc, 15, pl->flags);
    CuAssertIntEquals(tc, 4, pl->minx);
    CuAssertIntEquals(tc, 8, pl->maxx);
    CuAssertIntEquals(tc, 40, pl->miny);
    CuAssertIntEquals(tc, 80, pl->maxy);
    CuAssertPtrEquals(tc, NULL, pl->attribs);
    CuAssertStrEquals(tc, "Hell", pl->name);
    CuAssertPtrEquals(tc, pl, findplane(4, 40));
    CuAssertPtrEquals(tc, pl, getplane(r));
    CuAssertPtrEquals(tc, pl, getplanebyid(1));
    CuAssertIntEquals(tc, 1, getplaneid(r));
    CuAssertIntEquals(tc, 6, plane_center_x(pl));
    CuAssertIntEquals(tc, 60, plane_center_y(pl));
    CuAssertIntEquals(tc, 5, plane_width(pl));
    CuAssertIntEquals(tc, 41, plane_height(pl));
    test_teardown();
}
コード例 #2
0
ファイル: bind_region.c プロジェクト: stm2/server
static int tolua_region_create(lua_State * L)
{
    int x = (int)tolua_tonumber(L, 1, 0);
    int y = (int)tolua_tonumber(L, 2, 0);
    const char *tname = tolua_tostring(L, 3, 0);
    if (tname) {
        plane *pl = findplane(x, y);
        const terrain_type *terrain = get_terrain(tname);
        region *r, *result;
        if (!terrain) {
            return 0;
        }

        assert(!pnormalize(&x, &y, pl));
        r = result = findregion(x, y);

        if (r != NULL && r->units != NULL) {
            /* TODO: error message */
            result = NULL;
        }
        else if (r == NULL) {
            result = new_region(x, y, pl, 0);
        }
        if (result) {
            terraform_region(result, terrain);
            if (result->land) {
                fix_demand(result);
            }
        }

        tolua_pushusertype(L, result, TOLUA_CAST "region");
        return 1;
    }
    return 0;
}
コード例 #3
0
ファイル: region.c プロジェクト: Xolgrim/server
int koor_distance(int x1, int y1, int x2, int y2)
{
    const plane *p1 = findplane(x1, y1);
    const plane *p2 = findplane(x2, y2);
    if (p1 != p2)
        return INT_MAX;
    else {
        int width = plane_width(p1);
        int height = plane_height(p1);
        if (width && height) {
            return koor_distance_wrap_xy(x1, y1, x2, y2, width, height);
        }
        else {
            return koor_distance_orig(x1, y1, x2, y2);
        }
    }
}
コード例 #4
0
ファイル: input.c プロジェクト: Freeaqingme/OpenBSD
int
getcommand(void)
{
	int	c, i, done;
	const char	*s, *(*func)(char);
	PLANE	*pp;

	rezero();

	do {
		c = gettoken();
		if (c == tty_new.c_cc[VERASE]) {
			if (pop() < 0)
				noise();
		} else if (c == tty_new.c_cc[VKILL]) {
			while (pop() >= 0)
				;
		} else {
			done = 0;
			for (i = 0; i < st[T_STATE].num_rules; i++) {
				if (st[T_STATE].rule[i].token == c ||
				    st[T_STATE].rule[i].token == tval) {
					push(i, (c >= ALPHATOKEN) ? tval : c);
					done = 1;
					break;
				}
			}
			if (!done)
				noise();
		}
	} while (T_STATE != -1);

	if (level == 1)
		return (1);	/* forced update */

	dest_type = T_NODEST;
	
	for (i = 0; i < level; i++) {
		func = st[stack[i].state].rule[stack[i].rule].func;
		if (func != NULL)
			if ((s = (*func)(stack[i].ch)) != NULL) {
				ioerror(stack[i].pos, strlen(stack[i].str), s);
				return (-1);
			}
	}

	pp = findplane(p.plane_no);
	if (pp->new_altitude != p.new_altitude)
		pp->new_altitude = p.new_altitude;
	else if (pp->status != p.status)
		pp->status = p.status;
	else {
		pp->new_dir = p.new_dir;
		pp->delayd = p.delayd;
		pp->delayd_no = p.delayd_no;
	}
	return (0);
}
コード例 #5
0
ファイル: input.c プロジェクト: dank101/386BSD
char	*
setplane(c)
{
	PLANE	*pp;

	pp = findplane(number(c));
	if (pp == NULL)
		return ("Unknown Plane");
	bcopy(pp, &p, sizeof (p));
	p.delayd = 0;
	return (NULL);
}
コード例 #6
0
ファイル: teapot.c プロジェクト: Distrotech/mesa-demos
static void initdlists(void)
{
  GLUquadricObj *lcone,*lbase;
  GLfloat plane[4];
  GLfloat v0[3]={0.0,0.0,0.0};
  GLfloat v1[3]={1.0,0.0,0.0};
  GLfloat v2[3]={0.0,1.0,0.0};

  findplane(plane,v0,v1,v2);
  shadowmatrix(baseshadow,plane,lightpos);

  teapotdlist=glGenLists(1);
  glNewList(teapotdlist,GL_COMPILE);
  glRotatef(90.0,1.0,0.0,0.0);
  glCullFace(GL_FRONT);
  glBindTexture(GL_TEXTURE_2D,t2id);
  glutSolidTeapot(0.75);
  glCullFace(GL_BACK);
  glEndList();

  basedlist=glGenLists(1);
  glNewList(basedlist,GL_COMPILE);
  drawbase();
  glEndList();

  lightdlist=glGenLists(1);
  glNewList(lightdlist,GL_COMPILE);
  glDisable(GL_LIGHTING);
 
  lcone=gluNewQuadric();
  lbase=gluNewQuadric();
  glRotatef(45.0,0.0,1.0,0.0);

  glColor3f(1.0,1.0,1.0);
  glCullFace(GL_FRONT);
  gluDisk(lbase,0.0,0.2,12.0,1.0);
  glCullFace(GL_BACK);

  glColor3f(0.5,0.0,0.0);
  gluCylinder(lcone,0.2,0.0,0.5,12,1);

  gluDeleteQuadric(lcone);
  gluDeleteQuadric(lbase);

  glEnable(GL_LIGHTING);
  glEndList();
}
コード例 #7
0
ファイル: autoseed.c プロジェクト: philbooth/server
/* E3A island generation */
int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize)
{
#define MIN_QUALITY 1000
    int nfactions = 0;
    region_list *rlist = NULL;
    region_list *island = NULL;
    plane *pl = findplane(x, y);
    region *r = findregion(x, y);
    int nsize = 1;
    int q, maxq = INT_MIN, minq = INT_MAX;

    if (!r)
        r = new_region(x, y, pl, 0);
    assert(!r->units);
    do {
        terraform_region(r, random_terrain_e3(NODIRECTION));
    } while (!r->land);

    while (r) {
        fset(r, RF_MARK);
        if (r->land) {
            if (nsize < minsize) {
                nsize += random_neighbours(r, &rlist, &random_terrain_e3);
            }
            else {
                nsize += random_neighbours(r, &rlist, &get_ocean);
            }
        }
        regionqueue_push(&island, r);
        r = regionqueue_pop(&rlist);
    }

    smooth_island(island);

    if (nsize > minsize / 2) {
        for (rlist = island; rlist; rlist = rlist->next) {
            r = rlist->data;
            if (r->land && fval(r, RF_MARK)) {
                region *rn[MAXDIRECTIONS];

                get_neighbours(r, rn);
                q = region_quality(r, rn);
                if (q >= MIN_QUALITY && nfactions < numfactions && *players) {
                    starting_region(players, r, rn);
                    minq = _min(minq, q);
                    maxq = _max(maxq, q);
                    ++nfactions;
                }
            }
        }

        for (rlist = island; rlist && nfactions < numfactions; rlist = rlist->next) {
            r = rlist->data;
            if (!r->land && fval(r, RF_MARK)) {
                region *rn[MAXDIRECTIONS];
                get_neighbours(r, rn);
                q = region_quality(r, rn);
                if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) {
                    starting_region(players, r, rn);
                    minq = _min(minq, q);
                    maxq = _max(maxq, q);
                    ++nfactions;
                }
            }
        }
    }

    for (rlist = island; rlist; rlist = rlist->next) {
        r = rlist->data;
        if (r->units) {
            region *rn[MAXDIRECTIONS];
            get_neighbours(r, rn);
            q = region_quality(r, rn);
            if (q - minq > (maxq - minq) * 2 / 3) {
                terraform_region(r, newterrain(T_HIGHLAND));
                prepare_starting_region(r);
            }
            r->land->money = 50000;   /* 2% = 1000 silver */
        }
        else if (r->land) {
            r->land->money *= 4;
        }
    }
    return nfactions;
}
コード例 #8
0
ファイル: projshadow.c プロジェクト: xtmacbook/SGI
/* Parse arguments, and set up interface between OpenGL and window system */
int
main(int argc, char *argv[])
{
    GLUquadricObj *sphere, *cone, *base;
    GLfloat v0[3], v1[3], v2[3];
    unsigned *floortex;
    int texcomps, texwid, texht;

    glutInit(&argc, argv);
    glutInitWindowSize(512, 512);
    if(argc > 1)
    {
	char *args = argv[1];
	int done = GL_FALSE;
	while(!done)
	{
	    switch(*args)
	    {
	    case 's': /* single buffer */
		printf("Single Buffered\n");
		dblbuf = GL_FALSE;
		break;
	    case '-': /* do nothing */
		break;
	    case 0:
		done = GL_TRUE;
		break;
	    }
	    args++;
	}
    }
    if(dblbuf)
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL|GLUT_DOUBLE);
    else
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);

    (void)glutCreateWindow("projection shadows");
    glutDisplayFunc(redraw);
    glutKeyboardFunc(key);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutReshapeFunc(reshape);

    glutCreateMenu(menu);
    glutAddMenuEntry("No Shadows", NONE);
    glutAddMenuEntry("Black Shadows", SHADOW_BLACK);
    glutAddMenuEntry("Shadows on Texture", SHADOW);
    glutAttachMenu(GLUT_RIGHT_BUTTON);


    /* draw a perspective scene */
    glMatrixMode(GL_PROJECTION);
    glFrustum(-100., 100., -100., 100., 320., 640.); 
    glMatrixMode(GL_MODELVIEW);

    /* turn on features */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    /* make shadow matricies */

      /* 3 points on floor */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] =  100.f; v1[Y] = -100.f; v1[Z] = -320.f;
      v2[X] =  100.f; v2[Y] = -100.f; v2[Z] = -520.f;
      
      findplane(floorplane, v0, v1, v2);
      shadowmatrix(floorshadow, floorplane, lightpos);

      /* 3 points on left wall */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] = -100.f; v1[Y] = -100.f; v1[Z] = -520.f;
      v2[X] = -100.f; v2[Y] =  100.f; v2[Z] = -520.f;

      findplane(lwallplane, v0, v1, v2);
      shadowmatrix(leftwallshadow, lwallplane, lightpos);

    /* place light 0 in the right place */
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

    /* remove back faces to speed things up */
    glCullFace(GL_BACK);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    /* make display lists for sphere and cone; for efficiency */

    glNewList(WALLS, GL_COMPILE);
    glColor3f(1.f, 1.f, 1.f);
    glBegin(GL_QUADS);
    /* right wall */
    glNormal3f(-1.f, 0.f, 0.f);
    glVertex3f( 100.f, -100.f, -320.f);
    glVertex3f( 100.f,  100.f, -320.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);

    /* ceiling */
    glNormal3f(0.f, -1.f, 0.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -320.f);

    /* back wall */
    glNormal3f(0.f, 0.f, 1.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glEnd();
    glEndList();


    glNewList(SPHERE, GL_COMPILE);
    sphere = gluNewQuadric();
    glPushMatrix();
    glTranslatef(60.f, -50.f, -360.f);
    gluSphere(sphere, 20.f, 20, 20);
    gluDeleteQuadric(sphere);
    glPopMatrix();
    glEndList();


    glNewList(LIGHT, GL_COMPILE);
    sphere = gluNewQuadric();
    gluSphere(sphere, 5.f, 20, 20);
    gluDeleteQuadric(sphere);
    glEndList();

    glNewList(CONE, GL_COMPILE);
    cone = gluNewQuadric();
    base = gluNewQuadric();
    glPushMatrix();
    glTranslatef(-40.f, -40.f, -400.f);
    glRotatef(-90.f, 1.f, 0.f, 0.f);
    gluDisk(base, 0., 20., 20, 1);
    gluCylinder(cone, 20., 0., 60., 20, 20);
    gluDeleteQuadric(cone);
    gluDeleteQuadric(base);
    glPopMatrix();
    glEndList();


    glNewList(SHADOWERS, GL_COMPILE);
    glCallList(CONE);
    glCallList(SPHERE);
    glEndList();

    glNewList(FLOOR, GL_COMPILE);
    /* make the floor textured */
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glNormal3f(0.f, 1.f, 0.f);
    glTexCoord2i(0, 0);
    glVertex3f(-100.f, -100.f, -320.f);
    glTexCoord2i(1, 0);
    glVertex3f( 100.f, -100.f, -320.f);
    glTexCoord2i(1, 1);
    glVertex3f( 100.f, -100.f, -520.f);
    glTexCoord2i(0, 1);
    glVertex3f(-100.f, -100.f, -520.f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glEndList();

    glNewList(LEFTWALL, GL_COMPILE);
    glBegin(GL_QUADS);
    /* left wall */
    glNormal3f(1.f, 0.f, 0.f);
    glVertex3f(-100.f, -100.f, -320.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glEnd();
    glEndList();

    floortex = read_texture("../../data/wood0.rgb",
			    &texwid, &texht, &texcomps);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA,
		      GL_UNSIGNED_BYTE, floortex);

    free(floortex);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    glutMainLoop();
    return 0;
}