diff --git a/src/TextBox/SaveSelect.cpp b/src/TextBox/SaveSelect.cpp index 3218ee10..d8887d70 100644 --- a/src/TextBox/SaveSelect.cpp +++ b/src/TextBox/SaveSelect.cpp @@ -71,16 +71,8 @@ void TB_SaveSelect::SetVisible(bool enable, bool saving) fCoords.w = 244; fCoords.h = 152; - if (Renderer::getInstance()->widescreen) - { - fCoords.x = (Renderer::getInstance()->screenWidth / 2) - (fCoords.w / 2); - fCoords.y = 30; - } - else - { - fCoords.x = 38; - fCoords.y = 8; - } + fCoords.x = (Renderer::getInstance()->screenWidth / 2) - (fCoords.w / 2); + fCoords.y = 8; fNumFiles = MAX_SAVE_SLOTS; fSaving = saving; diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 71da492a..fa96af31 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -31,23 +31,14 @@ Font::Font() bool Font::load() { cleanup(); - std::string font = std::string("font_" + std::to_string(Renderer::getInstance()->scale) + ".fnt"); + std::string font = std::string("font_1.fnt"); LOG_DEBUG("Loading font file {}", font.c_str()); // special empty glyph _glyphs[0] = Font::Glyph{0, 0, 0, 0, 0, 0, 0, 0, 0}; std::string path = ResourceManager::getInstance()->getPath(font); - if (ResourceManager::getInstance()->fileExists(path)) - { - _upscale = 1; - } - else - { - _upscale = Renderer::getInstance()->scale; - font = std::string("font_1.fnt"); - path = ResourceManager::getInstance()->getPath(font); - } + ResourceManager::getInstance()->fileExists(path); LOG_DEBUG("Loading font file {}", path.c_str()); @@ -123,9 +114,6 @@ SDL_Texture *Font::atlas(uint32_t idx) uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool isShaded) { - x *= Renderer::getInstance()->scale; - y *= Renderer::getInstance()->scale; - int orgx = x; int i = 0; SDL_Rect dstrect; @@ -152,8 +140,8 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool { if (_rendering) { - int offset = (int)round(((double)_height / (double)Renderer::getInstance()->scale - 6.) / 2.); - Renderer::getInstance()->sprites.drawSprite((x / Renderer::getInstance()->scale), (y / Renderer::getInstance()->scale) + offset, SPR_TEXTBULLET); + int offset = (int)round(((double)_height - 6.) / 2.); + Renderer::getInstance()->sprites.drawSprite(x, y + offset, SPR_TEXTBULLET); } } else if (_rendering && ch != ' ') @@ -178,7 +166,7 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool if (isShaded) { shdrect.x = x + (glyph.xoffset * _upscale); - shdrect.y = y + (glyph.yoffset * _upscale + _shadowOffset * Renderer::getInstance()->scale); + shdrect.y = y + (glyph.yoffset * _upscale + _shadowOffset); shdrect.w = glyph.w * _upscale; shdrect.h = glyph.h * _upscale; SDL_SetTextureColorMod(atlas, 0, 0, 0); @@ -194,21 +182,21 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool { // 10.5 px for spaces - make smaller than they really are - the default if (rtl()) { - x -= (Renderer::getInstance()->scale == 1) ? 5 : 10; + x -= 5; if (i & 1) x--; } else { - x += (Renderer::getInstance()->scale == 1) ? 5 : 10; + x += 5; if (i & 1) x++; } } else if (ch == '=' && game.mode != GM_CREDITS) { - if (rtl()) x -= 7 * Renderer::getInstance()->scale; - else x += 7 * Renderer::getInstance()->scale; + if (rtl()) x -= 7; + else x += 7; } else { @@ -219,14 +207,11 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool } // return the final width of the text drawn - return abs((x - orgx) / Renderer::getInstance()->scale); + return abs(x - orgx); } uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bool isShaded) { - x *= Renderer::getInstance()->scale; - y *= Renderer::getInstance()->scale; - int orgx = x; int i = 0; SDL_Rect dstrect; @@ -252,8 +237,8 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo { if (_rendering) { - int offset = (int)round(((double)_height / (double)Renderer::getInstance()->scale - 6.) / 2.); - Renderer::getInstance()->sprites.drawSprite((x / Renderer::getInstance()->scale), (y / Renderer::getInstance()->scale) + offset, SPR_TEXTBULLET); + int offset = (int)round(((double)_height - 6.) / 2.); + Renderer::getInstance()->sprites.drawSprite(x, y + offset, SPR_TEXTBULLET); } } else if (_rendering && ch != ' ') @@ -278,7 +263,7 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo if (isShaded) { shdrect.x = x + (glyph.xoffset * _upscale); - shdrect.y = y + glyph.yoffset * _upscale + _shadowOffset * Renderer::getInstance()->scale; + shdrect.y = y + glyph.yoffset * _upscale + _shadowOffset; shdrect.w = glyph.w * _upscale; shdrect.h = glyph.h * _upscale; SDL_SetTextureColorMod(atlas, 0, 0, 0); @@ -292,13 +277,13 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo if (ch == ' ') { // 10.5 px for spaces - make smaller than they really are - the default - x += (Renderer::getInstance()->scale == 1) ? 5 : 10; + x += 5; if (i & 1) x++; } else if (ch == '=' && game.mode != GM_CREDITS) { - x += 7 * Renderer::getInstance()->scale; + x += 7; } else { @@ -308,7 +293,7 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo } // return the final width of the text drawn - return abs((x - orgx) / Renderer::getInstance()->scale); + return abs(x - orgx); } uint32_t Font::getWidth(const std::string &text) @@ -324,12 +309,12 @@ uint32_t Font::getWidth(const std::string &text) uint32_t Font::getHeight() const { - return _height / ((_upscale == 1) ? Renderer::getInstance()->scale : 1); + return _height; } uint32_t Font::getBase() const { - return _base / ((_upscale == 1) ? Renderer::getInstance()->scale : 1); + return _base; } }; // namespace Graphics diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index d6b94868..90c5d966 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -32,18 +32,18 @@ Renderer *Renderer::getInstance() return Singleton::get(); } -bool Renderer::init(int resolution) +bool Renderer::init(int scale, bool newWidescreen) { - _current_res = resolution; - if (!initVideo()) - return false; - + widescreen = newWidescreen; if (!font.load()) return false; if (!sprites.init()) return false; + if (!initVideo(scale)) + return false; + return true; } @@ -65,18 +65,9 @@ bool Renderer::isWindowVisible() && (flags & SDL_WINDOW_INPUT_FOCUS); // SDL_APPINPUTFOCUS } -bool Renderer::initVideo() +bool Renderer::initVideo(int scale) { - uint32_t window_flags = SDL_WINDOW_SHOWN; - - const NXE::Graphics::gres_t *res = getResolutions(true); - - uint32_t width = res[_current_res].width; - uint32_t height = res[_current_res].height; - scale = res[_current_res].scale; - screenHeight = res[_current_res].base_height; - screenWidth = res[_current_res].base_width; - widescreen = res[_current_res].widescreen; + uint32_t window_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI; if (_window) { @@ -84,8 +75,8 @@ bool Renderer::initVideo() return false; } - LOG_DEBUG("SDL_CreateWindow: {}x{}", width, height); - _window = SDL_CreateWindow(NXVERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); + LOG_DEBUG("SDL_CreateWindow: {}x{}", screenWidth, screenHeight); + _window = SDL_CreateWindow(NXVERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth * scale, screenHeight * scale, window_flags); if (!_window) { @@ -133,6 +124,9 @@ bool Renderer::initVideo() LOG_INFO("Renderer::initVideo: using: {} renderer", info.name); + if (!setResolution(scale, widescreen)) + return false; + std::string spotpath = ResourceManager::getInstance()->getPath("spot.png"); SDL_Surface *image; @@ -156,119 +150,94 @@ bool Renderer::flushAll() return true; } -void Renderer::setFullscreen(bool enable) +bool Renderer::setFullscreen(bool enable) { + _fullscreen = enable; SDL_ShowCursor(!enable); - SDL_SetWindowFullscreen(_window, (enable ? SDL_WINDOW_FULLSCREEN : 0)); + if (SDL_SetWindowFullscreen(_window, (enable ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0))) { + LOG_ERROR("Renderer::setFullscreen: SDL_SetWindowFullscreen failed: {}", SDL_GetError()); + return false; + } + if (SDL_RenderSetLogicalSize(_renderer, screenWidth, screenHeight)) { + LOG_ERROR("Renderer::setFullscreen: SDL_RenderSetLogicalSize failed: {}", SDL_GetError()); + return false; + } + + return true; } -bool Renderer::setResolution(int r, bool restoreOnFailure) +bool Renderer::setResolution(int scale, bool newWidescreen) { -#if defined(__VITA__) || defined(__SWITCH__) - r = 1; // one fixed resolution + int newWidth, newHeight; +#if defined(__VITA__) + newWidth = 480; + newHeight = 272; + newWidescreen = true; +#else +#if defined(__SWITCH__) + newWidescreen = true; #endif - - LOG_INFO("Renderer::setResolution({})", r); - if (r == _current_res) - return 0; - - uint32_t width = screenWidth; - uint32_t height = screenHeight; - - if (r == 0) - { - scale = 1; - widescreen = false; - } - else - { - const NXE::Graphics::gres_t *res = getResolutions(); - scale = res[r].scale; - screenHeight = res[r].base_height; - screenWidth = res[r].base_width; - widescreen = res[r].widescreen; - width = res[r].width; - height = res[r].height; + if (newWidescreen) { + newWidth = 432; + newHeight = 243; + } else { + newWidth = 320; + newHeight = 240; } +#endif - LOG_INFO("Setting scaling {}", scale); + LOG_INFO("Renderer logical resolution: {}x{}", newWidth, newHeight); - SDL_SetWindowSize(_window, width, height); + SDL_SetWindowSize(_window, newWidth * scale, newHeight * scale); - _current_res = r; + SDL_SetRenderTarget(_renderer, NULL); + SDL_DestroyTexture(_texture); + if (SDL_RenderSetLogicalSize(_renderer, newWidth, newHeight)) { + LOG_ERROR("Renderer::setResolution: SDL_RenderSetLogicalSize failed: {}", SDL_GetError()); + return false; + } if (!flushAll()) return false; + if (!createRenderTarget(newWidth, newHeight)) + return false; + + screenWidth = newWidth; + screenHeight = newHeight; + widescreen = newWidescreen; + recalc_map_offsets(); textbox.RecalculateOffsets(); return true; } -const Graphics::gres_t *Renderer::getResolutions(bool full_list) +int Renderer::getResolutionCount() { - static NXE::Graphics::gres_t res[] - = {// description, screen_w, screen_h, render_w, render_h, scale_factor, widescreen, enabled - // 4:3 - {(char *)"---", 0, 0, 0, 0, 1, false, true}, -#if defined(__VITA__) - {(char *)"960x544", 960, 544, 480, 272, 2, true, true}, -#elif defined(__SWITCH__) - {(char *)"1920x1080", 1920, 1080, 480, 270, 4, true, true}, +#if defined(__VITA__) || defined(__SWITCH__) + return 1; #else - {(char *)"320x240", 320, 240, 320, 240, 1, false, true}, - {(char *)"640x480", 640, 480, 320, 240, 2, false, true}, - // {(char*)"800x600", 800, 600, 320, 240, 2.5, false, true }, - // //requires float scalefactor - {(char *)"1024x768", 1024, 768, 341, 256, 3, false, true}, - {(char *)"1280x1024", 1280, 1024, 320, 256, 4, false, true}, - {(char *)"1600x1200", 1600, 1200, 320, 240, 5, false, true}, - // widescreen - {(char *)"480x272", 480, 272, 480, 272, 1, true, true}, - {(char *)"800x480", 800, 480, 400, 240, 2, true, true}, - {(char *)"1024x600", 1024, 600, 512, 300, 2, true, true}, - {(char *)"1280x720", 1280, 720, 427, 240, 3, true, true}, - {(char *)"1280x800", 1280, 800, 427, 267, 3, true, true}, - {(char *)"1360x768", 1360, 768, 454, 256, 3, true, true}, - {(char *)"1366x768", 1366, 768, 455, 256, 3, true, true}, - {(char *)"1440x900", 1440, 900, 480, 300, 3, true, true}, - {(char *)"1600x900", 1600, 900, 533, 300, 3, true, true}, - {(char *)"1920x1080", 1920, 1080, 480, 270, 4, true, true}, - {(char *)"2560x1440", 2560, 1440, 512, 288, 5, true, true}, - {(char *)"3840x2160", 3840, 2160, 480, 270, 8, true, true}, + return 4; #endif - {NULL, 0, 0, 0, 0, 0, false, false}}; - - if (!full_list) - { - int displayIdx = SDL_GetWindowDisplayIndex(_window); - LOG_DEBUG("Display idx: {}",displayIdx); - SDL_DisplayMode dm; - SDL_GetDesktopDisplayMode(displayIdx, &dm); - - LOG_INFO("Display W: {}, Display H: {}", dm.w, dm.h); - for (int i = 0; res[i].name; i++) - { - if (res[i].width > (uint32_t)dm.w || res[i].height > (uint32_t)dm.h) - { - LOG_INFO("Disabling {}", res[i].name); - - res[i].enabled = false; - } - } - } - return res; } -int Renderer::getResolutionCount() +bool Renderer::createRenderTarget(int width, int height) { - int i; - const gres_t *res = getResolutions(); + SDL_RendererInfo info; + SDL_GetRendererInfo(_renderer, &info); + + _texture = SDL_CreateTexture(_renderer, + info.texture_formats[0], + SDL_TEXTUREACCESS_TARGET, + width, height); + if (SDL_SetRenderTarget(_renderer, _texture)) { + LOG_ERROR("Renderer::createRenderTarget: SDL_SetRenderTarget failed: {}", SDL_GetError()); + return false; + } + SDL_RenderClear(_renderer); - for (i = 0; res[i].name; i++) - ; - return i; + return true; } void Renderer::showLoadingScreen() @@ -299,7 +268,12 @@ SDL_Window* Renderer::window() void Renderer::flip() { // LOG_INFO("===FLIPPING===\n"); + SDL_SetRenderTarget(_renderer, NULL); + SDL_SetRenderDrawColor(_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); + SDL_RenderClear(_renderer); + SDL_RenderCopy(_renderer, _texture, NULL, NULL); SDL_RenderPresent(_renderer); + SDL_SetRenderTarget(_renderer, _texture); // LOG_INFO("===FLIPPED===\n"); } @@ -311,13 +285,13 @@ void Renderer::drawSurface(Surface *src, int dstx, int dsty, int srcx, int srcy, SDL_Rect srcrect, dstrect; - srcrect.x = srcx * scale; - srcrect.y = srcy * scale; - srcrect.w = wd * scale; - srcrect.h = ht * scale; + srcrect.x = srcx; + srcrect.y = srcy; + srcrect.w = wd; + srcrect.h = ht; - dstrect.x = dstx * scale; - dstrect.y = dsty * scale; + dstrect.x = dstx; + dstrect.y = dsty; dstrect.w = srcrect.w; dstrect.h = srcrect.h; @@ -339,13 +313,13 @@ void Renderer::drawSurfaceMirrored(Surface *src, int dstx, int dsty, int srcx, i SDL_Rect srcrect, dstrect; - srcrect.x = srcx * scale; - srcrect.y = srcy * scale; - srcrect.w = wd * scale; - srcrect.h = ht * scale; + srcrect.x = srcx; + srcrect.y = srcy; + srcrect.w = wd; + srcrect.h = ht; - dstrect.x = dstx * scale; - dstrect.y = dsty * scale; + dstrect.x = dstx; + dstrect.y = dsty; dstrect.w = srcrect.w; dstrect.h = srcrect.h; @@ -365,16 +339,16 @@ void Renderer::blitPatternAcross(Surface *sfc, int x_dst, int y_dst, int y_src, SDL_Rect srcrect, dstrect; srcrect.x = 0; - srcrect.w = sfc->width() * scale; - srcrect.y = (y_src * scale); - srcrect.h = (height * scale); + srcrect.w = sfc->width(); + srcrect.y = y_src; + srcrect.h = height; dstrect.w = srcrect.w; dstrect.h = srcrect.h; - int x = (x_dst * scale); - int y = (y_dst * scale); - int destwd = screenWidth * scale; + int x = x_dst; + int y = y_dst; + int destwd = screenWidth; assert(!_need_clip && "clip for blitpattern is not implemented"); @@ -383,22 +357,22 @@ void Renderer::blitPatternAcross(Surface *sfc, int x_dst, int y_dst, int y_src, dstrect.x = x; dstrect.y = y; SDL_RenderCopy(_renderer, sfc->texture(), &srcrect, &dstrect); - x += sfc->width() * scale; + x += sfc->width(); } while (x < destwd); } void Renderer::drawLine(int x1, int y1, int x2, int y2, NXColor color) { SDL_SetRenderDrawColor(_renderer, color.r, color.g, color.b, SDL_ALPHA_OPAQUE); - SDL_RenderDrawLine(_renderer, x1 * scale, y1 * scale, x2 * scale, y2 * scale); + SDL_RenderDrawLine(_renderer, x1, y1, x2, y2); } void Renderer::drawRect(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, uint8_t b) { - SDL_Rect rects[4] = {{x1 * scale, y1 * scale, ((x2 - x1) + 1) * scale, scale}, - {x1 * scale, y2 * scale, ((x2 - x1) + 1) * scale, scale}, - {x1 * scale, y1 * scale, scale, ((y2 - y1) + 1) * scale}, - {x2 * scale, y1 * scale, scale, ((y2 - y1) + 1) * scale}}; + SDL_Rect rects[4] = {{x1, y1, ((x2 - x1) + 1), 1}, + {x1, y2, ((x2 - x1) + 1), 1}, + {x1, y1, 1, ((y2 - y1) + 1)}, + {x2, y1, 1, ((y2 - y1) + 1)}}; SDL_SetRenderDrawColor(_renderer, r, g, b, SDL_ALPHA_OPAQUE); SDL_RenderFillRects(_renderer, rects, 4); @@ -408,10 +382,10 @@ void Renderer::fillRect(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, ui { SDL_Rect rect; - rect.x = x1 * scale; - rect.y = y1 * scale; - rect.w = ((x2 - x1) + 1) * scale; - rect.h = ((y2 - y1) + 1) * scale; + rect.x = x1; + rect.y = y1; + rect.w = ((x2 - x1) + 1); + rect.h = ((y2 - y1) + 1); SDL_SetRenderDrawColor(_renderer, r, g, b, SDL_ALPHA_OPAQUE); SDL_RenderFillRect(_renderer, &rect);} @@ -438,10 +412,10 @@ void Renderer::setClip(int x, int y, int w, int h) { _need_clip = true; - _clip_rect.x = x * scale; - _clip_rect.y = y * scale; - _clip_rect.w = w * scale; - _clip_rect.h = h * scale; + _clip_rect.x = x; + _clip_rect.y = y; + _clip_rect.w = w; + _clip_rect.h = h; } void Renderer::clearClip() @@ -467,7 +441,7 @@ void Renderer::clip(SDL_Rect &srcrect, SDL_Rect &dstrect) { w -= dx; dstrect.x += dx; - srcrect.x += dx / scale; + srcrect.x += dx; } dx = dstrect.x + w - _clip_rect.x - _clip_rect.w; if (dx > 0) @@ -478,7 +452,7 @@ void Renderer::clip(SDL_Rect &srcrect, SDL_Rect &dstrect) { h -= dy; dstrect.y += dy; - srcrect.y += dy / scale; + srcrect.y += dy; } dy = dstrect.y + h - _clip_rect.y - _clip_rect.h; if (dy > 0) @@ -486,8 +460,8 @@ void Renderer::clip(SDL_Rect &srcrect, SDL_Rect &dstrect) dstrect.w = w; dstrect.h = h; - srcrect.w = w / scale; - srcrect.h = h / scale; + srcrect.w = w; + srcrect.h = h; } void Renderer::clipScaled(SDL_Rect &srcrect, SDL_Rect &dstrect) @@ -591,13 +565,10 @@ void Renderer::drawSpotLight(int x, int y, Object* o, int r, int g, int b, int u int width = o->Width() / CSFI; int height = o->Height() / CSFI; - x *= scale; - y *= scale; - - dstrec.x = (x - (width * (upscale / 2) * scale) + (width / 2 * scale)); - dstrec.y = (y - (height * (upscale / 2) * scale) + (height / 2 * scale)); - dstrec.w = width * upscale * scale; - dstrec.h = height * upscale * scale; + dstrec.x = (x - (width * (upscale / 2)) + (width / 2)); + dstrec.y = (y - (height * (upscale / 2)) + (height / 2)); + dstrec.w = width * upscale; + dstrec.h = height * upscale; SDL_SetTextureColorMod(_spot_light, r, g, b); SDL_RenderCopy(_renderer, _spot_light, NULL, &dstrec); diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index a5208a03..088d254b 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -24,18 +24,6 @@ const NXColor GREEN2(0x0,0x98,0x0); const NXColor GREEN3(0x0,0x4E,0x0); const NXColor GREEN4(0x0,0x19,0x0); -typedef struct -{ - char *name; - uint32_t width; - uint32_t height; - uint32_t base_width; - uint32_t base_height; - uint32_t scale; - bool widescreen; - bool enabled; -} gres_t; - class Renderer { public: @@ -44,18 +32,16 @@ class Renderer int screenWidth = 320; int screenHeight = 240; bool widescreen = false; - int scale = 1; - bool init(int resolution); + bool init(int scale, bool newWidescreen); void close(); bool isWindowVisible(); - bool initVideo(); - void setFullscreen(bool enable); + bool initVideo(int scale); + bool setFullscreen(bool enable); bool setResolution(int factor, bool restoreOnFailure = true); - const gres_t *getResolutions(bool full_list = false); int getResolutionCount(); bool flushAll(); @@ -108,10 +94,14 @@ class Renderer private: SDL_Window *_window = nullptr; SDL_Renderer *_renderer = nullptr; + SDL_Texture *_texture = nullptr; int _current_res = -1; bool _need_clip = false; SDL_Rect _clip_rect; SDL_Texture* _spot_light; + bool _fullscreen = false; + + bool createRenderTarget(int width, int height); protected: friend class Singleton; diff --git a/src/graphics/Surface.cpp b/src/graphics/Surface.cpp index b6f5224c..ba7f130e 100644 --- a/src/graphics/Surface.cpp +++ b/src/graphics/Surface.cpp @@ -32,20 +32,17 @@ bool Surface::loadImage(const std::string &pbm_name, bool use_colorkey) return false; } - _width = image->w * Renderer::getInstance()->scale; - _height = image->h * Renderer::getInstance()->scale; - - SDL_Surface *image_scaled = SDL_ZoomSurface(image, Renderer::getInstance()->scale); - SDL_FreeSurface(image); + _width = image->w; + _height = image->h; if (use_colorkey) { - SDL_SetColorKey(image_scaled, SDL_TRUE, SDL_MapRGB(image_scaled->format, 0, 0, 0)); + SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, 0, 0, 0)); } - _texture = SDL_CreateTextureFromSurface(Renderer::getInstance()->renderer(), image_scaled); + _texture = SDL_CreateTextureFromSurface(Renderer::getInstance()->renderer(), image); - SDL_FreeSurface(image_scaled); + SDL_FreeSurface(image); if (!_texture) { @@ -70,12 +67,12 @@ Surface *Surface::fromFile(const std::string &pbm_name, bool use_colorkey) int Surface::width() { - return _width / Renderer::getInstance()->scale; + return _width; } int Surface::height() { - return _height / Renderer::getInstance()->scale; + return _height; } SDL_Texture* Surface::texture() diff --git a/src/inventory.cpp b/src/inventory.cpp index d0d611d7..ff1afbb9 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -41,11 +41,6 @@ int RefreshInventoryScreen(void) inv.w = 244; inv.h = 152; - inv.x = (Renderer::getInstance()->screenWidth / 2) - (inv.w / 2); - if (Renderer::getInstance()->widescreen) - inv.y = 30; - else - inv.y = 8; // find current weapon and count # items for armssel selector inv.armssel.items[0] = 0; // show "no weapon" in case of no weapon @@ -132,14 +127,16 @@ static void DrawSelector(stSelector *selector, int x, int y) void DrawInventory(void) { + int inv_x = (Renderer::getInstance()->screenWidth / 2) - (inv.w / 2); + int inv_y = 8; int x, y, i, c; // draw the box - TextBox::DrawFrame(inv.x, inv.y, inv.w, inv.h); + TextBox::DrawFrame(inv_x, inv_y, inv.w, inv.h); // - draw the weapons ---- - x = inv.x + ARMS_X; - y = inv.y + ARMS_Y; + x = inv_x + ARMS_X; + y = inv_y + ARMS_Y; Renderer::getInstance()->sprites.drawSprite(x, y, SPR_TEXT_ARMS, 0, 0); y += Renderer::getInstance()->sprites.sprites[SPR_TEXT_ARMS].h; @@ -159,8 +156,8 @@ void DrawInventory(void) } // - draw the items ---- - x = inv.x + ITEMS_X; - y = inv.y + ITEMS_Y; + x = inv_x + ITEMS_X; + y = inv_y + ITEMS_Y; Renderer::getInstance()->sprites.drawSprite(x, y, SPR_TEXT_ITEMS, 0, 0); y += Renderer::getInstance()->sprites.sprites[SPR_TEXT_ITEMS].h; @@ -175,7 +172,7 @@ void DrawInventory(void) if (++c >= inv.itemsel.rowlen) { - x = inv.x + ITEMS_X; + x = inv_x + ITEMS_X; y += inv.itemsel.spacing_y; c = 0; } diff --git a/src/inventory.h b/src/inventory.h index 69888e7a..67c887b8 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -23,7 +23,7 @@ struct stSelector struct stInventory { - int x, y, w, h; + int w, h; stSelector armssel; stSelector itemsel; diff --git a/src/main.cpp b/src/main.cpp index 017a434f..0d123d89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -323,12 +323,13 @@ int main(int argc, char *argv[]) // so we know the initial screen resolution. settings_load(); - if (!Renderer::getInstance()->init(settings->resolution)) + if (!Renderer::getInstance()->init(settings->resolution, settings->widescreen)) { fatal("Failed to initialize graphics."); return 1; } - Renderer::getInstance()->setFullscreen(settings->fullscreen); + if (settings->resolution == 0) + Renderer::getInstance()->setFullscreen(true); // if (check_data_exists()) // { diff --git a/src/map.cpp b/src/map.cpp index 165aa864..94ec6376 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -138,42 +138,7 @@ bool load_map(const std::string &fname) fclose(fp); - if (Renderer::getInstance()->widescreen) - { - if (map.xsize * TILE_W < Renderer::getInstance()->screenWidth && map.ysize * TILE_W < Renderer::getInstance()->screenHeight) - { - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 80)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - (Renderer::getInstance()->screenHeight - 16)) - 8) * CSFI; - } - else if (map.xsize * TILE_W < Renderer::getInstance()->screenWidth) - { - if (map.xsize == 25) - { // MazeI - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 48)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } - else - { // Others - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 80)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } - } - else if (map.ysize * TILE_W < Renderer::getInstance()->screenHeight) - { - map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - (Renderer::getInstance()->screenHeight - 16)) - 8) * CSFI; - } - else - { - map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } - } - else - { - map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } + recalc_map_offsets(); LOG_DEBUG("load_map: '{}' loaded OK! - {}x{}", fname, map.xsize, map.ysize); return 0; @@ -183,32 +148,21 @@ void recalc_map_offsets() { if (Renderer::getInstance()->widescreen) { - if (map.xsize * TILE_W < Renderer::getInstance()->screenWidth && map.ysize * TILE_W < Renderer::getInstance()->screenHeight) + if (map.xsize * TILE_W < Renderer::getInstance()->screenWidth) { - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 80)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - (Renderer::getInstance()->screenHeight - 16)) - 8) * CSFI; + map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) / 2) * CSFI; } - else if (map.xsize * TILE_W < Renderer::getInstance()->screenWidth) + else { - if (map.xsize == 25) - { // MazeI - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 48)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } - else - { // Others - map.maxxscroll = (((map.xsize * TILE_W) - (Renderer::getInstance()->screenWidth - 80)) - 8) * CSFI; - map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; - } + map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; } - else if (map.ysize * TILE_W < Renderer::getInstance()->screenHeight) + + if (map.ysize * TILE_W < Renderer::getInstance()->screenHeight) { - map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; map.maxyscroll = (((map.ysize * TILE_H) - (Renderer::getInstance()->screenHeight - 16)) - 8) * CSFI; } else { - map.maxxscroll = (((map.xsize * TILE_W) - Renderer::getInstance()->screenWidth) - 8) * CSFI; map.maxyscroll = (((map.ysize * TILE_H) - Renderer::getInstance()->screenHeight) - 8) * CSFI; } } @@ -676,11 +630,7 @@ void map_draw_backdrop(void) // blit OSide's BK_FASTLEFT_LAYERS void DrawFastLeftLayered(void) { - int layer_ys[] = {87, 122, 145, 176, 240}; - if (Renderer::getInstance()->widescreen) - { - layer_ys[4] = 272; - } + int layer_ys[] = {87, 122, 145, 176, Renderer::getInstance()->screenHeight}; static const int move_spd[] = {0, 1, 2, 4, 8}; int nlayers = 5; @@ -688,7 +638,7 @@ void DrawFastLeftLayered(void) int i, x; if ((game.mode == GM_NORMAL || game.mode == GM_TITLE) && !game.frozen && !game.paused) - if (--map.parscroll_x <= -(480 * Renderer::getInstance()->scale * 2)) + if (--map.parscroll_x <= -480 * 2) map.parscroll_x = 0; y1 = x = 0; diff --git a/src/pause/options.cpp b/src/pause/options.cpp index f66a080e..e1507fcf 100644 --- a/src/pause/options.cpp +++ b/src/pause/options.cpp @@ -26,8 +26,8 @@ static void EnterRebindMenu(ODItem *item, int dir); void LeavingMainMenu(); void _res_get(ODItem *item); void _res_change(ODItem *item, int dir); -void _fullscreen_get(ODItem *item); -void _fullscreen_change(ODItem *item, int dir); +void _widescreen_get(ODItem *item); +void _widescreen_change(ODItem *item, int dir); void _facepics_get(ODItem *item); void _facepics_change(ODItem *item, int dir); void _lights_get(ODItem *item); @@ -251,7 +251,7 @@ static void EnterGraphicsMenu(ODItem *item, int dir) dlg->Clear(); NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_MENU_MOVE); dlg->AddItem("Resolution: ", _res_change, _res_get, -1, OD_CHOICE); - dlg->AddItem("Fullscreen: ", _fullscreen_change, _fullscreen_get, -1, OD_CHOICE); + dlg->AddItem("Widescreen: ", _widescreen_change, _widescreen_get, -1, OD_CHOICE); dlg->AddItem("Animated facepics: ", _facepics_change, _facepics_get, -1, OD_CHOICE); dlg->AddItem("Lights: ", _lights_change, _lights_get, -1, OD_CHOICE); dlg->AddSeparator(); @@ -278,48 +278,53 @@ static void EnterSoundMenu(ODItem *item, int dir) void _res_get(ODItem *item) { - const gres_t *reslist = Renderer::getInstance()->getResolutions(); - if (settings->resolution < 0 || settings->resolution >= Renderer::getInstance()->getResolutionCount()) { item->suffix[0] = 0; } else { - strcpy(item->suffix, reslist[settings->resolution].name); + if (settings->resolution == 0) { + strcpy(item->suffix, "fullscreen"); + } else { + strcpy(item->suffix, (std::to_string(settings->resolution) + "x").c_str()); + } } } void _res_change(ODItem *item, int dir) { int numres = Renderer::getInstance()->getResolutionCount(); + int oldres = settings->resolution; int newres; NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_DOOR); - newres = (settings->resolution + dir); + newres = (oldres + dir); if (newres >= numres) - newres = 1; - if (newres < 1) + newres = 0; + if (newres < 0) newres = (numres - 1); - const gres_t *res = Renderer::getInstance()->getResolutions(); - while (!res[newres].enabled) - { - newres += dir; - if (newres >= numres) - newres = 1; - if (newres < 1) - newres = (numres - 1); - } - if (Renderer::getInstance()->setResolution(newres, true)) - { - settings->resolution = newres; - } - else - { + if (!Renderer::getInstance()->setResolution(newres == 0 ? 1 : newres, settings->widescreen)) { new Message("Resolution change failed"); NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_GUN_CLICK); + return; + } + + settings->resolution = newres; + + if (newres == 0) { + if (!Renderer::getInstance()->setFullscreen(true)) { + new Message("Fullscreen mode change failed"); + NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_GUN_CLICK); + return; + } + } else if (oldres == 0) { + if (!Renderer::getInstance()->setFullscreen(false)) { + new Message("Fullscreen mode change failed"); + NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_GUN_CLICK); + } } } @@ -366,17 +371,20 @@ void _lang_change(ODItem *item, int dir) } } -void _fullscreen_get(ODItem *item) +void _widescreen_get(ODItem *item) { static const char *strs[] = {"Off", "On"}; - strcpy(item->suffix, strs[settings->fullscreen]); + strcpy(item->suffix, strs[settings->widescreen]); } -void _fullscreen_change(ODItem *item, int dir) +void _widescreen_change(ODItem *item, int dir) { - settings->fullscreen ^= 1; + settings->widescreen ^= 1; NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_MENU_SELECT); - Renderer::getInstance()->setFullscreen(settings->fullscreen); + if (!Renderer::getInstance()->setResolution(settings->resolution, settings->widescreen)) { + new Message("Resolution change failed"); + NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_GUN_CLICK); + } } void _facepics_get(ODItem *item) diff --git a/src/settings.cpp b/src/settings.cpp index 40213f8d..88169230 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -79,11 +79,13 @@ bool settings_load(Settings *setfile) memset(setfile, 0, sizeof(Settings)); #if defined(__VITA__) || defined(__SWITCH__) setfile->resolution = 1; + setfile->widescreen = true; #else - setfile->resolution = 2; // 640x480 Windowed, should be safe value + // 640x480 Windowed, should be safe value + setfile->resolution = 2; + setfile->widescreen = false; #endif setfile->last_save_slot = 0; - setfile->fullscreen = false; setfile->sound_enabled = true; setfile->music_enabled = 1; // both Boss and Regular music diff --git a/src/settings.h b/src/settings.h index cc09b125..7a9edd58 100644 --- a/src/settings.h +++ b/src/settings.h @@ -10,7 +10,7 @@ struct Settings int resolution; int last_save_slot; bool show_fps; - bool fullscreen; + bool widescreen; bool sound_enabled; int music_enabled;