Skip to content

Commit

Permalink
Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into…
Browse files Browse the repository at this point in the history
… port-debugger
  • Loading branch information
fgsfdsfgs committed Dec 4, 2023
2 parents 336b782 + d1be171 commit 75c4905
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile.port
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@ allclean:
rm -rf src/generated

codeclean:
find $(B_DIR)/game $(B_DIR)/inflate $(B_DIR)/lib $(B_DIR)/port -name '*.o' -delete
find $(B_DIR)/ -name '*.o' -delete
1 change: 1 addition & 0 deletions port/fast3d/gfx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern struct XYWidthHeight
gfx_current_game_window_viewport; // The area of the window the game is drawn to, (0, 0) is top-left corner
extern uint32_t gfx_msaa_level;
extern struct XYWidthHeight gfx_current_native_viewport; // The internal/native video mode of the game
extern float gfx_current_native_aspect; // The aspect ratio of the above mode
extern bool gfx_framebuffers_enabled;

void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name,
Expand Down
11 changes: 6 additions & 5 deletions port/fast3d/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ struct GfxDimensions gfx_current_dimensions;
static struct GfxDimensions gfx_prev_dimensions;
struct XYWidthHeight gfx_current_game_window_viewport;
struct XYWidthHeight gfx_current_native_viewport;
float gfx_current_native_aspect = 4.f / 3.f;
bool gfx_framebuffers_enabled = true;

static bool game_renders_to_framebuffer;
Expand Down Expand Up @@ -1652,12 +1653,12 @@ static void gfx_sp_geometry_mode(uint32_t clear, uint32_t set) {
static inline void gfx_update_aspect_mode(void) {
const uint32_t side = rsp.aspect_mode & G_ASPECT_CENTER_EXT;

rsp.aspect_scale = rsp.aspect_mode ? (4.f / 3.f) : gfx_current_window_dimensions.aspect_ratio;
rsp.aspect_scale = rsp.aspect_mode ? gfx_current_native_aspect : gfx_current_window_dimensions.aspect_ratio;

if (side == G_ASPECT_LEFT_EXT) {
rsp.aspect_ofs = 1.f - 3.f * gfx_current_dimensions.aspect_ratio / 4.f;
rsp.aspect_ofs = 1.f - gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect;
} else if (side == G_ASPECT_RIGHT_EXT) {
rsp.aspect_ofs = 3.f * gfx_current_dimensions.aspect_ratio / 4.f - 1.f;
rsp.aspect_ofs = gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect - 1.f;
} else {
rsp.aspect_ofs = 0.f;
}
Expand Down Expand Up @@ -1685,8 +1686,8 @@ static void gfx_adjust_viewport_or_scissor(XYWidthHeight* area, bool preserve_as
area->y = SCREEN_HEIGHT - area->y;
area->y *= RATIO_Y;
if (preserve_aspect) {
// preserve 4:3
const float ratio = (4.f / 3.f) / gfx_current_dimensions.aspect_ratio;
// preserve native aspect ratio
const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio;
const float midx = gfx_current_dimensions.width * 0.5f;
area->x = midx + (area->x - midx) * ratio;
area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f;
Expand Down
5 changes: 5 additions & 0 deletions port/src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "debugger.h"
#include "fs.h"

#if !SDL_VERSION_ATLEAST(2, 0, 14)
// this was added in 2.0.14
#define SDL_CONTROLLER_TYPE_VIRTUAL SDL_CONTROLLER_TYPE_UNKNOWN
#endif

#define CONTROLLERDB_FNAME "gamecontrollerdb.txt"

#define MAX_BIND_STR 256
Expand Down
4 changes: 3 additions & 1 deletion port/src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ s32 videoInit(void)
renderingAPI = &gfx_opengl_api;

gfx_current_native_viewport.width = 320;
gfx_current_native_viewport.height = 240;
gfx_current_native_viewport.height = 220;
gfx_current_native_aspect = 320.f / 220.f;
gfx_framebuffers_enabled = (bool)vidFramebuffers;
gfx_msaa_level = vidMSAA;

Expand Down Expand Up @@ -110,6 +111,7 @@ void videoUpdateNativeResolution(s32 w, s32 h)
{
gfx_current_native_viewport.width = w;
gfx_current_native_viewport.height = h;
gfx_current_native_aspect = (float)w / (float)h;
}

s32 videoGetNativeWidth(void)
Expand Down

0 comments on commit 75c4905

Please sign in to comment.