hedgewars/uMisc.pas
author unC0Rr
Thu, 18 Nov 2010 11:32:47 +0300
changeset 4374 bcefeeabaa33
parent 4371 ae172b2b03ed
child 4375 ae5507ddb989
permissions -rw-r--r--
Move some stuff from uMisc to uUtils
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     1
(*
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     2
* Hedgewars, a free turn based strategy game
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     3
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com>
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     4
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     5
* This program is free software; you can redistribute it and/or modify
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     6
* it under the terms of the GNU General Public License as published by
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     7
* the Free Software Foundation; version 2 of the License
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     8
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     9
* This program is distributed in the hope that it will be useful,
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    12
* GNU General Public License for more details.
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    13
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    14
* You should have received a copy of the GNU General Public License
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    15
* along with this program; if not, write to the Free Software
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
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
4374
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4371
diff changeset
    24
uses    SDLh, uConsts, GLunit, uTypes;
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2693
diff changeset
    25
3611
ed00aa2b339e interpret parameters before initializing everything
koda
parents: 3599
diff changeset
    26
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
    27
procedure movecursor(dx, dy: LongInt);
3929
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    28
(*
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    29
procedure AdjustColor(var Color: Longword);
208
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
    30
procedure SetKB(n: Longword);
3929
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    31
*)
208
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
    32
procedure SendKB;
306
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
    33
procedure SendStat(sit: TStatInfoType; s: shortstring);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
    34
function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
2290
bf87ca44782e Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents: 2279
diff changeset
    35
function  Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
759
8da05b316d81 Enable back fps counter
unc0rr
parents: 755
diff changeset
    36
procedure FreeTexture(tex: PTexture);
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
    37
function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
4374
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4371
diff changeset
    38
procedure OutError(Msg: shortstring; isFatalError: boolean);
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4371
diff changeset
    39
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4371
diff changeset
    40
procedure SDLTry(Assert: boolean; isFatal: boolean);
2735
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
    41
procedure MakeScreenshot(filename: shortstring);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    42
4359
83ef50815535 Move variables from uMisc to uVariables
unC0Rr
parents: 4357
diff changeset
    43
procedure initModule;
83ef50815535 Move variables from uMisc to uVariables
unC0Rr
parents: 4357
diff changeset
    44
procedure freeModule;
83ef50815535 Move variables from uMisc to uVariables
unC0Rr
parents: 4357
diff changeset
    45
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    46
implementation
4374
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4371
diff changeset
    47
uses uConsole, uIO, typinfo, sysutils, uVariables, uUtils;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
    48
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
    49
var KBnum: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    50
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3709
diff changeset
    51
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
    52
procedure movecursor(dx, dy: LongInt);
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    53
var x, y: LongInt;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    54
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    55
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
    56
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    57
SDL_GetMouseState(@x, @y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    58
Inc(x, dx);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    59
Inc(y, dy);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    60
SDL_WarpMouse(x, y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    61
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    62
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    63
2905
f3c79f7193a9 Engine:
smxx
parents: 2882
diff changeset
    64
procedure OutError(Msg: shortstring; isFatalError: boolean);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    65
begin
3407
dcc129c4352e Engine:
smxx
parents: 3381
diff changeset
    66
// obsolete? written in WriteLnToConsole() anyway
dcc129c4352e Engine:
smxx
parents: 3381
diff changeset
    67
// {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    68
WriteLnToConsole(Msg);
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    69
if isFatalError then
3407
dcc129c4352e Engine:
smxx
parents: 3381
diff changeset
    70
    begin
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    71
    SendIPC('E' + GetLastConsoleLine);
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    72
    SDL_Quit;
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    73
    halt(1)
3407
dcc129c4352e Engine:
smxx
parents: 3381
diff changeset
    74
    end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    75
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    76
2905
f3c79f7193a9 Engine:
smxx
parents: 2882
diff changeset
    77
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    78
begin
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    79
if not Assert then OutError(Msg, isFatal)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    80
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    81
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    82
procedure SDLTry(Assert: boolean; isFatal: boolean);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    83
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    84
if not Assert then OutError(SDL_GetError, isFatal)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    85
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    86
3929
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    87
(*
188
a7c2a61524c2 Cardinal -> Longword
unc0rr
parents: 183
diff changeset
    88
procedure AdjustColor(var Color: Longword);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    89
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    90
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    91
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    92
3929
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    93
procedure SetKB(n: Longword);
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    94
begin
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    95
KBnum:= n
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    96
end;
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    97
*)
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    98
9a4bbc1f67a2 Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents: 3914
diff changeset
    99
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   100
procedure SetTextureParameters(enableClamp: Boolean);
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   101
begin
3611
ed00aa2b339e interpret parameters before initializing everything
koda
parents: 3599
diff changeset
   102
    if enableClamp and ((cReducedQuality and rqClampLess) = 0) then
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   103
    begin
3594
aeca3d8f1b29 turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents: 3593
diff changeset
   104
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
aeca3d8f1b29 turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents: 3593
diff changeset
   105
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   106
    end;
3594
aeca3d8f1b29 turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents: 3593
diff changeset
   107
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
aeca3d8f1b29 turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents: 3593
diff changeset
   108
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   109
end;
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   110
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   111
208
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   112
procedure SendKB;
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   113
var s: shortstring;
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   114
begin
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   115
if KBnum <> 0 then
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   116
begin
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   117
s:= 'K' + inttostr(KBnum);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   118
SendIPCRaw(@s, Length(s) + 1)
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   119
end
208
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   120
end;
a049157d673a Implement Knowledge Base for libs/compilers bugs
unc0rr
parents: 196
diff changeset
   121
337
a46abb65eb0c - Fix not debug build
unc0rr
parents: 316
diff changeset
   122
procedure SendStat(sit: TStatInfoType; s: shortstring);
3784
75aa91bea32b Extend statistics collection (TeamKills, TurnSkips, TeamDamage)
burp
parents: 3779
diff changeset
   123
const stc: array [TStatInfoType] of char = 'rDkKHTPsSB';
2382
bfd378dfc4e7 Optimize network traffic a bit:
unc0rr
parents: 2376
diff changeset
   124
var buf: shortstring;
337
a46abb65eb0c - Fix not debug build
unc0rr
parents: 316
diff changeset
   125
begin
2382
bfd378dfc4e7 Optimize network traffic a bit:
unc0rr
parents: 2376
diff changeset
   126
buf:= 'i' + stc[sit] + s;
bfd378dfc4e7 Optimize network traffic a bit:
unc0rr
parents: 2376
diff changeset
   127
SendIPCRaw(@buf[0], length(buf) + 1)
337
a46abb65eb0c - Fix not debug build
unc0rr
parents: 316
diff changeset
   128
end;
a46abb65eb0c - Fix not debug build
unc0rr
parents: 316
diff changeset
   129
771
86fbe8753a7c - Enable back console (doesn't render yet)
unc0rr
parents: 762
diff changeset
   130
1912
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   131
procedure ResetVertexArrays(texture: PTexture);
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   132
begin
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   133
with texture^ do
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   134
    begin
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   135
    vb[0].X:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   136
    vb[0].Y:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   137
    vb[1].X:= w;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   138
    vb[1].Y:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   139
    vb[2].X:= w;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   140
    vb[2].Y:= h;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   141
    vb[3].X:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   142
    vb[3].Y:= h;
1912
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   143
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   144
    tb[0].X:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   145
    tb[0].Y:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   146
    tb[1].X:= rx;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   147
    tb[1].Y:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   148
    tb[2].X:= rx;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   149
    tb[2].Y:= ry;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   150
    tb[3].X:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   151
    tb[3].Y:= ry
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   152
    end;
1912
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   153
end;
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   154
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   155
function NewTexture(width, height: Longword; buf: Pointer): PTexture;
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   156
begin
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   157
new(NewTexture);
2715
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   158
NewTexture^.PrevTexture:= nil;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   159
NewTexture^.NextTexture:= nil;
3537
8f5b3108f29c New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents: 3534
diff changeset
   160
NewTexture^.Scale:= 1;
2715
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   161
if TextureList <> nil then
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   162
    begin
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   163
    TextureList^.PrevTexture:= NewTexture;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   164
    NewTexture^.NextTexture:= TextureList
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   165
    end;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   166
TextureList:= NewTexture;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   167
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   168
NewTexture^.w:= width;
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   169
NewTexture^.h:= height;
1896
fdacad5d0acc Don't use GLU
unc0rr
parents: 1895
diff changeset
   170
NewTexture^.rx:= 1.0;
fdacad5d0acc Don't use GLU
unc0rr
parents: 1895
diff changeset
   171
NewTexture^.ry:= 1.0;
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   172
1912
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   173
ResetVertexArrays(NewTexture);
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   174
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   175
glGenTextures(1, @NewTexture^.id);
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   176
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   177
glBindTexture(GL_TEXTURE_2D, NewTexture^.id);
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   178
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   179
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   180
SetTextureParameters(true);
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   181
end;
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1128
diff changeset
   182
2290
bf87ca44782e Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents: 2279
diff changeset
   183
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
2576
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   184
var tw, th, x, y: Longword;
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   185
    tmpp: pointer;
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   186
    fromP4, toP4: PLongWordArray;
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   187
begin
755
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   188
new(Surface2Tex);
2715
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   189
Surface2Tex^.PrevTexture:= nil;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   190
Surface2Tex^.NextTexture:= nil;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   191
if TextureList <> nil then
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   192
    begin
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   193
    TextureList^.PrevTexture:= Surface2Tex;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   194
    Surface2Tex^.NextTexture:= TextureList
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   195
    end;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   196
TextureList:= Surface2Tex;
0e4e0db79e2a Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents: 2705
diff changeset
   197
755
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   198
Surface2Tex^.w:= surf^.w;
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   199
Surface2Tex^.h:= surf^.h;
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   200
2576
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   201
if (surf^.format^.BytesPerPixel <> 4) then
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   202
    begin
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   203
    TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   204
    Surface2Tex^.id:= 0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   205
    exit
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   206
    end;
2576
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   207
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   208
755
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   209
glGenTextures(1, @Surface2Tex^.id);
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   210
755
edf26e9554ac Now show sprites too
unc0rr
parents: 754
diff changeset
   211
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id);
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   212
771
86fbe8753a7c - Enable back console (doesn't render yet)
unc0rr
parents: 762
diff changeset
   213
if SDL_MustLock(surf) then
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   214
    SDLTry(SDL_LockSurface(surf) >= 0, true);
771
86fbe8753a7c - Enable back console (doesn't render yet)
unc0rr
parents: 762
diff changeset
   215
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
   216
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   217
    begin
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   218
    tw:= toPowerOf2(Surf^.w);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   219
    th:= toPowerOf2(Surf^.h);
1896
fdacad5d0acc Don't use GLU
unc0rr
parents: 1895
diff changeset
   220
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   221
    Surface2Tex^.rx:= Surf^.w / tw;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   222
    Surface2Tex^.ry:= Surf^.h / th;
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2372
diff changeset
   223
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   224
    GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel);
1896
fdacad5d0acc Don't use GLU
unc0rr
parents: 1895
diff changeset
   225
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   226
    fromP4:= Surf^.pixels;
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   227
    toP4:= tmpp;
771
86fbe8753a7c - Enable back console (doesn't render yet)
unc0rr
parents: 762
diff changeset
   228
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   229
    for y:= 0 to Pred(Surf^.h) do
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   230
        begin
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   231
        for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x];
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   232
        for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0;
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   233
        toP4:= @(toP4^[tw]);
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   234
        fromP4:= @(fromP4^[Surf^.pitch div 4])
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   235
        end;
1896
fdacad5d0acc Don't use GLU
unc0rr
parents: 1895
diff changeset
   236
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   237
    for y:= Surf^.h to Pred(th) do
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   238
        begin
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   239
        for x:= 0 to Pred(tw) do toP4^[x]:= 0;
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   240
        toP4:= @(toP4^[tw])
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   241
        end;
771
86fbe8753a7c - Enable back console (doesn't render yet)
unc0rr
parents: 762
diff changeset
   242
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   243
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp);
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2372
diff changeset
   244
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   245
    FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   246
    end
2576
2eb7ce1c1f19 code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents: 2575
diff changeset
   247
else
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   248
    begin
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   249
    Surface2Tex^.rx:= 1.0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   250
    Surface2Tex^.ry:= 1.0;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   251
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels);
3859
ed3b6b3e9d6a more fixing of indentation
nemo
parents: 3784
diff changeset
   252
    end;
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   253
1912
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   254
ResetVertexArrays(Surface2Tex);
c3d31fb59f0e Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents: 1911
diff changeset
   255
754
94ac14829085 Some further work on switching to OpenGL rendering
unc0rr
parents: 753
diff changeset
   256
if SDL_MustLock(surf) then
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   257
    SDL_UnlockSurface(surf);
754
94ac14829085 Some further work on switching to OpenGL rendering
unc0rr
parents: 753
diff changeset
   258
2447
08d623a494e6 Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents: 2428
diff changeset
   259
SetTextureParameters(enableClamp);
753
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   260
end;
40fc0deb388f Start conversion to OpenGL rendering
unc0rr
parents: 626
diff changeset
   261
759
8da05b316d81 Enable back fps counter
unc0rr
parents: 755
diff changeset
   262
procedure FreeTexture(tex: PTexture);
8da05b316d81 Enable back fps counter
unc0rr
parents: 755
diff changeset
   263
begin
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   264
    if tex <> nil then
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   265
    begin
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3695
diff changeset
   266
        if tex^.NextTexture <> nil then
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   267
            tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3695
diff changeset
   268
        if tex^.PrevTexture <> nil then
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   269
            tex^.PrevTexture^.NextTexture:= tex^.NextTexture
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3695
diff changeset
   270
        else
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   271
            TextureList:= tex^.NextTexture;
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   272
        glDeleteTextures(1, @tex^.id);
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3464
diff changeset
   273
        Dispose(tex);
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   274
    end
759
8da05b316d81 Enable back fps counter
unc0rr
parents: 755
diff changeset
   275
end;
337
a46abb65eb0c - Fix not debug build
unc0rr
parents: 316
diff changeset
   276
949
866729775535 Use nick from frontend to prepend chat messages
unc0rr
parents: 945
diff changeset
   277
2735
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   278
procedure MakeScreenshot(filename: shortstring);
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   279
var p: Pointer;
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   280
    size: Longword;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   281
    f: file;
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   282
    // Windows Bitmap Header
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   283
    head: array[0..53] of Byte = (
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   284
    $42, $4D, // identifier ("BM")
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   285
    0, 0, 0, 0, // file size
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   286
    0, 0, 0, 0, // reserved
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   287
    54, 0, 0, 0, // starting offset
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   288
    40, 0, 0, 0, // header size
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   289
    0, 0, 0, 0, // width
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   290
    0, 0, 0, 0, // height
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   291
    1, 0, // color planes
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   292
    24, 0, // bit depth
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   293
    0, 0, 0, 0, // compression method (uncompressed)
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   294
    0, 0, 0, 0, // image size
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   295
    96, 0, 0, 0, // horizontal resolution
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   296
    96, 0, 0, 0, // vertical resolution
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   297
    0, 0, 0, 0, // number of colors (all)
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   298
    0, 0, 0, 0 // number of important colors
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   299
    );
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   300
begin
3107
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   301
// flash
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   302
ScreenFade:= sfFromWhite;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   303
ScreenFadeValue:= sfMax;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   304
ScreenFadeSpeed:= 5;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   305
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   306
size:= cScreenWidth * cScreenHeight * 3;
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   307
p:= GetMem(size);
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   308
2735
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   309
// update header information and file name
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   310
3350
5cd02aafc612 Engine:
smxx
parents: 3337
diff changeset
   311
filename:= ParamStr(1) + '/Screenshots/' + filename + '.bmp';
2735
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   312
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   313
head[$02]:= (size + 54) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   314
head[$03]:= ((size + 54) shr 8) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   315
head[$04]:= ((size + 54) shr 16) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   316
head[$05]:= ((size + 54) shr 24) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   317
head[$12]:= cScreenWidth and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   318
head[$13]:= (cScreenWidth shr 8) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   319
head[$14]:= (cScreenWidth shr 16) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   320
head[$15]:= (cScreenWidth shr 24) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   321
head[$16]:= cScreenHeight and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   322
head[$17]:= (cScreenHeight shr 8) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   323
head[$18]:= (cScreenHeight shr 16) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   324
head[$19]:= (cScreenHeight shr 24) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   325
head[$22]:= size and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   326
head[$23]:= (size shr 8) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   327
head[$24]:= (size shr 16) and $ff;
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   328
head[$25]:= (size shr 24) and $ff;
2163
12730f5e79b9 koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents: 2162
diff changeset
   329
12730f5e79b9 koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents: 2162
diff changeset
   330
//remember that opengles operates on a single surface, so GL_FRONT *should* be implied
3663
8c28abf427f5 reduce the number of keywords used and switch to BMP format for screenshots
koda
parents: 3650
diff changeset
   331
//glReadBuffer(GL_FRONT);
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   332
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   333
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   334
{$I-}
2735
f2008d0ce3f8 Engine:
smxx
parents: 2726
diff changeset
   335
Assign(f, filename);
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   336
Rewrite(f, 1);
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   337
if IOResult = 0 then
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   338
    begin
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   339
    BlockWrite(f, head, sizeof(head));
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   340
    BlockWrite(f, p^, size);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   341
    Close(f);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   342
    end;
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   343
{$I+}
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   344
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   345
FreeMem(p)
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   346
end;
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   347
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   348
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   349
{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   350
var convertedSurf: PSDL_Surface = nil;
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   351
begin
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   352
    if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   353
    begin
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   354
        convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   355
        SDL_FreeSurface(tmpsurf);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   356
        exit(convertedSurf);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   357
    end;
2705
2b5625c4ec16 fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents: 2699
diff changeset
   358
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   359
    exit(tmpsurf);
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   360
end;
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   361
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   362
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   363
procedure initModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   364
begin
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2947
diff changeset
   365
    KBnum           := 0;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   366
end;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   367
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   368
procedure freeModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   369
begin
3626
19f78afa0188 fix the multitouch shooting and moving
koda
parents: 3613
diff changeset
   370
    recordFileName:= '';
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   371
    while TextureList <> nil do FreeTexture(TextureList);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   372
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   373
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   374
end.