hedgewars/uLandTexture.pas
author nemo
Fri, 14 Dec 2012 09:58:26 -0500
changeset 8292 c284ea71a4f8
parent 8027 e5ba3dd12531
child 8096 453917e94e55
child 9080 9b42757d7e71
permissions -rw-r--r--
*sigh*
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     1
(*
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6580
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     4
 *
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     8
 *
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    13
 *
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    17
 *)
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    18
2599
c7153d2348f3 move compiler directives to standard pascal
koda
parents: 2592
diff changeset
    19
{$INCLUDE "options.inc"}
2587
0dfa56a8513c fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents: 2376
diff changeset
    20
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    21
unit uLandTexture;
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    22
interface
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    23
uses SDLh;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    24
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
    25
procedure initModule;
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
    26
procedure freeModule;
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    27
procedure UpdateLandTexture(X, Width, Y, Height: LongInt; landAdded: boolean);
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    28
procedure DrawLand(dX, dY: LongInt);
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
    29
procedure ResetLand;
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
    30
procedure SetLandTexture;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    31
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    32
implementation
4403
unc0rr
parents: 4390
diff changeset
    33
uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender;
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    34
7172
f68d62711a5c After experimenting with a long running average at maxed out FPS and a variety of map sizes, 128 seems to actually be a good size to use if only drawing bits of world with stuff in it. 64 actually did even better in some situations, but significantly worse in others (lots of land, zoomed out).
nemo
parents: 7170
diff changeset
    35
const TEXSIZE = 128;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    36
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
    37
type TLandRecord = record
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    38
            shouldUpdate, landAdded: boolean;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    39
            tex: PTexture;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    40
            end;
3615
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
    41
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
    42
var LandTextures: array of array of TLandRecord;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    43
    tmpPixels: array [0..TEXSIZE - 1, 0..TEXSIZE - 1] of LongWord;
3615
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
    44
    LANDTEXARW: LongWord;
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
    45
    LANDTEXARH: LongWord;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3666
diff changeset
    46
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    47
function Pixels(x, y: Longword): Pointer;
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    48
var ty: Longword;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    49
begin
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    50
for ty:= 0 to TEXSIZE - 1 do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    51
    Move(LandPixels[y * TEXSIZE + ty, x * TEXSIZE], tmpPixels[ty, 0], sizeof(Longword) * TEXSIZE);
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2248
diff changeset
    52
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    53
Pixels:= @tmpPixels
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    54
end;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    55
1859
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    56
function Pixels2(x, y: Longword): Pointer;
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    57
var tx, ty: Longword;
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    58
begin
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    59
for ty:= 0 to TEXSIZE - 1 do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    60
    for tx:= 0 to TEXSIZE - 1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    61
        tmpPixels[ty, tx]:= Land[y * TEXSIZE + ty, x * TEXSIZE + tx] or AMask;
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2248
diff changeset
    62
1859
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    63
Pixels2:= @tmpPixels
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    64
end;
e071284b118e Pixels2 proc, which uses Land array when updating textures
unc0rr
parents: 1852
diff changeset
    65
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    66
procedure UpdateLandTexture(X, Width, Y, Height: LongInt; landAdded: boolean);
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    67
var tx, ty: Longword;
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    68
begin
8027
e5ba3dd12531 make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents: 7850
diff changeset
    69
    if cOnlyStats then exit;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6383
diff changeset
    70
    if (Width <= 0) or (Height <= 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6383
diff changeset
    71
        exit;
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    72
    TryDo((X >= 0) and (X < LAND_WIDTH), 'UpdateLandTexture: wrong X parameter', true);
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    73
    TryDo(X + Width <= LAND_WIDTH, 'UpdateLandTexture: wrong Width parameter', true);
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    74
    TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    75
    TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true);
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    76
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    77
    if (cReducedQuality and rqBlurryLand) = 0 then
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    78
        for ty:= Y div TEXSIZE to (Y + Height - 1) div TEXSIZE do
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    79
            for tx:= X div TEXSIZE to (X + Width - 1) div TEXSIZE do
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    80
                begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    81
                LandTextures[tx, ty].shouldUpdate:= true;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    82
                LandTextures[tx, ty].landAdded:= landAdded
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    83
                end
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    84
    else
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    85
        for ty:= (Y div TEXSIZE) div 2 to ((Y + Height - 1) div TEXSIZE) div 2 do
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    86
            for tx:= (X div TEXSIZE) div 2 to ((X + Width - 1) div TEXSIZE) div 2 do
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    87
                begin
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
    88
                LandTextures[tx, ty].shouldUpdate:= true;
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    89
                LandTextures[tx, ty].landAdded:= landAdded
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    90
                end
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    91
end;
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    92
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    93
procedure RealLandTexUpdate;
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    94
var x, y, ty, tx, lx, ly : LongWord;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    95
    isEmpty: boolean;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
    96
begin
8027
e5ba3dd12531 make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents: 7850
diff changeset
    97
    if cOnlyStats then exit;
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
    98
