396 |
396 |
397 procedure StoreLoad(reload: boolean); |
397 procedure StoreLoad(reload: boolean); |
398 var ii: TSprite; |
398 var ii: TSprite; |
399 ai: TAmmoType; |
399 ai: TAmmoType; |
400 tmpsurf, tmpoverlay: PSDL_Surface; |
400 tmpsurf, tmpoverlay: PSDL_Surface; |
401 i, y, imflags: LongInt; |
401 i, imflags: LongInt; |
402 keyConfirm, keyQuit: shortstring; |
402 keyConfirm, keyQuit: shortstring; |
403 begin |
403 begin |
404 AddFileLog('StoreLoad()'); |
404 AddFileLog('StoreLoad()'); |
405 |
405 |
406 if not cOnlyStats then |
406 if not cOnlyStats then |
441 // these sprites are optional |
441 // these sprites are optional |
442 if critical then |
442 if critical then |
443 imflags := (imflags or ifCritical); |
443 imflags := (imflags or ifCritical); |
444 |
444 |
445 // load the image |
445 // load the image |
446 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags); |
446 if checkSum then |
447 if (tmpsurf <> nil) and checkSum then |
447 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags or ifDigestAlpha) |
448 for y := 0 to tmpsurf^.h-1 do |
448 else |
449 syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(tmpsurf^.pixels)^[y*tmpsurf^.pitch], tmpsurf^.w*4) |
449 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags); |
450 end; |
450 end; |
451 |
451 |
452 if tmpsurf <> nil then |
452 if tmpsurf <> nil then |
453 begin |
453 begin |
454 if getImageDimensions then |
454 if getImageDimensions then |
648 end; |
648 end; |
649 |
649 |
650 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
650 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
651 var tmpsurf: PSDL_Surface; |
651 var tmpsurf: PSDL_Surface; |
652 s: shortstring; |
652 s: shortstring; |
653 logMsg: shortstring; |
653 logMsg, digestMsg: shortstring; |
654 rwops: PSDL_RWops; |
654 rwops: PSDL_RWops; |
|
655 y, x: LongInt; |
|
656 rowData: PByteArray; |
655 begin |
657 begin |
656 LoadImage:= nil; |
658 LoadImage:= nil; |
|
659 digestMsg:= ''; |
657 logMsg:= msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + ']'; |
660 logMsg:= msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + ']'; |
658 |
661 |
659 s:= filename + '.png'; |
662 s:= filename + '.png'; |
660 |
663 |
661 rwops:= nil; |
664 rwops:= nil; |
702 tmpsurf:= doSurfaceConversion(tmpsurf); |
705 tmpsurf:= doSurfaceConversion(tmpsurf); |
703 |
706 |
704 if (imageFlags and ifColorKey) <> 0 then |
707 if (imageFlags and ifColorKey) <> 0 then |
705 if checkFails(SDL_SetColorKey(tmpsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true) then exit; |
708 if checkFails(SDL_SetColorKey(tmpsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true) then exit; |
706 |
709 |
|
710 if ((imageFlags and (ifDigestAll or ifDigestAlpha)) <> 0) |
|
711 and (tmpsurf^.format^.BytesPerPixel = 4)then |
|
712 begin |
|
713 if SDL_MustLock(tmpsurf) then |
|
714 SDL_LockSurface(tmpsurf); |
|
715 |
|
716 if (imageFlags and ifDigestAll) <> 0 then |
|
717 begin |
|
718 for y := 0 to tmpsurf^.h - 1 do |
|
719 syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(tmpsurf^.pixels)^[y*tmpsurf^.pitch], tmpsurf^.w*4); |
|
720 digestMsg := ' [CD: ' + inttostr(syncedPixelDigest) + ']' |
|
721 end |
|
722 else if (imageFlags and ifDigestAlpha) <> 0 then |
|
723 begin |
|
724 rowData := GetMem(tmpsurf^.w); |
|
725 for y := 0 to tmpsurf^.h - 1 do |
|
726 begin |
|
727 for x := 0 to tmpsurf^.w - 1 do |
|
728 rowData^[x] := PByteArray(tmpsurf^.pixels)^[y * tmpsurf^.pitch + x * 4 + AByteIndex]; |
|
729 syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, tmpsurf^.w); |
|
730 end; |
|
731 FreeMem(rowData, tmpsurf^.w); |
|
732 digestMsg := ' [AD: ' + inttostr(syncedPixelDigest) + ']' |
|
733 end; |
|
734 |
|
735 if SDL_MustLock(tmpsurf) then |
|
736 SDL_UnlockSurface(tmpsurf); |
|
737 end; |
|
738 |
707 // log success |
739 // log success |
708 WriteLnToConsole(logMsg + ' ' + msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')'); |
740 WriteLnToConsole(logMsg + ' ' + msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')' + digestMsg); |
709 |
741 |
710 LoadImage:= tmpsurf //Result |
742 LoadImage:= tmpsurf //Result |
711 end; |
743 end; |
712 |
744 |
713 |
745 |
872 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
904 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
873 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
905 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
874 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer |
906 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer |
875 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel |
907 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel |
876 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer should be 16 |
908 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer should be 16 |
877 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // prefer hw rendering |
909 {$IFNDEF DARWIN} |
|
910 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // force hw rendering except on macOS |
|
911 {$ENDIF} |
878 end; |
912 end; |
879 |
913 |
880 procedure SetupOpenGL; |
914 procedure SetupOpenGL; |
881 begin |
915 begin |
882 AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')'); |
916 AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')'); |