Skip to content

Commit

Permalink
Remove dynamic resolution change
Browse files Browse the repository at this point in the history
Fix screen flicker when changing options
  • Loading branch information
cxong committed Jun 7, 2013
1 parent c82ee4a commit a25b5fc
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 108 deletions.
52 changes: 26 additions & 26 deletions src/cdogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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;
}
}

Expand All @@ -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])
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -422,7 +422,7 @@ void Bonuses(void)

void MissionSummary(void *bkg)
{
memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gConfig.Graphics));
memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig));

Bonuses();

Expand All @@ -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");

Expand All @@ -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
Expand All @@ -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!"
Expand All @@ -484,15 +484,15 @@ 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
{
DisplayPlayer(CenterOfRight(60), &gPlayer2Data, CHARACTER_PLAYER2, 0);
CDogsTextStringAt(
CenterOfRight(CDogsTextWidth(IS_WINNER)),
gConfig.Graphics.ResolutionWidth / 2,
gGraphicsDevice.cachedConfig.ResolutionWidth / 2,
IS_WINNER);
}
CopyToScreen();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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];
}
Expand All @@ -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))
Expand Down Expand Up @@ -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)
{
Expand Down
22 changes: 11 additions & 11 deletions src/cdogs/automap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
}

Expand All @@ -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 ||
Expand Down Expand Up @@ -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++)
Expand All @@ -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++)
Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/drawtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/cdogs/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit a25b5fc

Please sign in to comment.