Skip to content

Commit c4b9814

Browse files
authored
Merge pull request #3510 from BlisterB/master
[WideScreen] Various fixes related with FakeResolution Mode (Pictures/Panoramas' position & Camera Scrolling)
2 parents 8acd2e1 + 48a9386 commit c4b9814

7 files changed

Lines changed: 82 additions & 59 deletions

File tree

src/game_interpreter_control_variables.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,11 @@ int ControlVariables::Event(int op, int event_id, const Game_BaseInterpreterCont
190190
break;
191191
case 4: {
192192
// Screen X
193-
if (Player::game_config.fake_resolution.Get()) {
194-
int pan_delta = (Game_Player::GetDefaultPanX() - lcf::rpg::SavePartyLocation::kPanXDefault) / TILE_SIZE;
195-
return character->GetScreenX() - pan_delta;
196-
} else {
197-
return character->GetScreenX();
198-
}
193+
return character->GetScreenX();
199194
}
200195
case 5: {
201196
// Screen Y
202-
if (Player::game_config.fake_resolution.Get()) {
203-
int pan_delta = (Game_Player::GetDefaultPanY() - lcf::rpg::SavePartyLocation::kPanYDefault) / TILE_SIZE;
204-
return character->GetScreenY() - pan_delta;
205-
} else {
206-
return character->GetScreenY();
207-
}
197+
return character->GetScreenY();
208198
}
209199
case 6:
210200
// Event ID

src/game_map.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,14 @@ void Game_Map::SetPositionX(int x, bool reset_panorama) {
17231723
const int map_width = GetTilesX() * SCREEN_TILE_SIZE;
17241724
if (LoopHorizontal()) {
17251725
x = Utils::PositiveModulo(x, map_width);
1726+
1727+
// If the map is too small to fit in the screen, add an offset corresponding to the black border's size
1728+
if (Player::game_config.fake_resolution.Get()) {
1729+
int map_width_in_pixels = Game_Map::GetTilesX() * TILE_SIZE;
1730+
if (map_width_in_pixels < Player::screen_width) {
1731+
x += ((Player::screen_width - map_width_in_pixels) / 2 / TILE_SIZE) * SCREEN_TILE_SIZE;
1732+
}
1733+
}
17261734
} else {
17271735
// Do not use std::clamp here. When the map is smaller than the screen the
17281736
// upper bound is smaller than the lower bound making the function fail.
@@ -1747,6 +1755,14 @@ void Game_Map::SetPositionY(int y, bool reset_panorama) {
17471755
const int map_height = GetTilesY() * SCREEN_TILE_SIZE;
17481756
if (LoopVertical()) {
17491757
y = Utils::PositiveModulo(y, map_height);
1758+
1759+
// If the map is too small to fit in the screen, add an offset corresponding to the black border's size
1760+
if (Player::game_config.fake_resolution.Get()) {
1761+
int map_height_in_pixels = Game_Map::GetTilesY() * TILE_SIZE;
1762+
if (map_height_in_pixels < Player::screen_height) {
1763+
y += ((Player::screen_height - map_height_in_pixels) / 2 / TILE_SIZE) * SCREEN_TILE_SIZE;
1764+
}
1765+
}
17501766
} else {
17511767
// Do not use std::clamp here. When the map is smaller than the screen the
17521768
// upper bound is smaller than the lower bound making the function fail.
@@ -2035,9 +2051,6 @@ void Game_Map::Caching::MapEventCache::RemoveEvent(const lcf::rpg::Event& ev) {
20352051
namespace {
20362052
int parallax_width;
20372053
int parallax_height;
2038-
2039-
bool parallax_fake_x;
2040-
bool parallax_fake_y;
20412054
}
20422055

20432056
/* Helper function to get the current parallax parameters. If the default
@@ -2141,12 +2154,14 @@ void Game_Map::Parallax::ResetPositionX() {
21412154
return;
21422155
}
21432156

2144-
parallax_fake_x = false;
2145-
21462157
if (!params.scroll_horz && !LoopHorizontal()) {
2158+
// What is the width of the panorama to display on screen?
21472159
int pan_screen_width = Player::screen_width;
2148-
if (Player::game_config.fake_resolution.Get()) {
2149-
pan_screen_width = SCREEN_TARGET_WIDTH;
2160+
if (Player::game_config.fake_resolution.Get()) {
2161+
int map_width = Game_Map::GetTilesX() * TILE_SIZE;
2162+
if (map_width < pan_screen_width) {
2163+
pan_screen_width = map_width;
2164+
}
21502165
}
21512166

21522167
int tiles_per_screen = pan_screen_width / TILE_SIZE;
@@ -2165,10 +2180,7 @@ void Game_Map::Parallax::ResetPositionX() {
21652180
}
21662181
} else {
21672182
panorama.pan_x = 0;
2168-
parallax_fake_x = true;
21692183
}
2170-
} else {
2171-
parallax_fake_x = true;
21722184
}
21732185
}
21742186

@@ -2179,12 +2191,14 @@ void Game_Map::Parallax::ResetPositionY() {
21792191
return;
21802192
}
21812193

2182-
parallax_fake_y = false;
2183-
21842194
if (!params.scroll_vert && !Game_Map::LoopVertical()) {
2195+
// What is the height of the panorama to display on screen?
21852196
int pan_screen_height = Player::screen_height;
21862197
if (Player::game_config.fake_resolution.Get()) {
2187-
pan_screen_height = SCREEN_TARGET_HEIGHT;
2198+
int map_height = Game_Map::GetTilesY() * TILE_SIZE;
2199+
if (map_height < pan_screen_height) {
2200+
pan_screen_height = map_height;
2201+
}
21882202
}
21892203

21902204
int tiles_per_screen = pan_screen_height / TILE_SIZE;
@@ -2198,10 +2212,7 @@ void Game_Map::Parallax::ResetPositionY() {
21982212
SetPositionY(pv);
21992213
} else {
22002214
panorama.pan_y = 0;
2201-
parallax_fake_y = true;
22022215
}
2203-
} else {
2204-
parallax_fake_y = true;
22052216
}
22062217
}
22072218

@@ -2296,11 +2307,3 @@ void Game_Map::Parallax::ClearChangedBG() {
22962307
Params params {}; // default Param indicates no override
22972308
ChangeBG(params);
22982309
}
2299-
2300-
bool Game_Map::Parallax::FakeXPosition() {
2301-
return parallax_fake_x;
2302-
}
2303-
2304-
bool Game_Map::Parallax::FakeYPosition() {
2305-
return parallax_fake_y;
2306-
}

src/game_map.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,6 @@ namespace Game_Map {
826826
* the map properties.
827827
*/
828828
void ClearChangedBG();
829-
830-
/** @return Whether ox adjustment is required for fake resolution mode */
831-
bool FakeXPosition();
832-
833-
/** @return Whether oy adjustment is required for fake resolution mode */
834-
bool FakeYPosition();
835829
}
836830
}
837831

src/game_player.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,33 @@ void Game_Player::UpdateScroll(int amount, bool was_jumping) {
191191
return;
192192
}
193193

194-
auto dx = (GetX() * SCREEN_TILE_SIZE) - Game_Map::GetPositionX() - GetPanX();
195-
auto dy = (GetY() * SCREEN_TILE_SIZE) - Game_Map::GetPositionY() - GetPanY();
194+
const auto map_width = Game_Map::GetTilesX() * SCREEN_TILE_SIZE;
195+
const auto map_height = Game_Map::GetTilesY() * SCREEN_TILE_SIZE;
196+
197+
// When using FakeResolution mode, if the map is too small to fit the screen
198+
// we need to calculate the black border offset, in case of a looping map for example
199+
int screen_offset_x = 0;
200+
if (Player::game_config.fake_resolution.Get()) {
201+
int map_width_in_pixels = Game_Map::GetTilesX() * TILE_SIZE;
202+
if (map_width_in_pixels < Player::screen_width) {
203+
screen_offset_x = ((Player::screen_width - map_width_in_pixels) / 2 / TILE_SIZE) * SCREEN_TILE_SIZE;
204+
}
205+
}
206+
int screen_offset_y = 0;
207+
if (Player::game_config.fake_resolution.Get()) {
208+
int map_height_in_pixels = Game_Map::GetTilesY() * TILE_SIZE;
209+
if (map_height_in_pixels < Player::screen_height) {
210+
screen_offset_y = ((Player::screen_height - map_height_in_pixels) / 2 / TILE_SIZE) * SCREEN_TILE_SIZE;
211+
}
212+
}
196213

197-
const auto w = Game_Map::GetTilesX() * SCREEN_TILE_SIZE;
198-
const auto h = Game_Map::GetTilesY() * SCREEN_TILE_SIZE;
214+
auto dx = (GetX() * SCREEN_TILE_SIZE) - Game_Map::GetPositionX() - GetPanX() + screen_offset_x;
215+
auto dy = (GetY() * SCREEN_TILE_SIZE) - Game_Map::GetPositionY() - GetPanY() + screen_offset_y;
199216

200-
dx = Utils::PositiveModulo(dx + w / 2, w) - w / 2;
201-
dy = Utils::PositiveModulo(dy + h / 2, h) - h / 2;
217+
dx = Utils::PositiveModulo(dx + map_width / 2, map_width) - map_width / 2;
218+
dy = Utils::PositiveModulo(dy + map_height / 2, map_height) - map_height / 2;
202219

220+
// If sx or sy equals zero, no scrolling is needed in the corresponding direction
203221
const auto sx = Utils::Signum(dx);
204222
const auto sy = Utils::Signum(dy);
205223

src/plane.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ void Plane::Draw(Bitmap& dst) {
8484
dst_rect.x = bg_x;
8585
dst_rect.width = bg_width;
8686

87-
if (Game_Map::GetDisplayX() / 16 + Player::screen_width > Game_Map::GetTilesX() * TILE_SIZE) {
88-
// Do not draw out of bounds to the right
89-
dst_rect.width -= (Game_Map::GetDisplayX() / 16 + Player::screen_width) - (Game_Map::GetTilesX() * TILE_SIZE);
90-
}
91-
9287
// Correct the offset if the top-left corner moved.
9388
offset_x = shake_x + bg_x;
9489
}

src/sprite_picture.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "game_windows.h"
2525
#include "player.h"
2626
#include "bitmap.h"
27+
#include "game_map.h"
2728

2829
Sprite_Picture::Sprite_Picture(int pic_id, Drawable::Flags flags)
2930
: Sprite(flags),
@@ -106,8 +107,26 @@ void Sprite_Picture::Draw(Bitmap& dst) {
106107
}
107108

108109
if (Player::game_config.fake_resolution.Get()) {
109-
SetX(x + Player::menu_offset_x);
110-
SetY(y + Player::menu_offset_y);
110+
if (data.fixed_to_map) {
111+
// If the picture scrolls with the map, apply the black border if the map is too small
112+
int offset_x = 0;
113+
int map_width = Game_Map::GetTilesX() * TILE_SIZE;
114+
if (map_width < Player::screen_width) {
115+
offset_x += (Player::screen_width - map_width) / 2;
116+
}
117+
SetX(x + offset_x);
118+
119+
int offset_y = 0;
120+
int map_height = Game_Map::GetTilesY() * TILE_SIZE;
121+
if (map_height < Player::screen_height) {
122+
offset_y += (Player::screen_height - map_height) / 2;
123+
}
124+
SetY(y + offset_y);
125+
} else {
126+
// If the picture doesn't scroll with the map, simulate the 340x240 screen
127+
SetX(x + Player::menu_offset_x);
128+
SetY(y + Player::menu_offset_y);
129+
}
111130
} else {
112131
SetX(x);
113132
SetY(y);

src/spriteset_map.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,16 @@ void Spriteset_Map::CalculateMapRenderOffset() {
326326

327327
void Spriteset_Map::CalculatePanoramaRenderOffset() {
328328
// Resolution hack for Panorama
329+
// If the map is too small to fit in the screen, add an offset corresponding to the black border's size
329330
if (Player::game_config.fake_resolution.Get()) {
330-
if (Game_Map::Parallax::FakeXPosition()) {
331-
panorama->SetRenderOx((Player::screen_width - SCREEN_TARGET_WIDTH) / 2);
331+
int map_width_in_pixels = Game_Map::GetTilesX() * TILE_SIZE;
332+
if (map_width_in_pixels < Player::screen_width) {
333+
panorama->SetRenderOx((Player::screen_width - map_width_in_pixels) / 2);
332334
}
333-
if (Game_Map::Parallax::FakeYPosition()) {
334-
panorama->SetRenderOy((Player::screen_height - SCREEN_TARGET_HEIGHT) / 2);
335+
336+
int map_height_in_pixels = Game_Map::GetTilesY() * TILE_SIZE;
337+
if (map_height_in_pixels < Player::screen_height) {
338+
panorama->SetRenderOy((Player::screen_height - map_height_in_pixels) / 2);
335339
}
336340
}
337341
}

0 commit comments

Comments
 (0)