1 /*******************************************************************
2 *
3 * DESCRIPTION: davehook.cpp
4 *
5 * AUTHOR: David Malcolm
6 *
7 * HISTORY: Created 18/11/97
8 *
9 *******************************************************************/
10
11 /* Includes ********************************************************/
12 #include "3dc.h"
13 #include "davehook.h"
14
15
16 #include "r2base.h"
17 // hooks to R2 code
18
19 #include "gadget.h"
20 // hooks to gadgets code
21
22 #include "daemon.h"
23 // hooks to daemon code
24
25 #include "rentrntq.h"
26
27 //#include "ammo666.hpp"
28
29 #include "iofocus.h"
30
31 #include "font.h"
32
33 #include "hudgadg.hpp"
34
35 #include "consvar.hpp"
36 #include "conscmnd.hpp"
37
38 #include "missions.hpp"
39
40 #include "indexfnt.hpp"
41 // Includes for console variables:
42 #include "textexp.hpp"
43
44 // Includes for console commands:
45 #include "consvar.hpp"
46 #include "modcmds.hpp"
47 #include "trepgadg.hpp"
48
49 #include "consbind.hpp"
50
51 #include "consbtch.hpp"
52
53
54 #define UseLocalAssert Yes
55 #include "ourasert.h"
56
57 #include "avp_menus.h"
58 /* Version settings ************************************************/
59
60 /* Constants *******************************************************/
61
62 /* Macros **********************************************************/
63
64 /* Imported function prototypes ************************************/
65
66 /* Imported data ***************************************************/
67 #ifdef __cplusplus
68 extern "C"
69 {
70 #endif
71
72 extern unsigned char KeyboardInput[];
73
74 extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
75 extern int VideoModeColourDepth;
76
77 extern int bEnableTextprint;
78 extern int bEnableTextprintXY;
79 extern signed int HUDTranslucencyLevel;
80
81 #ifdef __cplusplus
82 };
83 #endif
84
85
86
87 /* Exported globals ************************************************/
88 #if 0
89 int FixP_Test = (ONE_FIXED/2);
90 #endif
91
92 /* Internal type definitions ***************************************/
93
94 /* Internal function prototypes ************************************/
95 namespace Testing
96 {
97 void VVTest(void);
98 void VITest(int);
99 int IVTest(void);
100 int IITest(int);
101
102 void DumpRefCounts(void);
103 void DumpVideoMode(void);
104 };
105
106 static int bFirstFrame = No;
107
108 /* Internal globals ************************************************/
109
110 /* Exported function definitions ***********************************/
CreateAll(void)111 /*static*/ void ConsoleVariable :: CreateAll(void)
112 {
113 // hook to create all the console variables
114 // (to make it easy to add new ones)
115
116
117 MakeSimpleConsoleVariable_Int
118 (
119 TextExpansion :: bVerbose, // int& Value_ToUse,
120 "EXPV", // ProjChar* pProjCh_ToUse,
121 "(VERBOSE REPORTS OF TEXT EXPANSIONS)", // ProjChar* pProjCh_Description_ToUse
122 0, // int MinVal_New,
123 1 // int MaxVal_New
124 );
125
126 #if 0
127 MakeSimpleConsoleVariable_Int
128 (
129 bEnableTextprint, // int& Value_ToUse,
130 "TEXT", // ProjChar* pProjCh_ToUse,
131 "(ENABLE/DISABLE DIAGNOSTIC TEXT)", // ProjChar* pProjCh_Description_ToUse
132 0, // int MinVal_New,
133 1 // int MaxVal_New
134 );
135
136 MakeSimpleConsoleVariable_Int
137 (
138 bEnableTextprintXY, // int& Value_ToUse,
139 "TEXTXY", // ProjChar* pProjCh_ToUse,
140 "(ENABLE/DISABLE POSITIONED TEXT)", // ProjChar* pProjCh_Description_ToUse
141 0, // int MinVal_New,
142 1 // int MaxVal_New
143 );
144 MakeSimpleConsoleVariable_Int
145 (
146 HUDTranslucencyLevel, // int& Value_ToUse,
147 "HUDALPHA", // ProjChar* pProjCh_ToUse,
148 "(OPACITY OF HEAD-UP-DISPLAY)", // ProjChar* pProjCh_Description_ToUse
149 0, // int MinVal_New,
150 255 // int MaxVal_New
151 );
152
153 MakeSimpleConsoleVariable_FixP
154 (
155 FixP_Test, // int& Value_ToUse,
156 "FIXPTEST", // ProjChar* pProjCh_ToUse,
157 "(A TEST)", // ProjChar* pProjCh_Description_ToUse
158 0, // int MinVal_New,
159 65536 // int MaxVal_New
160 );
161
162 MakeSimpleConsoleVariable_FixP
163 (
164 Daemon :: DaemonTimeScale, // int& Value_ToUse,
165 "IO-TIME", // ProjChar* pProjCh_ToUse,
166 "TIMESCALE FOR USER INTERFACE", // ProjChar* pProjCh_Description_ToUse
167 655, // int MinVal_New,
168 65536 // int MaxVal_New
169 );
170
171 MakeSimpleConsoleVariable_Int
172 (
173 KeyBinding :: bEcho,
174 "ECHO-BIND",
175 "(ENABLES ECHOING OF STRINGS BOUND TO KEYS)",
176 0,
177 1
178 );
179
180 MakeSimpleConsoleVariable_Int
181 (
182 BatchFileProcessing :: bEcho,
183 "ECHO-BATCH",
184 "(ENABLES ECHOING OF BATCH FILES)",
185 0,
186 1
187 );
188 #endif
189
190
191 }
192
CreateAll(void)193 /*static*/ void ConsoleCommand :: CreateAll(void)
194 {
195 Make
196 (
197 "LISTCMD",
198 "LIST ALL CONSOLE COMMANDS",
199 ConsoleCommand :: ListAll
200 );
201
202 Make
203 (
204 "LISTEXP",
205 "LIST ALL TEXT EXPANSIONS",
206 TextExpansion :: ListAll
207 );
208
209 Make
210 (
211 "LISTVAR",
212 "LIST ALL CONSOLE VARIABLES",
213 ConsoleVariable :: ListAllVariables
214 );
215
216
217
218 // Need to add
219 #if 0
220 static void AttemptToBind
221 (
222 SCString* pSCString_Key, // description of key
223 SCString* pSCString_ToBind // string to be bound
224 );
225 static void AttemptToUnbind
226 (
227 SCString* pSCString_Key // description of key
228 );
229 #endif
230
231
232 Make
233 (
234 "LISTBIND",
235 "LIST ALL KEY BINDINGS",
236 KeyBinding::ListAllBindings
237 );
238 Make
239 (
240 "UNBIND-ALL",
241 "GET RID OF ALL KEY BINDINGS",
242 KeyBinding::UnbindAll
243 );
244 #if 0
245 Make
246 (
247 "LISTMOD",
248 "LIST ALL MODULES",
249 ModuleCommands :: ListModules
250 );
251 Make
252 (
253 "C-KILL",
254 "CLEAR TEXT REPORT QUEUE",
255 TextReportGadget :: ClearTheQueue
256 );
257
258 Make
259 (
260 "D-REFDUMP",
261 "DIAGNOSTICS ON REFERENCE COUNTS",
262 Testing :: DumpRefCounts
263 );
264
265 Make
266 (
267 "VIDMODE",
268 "DUMP INFO ON VIDEO MODE",
269 Testing :: DumpVideoMode
270 );
271 #endif
272 #if 0
273 Make
274 (
275 "VVTEST",
276 "TEST COMMAND",
277 Testing :: VVTest
278 );
279 Make
280 (
281 "VITEST",
282 "TEST COMMAND",
283 Testing :: VITest
284 );
285 Make
286 (
287 "IVTEST",
288 "TEST COMMAND",
289 Testing :: IVTest
290 );
291 Make
292 (
293 "IITEST",
294 "TEST COMMAND",
295 Testing :: IITest
296 );
297 #endif
298
299
300 }
301
DAVEHOOK_Init(void)302 void DAVEHOOK_Init(void)
303 {
304 #if 0
305 static SCString* pSCString_TestLeak = new SCString("this is a test memory leak");
306 #endif
307
308 MissionHacks :: TestInit();
309
310 {
311 DAEMON_Init();
312
313 // AmmoDaemon :: Init();
314 }
315
316 new IndexedFont_HUD(DATABASE_MESSAGE_FONT);
317
318 GADGET_Init();
319
320 #if UseGadgets
321 ConsoleVariable :: CreateAll();
322 ConsoleCommand :: CreateAll();
323 #endif
324
325 }
326
DAVEHOOK_UnInit(void)327 void DAVEHOOK_UnInit(void)
328 {
329 IndexedFont :: UnloadFont(DATABASE_MESSAGE_FONT);
330
331 GADGET_UnInit();
332 }
333
DAVEHOOK_Maintain(void)334 void DAVEHOOK_Maintain(void)
335 {
336 {
337 // AmmoDaemon :: Maintain();
338
339 DAEMON_Maintain();
340 }
341
342 #if KeyBindingUses_KEY_ID
343 {
344 KeyBinding :: Maintain();
345 }
346 #endif
347
348 // Hacked in input support:
349 {
350 #if 0
351 if ( KeyboardInput[ KEY_J ] )
352 {
353 // Test jitter hack
354 HUDGadget* pHUD = HUDGadget :: GetHUD();
355
356 if ( pHUD )
357 {
358 pHUD -> Jitter(ONE_FIXED);
359 }
360
361 }
362 #endif
363
364 #if 0
365 if ( KeyboardInput[ KEY_CR ] )
366 {
367 IOFOCUS_Toggle();
368
369 #if 0
370 // toggle typing/control mode
371 textprint("\n\n\n\nTOGGLE TYPING MODE\n");
372 #endif
373 }
374 #endif
375 }
376
377 if ( bFirstFrame )
378 {
379 RE_ENTRANT_QUEUE_WinMain_FlushMessagesWithoutProcessing();
380 // this is a hack to ensure that none of the keypresses used
381 // in the menu get through to the first frame of the game and
382 // for example, switch to typing mode (for CR presses)
383
384 bFirstFrame = No;
385 }
386 else
387 {
388 // Flush the WinProc messages:
389 RE_ENTRANT_QUEUE_WinMain_FlushMessages();
390 }
391 }
392
DAVEHOOK_ScreenModeChange_Setup(void)393 void DAVEHOOK_ScreenModeChange_Setup(void)
394 {
395 }
396
DAVEHOOK_ScreenModeChange_Cleanup(void)397 void DAVEHOOK_ScreenModeChange_Cleanup(void)
398 {
399 R2BASE_ScreenModeChange_Cleanup();
400 GADGET_ScreenModeChange_Cleanup();
401
402 bFirstFrame = Yes;
403 // to ensure a flush without processing of messages in first frame, so as to
404 // avoid carriage returns/enter from menu selections triggering typing mode
405
406 // Run program-generated batch file:
407 #if !(PREDATOR_DEMO|MARINE_DEMO||ALIEN_DEMO||DEATHMATCH_DEMO)
408 BatchFileProcessing :: Run("config.cfg");
409
410 // Run user-generated batch file:
411 BatchFileProcessing :: Run("startup.cfg");
412 #endif
413 }
414
415
416 /* Internal function definitions ***********************************/
VVTest(void)417 void Testing :: VVTest(void)
418 {
419 textprint("Testing :: VVTest()\n");
420 }
VITest(int i)421 void Testing :: VITest(int i)
422 {
423 textprint("Testing :: VITest(%i)\n",i);
424 }
IVTest(void)425 int Testing :: IVTest(void)
426 {
427 textprint("Testing :: IVTest()\n");
428
429 return 180;
430 }
IITest(int i)431 int Testing :: IITest(int i)
432 {
433 textprint("Testing :: IITest(%i)\n",i);
434
435 return (i*2);
436 }
437
438
439 // Diagnostic hook for reference counting system:
DumpRefCounts(void)440 void Testing :: DumpRefCounts(void)
441 {
442 #if TrackReferenceCounted
443 {
444 SCString* pSCString_Feedback = new SCString("DUMPING REFCOUNT INFO");
445 pSCString_Feedback -> SendToScreen();
446 pSCString_Feedback -> R_Release();
447
448 LogFile tempLog("REFDUMP.TXT");
449 RefCountObject :: DumpAll(tempLog);
450 }
451 #else
452 {
453 SCString* pSCString_Feedback = new SCString("REFCOUNT INFO DISABLED AT COMPILE-TIME");
454 pSCString_Feedback -> SendToScreen();
455 pSCString_Feedback -> R_Release();
456 }
457 #endif
458 }
459
DumpVideoMode(void)460 void Testing :: DumpVideoMode(void)
461 {
462 char msg[256];
463 sprintf
464 (
465 msg,
466 "VIDEO MODE:%iX%iX%i",
467 ScreenDescriptorBlock . SDB_Width,
468 ScreenDescriptorBlock . SDB_Height,
469 VideoModeColourDepth
470 );
471
472 SCString* pSCString_Feedback = new SCString(msg);
473 pSCString_Feedback -> SendToScreen();
474 pSCString_Feedback -> R_Release();
475 }
476