doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

m_misc.c (3733B)


      1 #include <ctype.h>
      2 #include <fcntl.h>
      3 #include <stdlib.h>
      4 #include <sys/stat.h>
      5 #include <sys/types.h>
      6 #include <unistd.h>
      7 
      8 #include "m_misc.h"
      9 #include "m_swap.h"
     10 #include "doomdef.h"
     11 #include "z_zone.h"
     12 #include "m_argv.h"
     13 #include "w_wad.h"
     14 #include "i_system.h"
     15 #include "i_video.h"
     16 #include "v_video.h"
     17 #include "hu_stuff.h"
     18 #include "doomstat.h"
     19 #include "dstrings.h"
     20 
     21 extern int   key_right;
     22 extern int   key_left;
     23 extern int   key_up;
     24 extern int   key_down;
     25 extern int   key_strafeleft;
     26 extern int   key_straferight;
     27 extern int   key_fire;
     28 extern int   key_use;
     29 extern int   key_strafe;
     30 extern int   key_speed;
     31 extern int   mousebfire;
     32 extern int   mousebstrafe;
     33 extern int   mousebforward;
     34 extern int   joybfire;
     35 extern int   joybstrafe;
     36 extern int   joybuse;
     37 extern int   joybspeed;
     38 extern int   mouseSensitivity;
     39 extern int   showMessages;
     40 extern int   detailLevel;
     41 extern int   screenblocks;
     42 extern int   numChannels;
     43 extern char*  chat_macros[];
     44 
     45 int   usemouse;
     46 int   usejoystick;
     47 
     48 typedef struct default_t Default;
     49 
     50 struct default_t {
     51     int*  location;
     52     long  defaultvalue;
     53     long  scantranslate;
     54     long  untranslated;
     55 };
     56 
     57 Default defaults[] = {
     58 	/* location              default*/
     59     { &mouseSensitivity,     5                      },
     60     { &snd_SfxVolume,        8                      },
     61     { &snd_MusicVolume,      8                      },
     62     { &showMessages,         1                      },
     63     { &key_right,            KEY_RIGHTARROW         },
     64     { &key_left,             KEY_LEFTARROW          },
     65     { &key_up,               KEY_UPARROW            },
     66     { &key_down,             KEY_DOWNARROW          },
     67     { &key_strafeleft,       ','                    },
     68     { &key_straferight,      '.'                    },
     69     { &key_fire,             KEY_RCTRL              },
     70     { &key_use,              ' '                    },
     71     { &key_strafe,           KEY_RALT               },
     72     { &key_speed,            KEY_RSHIFT             },
     73     { &usemouse,             1                      },
     74     { &mousebfire,           0                      },
     75     { &mousebstrafe,         1                      },
     76     { &mousebforward,        2                      },
     77     { &usejoystick,          0                      },
     78     { &joybfire,             0                      },
     79     { &joybstrafe,           1                      },
     80     { &joybuse,              3                      },
     81     { &joybspeed,            2                      },
     82     { &screenblocks,         9                      },
     83     { &detailLevel,          0                      },
     84     { &numChannels,          3                      },
     85     { &usegamma,             0                      },
     86     { (int*)&chat_macros[0], (long)HUSTR_CHATMACRO0 },
     87     { (int*)&chat_macros[1], (long)HUSTR_CHATMACRO1 },
     88     { (int*)&chat_macros[2], (long)HUSTR_CHATMACRO2 },
     89     { (int*)&chat_macros[3], (long)HUSTR_CHATMACRO3 },
     90     { (int*)&chat_macros[4], (long)HUSTR_CHATMACRO4 },
     91     { (int*)&chat_macros[5], (long)HUSTR_CHATMACRO5 },
     92     { (int*)&chat_macros[6], (long)HUSTR_CHATMACRO6 },
     93     { (int*)&chat_macros[7], (long)HUSTR_CHATMACRO7 },
     94     { (int*)&chat_macros[8], (long)HUSTR_CHATMACRO8 },
     95     { (int*)&chat_macros[9], (long)HUSTR_CHATMACRO9 }
     96 };
     97 
     98 void
     99 M_LoadDefaults()
    100 {
    101     uint     i;
    102 
    103     for (i = 0; i < LENGTH(defaults); ++i)
    104 		*defaults[i].location = defaults[i].defaultvalue;
    105 }
    106 
    107 void
    108 M_WriteFile(char* name, void* src, uint n)
    109 {
    110 	FILE* f;
    111 
    112 	f = fopen(name, "w");
    113 	fwrite(src, n, 1, f);
    114 	fclose(f);
    115 }
    116 
    117 void
    118 M_ReadFile(char* name, uchar** buf)
    119 {
    120 	FILE* f;
    121 	ulong n;
    122 
    123 	f = fopen(name, "r");
    124 	fseek(f, 0, SEEK_END);
    125 	n = ftell(f);
    126 	fseek(f, 0, SEEK_SET);
    127 	*buf = Z_Malloc(n, PU_STATIC, NULL);
    128 	fread(*buf, n, 1, f);
    129     fclose(f);
    130 }