diff --git a/src/cdogs.c b/src/cdogs.c index 4f2286525..87f0f71d2 100644 --- a/src/cdogs.c +++ b/src/cdogs.c @@ -142,7 +142,7 @@ int MissionDescription(int y, const char *description) int w, ix, x, lines; const char *ws, *word, *p, *s; -#define MAX_BOX_WIDTH (gConfig.Graphics.ResolutionWidth - (gConfig.Graphics.ResolutionWidth / 6)) +#define MAX_BOX_WIDTH (gGraphicsDevice.cachedConfig.ResolutionWidth - (gGraphicsDevice.cachedConfig.ResolutionWidth / 6)) ix = x = CenterX((MAX_BOX_WIDTH)); lines = 1; @@ -194,9 +194,9 @@ void CampaignIntro(void *bkg) debug(D_NORMAL, "\n"); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); - y = gConfig.Graphics.ResolutionWidth / 4; + y = gGraphicsDevice.cachedConfig.ResolutionWidth / 4; sprintf(s, "%s by %s", gCampaign.setting->title, gCampaign.setting->author); CDogsTextStringSpecial(s, TEXT_TOP | TEXT_XCENTER, 0, (y - 25)); @@ -212,9 +212,9 @@ void MissionBriefing(void *bkg) char s[512]; int i, y; - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); - y = gConfig.Graphics.ResolutionWidth / 4; + y = gGraphicsDevice.cachedConfig.ResolutionWidth / 4; sprintf(s, "Mission %d: %s", gMission.index + 1, gMission.missionData->title); CDogsTextStringSpecial(s, TEXT_TOP | TEXT_XCENTER, 0, (y - 25)); @@ -231,23 +231,23 @@ void MissionBriefing(void *bkg) y += CDogsTextHeight() * MissionDescription(y, gMission.missionData->description); - y += gConfig.Graphics.ResolutionHeight / 10; + y += gGraphicsDevice.cachedConfig.ResolutionHeight / 10; for (i = 0; i < gMission.missionData->objectiveCount; i++) { if (gMission.missionData->objectives[i].required > 0) { CDogsTextStringAt( - gConfig.Graphics.ResolutionWidth / 6, + gGraphicsDevice.cachedConfig.ResolutionWidth / 6, y, gMission.missionData->objectives[i].description); DrawObjectiveInfo( i, - gConfig.Graphics.ResolutionWidth - (gConfig.Graphics.ResolutionWidth / 6), + gGraphicsDevice.cachedConfig.ResolutionWidth - (gGraphicsDevice.cachedConfig.ResolutionWidth / 6), y + 8, gMission.missionData); - y += gConfig.Graphics.ResolutionHeight / 12; + y += gGraphicsDevice.cachedConfig.ResolutionHeight / 12; } } @@ -259,7 +259,7 @@ void MissionBriefing(void *bkg) void Summary(int x, struct PlayerData *data, int character) { char s[50]; - int y = gConfig.Graphics.ResolutionHeight / 3; + int y = gGraphicsDevice.cachedConfig.ResolutionHeight / 3; if (lastPassword[0]) { @@ -270,7 +270,7 @@ void Summary(int x, struct PlayerData *data, int character) s1, TEXT_BOTTOM | TEXT_XCENTER, 0, - gConfig.Graphics.ResolutionHeight / 12); + gGraphicsDevice.cachedConfig.ResolutionHeight / 12); } if (data->survived) { @@ -342,8 +342,8 @@ void Summary(int x, struct PlayerData *data, int character) void Bonuses(void) { int i; - int y = (gConfig.Graphics.ResolutionHeight / 2) + (gConfig.Graphics.ResolutionHeight / 10); - int x = gConfig.Graphics.ResolutionWidth / 6; + int y = (gGraphicsDevice.cachedConfig.ResolutionHeight / 2) + (gGraphicsDevice.cachedConfig.ResolutionHeight / 10); + int x = gGraphicsDevice.cachedConfig.ResolutionWidth / 6; int done, req, total; int access_bonus = 0; int index; @@ -422,7 +422,7 @@ void Bonuses(void) void MissionSummary(void *bkg) { - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); Bonuses(); @@ -441,7 +441,7 @@ void ShowScore(void *bkg, int score1, int score2) { char s[10]; - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); debug(D_NORMAL, "\n"); @@ -450,14 +450,14 @@ void ShowScore(void *bkg, int score1, int score2) sprintf(s, "Score: %d", score1); CDogsTextStringAt( CenterOfLeft(CDogsTextWidth(s)), - gConfig.Graphics.ResolutionWidth / 3, + gGraphicsDevice.cachedConfig.ResolutionWidth / 3, s); DisplayPlayer(CenterOfRight(60), &gPlayer2Data, CHARACTER_PLAYER2, 0); sprintf(s, "Score: %d", score2); CDogsTextStringAt( CenterOfRight(CDogsTextWidth(s)), - gConfig.Graphics.ResolutionWidth / 3, + gGraphicsDevice.cachedConfig.ResolutionWidth / 3, s); } else @@ -471,7 +471,7 @@ void ShowScore(void *bkg, int score1, int score2) void FinalScore(void *bkg, int score1, int score2) { - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); #define IS_DRAW "It's a draw!" #define IS_WINNER "Winner!" @@ -484,7 +484,7 @@ void FinalScore(void *bkg, int score1, int score2) DisplayPlayer(CenterOfLeft(60), &gPlayer1Data, CHARACTER_PLAYER1, 0); CDogsTextStringAt( CenterOfLeft(CDogsTextWidth(IS_WINNER)), - gConfig.Graphics.ResolutionWidth / 2, + gGraphicsDevice.cachedConfig.ResolutionWidth / 2, IS_WINNER); } else @@ -492,7 +492,7 @@ void FinalScore(void *bkg, int score1, int score2) DisplayPlayer(CenterOfRight(60), &gPlayer2Data, CHARACTER_PLAYER2, 0); CDogsTextStringAt( CenterOfRight(CDogsTextWidth(IS_WINNER)), - gConfig.Graphics.ResolutionWidth / 2, + gGraphicsDevice.cachedConfig.ResolutionWidth / 2, IS_WINNER); } CopyToScreen(); @@ -529,7 +529,7 @@ void Victory(void *bkg) int x, i; const char *s; - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); x = 160 - CDogsTextWidth(CONGRATULATIONS) / 2; CDogsTextStringAt(x, 100, CONGRATULATIONS); @@ -823,7 +823,7 @@ void *MakeBkg(void) int i; TranslationTable randomTintTable; - CMALLOC(bkg, GraphicsGetMemSize(&gConfig.Graphics)); + CMALLOC(bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); gCampaign.setting = SetupAndGetQuickPlay(); gCampaign.seed = rand(); @@ -841,7 +841,7 @@ void *MakeBkg(void) SetPaletteRanges(15, 12, 10, 0); BuildTranslationTables(); SetRandomTintTable(&randomTintTable, 256); - for (i = 0; i < GraphicsGetMemSize(&gConfig.Graphics); i++) + for (i = 0; i < GraphicsGetMemSize(&gGraphicsDevice.cachedConfig); i++) { p[i] = randomTintTable[p[i] & 0xFF]; } @@ -854,7 +854,7 @@ void MainLoop(credits_displayer_t *creditsDisplayer, custom_campaigns_t *campaig unsigned char *my_screen; void *bkg = MakeBkg(); - CCALLOC(my_screen, GraphicsGetMemSize(&gConfig.Graphics)); + CCALLOC(my_screen, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); SetDstScreen(my_screen); while (MainMenu(bkg, creditsDisplayer, campaigns)) @@ -1004,9 +1004,9 @@ int main(int argc, char *argv[]) { char *val = strchr(argv[i], '='); val++; sscanf(val, "%dx%d", - &gConfig.Graphics.ResolutionWidth, &gConfig.Graphics.ResolutionHeight); + &gGraphicsDevice.cachedConfig.ResolutionWidth, &gGraphicsDevice.cachedConfig.ResolutionHeight); debug(D_NORMAL, "Video mode %dx%d set...\n", - gConfig.Graphics.ResolutionWidth, gConfig.Graphics.ResolutionHeight); + gGraphicsDevice.cachedConfig.ResolutionWidth, gGraphicsDevice.cachedConfig.ResolutionHeight); } if (strcmp(argv[i] + 1, "forcemode") == 0) { diff --git a/src/cdogs/automap.c b/src/cdogs/automap.c index c0dae2d82..f949a97f8 100644 --- a/src/cdogs/automap.c +++ b/src/cdogs/automap.c @@ -110,12 +110,12 @@ void DrawCross(TTileItem * t, unsigned char color) unsigned char *scr = GetDstScreen(); scr += MAP_XOFFS + MAP_FACTOR * t->x / TILE_WIDTH; - scr += (MAP_YOFFS + MAP_FACTOR * t->y / TILE_HEIGHT) * gConfig.Graphics.ResolutionWidth; + scr += (MAP_YOFFS + MAP_FACTOR * t->y / TILE_HEIGHT) * gGraphicsDevice.cachedConfig.ResolutionWidth; *scr = color; *(scr - 1) = color; *(scr + 1) = color; - *(scr - gConfig.Graphics.ResolutionWidth) = color; - *(scr + gConfig.Graphics.ResolutionWidth) = color; + *(scr - gGraphicsDevice.cachedConfig.ResolutionWidth) = color; + *(scr + gGraphicsDevice.cachedConfig.ResolutionWidth) = color; } static void DisplayObjective(TTileItem * t, int objectiveIndex) @@ -141,13 +141,13 @@ static void DisplayExit(void) for (i = x1; i <= x2; i++) { - *(scr + i + y1 * gConfig.Graphics.ResolutionWidth) = EXIT_COLOR; - *(scr + i + y2 * gConfig.Graphics.ResolutionWidth) = EXIT_COLOR; + *(scr + i + y1 * gGraphicsDevice.cachedConfig.ResolutionWidth) = EXIT_COLOR; + *(scr + i + y2 * gGraphicsDevice.cachedConfig.ResolutionWidth) = EXIT_COLOR; } for (i = y1 + 1; i < y2; i++) { - *(scr + x1 + i * gConfig.Graphics.ResolutionWidth) = EXIT_COLOR; - *(scr + x2 + i * gConfig.Graphics.ResolutionWidth) = EXIT_COLOR; + *(scr + x1 + i * gGraphicsDevice.cachedConfig.ResolutionWidth) = EXIT_COLOR; + *(scr + x2 + i * gGraphicsDevice.cachedConfig.ResolutionWidth) = EXIT_COLOR; } } @@ -158,7 +158,7 @@ static void DisplaySummary(void) //unsigned char *scr = GetDstScreen(); unsigned char color; - y = gConfig.Graphics.ResolutionWidth - 5 - CDogsTextHeight(); // 10 pixels from bottom + y = gGraphicsDevice.cachedConfig.ResolutionWidth - 5 - CDogsTextHeight(); // 10 pixels from bottom for (i = 0; i < gMission.missionData->objectiveCount; i++) { if (gMission.objectives[i].required > 0 || @@ -248,13 +248,13 @@ void DisplayAutoMap(int showAll) screen = p = GetDstScreen(); for (x = 0; - x < gConfig.Graphics.ResolutionWidth * gConfig.Graphics.ResolutionHeight; + x < gGraphicsDevice.cachedConfig.ResolutionWidth * gGraphicsDevice.cachedConfig.ResolutionHeight; x++) { p[x] = tableGreen[p[x] & 0xFF]; } - screen += MAP_YOFFS * gConfig.Graphics.ResolutionWidth + MAP_XOFFS; + screen += MAP_YOFFS * gGraphicsDevice.cachedConfig.ResolutionWidth + MAP_XOFFS; for (y = 0; y < YMAX; y++) for (i = 0; i < MAP_FACTOR; i++) { for (x = 0; x < XMAX; x++) @@ -270,7 +270,7 @@ void DisplayAutoMap(int showAll) *screen++ = FLOOR_COLOR; } else screen += MAP_FACTOR; - screen += gConfig.Graphics.ResolutionWidth - XMAX * MAP_FACTOR; + screen += gGraphicsDevice.cachedConfig.ResolutionWidth - XMAX * MAP_FACTOR; } for (y = 0; y < YMAX; y++) diff --git a/src/cdogs/blit.c b/src/cdogs/blit.c index db47b010d..af1012b74 100644 --- a/src/cdogs/blit.c +++ b/src/cdogs/blit.c @@ -89,7 +89,7 @@ void Blit(int x, int y, void *pic, void *table, int mode) { current += width; continue; } - yoff *= gConfig.Graphics.ResolutionWidth; + yoff *= gGraphicsDevice.cachedConfig.ResolutionWidth; for (j = 0; j < width; j++) { xoff = j + x; if (xoff < clipleft){ @@ -204,8 +204,8 @@ void CopyToScreen(void) unsigned char *pScreen = gGraphicsDevice.screen->pixels; int scr_w, scr_h, scr_size, scalef; - scr_w = gConfig.Graphics.ResolutionWidth; - scr_h = gConfig.Graphics.ResolutionHeight; + scr_w = gGraphicsDevice.cachedConfig.ResolutionWidth; + scr_h = gGraphicsDevice.cachedConfig.ResolutionHeight; scr_size = scr_w * scr_h; scalef = gConfig.Graphics.ScaleFactor; diff --git a/src/cdogs/drawtools.c b/src/cdogs/drawtools.c index 955a06a4e..195b047dc 100644 --- a/src/cdogs/drawtools.c +++ b/src/cdogs/drawtools.c @@ -45,7 +45,7 @@ void Draw_Point (const int x, const int y, const unsigned char c) //debug("(%d, %d)\n", x, y); - screen[PixelIndex(x, y, gConfig.Graphics.ResolutionWidth, gConfig.Graphics.ResolutionHeight)] = c; + screen[PixelIndex(x, y, gGraphicsDevice.cachedConfig.ResolutionWidth, gGraphicsDevice.cachedConfig.ResolutionHeight)] = c; } static diff --git a/src/cdogs/game.c b/src/cdogs/game.c index 488e7b064..ff847b884 100644 --- a/src/cdogs/game.c +++ b/src/cdogs/game.c @@ -273,12 +273,12 @@ void BlackLine(void) int i; unsigned char *p = GetDstScreen(); - p += (gConfig.Graphics.ResolutionWidth / 2) - 1; - for (i = 0; i < gConfig.Graphics.ResolutionHeight; i++) + p += (gGraphicsDevice.cachedConfig.ResolutionWidth / 2) - 1; + for (i = 0; i < gGraphicsDevice.cachedConfig.ResolutionHeight; i++) { *p++ = 1; *p = 1; - p += gConfig.Graphics.ResolutionWidth - 1; + p += gGraphicsDevice.cachedConfig.ResolutionWidth - 1; } } @@ -300,7 +300,7 @@ void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2) abs(player1->tileItem.x - player2->tileItem.x) < SPLIT_X && abs(player1->tileItem.y - player2->tileItem.y) < SPLIT_Y) { - CDogsSetClip(0, 0, gConfig.Graphics.ResolutionWidth - 1, gConfig.Graphics.ResolutionHeight - 1); + CDogsSetClip(0, 0, gGraphicsDevice.cachedConfig.ResolutionWidth - 1, gGraphicsDevice.cachedConfig.ResolutionHeight - 1); // One screen x = (player1->tileItem.x + player2->tileItem.x) / 2; @@ -326,20 +326,20 @@ void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2) CDogsSetClip( 0, 0, - (gConfig.Graphics.ResolutionWidth / 2) - 1, - gConfig.Graphics.ResolutionHeight - 1); + (gGraphicsDevice.cachedConfig.ResolutionWidth / 2) - 1, + gGraphicsDevice.cachedConfig.ResolutionHeight - 1); DoBuffer(b, player1->tileItem.x, player1->tileItem.y, 0, X_TILES_HALF, xNoise, yNoise); SoundSetLeftEar(player1->tileItem.x, player1->tileItem.y); CDogsSetClip( - (gConfig.Graphics.ResolutionWidth / 2) + 1, + (gGraphicsDevice.cachedConfig.ResolutionWidth / 2) + 1, 0, - gConfig.Graphics.ResolutionWidth - 1, - gConfig.Graphics.ResolutionHeight - 1); + gGraphicsDevice.cachedConfig.ResolutionWidth - 1, + gGraphicsDevice.cachedConfig.ResolutionHeight - 1); DoBuffer( b, player2->tileItem.x, player2->tileItem.y, - (gConfig.Graphics.ResolutionWidth / 2) + 1, + (gGraphicsDevice.cachedConfig.ResolutionWidth / 2) + 1, X_TILES_HALF, xNoise, yNoise); @@ -354,8 +354,8 @@ void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2) CDogsSetClip( 0, 0, - gConfig.Graphics.ResolutionWidth - 1, - gConfig.Graphics.ResolutionHeight - 1); + gGraphicsDevice.cachedConfig.ResolutionWidth - 1, + gGraphicsDevice.cachedConfig.ResolutionHeight - 1); DoBuffer(b, player1->tileItem.x, player1->tileItem.y, 0, X_TILES, xNoise, yNoise); SoundSetEars(player1->tileItem.x, player1->tileItem.y); @@ -367,8 +367,8 @@ void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2) CDogsSetClip( 0, 0, - gConfig.Graphics.ResolutionWidth - 1, - gConfig.Graphics.ResolutionHeight - 1); + gGraphicsDevice.cachedConfig.ResolutionWidth - 1, + gGraphicsDevice.cachedConfig.ResolutionHeight - 1); DoBuffer(b, player2->tileItem.x, player2->tileItem.y, 0, X_TILES, xNoise, yNoise); SoundSetEars(player2->tileItem.x, player2->tileItem.y); @@ -382,8 +382,8 @@ void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2) CDogsSetClip( 0, 0, - gConfig.Graphics.ResolutionWidth - 1, - gConfig.Graphics.ResolutionHeight - 1); + gGraphicsDevice.cachedConfig.ResolutionWidth - 1, + gGraphicsDevice.cachedConfig.ResolutionHeight - 1); } #define PLACE_LEFT 0 @@ -457,7 +457,7 @@ static void MissionUpdateObjectives(void) int x, y; x = 5; - y = gConfig.Graphics.ResolutionHeight - 5 - CDogsTextHeight(); + y = gGraphicsDevice.cachedConfig.ResolutionHeight - 5 - CDogsTextHeight(); for (i = 0; i < gMission.missionData->objectiveCount; i++) { if (gMission.missionData->objectives[i].type == OBJECTIVE_INVESTIGATE) @@ -644,7 +644,7 @@ int gameloop(void) time_t t; struct tm *tp; - CDogsSetClip(0, 0, gConfig.Graphics.ResolutionWidth - 1, gConfig.Graphics.ResolutionHeight - 1); + CDogsSetClip(0, 0, gGraphicsDevice.cachedConfig.ResolutionWidth - 1, gGraphicsDevice.cachedConfig.ResolutionHeight - 1); if (MusicGetStatus(&gSoundDevice) != MUSIC_OK) { diff --git a/src/cdogs/grafx.c b/src/cdogs/grafx.c index d8d4fb068..bfb9e7e28 100644 --- a/src/cdogs/grafx.c +++ b/src/cdogs/grafx.c @@ -120,6 +120,7 @@ static int ValidMode(unsigned int w, unsigned int h) return 0; } + GraphicsDevice gGraphicsDevice = { 0, @@ -127,15 +128,30 @@ GraphicsDevice gGraphicsDevice = NULL }; +int IsRestartRequiredForConfig(GraphicsDevice *device, GraphicsConfig *config) +{ + return + !device->IsInitialized || + device->cachedConfig.Fullscreen != config->Fullscreen || + device->cachedConfig.ScaleFactor != config->ScaleFactor; +} + /* Initialises the video subsystem. Note: dynamic resolution change is not supported. */ +// 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, int force) { int sdl_flags = 0; unsigned int w, h = 0; unsigned int rw, rh; + if (!IsRestartRequiredForConfig(device, config)) + { + return; + } + device->IsInitialized = 0; sdl_flags |= SDL_HWPALETTE; @@ -146,8 +162,17 @@ void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int forc sdl_flags |= SDL_FULLSCREEN; } - rw = w = config->ResolutionWidth; - rh = h = config->ResolutionHeight; + // Don't allow resolution to change + if (!device->IsWindowInitialized) + { + rw = w = config->ResolutionWidth; + rh = h = config->ResolutionHeight; + } + else + { + rw = w = device->cachedConfig.ResolutionWidth; + rh = h = device->cachedConfig.ResolutionHeight; + } if (config->ScaleFactor > 1) { @@ -203,6 +228,7 @@ void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int forc device->IsInitialized = 1; device->IsWindowInitialized = 1; + device->cachedConfig = *config; } void GraphicsTerminate(GraphicsDevice *device) diff --git a/src/cdogs/grafx.h b/src/cdogs/grafx.h index a772fda26..9e728e072 100644 --- a/src/cdogs/grafx.h +++ b/src/cdogs/grafx.h @@ -61,15 +61,6 @@ typedef struct RGB color_t; typedef color_t TPalette[256]; typedef unsigned char TranslationTable[256]; -typedef struct -{ - int IsInitialized; - int IsWindowInitialized; - SDL_Surface *screen; -} GraphicsDevice; - -extern GraphicsDevice gGraphicsDevice; - typedef struct { int Brightness; @@ -79,6 +70,16 @@ typedef struct int ScaleFactor; } GraphicsConfig; +typedef struct +{ + int IsInitialized; + int IsWindowInitialized; + SDL_Surface *screen; + GraphicsConfig cachedConfig; +} GraphicsDevice; + +extern GraphicsDevice gGraphicsDevice; + void SetColorZero( GraphicsDevice *device, unsigned char r, unsigned char g, unsigned char b); @@ -118,12 +119,12 @@ INLINE static int PicHeight(const void *pic) return ((const short *)pic)[1]; } -#define CenterX(w) ((gConfig.Graphics.ResolutionWidth - w) / 2) -#define CenterY(h) ((gConfig.Graphics.ResolutionHeight - h) / 2) +#define CenterX(w) ((gGraphicsDevice.cachedConfig.ResolutionWidth - w) / 2) +#define CenterY(h) ((gGraphicsDevice.cachedConfig.ResolutionHeight - h) / 2) #define CenterOf(a, b, w) ((a + (((b - a) - w) / 2))) -#define CenterOfRight(w) CenterOf((gConfig.Graphics.ResolutionWidth / 2), (gConfig.Graphics.ResolutionWidth), w) -#define CenterOfLeft(w) CenterOf(0, (gConfig.Graphics.ResolutionWidth / 2), w) +#define CenterOfRight(w) CenterOf((gGraphicsDevice.cachedConfig.ResolutionWidth / 2), (gGraphicsDevice.cachedConfig.ResolutionWidth), w) +#define CenterOfLeft(w) CenterOf(0, (gGraphicsDevice.cachedConfig.ResolutionWidth / 2), w) #endif diff --git a/src/cdogs/hiscores.c b/src/cdogs/hiscores.c index 0850de4b4..2dde492e3 100644 --- a/src/cdogs/hiscores.c +++ b/src/cdogs/hiscores.c @@ -205,7 +205,7 @@ void DisplayAllTimeHighScores(void *bkg) memcpy( GetDstScreen(), bkg, - GraphicsGetMemSize(&gConfig.Graphics)); + GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); index = DisplayPage("All time high scores:", index, allTimeHigh, gPlayer1Data.allTime, gOptions.twoPlayers ? gPlayer2Data. @@ -220,7 +220,7 @@ void DisplayTodaysHighScores(void *bkg) while (index < MAX_ENTRY && todaysHigh[index].score > 0) { - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); index = DisplayPage("Today's highest score:", index, todaysHigh, gPlayer1Data.today, gOptions.twoPlayers ? gPlayer2Data. diff --git a/src/cdogs/map.h b/src/cdogs/map.h index 7344b9ac7..b53bc42f0 100644 --- a/src/cdogs/map.h +++ b/src/cdogs/map.h @@ -29,11 +29,11 @@ #define TILE_HEIGHT 12 //#define X_TILES 21 -#define X_TILES (gConfig.Graphics.ResolutionWidth / TILE_WIDTH + 2) +#define X_TILES (gGraphicsDevice.cachedConfig.ResolutionWidth / TILE_WIDTH + 2) #define X_TILES_HALF ((X_TILES / 2) + 1) //#define Y_TILES 19 -#define Y_TILES (gConfig.Graphics.ResolutionHeight / TILE_HEIGHT + 2) +#define Y_TILES (gGraphicsDevice.cachedConfig.ResolutionHeight / TILE_HEIGHT + 2) #define NO_WALK 1 #define NO_SEE 2 diff --git a/src/cdogs/text.c b/src/cdogs/text.c index 73ef433f9..a2876675c 100644 --- a/src/cdogs/text.c +++ b/src/cdogs/text.c @@ -188,8 +188,8 @@ int CDogsTextWidth(const char *s) void CDogsTextStringSpecial(const char *s, unsigned int opts, unsigned int xpad, unsigned int ypad) { - int scrw = gConfig.Graphics.ResolutionWidth; - int scrh = gConfig.Graphics.ResolutionHeight; + int scrw = gGraphicsDevice.cachedConfig.ResolutionWidth; + int scrh = gGraphicsDevice.cachedConfig.ResolutionHeight; int x, y, w, h; x = y = w = h = 0; diff --git a/src/cdogsed.c b/src/cdogsed.c index fb43df90f..527144b94 100644 --- a/src/cdogsed.c +++ b/src/cdogsed.c @@ -507,7 +507,7 @@ void Display(int index, int xc, int yc, int key) int i; SetSecondaryMouseRects(NULL); - memset(GetDstScreen(), 58, GraphicsGetMemSize(&gConfig.Graphics)); + memset(GetDstScreen(), 58, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); sprintf(s, "Key: 0x%x", key); CDogsTextStringAt(270, 190, s); @@ -1215,7 +1215,7 @@ static void Save(int asCode) strcpy(filename, lastFile); for (;;) { - memset(GetDstScreen(), 58, GraphicsGetMemSize(&gConfig.Graphics)); + memset(GetDstScreen(), 58, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); CDogsTextStringAt(125, 50, "Save as:"); CDogsTextGoto(125, 50 + CDogsTextHeight()); CDogsTextChar('\020'); @@ -1262,7 +1262,7 @@ static int ConfirmQuit(void) { int c; - memset(GetDstScreen(), 58, GraphicsGetMemSize(&gConfig.Graphics)); + memset(GetDstScreen(), 58, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); CDogsTextStringAt(80, 50, "Campaign has been modified, but not saved"); CDogsTextStringAt(110, 50 + TH, "Quit anyway? (Y/N)"); CopyToScreen(); @@ -1561,7 +1561,7 @@ int main(int argc, char *argv[]) CDogsSetPalette(gPalette); - CCALLOC(my_screen, GraphicsGetMemSize(&gConfig.Graphics)); + CCALLOC(my_screen, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); SetDstScreen(my_screen); KeyInit(&gKeyboard); diff --git a/src/charsed.c b/src/charsed.c index 9cd6e28dc..b38b242e3 100644 --- a/src/charsed.c +++ b/src/charsed.c @@ -216,7 +216,7 @@ static void Display(CampaignSetting *setting, int index, int xc, int yc) const TBadGuy *b; int i; - memset(GetDstScreen(), 74, GraphicsGetMemSize(&gConfig.Graphics)); + memset(GetDstScreen(), 74, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); sprintf(s, "%d/%d", setting->characterCount, MAX_CHARACTERS); CDogsTextStringAt(10, 190, s); @@ -297,7 +297,7 @@ static void Display(CampaignSetting *setting, int index, int xc, int yc) &setting->characters[i], index == i); x += 20; - if (x > gConfig.Graphics.ResolutionWidth) + if (x > gGraphicsDevice.cachedConfig.ResolutionWidth) { x = 10; y += 30; diff --git a/src/credits.c b/src/credits.c index bfd56a695..9be533bd1 100644 --- a/src/credits.c +++ b/src/credits.c @@ -128,16 +128,16 @@ void ShowCredits(credits_displayer_t *displayer) CDogsTextStringWithTableAt( 16, - gConfig.Graphics.ResolutionHeight - 50, + gGraphicsDevice.cachedConfig.ResolutionHeight - 50, "Credits:", displayer->textTranslationTable); CDogsTextStringWithTableAt( 20, - gConfig.Graphics.ResolutionHeight - 40, + gGraphicsDevice.cachedConfig.ResolutionHeight - 40, credits->name, displayer->nameTranslationTable); CDogsTextStringWithTableAt( - 20, gConfig.Graphics.ResolutionHeight - 40 + CDogsTextHeight(), + 20, gGraphicsDevice.cachedConfig.ResolutionHeight - 40 + CDogsTextHeight(), credits->message, displayer->textTranslationTable); diff --git a/src/mainmenu.c b/src/mainmenu.c index 09c8c42da..e3614ae25 100644 --- a/src/mainmenu.c +++ b/src/mainmenu.c @@ -53,7 +53,7 @@ int MainMenu( { KeyPoll(&gKeyboard); JoyPoll(&gJoysticks); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); ShowControls(); MenuDisplay(menu, creditsDisplayer); CopyToScreen(); diff --git a/src/menu.c b/src/menu.c index 0b895a8eb..9bbd0055a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -285,7 +285,7 @@ void MenuDisplay(menu_t *menu, credits_displayer_t *creditsDisplayer) menu->u.normal.title, TEXT_XCENTER | TEXT_TOP, 0, - gConfig.Graphics.ResolutionWidth / 12); + gGraphicsDevice.cachedConfig.ResolutionWidth / 12); } MenuDisplaySubmenus(menu); @@ -301,8 +301,8 @@ void MenuDisplayItems(menu_t *menu, credits_displayer_t *creditsDisplayer) if (d & MENU_DISPLAY_ITEMS_AUTHORS) { DrawTPic( - (gConfig.Graphics.ResolutionWidth - PicWidth(gPics[PIC_LOGO])) / 2, - gConfig.Graphics.ResolutionHeight / 12, + (gGraphicsDevice.cachedConfig.ResolutionWidth - PicWidth(gPics[PIC_LOGO])) / 2, + gGraphicsDevice.cachedConfig.ResolutionHeight / 12, gPics[PIC_LOGO], gCompiledPics[PIC_LOGO]); CDogsTextStringSpecial( @@ -430,7 +430,7 @@ void MenuDisplaySubmenus(menu_t *menu) s, TEXT_XCENTER | TEXT_BOTTOM, 0, - gConfig.Graphics.ResolutionWidth / 12); + gGraphicsDevice.cachedConfig.ResolutionWidth / 12); } y += CDogsTextHeight(); @@ -451,7 +451,7 @@ void MenuDisplaySubmenus(menu_t *menu) int xKeys; x = CenterX((CDogsTextCharWidth('a') * 10)) / 2; xKeys = x * 3; - yStart = (gConfig.Graphics.ResolutionHeight / 2) - (CDogsTextHeight() * 10); + yStart = (gGraphicsDevice.cachedConfig.ResolutionHeight / 2) - (CDogsTextHeight() * 10); for (i = 0; i < menu->u.normal.numSubMenus; i++) { diff --git a/src/password.c b/src/password.c index cb5f388a2..5b87c4bd2 100644 --- a/src/password.c +++ b/src/password.c @@ -211,7 +211,7 @@ static int EnterCode(void *bkg, const char *password) int cmd; KeyPoll(&gKeyboard); JoyPoll(&gJoysticks); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); cmd = GetMenuCmd(); if (!PasswordEntry(cmd, buffer)) { @@ -238,7 +238,7 @@ static int EnterCode(void *bkg, const char *password) CDogsTextWidth(buffer) + CDogsTextCharWidth(SYMBOL_LEFT) + CDogsTextCharWidth(SYMBOL_RIGHT)), - gConfig.Graphics.ResolutionWidth / 4); + gGraphicsDevice.cachedConfig.ResolutionWidth / 4); CDogsTextChar(SYMBOL_LEFT); CDogsTextString(buffer); CDogsTextChar(SYMBOL_RIGHT); @@ -247,7 +247,7 @@ static int EnterCode(void *bkg, const char *password) "Enter code", TEXT_XCENTER | TEXT_TOP, 0, - gConfig.Graphics.ResolutionHeight / 12); + gGraphicsDevice.cachedConfig.ResolutionHeight / 12); ShowControls(); CopyToScreen(); @@ -271,7 +271,7 @@ int EnterPassword(void *bkg, const char *password) int cmd; KeyPoll(&gKeyboard); JoyPoll(&gJoysticks); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); cmd = GetMenuCmd(); if (AnyButton(cmd)) { diff --git a/src/prep.c b/src/prep.c index 4489b656c..52bd96882 100644 --- a/src/prep.c +++ b/src/prep.c @@ -241,7 +241,7 @@ void DisplayPlayer(int x, struct PlayerData *data, int character, char s[22]; int y; - y = gConfig.Graphics.ResolutionHeight / 10; + y = gGraphicsDevice.cachedConfig.ResolutionHeight / 10; cd = &characterDesc[character]; @@ -273,7 +273,7 @@ void DisplayPlayer(int x, struct PlayerData *data, int character, static void ShowPlayerControls(int x, KeyConfig *config) { char s[256]; - int y = gConfig.Graphics.ResolutionHeight - (gConfig.Graphics.ResolutionHeight / 6); + int y = gGraphicsDevice.cachedConfig.ResolutionHeight - (gGraphicsDevice.cachedConfig.ResolutionHeight / 6); if (config->Device == INPUT_DEVICE_KEYBOARD) { @@ -317,7 +317,7 @@ static void ShowSelection(int x, struct PlayerData *data, int character) { CDogsTextStringAt( x + 40, - (gConfig.Graphics.ResolutionHeight / 10) + 20, + (gGraphicsDevice.cachedConfig.ResolutionHeight / 10) + 20, "None selected..."); } else @@ -327,7 +327,7 @@ static void ShowSelection(int x, struct PlayerData *data, int character) { CDogsTextStringAt( x + 40, - (gConfig.Graphics.ResolutionHeight / 10) + 20 + i * CDogsTextHeight(), + (gGraphicsDevice.cachedConfig.ResolutionHeight / 10) + 20 + i * CDogsTextHeight(), gGunDescriptions[data->weapons[i]].gunName); } } @@ -428,15 +428,15 @@ static int NameSelection(int x, int index, struct PlayerData *data, { x = CenterOf( 0, - gConfig.Graphics.ResolutionWidth / 2 + gGraphicsDevice.cachedConfig.ResolutionWidth / 2 , (ENTRY_SPACING * (ENTRY_COLS - 1)) + CDogsTextCharWidth('a')); } else if (gOptions.twoPlayers && index == CHARACTER_PLAYER2) { x = CenterOf( - gConfig.Graphics.ResolutionWidth / 2, - gConfig.Graphics.ResolutionWidth, + gGraphicsDevice.cachedConfig.ResolutionWidth / 2, + gGraphicsDevice.cachedConfig.ResolutionWidth, (ENTRY_SPACING * (ENTRY_COLS - 1)) + CDogsTextCharWidth('a')); } else @@ -1006,7 +1006,7 @@ int PlayerSelection(int twoPlayers, void *bkg) int cmd2 = 0; KeyPoll(&gKeyboard); JoyPoll(&gJoysticks); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to allow exit @@ -1041,7 +1041,7 @@ int PlayerEquip(void *bkg) int cmd2 = 0; KeyPoll(&gKeyboard); JoyPoll(&gJoysticks); - memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics)); + memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to exit from menu