From ff40191eab9245734d4e1b4952e4589f65fbaf43 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 12 Dec 2018 08:32:32 +0000 Subject: [PATCH] Start of resolution update. --- src/defs.h | 3 +++ src/galaxy/galacticMap.c | 28 ++++++++++++++++------------ src/game/credits.c | 10 +++++----- src/game/fighterDatabase.c | 4 ++++ src/{system => game}/load.c | 0 src/{system => game}/load.h | 0 src/{system => game}/options.c | 12 ++++++++---- src/{system => game}/options.h | 0 src/{system => game}/save.c | 0 src/{system => game}/save.h | 0 src/game/stats.c | 4 ++++ src/game/title.c | 26 ++++++++++++++------------ src/game/trophies.c | 4 ++++ src/structs.h | 6 ++++-- src/system/draw.c | 11 ++++++++--- src/system/init.c | 27 +++++++++++++++++---------- src/system/input.c | 16 +++++++++------- src/system/widgets.c | 4 ++-- 18 files changed, 98 insertions(+), 57 deletions(-) rename src/{system => game}/load.c (100%) rename src/{system => game}/load.h (100%) rename src/{system => game}/options.c (92%) rename src/{system => game}/options.h (100%) rename src/{system => game}/save.c (100%) rename src/{system => game}/save.h (100%) diff --git a/src/defs.h b/src/defs.h index 7d5dbc4..80bc547 100644 --- a/src/defs.h +++ b/src/defs.h @@ -62,6 +62,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SCREEN_WIDTH 1280 #define SCREEN_HEIGHT 720 +#define UI_WIDTH 1280 +#define UI_HEIGHT 720 + #define MAX_KEYBOARD_KEYS 350 #define MAX_MOUSE_BUTTONS 6 diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index 2b64a5c..ba668db 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -327,7 +327,7 @@ static void doStarSystemView(void) for (mission = selectedStarSystem->missionHead.next ; mission != NULL ; mission = mission->next) { - if (mission->available && collision(app.mouse.x - app.mouse.w / 2, app.mouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h)) + if (mission->available && collision(app.uiMouse.x - app.mouse.w / 2, app.uiMouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h)) { hoverMission = mission; @@ -524,17 +524,17 @@ static void drawGalaxy(void) ay = r.y; aa = -1; - ax = MAX(MIN(SCREEN_WIDTH - 64, ax), 64); - ay = MAX(MIN(SCREEN_HEIGHT - 64, ay), 64); + ax = MAX(MIN(app.winWidth - 64, ax), 64); + ay = MAX(MIN(app.winHeight - 64, ay), 64); if (r.x < 0) { ax = 64 + (sin(arrowPulse) * 10); aa = 270; } - else if (r.x > SCREEN_WIDTH) + else if (r.x > app.winWidth) { - ax = SCREEN_WIDTH - 64 + (sin(arrowPulse) * 10); + ax = app.winWidth - 64 + (sin(arrowPulse) * 10); aa = 90; } else if (r.y < 0) @@ -542,9 +542,9 @@ static void drawGalaxy(void) ay = 64 + (sin(arrowPulse) * 10); aa = 0; } - else if (r.y > SCREEN_HEIGHT) + else if (r.y > app.winHeight) { - ay = SCREEN_HEIGHT - 64 + (sin(arrowPulse) * 10); + ay = app.winHeight - 64 + (sin(arrowPulse) * 10); aa = 180; } @@ -580,8 +580,8 @@ static void drawInfoBars(void) if (show != SHOW_STAR_SYSTEM && selectedStarSystem != NULL) { r.x = 0; - r.y = SCREEN_HEIGHT - 35; - r.w = SCREEN_WIDTH; + r.y = app.winHeight - 35; + r.w = app.winWidth; r.h = 35; SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); @@ -589,19 +589,19 @@ static void drawInfoBars(void) SDL_RenderFillRect(app.renderer, &r); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); - drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 30, 18, TA_CENTER, colors.white, selectedStarSystem->description); + drawText(app.winWidth / 2, app.winHeight - 30, 18, TA_CENTER, colors.white, selectedStarSystem->description); } r.x = 0; r.y = 0; - r.w = SCREEN_WIDTH; + r.w = app.winWidth; r.h = 35; SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 200); SDL_RenderFillRect(app.renderer, &r); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); - drawText((SCREEN_WIDTH / 2), 5, 18, TA_CENTER, colors.white, MISSIONS_TEXT, game.completedMissions, game.availableMissions); + drawText((app.winWidth / 2), 5, 18, TA_CENTER, colors.white, MISSIONS_TEXT, game.completedMissions, game.availableMissions); } static void selectStarSystem(void) @@ -635,6 +635,8 @@ static void drawStarSystemDetail(void) int y; Mission *mission; SDL_Rect r; + + SDL_SetRenderTarget(app.renderer, app.uiBuffer); r.w = 900; r.h = 600; @@ -722,6 +724,8 @@ static void drawStarSystemDetail(void) startMissionButton->enabled = (!game.currentMission->completed || selectedStarSystem->type == SS_SOL || campaignComplete); drawWidgets("starSystem"); + + SDL_SetRenderTarget(app.renderer, app.backBuffer); } static void fallenOK(void) diff --git a/src/game/credits.c b/src/game/credits.c index fe19c57..2e1a0d9 100644 --- a/src/game/credits.c +++ b/src/game/credits.c @@ -70,7 +70,7 @@ static void logic(void) if (!c->next) { - c->y = MAX(c->y, (SCREEN_HEIGHT - c->h) / 2); + c->y = MAX(c->y, (app.winHeight - c->h) / 2); } } @@ -88,15 +88,15 @@ static void draw(void) drawBackground(background); - blit(earthTexture, SCREEN_WIDTH - 200, (SCREEN_HEIGHT / 2) + 100, 1); + blit(earthTexture, app.winWidth - 200, (app.winHeight / 2) + 100, 1); app.textWidth = CREDIT_LINE_LIMIT; for (c = head.next ; c != NULL ; c = c->next) { - if (c->y > -c->h && c->y < SCREEN_HEIGHT) + if (c->y > -c->h && c->y < app.winHeight) { - drawText(SCREEN_WIDTH / 2, (int)c->y, c->size, TA_CENTER, colors.white, c->text); + drawText(app.winWidth / 2, (int)c->y, c->size, TA_CENTER, colors.white, c->text); } } @@ -110,7 +110,7 @@ static void loadCredits(void) char *text; Credit *c; - y = SCREEN_HEIGHT + 100; + y = app.winHeight + 100; text = readFile("data/credits/credits.json"); root = cJSON_Parse(text); diff --git a/src/game/fighterDatabase.c b/src/game/fighterDatabase.c index d325670..085eefc 100644 --- a/src/game/fighterDatabase.c +++ b/src/game/fighterDatabase.c @@ -100,6 +100,8 @@ void drawFighterDatabase(void) Entity *fighter; int i, y, numCannons; + SDL_SetRenderTarget(app.renderer, app.uiBuffer); + SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_RenderFillRect(app.renderer, NULL); @@ -164,6 +166,8 @@ void drawFighterDatabase(void) app.textWidth = 0; drawWidgets("fighterDB"); + + SDL_SetRenderTarget(app.renderer, app.backBuffer); } static int countFighterGuns(Entity *fighter, int type) diff --git a/src/system/load.c b/src/game/load.c similarity index 100% rename from src/system/load.c rename to src/game/load.c diff --git a/src/system/load.h b/src/game/load.h similarity index 100% rename from src/system/load.h rename to src/game/load.h diff --git a/src/system/options.c b/src/game/options.c similarity index 92% rename from src/system/options.c rename to src/game/options.c index def477b..3559c4f 100644 --- a/src/system/options.c +++ b/src/game/options.c @@ -90,6 +90,8 @@ void drawOptions(void) static void drawMain(void) { SDL_Rect r; + + SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); @@ -98,15 +100,15 @@ static void drawMain(void) r.w = 500; r.h = 600; - r.x = (SCREEN_WIDTH / 2) - r.w / 2; - r.y = (SCREEN_HEIGHT / 2) - r.h / 2; + r.x = (UI_WIDTH / 2) - r.w / 2; + r.y = (UI_HEIGHT / 2) - r.h / 2; SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_RenderFillRect(app.renderer, &r); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255); SDL_RenderDrawRect(app.renderer, &r); - drawText(SCREEN_WIDTH / 2, 70, 28, TA_CENTER, colors.white, OPTIONS_TEXT); + drawText(UI_WIDTH / 2, 70, 28, TA_CENTER, colors.white, OPTIONS_TEXT); SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); SDL_RenderDrawLine(app.renderer, r.x, 120, r.x + r.w, 120); @@ -115,9 +117,11 @@ static void drawMain(void) app.textWidth = r.w - 100; - drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, RESOLUTION_TEXT); + drawText(UI_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, RESOLUTION_TEXT); app.textWidth = 0; + + SDL_SetRenderTarget(app.renderer, app.backBuffer); } void updateCustomResolutionOption(void) diff --git a/src/system/options.h b/src/game/options.h similarity index 100% rename from src/system/options.h rename to src/game/options.h diff --git a/src/system/save.c b/src/game/save.c similarity index 100% rename from src/system/save.c rename to src/game/save.c diff --git a/src/system/save.h b/src/game/save.h similarity index 100% rename from src/system/save.h rename to src/game/save.h diff --git a/src/game/stats.c b/src/game/stats.c index 96d6366..2a61f0f 100644 --- a/src/game/stats.c +++ b/src/game/stats.c @@ -131,6 +131,8 @@ void drawStats(void) int i, y, startIndex; SDL_Rect r; + SDL_SetRenderTarget(app.renderer, app.uiBuffer); + SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_RenderFillRect(app.renderer, NULL); @@ -185,6 +187,8 @@ void drawStats(void) drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1)); drawWidgets("stats"); + + SDL_SetRenderTarget(app.renderer, app.backBuffer); } static void nextPage(void) diff --git a/src/game/title.c b/src/game/title.c index a92eb1b..d110e4f 100644 --- a/src/game/title.c +++ b/src/game/title.c @@ -69,7 +69,7 @@ void initTitle(void) earthTexture = getAtlasImage("gfx/planets/earth.png"); - earth.x = rand() % SCREEN_WIDTH; + earth.x = rand() % app.winWidth; earth.y = -(128 + (rand() % 128)); initEffects(); @@ -110,8 +110,8 @@ static void initFighters(void) for (i = 0 ; i < NUM_FIGHTERS ; i++) { - fighters[i].x = rand() % (SCREEN_WIDTH - 32); - fighters[i].y = SCREEN_HEIGHT + (rand() % SCREEN_HEIGHT); + fighters[i].x = rand() % (app.winWidth - 32); + fighters[i].y = app.winHeight + (rand() % app.winHeight); fighters[i].texture = getAtlasImage(fighterTextures[rand() % numTextures]); fighters[i].dy = -(1 + rand() % 3); } @@ -127,9 +127,9 @@ static void logic(void) earth.y += 0.1; - if (earth.y > SCREEN_HEIGHT + 128) + if (earth.y > app.winHeight + 128) { - earth.x = rand() % SCREEN_WIDTH; + earth.x = rand() % app.winWidth; earth.y = -(128 + (rand() % 128)); } @@ -166,8 +166,8 @@ static void doFighters(void) if (self->y <= -64) { - self->x = rand() % (SCREEN_WIDTH - 32); - self->y = SCREEN_HEIGHT + (rand() % SCREEN_HEIGHT); + self->x = rand() % (app.winWidth - 32); + self->y = app.winHeight + (rand() % app.winHeight); self->texture = getAtlasImage(fighterTextures[rand() % numTextures]); self->dy = -(1 + rand() % 3); } @@ -190,18 +190,20 @@ static void draw(void) setAtlasColor(255, 255, 255, 255); - blit(logo[0], (SCREEN_WIDTH / 2) - logo[0]->rect.w, 30, 0); - blit(logo[1], (SCREEN_WIDTH / 2), 30, 0); + blit(logo[0], (app.winWidth / 2) - logo[0]->rect.w, 30, 0); + blit(logo[1], (app.winWidth / 2), 30, 0); - blit(pandoranWar, SCREEN_WIDTH / 2, 110, 1); + blit(pandoranWar, app.winWidth / 2, 110, 1); - drawText(10, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2018"); - drawText(SCREEN_WIDTH - 10, SCREEN_HEIGHT - 25, 14, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION); + drawText(10, app.winHeight - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2018"); + drawText(app.winWidth - 10, app.winHeight - 25, 14, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION); switch (show) { case SHOW_TITLE: + SDL_SetRenderTarget(app.renderer, app.uiBuffer); drawWidgets("title"); + SDL_SetRenderTarget(app.renderer, app.backBuffer); break; case SHOW_STATS: diff --git a/src/game/trophies.c b/src/game/trophies.c index a72bada..7c267f9 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -133,6 +133,8 @@ void drawTrophies(void) SDL_Rect r; int start, end, i, x, y; + SDL_SetRenderTarget(app.renderer, app.uiBuffer); + SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_RenderFillRect(app.renderer, NULL); @@ -201,6 +203,8 @@ void drawTrophies(void) } drawWidgets("trophies"); + + SDL_SetRenderTarget(app.renderer, app.backBuffer); } void awardTrophy(char *id) diff --git a/src/structs.h b/src/structs.h index cfff2c5..60b3f98 100644 --- a/src/structs.h +++ b/src/structs.h @@ -498,8 +498,8 @@ typedef struct { int saveGame; int winWidth; int winHeight; - float scaleX; - float scaleY; + PointF scale; + PointF uiScale; int fullscreen; int musicVolume; int soundVolume; @@ -508,8 +508,10 @@ typedef struct { int hideMouse; Gameplay gameplay; Mouse mouse; + PointF uiMouse; int keyboard[MAX_KEYBOARD_KEYS]; SDL_Texture *backBuffer; + SDL_Texture *uiBuffer; SDL_Renderer *renderer; SDL_Window *window; Delegate delegate; diff --git a/src/system/draw.c b/src/system/draw.c index 2591015..dbd612c 100644 --- a/src/system/draw.c +++ b/src/system/draw.c @@ -62,6 +62,10 @@ static void initColor(SDL_Color *c, int r, int g, int b) void prepareScene(void) { + SDL_SetRenderTarget(app.renderer, app.uiBuffer); + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0); + SDL_RenderClear(app.renderer); + SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_RenderClear(app.renderer); @@ -72,19 +76,20 @@ void presentScene(void) if (dev.debug) { drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); + if (dev.showFPS) { drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps); } } + SDL_SetRenderTarget(app.renderer, NULL); + SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL); + SDL_RenderCopy(app.renderer, app.uiBuffer, NULL, NULL); if (!app.hideMouse) { drawMouse(); } - - SDL_SetRenderTarget(app.renderer, NULL); - SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL); SDL_RenderPresent(app.renderer); } diff --git a/src/system/init.c b/src/system/init.c index e87f528..7ef8acb 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -111,14 +111,21 @@ void initSDL(int argc, char *argv[]) exit(1); } - app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT); + app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, app.winWidth, app.winHeight); - app.scaleX = SCREEN_WIDTH; - app.scaleX /= app.winWidth; - app.scaleY = SCREEN_HEIGHT; - app.scaleY /= app.winHeight; + app.scale.x = app.scale.y = 1; + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Game scale factor: %.2f,%.2f\n", app.scale.x, app.scale.y); + + app.uiBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, UI_WIDTH, UI_HEIGHT); + SDL_SetTextureBlendMode(app.uiBuffer, SDL_BLENDMODE_BLEND); - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Game scale factor: %.2f,%.2f\n", app.scaleX, app.scaleY); + app.uiScale.x = UI_WIDTH; + app.uiScale.x /= app.winWidth; + app.uiScale.y = UI_HEIGHT; + app.uiScale.y /= app.winHeight; + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "UI scale factor: %.2f,%.2f\n", app.uiScale.x, app.uiScale.y); } void initGameSystem(void) @@ -169,10 +176,10 @@ static void showLoadingStep(float step, float maxSteps) prepareScene(); - r.w = SCREEN_WIDTH - 400; - r.h = 14; - r.x = (SCREEN_WIDTH / 2) - r.w / 2; - r.y = (SCREEN_HEIGHT / 2) - r.h / 2; + r.w = 600; + r.h = 12; + r.x = (app.winWidth / 2) - r.w / 2; + r.y = (app.winHeight / 2) - r.h / 2; SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); SDL_RenderDrawRect(app.renderer, &r); diff --git a/src/system/input.c b/src/system/input.c index 409f5ff..93a7b13 100644 --- a/src/system/input.c +++ b/src/system/input.c @@ -108,13 +108,6 @@ void setMouseCursor(int isDrag) void drawMouse(void) { - int x, y; - - SDL_GetMouseState(&x, &y); - - app.mouse.x = x * app.scaleX; - app.mouse.y = y * app.scaleY; - setAtlasColor(255, 255, 255, 255); blit(mousePointer, app.mouse.x, app.mouse.y, 1); @@ -123,6 +116,7 @@ void drawMouse(void) void doInput(void) { SDL_Event event; + int x, y; while (SDL_PollEvent(&event)) { @@ -169,6 +163,14 @@ void doInput(void) break; } } + + SDL_GetMouseState(&x, &y); + + app.mouse.x = x * app.scale.x; + app.mouse.y = y * app.scale.y; + + app.uiMouse.x = x * app.uiScale.x; + app.uiMouse.y = y * app.uiScale.y; } void clearInput(void) diff --git a/src/system/widgets.c b/src/system/widgets.c index e42f5f5..107fc1d 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -131,7 +131,7 @@ void drawWidgets(const char *group) { if (!mouseOver && !app.awaitingWidgetInput) { - mouseOver = (w->type != WT_SELECT && w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.mouse.x, app.mouse.y, 1, 1)); + mouseOver = (w->type != WT_SELECT && w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.uiMouse.x, app.uiMouse.y, 1, 1)); if (mouseOver && selectedWidget != w) { @@ -257,7 +257,7 @@ static void handleMouse(void) { Widget *old; - if (selectedWidget && collision(selectedWidget->rect.x, selectedWidget->rect.y, selectedWidget->rect.w, selectedWidget->rect.h, app.mouse.x, app.mouse.y, 1, 1)) + if (selectedWidget && collision(selectedWidget->rect.x, selectedWidget->rect.y, selectedWidget->rect.w, selectedWidget->rect.h, app.uiMouse.x, app.uiMouse.y, 1, 1)) { if (app.mouse.button[SDL_BUTTON_LEFT]) {