summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 49c7dbd)
raw | patch | inline | side by side (parent: 49c7dbd)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 17 Apr 2020 11:15:11 +0000 (15:15 +0400) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 17 Apr 2020 11:15:11 +0000 (15:15 +0400) |
src/args.c | [new file with mode: 0644] | patch | blob |
src/args.h | [new file with mode: 0644] | patch | blob |
src/config.c | patch | blob | history | |
src/config.h | patch | blob | history | |
src/gl/render.c | patch | blob | history | |
src/render.h | patch | blob | history | |
src/sdl/main.c | patch | blob | history | |
src/sdl2/main.c | patch | blob | history | |
src/soft/render.c | patch | blob | history | |
src/view.c | patch | blob | history | |
src/view.h | patch | blob | history |
diff --git a/src/args.c b/src/args.c
--- /dev/null
+++ b/src/args.c
@@ -0,0 +1,38 @@
+#include "args.h"
+#include "system.h"
+#include "error.h"
+#include "config.h"
+#include <assert.h>
+
+void ARG_parse (int argc, char **argv, int n, const cfg_t **list) {
+ assert(argc >= 0);
+ assert(argv != NULL);
+ assert(n >= 0);
+ assert(list != NULL);
+ int i, j;
+ char *key;
+ const cfg_t *c;
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] == '-' && argv[i][1] != 0) {
+ j = 0;
+ c = NULL;
+ key = &argv[i][1];
+ while (j < n && c == NULL){
+ c = CFG_find_entry(key, list[j]);
+ j++;
+ }
+ if (c == NULL) {
+ ERR_failinit("%s: unknown parameter %s\n", argv[0], argv[i]);
+ } else if (c->t == Y_SW_ON || c->t == Y_SW_OFF) {
+ CFG_update_key(key, "on", c);
+ } else if (i + 1 < argc) {
+ CFG_update_key(key, argv[i + 1], c);
+ i += 1;
+ } else {
+ ERR_failinit("%s: missing argument for parameter %s\n", argv[0], argv[i]);
+ }
+ } else {
+ ERR_failinit("%s: something wrong here: %s\n", argv[0], argv[i]);
+ }
+ }
+}
diff --git a/src/args.h b/src/args.h
--- /dev/null
+++ b/src/args.h
@@ -0,0 +1,8 @@
+#ifndef ARGS_H_INCLUDED
+#define ARGS_H_INCLUDED
+
+#include "system.h"
+
+void ARG_parse (int argc, char **argv, int n, const cfg_t **list);
+
+#endif /* ARGS_H_INCLUDED */
diff --git a/src/config.c b/src/config.c
index ed611c3b47772c3525f4ebaa2daf7588501c72fa..80c94bf3c85613e268342fc1eba88e42075ab582 100644 (file)
--- a/src/config.c
+++ b/src/config.c
case Y_DWORD: *(dword*)p = atoi(value); break;
case Y_STRING: strcpy(p, value); break; // TODO fix this security problem
case Y_SW_ON: *(byte*)p = strcasecmp(value, "on") == 0 ? 1 : 0; break;
- case Y_SW_OFF: *(byte*)p = strcasecmp(value, "off") == 0 ? 0 : 1; break;
+ case Y_SW_OFF: *(byte*)p = strcasecmp(value, "off") == 0 ? 1 : 0; break;
case Y_FILES: F_addwad(value); break;
case Y_KEY: *(int*)p = I_string_to_key(value); break;
default: assert(0); // unknown type -> something broken
/* --- reader --- */
-int CFG_read_config (const char *name, const cfg_t *cfg) {
+int CFG_read_config (const char *name, int n, const cfg_t **cfg) {
+ assert(name != NULL);
+ assert(n >= 0);
+ assert(cfg != NULL);
+ int i;
char key[64];
char value[64];
assert(name != NULL);
if (CFG_open_iterator(name)) {
while (CFG_scan_iterator(key, 64, value, 64)) {
- CFG_update_key(key, value, cfg);
+ i = 0;
+ while (i < n && CFG_update_key(key, value, cfg[i]) == 0) {
+ i++;
+ }
}
CFG_close_iterator();
return 1;
@@ -172,21 +179,21 @@ static void CFG_write_key_value (FILE *f, const char *key, const char *value) {
static int CFG_write_entry (FILE *f, const cfg_t *entry) {
assert(f != NULL);
assert(entry != NULL);
- char buf[64];
+ char buf[16];
const char *str;
const char *key = entry->cfg;
if (key != NULL) {
switch (entry->t) {
case Y_BYTE:
- snprintf(buf, 64, "%i", *(byte*)entry->p);
+ snprintf(buf, 16, "%i", *(byte*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_WORD:
- snprintf(buf, 64, "%i", *(word*)entry->p);
+ snprintf(buf, 16, "%i", *(word*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_DWORD:
- snprintf(buf, 64, "%i", *(dword*)entry->p);
+ snprintf(buf, 16, "%i", *(dword*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_STRING:
diff --git a/src/config.h b/src/config.h
index c666722c9c2d61029394593981bb28faacf311ff..4290768f42ac8506314f96fa053f2b94e6667c55 100644 (file)
--- a/src/config.h
+++ b/src/config.h
int CFG_scan_iterator (char *key, int keylen, char *value, int valuelen);
void CFG_close_iterator (void);
-int CFG_read_config (const char *name, const cfg_t *cfg);
+int CFG_read_config (const char *name, int n, const cfg_t **cfg);
int CFG_update_config (const char *old, const char *new, int n, const cfg_t **cfg, const char *msg);
#endif /* CONFIG_H_INCLUDED */
diff --git a/src/gl/render.c b/src/gl/render.c
index f0619ba5ccfa89b5862939bfdfe14b5fdfbc42dc..f68327a051e0572b51c0d0f428e737c330d868ff 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
} image;
/* Render Specific */
-static int SCRW = 320;
-static int SCRH = 200;
+static int SCRW;
+static int SCRH;
+static float screen_scale;
static int screen_width = 320;
static int screen_height = 200;
-static float screen_scale = 1.0;
+static byte screen_full = 0;
+static int init_screen_width = 0;
+static int init_screen_height = 0;
+static byte init_screen_full = 0xFF;
static rgb playpal[256];
static byte bright[256];
static GLuint lastTexture;
{"W73A_1", "W73A_2", NULL, NULL, NULL},
{"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL}
};
+static byte w_horiz = 1;
static int max_wall_width;
static int max_wall_height;
static int max_textures;
}
}
Y_get_videomode(&screen_width, &screen_height);
+ screen_full = Y_get_fullscreen();
screen_scale = max(1, screen_width / 320);
root = R_cache_new();
assert(root);
return &video_menu;
}
+const cfg_t *R_args (void) {
+ static const cfg_t args[] = {
+ { "fullscr", &init_screen_full, Y_SW_ON },
+ { "window", &init_screen_full, Y_SW_OFF },
+ { "width", &init_screen_width, Y_DWORD },
+ { "height", &init_screen_height, Y_DWORD },
+ { NULL, NULL, 0 } // end
+ };
+ return args;
+}
+
+const cfg_t *R_conf (void) {
+ static const cfg_t conf[] = {
+ { "sky", &w_horiz, Y_SW_ON },
+ { "fullscreen", &screen_full, Y_SW_ON },
+ { "screen_width", &screen_width, Y_DWORD },
+ { "screen_height", &screen_height, Y_DWORD },
+ { NULL, NULL, 0 } // end
+ };
+ return conf;
+}
+
void R_init (void) {
logo("R_init: intialize opengl render\n");
R_init_playpal();
- R_set_videomode(SCRW, SCRH, 0);
+ init_screen_width = init_screen_width > 0 ? init_screen_width : screen_width;
+ init_screen_height = init_screen_height > 0 ? init_screen_height : screen_height;
+ init_screen_full = init_screen_full != 0xFF ? init_screen_full : screen_full;
+ R_set_videomode(init_screen_width, init_screen_height, init_screen_full);
}
void R_done (void) {
diff --git a/src/render.h b/src/render.h
index 443b98f5e3c62758e826c711582e8658146f2ee6..0b6319c46f367f10ec8297bd5b5cca35d6144773 100644 (file)
--- a/src/render.h
+++ b/src/render.h
#ifndef RENDER_H_INCLUDED
#define RENDER_H_INCLUDED
+#include "system.h"
#include "menu.h"
+const cfg_t *R_args (void);
+const cfg_t *R_conf (void);
const menu_t *R_menu (void);
+
void R_init (void);
void R_draw (void);
void R_done (void);
diff --git a/src/sdl/main.c b/src/sdl/main.c
index a440844bc274744a8556da2b370e14e3f59fec15..1c16dc33307100048c40af58c3a38ee2060b7319 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
#include "files.h" // F_startup F_addwad F_initwads F_allocres
#include "config.h" // CFG_args CFG_load CFG_save
+#include "args.h" // ARG_parse
#include "memory.h" // M_startup
#include "game.h" // G_init G_act
#include "sound.h" // S_init S_done
// {"vga", &shot_vga, Y_SW_ON},
{"sndvol", &snd_vol, Y_WORD},
{"musvol", &mus_vol, Y_WORD},
-// {"fullscr", &fullscreen, Y_SW_ON},
-// {"window", &fullscreen, Y_SW_OFF},
{"mon", &nomon, Y_SW_OFF},
-// {"gamma", &gammaa, Y_DWORD},
{"warp", &_warp, Y_BYTE},
-// {"width", &SCRW, Y_DWORD},
-// {"height", &SCRH, Y_DWORD},
// {"config", NULL, cfg_file, Y_STRING},
{NULL, NULL, 0} // end
};
// {"screenshot", &shot_vga, Y_SW_ON},
{"sound_volume", &snd_vol, Y_WORD},
{"music_volume", &mus_vol, Y_WORD},
-// {"fullscreen", &fullscreen, Y_SW_ON},
- {"sky", &w_horiz, Y_SW_ON},
-// {"gamma", &gammaa, Y_DWORD},
-// {"screen_width", &SCRW, Y_DWORD},
-// {"screen_height", &SCRH, Y_DWORD},
{"music_random", &music_random, Y_SW_ON},
{"music_time", &music_time, Y_DWORD},
{"music_fade", &music_fade, Y_DWORD},
};
static void CFG_args (int argc, char **argv) {
- int i;
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] != 0) {
- if (i + 1 >= argc) {
- ERR_failinit("CFG_args: not enough arguments for parameter %s\n", argv[i]);
- } else {
- if (CFG_update_key(&argv[i][1], argv[i + 1], arg) != 0) {
- ERR_failinit("CFG_args: unknown parameter %s\n", argv[i]);
- }
- i += 1;
- }
- } else {
- ERR_failinit("CFG_args: something wrong here: %s\n", argv[i]);
- }
- }
+ const cfg_t *list[] = { arg, R_args() };
+ ARG_parse(argc, argv, 2, list);
}
static void CFG_load (void) {
- CFG_read_config("default.cfg", cfg);
- CFG_read_config("doom2d.cfg", cfg);
+ const cfg_t *list[] = { cfg, R_conf() };
+ CFG_read_config("default.cfg", 2, list);
+ CFG_read_config("doom2d.cfg", 2, list);
}
static void CFG_save (void) {
- const cfg_t *list[] = { &cfg, NULL };
- CFG_update_config("doom2d.cfg", "doom2d.cfg", 1, list, "generated by doom2d, do not modify");
- //CFG_update_config("doom2d.cfg", "doom2d.tmp", cfg, "temporary file");
- //CFG_update_config("doom2d.tmp", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
- //remove("doom2d.tmp");
+ const cfg_t *list[] = { cfg, R_conf() };
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", 2, list, "generated by doom2d, do not modify");
}
/* --- error.h --- */
diff --git a/src/sdl2/main.c b/src/sdl2/main.c
index 37b4c26334bfdd97514161b68610c5152d2fb18b..f9eb159fe7b7342c1ab28cd2fd9a9a9a5ed783c7 100644 (file)
--- a/src/sdl2/main.c
+++ b/src/sdl2/main.c
#include "files.h" // F_startup F_addwad F_initwads F_allocres
#include "config.h" // CFG_args CFG_load CFG_save
+#include "args.h" // ARG_parse
#include "memory.h" // M_startup
#include "game.h" // G_init G_act
#include "sound.h" // S_init S_done
// {"vga", &shot_vga, Y_SW_ON},
{"sndvol", &snd_vol, Y_WORD},
{"musvol", &mus_vol, Y_WORD},
-// {"fullscr", &fullscreen, Y_SW_ON},
-// {"window", &fullscreen, Y_SW_OFF},
{"mon", &nomon, Y_SW_OFF},
-// {"gamma", &gammaa, Y_DWORD},
{"warp", &_warp, Y_BYTE},
-// {"width", &SCRW, Y_DWORD},
-// {"height", &SCRH, Y_DWORD},
// {"config", NULL, cfg_file, Y_STRING},
{NULL, NULL, 0} // end
};
// {"screenshot", &shot_vga, Y_SW_ON},
{"sound_volume", &snd_vol, Y_WORD},
{"music_volume", &mus_vol, Y_WORD},
-// {"fullscreen", &fullscreen, Y_SW_ON},
- {"sky", &w_horiz, Y_SW_ON},
-// {"gamma", &gammaa, Y_DWORD},
-// {"screen_width", &SCRW, Y_DWORD},
-// {"screen_height", &SCRH, Y_DWORD},
{"music_random", &music_random, Y_SW_ON},
{"music_time", &music_time, Y_DWORD},
{"music_fade", &music_fade, Y_DWORD},
};
static void CFG_args (int argc, char **argv) {
- int i;
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] != 0) {
- if (i + 1 >= argc) {
- ERR_failinit("CFG_args: not enough arguments for parameter %s\n", argv[i]);
- } else {
- if (CFG_update_key(&argv[i][1], argv[i + 1], arg) != 0) {
- ERR_failinit("CFG_args: unknown parameter %s\n", argv[i]);
- }
- i += 1;
- }
- } else {
- ERR_failinit("CFG_args: something wrong here: %s\n", argv[i]);
- }
- }
+ const cfg_t *list[] = { arg, R_args() };
+ ARG_parse(argc, argv, 2, list);
}
static void CFG_load (void) {
- CFG_read_config("default.cfg", cfg);
- CFG_read_config("doom2d.cfg", cfg);
+ const cfg_t *list[] = { cfg, R_conf() };
+ CFG_read_config("default.cfg", 2, list);
+ CFG_read_config("doom2d.cfg", 2, list);
}
static void CFG_save (void) {
- const cfg_t *list[] = { &cfg, NULL };
- CFG_update_config("doom2d.cfg", "doom2d.cfg", 1, list, "generated by doom2d, do not modify");
- //CFG_update_config("doom2d.cfg", "doom2d.tmp", cfg, "temporary file");
- //CFG_update_config("doom2d.tmp", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
- //remove("doom2d.tmp");
+ const cfg_t *list[] = { cfg, R_conf() };
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", 2, list, "generated by doom2d, do not modify");
}
/* --- error.h --- */
int main (int argc, char **argv) {
char *pw;
+ CFG_args(argc, argv);
logo("system: initialize SDL2\n");
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS) == -1) {
logo("system: failed to init SDL2: %s\n", SDL_GetError());
pl2.kp = KEY_E;
srand(SDL_GetTicks());
F_startup();
+ CFG_load();
#ifndef WIN32
pw = "/usr/share/doom2d-rembo/doom2d.wad";
#else
} else {
F_addwad("doom2d.wad");
}
- CFG_args(argc, argv);
- CFG_load();
F_initwads();
M_startup();
F_allocres();
diff --git a/src/soft/render.c b/src/soft/render.c
index 363a058264c44f6d50006811acbee118658af243..38c3ba7f3bc057bcca8db85497cbe1bc5ef06360 100644 (file)
--- a/src/soft/render.c
+++ b/src/soft/render.c
static int anih[ANIT][5];
static byte anic[ANIT];
static int max_textures;
+static byte w_horiz = 1;
static vgaimg *horiz;
+static int init_screen_width = 0;
+static int init_screen_height = 0;
+static byte init_screen_full = 0xFF;
+static int init_screen_gammaa = -1;
+
/* --- misc --- */
static void *Z_getspr (char n[4], int s, int d, char *dir) {
return &video_menu;
}
+const cfg_t *R_args (void) {
+ static const cfg_t args[] = {
+ { "fullscr", &init_screen_full, Y_SW_ON },
+ { "window", &init_screen_full, Y_SW_OFF },
+ { "width", &init_screen_width, Y_DWORD },
+ { "height", &init_screen_height, Y_DWORD },
+ { "gamma", &init_screen_gammaa, Y_DWORD },
+ { NULL, NULL, 0 } // end
+ };
+ return args;
+}
+
+const cfg_t *R_conf (void) {
+ static const cfg_t conf[] = {
+ { "sky", &w_horiz, Y_SW_ON },
+ { "fullscreen", &fullscreen, Y_SW_ON },
+ { "screen_width", &SCRW, Y_DWORD },
+ { "screen_height", &SCRH, Y_DWORD },
+ { "gamma", &gammaa, Y_DWORD },
+ { NULL, NULL, 0 } // end
+ };
+ return conf;
+}
+
void R_init () {
int i;
logo("R_init: initialize software render\n");
}
F_loadres(F_getresid("MIXMAP"), mixmap, 0, 0x10000);
F_loadres(F_getresid("COLORMAP"), clrmap, 0, 256*12);
+ SCRW = init_screen_width > 0 ? init_screen_width : SCRW;
+ SCRH = init_screen_height > 0 ? init_screen_height : SCRH;
+ fullscreen = init_screen_full != 0xFF ? init_screen_full : fullscreen;
+ gammaa = init_screen_gammaa >= 0 ? init_screen_gammaa : gammaa;
R_set_videomode(SCRW, SCRH, fullscreen);
V_setrect(0, SCRW, 0, SCRH);
V_clr(0, SCRW, 0, SCRH, 0);
diff --git a/src/view.c b/src/view.c
index 77985e1ce06cc24bac80ac833ab0755e5b195d20..08fde9f9e72ea997057401dac8a585d50b1f2b39 100644 (file)
--- a/src/view.c
+++ b/src/view.c
#include "my.h"
#include "render.h"
-byte w_horiz=ON;
int sky_type=1;
dword walf[256];
byte walswp[256];
diff --git a/src/view.h b/src/view.h
index 6b70fdd1dce3f9a9cf8c56f614bda1a70b24b0d6..200bf020fde8afe762f4a5f4e061f1ab97c480dd 100644 (file)
--- a/src/view.h
+++ b/src/view.h
char t;
} wall_t;
-extern byte w_horiz;
extern int sky_type;
extern dword walf[256];
extern byte walswp[256];