27 interface |
27 interface |
28 {$ELSE} |
28 {$ELSE} |
29 program hwengine; |
29 program hwengine; |
30 {$ENDIF} |
30 {$ENDIF} |
31 |
31 |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler, uSound, |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler, |
33 uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uLandTexture, uCollisions, |
33 uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uAILandMarks, uLandTexture, uCollisions, |
34 SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted |
34 SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted |
35 {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF} |
35 {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF} |
36 {$IFDEF SDL13}, uTouch{$ENDIF}{$IFDEF ANDROID}, GLUnit{$ENDIF}, uAILandMarks; |
36 {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF} |
|
37 {$IFDEF ANDROID}, GLUnit{$ENDIF} |
|
38 ; |
37 |
39 |
38 |
40 |
39 {$IFDEF HWLIBRARY} |
41 {$IFDEF HWLIBRARY} |
40 procedure initEverything(complete:boolean); |
42 procedure initEverything(complete:boolean); |
41 procedure freeEverything(complete:boolean); |
43 procedure freeEverything(complete:boolean); |
441 |
441 |
442 // clean up all the memory allocated |
442 // clean up all the memory allocated |
443 freeEverything(true); |
443 freeEverything(true); |
444 end; |
444 end; |
445 |
445 |
|
446 //////////////////////////////////////////////////////////////////////////////// |
|
447 // As a rule of thumb, every module that is listed in either initEverything or |
|
448 // freeEverything should come in pair, even if they are stubs. Only use this |
|
449 // section for inialising variables and remeber that game args overwrite these, |
|
450 // so handle this section with care. Pay attention to the init/free order too! |
446 procedure initEverything (complete:boolean); |
451 procedure initEverything (complete:boolean); |
447 begin |
452 begin |
448 Randomize(); |
453 Randomize(); |
449 |
454 |
450 uUtils.initModule(complete); // this opens the debug file, must be the first |
455 uUtils.initModule(complete); // opens the debug file, must be the first |
451 uMisc.initModule; |
456 uVariables.initModule; // inits all global variables |
452 uVariables.initModule; |
457 uConsole.initModule; // opens stdout |
453 uConsole.initModule; |
458 uCommands.initModule; // helps below |
454 uCommands.initModule; |
459 uCommandHandlers.initModule; // registers all messages from frontend |
455 uCommandHandlers.initModule; |
460 |
456 |
461 uLand.initModule; // computes land |
457 uLand.initModule; |
462 uLandPainted.initModule; // computes drawn land |
458 uLandPainted.initModule; |
463 uIO.initModule; // sets up sockets |
459 uIO.initModule; |
|
460 |
464 |
461 if complete then |
465 if complete then |
462 begin |
466 begin |
463 {$IFDEF ANDROID}GLUnit.init;{$ENDIF} |
467 {$IFDEF ANDROID}GLUnit.initModule;{$ENDIF} |
464 {$IFDEF SDL13}uTouch.initModule;{$ENDIF} |
468 {$IFDEF USE_TOUCH_INTERFACE}uTouch.initModule;{$ENDIF} |
|
469 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.initModule;{$ENDIF} //stub |
465 uAI.initModule; |
470 uAI.initModule; |
466 //uAIActions does not need initialization |
|
467 //uAIAmmoTests does not need initialization |
|
468 uAIMisc.initModule; |
471 uAIMisc.initModule; |
|
472 uAILandMarks.initModule; //stub |
469 uAmmos.initModule; |
473 uAmmos.initModule; |
|
474 uCaptions.initModule; |
|
475 |
470 uChat.initModule; |
476 uChat.initModule; |
471 uCollisions.initModule; |
477 uCollisions.initModule; |
472 //uFloat does not need initialization |
|
473 //uGame does not need initialization |
|
474 uGears.initModule; |
478 uGears.initModule; |
475 uInputHandler.initModule; |
479 uInputHandler.initModule; //stub |
476 //uLandGraphics does not need initialization |
480 uMisc.initModule; |
477 //uLandObjects does not need initialization |
481 uLandTexture.initModule; //stub |
478 //uLandTemplates does not need initialization |
|
479 //uLocale does not need initialization |
|
480 uScript.initModule; |
482 uScript.initModule; |
481 uSound.initModule; |
483 uSound.initModule; |
482 uStats.initModule; |
484 uStats.initModule; |
483 uStore.initModule; |
485 uStore.initModule; |
484 uTeams.initModule; |
486 uTeams.initModule; |
485 uVisualGears.initModule; |
487 uVisualGears.initModule; |
486 uWorld.initModule; |
488 uWorld.initModule; |
487 uCaptions.initModule; |
|
488 end; |
489 end; |
489 end; |
490 end; |
490 |
491 |
491 procedure freeEverything (complete:boolean); |
492 procedure freeEverything (complete:boolean); |
492 begin |
493 begin |
493 if complete then |
494 if complete then |
494 begin |
495 begin |
495 WriteLnToConsole('Freeing resources...'); |
496 WriteLnToConsole('Freeing resources...'); |
496 uAI.freeModule; |
497 uAI.freeModule; // AI things need to be freed first |
|
498 uAIMisc.freeModule; //stub |
497 uAILandMarks.freeModule; |
499 uAILandMarks.freeModule; |
498 uAIMisc.freeModule; //stub |
|
499 uCaptions.freeModule; |
500 uCaptions.freeModule; |
500 uWorld.freeModule; |
501 uWorld.freeModule; |
501 uVisualGears.freeModule; |
502 uVisualGears.freeModule; |
502 uTeams.freeModule; |
503 uTeams.freeModule; |
503 uInputHandler.freeModule; |
504 uInputHandler.freeModule; |
504 uStats.freeModule; //stub |
505 uStats.freeModule; //stub |
505 uSound.freeModule; |
506 uSound.freeModule; |
506 uScript.freeModule; |
507 uScript.freeModule; |
507 //uRandom does not need to be freed |
508 uMisc.freeModule; |
508 //uLocale does not need to be freed |
|
509 //uLandTemplates does not need to be freed |
|
510 uLandTexture.freeModule; |
509 uLandTexture.freeModule; |
511 //uLandObjects does not need to be freed |
|
512 //uLandGraphics does not need to be freed |
|
513 uGears.freeModule; |
510 uGears.freeModule; |
514 //uGame does not need to be freed |
|
515 //uFloat does not need to be freed |
|
516 uCollisions.freeModule; //stub |
511 uCollisions.freeModule; //stub |
517 uChat.freeModule; |
512 uChat.freeModule; |
518 uAmmos.freeModule; |
513 uAmmos.freeModule; |
519 //uAIAmmoTests does not need to be freed |
514 uStore.freeModule; // closes SDL |
520 //uAIActions does not need to be freed |
|
521 uStore.freeModule; |
|
522 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.freeModule;{$ENDIF} |
515 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.freeModule;{$ENDIF} |
|
516 {$IFDEF USE_TOUCH_INTERFACE}uTouch.freeModule;{$ENDIF} //stub |
|
517 {$IFDEF ANDROID}GLUnit.freeModule;{$ENDIF} |
523 end; |
518 end; |
524 |
519 |
525 uIO.freeModule; |
520 uIO.freeModule; |
526 uLand.freeModule; |
521 uLand.freeModule; |
527 uLandPainted.freeModule; |
522 uLandPainted.freeModule; |
528 |
523 |
529 uCommandHandlers.freeModule; |
524 uCommandHandlers.freeModule; |
530 uCommands.freeModule; |
525 uCommands.freeModule; |
531 uConsole.freeModule; |
526 uConsole.freeModule; // closes stdout |
532 uVariables.freeModule; |
527 uVariables.freeModule; |
533 uUtils.freeModule; |
528 uUtils.freeModule; // closes debug file |
534 uMisc.freeModule; // uMisc closes the debug log. |
529 end; |
535 end; |
530 |
536 |
531 //////////////////////////////////////////////////////////////////////////////// |
537 ///////////////////////// |
|
538 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF}; |
532 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF}; |
539 var Preview: TPreview; |
533 var Preview: TPreview; |
540 begin |
534 begin |
|
535 {$IFDEF HWLIBRARY} |
541 initEverything(false); |
536 initEverything(false); |
542 {$IFDEF HWLIBRARY} |
|
543 WriteLnToConsole('Preview connecting on port ' + inttostr(port)); |
537 WriteLnToConsole('Preview connecting on port ' + inttostr(port)); |
544 ipcPort:= port; |
538 ipcPort:= port; |
545 InitStepsFlags:= cifRandomize; |
539 InitStepsFlags:= cifRandomize; |
546 {$ENDIF} |
540 {$ENDIF} |
547 InitIPC; |
541 InitIPC; |
581 Write(stdout, ParamStr(i) + ' '); |
575 Write(stdout, ParamStr(i) + ' '); |
582 |
576 |
583 WriteLn(stdout, ''); |
577 WriteLn(stdout, ''); |
584 end; |
578 end; |
585 |
579 |
586 //////////////////// |
580 //////////////////////////////////////////////////////////////////////////////// |
587 {$INCLUDE "ArgParsers.inc"} |
581 {$INCLUDE "ArgParsers.inc"} |
588 |
582 |
589 procedure GetParams; |
583 procedure GetParams; |
590 begin |
584 begin |
591 if (ParamCount < 3) then |
585 if (ParamCount < 3) then |
592 GameType:= gmtSyntax |
586 GameType:= gmtSyntax |
593 else |
587 else |
594 if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then |
588 if (ParamCount = 3) and (ParamStr(3) = 'landpreview') then |
595 internalSetGameTypeLandPreviewFromParameters() |
589 begin |
596 else if ParamCount = cDefaultParamNum then |
590 initEverything(false); |
597 internalStartGameWithParameters() |
591 ipcPort:= StrToInt(ParamStr(2)); |
|
592 GameType:= gmtLandPreview; |
|
593 exit; |
|
594 end |
|
595 else |
|
596 begin |
|
597 initEverything(true); |
|
598 if (ParamCount = 3) and (ParamStr(3) = '--stats-only') then |
|
599 playReplayFileWithParameters() |
|
600 else |
|
601 if ParamCount = cDefaultParamNum then |
|
602 internalStartGameWithParameters() |
598 {$IFDEF USE_VIDEO_RECORDING} |
603 {$IFDEF USE_VIDEO_RECORDING} |
599 else if ParamCount = cVideorecParamNum then |
604 else if ParamCount = cVideorecParamNum then |
600 internalStartVideoRecordingWithParameters() |
605 internalStartVideoRecordingWithParameters() |
601 {$ENDIF} |
606 {$ENDIF} |
602 else |
607 else |
603 playReplayFileWithParameters(); |
608 playReplayFileWithParameters(); |
|
609 end |
604 end; |
610 end; |
605 |
611 |
606 //////////////////////////////////////////////////////////////////////////////// |
612 //////////////////////////////////////////////////////////////////////////////// |
607 /////////////////////////////// m a i n //////////////////////////////////////// |
613 /////////////////////////////// m a i n //////////////////////////////////////// |
608 //////////////////////////////////////////////////////////////////////////////// |
614 //////////////////////////////////////////////////////////////////////////////// |