hedgewars/uStore.pas
branchphysfslayer
changeset 8520 1dedcc37bfe8
parent 8370 0c79946e96f8
child 8444 75db7bb8dce8
child 8838 aa2ffd427f6a
equal deleted inserted replaced
8056:d5d5e1698554 8520:1dedcc37bfe8
    31 procedure RenderHealth(var Hedgehog: THedgehog);
    31 procedure RenderHealth(var Hedgehog: THedgehog);
    32 procedure AddProgress;
    32 procedure AddProgress;
    33 procedure FinishProgress;
    33 procedure FinishProgress;
    34 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    34 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    35 
    35 
    36 // loads an image from the game's data files
    36 // loads an image from the games data files
    37 function  LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    37 function  LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    38 // like LoadDataImage but uses altPath as fallback-path if file not found/loadable in path
    38 // like LoadDataImage but uses altPath as fallback-path if file not found/loadable in path
    39 function  LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    39 function  LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    40 // like LoadDataImage but uses altFile as fallback-filename if file cannot be loaded
    40 // like LoadDataImage but uses altFile as fallback-filename if file cannot be loaded
    41 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    41 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    54 
    54 
    55 procedure WarpMouse(x, y: Word); inline;
    55 procedure WarpMouse(x, y: Word); inline;
    56 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    56 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    57 
    57 
    58 implementation
    58 implementation
    59 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands
    59 uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands
    60     , uPhysFSLayer
    60     , uPhysFSLayer
    61     , uDebug
    61     , uDebug
    62     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
    62     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
    63     {$IF NOT DEFINED(SDL13) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
    63     {$IF NOT DEFINED(SDL13) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
    64 
    64 
    69     SDLwindow: PSDL_Window;
    69     SDLwindow: PSDL_Window;
    70     SDLGLcontext: PSDL_GLContext;
    70     SDLGLcontext: PSDL_GLContext;
    71 {$ELSE}
    71 {$ELSE}
    72     SDLPrimSurface: PSDL_Surface;
    72     SDLPrimSurface: PSDL_Surface;
    73 {$ENDIF}
    73 {$ENDIF}
       
    74     squaresize : LongInt;
       
    75     numsquares : LongInt;
       
    76     ProgrTex: PTexture;
       
    77 
       
    78 const 
       
    79     cHHFileName = 'Hedgehog';
       
    80     cCHFileName = 'Crosshair';
    74 
    81 
    75 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    82 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    76 var w, h: LongInt;
    83 var w, h: LongInt;
    77     tmpsurf: PSDL_Surface;
    84     tmpsurf: PSDL_Surface;
    78     clr: TSDL_Color;
    85     clr: TSDL_Color;
   146     r, rr: TSDL_Rect;
   153     r, rr: TSDL_Rect;
   147     drY: LongInt;
   154     drY: LongInt;
   148     texsurf, flagsurf, iconsurf: PSDL_Surface;
   155     texsurf, flagsurf, iconsurf: PSDL_Surface;
   149     foundBot: boolean;
   156     foundBot: boolean;
   150 begin
   157 begin
       
   158     if cOnlyStats then exit;
   151 r.x:= 0;
   159 r.x:= 0;
   152 r.y:= 0;
   160 r.y:= 0;
   153 drY:= - 4;
   161 drY:= - 4;
   154 for t:= 0 to Pred(TeamsCount) do
   162 for t:= 0 to Pred(TeamsCount) do
   155     with TeamsArray[t]^ do
   163     with TeamsArray[t]^ do
   434 if not reload then
   442 if not reload then
   435     AddProgress;
   443     AddProgress;
   436 IMG_Quit();
   444 IMG_Quit();
   437 end;
   445 end;
   438 
   446 
   439 {$IF NOT DEFINED(S3D_DISABLED) OR DEFINED(USE_VIDEO_RECORDING)}
   447 {$IF DEFINED(USE_S3D_RENDERING) OR DEFINED(USE_VIDEO_RECORDING)}
   440 procedure CreateFramebuffer(var frame, depth, tex: GLuint);
   448 procedure CreateFramebuffer(var frame, depth, tex: GLuint);
   441 begin
   449 begin
   442     glGenFramebuffersEXT(1, @frame);
   450     glGenFramebuffersEXT(1, @frame);
   443     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
   451     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
   444     glGenRenderbuffersEXT(1, @depth);
   452     glGenRenderbuffersEXT(1, @depth);
   536         end;
   544         end;
   537 {$IFDEF USE_VIDEO_RECORDING}
   545 {$IFDEF USE_VIDEO_RECORDING}
   538     if defaultFrame <> 0 then
   546     if defaultFrame <> 0 then
   539         DeleteFramebuffer(defaultFrame, depthv, texv);
   547         DeleteFramebuffer(defaultFrame, depthv, texv);
   540 {$ENDIF}
   548 {$ENDIF}
   541 {$IFNDEF S3D_DISABLED}
   549 {$IFDEF USE_S3D_RENDERING}
   542     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   550     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
   543         begin
   551         begin
   544         DeleteFramebuffer(framel, depthl, texl);
   552         DeleteFramebuffer(framel, depthl, texl);
   545         DeleteFramebuffer(framer, depthr, texr);
   553         DeleteFramebuffer(framer, depthr, texr);
   546         end
   554         end
   547 {$ENDIF}
   555 {$ENDIF}
   573     end;
   581     end;
   574 
   582 
   575     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
   583     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
   576     begin
   584     begin
   577         SDL_FreeSurface(tmpsurf);
   585         SDL_FreeSurface(tmpsurf);
   578         OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
   586         OutError(msgFailedSize, ((not cOnlyStats) and ((imageFlags and ifCritical) <> 0)));
   579         // dummy surface to replace non-critical textures that failed to load due to their size
   587         // dummy surface to replace non-critical textures that failed to load due to their size
   580         LoadImage:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask);
   588         LoadImage:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask);
   581         exit;
   589         exit;
   582     end;
   590     end;
   583 
   591 
   595 function LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   603 function LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   596 var tmpsurf: PSDL_Surface;
   604 var tmpsurf: PSDL_Surface;
   597 begin
   605 begin
   598     // check for file in user dir (never critical)
   606     // check for file in user dir (never critical)
   599     tmpsurf:= LoadImage(cPathz[path] + '/' + filename, imageFlags);
   607     tmpsurf:= LoadImage(cPathz[path] + '/' + filename, imageFlags);
       
   608     
       
   609     LoadDataImage:= tmpsurf;
   600 end;
   610 end;
   601 
   611 
   602 
   612 
   603 function LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   613 function LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   604 var tmpsurf: PSDL_Surface;
   614 var tmpsurf: PSDL_Surface;
   802             AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
   812             AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
   803         end;
   813         end;
   804     end;
   814     end;
   805 {$ENDIF}
   815 {$ENDIF}
   806 
   816 
   807 {$IFNDEF S3D_DISABLED}
   817 {$IFDEF USE_S3D_RENDERING}
   808     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   818     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
   809     begin
   819     begin
   810         // prepare left and right frame buffers and associated textures
   820         // prepare left and right frame buffers and associated textures
   811         if glLoadExtension('GL_EXT_framebuffer_object') then
   821         if glLoadExtension('GL_EXT_framebuffer_object') then
   812             begin
   822             begin
   813             CreateFramebuffer(framel, depthl, texl);
   823             CreateFramebuffer(framel, depthl, texl);
   865 ////////////////////////////////////////////////////////////////////////////////
   875 ////////////////////////////////////////////////////////////////////////////////
   866 procedure AddProgress;
   876 procedure AddProgress;
   867 var r: TSDL_Rect;
   877 var r: TSDL_Rect;
   868     texsurf: PSDL_Surface;
   878     texsurf: PSDL_Surface;
   869 begin
   879 begin
       
   880     if cOnlyStats then exit;
   870     if Step = 0 then
   881     if Step = 0 then
   871     begin
   882     begin
   872         WriteToConsole(msgLoading + 'progress sprite: ');
   883         WriteToConsole(msgLoading + 'progress sprite: ');
   873         texsurf:= LoadDataImage(ptGraphics, 'Progress', ifCritical or ifTransparent);
   884         texsurf:= LoadDataImage(ptGraphics, 'Progress', ifCritical or ifTransparent);
   874 
   885 
   875         ProgrTex:= Surface2Tex(texsurf, false);
   886         ProgrTex:= Surface2Tex(texsurf, false);
   876 
   887 
   877         squaresize:= texsurf^.w shr 1;
   888         squaresize:= texsurf^.w shr 1;
   878         numsquares:= texsurf^.h div squaresize;
   889         numsquares:= texsurf^.h div squaresize;
   879         SDL_FreeSurface(texsurf);
   890         SDL_FreeSurface(texsurf);
   880 
   891         with mobileRecord do
   881         uMobile.GameLoading();
   892             if GameLoading <> nil then
       
   893                 GameLoading();
       
   894         
   882         end;
   895         end;
   883 
   896 
   884     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
   897     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
   885 
   898 
   886     glClear(GL_COLOR_BUFFER_BIT);
   899     glClear(GL_COLOR_BUFFER_BIT);
   899     inc(Step);
   912     inc(Step);
   900 end;
   913 end;
   901 
   914 
   902 procedure FinishProgress;
   915 procedure FinishProgress;
   903 begin
   916 begin
   904     uMobile.GameLoaded();
   917     with mobileRecord do
       
   918         if GameLoaded <> nil then
       
   919             GameLoaded();
   905     WriteLnToConsole('Freeing progress surface... ');
   920     WriteLnToConsole('Freeing progress surface... ');
   906     FreeTexture(ProgrTex);
   921     FreeTexture(ProgrTex);
   907     ProgrTex:= nil;
   922     ProgrTex:= nil;
   908     Step:= 0
   923     Step:= 0
   909 end;
   924 end;
  1119 var flags: Longword = 0;
  1134 var flags: Longword = 0;
  1120     reinit: boolean = false;
  1135     reinit: boolean = false;
  1121     {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
  1136     {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
  1122     {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
  1137     {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
  1123 begin
  1138 begin
       
  1139     if cOnlyStats then
       
  1140         begin
       
  1141         MaxTextureSize:= 1024;
       
  1142         exit
       
  1143         end;
  1124     if Length(s) = 0 then
  1144     if Length(s) = 0 then
  1125         cFullScreen:= (not cFullScreen)
  1145          cFullScreen:= (not cFullScreen)
       
  1146     else cFullScreen:= s = '1';
       
  1147     
       
  1148     if cFullScreen then
       
  1149         begin
       
  1150         cScreenWidth:= cFullscreenWidth;
       
  1151         cScreenHeight:= cFullscreenHeight;
       
  1152         end
  1126     else
  1153     else
  1127         cFullScreen:= s = '1';
  1154         begin
       
  1155         cScreenWidth:= cWindowedWidth;
       
  1156         cScreenHeight:= cWindowedHeight;
       
  1157         end;
  1128 
  1158 
  1129     AddFileLog('Preparing to change video parameters...');
  1159     AddFileLog('Preparing to change video parameters...');
  1130 {$IFDEF SDL13}
  1160 {$IFDEF SDL13}
  1131     if SDLwindow = nil then
  1161     if SDLwindow = nil then
  1132 {$ELSE}
  1162 {$ELSE}
  1200     flags:= flags or SDL_WINDOW_BORDERLESS;
  1230     flags:= flags or SDL_WINDOW_BORDERLESS;
  1201     {$ENDIF}
  1231     {$ENDIF}
  1202 
  1232 
  1203     if SDLwindow = nil then
  1233     if SDLwindow = nil then
  1204         if cFullScreen then
  1234         if cFullScreen then
  1205             SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN)
  1235             SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags or SDL_WINDOW_FULLSCREEN)
  1206         else
  1236         else
       
  1237             begin
  1207             SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
  1238             SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
       
  1239             end;
  1208     SDLTry(SDLwindow <> nil, true);
  1240     SDLTry(SDLwindow <> nil, true);
  1209 {$ELSE}
  1241 {$ELSE}
  1210     flags:= SDL_OPENGL or SDL_RESIZABLE;
  1242     flags:= SDL_OPENGL or SDL_RESIZABLE;
  1211     if cFullScreen then
  1243     if cFullScreen then
       
  1244         begin
  1212         flags:= flags or SDL_FULLSCREEN;
  1245         flags:= flags or SDL_FULLSCREEN;
  1213 
  1246         end;
  1214     if not cOnlyStats then
  1247     if not cOnlyStats then
  1215         begin
  1248         begin
  1216     {$IFDEF WIN32}
  1249     {$IFDEF WIN32}
  1217         s:= SDL_getenv('SDL_VIDEO_CENTERED');
  1250         s:= SDL_getenv('SDL_VIDEO_CENTERED');
  1218         SDL_putenv('SDL_VIDEO_CENTERED=1');
  1251         SDL_putenv('SDL_VIDEO_CENTERED=1');
  1219     {$ENDIF}
  1252     {$ENDIF}
  1220         SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
  1253         SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, 0, flags);
  1221         SDLTry(SDLPrimSurface <> nil, true);
  1254         SDLTry(SDLPrimSurface <> nil, true);
  1222     {$IFDEF WIN32}SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));{$ENDIF}
  1255     {$IFDEF WIN32}SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));{$ENDIF}
  1223         end;
  1256         end;
  1224 {$ENDIF}
  1257 {$ENDIF}
  1225 
  1258