hedgewars/hwengine.pas
changeset 10175 c92668840ea8
parent 10162 38dbf26475d8
child 10176 ea022e9483c2
equal deleted inserted replaced
10174:710ffaae7d59 10175:c92668840ea8
    37      {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF}
    37      {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF}
    38      {$IFDEF ANDROID}, GLUnit{$ENDIF}
    38      {$IFDEF ANDROID}, GLUnit{$ENDIF}
    39      ;
    39      ;
    40 
    40 
    41 {$IFDEF HWLIBRARY}
    41 {$IFDEF HWLIBRARY}
       
    42 procedure RunEngine(argc: LongInt; argv: PPChar); cdecl; export;
       
    43 
    42 procedure preInitEverything();
    44 procedure preInitEverything();
    43 procedure initEverything(complete:boolean);
    45 procedure initEverything(complete:boolean);
    44 procedure freeEverything(complete:boolean);
    46 procedure freeEverything(complete:boolean);
    45 procedure Game(argc: LongInt; argv: PPChar); cdecl; export;
       
    46 procedure GenLandPreview(port: Longint); cdecl; export;
       
    47 
    47 
    48 implementation
    48 implementation
    49 {$ELSE}
    49 {$ELSE}
    50 procedure preInitEverything(); forward;
    50 procedure preInitEverything(); forward;
    51 procedure initEverything(complete:boolean); forward;
    51 procedure initEverything(complete:boolean); forward;
   322     StopVideoRecording();
   322     StopVideoRecording();
   323 end;
   323 end;
   324 {$ENDIF}
   324 {$ENDIF}
   325 
   325 
   326 ///////////////////////////////////////////////////////////////////////////////
   326 ///////////////////////////////////////////////////////////////////////////////
   327 procedure Game{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar); cdecl; export{$ENDIF};
   327 procedure Game;
   328 //var p: TPathType;
   328 //var p: TPathType;
   329 var s: shortstring;
   329 var s: shortstring;
   330     i: LongInt;
   330     i: LongInt;
   331 begin
   331 begin
   332 {$IFDEF HWLIBRARY}
       
   333     preInitEverything();
       
   334     parseCommandLine(argc, argv);
       
   335 {$ENDIF}
       
   336     initEverything(true);
   332     initEverything(true);
   337     WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString +
   333     WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString +
   338                      ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion));
   334                      ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion));
   339     AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"');
   335     AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"');
   340     AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"');
   336     AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"');
   528     uPhysFSLayer.freeModule;
   524     uPhysFSLayer.freeModule;
   529     uScript.freeModule;
   525     uScript.freeModule;
   530 end;
   526 end;
   531 
   527 
   532 ///////////////////////////////////////////////////////////////////////////////
   528 ///////////////////////////////////////////////////////////////////////////////
   533 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
   529 procedure GenLandPreview;
   534 var Preview: TPreviewAlpha;
   530 var Preview: TPreviewAlpha;
   535 begin
   531 begin
   536     initEverything(false);
   532     initEverything(false);
   537 {$IFDEF HWLIBRARY}
   533 
   538     WriteLnToConsole('Preview connecting on port ' + inttostr(port));
       
   539     ipcPort:= port;
       
   540     InitStepsFlags:= cifRandomize;
       
   541 {$ENDIF}
       
   542     InitIPC;
   534     InitIPC;
   543     IPCWaitPongEvent;
   535     IPCWaitPongEvent;
   544     TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   536     TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   545 
   537 
   546     ScriptOnPreviewInit;
   538     ScriptOnPreviewInit;
   550     SendIPCRaw(@MaxHedgehogs, sizeof(byte));
   542     SendIPCRaw(@MaxHedgehogs, sizeof(byte));
   551     WriteLnToConsole('Preview sent, disconnect');
   543     WriteLnToConsole('Preview sent, disconnect');
   552     freeEverything(false);
   544     freeEverything(false);
   553 end;
   545 end;
   554 
   546 
   555 {$IFNDEF HWLIBRARY}
   547 {$IFDEF HWLIBRARY}
       
   548 procedure RunEngine(argc: LongInt; argv: PPChar); cdecl; export;
       
   549 begin
       
   550     operatingsystem_parameter_argc:= argc;
       
   551     operatingsystem_parameter_argv:= argv;
       
   552 {$ELSE}
       
   553 begin
       
   554 {$ENDIF}
   556 
   555 
   557 ///////////////////////////////////////////////////////////////////////////////
   556 ///////////////////////////////////////////////////////////////////////////////
   558 /////////////////////////////////// m a i n ///////////////////////////////////
   557 /////////////////////////////////// m a i n ///////////////////////////////////
   559 ///////////////////////////////////////////////////////////////////////////////
   558 ///////////////////////////////////////////////////////////////////////////////
   560 begin
       
   561 {$IFDEF PAS2C}
   559 {$IFDEF PAS2C}
   562     // workaround for pascal's ParamStr and ParamCount
   560     // workaround for pascal's ParamStr and ParamCount
   563     init(argc, argv);
   561     init(argc, argv);
   564 {$ENDIF}
   562 {$ENDIF}
   565     preInitEverything();
   563     preInitEverything();
   566     cTagsMask:= htTeamName or htName or htHealth; // this one doesn't fit nicely w/ reset of other variables. suggestions welcome
   564 
   567     GetParams();
   565     GetParams();
   568 
   566 
   569     if GameType = gmtLandPreview then
   567     if GameType = gmtLandPreview then
   570         GenLandPreview()
   568         GenLandPreview()
   571     else if GameType <> gmtSyntax then
   569     else if GameType <> gmtSyntax then
   572         Game();
   570         Game();
   573 
   571 
   574     // return 1 when engine is not called correctly
   572     // return 1 when engine is not called correctly
   575     {$IFDEF PAS2C}
   573     {$IFDEF PAS2C OR HWLIBRARY}
   576     exit(LongInt(GameType = gmtSyntax));
   574     exit(LongInt(GameType = gmtSyntax));
   577     {$ELSE}
   575     {$ELSE}
   578     halt(LongInt(GameType = gmtSyntax));
   576     halt(LongInt(GameType = gmtSyntax));
   579     {$ENDIF}
   577     {$ENDIF}
   580 
   578 
   581 {$ENDIF}
   579 {$IFDEF HWLIBRARY}
       
   580 end;
       
   581 {$ENDIF}
       
   582 
   582 end.
   583 end.