(*
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
    99
if LandTextures[0, 0].tex = nil then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   100
    for x:= 0 to LANDTEXARW -1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   101
        for y:= 0 to LANDTEXARH - 1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   102
            with LandTextures[x, y] do
3491
4619b1ae99b5 Engine:
smxx
parents: 3165
diff changeset
   103
                begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6383
diff changeset
   104
                tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6383
diff changeset
   105
                glBindTexture(GL_TEXTURE_2D, tex^.id);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6383
diff changeset
   106
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh);
3491
4619b1ae99b5 Engine:
smxx
parents: 3165
diff changeset
   107
                end
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   108
else
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   109
*)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   110
    for x:= 0 to LANDTEXARW -1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   111
        for y:= 0 to LANDTEXARH - 1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   112
            with LandTextures[x, y] do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   113
                if shouldUpdate then
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   114
                    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   115
                    shouldUpdate:= false;
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   116
                    isEmpty:= not landAdded;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   117
                    landAdded:= false;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   118
                    ty:= 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   119
                    tx:= 1;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   120
                    ly:= y * TEXSIZE;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   121
                    lx:= x * TEXSIZE;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   122
                    // first check edges
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   123
                    while isEmpty and (ty < TEXSIZE) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   124
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   125
                        isEmpty:= LandPixels[ly + ty, lx] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   126
                        if isEmpty then isEmpty:= LandPixels[ly + ty, lx + TEXSIZE-1] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   127
                        inc(ty)
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   128
                        end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   129
                    while isEmpty and (tx < TEXSIZE-1) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   130
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   131
                        isEmpty:= LandPixels[ly, lx + tx] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   132
                        if isEmpty then isEmpty:= LandPixels[ly + TEXSIZE-1, lx + tx] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   133
                        inc(tx)
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   134
                        end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   135
                    // then search every other remaining. does this sort of stuff defeat compiler opts?
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   136
                    ty:= 2;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   137
                    while isEmpty and (ty < TEXSIZE-1) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   138
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   139
                        tx:= 2;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   140
                        while isEmpty and (tx < TEXSIZE-1) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   141
                            begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   142
                            isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   143
                            inc(tx,2)
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   144
                            end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   145
                        inc(ty,2);
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   146
                        end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   147
                    // and repeat
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   148
                    ty:= 1;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   149
                    while isEmpty and (ty < TEXSIZE-1) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   150
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   151
                        tx:= 1;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   152
                        while isEmpty and (tx < TEXSIZE-1) do
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   153
                            begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   154
                            isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   155
                            inc(tx,2)
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   156
                            end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   157
                        inc(ty,2);
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   158
                        end;
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   159
                    if not isEmpty then
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   160
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   161
                        if tex = nil then tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y));
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   162
                        glBindTexture(GL_TEXTURE_2D, tex^.id);
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   163
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE, TEXSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x,y));
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   164
                        end
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   165
                    else if tex <> nil then
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   166
                        begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   167
                        FreeTexture(tex);
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   168
                        tex:= nil
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   169
                        end;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   170
                    end
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   171
end;
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   172
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   173
procedure DrawLand(dX, dY: LongInt);
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   174
var x, y: LongInt;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   175
begin
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   176
RealLandTexUpdate;
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   177
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   178
for x:= 0 to LANDTEXARW -1 do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   179
    for y:= 0 to LANDTEXARH - 1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   180
        with LandTextures[x, y] do
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   181
            if tex <> nil then
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   182
                if (cReducedQuality and rqBlurryLand) = 0 then
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   183
                    DrawTexture(dX + x * TEXSIZE, dY + y * TEXSIZE, tex)
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   184
                else
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   185
                    DrawTexture(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0)
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3513
diff changeset
   186
1807
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   187
end;
795f97007833 Split land texture into small ones:
unc0rr
parents: 1806
diff changeset
   188
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
   189
procedure SetLandTexture;
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   190
begin
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   191
    if (cReducedQuality and rqBlurryLand) = 0 then
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   192
        begin
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   193
        LANDTEXARW:= LAND_WIDTH div TEXSIZE;
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   194
        LANDTEXARH:= LAND_HEIGHT div TEXSIZE;
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   195
        end
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   196
    else
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   197
        begin
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   198
        LANDTEXARW:= (LAND_WIDTH div TEXSIZE) div 2;
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   199
        LANDTEXARH:= (LAND_HEIGHT div TEXSIZE) div 2;
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   200
        end;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3666
diff changeset
   201
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   202
    SetLength(LandTextures, LANDTEXARW, LANDTEXARH);
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   203
end;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3666
diff changeset
   204
7850
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
   205
procedure initModule;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
   206
begin
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
   207
end;
fcbb024090a4 cleanup in initEverything and freeEverything
koda
parents: 7172
diff changeset
   208
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   209
procedure ResetLand;
3615
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   210
var x, y: LongInt;
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   211
begin
6382
0e76c5cd4250 move the order of reloading texture to workaround buggy drivers
koda
parents: 6380
diff changeset
   212
    for x:= 0 to LANDTEXARW - 1 do
3615
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   213
        for y:= 0 to LANDTEXARH - 1 do
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   214
            with LandTextures[x, y] do
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   215
                begin
7170
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   216
                if tex <> nil then
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   217
                    begin
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   218
                    FreeTexture(tex);
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   219
                    tex:= nil
84ac6c6d2d8e Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents: 7151
diff changeset
   220
                    end
5654
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   221
                end;
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   222
end;
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   223
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   224
procedure freeModule;
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   225
begin
1cb68f420aa6 Free land texture, reset sky colour.
nemo
parents: 4976
diff changeset
   226
    ResetLand;
3615
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   227
    if LandBackSurface <> nil then
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   228
        SDL_FreeSurface(LandBackSurface);
b78d7959540a further code cleanup and less redundancy
koda
parents: 3612
diff changeset
   229
    LandBackSurface:= nil;
7151
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 6700
diff changeset
   230
    SetLength(LandTextures, 0, 0);
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3595
diff changeset
   231
end;
1806
3c4f0886c123 More reorganization
unc0rr
parents:
diff changeset
   232
end.