36 {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF} |
36 {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF} |
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 var isInternal: Boolean; |
41 |
42 |
42 {$IFDEF HWLIBRARY} |
43 {$IFDEF HWLIBRARY} |
43 procedure preInitEverything(); |
44 procedure preInitEverything(); |
44 procedure initEverything(complete:boolean); |
45 procedure initEverything(complete:boolean); |
45 procedure freeEverything(complete:boolean); |
46 procedure freeEverything(complete:boolean); |
46 procedure Game(gameArgs: PPChar); cdecl; export; |
47 procedure Game(argc: LongInt; argv: PPChar); cdecl; export; |
47 procedure GenLandPreview(port: Longint); cdecl; export; |
48 procedure GenLandPreview(port: Longint); cdecl; export; |
48 |
49 |
49 implementation |
50 implementation |
50 {$ELSE} |
51 {$ELSE} |
51 procedure preInitEverything(); forward; |
52 procedure preInitEverything(); forward; |
52 procedure initEverything(complete:boolean); forward; |
53 procedure initEverything(complete:boolean); forward; |
53 procedure freeEverything(complete:boolean); forward; |
54 procedure freeEverything(complete:boolean); forward; |
54 {$ENDIF} |
55 {$ENDIF} |
|
56 |
|
57 {$INCLUDE "ArgParsers.inc"} |
55 |
58 |
56 /////////////////////////////////////////////////////////////////////////////// |
59 /////////////////////////////////////////////////////////////////////////////// |
57 function DoTimer(Lag: LongInt): boolean; |
60 function DoTimer(Lag: LongInt): boolean; |
58 var s: shortstring; |
61 var s: shortstring; |
59 begin |
62 begin |
259 SDL_QUITEV: |
262 SDL_QUITEV: |
260 isTerminated:= true |
263 isTerminated:= true |
261 end; //end case event.type_ of |
264 end; //end case event.type_ of |
262 end; //end while SDL_PollEvent(@event) <> 0 do |
265 end; //end while SDL_PollEvent(@event) <> 0 do |
263 |
266 |
|
267 if (CursorMovementX <> 0) or (CursorMovementY <> 0) then |
|
268 handlePositionUpdate(CursorMovementX * cameraKeyboardSpeed, CursorMovementY * cameraKeyboardSpeed); |
|
269 |
264 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and |
270 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and |
265 ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then |
271 ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then |
266 begin |
272 begin |
267 cScreenResizeDelay:= 0; |
273 cScreenResizeDelay:= 0; |
268 cScreenWidth:= cNewScreenWidth; |
274 cWindowedWidth:= cNewScreenWidth; |
269 cScreenHeight:= cNewScreenHeight; |
275 cWindowedHeight:= cNewScreenHeight; |
|
276 cScreenWidth:= cWindowedWidth; |
|
277 cScreenHeight:= cWindowedHeight; |
270 |
278 |
271 ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true); |
279 ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true); |
272 WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight)); |
280 WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight)); |
273 ScriptOnScreenResize(); |
281 ScriptOnScreenResize(); |
274 InitCameraBorders(); |
282 InitCameraBorders(); |
275 InitTouchInterface(); |
283 InitTouchInterface(); |
|
284 SendIPC('W' + IntToStr(cScreenWidth) + 'x' + IntToStr(cScreenHeight)); |
276 end; |
285 end; |
277 |
286 |
278 CurrTime:= SDL_GetTicks(); |
287 CurrTime:= SDL_GetTicks(); |
279 if PrevTime + longword(cTimerInterval) <= CurrTime then |
288 if PrevTime + longword(cTimerInterval) <= CurrTime then |
280 begin |
289 begin |
318 StopVideoRecording(); |
327 StopVideoRecording(); |
319 end; |
328 end; |
320 {$ENDIF} |
329 {$ENDIF} |
321 |
330 |
322 /////////////////////////////////////////////////////////////////////////////// |
331 /////////////////////////////////////////////////////////////////////////////// |
323 procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF}; |
332 procedure Game{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar); cdecl; export{$ENDIF}; |
324 var p: TPathType; |
333 var p: TPathType; |
325 s: shortstring; |
334 s: shortstring; |
326 i: LongInt; |
335 i: LongInt; |
327 begin |
336 begin |
328 {$IFDEF HWLIBRARY} |
337 {$IFDEF HWLIBRARY} |
329 preInitEverything(); |
338 preInitEverything(); |
330 cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF}; |
339 parseCommandLine(argc, argv); |
331 ipcPort:= StrToInt(gameArgs[0]); |
|
332 cScreenWidth:= StrToInt(gameArgs[1]); |
|
333 cScreenHeight:= StrToInt(gameArgs[2]); |
|
334 cReducedQuality:= StrToInt(gameArgs[3]); |
|
335 cLocaleFName:= gameArgs[4]; |
|
336 UserNick:= gameArgs[5]; |
|
337 SetSound(gameArgs[6] = '1'); |
|
338 SetMusic(gameArgs[7] = '1'); |
|
339 cAltDamage:= gameArgs[8] = '1'; |
|
340 PathPrefix:= gameArgs[9]; |
|
341 UserPathPrefix:= '../Documents'; |
|
342 recordFileName:= gameArgs[10]; |
|
343 {$ENDIF} |
340 {$ENDIF} |
344 initEverything(true); |
341 initEverything(true); |
345 |
|
346 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
342 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
347 AddFileLog('Prefix: "' + PathPrefix +'"'); |
343 AddFileLog('Prefix: "' + PathPrefix +'"'); |
348 AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); |
344 AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); |
349 |
345 |
350 for i:= 0 to ParamCount do |
346 for i:= 0 to ParamCount do |
542 end; |
538 end; |
543 |
539 |
544 {$IFNDEF HWLIBRARY} |
540 {$IFNDEF HWLIBRARY} |
545 |
541 |
546 /////////////////////////////////////////////////////////////////////////////// |
542 /////////////////////////////////////////////////////////////////////////////// |
547 {$INCLUDE "ArgParsers.inc"} |
|
548 |
|
549 procedure GetParams; |
|
550 var startIndex,tmpInt: LongInt; |
|
551 debug: string; |
|
552 begin |
|
553 (* |
|
554 tmpInt:=0; |
|
555 while (tmpInt <= ParamCount) do |
|
556 begin |
|
557 WriteLn(stdout,inttostr(tmpInt) + ': ' + ParamStr(tmpInt)); |
|
558 inc(tmpInt); |
|
559 end; |
|
560 *) |
|
561 |
|
562 if (ParamCount = 3) and (ParamStr(3) = 'landpreview') then |
|
563 begin |
|
564 PathPrefix := ParamStr(1); |
|
565 ipcPort := StrToInt(ParamStr(2)); |
|
566 GameType := gmtLandPreview; |
|
567 exit; |
|
568 end; |
|
569 |
|
570 //TODO: prepend something so that we can use a cDefaultParamNum of parameters |
|
571 if ParamCount = cDefaultParamNum then |
|
572 begin |
|
573 internalStartGameWithParameters(); |
|
574 exit; |
|
575 end |
|
576 {$IFDEF USE_VIDEO_RECORDING} |
|
577 else if ParamCount = cVideorecParamNum then |
|
578 begin |
|
579 internalStartVideoRecordingWithParameters(); |
|
580 exit; |
|
581 end |
|
582 {$ENDIF}; |
|
583 |
|
584 if (ParamCount < 2) then |
|
585 begin |
|
586 DisplayUsage(); |
|
587 GameType:= gmtSyntax; |
|
588 end |
|
589 else |
|
590 begin |
|
591 if (ParamCount >= 2) then |
|
592 begin |
|
593 UserPathPrefix := '.'; |
|
594 PathPrefix := ParamStr(1); |
|
595 recordFileName := ParamStr(2); |
|
596 startIndex := 3; |
|
597 end; |
|
598 |
|
599 playReplayFileWithParameters(startIndex); |
|
600 end; |
|
601 (* |
|
602 WriteLn(stdout,recordFilename); |
|
603 WriteLn(stdout,PathPrefix); |
|
604 WriteLn(stdout,UserPathPrefix); |
|
605 *) |
|
606 end; |
|
607 |
|
608 /////////////////////////////////////////////////////////////////////////////// |
|
609 /////////////////////////////////// m a i n /////////////////////////////////// |
543 /////////////////////////////////// m a i n /////////////////////////////////// |
610 /////////////////////////////////////////////////////////////////////////////// |
544 /////////////////////////////////////////////////////////////////////////////// |
611 begin |
545 begin |
612 preInitEverything(); |
546 preInitEverything(); |
613 GetParams(); |
547 GetParams(); |
614 |
548 |
615 if GameType = gmtLandPreview then |
549 if GameType = gmtLandPreview then |
616 GenLandPreview() |
550 GenLandPreview() |
617 else if GameType = gmtSyntax then |
551 else if GameType <> gmtSyntax then |
618 //Exit cleanly |
552 Game(); |
619 else Game(); |
|
620 |
553 |
621 // return 1 when engine is not called correctly |
554 // return 1 when engine is not called correctly |
622 halt(LongInt(GameType = gmtSyntax)); |
555 halt(LongInt(GameType = gmtSyntax)); |
623 {$ENDIF} |
556 {$ENDIF} |
624 end. |
557 end. |