# HG changeset patch # User Xeli # Date 1308695911 -7200 # Node ID 22c1f4833a863cdf4f9d4104566fd9d294542a23 # Parent 34abd278344ef02031fd102fe83b64edf3b86725 First commit.. diff -r 34abd278344e -r 22c1f4833a86 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/SDLh.pas Wed Jun 22 00:38:31 2011 +0200 @@ -35,13 +35,15 @@ {$ENDIF} {$IFDEF UNIX} - {$IFNDEF DARWIN} + {$IFNDEF DARWIN} {$linklib c} {$ENDIF} {$IFDEF HAIKU} {$linklib root} {$ELSE} - {$linklib pthread} + {$IFNDEF ANDROID} + {$linklib pthread} + {$ENDIF} {$ENDIF} {$ENDIF} @@ -74,18 +76,26 @@ SDL_ImageLibName = 'SDL_image.dll'; SDL_NetLibName = 'SDL_net.dll'; {$ELSE} - {$IFDEF DARWIN} + {$IFDEF DARWINN} SDLLibName = 'SDL'; SDL_TTFLibName = 'SDL_ttf'; SDL_MixerLibName = 'SDL_mixer'; SDL_ImageLibName = 'SDL_image'; SDL_NetLibName = 'SDL_net'; {$ELSE} - SDLLibName = 'libSDL.so'; - SDL_TTFLibName = 'libSDL_ttf.so'; - SDL_MixerLibName = 'libSDL_mixer.so'; - SDL_ImageLibName = 'libSDL_image.so'; - SDL_NetLibName = 'libSDL_net.so'; + {$IFDEF ANDROID} + SDLLibName = 'SDL'; + SDL_TTFLibName = 'libSDL_ttf.so'; + SDL_MixerLibName = 'libSDL_mixer.so'; + SDL_ImageLibName = 'libSDL_image.so'; + SDL_NetLibName = 'libSDL_net.so'; + {$ELSE} + SDLLibName = 'SDL'; + SDL_TTFLibName = 'libSDL_ttf.so'; + SDL_MixerLibName = 'libSDL_mixer.so'; + SDL_ImageLibName = 'libSDL_image.so'; + SDL_NetLibName = 'libSDL_net.so'; + {$ENDIF} {$ENDIF} {$ENDIF} @@ -345,7 +355,8 @@ alpha: Byte; {$ENDIF} end; - + + SDL_eventaction = (SDL_ADDEVENT = 0, SDL_PEEPEVENT, SDL_GETEVENT); PSDL_Surface = ^TSDL_Surface; TSDL_Surface = record @@ -473,7 +484,7 @@ type_: LongInt; windowID: LongInt; padding1, padding2: byte; - x, y, z, xrel, yrel : LongInt; + x, y, z,xrel, yrel : LongInt; pressure, pressure_max, pressure_min, rotation, tilt, cursor: LongInt; {$ELSE} @@ -784,8 +795,13 @@ function SDL_GetNumMice: LongInt; cdecl; external SDLLibName; function SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): boolean; cdecl; external SDLLibName; -procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName; -function SDL_SetHint(name, value: PChar): boolean; cdecl; external SDLLibName; + +procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName ; + +function SDL_SetHint(name, value: PChar): boolean; cdecl; external SDLLibName; + +function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; minType, maxType: LongInt): LongInt; cdecl; external SDLLibName; + {$ENDIF} function SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName; @@ -850,7 +866,11 @@ function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; - +(* +function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; +function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; +function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; +*) function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName; procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName; @@ -981,6 +1001,17 @@ (PByteArray(buf)^[1] shl 16) or (PByteArray(buf)^[0] shl 24) end; - +(* +function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; +begin +TTF_RenderUTF8_Solid:= SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, RMask, GMask, BMask, AMask); +end; +function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; +begin +TTF_RenderUTF8_Blended:= SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, RMask, GMask, BMask, AMask); +end; +function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; +begin +TTF_RenderUTF8_Shaded:= SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, RMask, GMask, BMask, AMask); +end;*) end. - diff -r 34abd278344e -r 22c1f4833a86 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/hwengine.pas Wed Jun 22 00:38:31 2011 +0200 @@ -31,12 +31,12 @@ uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, - sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted; + sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted {$IFDEF ANDROID}, log in 'log.pas', GLUnit{$ENDIF}; {$IFDEF HWLIBRARY} procedure initEverything(complete:boolean); procedure freeEverything(complete:boolean); -procedure Game(gameArgs: PPChar); cdecl; export; +procedure Game(); cdecl; export; implementation {$ELSE} @@ -141,24 +141,25 @@ /////////////////// procedure MainLoop; -{$WARNINGS OFF} -// disable "Some fields weren't initialized" warning -const event: TSDL_Event = (); -{$WARNINGS ON} var PrevTime, CurrTime: Longword; + event: TSDL_Event; begin PrevTime:= SDL_GetTicks; while isTerminated = false do begin - - while SDL_PollEvent(@event) <> 0 do +{$IFDEF ANDROID} + SDL_PumpEvents(); + while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do +{$ELSE} + while SDL_PollEvent(@event) <> 0 do +{$ENDIF} begin - case event.type_ of + case event.type_ of SDL_KEYDOWN: if GameState = gsChat then {$IFDEF SDL13} // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 KeyPressChat(event.key.keysym.sym); - SDL_WINDOWEVENT: + SDL_WINDOWEVENT: if event.window.event = SDL_WINDOWEVENT_SHOWN then cHasFocus:= true; {$ELSE} @@ -201,7 +202,7 @@ /////////////// {$IFDEF HWLIBRARY} -procedure Game(gameArgs: PPChar); cdecl; export; +procedure Game(); cdecl; export; {$ELSE} procedure Game; {$ENDIF} @@ -213,20 +214,20 @@ cBits:= 32; cFullScreen:= false; cTimerInterval:= 8; - PathPrefix:= 'Data'; - UserPathPrefix:= '.'; + PathPrefix:= '/sdcard/Data'; cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF}; - val(gameArgs[0], ipcPort); - val(gameArgs[1], cScreenWidth); - val(gameArgs[2], cScreenHeight); - val(gameArgs[3], cReducedQuality); - cLocaleFName:= gameArgs[4]; - UserNick:= gameArgs[5]; - isSoundEnabled:= gameArgs[6] = '1'; - isMusicEnabled:= gameArgs[7] = '1'; - cAltDamage:= gameArgs[8] = '1'; - val(gameArgs[9], rotationQt); - recordFileName:= gameArgs[10]; + val('0', ipcPort); + val('800', cScreenWidth); + val('480', cScreenHeight); + //val('1', cReducedQuality); + cReducedQuality := $00000000; + cLocaleFName:= 'null'; + UserNick:= 'xeli'; + isSoundEnabled:= '0' = '1'; + isMusicEnabled:= '0' = '1'; + cAltDamage:= '1' = '1'; + val('0', rotationQt); + recordFileName:= '/sdcard/bla.hwd'; cStereoMode:= smNone; {$ENDIF} @@ -235,16 +236,10 @@ WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); AddFileLog('Prefix: "' + PathPrefix +'"'); - AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); for i:= 0 to ParamCount do AddFileLog(inttostr(i) + ': ' + ParamStr(i)); for p:= Succ(Low(TPathType)) to High(TPathType) do - if (p <> ptMapCurrent) and (p <> ptData) then UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p]; - - UserPathz[ptData]:= UserPathPrefix + '/Data'; - - for p:= Succ(Low(TPathType)) to High(TPathType) do if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; WriteToConsole('Init SDL... '); @@ -270,7 +265,6 @@ InitKbdKeyTable(); AddProgress(); - LoadLocale(UserPathz[ptLocale] + '/en.txt'); // Do an initial load with english LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5) else cLocale := Copy(cLocaleFName,1,2); @@ -278,12 +272,8 @@ begin // Try two letter locale first before trying specific locale overrides if (Length(cLocale) > 2) and (Copy(cLocale,1,2) <> 'en') then - begin - LoadLocale(UserPathz[ptLocale] + '/' + Copy(cLocale,1,2)+'.txt'); - LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocale,1,2)+'.txt') - end; - LoadLocale(UserPathz[ptLocale] + '/' + cLocaleFName); - LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName) + LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocale,1,2)+'.txt'); + LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); end else cLocale := 'en'; @@ -341,7 +331,10 @@ if complete then begin - uAI.initModule; + {$IFDEF ANDROID} + GLUnit.init; + {$ENDIF} + uAI.initModule; //uAIActions does not need initialization //uAIAmmoTests does not need initialization uAIMisc.initModule; @@ -442,7 +435,7 @@ begin WriteLn('Wrong argument format: correct configurations is'); WriteLn(); - WriteLn(' hwengine [options]'); + WriteLn(' hwengine [options]'); WriteLn(); WriteLn('where [options] must be specified either as:'); WriteLn(' --set-video [screen width] [screen height] [color dept]'); @@ -465,10 +458,10 @@ procedure GetParams; begin - if (ParamCount < 3) then + if (ParamCount < 2) then GameType:= gmtSyntax else - if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then + if (ParamCount = 3) then internalSetGameTypeLandPreviewFromParameters() else if (ParamCount = cDefaultParamNum) then diff -r 34abd278344e -r 22c1f4833a86 hedgewars/options.inc --- a/hedgewars/options.inc Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/options.inc Wed Jun 22 00:38:31 2011 +0200 @@ -27,11 +27,22 @@ {$DEFINE GLunit:=GL} +{$IFDEF ANDROID} + {$DEFINE SDL13} + {$DEFINE HWLIBRARY} + {$DEFINE S3D_DISABLED} + {$DEFINE LUA_DISABLED} + {$DEFINE GLunit:=gles11} + {$DEFINE DEBUGFILE} + {$DEFINE MOBILE} +{$ENDIF} + {$IFDEF IPHONEOS} {$DEFINE SDL13} {$DEFINE HWLIBRARY} {$DEFINE S3D_DISABLED} {$DEFINE GLunit:=gles11} + {$DEFINE MOBILE} {$ENDIF} {$DEFINE DEBUGFILE} diff -r 34abd278344e -r 22c1f4833a86 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/uAI.pas Wed Jun 22 00:38:31 2011 +0200 @@ -30,7 +30,7 @@ implementation uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions, - uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes, + uAmmos, SysUtils{$IFDEF UNIX}{$IFNDEF ANDROID}, cthreads{$ENDIF}{$ENDIF}, uTypes, uVariables, uCommands, uUtils, uDebug; var BestActions: TActions; diff -r 34abd278344e -r 22c1f4833a86 hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/uConsole.pas Wed Jun 22 00:38:31 2011 +0200 @@ -26,9 +26,10 @@ procedure WriteToConsole(s: shortstring); procedure WriteLnToConsole(s: shortstring); function GetLastConsoleLine: shortstring; +function ShortStringAsPChar(var s: shortstring): PChar; implementation -uses Types, uVariables, uUtils; +uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF}; const cLineWidth: LongInt = 0; cLinesCount = 8; @@ -52,6 +53,9 @@ done: boolean; begin {$IFNDEF NOCONSOLE} + {$IFDEF ANDROID} + Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar(s)); +{$ELSE} AddFileLog('[Con] ' + s); Write(stderr, s); done:= false; @@ -70,18 +74,21 @@ done:= (Length(s) = 0); end; {$ENDIF} +{$ENDIF} end; procedure WriteLnToConsole(s: shortstring); begin {$IFNDEF NOCONSOLE} WriteToConsole(s); +{$IFNDEF ANDROID} WriteLn(stderr); inc(CurrLine); if CurrLine = cLinesCount then CurrLine:= 0; PByte(@ConsoleLines[CurrLine].s)^:= 0 {$ENDIF} +{$ENDIF} end; @@ -118,4 +125,12 @@ end; +Function ShortStringAsPChar(var S: ShortString) : PChar; +Var NewString : String; +Begin +if Length(S) = High(S) then Dec(S[0]); +s[Ord(Length(s))+1] := #0; +Result := @S[1]; +End; + end. diff -r 34abd278344e -r 22c1f4833a86 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/uLand.pas Wed Jun 22 00:38:31 2011 +0200 @@ -1358,7 +1358,7 @@ if digest = '' then digest:= s else - TryDo(s = digest, 'Different maps generated, sorry', true); +// TryDo(s = digest, 'Different maps generated, sorry', true); end; procedure chSendLandDigest(var s: shortstring); diff -r 34abd278344e -r 22c1f4833a86 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/uStore.pas Wed Jun 22 00:38:31 2011 +0200 @@ -531,7 +531,7 @@ {$ENDIF} begin -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); {$ELSE} @@ -950,7 +950,7 @@ y:= SDL_WINDOWPOS_CENTERED_MASK; flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN; -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} // make the sdl window appear on the second monitor when present x:= x or (SDL_GetNumVideoDisplays() - 1); y:= y or (SDL_GetNumVideoDisplays() - 1); diff -r 34abd278344e -r 22c1f4833a86 hedgewars/uUtils.pas --- a/hedgewars/uUtils.pas Tue Jun 21 17:28:53 2011 -0400 +++ b/hedgewars/uUtils.pas Wed Jun 22 00:38:31 2011 +0200 @@ -21,7 +21,7 @@ unit uUtils; interface -uses uTypes, uFloat, GLunit; +uses uTypes, uFloat, GLunit, uConsole; procedure SplitBySpace(var a, b: shortstring); procedure SplitByChar(var a, b: ansistring; c: char); @@ -261,10 +261,15 @@ procedure AddFileLog(s: shortstring); begin s:= s; +WriteToConsole(s); {$IFDEF DEBUGFILE} +{$IFDEF ANDROID} + WriteToConsole(s); +{$ELSE} writeln(f, GameTicks: 6, ': ', s); flush(f) {$ENDIF} +{$ENDIF} end;