home *** CD-ROM | disk | FTP | other *** search
/ Instant Doom Levels / Instant.Doom.Levels.-.Level.Master.II.iso / EDITORS / ZIPPED / WSCDEU52.ZIP / INCLUDE / WINDEU.H < prev    next >
C/C++ Source or Header  |  1995-03-05  |  14KB  |  390 lines

  1. /*----------------------------------------------------------------------------*
  2.  | This file is part of WinDEU, the port of DEU to Windows.                   |
  3.  | WinDEU was created by the DEU team:                                        |
  4.  |  Renaud Paquay, Raphael Quinet, Brendon Wyber and others...                |
  5.  |                                                                            |
  6.  | DEU is an open project: if you think that you can contribute, please join  |
  7.  | the DEU team.  You will be credited for any code (or ideas) included in    |
  8.  | the next version of the program.                                           |
  9.  |                                                                            |
  10.  | If you want to make any modifications and re-distribute them on your own,  |
  11.  | you must follow the conditions of the WinDEU license. Read the file        |
  12.  | LICENSE or README.TXT in the top directory.  If do not  have a copy of     |
  13.  | these files, you can request them from any member of the DEU team, or by   |
  14.  | mail: Raphael Quinet, Rue des Martyrs 9, B-4550 Nandrin (Belgium).         |
  15.  |                                                                            |
  16.  | This program comes with absolutely no warranty.  Use it at your own risks! |
  17.  *----------------------------------------------------------------------------*
  18.  
  19.     Project WinDEU
  20.     DEU team
  21.     Jul-Dec 1994, Jan-Mar 1995
  22.  
  23.     FILE:         windeu.h
  24. */
  25. #ifndef __windeu_h
  26. #define __windeu_h
  27.  
  28. #ifndef __common_h
  29.     #include "common.h"
  30. #endif
  31.  
  32. /*
  33.    description of the command line arguments and config file keywords
  34. */
  35.  
  36. enum OPT_TYPE
  37. {
  38.       OPT_BOOLEAN,          /* boolean (toggle) */
  39.       OPT_INTEGER,          /* integer number */
  40.       OPT_STRING,           /* character string */
  41.       OPT_STRINGACC,        /* character string, but store in a list */
  42.       OPT_STRINGLIST,       /* list of character strings */
  43.       OPT_END               /* end of the options description */
  44. };
  45.  
  46.  
  47. typedef struct
  48. {
  49.    char *short_name;        /* abbreviated command line argument */
  50.    char *long_name;         /* command line arg. or keyword */
  51.    enum OPT_TYPE opt_type ; /* type of this option */
  52.    char *msg_if_true;       /* message printed if option is true */
  53.    char *msg_if_false;      /* message printed if option is false */
  54.    void *data_ptr;          /* pointer to the data */
  55. } OptDesc;
  56.  
  57. /*
  58.    the macros and constants
  59. */
  60.  
  61. /* name of the configuration file */
  62. #define DEU_CONFIG_FILE     "WINDEU.INI"
  63.  
  64. /* name of the log file (debug mode) */
  65. #define DEU_LOG_FILE        "WINDEU.LOG"
  66.  
  67. /*
  68.  
  69.     Macros to select and unselect the WAIT cursor inside a function
  70.  
  71. */
  72.  
  73. #define SELECT_WAIT_CURSOR() \
  74.     HCURSOR hSaveOldCursor = ::SetCursor(::LoadCursor(0, IDC_WAIT));
  75.  
  76. #define UNSELECT_WAIT_CURSOR() \
  77.     ::SetCursor(hSaveOldCursor);
  78.  
  79.  
  80. /*
  81.  
  82.     Macros used to save and restore the working message of the status bar
  83.     in a function
  84.  
  85. */
  86. #define SAVE_WORK_MSG()                    \
  87.     char OldSaveMsg[80];                \
  88.     GetWorkMessage (OldSaveMsg, 80);
  89.  
  90.  
  91. #define RESTORE_WORK_MSG()               \
  92.     WorkMessage (OldSaveMsg);
  93.  
  94.  
  95. /*
  96.  
  97.     Use these macros to set/restore a help context ID.
  98.     You can't use this in blocks of different scope level,
  99.     because of the intermediate var. definition
  100.  
  101. */
  102. #define SET_HELP_CONTEXT(hc)            \
  103. {                                       \
  104.     DWORD OldHelpContext = HelpContext; \
  105.     HelpContext          = hc;
  106.  
  107. #define RESTORE_HELP_CONTEXT()           \
  108.     HelpContext = OldHelpContext;       \
  109. }
  110.  
  111.  
  112. // General macro to assert a bounded number
  113. #define assert_bound(var,min,max)         \
  114.     assert((var) >= (min) && (var) <= (max))
  115.  
  116. // Macros to assert a valid object number (but NOT -1)
  117. #define assert_tnum(t)                        \
  118.     assert_bound((t), 0, NumThings-1)
  119.  
  120. #define assert_ldnum(ld)                    \
  121.     assert_bound((ld), 0, NumLineDefs-1)
  122.  
  123. #define assert_sdnum(sd)                    \
  124.     assert_bound((sd), 0, NumSideDefs-1)
  125.  
  126. #define assert_vnum(v)                        \
  127.     assert_bound((v), 0, NumVertexes-1)
  128.  
  129. #define assert_snum(s)                        \
  130.     assert_bound((s), 0, NumSectors-1)
  131.  
  132.  
  133. // Macros to assert a valid object number (INCLUDING '-1')
  134. #define assert_vtnum(t)                        \
  135.     assert_bound((t), -1, NumThings-1)
  136.  
  137. #define assert_vldnum(ld)                    \
  138.     assert_bound((ld), -1, NumLineDefs-1)
  139.  
  140. #define assert_vsdnum(sd)                    \
  141.     assert_bound((sd), -1, NumSideDefs-1)
  142.  
  143. #define assert_vvnum(v)                        \
  144.     assert_bound((v), -1, NumVertexes-1)
  145.  
  146. #define assert_vsnum(s)                        \
  147.     assert_bound((s), -1, NumSectors-1)
  148.  
  149.  
  150. /*
  151.    the interfile global variables
  152. */
  153.  
  154. /* from windeu.cpp */
  155. extern int   DoomVersion;    /* 1 for DOOM or 2 for DOOM2 */
  156. extern BOOL  Registered;    /* registered or shareware WAD file? */
  157. extern BOOL  Debug;         /* are we debugging? */
  158. extern BOOL  Quiet;         /* don't play a sound when an object is selected */
  159. extern BOOL  Quieter;       /* don't play any sound, even when an error occurs */
  160. extern BOOL  Expert;        /* don't ask for confirmation for some operations */
  161. extern int   InitialScale;  /* initial zoom factor for map */
  162. extern BOOL  Colour2;       /* use the alternate set for things colors */
  163. extern BOOL  AdditiveSelBox;/* additive selection box or select in box only? */
  164. extern int   SplitFactor;   /* factor used by the Nodes builder */
  165. extern BOOL  Select0;       /* select object 0 by default when switching modes */
  166. extern char *MainWad;       /* name of the main wad file */
  167. extern Bool  Use3DControls;    /* Enable CTL3DV2.DLL or CTL3D32.DLL? */
  168. extern Bool  DrawLineDefsLen;/* Display length of moving LineDefs */
  169. extern int   BuildPriority;    /* Priority for the nodes builder */
  170. // Moved from WINDEU.CPP to use them in WinDEUApp class
  171. extern Bool  Reminder;        /* display a funny message when DEU starts */
  172. extern char **PatchWads;    /* list of patch wad files */
  173.  
  174. extern FILE *logfile;       /* filepointer to the error log */
  175.  
  176. /* from editcli.cpp */
  177. extern BOOL InfoShown;          /* is the bottom line displayed? */
  178.  
  179. /* from windeapp.cpp */
  180. extern DWORD HelpContext;
  181.  
  182. /* from windeu.cpp (config file options) */
  183. extern char  *DefaultWallTexture;        /* default normal wall texture */
  184. extern char  *DefaultLowerTexture;        /* default lower wall texture */
  185. extern char  *DefaultUpperTexture;        /* default upper wall texture */
  186. extern char  *DefaultFloorTexture;        /* default floor texture */
  187. extern char  *DefaultCeilingTexture;    /* default ceiling texture */
  188. extern SHORT  DefaultFloorHeight;        /* default floor height */
  189. extern SHORT  DefaultCeilingHeight;        /* default ceiling height */
  190.  
  191.  
  192. /*
  193.    the function prototypes
  194. */
  195.  
  196. /* from windeu.cpp */
  197. void InitWindeu (int argc, char *argv[]) ;
  198. void CleanupWindeu () ;
  199. void CenterWindow (TWindow *pWnd);
  200. void Beep ();
  201. void PlaySound (int, int);
  202. void ProgError (char *, ...);
  203. void LogMessage (char *, ...);
  204. void WorkMessage (char*, ...);
  205. void GetWorkMessage (char *buffer, size_t bufferSize);
  206. BOOL Confirm (char*, ...);
  207. void Notify (char *, ...);
  208. void FunnyMessage ();
  209. void Usage ();
  210. void ParseCommandLineOptions (int argc, char *argv[]);
  211. void ParseConfigFileOptions (char *filename);
  212. void AppendItemToList (char ***list, char *item);
  213.  
  214. ////////////////////////////////////////////////////////////////////////
  215. //
  216. // How WinDEU Cooperates with others Windows apps.
  217. // ===============================================
  218. //
  219. //RP: Feb 2 1995
  220. //
  221. // COOPERATION_VERSION == 1
  222. //
  223. //    First attempt to make WinDEU multi-task with other Windows
  224. //    apps.
  225. //
  226. //    1. I defined a 'Cooperate' function which makes 1 (ONE) call to
  227. //       PeekMessage, effectively giving control to Windows and parsing
  228. //       1(ONE) message in the WinDEU message queue. That's why you can
  229. //       still edit your level while building it. I MUST FIND A WAY TO
  230. //       AVOID THIS.
  231. //
  232. //    2. I defined a 'BuildPriority' config option which defines the
  233. //       frenquency at which WinDEU asks Windows to give control to other
  234. //       apps. The COOPERATE macro uses BuildPriority to make calls to
  235. //       the 'Cooperate' function.
  236. //       If for example, BuildPriority is defined as 15, it means
  237. //       that 15 of 100 calls to 'COOPERATE' will effectively make a call
  238. //       to the 'Cooperate' function (which gives control to Windows).
  239. //
  240. //    3. I had then to put calls to 'COOPERATE' in the nodes builder code.
  241. //       This wad the trickiest part of the work, because until now, the time
  242. //       is not taken into account by COOPERATE. The problem is to put
  243. //       COOPERATE in the code at 'right places'. To define 'Right Places',
  244. //       I had to take two parameters into account:
  245. //       - The overhead must be controlled. That means I can't call
  246. //         COOPERATE in every loop. If I put a COOPERATE in a loop of
  247. //         1000 iterations which simply make 'i++', the overhead would be
  248. //         too big (WinDEU spends its time giving control to Windows, even with
  249. //         a priority of 1).
  250. //       - There must be enough calls to COOPERATE to let Windows take control
  251. //         often enough.
  252. //       - The calls to COOPERATE should be as regular (at the 'time' point of
  253. //         view) as possible
  254. //       So 'Right places' means not to much calls, not to few, and
  255. //       as regular (time point of view) as possible:
  256. //
  257. //  Here's the first definition of COOPERATE:
  258. //
  259. //     #define COOPERATE()                          \
  260. //     {                                            \
  261. //         if ( BuildPriority != 0 )                \
  262. //         {                                        \
  263. //             CoopCount++;                         \
  264. //             if ( CoopCount >= PRIORITY_RES )     \
  265. //                 CoopCount = 0;                   \
  266. //             if (CoopExecTab[CoopCount])          \
  267. //                 Cooperate();                     \
  268. //         }                                        \
  269. //     }
  270. //
  271. //    NOTE: The CoopExecTab is an array of boolean values indicating
  272. //          if the correponding COOPERATE call must
  273. //          If BuildPriority == 50, 1 element of 2 of CoopExecTab == TRUE
  274. //
  275. // Conclusion:
  276. // ----------
  277. //    Finaly, it worked not bad, but I wasn't happy because the time is
  278. //    not taken into account. That means calls to 'Cooperate()' depends largely
  279. //    on the processor speed and number of iterations in a loop.
  280. //
  281. //RP: Feb 5 1995
  282. //
  283. // COOPERATION_VERSION == 2
  284. //
  285. //    1. I redefined to 'BuildPriority' config options. It now means
  286. //       the MINIMUM number of milliseconds WinDEU will work before
  287. //       calling Cooperate.
  288. //
  289. //    2. The 'Cooperate' function makes 'BuildPriority / 10' calls to
  290. //       'PeekMessage' every time it's called. It means a maximum of
  291. //       100 messages/sec will be processed by WinDEU when building
  292. //       a level. I don't know if it's really useful.
  293. //
  294. //    3. COOPERATE now uses the GetTickCount() Windows function to decide
  295. //       to call Cooperate(). Gere's the new definition of COOPERATE:
  296. //
  297. //     #define COOPERATE()                                              \
  298. //     {                                                                \
  299. //         if ( BuildPriority > 0 )                                    \
  300. //         {                                                           \
  301. //             ULONG CurTickCount = ::GetTickCount();                  \
  302. //             if ( CurTickCount - LastCoopCallTick > BuildPriority )  \
  303. //             {                                                        \
  304. //                 Cooperate();                                        \
  305. //                 LastTickCount = CurTickCount;                        \
  306. //             }                                                        \
  307. //         }                                                           \
  308. //     }
  309. //
  310. // Conclusion:
  311. // ----------
  312. //   It works not well, and BuildPriority doesn't depend anymore on the
  313. //   processor speed, but there's still some problems:
  314. //   - The overhead is a little bigger than previously (because of calls
  315. //     to GetTickCount() in EVERY calls to COOPERATE.
  316. //   - It means that I must still be carefull when inserting COOPERATE
  317. //     calls in the code.
  318. //   - The BuildPriority has now a 'time-slice' semantic.
  319. //
  320. // GENERAL NOTE:
  321. // ============
  322. //       When BuildPriority is equal to '0', WinDEU doesn't cooperate at
  323. //       all, like previous version of WinDEU. The overhead of COOPERATE
  324. //       calls in the WinDEU codes is nearly null (COOPERATE tests if
  325. //       BuildPriority != 0 before doing something).
  326. //
  327. #define COOPERATION_VERSION    2
  328.  
  329. #if (COOPERATION_VERSION == 1)
  330.  
  331. // Maximum and minumum possible values for the BuildPriority.
  332. #define BUILD_PRIORITY_MIN      0    // no multi-tasking
  333. #define BUILD_PRIORITY_MAX    100
  334.  
  335. #elif (COOPERATION_VERSION == 2)
  336. // Maximum and minumum possible values for the BuildPriority.
  337. // You should never use a BuildPriority too small (1-15), because
  338. // WinDEU will spend most its time giving control to Windows.
  339. // With Pentium processor, maybe these small values could be used.
  340. #define BUILD_PRIORITY_MIN       0    // no multi-tasking
  341. #define BUILD_PRIORITY_MAX    1000    // 1 second
  342.  
  343. #endif    // COOPERATION_VERSION
  344.  
  345.  
  346. extern void Cooperate(void);
  347.  
  348.  
  349. #if (COOPERATION_VERSION == 1)
  350.  
  351. extern int CoopCount;
  352. extern Bool  CoopExecTab[];
  353. void BuildCoopExecTab(void);
  354.  
  355. #define COOPERATE()                              \
  356. {                                                \
  357.     if ( BuildPriority != 0 )                    \
  358.     {                                            \
  359.         CoopCount++;                             \
  360.         if ( CoopCount >= BUILD_PRIORIY_MAX )     \
  361.             CoopCount = 0;                       \
  362.         if (CoopExecTab[CoopCount])              \
  363.             Cooperate();                         \
  364.     }                                            \
  365. }
  366.  
  367. #elif (COOPERATION_VERSION == 2)
  368.  
  369. // Last time (tick count) Cooperate was called by COOPERATE
  370. extern ULONG LastCoopCallTick;
  371.  
  372. #define COOPERATE()                                                  \
  373. {                                                                    \
  374.     if ( BuildPriority > 0 )                                        \
  375.     {                                                               \
  376.         if ( ::GetTickCount() - LastCoopCallTick >= BuildPriority ) \
  377.         {                                                            \
  378.             Cooperate();                                            \
  379.             LastCoopCallTick = ::GetTickCount();                    \
  380.         }                                                            \
  381.     }                                                               \
  382. }
  383.  
  384. #endif    // COOPERATION_VERSION
  385.  
  386.  
  387. #endif  /* __windeu_h */
  388. /* end of file */
  389.  
  390.