hedgewars/uMisc.pas
author sheepluva
Wed, 17 Dec 2014 23:01:43 +0100
changeset 10692 a88647ead05c
parent 10658 a3872ffdeab1
child 10693 9819e69bc6db
permissions -rw-r--r--
don't save alpha channel to screenshots when not needed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     1
(*
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9317
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     4
 *
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     8
 *
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    12
 * GNU General Public License for more details.
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    13
 *
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10015
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6884
diff changeset
    17
 *)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    21
unit uMisc;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    22
interface
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    23
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
    24
uses SDLh, uConsts, GLunit, uTypes;
1054
80225c6af656 - Prepare for sudden death implementation
unc0rr
parents: 988
diff changeset
    25
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
    26
procedure initModule;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
    27
procedure freeModule;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
    28
3169
c8c6ac44f51b prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents: 3165
diff changeset
    29
procedure movecursor(dx, dy: LongInt);
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
    30
function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
    31
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean;
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
    32
function  GetTeamStatString(p: PTeam): shortstring;
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
    33
{$IFDEF SDL2}
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6990
diff changeset
    34
function  SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    35
{$ELSE}
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6990
diff changeset
    36
function  SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    37
{$ENDIF}
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    38
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    39
implementation
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 6992
diff changeset
    40
uses SysUtils, uVariables, uUtils
8865
dd4035ee0f12 use SDL_Threads everywhere
koda
parents: 7848
diff changeset
    41
     {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF};
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    42
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    43
type PScreenshot = ^TScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    44
     TScreenshot = record
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    45
         buffer: PByte;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    46
         filename: shortstring;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    47
         width, height: LongInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    48
         size: QWord;
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    49
         alpha: boolean;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    50
         end;
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3709
diff changeset
    51
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7848
diff changeset
    52
var conversionFormat : PSDL_PixelFormat;
7049
35d762458d66 minor changes for warnings and a variables scope
koda
parents: 7043
diff changeset
    53
3169
c8c6ac44f51b prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents: 3165
diff changeset
    54
