summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: abdc9af)
raw | patch | inline | side by side (parent: abdc9af)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 17 Apr 2020 07:59:33 +0000 (11:59 +0400) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 17 Apr 2020 07:59:33 +0000 (11:59 +0400) |
src/config.c | patch | blob | history | |
src/config.h | patch | blob | history | |
src/game.c | patch | blob | history | |
src/game.h | patch | blob | history | |
src/sdl/main.c | patch | blob | history | |
src/sdl2/main.c | patch | blob | history | |
src/system.h | patch | blob | history |
diff --git a/src/config.c b/src/config.c
index f80fd2619c1ac5662c26733e392b07a829cd5474..885a0e4b8aeee0b998c6d0e270c114b38939235a 100644 (file)
--- a/src/config.c
+++ b/src/config.c
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include "map.h"
-#include "sound.h"
-#include "music.h"
-#include "view.h"
-#include "monster.h"
-#include "player.h"
-#include "menu.h"
+#include "system.h"
#include "files.h"
-#include "render.h"
-#include "error.h"
#include "input.h"
-#include "my.h"
-
-enum {NONE, BYTE, WORD, DWORD, STRING, SW_ON, SW_OFF, FILES, KEY};
-
-typedef struct cfg_t {
- const char *cfg;
- void *p;
- byte t;
-} cfg_t;
-
-byte cheat;
-byte shot_vga;
static FILE *f;
static int ch;
-static const cfg_t arg[] = {
- {"file", NULL, FILES},
- {"cheat", &cheat, SW_ON},
- {"vga", &shot_vga, SW_ON},
- {"sndvol", &snd_vol, WORD},
- {"musvol",&mus_vol, WORD},
-// {"fullscr", &fullscreen, SW_ON},
-// {"window", &fullscreen, SW_OFF},
- {"mon", &nomon, SW_OFF},
-// {"gamma", &gammaa, DWORD},
- {"warp", &_warp, BYTE},
-// {"width", &SCRW, DWORD},
-// {"height", &SCRH, DWORD},
-// {"config", NULL, cfg_file, STRING},
- {NULL, NULL, NONE} // end
-};
-
-static const cfg_t cfg[] = {
- {"screenshot", &shot_vga, SW_ON},
- {"sound_volume", &snd_vol, WORD},
- {"music_volume", &mus_vol, WORD},
-// {"fullscreen", &fullscreen, SW_ON},
- {"sky", &w_horiz, SW_ON},
-// {"gamma", &gammaa, DWORD},
-// {"screen_width", &SCRW, DWORD},
-// {"screen_height", &SCRH, DWORD},
- {"music_random", &music_random, SW_ON},
- {"music_time", &music_time, DWORD},
- {"music_fade", &music_fade, DWORD},
- {"pl1_left", &pl1.kl, KEY},
- {"pl1_right",&pl1.kr, KEY},
- {"pl1_up", &pl1.ku, KEY},
- {"pl1_down", &pl1.kd, KEY},
- {"pl1_jump", &pl1.kj, KEY},
- {"pl1_fire", &pl1.kf, KEY},
- {"pl1_next", &pl1.kwr, KEY},
- {"pl1_prev", &pl1.kwl, KEY},
- {"pl1_use", &pl1.kp, KEY},
- {"pl2_left", &pl2.kl, KEY},
- {"pl2_right",&pl2.kr, KEY},
- {"pl2_up", &pl2.ku, KEY},
- {"pl2_down", &pl2.kd, KEY},
- {"pl2_jump", &pl2.kj, KEY},
- {"pl2_fire", &pl2.kf, KEY},
- {"pl2_next", &pl2.kwr, KEY},
- {"pl2_prev", &pl2.kwl, KEY},
- {"pl2_use", &pl2.kp, KEY},
- {NULL, NULL, NONE} // end
-};
-
-static const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) {
+const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) {
assert(key != NULL);
assert(cfg != NULL);
int i = 0;
return cfg[i].cfg ? &cfg[i] : NULL;
}
-static int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) {
+int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) {
const cfg_t *entry = CFG_find_entry(key, cfg);
if (entry != NULL) {
void *p = entry->p;
switch (entry->t) {
- case BYTE: *(byte*)p = atoi(value); break;
- case WORD: *(word*)p = atoi(value); break;
- case DWORD: *(dword*)p = atoi(value); break;
- case STRING: strcpy(p, value); break; // TODO fix this security problem
- case SW_ON: *(byte*)p = strcasecmp(value, "on") == 0 ? 1 : 0; break;
- case SW_OFF: *(byte*)p = strcasecmp(value, "off") == 0 ? 0 : 1; break;
- case FILES: F_addwad(value); break;
- case KEY: *(int*)p = I_string_to_key(value); break;
+ case Y_BYTE: *(byte*)p = atoi(value); break;
+ case Y_WORD: *(word*)p = atoi(value); break;
+ 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_FILES: F_addwad(value); break;
+ case Y_KEY: *(int*)p = I_string_to_key(value); break;
default: assert(0); // unknown type -> something broken
}
return 1;
/* --- parser --- */
-static int CFG_open_iterator (const char *name) {
+int CFG_open_iterator (const char *name) {
assert(f == NULL);
f = fopen(name, "rb");
if (f != NULL) {
}
}
-static int CFG_scan_iterator (char *key, int keylen, char *value, int valuelen) {
+int CFG_scan_iterator (char *key, int keylen, char *value, int valuelen) {
assert(key != NULL);
assert(keylen > 0);
assert(value != NULL);
return found;
}
-static void CFG_close_iterator (void) {
+void CFG_close_iterator (void) {
assert(f != NULL);
fclose(f);
f = NULL;
/* --- reader --- */
-static int CFG_read_config (const char *name) {
+int CFG_read_config (const char *name, const cfg_t *cfg) {
char key[64];
char value[64];
assert(name != NULL);
}
}
-void CFG_args (int argc, const 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]);
- }
- }
-}
-void CFG_load (void) {
- CFG_read_config("default.cfg");
- CFG_read_config("doom2d.cfg");
-}
/* --- writer --- */
const char *key = entry->cfg;
if (key != NULL) {
switch (entry->t) {
- case BYTE:
+ case Y_BYTE:
snprintf(buf, 64, "%i", *(byte*)entry->p);
CFG_write_key_value(f, key, buf);
break;
- case WORD:
+ case Y_WORD:
snprintf(buf, 64, "%i", *(word*)entry->p);
CFG_write_key_value(f, key, buf);
break;
- case DWORD:
+ case Y_DWORD:
snprintf(buf, 64, "%i", *(dword*)entry->p);
CFG_write_key_value(f, key, buf);
break;
- case STRING:
+ case Y_STRING:
CFG_write_key_value(f, key, entry->p);
break;
- case SW_ON:
- case SW_OFF:
+ case Y_SW_ON:
+ case Y_SW_OFF:
str = *(byte*)entry->p ? "on" : "off";
CFG_write_key_value(f, key, str);
break;
- case KEY:
+ case Y_KEY:
str = I_key_to_string(*(int*)entry->p);
CFG_write_key_value(f, key, str);
break;
- case FILES: return 1; // ignore
- case NONE: return 0; // end
+ case Y_FILES: return 1; // ignore
+ case 0: return 0; // end
default: assert(0); // unknown type -> something broken
}
}
- return entry->t == NONE ? 0 : 1;
+ return entry->t == 0 ? 0 : 1;
}
-static int CFG_update_config (const char *old, const char *new, const cfg_t *cfg, const char *msg) {
+int CFG_update_config (const char *old, const char *new, const cfg_t *cfg, const char *msg) {
assert(old != NULL);
assert(new != NULL);
assert(cfg != NULL);
@@ -329,10 +238,3 @@ static int CFG_update_config (const char *old, const char *new, const cfg_t *cfg
}
return nf != NULL;
}
-
-void CFG_save (void) {
- CFG_update_config("doom2d.cfg", "doom2d.cfg", cfg, "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");
-}
diff --git a/src/config.h b/src/config.h
index 72a5355349bc33ce238b6b6e4ce82704882bf778..29d17d71497f1e93ed3f7f9d71732c7daed4a732 100644 (file)
--- a/src/config.h
+++ b/src/config.h
#define CONFIG_H_INCLUDED
#include "glob.h"
+#include "system.h"
-extern byte cheat;
-extern byte shot_vga;
+const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg);
+int CFG_update_key (const char *key, const char *value, const cfg_t *cfg);
-void CFG_args (int argc, char **argv);
-void CFG_load (void);
-void CFG_save (void);
+int CFG_open_iterator (const char *name);
+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_update_config (const char *old, const char *new, const cfg_t *cfg, const char *msg);
#endif /* CONFIG_H_INCLUDED */
diff --git a/src/game.c b/src/game.c
index b540223a46028b5beaddaa4265a6722987b8f8aa..eba57b827eb251a2447bf4872c6c8b22a2113c1e 100644 (file)
--- a/src/game.c
+++ b/src/game.c
int dm_pl1p;
int dm_pl2p;
pos_t dm_pos[100];
+byte cheat;
static void *telepsnd;
diff --git a/src/game.h b/src/game.h
index 48b7898f74376370c35f51e0a1fe9371bae53be9..03aff95032fd3bea718a57dc2cef0b16a2b3281b 100644 (file)
--- a/src/game.h
+++ b/src/game.h
extern int dm_pl1p;
extern int dm_pl2p;
extern pos_t dm_pos[100];
+extern byte cheat;
extern int lt_time;
extern int lt_type;
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 4f529db45c1667da9e7b40e0c3b1e41444174cd2..2df46b3fb96cdc76a92b6e799f72878b45493c2f 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
#include "player.h" // pl1 pl2
#include "menu.h" // G_keyf
#include "error.h" // logo
+#include "monster.h" // nomon
#include "files.h" // F_startup F_addwad F_initwads F_allocres
#include "config.h" // CFG_args CFG_load CFG_save
static int text_input;
static videomode_t vlist;
+static const cfg_t arg[] = {
+ {"file", NULL, Y_FILES},
+ {"cheat", &cheat, Y_SW_ON},
+// {"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
+};
+
+static const cfg_t cfg[] = {
+// {"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},
+ {"pl1_left", &pl1.kl, Y_KEY},
+ {"pl1_right",&pl1.kr, Y_KEY},
+ {"pl1_up", &pl1.ku, Y_KEY},
+ {"pl1_down", &pl1.kd, Y_KEY},
+ {"pl1_jump", &pl1.kj, Y_KEY},
+ {"pl1_fire", &pl1.kf, Y_KEY},
+ {"pl1_next", &pl1.kwr, Y_KEY},
+ {"pl1_prev", &pl1.kwl, Y_KEY},
+ {"pl1_use", &pl1.kp, Y_KEY},
+ {"pl2_left", &pl2.kl, Y_KEY},
+ {"pl2_right", &pl2.kr, Y_KEY},
+ {"pl2_up", &pl2.ku, Y_KEY},
+ {"pl2_down", &pl2.kd, Y_KEY},
+ {"pl2_jump", &pl2.kj, Y_KEY},
+ {"pl2_fire", &pl2.kf, Y_KEY},
+ {"pl2_next", &pl2.kwr, Y_KEY},
+ {"pl2_prev", &pl2.kwl, Y_KEY},
+ {"pl2_use", &pl2.kp, Y_KEY},
+ {NULL, NULL, 0} // end
+};
+
+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]);
+ }
+ }
+}
+
+static void CFG_load (void) {
+ CFG_read_config("default.cfg", cfg);
+ CFG_read_config("doom2d.cfg", cfg);
+}
+
+static void CFG_save (void) {
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", cfg, "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");
+}
+
/* --- error.h --- */
void logo (const char *s, ...) {
diff --git a/src/sdl2/main.c b/src/sdl2/main.c
index 67387dba6b6d8bf2cabfc2e1382ceeb00628e2fb..ae80fe9d6dd8c62f8993994620a0204fe846943d 100644 (file)
--- a/src/sdl2/main.c
+++ b/src/sdl2/main.c
#include "player.h" // pl1 pl2
#include "menu.h" // G_keyf
#include "error.h" // logo
+#include "monster.h" // nomon
#include "files.h" // F_startup F_addwad F_initwads F_allocres
#include "config.h" // CFG_args CFG_load CFG_save
static SDL_Surface *surf;
static videomode_t vlist;
+static const cfg_t arg[] = {
+ {"file", NULL, Y_FILES},
+ {"cheat", &cheat, Y_SW_ON},
+// {"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
+};
+
+static const cfg_t cfg[] = {
+// {"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},
+ {"pl1_left", &pl1.kl, Y_KEY},
+ {"pl1_right",&pl1.kr, Y_KEY},
+ {"pl1_up", &pl1.ku, Y_KEY},
+ {"pl1_down", &pl1.kd, Y_KEY},
+ {"pl1_jump", &pl1.kj, Y_KEY},
+ {"pl1_fire", &pl1.kf, Y_KEY},
+ {"pl1_next", &pl1.kwr, Y_KEY},
+ {"pl1_prev", &pl1.kwl, Y_KEY},
+ {"pl1_use", &pl1.kp, Y_KEY},
+ {"pl2_left", &pl2.kl, Y_KEY},
+ {"pl2_right", &pl2.kr, Y_KEY},
+ {"pl2_up", &pl2.ku, Y_KEY},
+ {"pl2_down", &pl2.kd, Y_KEY},
+ {"pl2_jump", &pl2.kj, Y_KEY},
+ {"pl2_fire", &pl2.kf, Y_KEY},
+ {"pl2_next", &pl2.kwr, Y_KEY},
+ {"pl2_prev", &pl2.kwl, Y_KEY},
+ {"pl2_use", &pl2.kp, Y_KEY},
+ {NULL, NULL, 0} // end
+};
+
+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]);
+ }
+ }
+}
+
+static void CFG_load (void) {
+ CFG_read_config("default.cfg", cfg);
+ CFG_read_config("doom2d.cfg", cfg);
+}
+
+static void CFG_save (void) {
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", cfg, "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");
+}
+
/* --- error.h --- */
void logo (const char *s, ...) {
diff --git a/src/system.h b/src/system.h
index 0de8d42ef9e216cb22c6d87f371dd5b5361b49a3..9b571858a3505e0f79c7e25ee6e28164b29eab60 100644 (file)
--- a/src/system.h
+++ b/src/system.h
#include "glob.h"
+enum { Y_BYTE = 1, Y_WORD, Y_DWORD, Y_STRING, Y_SW_ON, Y_SW_OFF, Y_FILES, Y_KEY };
+
+typedef struct cfg_t {
+ const char *cfg;
+ void *p;
+ byte t;
+} cfg_t;
+
typedef struct videomode_size_t {
int w, h, r;
} videomode_size_t;