Ejemplo n.º 1
0
static void AddGraphicsMode(
	GraphicsDevice *device, int width, int height, int scaleFactor)
{
	int i = 0;
	int actualResolutionToAdd = width * height * scaleFactor * scaleFactor;
	GraphicsMode *mode = NULL;

	// Don't add if mode already exists
	if (FindValidMode(device, width, height, scaleFactor) != -1)
	{
		return;
	}

	for (; i < device->numValidModes; i++)
	{
		// Ordered by actual resolution ascending and scale descending
		int actualResolution;
		mode = &device->validModes[i];
		actualResolution =
			mode->Width * mode->Height * mode->ScaleFactor * mode->ScaleFactor;
		if (actualResolution > actualResolutionToAdd ||
			(actualResolution == actualResolutionToAdd &&
			mode->ScaleFactor < scaleFactor))
		{
			break;
		}
	}
	device->numValidModes++;
	CREALLOC(device->validModes, device->numValidModes * sizeof *device->validModes);
	// If inserting, move later modes one place further
	if (i < device->numValidModes - 1)
	{
		memmove(
			device->validModes + i + 1,
			device->validModes + i,
			(device->numValidModes - 1 - i) * sizeof *device->validModes);
	}
	mode = &device->validModes[i];
	mode->Width = width;
	mode->Height = height;
	mode->ScaleFactor = scaleFactor;
}
Ejemplo n.º 2
0
static void AddGraphicsMode(GraphicsDevice *device, const int w, const int h)
{
    // Don't add if mode already exists
    if (FindValidMode(device, w, h) != -1)
    {
        return;
    }

    const int size = w * h;
    int i;
    for (i = 0; i < (int)device->validModes.size; i++)
    {
        // Ordered by actual resolution ascending and scale descending
        const Vec2i *mode = CArrayGet(&device->validModes, i);
        const int actualResolution = mode->x * mode->y;
        if (actualResolution >= size)
        {
            break;
        }
    }
    Vec2i mode = Vec2iNew(w, h);
    CArrayInsert(&device->validModes, i, &mode);
}
Ejemplo n.º 3
0
// Initialises the video subsystem.
// To prevent needless screen flickering, config is compared with cache
// to see if anything changed. If not, don't recreate the screen.
void GraphicsInitialize(GraphicsDevice *g, const bool force)
{
#ifdef __GCWZERO__
	int sdl_flags = SDL_HWSURFACE | SDL_TRIPLEBUF;
#else
	int sdl_flags = SDL_SWSURFACE;
#endif
	unsigned int w, h = 0;
	unsigned int rw, rh;

	if (g->IsInitialized && !g->cachedConfig.needRestart)
	{
		return;
	}

	if (!g->IsWindowInitialized)
	{
		/* only do this the first time */
		char title[32];
		debug(D_NORMAL, "setting caption and icon...\n");
		sprintf(title, "C-Dogs SDL %s%s",
			g->cachedConfig.IsEditor ? "Editor " : "",
			CDOGS_SDL_VERSION);
		SDL_WM_SetCaption(title, NULL);
		char buf[CDOGS_PATH_MAX];
		GetDataFilePath(buf, "cdogs_icon.bmp");
		g->icon = SDL_LoadBMP(buf);
		SDL_WM_SetIcon(g->icon, NULL);
		AddSupportedGraphicsModes(g);
	}

	g->IsInitialized = false;

	sdl_flags |= g->cachedConfig.IsEditor ? SDL_RESIZABLE : 0;
	if (g->cachedConfig.Fullscreen)
	{
		sdl_flags |= SDL_FULLSCREEN;
	}

	rw = w = g->cachedConfig.Res.x;
	rh = h = g->cachedConfig.Res.y;

	if (g->cachedConfig.ScaleFactor > 1)
	{
		rw *= g->cachedConfig.ScaleFactor;
		rh *= g->cachedConfig.ScaleFactor;
	}

	if (!force && !g->cachedConfig.IsEditor)
	{
		g->modeIndex = FindValidMode(g, w, h, g->cachedConfig.ScaleFactor);
		if (g->modeIndex == -1)
		{
			g->modeIndex = 0;
			printf("!!! Invalid Video Mode %dx%d\n", w, h);
			return;
		}
	}

	printf("Graphics mode:\t%dx%d %dx (actual %dx%d)\n",
		w, h, g->cachedConfig.ScaleFactor, rw, rh);
	SDL_FreeSurface(g->screen);
	g->screen = SDL_SetVideoMode(rw, rh, 32, sdl_flags);
	if (g->screen == NULL)
	{
		printf("ERROR: InitVideo: %s\n", SDL_GetError());
		return;
	}
	SDL_PixelFormat *f = g->screen->format;
	g->Amask = -1 & ~(f->Rmask | f->Gmask | f->Bmask);
	Uint32 aMask = g->Amask;
	g->Ashift = 0;
	while (aMask != 0xff)
	{
		g->Ashift += 8;
		aMask >>= 8;
	}

	CFREE(g->buf);
	CCALLOC(g->buf, GraphicsGetMemSize(&g->cachedConfig));
	CFREE(g->bkg);
	CCALLOC(g->bkg, GraphicsGetMemSize(&g->cachedConfig));

	debug(D_NORMAL, "Changed video mode...\n");

	GraphicsSetBlitClip(
		g, 0, 0, g->cachedConfig.Res.x - 1, g->cachedConfig.Res.y - 1);
	debug(D_NORMAL, "Internal dimensions:\t%dx%d\n",
		g->cachedConfig.Res.x, g->cachedConfig.Res.y);

	g->IsInitialized = true;
	g->IsWindowInitialized = true;
	g->cachedConfig.Res.x = w;
	g->cachedConfig.Res.y = h;
	g->cachedConfig.needRestart = false;
}
Ejemplo n.º 4
0
// Initialises the video subsystem.
// To prevent needless screen flickering, config is compared with cache
// to see if anything changed. If not, don't recreate the screen.
void GraphicsInitialize(
	GraphicsDevice *device, GraphicsConfig *config, TPalette palette,
	int force)
{
	int sdl_flags = 0;
	unsigned int w, h = 0;
	unsigned int rw, rh;

	if (!IsRestartRequiredForConfig(device, config))
	{
		return;
	}

	if (!device->IsWindowInitialized)
	{
		/* only do this the first time */
		char title[32];
		debug(D_NORMAL, "setting caption and icon...\n");
		sprintf(title, "C-Dogs SDL %s%s",
			config->IsEditor ? "Editor " : "",
			CDOGS_SDL_VERSION);
		SDL_WM_SetCaption(title, NULL);
		device->icon = SDL_LoadBMP(GetDataFilePath("cdogs_icon.bmp"));
		SDL_WM_SetIcon(device->icon, NULL);
		AddSupportedGraphicsModes(device);
	}

	device->IsInitialized = 0;

	sdl_flags |= SDL_SWSURFACE;
	sdl_flags |= config->IsEditor ? SDL_RESIZABLE : 0;
	if (config->Fullscreen)
	{
		sdl_flags |= SDL_FULLSCREEN;
	}

	rw = w = config->Res.x;
	rh = h = config->Res.y;

	if (config->ScaleFactor > 1)
	{
		rw *= config->ScaleFactor;
		rh *= config->ScaleFactor;
	}

	if (!force && !config->IsEditor)
	{
		device->modeIndex = FindValidMode(device, w, h, config->ScaleFactor);
		if (device->modeIndex == -1)
		{
			device->modeIndex = 0;
			printf("!!! Invalid Video Mode %dx%d\n", w, h);
			return;
		}
	}
	else
	{
		printf("\n");
		printf("  BIG FAT WARNING: If this blows up in your face,\n");
		printf("  and mutilates your cat, please don't cry.\n");
		printf("\n");
	}

	printf("Graphics mode:\t%dx%d %dx (actual %dx%d)\n",
		w, h, config->ScaleFactor, rw, rh);
	SDL_FreeSurface(device->screen);
	device->screen = SDL_SetVideoMode(rw, rh, 32, sdl_flags);
	if (device->screen == NULL)
	{
		printf("ERROR: InitVideo: %s\n", SDL_GetError());
		return;
	}
	SDL_PixelFormat *f = device->screen->format;
	device->Amask = -1 & ~(f->Rmask | f->Gmask | f->Bmask);
	Uint32 aMask = device->Amask;
	device->Ashift = 0;
	while (aMask != 0xff)
	{
		device->Ashift += 8;
		aMask >>= 8;
	}

	CFREE(device->buf);
	CCALLOC(device->buf, GraphicsGetMemSize(config));
	CFREE(device->bkg);
	CCALLOC(device->bkg, GraphicsGetMemSize(config));

	debug(D_NORMAL, "Changed video mode...\n");

	GraphicsSetBlitClip(
		device,
		0, 0, config->Res.x - 1,config->Res.y - 1);
	debug(D_NORMAL, "Internal dimensions:\t%dx%d\n",
		config->Res.x, config->Res.y);

	device->IsInitialized = 1;
	device->IsWindowInitialized = 1;
	device->cachedConfig = *config;
	device->cachedConfig.Res.x = w;
	device->cachedConfig.Res.y = h;
	CDogsSetPalette(palette);
}