Skip to content

Commit c138d7f

Browse files
authored
Reorganize svga (#109)
1 parent 2716012 commit c138d7f

File tree

11 files changed

+148
-354
lines changed

11 files changed

+148
-354
lines changed

src/game/game.cc

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ DB_DATABASE* master_db_handle;
124124
DB_DATABASE* critter_db_handle;
125125

126126
// 0x43B080
127-
int game_init(const char* windowTitle, bool isMapper, int font, int a4, int argc, char** argv)
127+
int game_init(const char* windowTitle, bool isMapper, int font, int flags, int argc, char** argv)
128128
{
129129
char path[COMPAT_MAX_PATH];
130130

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

144144
win_set_minimized_title(windowTitle);
145-
initWindow(1, a4);
145+
146+
VideoOptions video_options;
147+
video_options.width = 640;
148+
video_options.height = 480;
149+
video_options.fullscreen = true;
150+
video_options.scale = 1;
151+
152+
Config resolutionConfig;
153+
if (config_init(&resolutionConfig)) {
154+
if (config_load(&resolutionConfig, "f1_res.ini", false)) {
155+
int screenWidth;
156+
if (config_get_value(&resolutionConfig, "MAIN", "SCR_WIDTH", &screenWidth)) {
157+
video_options.width = std::max(screenWidth, 640);
158+
}
159+
160+
int screenHeight;
161+
if (config_get_value(&resolutionConfig, "MAIN", "SCR_HEIGHT", &screenHeight)) {
162+
video_options.height = std::max(screenHeight, 480);
163+
}
164+
165+
bool windowed;
166+
if (configGetBool(&resolutionConfig, "MAIN", "WINDOWED", &windowed)) {
167+
video_options.fullscreen = !windowed;
168+
}
169+
170+
int scaleValue;
171+
if (config_get_value(&resolutionConfig, "MAIN", "SCALE_2X", &scaleValue)) {
172+
video_options.scale = scaleValue + 1;
173+
video_options.width /= video_options.scale;
174+
video_options.height /= video_options.scale;
175+
}
176+
}
177+
config_exit(&resolutionConfig);
178+
}
179+
180+
initWindow(&video_options, flags);
146181
palette_init();
147182

148183
if (!game_in_mapper) {

src/game/game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern MessageList misc_message_file;
2525
extern DB_DATABASE* master_db_handle;
2626
extern DB_DATABASE* critter_db_handle;
2727

28-
int game_init(const char* windowTitle, bool isMapper, int a3, int a4, int argc, char** argv);
28+
int game_init(const char* windowTitle, bool isMapper, int font, int flags, int argc, char** argv);
2929
void game_reset();
3030
void game_exit();
3131
int game_handle_input(int eventCode, bool isInCombatMode);

src/game/main.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ static void main_exit_system()
250250
main_selfrun_exit();
251251

252252
game_exit();
253+
254+
// TODO: Find a better place for this call.
255+
SDL_Quit();
253256
}
254257

255258
// 0x472958

src/game/map.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ int iso_init()
279279
// NOTE: Uninline.
280280
square_init();
281281

282-
display_win = win_add(0, 0, screenGetWidth(), screenGetVisibleHeight(), 256, 10);
282+
display_win = win_add(0, 0, screenGetWidth(), screenGetHeight() - INTERFACE_BAR_HEIGHT, 256, 10);
283283
if (display_win == -1) {
284284
debug_printf("win_add failed in iso_init\n");
285285
return -1;

src/int/window.cc

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -105,54 +105,6 @@ static int winTOS = -1;
105105
// 0x508698
106106
static int currentWindow = -1;
107107

108-
// 0x50869C
109-
static VideoSystemInitProc* gfx_init[12] = {
110-
init_mode_320_200,
111-
init_mode_640_480,
112-
init_mode_640_480_16,
113-
init_mode_320_400,
114-
init_mode_640_480_16,
115-
init_mode_640_400,
116-
init_mode_640_480_16,
117-
init_mode_800_600,
118-
init_mode_640_480_16,
119-
init_mode_1024_768,
120-
init_mode_640_480_16,
121-
init_mode_1280_1024,
122-
};
123-
124-
// 0x5086CC
125-
static int fontnum[12] = {
126-
3,
127-
0,
128-
0,
129-
3,
130-
0,
131-
0,
132-
0,
133-
0,
134-
0,
135-
0,
136-
0,
137-
0,
138-
};
139-
140-
// 0x5086FC
141-
static Size sizes[12] = {
142-
{ 320, 200 },
143-
{ 640, 480 },
144-
{ 640, 240 },
145-
{ 320, 400 },
146-
{ 640, 200 },
147-
{ 640, 400 },
148-
{ 800, 300 },
149-
{ 800, 600 },
150-
{ 1024, 384 },
151-
{ 1024, 768 },
152-
{ 1280, 512 },
153-
{ 1280, 1024 },
154-
};
155-
156108
// 0x50875C
157109
static int numInputFunc = 0;
158110

@@ -1575,7 +1527,7 @@ static void windowRemoveProgramReferences(Program* program)
15751527
}
15761528

15771529
// 0x4A5C9C
1578-
void initWindow(int resolution, int a2)
1530+
void initWindow(VideoOptions* video_options, int flags)
15791531
{
15801532
char err[COMPAT_MAX_PATH];
15811533
int rc;
@@ -1588,17 +1540,18 @@ void initWindow(int resolution, int a2)
15881540
currentTextColorB = 0;
15891541
currentHighlightColorR = 0;
15901542
currentHighlightColorG = 0;
1543+
currentHighlightColorB = 0;
15911544
currentTextFlags = 0x2010000;
15921545

1593-
yres = sizes[resolution].height; // screen height
1594-
currentHighlightColorB = 0;
1595-
xres = sizes[resolution].width; // screen width
1546+
// TODO: Review usage.
1547+
yres = 640;
1548+
xres = 480;
15961549

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

1601-
rc = win_init(gfx_init[resolution], GNW95_reset_mode, a2);
1554+
rc = win_init(video_options, flags);
16021555
if (rc != WINDOW_MANAGER_OK) {
16031556
switch (rc) {
16041557
case WINDOW_MANAGER_ERR_INITIALIZING_VIDEO_MODE:

src/int/window.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "int/widget.h"
77
#include "plib/gnw/gnw.h"
88
#include "plib/gnw/rect.h"
9+
#include "plib/gnw/svga_types.h"
910

1011
namespace fallout {
1112

@@ -86,7 +87,7 @@ int windowDisplayTransBuf(unsigned char* src, int srcWidth, int srcHeight, int d
8687
int windowDisplayBufScaled(unsigned char* src, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight);
8788
int windowGetXres();
8889
int windowGetYres();
89-
void initWindow(int resolution, int a2);
90+
void initWindow(VideoOptions* video_options, int flags);
9091
void windowSetWindowFuncs(ManagedWindowCreateCallback* createCallback, ManagedWindowSelectFunc* selectCallback, WindowDeleteCallback* deleteCallback, DisplayInWindowCallback* displayCallback);
9192
void windowClose();
9293
bool windowDeleteButton(const char* buttonName);

src/plib/gnw/gnw.cc

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ static int window_index[MAX_WINDOW_COUNT];
5757
// 0x6AC1E8
5858
static Window* window[MAX_WINDOW_COUNT];
5959

60-
// 0x6AC2B0
61-
static VideoSystemExitProc* video_reset;
62-
6360
// 0x6AC2B4
6461
static int num_windows;
6562

@@ -72,17 +69,14 @@ static bool buffering;
7269
// 0x6AC2C0
7370
static int bk_color;
7471

75-
// 0x6AC2C4
76-
static VideoSystemInitProc* video_set;
77-
7872
// 0x6AC2C8
7973
static int doing_refresh_all;
8074

8175
// 0x6AC2CC
8276
void* GNW_texture;
8377

8478
// 0x4C1CF0
85-
int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int flags)
79+
int win_init(VideoOptions* video_options, int flags)
8680
{
8781
#ifdef _WIN32
8882
CloseHandle(GNW95_mutex);
@@ -117,32 +111,16 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide
117111
return WINDOW_MANAGER_ERR_INITIALIZING_TEXT_FONTS;
118112
}
119113

120-
reset_mode();
121-
122-
video_set = videoSystemInitProc;
123-
video_reset = GNW95_reset_mode;
124-
125-
int rc = videoSystemInitProc();
126-
if (rc == -1) {
127-
if (video_reset != NULL) {
128-
video_reset();
129-
}
114+
if (!svga_init(video_options)) {
115+
svga_exit();
130116

131117
return WINDOW_MANAGER_ERR_INITIALIZING_VIDEO_MODE;
132118
}
133119

134-
if (rc == 8) {
135-
return WINDOW_MANAGER_ERR_8;
136-
}
137-
138120
if ((flags & 1) != 0) {
139121
screen_buffer = (unsigned char*)mem_malloc((scr_size.lry - scr_size.uly + 1) * (scr_size.lrx - scr_size.ulx + 1));
140122
if (screen_buffer == NULL) {
141-
if (video_reset != NULL) {
142-
video_reset();
143-
} else {
144-
GNW95_reset_mode();
145-
}
123+
svga_exit();
146124

147125
return WINDOW_MANAGER_ERR_NO_MEMORY;
148126
}
@@ -157,11 +135,7 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide
157135
if (!initColors()) {
158136
unsigned char* palette = (unsigned char*)mem_malloc(768);
159137
if (palette == NULL) {
160-
if (video_reset != NULL) {
161-
video_reset();
162-
} else {
163-
GNW95_reset_mode();
164-
}
138+
svga_exit();
165139

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

189163
Window* w = window[0] = (Window*)mem_malloc(sizeof(*w));
190164
if (w == NULL) {
191-
if (video_reset != NULL) {
192-
video_reset();
193-
} else {
194-
GNW95_reset_mode();
195-
}
165+
svga_exit();
196166

197167
if (screen_buffer != NULL) {
198168
mem_free(screen_buffer);
@@ -260,9 +230,7 @@ void win_exit(void)
260230
mem_free(screen_buffer);
261231
}
262232

263-
if (video_reset != NULL) {
264-
video_reset();
265-
}
233+
svga_exit();
266234

267235
GNW_input_exit();
268236
GNW_rect_exit();

src/plib/gnw/gnw.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "plib/gnw/gnw_types.h"
77
#include "plib/gnw/rect.h"
8+
#include "plib/gnw/svga_types.h"
89

910
namespace fallout {
1011

@@ -29,15 +30,12 @@ typedef enum WindowManagerErr {
2930
WINDOW_MANAGER_ERR_INITIALIZING_INPUT = 11,
3031
} WindowManagerErr;
3132

32-
typedef int(VideoSystemInitProc)();
33-
typedef void(VideoSystemExitProc)();
34-
3533
extern bool GNW_win_init_flag;
3634
extern int GNW_wcolor[6];
3735

3836
extern void* GNW_texture;
3937

40-
int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3);
38+
int win_init(VideoOptions* video_options, int flags);
4139
int win_active();
4240
void win_exit(void);
4341
int win_add(int x, int y, int width, int height, int color, int flags);

0 commit comments

Comments
 (0)