procedure movecursor(dx, dy: LongInt);
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    55
var x, y: LongInt;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    56
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    57
if (dx = 0) and (dy = 0) then exit;
2671
7e0f88013fe8 smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents: 2670
diff changeset
    58
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    59
SDL_GetMouseState(@x, @y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    60
Inc(x, dx);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    61
Inc(y, dy);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    62
SDL_WarpMouse(x, y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    63
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    64
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    65
{$IFDEF PNG_SCREENSHOTS}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    66
// this funtion will be executed in separate thread
8865
dd4035ee0f12 use SDL_Threads everywhere
koda
parents: 7848
diff changeset
    67
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    68
var i: LongInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    69
    png_ptr: ^png_struct;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    70
    info_ptr: ^png_info;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7848
diff changeset
    71
    f: File;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    72
    image: PScreenshot;
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    73
    bpp: Integer; // bytes per pixel
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    74
    ctype: Integer; // png color type
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    75
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    76
image:= PScreenshot(screenshot);
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    77
if image^.alpha then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    78
    begin
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    79
    bpp:= 4;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    80
    ctype:= PNG_COLOR_TYPE_RGBA;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    81
    end
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    82
else
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    83
    begin
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    84
    bpp:= 3;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    85
    ctype:= PNG_COLOR_TYPE_RGB;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
    86
    end;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    87
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    88
png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    89
if png_ptr = nil then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    90
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    91
    // AddFileLog('Error: Could not create png write struct.');
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
    92
    SaveScreenshot:= 0;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
    93
    exit;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    94
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    95
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    96
info_ptr := png_create_info_struct(png_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    97
if info_ptr = nil then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    98
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    99
    png_destroy_write_struct(@png_ptr, nil);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   100
    // AddFileLog('Error: Could not create png info struct.');
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   101
    SaveScreenshot:= 0;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   102
    exit;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   103
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   104
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   105
{$IOCHECKS OFF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   106
Assign(f, image^.filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   107
Rewrite(f, 1);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   108
if IOResult = 0 then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   109
    begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   110
    png_init_pascal_io(png_ptr,@f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   111
    png_set_IHDR(png_ptr, info_ptr, image^.width, image^.height,
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   112
                 8, // bit depth
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   113
                 ctype, PNG_INTERLACE_NONE,
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   114
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   115
    png_write_info(png_ptr, info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   116
    // glReadPixels and libpng number rows in different order
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   117
    for i:= image^.height-1 downto 0 do
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   118
        png_write_row(png_ptr, image^.buffer + i*bpp*image^.width);
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   119
    png_write_end(png_ptr, info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   120
    Close(f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   121
    end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   122
{$IOCHECKS ON}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   123
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   124
// free everything
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   125
png_destroy_write_struct(@png_ptr, @info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   126
FreeMem(image^.buffer, image^.size);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   127
Dispose(image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   128
SaveScreenshot:= 0;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   129
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   130
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   131
{$ELSE} // no PNG_SCREENSHOTS
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   132
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   133
// this funtion will be executed in separate thread
8865
dd4035ee0f12 use SDL_Threads everywhere
koda
parents: 7848
diff changeset
   134
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   135
var f: file;
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   136
    // Windows Bitmap Header
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   137
    head: array[0..53] of Byte = (
6267
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   138
    $42, $4D,       // identifier ("BM")
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   139
    0, 0, 0, 0,     // file size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   140
    0, 0, 0, 0,     // reserved
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   141
    54, 0, 0, 0,    // starting offset
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   142
    40, 0, 0, 0,    // header size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   143
    0, 0, 0, 0,     // width
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   144
    0, 0, 0, 0,     // height
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   145
    1, 0,           // color planes
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   146
    24, 0,          // bit depth
6267
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   147
    0, 0, 0, 0,     // compression method (uncompressed)
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   148
    0, 0, 0, 0,     // image size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   149
    96, 0, 0, 0,    // horizontal resolution
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   150
    96, 0, 0, 0,    // vertical resolution
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   151
    0, 0, 0, 0,     // number of colors (all)
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   152
    0, 0, 0, 0      // number of important colors
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   153
    );
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   154
    image: PScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   155
    size: QWord;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7848
diff changeset
   156
    writeResult:LongInt;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   157
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   158
image:= PScreenshot(screenshot);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   159
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   160
size:= image^.Width*image^.Height*4;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   161
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   162
head[$02]:= (size + 54) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   163
head[$03]:= ((size + 54) shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   164
head[$04]:= ((size + 54) shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   165
head[$05]:= ((size + 54) shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   166
head[$12]:= image^.Width and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   167
head[$13]:= (image^.Width shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   168
head[$14]:= (image^.Width shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   169
head[$15]:= (image^.Width shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   170
head[$16]:= image^.Height and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   171
head[$17]:= (image^.Height shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   172
head[$18]:= (image^.Height shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   173
head[$19]:= (image^.Height shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   174
head[$22]:= size and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   175
head[$23]:= (size shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   176
head[$24]:= (size shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   177
head[$25]:= (size shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   178
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   179
if image^.alpha then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   180
    head[$1C]:= 32;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   181
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   182
{$IOCHECKS OFF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   183
Assign(f, image^.filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   184
Rewrite(f, 1);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   185
if IOResult = 0 then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   186
    begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7848
diff changeset
   187
    BlockWrite(f, head, sizeof(head), writeResult);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7848
diff changeset
   188
    BlockWrite(f, image^.buffer^, size, writeResult);
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   189
    Close(f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   190
    end
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   191
else
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   192
    begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   193
    //AddFileLog('Error: Could not write to ' + filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   194
    end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   195
{$IOCHECKS ON}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   196
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   197
// free everything
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   198
FreeMem(image^.buffer, image^.size);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   199
Dispose(image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   200
SaveScreenshot:= 0;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   201
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   202
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   203
{$ENDIF} // no PNG_SCREENSHOTS
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   204
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   205
{$IFDEF USE_VIDEO_RECORDING}
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   206
// make image k times smaller (useful for saving thumbnails)
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   207
procedure ReduceImage(img: PByte; width, height, k: LongInt; bpp: Integer);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   208
    var i, j, i0, j0, w, h, r, g, b, off, ksqr: LongInt;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   209
begin
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   210
    w:= width  div k;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   211
    h:= height div k;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   212
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   213
    // rescale inplace
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   214
    if k <> 1 then
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   215
    begin
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   216
        ksqr:= k*k;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   217
        for i:= 0 to h-1 do
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   218
            for j:= 0 to w-1 do
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   219
            begin
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   220
                r:= 0;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   221
                g:= 0;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   222
                b:= 0;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   223
                for i0:= 0 to k-1 do
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   224
                    for j0:= 0 to k-1 do
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   225
                    begin
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   226
                        off:= bpp*(width*(i*k+i0) + j*k+j0);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   227
                        inc(r, img[off]); inc(off);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   228
                        inc(g, img[off]); inc(off);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   229
                        inc(b, img[off]);
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   230
                    end;
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   231
                off:= bpp*(w*i + j);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   232
                img[off]:= r div (ksqr); inc(off);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   233
                img[off]:= g div (ksqr); inc(off);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   234
                img[off]:= b div (ksqr);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   235
                // if there's an alpha channel set opacity to max
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   236
                if bpp > 3 then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   237
                    begin
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   238
                    inc(off);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   239
                    img[off]:= 255;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   240
                    end;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   241
            end;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   242
    end;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   243
end;
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   244
{$ENDIF}
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   245
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   246
// captures and saves the screen. returns true on success.
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   247
// saved image will be k times smaller than original (useful for saving thumbnails).
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   248
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   249
var p: Pointer;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   250
    size: QWord;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   251
    image: PScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   252
    format: GLenum;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   253
    ext: string[4];
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   254
    x,y: LongWord;
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   255
    hasA: boolean;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   256
    bpp: Integer;
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   257
begin
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   258
hasA:= (dump > 0);
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   259
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   260
if hasA then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   261
    bpp:= 4
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   262
else
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   263
    bpp:= 3;
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   264
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   265
{$IFDEF PNG_SCREENSHOTS}
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   266
if hasA then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   267
    format:= GL_RGBA
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   268
else
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   269
    format:= GL_RGB;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   270
ext:= '.png';
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   271
{$ELSE}
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   272
if hasA then
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   273
    format:= GL_BGRA
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   274
else
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   275
    format:= GL_BGR;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   276
ext:= '.bmp';
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   277
{$ENDIF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   278
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   279
if dump > 0 then
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   280
     size:= LAND_WIDTH*LAND_HEIGHT*bpp
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   281
else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * bpp;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   282
p:= GetMem(size); // will be freed in SaveScreenshot()
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   283
5910
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   284
// memory could not be allocated
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   285
if p = nil then
5912
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   286
begin
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   287
    AddFileLog('Error: Could not allocate memory for screenshot.');
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   288
    MakeScreenshot:= false;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   289
    exit;
5912
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   290
end;
5910
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   291
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   292
// read pixels from the front buffer
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   293
if dump > 0 then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   294
    begin
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   295
    for y:= 0 to LAND_HEIGHT-1 do
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   296
        for x:= 0 to LAND_WIDTH-1 do
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   297
            if dump = 2 then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   298
                PLongWordArray(p)^[y*LAND_WIDTH+x]:= LandPixels[LAND_HEIGHT-1-y, x]
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   299
            else
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   300
                begin
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   301
                if Land[LAND_HEIGHT-1-y, x] and lfIndestructible = lfIndestructible then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   302
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or RMask)
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   303
                else if Land[LAND_HEIGHT-1-y, x] and lfIce = lfIce then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   304
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or BMask)
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   305
                else if Land[LAND_HEIGHT-1-y, x] and lfBouncy = lfBouncy then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   306
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or GMask)
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   307
                else if Land[LAND_HEIGHT-1-y, x] and lfObject = lfObject then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   308
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= $FFFFFFFF
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   309
                else if Land[LAND_HEIGHT-1-y, x] and lfBasic = lfBasic then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   310
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= AMask
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   311
                else
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   312
                    PLongWordArray(p)^[y*LAND_WIDTH+x]:= 0
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   313
                end
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   314
    end
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   315
else
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   316
    begin
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   317
    glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p);
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   318
{$IFDEF USE_VIDEO_RECORDING}
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   319
    ReduceImage(p, cScreenWidth, cScreenHeight, k, bpp)
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   320
{$ENDIF}
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   321
    end;
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7049
diff changeset
   322
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   323
// allocate and fill structure that will be passed to new thread
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   324
New(image); // will be disposed in SaveScreenshot()
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   325
if dump = 2 then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   326
     image^.filename:= shortstring(UserPathPrefix) + filename + '_landpixels' + ext
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   327
else if dump = 1 then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   328
     image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext
10658
a3872ffdeab1 fix copypasta
nemo
parents: 10633
diff changeset
   329
else image^.filename:= shortstring(UserPathPrefix) + filename + ext;
10633
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   330
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   331
if dump <> 0 then
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   332
    begin
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   333
    image^.width:= LAND_WIDTH;
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   334
    image^.height:= LAND_HEIGHT
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   335
    end
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   336
else
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   337
    begin
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   338
    image^.width:= cScreenWidth div k;
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   339
    image^.height:= cScreenHeight div k
2f062fac5791 Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents: 10150
diff changeset
   340
    end;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   341
image^.size:= size;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   342
image^.buffer:= p;
10692
a88647ead05c don't save alpha channel to screenshots when not needed
sheepluva
parents: 10658
diff changeset
   343
image^.alpha:= hasA;
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   344
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   345
SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image);
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   346
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   347
end;
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   348
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   349
// http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   350
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   351
var convertedSurf: PSDL_Surface;
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   352
begin
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   353
    doSurfaceConversion:= tmpsurf;
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   354
    if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   355
       (tmpsurf^.format^.bitsperpixel = 24) then
7049
35d762458d66 minor changes for warnings and a variables scope
koda
parents: 7043
diff changeset
   356
    begin
5046
fc6639d56799 this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents: 5004
diff changeset
   357
        convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   358
        SDL_FreeSurface(tmpsurf);
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6952
diff changeset
   359
        doSurfaceConversion:= convertedSurf;
7049
35d762458d66 minor changes for warnings and a variables scope
koda
parents: 7043
diff changeset
   360
    end;
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   361
end;
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   362
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   363
{$IFDEF SDL2}
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6990
diff changeset
   364
function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   365
{$ELSE}
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6990
diff changeset
   366
function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   367
{$ENDIF}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   368
begin
6857
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   369
    SDL_RectMake.x:= x;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   370
    SDL_RectMake.y:= y;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   371
    SDL_RectMake.w:= width;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   372
    SDL_RectMake.h:= height;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   373
end;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   374
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   375
function GetTeamStatString(p: PTeam): shortstring;
10124
aabd1b75d5a3 Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents: 10108
diff changeset
   376
var s: shortstring;
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
   377
begin
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   378
    s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   379
    GetTeamStatString:= s;
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
   380
end;
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
   381
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   382
{$IFDEF SDL2}
10150
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10127
diff changeset
   383
// FIXME - pretty sure this is not handling endianness correctly like the SDL1 is
9311
5baf10a52f43 engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents: 9080
diff changeset
   384
const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   385
{$ELSE}
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   386
const format: TSDL_PixelFormat = (
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   387
        palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   388
        Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   389
        Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   390
        RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   391
        colorkey: 0; alpha: 255);
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   392
{$ENDIF}
9958
5a222923c8f8 - Don't define NOCONSOLE
unc0rr
parents: 9521
diff changeset
   393
5a222923c8f8 - Don't define NOCONSOLE
unc0rr
parents: 9521
diff changeset
   394
procedure initModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   395
begin
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   396
{$IFDEF SDL2}
5052
74a81c276d67 fix a couple of loose ends
koda
parents: 5050
diff changeset
   397
    conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   398
{$ELSE}
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   399
    conversionFormat:= @format;
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   400
{$ENDIF}
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   401
end;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   402
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   403
procedure freeModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   404
begin
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   405
{$IFDEF SDL2}
5046
fc6639d56799 this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents: 5004
diff changeset
   406
    SDL_FreeFormat(conversionFormat);
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9311
diff changeset
   407
{$ENDIF}
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   408
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   409
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   410
end.