diff --git a/src/cdogs.c b/src/cdogs.c index 4dc6c21a7..a24e3e9dc 100644 --- a/src/cdogs.c +++ b/src/cdogs.c @@ -188,16 +188,16 @@ int MissionDescription(int y, const char *description) return lines; } -void CampaignIntro(void *bkg) +void CampaignIntro(GraphicsDevice *graphicsDevice) { int y; char s[1024]; debug(D_NORMAL, "\n"); - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphicsDevice); - y = gGraphicsDevice.cachedConfig.ResolutionWidth / 4; + y = graphicsDevice->cachedConfig.ResolutionWidth / 4; sprintf(s, "%s by %s", gCampaign.Setting.title, gCampaign.Setting.author); CDogsTextStringSpecial(s, TEXT_TOP | TEXT_XCENTER, 0, (y - 25)); @@ -208,14 +208,14 @@ void CampaignIntro(void *bkg) WaitForAnyKeyOrButton(&gKeyboard, &gJoysticks); } -void MissionBriefing(void *bkg) +void MissionBriefing(GraphicsDevice *graphics) { char s[512]; int i, y; - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); - y = gGraphicsDevice.cachedConfig.ResolutionWidth / 4; + y = graphics->cachedConfig.ResolutionWidth / 4; sprintf(s, "Mission %d: %s", gMission.index + 1, gMission.missionData->title); CDogsTextStringSpecial(s, TEXT_TOP | TEXT_XCENTER, 0, (y - 25)); @@ -235,23 +235,23 @@ void MissionBriefing(void *bkg) y += CDogsTextHeight() * MissionDescription(y, gMission.missionData->description); - y += gGraphicsDevice.cachedConfig.ResolutionHeight / 10; + y += graphics->cachedConfig.ResolutionHeight / 10; for (i = 0; i < gMission.missionData->objectiveCount; i++) { if (gMission.missionData->objectives[i].required > 0) { CDogsTextStringAt( - gGraphicsDevice.cachedConfig.ResolutionWidth / 6, + graphics->cachedConfig.ResolutionWidth / 6, y, gMission.missionData->objectives[i].description); DrawObjectiveInfo( i, - gGraphicsDevice.cachedConfig.ResolutionWidth - (gGraphicsDevice.cachedConfig.ResolutionWidth / 6), + graphics->cachedConfig.ResolutionWidth - (graphics->cachedConfig.ResolutionWidth / 6), y + 8, gMission.missionData); - y += gGraphicsDevice.cachedConfig.ResolutionHeight / 12; + y += graphics->cachedConfig.ResolutionHeight / 12; } } @@ -423,9 +423,9 @@ void Bonuses(void) } } -void MissionSummary(void *bkg) +void MissionSummary(GraphicsDevice *graphics) { - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); Bonuses(); @@ -439,11 +439,11 @@ void MissionSummary(void *bkg) WaitForAnyKeyOrButton(&gKeyboard, &gJoysticks); } -void ShowScore(void *bkg, int score1, int score2) +void ShowScore(GraphicsDevice *graphicsDevice, int score1, int score2) { char s[10]; - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphicsDevice); debug(D_NORMAL, "\n"); @@ -452,14 +452,14 @@ void ShowScore(void *bkg, int score1, int score2) sprintf(s, "Score: %d", score1); CDogsTextStringAt( CenterOfLeft(CDogsTextWidth(s)), - gGraphicsDevice.cachedConfig.ResolutionWidth / 3, + graphicsDevice->cachedConfig.ResolutionWidth / 3, s); DisplayPlayer(CenterOfRight(60), &gPlayer2Data, CHARACTER_PLAYER2, 0); sprintf(s, "Score: %d", score2); CDogsTextStringAt( CenterOfRight(CDogsTextWidth(s)), - gGraphicsDevice.cachedConfig.ResolutionWidth / 3, + graphicsDevice->cachedConfig.ResolutionWidth / 3, s); } else @@ -471,9 +471,9 @@ void ShowScore(void *bkg, int score1, int score2) WaitForAnyKeyOrButton(&gKeyboard, &gJoysticks); } -void FinalScore(void *bkg, int score1, int score2) +void FinalScore(GraphicsDevice *graphicsDevice, int score1, int score2) { - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphicsDevice); #define IS_DRAW "It's a draw!" #define IS_WINNER "Winner!" @@ -486,7 +486,7 @@ void FinalScore(void *bkg, int score1, int score2) DisplayPlayer(CenterOfLeft(60), &gPlayer1Data, CHARACTER_PLAYER1, 0); CDogsTextStringAt( CenterOfLeft(CDogsTextWidth(IS_WINNER)), - gGraphicsDevice.cachedConfig.ResolutionWidth / 2, + graphicsDevice->cachedConfig.ResolutionWidth / 2, IS_WINNER); } else @@ -494,7 +494,7 @@ void FinalScore(void *bkg, int score1, int score2) DisplayPlayer(CenterOfRight(60), &gPlayer2Data, CHARACTER_PLAYER2, 0); CDogsTextStringAt( CenterOfRight(CDogsTextWidth(IS_WINNER)), - gGraphicsDevice.cachedConfig.ResolutionWidth / 2, + graphicsDevice->cachedConfig.ResolutionWidth / 2, IS_WINNER); } CopyToScreen(); @@ -526,12 +526,12 @@ static const char *finalWords2P[] = { #define CONGRATULATIONS "Congratulations, you have completed " -void Victory(void *bkg) +void Victory(GraphicsDevice *graphics) { int x, i; const char *s; - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); x = 160 - CDogsTextWidth(CONGRATULATIONS) / 2; CDogsTextStringAt(x, 100, CONGRATULATIONS); @@ -668,7 +668,7 @@ static void PlayMenuSong(void) } -int Game(void *bkg, int mission) +int Game(GraphicsDevice *graphics, int mission) { int run, gameOver; int allTime, todays; @@ -686,9 +686,9 @@ int Game(void *bkg, int mission) InitializeBadGuys(); if (IsMissionBriefingNeeded(gCampaign.Entry.mode)) { - MissionBriefing(bkg); + MissionBriefing(graphics); } - PlayerEquip(bkg); + PlayerEquip(graphics); InitPlayers(gOptions.twoPlayers, maxHealth, mission); @@ -714,12 +714,13 @@ int Game(void *bkg, int mission) PlayMenuSong(); printf(">> Starting\n"); - if (run) { - MissionSummary(bkg); - if (gameOver - && (gPlayer1Data.survived - || gPlayer2Data.survived)) - Victory(bkg); + if (run) + { + MissionSummary(graphics); + if (gameOver && (gPlayer1Data.survived || gPlayer2Data.survived)) + { + Victory(graphics); + } } allTime = todays = 0; @@ -743,9 +744,13 @@ int Game(void *bkg, int mission) gPlayer1Data.today++; } if (allTime && !gameOver) - DisplayAllTimeHighScores(bkg); + { + DisplayAllTimeHighScores(graphics); + } if (todays && !gameOver) - DisplayTodaysHighScores(bkg); + { + DisplayTodaysHighScores(graphics); + } mission++; @@ -757,7 +762,7 @@ int Game(void *bkg, int mission) return run; } -int Campaign(void *bkg) +int Campaign(GraphicsDevice *graphics) { int mission = 0; @@ -768,13 +773,13 @@ int Campaign(void *bkg) { MissionSave m; AutosaveLoadMission(&gAutosave, &m, gCampaign.Entry.path); - mission = EnterPassword(bkg, m.Password); + mission = EnterPassword(graphics, m.Password); } - return Game(bkg, mission); + return Game(graphics, mission); } -void DogFight(void *bkg) +void DogFight(GraphicsDevice *graphicsDevice) { int run; int score1 = 0, score2 = 0; @@ -791,7 +796,7 @@ void DogFight(void *bkg) SetupMission(0, 1, &gCampaign); SetupMap(); - if (PlayerEquip(bkg)) + if (PlayerEquip(graphicsDevice)) { srand((unsigned int)time(NULL)); InitPlayers(YES, 500, 0); @@ -812,7 +817,9 @@ void DogFight(void *bkg) PlayMenuSong(); if (run) - ShowScore(bkg, score1, score2); + { + ShowScore(graphicsDevice, score1, score2); + } } while (run && score1 < 5 && score2 < 5); @@ -820,57 +827,23 @@ void DogFight(void *bkg) gOptions.twoPlayers = twoPlayers; if (run) - FinalScore(bkg, score1, score2); -} - -void *MakeBkg(void) -{ - unsigned char *bkg; - struct Buffer *buffer = NewBuffer(); - unsigned char *p; - int i; - TranslationTable randomTintTable; - - SetupQuickPlayCampaign(&gCampaign.Setting); - gCampaign.seed = rand(); - SetupMission(0, 1, &gCampaign); - SetupMap(); - SetBuffer(1024, 768, buffer, X_TILES); - FixBuffer(buffer, 255); - DrawBuffer(buffer, 0); - CFREE(buffer); - KillAllObjects(); - FreeTriggersAndWatches(); - gCampaign.seed = gConfig.Game.RandomSeed; - - p = gGraphicsDevice.buf; - SetPaletteRanges(15, 12, 10, 0); - BuildTranslationTables(); - SetRandomTintTable(&randomTintTable, 256); - for (i = 0; i < GraphicsGetMemSize(&gGraphicsDevice.cachedConfig); i++) { - p[i] = randomTintTable[p[i] & 0xFF]; + FinalScore(graphicsDevice, score1, score2); } - - CMALLOC(bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); - memcpy(bkg, gGraphicsDevice.buf, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); - return bkg; } void MainLoop(credits_displayer_t *creditsDisplayer, custom_campaigns_t *campaigns) { - void *bkg = MakeBkg(); - - while (MainMenu(bkg, creditsDisplayer, campaigns)) + while (MainMenu(&gGraphicsDevice, creditsDisplayer, campaigns)) { debug(D_NORMAL, ">> Entering campaign\n"); if (IsIntroNeeded(gCampaign.Entry.mode)) { - CampaignIntro(bkg); + CampaignIntro(&gGraphicsDevice); } debug(D_NORMAL, ">> Entering selection\n"); - if (!PlayerSelection(gOptions.twoPlayers, bkg)) + if (!PlayerSelection(gOptions.twoPlayers, &gGraphicsDevice)) { continue; } @@ -878,16 +851,15 @@ void MainLoop(credits_displayer_t *creditsDisplayer, custom_campaigns_t *campaig debug(D_NORMAL, ">> Starting campaign\n"); if (gCampaign.Entry.mode == CAMPAIGN_MODE_DOGFIGHT) { - DogFight(bkg); + DogFight(&gGraphicsDevice); } - else if (Campaign(bkg)) + else if (Campaign(&gGraphicsDevice)) { - DisplayAllTimeHighScores(bkg); - DisplayTodaysHighScores(bkg); + DisplayAllTimeHighScores(&gGraphicsDevice); + DisplayTodaysHighScores(&gGraphicsDevice); } } debug(D_NORMAL, ">> Leaving Main Game Loop\n"); - CFREE(bkg); } void PrintTitle(void) diff --git a/src/cdogs/grafx.c b/src/cdogs/grafx.c index 72f2df6ad..327b4934f 100644 --- a/src/cdogs/grafx.c +++ b/src/cdogs/grafx.c @@ -56,11 +56,15 @@ #include #include -#include "defs.h" +#include "actors.h" #include "blit.h" #include "config.h" +#include "defs.h" +#include "draw.h" +#include "mission.h" #include "pics.h" /* for gPalette */ #include "files.h" +#include "triggers.h" #include "utils.h" GFX_Mode gfx_modelist[] = { @@ -130,6 +134,8 @@ int IsRestartRequiredForConfig(GraphicsDevice *device, GraphicsConfig *config) return !device->IsInitialized || device->cachedConfig.Fullscreen != config->Fullscreen || + device->cachedConfig.ResolutionWidth != config->ResolutionWidth || + device->cachedConfig.ResolutionHeight != config->ResolutionHeight || device->cachedConfig.ScaleFactor != config->ScaleFactor; } @@ -140,11 +146,39 @@ void GraphicsInit(GraphicsDevice *device) device->screen = NULL; memset(&device->cachedConfig, 0, sizeof device->cachedConfig); device->buf = NULL; + device->bkg = NULL; } -/* Initialises the video subsystem. +void MakeBkg(GraphicsDevice *device, GraphicsConfig *config) +{ + struct Buffer *buffer = NewBuffer(); + unsigned char *p; + int i; + TranslationTable randomTintTable; + + SetupQuickPlayCampaign(&gCampaign.Setting); + gCampaign.seed = rand(); + SetupMission(0, 1, &gCampaign); + SetupMap(); + SetBuffer(1024, 768, buffer, X_TILES); + FixBuffer(buffer, 255); + DrawBuffer(buffer, 0); + CFREE(buffer); + KillAllObjects(); + FreeTriggersAndWatches(); + gCampaign.seed = gConfig.Game.RandomSeed; + + p = device->buf; + SetPaletteRanges(15, 12, 10, 0); + BuildTranslationTables(); + SetRandomTintTable(&randomTintTable, 256); + for (i = 0; i < GraphicsGetMemSize(config); i++) + { + p[i] = randomTintTable[p[i] & 0xFF]; + } +} - Note: dynamic resolution change is not supported. */ +// 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, int force) @@ -168,17 +202,8 @@ void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int forc sdl_flags |= SDL_FULLSCREEN; } - // 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; - } + rw = w = config->ResolutionWidth; + rh = h = config->ResolutionHeight; if (config->ScaleFactor > 1) { @@ -213,6 +238,8 @@ void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int forc CFREE(device->buf); CCALLOC(device->buf, GraphicsGetMemSize(config)); + CFREE(device->bkg); + CCALLOC(device->bkg, GraphicsGetMemSize(config)); if (!device->IsWindowInitialized) { @@ -240,6 +267,10 @@ void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int forc device->cachedConfig = *config; device->cachedConfig.ResolutionWidth = w; device->cachedConfig.ResolutionHeight = h; + // Need to make background here since dimensions use cached config + MakeBkg(device, config); + memcpy(device->bkg, device->buf, GraphicsGetMemSize(config)); + memset(device->buf, 0, GraphicsGetMemSize(config)); } void GraphicsTerminate(GraphicsDevice *device) @@ -248,6 +279,7 @@ void GraphicsTerminate(GraphicsDevice *device) SDL_FreeSurface(device->screen); SDL_VideoQuit(); CFREE(device->buf); + CFREE(device->bkg); } int GraphicsGetMemSize(GraphicsConfig *config) @@ -255,6 +287,11 @@ int GraphicsGetMemSize(GraphicsConfig *config) return config->ResolutionWidth * config->ResolutionHeight; } +void GraphicsBlitBkg(GraphicsDevice *device) +{ + memcpy(device->buf, device->bkg, GraphicsGetMemSize(&device->cachedConfig)); +} + char *GrafxGetResolutionStr(void) { static char buf[16]; diff --git a/src/cdogs/grafx.h b/src/cdogs/grafx.h index 855da5820..c4dec6241 100644 --- a/src/cdogs/grafx.h +++ b/src/cdogs/grafx.h @@ -70,6 +70,7 @@ typedef struct SDL_Surface *screen; GraphicsConfig cachedConfig; unsigned char *buf; + unsigned char *bkg; } GraphicsDevice; extern GraphicsDevice gGraphicsDevice; @@ -85,6 +86,7 @@ void GraphicsInit(GraphicsDevice *device); void GraphicsInitialize(GraphicsDevice *device, GraphicsConfig *config, int force); void GraphicsTerminate(GraphicsDevice *device); int GraphicsGetMemSize(GraphicsConfig *config); +void GraphicsBlitBkg(GraphicsDevice *device); void Gfx_ModePrev(void); void Gfx_ModeNext(void); diff --git a/src/cdogs/hiscores.c b/src/cdogs/hiscores.c index 9c4389f32..933961692 100644 --- a/src/cdogs/hiscores.c +++ b/src/cdogs/hiscores.c @@ -197,16 +197,13 @@ static int DisplayPage( return idx; } -void DisplayAllTimeHighScores(void *bkg) +void DisplayAllTimeHighScores(GraphicsDevice *graphics) { int idx = 0; while (idx < MAX_ENTRY && allTimeHigh[idx].score > 0) { - memcpy( - gGraphicsDevice.buf, - bkg, - GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); idx = DisplayPage( "All time high scores:", idx, allTimeHigh, gPlayer1Data.allTime, @@ -215,13 +212,13 @@ void DisplayAllTimeHighScores(void *bkg) } } -void DisplayTodaysHighScores(void *bkg) +void DisplayTodaysHighScores(GraphicsDevice *graphics) { int idx = 0; while (idx < MAX_ENTRY && todaysHigh[idx].score > 0) { - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); idx = DisplayPage("Today's highest score:", idx, todaysHigh, gPlayer1Data.today, gOptions.twoPlayers ? gPlayer2Data. diff --git a/src/cdogs/hiscores.h b/src/cdogs/hiscores.h index 03444767e..ac8eadc62 100644 --- a/src/cdogs/hiscores.h +++ b/src/cdogs/hiscores.h @@ -50,10 +50,11 @@ #define __HISCORES #include "gamedata.h" +#include "grafx.h" void EnterHighScore(struct PlayerData *data); -void DisplayAllTimeHighScores(void *bkg); -void DisplayTodaysHighScores(void *bkg); +void DisplayAllTimeHighScores(GraphicsDevice *graphics); +void DisplayTodaysHighScores(GraphicsDevice *graphics); void SaveHighScores(void); void LoadHighScores(void); diff --git a/src/mainmenu.c b/src/mainmenu.c index 7a074750d..401fc5021 100644 --- a/src/mainmenu.c +++ b/src/mainmenu.c @@ -42,7 +42,7 @@ MenuSystem *MenuCreateAll(custom_campaigns_t *campaigns); int MainMenu( - void *bkg, + GraphicsDevice *graphics, credits_displayer_t *creditsDisplayer, custom_campaigns_t *campaigns) { @@ -50,7 +50,7 @@ int MainMenu( MenuSystem *menu = MenuCreateAll(campaigns); MenuSetCreditsDisplayer(menu, creditsDisplayer); MenuSetInputDevices(menu, &gJoysticks, &gKeyboard); - MenuSetBackground(menu, bkg); + MenuSetGraphicsDevice(menu, graphics); MenuLoop(menu); doPlay = menu->current->type == MENU_TYPE_CAMPAIGN_ITEM; @@ -259,7 +259,7 @@ menu_t *MenuCreateOptions(const char *name) MenuAddSubmenu( menu, MenuCreateOptionUpDownFunc( - "Video resolution (restart required)", + "Video resolution", Gfx_ModePrev, Gfx_ModeNext, MENU_OPTION_DISPLAY_STYLE_STR_FUNC, diff --git a/src/mainmenu.h b/src/mainmenu.h index 616fcafe4..663780492 100644 --- a/src/mainmenu.h +++ b/src/mainmenu.h @@ -27,11 +27,12 @@ #define __MAINMENU #include +#include #include "credits.h" int MainMenu( - void *bkg, + GraphicsDevice *graphics, credits_displayer_t *creditsDisplayer, custom_campaigns_t *campaigns); diff --git a/src/menu.c b/src/menu.c index 2f218f7d6..ce4d6ddeb 100644 --- a/src/menu.c +++ b/src/menu.c @@ -83,9 +83,9 @@ void MenuSetInputDevices(MenuSystem *menu, joysticks_t *joysticks, keyboard_t *k menu->keyboard = keyboard; } -void MenuSetBackground(MenuSystem *menu, void *bkg) +void MenuSetGraphicsDevice(MenuSystem *menu, GraphicsDevice *graphics) { - menu->bkg = bkg; + menu->graphics = graphics; } int MenuHasExitType(MenuSystem *menu, menu_type_e exitType) @@ -140,12 +140,9 @@ void MenuLoop(MenuSystem *menu) break; } // Draw - if (menu->bkg != NULL) + if (menu->graphics != NULL) { - memcpy( - gGraphicsDevice.buf, - menu->bkg, - GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(menu->graphics); } ShowControls(); MenuDisplay(menu); diff --git a/src/menu.h b/src/menu.h index 0b1bc40b3..95c68cbe7 100644 --- a/src/menu.h +++ b/src/menu.h @@ -51,6 +51,7 @@ #include #include +#include #include #include "credits.h" @@ -179,13 +180,13 @@ typedef struct credits_displayer_t *creditsDisplayer; joysticks_t *joysticks; keyboard_t *keyboard; - void *bkg; + GraphicsDevice *graphics; } MenuSystem; void MenuSetCreditsDisplayer(MenuSystem *menu, credits_displayer_t *creditsDisplayer); void MenuSetInputDevices(MenuSystem *menu, joysticks_t *joysticks, keyboard_t *keyboard); -void MenuSetBackground(MenuSystem *menu, void *bkg); +void MenuSetGraphicsDevice(MenuSystem *menu, GraphicsDevice *graphics); void MenuAddExitType(MenuSystem *menu, menu_type_e exitType); void MenuLoop(MenuSystem *menu); void MenuReset(MenuSystem *menu); diff --git a/src/password.c b/src/password.c index 0c64e213b..d45e60a0c 100644 --- a/src/password.c +++ b/src/password.c @@ -218,7 +218,7 @@ static int PasswordEntry(int cmd, char *buffer) return 1; } -static int EnterCode(void *bkg, const char *password) +static int EnterCode(GraphicsDevice *graphicsDevice, const char *password) { int mission = 0; int done = 0; @@ -229,7 +229,7 @@ static int EnterCode(void *bkg, const char *password) { int cmd; InputPoll(&gJoysticks, &gKeyboard); - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphicsDevice); cmd = GetMenuCmd(); if (!PasswordEntry(cmd, buffer)) { @@ -256,7 +256,7 @@ static int EnterCode(void *bkg, const char *password) CDogsTextWidth(buffer) + CDogsTextCharWidth(SYMBOL_LEFT) + CDogsTextCharWidth(SYMBOL_RIGHT)), - gGraphicsDevice.cachedConfig.ResolutionWidth / 4); + graphicsDevice->cachedConfig.ResolutionWidth / 4); CDogsTextChar(SYMBOL_LEFT); CDogsTextString(buffer); CDogsTextChar(SYMBOL_RIGHT); @@ -265,7 +265,7 @@ static int EnterCode(void *bkg, const char *password) "Enter code", TEXT_XCENTER | TEXT_TOP, 0, - gGraphicsDevice.cachedConfig.ResolutionHeight / 12); + graphicsDevice->cachedConfig.ResolutionHeight / 12); ShowControls(); CopyToScreen(); @@ -284,14 +284,17 @@ typedef enum } ReturnCode; MenuSystem *MenuCreateStart( - int hasPassword, void *bkg, joysticks_t *joysticks, keyboard_t *keyboard); + int hasPassword, + GraphicsDevice *graphics, + joysticks_t *joysticks, + keyboard_t *keyboard); -int EnterPassword(void *bkg, const char *password) +int EnterPassword(GraphicsDevice *graphics, const char *password) { MenuSystem *startMenu; int mission = TestPassword(password); int hasPassword = mission > 0; - startMenu = MenuCreateStart(hasPassword, bkg, &gJoysticks, &gKeyboard); + startMenu = MenuCreateStart(hasPassword, graphics, &gJoysticks, &gKeyboard); for (;;) { int returnCode; @@ -308,7 +311,7 @@ int EnterPassword(void *bkg, const char *password) } else if (returnCode == RETURN_CODE_ENTER_CODE) { - int enteredMission = EnterCode(bkg, password); + int enteredMission = EnterCode(graphics, password); if (enteredMission > 0) { return enteredMission; @@ -319,12 +322,15 @@ int EnterPassword(void *bkg, const char *password) } MenuSystem *MenuCreateStart( - int hasPassword, void *bkg, joysticks_t *joysticks, keyboard_t *keyboard) + int hasPassword, + GraphicsDevice *graphics, + joysticks_t *joysticks, + keyboard_t *keyboard) { MenuSystem *ms; CCALLOC(ms, sizeof *ms); MenuSetInputDevices(ms, joysticks, keyboard); - MenuSetBackground(ms, bkg); + MenuSetGraphicsDevice(ms, graphics); ms->root = ms->current = MenuCreateNormal("", "", MENU_TYPE_NORMAL, 0); if (hasPassword) { diff --git a/src/password.h b/src/password.h index cca38c3a8..4413fd479 100644 --- a/src/password.h +++ b/src/password.h @@ -19,10 +19,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __password -#define __password +#ifndef __PASSWORD +#define __PASSWORD + +#include const char *MakePassword(int mission); -int EnterPassword(void *bkg, const char *password); +int EnterPassword(GraphicsDevice *graphics, const char *password); #endif diff --git a/src/prep.c b/src/prep.c index 778520e7c..598b09088 100644 --- a/src/prep.c +++ b/src/prep.c @@ -1041,7 +1041,7 @@ static int MakeSelection(int mode, int x, int character, return mode; } -int PlayerSelection(int twoPlayers, void *bkg) +int PlayerSelection(int twoPlayers, GraphicsDevice *graphics) { int mode1, mode2; @@ -1057,7 +1057,7 @@ int PlayerSelection(int twoPlayers, void *bkg) int cmd1 = 0; int cmd2 = 0; InputPoll(&gJoysticks, &gKeyboard); - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to allow exit @@ -1079,7 +1079,7 @@ int PlayerSelection(int twoPlayers, void *bkg) return 1; } -int PlayerEquip(void *bkg) +int PlayerEquip(GraphicsDevice *graphics) { int done1 = 0, done2; @@ -1091,7 +1091,7 @@ int PlayerEquip(void *bkg) int cmd1 = 0; int cmd2 = 0; InputPoll(&gJoysticks, &gKeyboard); - memcpy(gGraphicsDevice.buf, bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); + GraphicsBlitBkg(graphics); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to exit from menu diff --git a/src/prep.h b/src/prep.h index 4015a9693..7a02de943 100644 --- a/src/prep.h +++ b/src/prep.h @@ -23,11 +23,11 @@ #define __PREP #include +#include -void DisplayPlayer(int x, struct PlayerData *data, int character, - int editingName); -int PlayerSelection(int twoPlayers, void *bkg); -int PlayerEquip(void *bkg); +void DisplayPlayer(int x, struct PlayerData *data, int character, int editingName); +int PlayerSelection(int twoPlayers, GraphicsDevice *graphics); +int PlayerEquip(GraphicsDevice *graphics); void LoadTemplates(void); void SaveTemplates(void);