hedgewars/uLand.pas
changeset 1806 3c4f0886c123
parent 1805 dd9fb4b13fd8
child 1807 795f97007833
equal deleted inserted replaced
1805:dd9fb4b13fd8 1806:3c4f0886c123
    24 	TPreview  = packed array[0..127, 0..31] of byte;
    24 	TPreview  = packed array[0..127, 0..31] of byte;
    25 	TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    25 	TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    26 
    26 
    27 var  Land: TLandArray;
    27 var  Land: TLandArray;
    28      LandPixels: TLandArray;
    28      LandPixels: TLandArray;
    29      LandTexture: PTexture = nil;
       
    30      LandDirty: TDirtyTag;
    29      LandDirty: TDirtyTag;
    31      hasBorder: boolean; // I'm putting this here for now.  I'd like it to be toggleable by user (so user can set a border on a non-cave map) - will turn off air attacks
    30      hasBorder: boolean; // I'm putting this here for now.  I'd like it to be toggleable by user (so user can set a border on a non-cave map) - will turn off air attacks
    32      hasGirders: boolean;  // I think should be on template by template basis. some caverns might have open water and large spaces.  Some islands don't need? It might be better to tweak the girder code based upon space above.  dunno.
    31      hasGirders: boolean;  // I think should be on template by template basis. some caverns might have open water and large spaces.  Some islands don't need? It might be better to tweak the girder code based upon space above.  dunno.
    33      playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.  Maybe not a good idea, but, for now?  Could also be used to prevent placing a girder outside play area on maps with hasBorder = true
    32      playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.  Maybe not a good idea, but, for now?  Could also be used to prevent placing a girder outside play area on maps with hasBorder = true
    34 
    33 
    35 // in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ?
    34 // in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ?
    36 
    35 
    37 procedure GenMap;
    36 procedure GenMap;
    38 function  GenPreview: TPreview;
    37 function  GenPreview: TPreview;
    39 procedure CheckLandDigest(s: shortstring);
    38 procedure CheckLandDigest(s: shortstring);
    40 procedure UpdateLandTexture(Y, Height: LongInt);
       
    41 procedure DrawLand (X, Y: LongInt);
       
    42 
    39 
    43 implementation
    40 implementation
    44 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO, uAmmos;
    41 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO, uAmmos, uLandTexture;
    45 
    42 
    46 type TPixAr = record
    43 type TPixAr = record
    47               Count: Longword;
    44               Count: Longword;
    48               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
    45               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
    49               end;
    46               end;
    50 
       
    51 var updTopY: LongInt = LAND_HEIGHT;
       
    52     updBottomY: LongInt = 0;
       
    53 
    47 
    54 procedure LogLandDigest;
    48 procedure LogLandDigest;
    55 var ctx: TSHA1Context;
    49 var ctx: TSHA1Context;
    56     dig: TSHA1Digest;
    50     dig: TSHA1Digest;
    57     s: shortstring;
    51     s: shortstring;
   788             end
   782             end
   789         end;
   783         end;
   790 GenPreview:= Preview
   784 GenPreview:= Preview
   791 end;
   785 end;
   792 
   786 
   793 procedure UpdateLandTexture(Y, Height: LongInt);
       
   794 begin
       
   795 if (Height <= 0) then exit;
       
   796 
       
   797 TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
       
   798 TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true);
       
   799 
       
   800 if Y < updTopY then updTopY:= Y;
       
   801 if Y + Height > updBottomY then updBottomY:= Y + Height
       
   802 end;
       
   803 
       
   804 procedure RealLandTexUpdate;
       
   805 begin
       
   806 if updBottomY = 0 then exit;
       
   807 
       
   808 if LandTexture = nil then
       
   809 	LandTexture:= NewTexture(LAND_WIDTH, LAND_HEIGHT, @LandPixels)
       
   810 else
       
   811 	begin
       
   812 	glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
       
   813 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, updTopY, LAND_WIDTH, updBottomY - updTopY, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[updTopY, 0]);
       
   814 	end;
       
   815 
       
   816 updTopY:= LAND_HEIGHT + 1;
       
   817 updBottomY:= 0
       
   818 end;
       
   819 
       
   820 procedure DrawLand(X, Y: LongInt);
       
   821 begin
       
   822 RealLandTexUpdate;
       
   823 DrawTexture(X, Y, LandTexture)
       
   824 end;
       
   825 
       
   826 initialization
   787 initialization
   827 
   788 
   828 end.
   789 end.