예제 #1
0
GraphicsDevice::GraphicsDevice(const ivec2 &windowSize,
							   bool fullscreen,
							   bool resizable,
							   bool showcursor,
							   const char * title)
: windowSurface(0),
  dimensions(0,0),
  nearClip(0.1f),
  farClip(100.0f) {
	attr = generateDefaultAttributes();
	
	setAttributes();
	
	if(title) {
		SDL_WM_SetCaption(title, title);
	} else {
		SDL_WM_SetCaption("SDL App", "SDL App");
	}
	
	windowSurface = SDL_SetVideoMode(windowSize.x,
	                                 windowSize.y,
	                                 0,
	                                 SDL_OPENGL
	                                 | SDL_HWSURFACE
	                                 | SDL_DOUBLEBUF
									 | (resizable?SDL_RESIZABLE:0)
	                                 | (fullscreen?SDL_FULLSCREEN:0));
	                                
#ifdef _WIN32
	/*
	See:
	<http://listas.apesol.org/pipermail/sdl-libsdl.org/2002-July/028824.html>
	Sometimes, after calling SDL_SetVideoMode, MessageBox and standard assert
	(which calls MessageBox internally) will return immediately without
	displaying a message box window.
	*/
	flushMessageQueue();
#endif
	
	assert(windowSurface && "Couldn't create window!");
	
	initializeOpenGLExtensions();
	resizeOpenGLViewport(windowSize, nearClip, farClip);
	
	SDL_ShowCursor(showcursor ? SDL_ENABLE : SDL_DISABLE);
}
예제 #2
0
PRIVATE void slideTiles(MAKE_THIS(MainWindow), int xDirection, int yDirection){ SELFREF_INIT;
	int traversX[4], traversY[4], i, y, j, x;
	struct coords farthestCoords;
	BOOL moved = FALSE;

	for (i = 0; i < 4; i++){
		traversX[i] = xDirection < 0 ? i : 3 - i;
		traversY[i] = yDirection < 0 ? i : 3 - i;
	}

	for (i = 0, y = traversY[i]; i < 4; i++, y = traversY[i]){
		for (j = 0, x = traversX[j]; j < 4; j++, x = traversX[j]){
			if (this->tiles[y][x]){
				farthestCoords = findFarthest(this, this->tiles[y][x], xDirection, yDirection);

				if (farthestCoords.x != x || farthestCoords.y != y){
					if (this->tiles[farthestCoords.y][farthestCoords.x]){ /* We need a merger! */
						deleteTile(this->tiles[farthestCoords.y][farthestCoords.x]);
						this->tiles[farthestCoords.y][farthestCoords.x] = NULL;
						this->tiles[y][x]->merged = TRUE;
						$(this->tiles[y][x])_incNumber();
					}

					$(this->tiles[y][x])_moveTile(farthestCoords.y, farthestCoords.x);
					swapTiles(this->tiles, y, x, farthestCoords.y, farthestCoords.x);
					moved = TRUE;
				}
			}
		}
	}

	if (moved){
		for (i = 0; i < 4; i++)
			for (j = 0; j < 4; j++)
				if (this->tiles[i][j])
					this->tiles[i][j]->merged = FALSE;
		addRandomTile(this);
	}

	flushMessageQueue();
}