Esempio n. 1
0
CGLMapView::CGLMapView()
{
	//no tiles yet
	m_nTiles = 0;

	//create the map
	m_pMap = new CS3DMap;

	//TEMP MAP CREATION
	MAPS->createMap(MAP_BORDERS_NO_X, m_pMap, NULL);
	m_nTiles = m_pMap->m_mapPieces.size();
	m_pMap->m_dInitialDepth = 80.0;
	m_pMap->m_iMode = MAP_SEAFARERS;
	m_pMap->m_iChipsUsed = MAP_USES_SEA_CHIPS;
	m_pMap->m_dInitialRot = 60.;

	//set current
	MAPS->setCurrent(m_pMap);

	resetEye();
	resetMapState();
	resetTileState();
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  XVisualInfo *vi;
  Colormap cmap;
  XSetWindowAttributes swa;
  Window win;
  GLXContext cx;
  XEvent event;
  fd_set readfds;
  struct timeval timeout;
  int xServerFD;
  int nselected;
    
  /* get a connection */
  xDisplay = XOpenDisplay(0);
  if (xDisplay == NULL) {
    fprintf(stderr, "can't open display\n");
    exit(1);
  }
    
  /* get an appropriate visual */
  vi = glXChooseVisual(xDisplay, DefaultScreen(xDisplay), attributeList);
  if (vi == NULL) {
    fprintf(stderr, "can't get visual\n");
    exit(1);
  }
    
  /* create a GLX context */
  cx = glXCreateContext(xDisplay, vi, 0, GL_FALSE);
  if (cx == NULL) {
    fprintf(stderr, "can't create GL context\n");
    exit(1);
  }
    
  /* create a color map */
  cmap = XCreateColormap(xDisplay, RootWindow(xDisplay, vi->screen), vi->visual, AllocNone);
    
  /* create a window */
  swa.colormap = cmap;
  swa.border_pixel = 0;
  swa.event_mask = StructureNotifyMask;

  windowWidth = 500;
  windowHeight = 500;
    
  win = XCreateWindow(xDisplay, RootWindow(xDisplay, vi->screen), 0, 0, windowWidth, windowHeight,
                      0, vi->depth, InputOutput, vi->visual,
                      CWBorderPixel|CWColormap|CWEventMask, &swa);

  XSelectInput(xDisplay, win, KeyPressMask | ExposureMask | StructureNotifyMask);
    
  XMapWindow(xDisplay, win);
  // wait for the window to be mapped
  XIfEvent(xDisplay, &event, WaitForNotify, (char*)win);
  /* connect the context to the window */
  glXMakeCurrent(xDisplay, win, cx);

  quad = gluNewQuadric();
  if (quad == NULL) {
    fprintf(stderr, "can't allocate quadric\n");
    exit(1);
  }

  resetEye();

  xServerFD = ConnectionNumber(xDisplay);
  XFlush(xDisplay);
  
  while (1) {
    while (processX()) {
    }
    if (needRepaint) {
      doPaint();
    }
    FD_ZERO(&readfds);
    if (!atEOF) {
      FD_SET(0, &readfds);
    }
    FD_SET(xServerFD, &readfds);
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    nselected = select(xServerFD+1, &readfds, NULL, NULL, atEOF ? &timeout : NULL);
    if (nselected < 0) {
      perror("select");
      continue;
    }
    if (nselected == 0) {
      continue;
    }
    if (FD_ISSET(0, &readfds)) {
      processStdin();
    }
  }
}
Esempio n. 3
0
static void
keypress(XEvent *event)
{
  char buffer[20];
  int bufsize = 20;
  KeySym key;
  XComposeStatus compose;
  int charcount;
  int modifiers = event->xkey.state;
  
  charcount = XLookupString((XKeyEvent *)event, buffer, bufsize, &key, &compose);
  
  switch (key) {
  case XK_Left:
    eyeTheta += dAngle;
    break;
  case XK_Right:
    eyeTheta -= dAngle;
    break;
  case XK_Up:
    if (modifiers & 0x01) {
      eyeR *= 0.8;
    } else {
      eyePhi -= dAngle;
    }
    break;
  case XK_Down:
    if (modifiers & 0x01) {
      eyeR *= 1.2;
    } else {
      eyePhi += dAngle;
    }
    break;

  case XK_q:
  case XK_Escape:
    exit(0);

  case XK_r:
    resetEye();
    break;

  case XK_comma:
    currentFrame--;
    followLastFrame = 0;
    break;
    
  case XK_period:
    currentFrame++;
    followLastFrame = 0;
    break;
    
  case XK_less:
    currentFrame = 0;
    followLastFrame = 0;
    break;
    
  case XK_greater:
    currentFrame = numFrames - 1;
    followLastFrame = 1;
    break;
    
  default:
    //fprintf(stderr, "keypress: 0x%x, 0x%x\n", (unsigned int)key, modifiers);
    break;
  }
  repaint();
}
Esempio n. 4
0
/////////////////////////////////////////////////////////////////////////////
// load a game from the database
/////////////////////////////////////////////////////////////////////////////
void CGLView::loadGame(int iGame, BOOL bIncomplete)
{
	int i;

	//load the game data
	if(TRUE == bIncomplete)
	{
		DATABASE->loadIncompleteGame(iGame, m_pGame, UNDO, this);

		//set the save game flag
		THISVIEW->setGameIndex(iGame);
	}
	else
	{
		DATABASE->loadGame(iGame, m_pGame, UNDO, this);
	}

	//set some size stuff
	m_nTiles = m_pBoard.GetSize();
	m_iNumPlayers = m_pGame->m_players.size();

	//reset road lengths
	calculateRoadLengths();

	//load up the map they used
	MAPS->loadMapByID(m_pGame->m_uiMapID);

	//reset look position
	resetEye();

	//copy the initial rotation
	m_dyRot = MAP->m_dInitialRot;

	//reset the jungle/volcano variants
	if(IS_VARIANT(VARIANT_USE_JUNGLE) || IS_VARIANT(VARIANT_USE_VOLCANO) || IS_VARIANT(VARIANT_USE_VOLCANO_GOLD))
	{
		MAP->m_iChipsUsed |= MAP_USES_SEA_CHIPS;
	}

	//build the texture maps
	buildOtherTextures();

	//make sure textures are enabled
	glEnable(GL_TEXTURE_2D);

	//initialize stats
	STAT->init();

	//update stats
	for(i = 0; i < STAT_SIZE; i++)
	{
		STAT->update(i);
	}

	//the game has been inited
	m_pGame->m_bInit = TRUE;

	//prepare build options if we're in game
	if(GAME_COMPLETE != m_pGame->m_iState)
	{
		m_iMode = GL_WAIT;

		//reset the time ref
		m_pGame->m_timeRef = COleDateTime::GetCurrentTime();
	}
	else
	{
		m_iMode = GL_GAME_OVER;

		//switch to the player panel
		THISVIEW->initPanel();

		//update counts
		for(i = 0; i < (int) m_pGame->m_players.size(); i++)
		{
			THISVIEW->updateCounts(i);
		}

		//toggle actions off
		ACTIONS->ShowWindow(SW_HIDE);

		//toggle controls
		CONTROLS->ShowWindow(SW_HIDE);
	}

	//refresh
	Invalidate();
}