Skip to content

Commit

Permalink
Reorganize svga (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov authored Oct 5, 2023
1 parent 2716012 commit c138d7f
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 354 deletions.
39 changes: 37 additions & 2 deletions src/game/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ DB_DATABASE* master_db_handle;
DB_DATABASE* critter_db_handle;

// 0x43B080
int game_init(const char* windowTitle, bool isMapper, int font, int a4, int argc, char** argv)
int game_init(const char* windowTitle, bool isMapper, int font, int flags, int argc, char** argv)
{
char path[COMPAT_MAX_PATH];

Expand All @@ -142,7 +142,42 @@ int game_init(const char* windowTitle, bool isMapper, int font, int a4, int argc
}

win_set_minimized_title(windowTitle);
initWindow(1, a4);

VideoOptions video_options;
video_options.width = 640;
video_options.height = 480;
video_options.fullscreen = true;
video_options.scale = 1;

Config resolutionConfig;
if (config_init(&resolutionConfig)) {
if (config_load(&resolutionConfig, "f1_res.ini", false)) {
int screenWidth;
if (config_get_value(&resolutionConfig, "MAIN", "SCR_WIDTH", &screenWidth)) {
video_options.width = std::max(screenWidth, 640);
}

int screenHeight;
if (config_get_value(&resolutionConfig, "MAIN", "SCR_HEIGHT", &screenHeight)) {
video_options.height = std::max(screenHeight, 480);
}

bool windowed;
if (configGetBool(&resolutionConfig, "MAIN", "WINDOWED", &windowed)) {
video_options.fullscreen = !windowed;
}

int scaleValue;
if (config_get_value(&resolutionConfig, "MAIN", "SCALE_2X", &scaleValue)) {
video_options.scale = scaleValue + 1;
video_options.width /= video_options.scale;
video_options.height /= video_options.scale;
}
}
config_exit(&resolutionConfig);
}

initWindow(&video_options, flags);
palette_init();

if (!game_in_mapper) {
Expand Down
2 changes: 1 addition & 1 deletion src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern MessageList misc_message_file;
extern DB_DATABASE* master_db_handle;
extern DB_DATABASE* critter_db_handle;

int game_init(const char* windowTitle, bool isMapper, int a3, int a4, int argc, char** argv);
int game_init(const char* windowTitle, bool isMapper, int font, int flags, int argc, char** argv);
void game_reset();
void game_exit();
int game_handle_input(int eventCode, bool isInCombatMode);
Expand Down
3 changes: 3 additions & 0 deletions src/game/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ static void main_exit_system()
main_selfrun_exit();

game_exit();

// TODO: Find a better place for this call.
SDL_Quit();
}

// 0x472958
Expand Down
2 changes: 1 addition & 1 deletion src/game/map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int iso_init()
// NOTE: Uninline.
square_init();

display_win = win_add(0, 0, screenGetWidth(), screenGetVisibleHeight(), 256, 10);
display_win = win_add(0, 0, screenGetWidth(), screenGetHeight() - INTERFACE_BAR_HEIGHT, 256, 10);
if (display_win == -1) {
debug_printf("win_add failed in iso_init\n");
return -1;
Expand Down
59 changes: 6 additions & 53 deletions src/int/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,54 +105,6 @@ static int winTOS = -1;
// 0x508698
static int currentWindow = -1;

// 0x50869C
static VideoSystemInitProc* gfx_init[12] = {
init_mode_320_200,
init_mode_640_480,
init_mode_640_480_16,
init_mode_320_400,
init_mode_640_480_16,
init_mode_640_400,
init_mode_640_480_16,
init_mode_800_600,
init_mode_640_480_16,
init_mode_1024_768,
init_mode_640_480_16,
init_mode_1280_1024,
};

// 0x5086CC
static int fontnum[12] = {
3,
0,
0,
3,
0,
0,
0,
0,
0,
0,
0,
0,
};

// 0x5086FC
static Size sizes[12] = {
{ 320, 200 },
{ 640, 480 },
{ 640, 240 },
{ 320, 400 },
{ 640, 200 },
{ 640, 400 },
{ 800, 300 },
{ 800, 600 },
{ 1024, 384 },
{ 1024, 768 },
{ 1280, 512 },
{ 1280, 1024 },
};

// 0x50875C
static int numInputFunc = 0;

Expand Down Expand Up @@ -1575,7 +1527,7 @@ static void windowRemoveProgramReferences(Program* program)
}

// 0x4A5C9C
void initWindow(int resolution, int a2)
void initWindow(VideoOptions* video_options, int flags)
{
char err[COMPAT_MAX_PATH];
int rc;
Expand All @@ -1588,17 +1540,18 @@ void initWindow(int resolution, int a2)
currentTextColorB = 0;
currentHighlightColorR = 0;
currentHighlightColorG = 0;
currentHighlightColorB = 0;
currentTextFlags = 0x2010000;

yres = sizes[resolution].height; // screen height
currentHighlightColorB = 0;
xres = sizes[resolution].width; // screen width
// TODO: Review usage.
yres = 640;
xres = 480;

for (int i = 0; i < MANAGED_WINDOW_COUNT; i++) {
windows[i].window = -1;
}

rc = win_init(gfx_init[resolution], GNW95_reset_mode, a2);
rc = win_init(video_options, flags);
if (rc != WINDOW_MANAGER_OK) {
switch (rc) {
case WINDOW_MANAGER_ERR_INITIALIZING_VIDEO_MODE:
Expand Down
3 changes: 2 additions & 1 deletion src/int/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "int/widget.h"
#include "plib/gnw/gnw.h"
#include "plib/gnw/rect.h"
#include "plib/gnw/svga_types.h"

namespace fallout {

Expand Down Expand Up @@ -86,7 +87,7 @@ int windowDisplayTransBuf(unsigned char* src, int srcWidth, int srcHeight, int d
int windowDisplayBufScaled(unsigned char* src, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight);
int windowGetXres();
int windowGetYres();
void initWindow(int resolution, int a2);
void initWindow(VideoOptions* video_options, int flags);
void windowSetWindowFuncs(ManagedWindowCreateCallback* createCallback, ManagedWindowSelectFunc* selectCallback, WindowDeleteCallback* deleteCallback, DisplayInWindowCallback* displayCallback);
void windowClose();
bool windowDeleteButton(const char* buttonName);
Expand Down
46 changes: 7 additions & 39 deletions src/plib/gnw/gnw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ static int window_index[MAX_WINDOW_COUNT];
// 0x6AC1E8
static Window* window[MAX_WINDOW_COUNT];

// 0x6AC2B0
static VideoSystemExitProc* video_reset;

// 0x6AC2B4
static int num_windows;

Expand All @@ -72,17 +69,14 @@ static bool buffering;
// 0x6AC2C0
static int bk_color;

// 0x6AC2C4
static VideoSystemInitProc* video_set;

// 0x6AC2C8
static int doing_refresh_all;

// 0x6AC2CC
void* GNW_texture;

// 0x4C1CF0
int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int flags)
int win_init(VideoOptions* video_options, int flags)
{
#ifdef _WIN32
CloseHandle(GNW95_mutex);
Expand Down Expand Up @@ -117,32 +111,16 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide
return WINDOW_MANAGER_ERR_INITIALIZING_TEXT_FONTS;
}

reset_mode();

video_set = videoSystemInitProc;
video_reset = GNW95_reset_mode;

int rc = videoSystemInitProc();
if (rc == -1) {
if (video_reset != NULL) {
video_reset();
}
if (!svga_init(video_options)) {
svga_exit();

return WINDOW_MANAGER_ERR_INITIALIZING_VIDEO_MODE;
}

if (rc == 8) {
return WINDOW_MANAGER_ERR_8;
}

if ((flags & 1) != 0) {
screen_buffer = (unsigned char*)mem_malloc((scr_size.lry - scr_size.uly + 1) * (scr_size.lrx - scr_size.ulx + 1));
if (screen_buffer == NULL) {
if (video_reset != NULL) {
video_reset();
} else {
GNW95_reset_mode();
}
svga_exit();

return WINDOW_MANAGER_ERR_NO_MEMORY;
}
Expand All @@ -157,11 +135,7 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide
if (!initColors()) {
unsigned char* palette = (unsigned char*)mem_malloc(768);
if (palette == NULL) {
if (video_reset != NULL) {
video_reset();
} else {
GNW95_reset_mode();
}
svga_exit();

if (screen_buffer != NULL) {
mem_free(screen_buffer);
Expand All @@ -188,11 +162,7 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide

Window* w = window[0] = (Window*)mem_malloc(sizeof(*w));
if (w == NULL) {
if (video_reset != NULL) {
video_reset();
} else {
GNW95_reset_mode();
}
svga_exit();

if (screen_buffer != NULL) {
mem_free(screen_buffer);
Expand Down Expand Up @@ -260,9 +230,7 @@ void win_exit(void)
mem_free(screen_buffer);
}

if (video_reset != NULL) {
video_reset();
}
svga_exit();

GNW_input_exit();
GNW_rect_exit();
Expand Down
6 changes: 2 additions & 4 deletions src/plib/gnw/gnw.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "plib/gnw/gnw_types.h"
#include "plib/gnw/rect.h"
#include "plib/gnw/svga_types.h"

namespace fallout {

Expand All @@ -29,15 +30,12 @@ typedef enum WindowManagerErr {
WINDOW_MANAGER_ERR_INITIALIZING_INPUT = 11,
} WindowManagerErr;

typedef int(VideoSystemInitProc)();
typedef void(VideoSystemExitProc)();

extern bool GNW_win_init_flag;
extern int GNW_wcolor[6];

extern void* GNW_texture;

int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3);
int win_init(VideoOptions* video_options, int flags);
int win_active();
void win_exit(void);
int win_add(int x, int y, int width, int height, int color, int flags);
Expand Down
Loading

0 comments on commit c138d7f

Please sign in to comment.