Changeset 8


Ignore:
Timestamp:
Mar 16, 2011, 10:47:36 PM (13 years ago)
Author:
george
Message:
  • Modified: Speed up drawing of screen image and map overview using TBitmap.RawImage.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r7 r8  
    77uses
    88  Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList,
    9   IntfGraphics, FPImage, LCLType, SpecializedBitmap;
     9  IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType;
    1010
    1111const
     
    9696    FRedrawPending: Boolean;
    9797    FBitmapLower: TBitmapTColor;
     98    IntfImage: TLazIntfImage;
    9899    function GetPlayerCount: Integer;
    99100    procedure SetBitmap(const AValue: TBitmap);
     
    229230var
    230231  X, Y: Integer;
     232  PixelPtr: PInteger;
     233  PixelRowPtr: PInteger;
     234  RawImage: TRawImage;
     235  BytePerPixel: Integer;
     236  P: Integer;
    231237begin
    232238  try
    233     Bitmap.BeginUpdate(True);
    234   for Y := 0 to Bitmap.Height - 1 do
    235     for X := 0 to Bitmap.Width - 1 do
    236       Bitmap.Canvas.Pixels[X, Y] := SurfaceMatterColors[TSurfaceMatter(
    237         Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X),
    238           Trunc(Y / Bitmap.Height * Surface.Count.Y)])];
     239    Bitmap.BeginUpdate;
     240    RawImage := Bitmap.RawImage;
     241    PixelRowPtr := PInteger(RawImage.Data);
     242    BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     243    for Y := 0 to Bitmap.Height - 1 do begin
     244      PixelPtr := PixelRowPtr;
     245      for X := 0 to Bitmap.Width - 1 do begin
     246        P := SurfaceMatterColors[TSurfaceMatter(
     247          Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X),
     248            Trunc(Y / Bitmap.Height * Surface.Count.Y)])];
     249        PixelPtr^ := ((P and $ff) shl 16) or (P and $00ff00) or ((P shr 16) and $ff);
     250        Inc(PByte(PixelPtr), BytePerPixel);
     251      end;
     252      Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);
     253    end;
    239254  finally
    240255    Bitmap.EndUpdate;
     
    591606begin
    592607  FBitmapLower := TBitmapTColor.Create;
     608  IntfImage := TLazIntfImage.Create(1, 1);
    593609  Players := TObjectList.Create;
    594610  World := TWorld.Create;
     
    600616begin
    601617  FBitmapLower.Free;
     618  IntfImage.Free;
    602619  Players.Free;
    603620  World.Free;
     
    616633procedure TEngine.Draw;
    617634var
    618   IntfImage: TLazIntfImage;
    619635  I: Integer;
    620636  X, Y: Integer;
    621637  H, W: Integer;
    622638  Ratio: Single;
     639  PixelPtr: PInteger;
     640  PixelRowPtr: PInteger;
     641  RawImage: TRawImage;
     642  BytePerPixel: Integer;
     643  P: Integer;
    623644begin
    624645  if FRedrawPending then begin
     
    627648      TPlayer(Players[I]).Paint;
    628649    end;
    629     if Assigned(FBitmap) then begin
    630       //FBitmap.Canvas.StretchDraw(Rect(0, 0, FBitmap.Width, FBitmap.Height), FBitmapLower);
    631       try
    632         IntfImage := FBitmap.CreateIntfImage;
    633         if (FBitmap.Width / FBitmapLower.Width) < (FBitmap.Height / FBitmapLower.Height) then
    634           Ratio := FBitmap.Width / FBitmapLower.Width
    635           else Ratio := FBitmap.Height / FBitmapLower.Height;
    636         for Y := 0 to Trunc(FBitmapLower.Height * Ratio) - 1 do
    637           for X := 0 to Trunc(FBitmapLower.Width * Ratio) - 1 do
    638             IntfImage.Colors[X, Y] := TColorToFPColor(FBitmapLower.Pixels[Trunc(X / Ratio), Trunc(Y / Ratio)]);
    639         FBitmap.LoadFromIntfImage(IntfImage);
    640       finally
    641         IntfImage.Free;
     650    if Assigned(FBitmap) then try
     651      Bitmap.BeginUpdate(False);
     652      RawImage := Bitmap.RawImage;
     653      PixelRowPtr := PInteger(RawImage.Data);
     654      BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     655      if (IntfImage.Width <> FBitmap.Width) or (IntfImage.Height <> FBitmap.Height) then
     656        IntfImage.SetSize(FBitmap.Width, FBitmap.Height);
     657      if (FBitmap.Width / FBitmapLower.Width) < (FBitmap.Height / FBitmapLower.Height) then
     658        Ratio := FBitmap.Width / FBitmapLower.Width
     659        else Ratio := FBitmap.Height / FBitmapLower.Height;
     660      for Y := 0 to Trunc(FBitmapLower.Height * Ratio) - 1 do begin
     661        PixelPtr := PixelRowPtr;
     662        for X := 0 to Trunc(FBitmapLower.Width * Ratio) - 1 do begin
     663          P := FBitmapLower.Pixels[Trunc(X / Ratio), Trunc(Y / Ratio)];
     664          PixelPtr^ := ((P and $ff) shl 16) or (P and $00ff00) or ((P shr 16) and $ff);
     665          Inc(PByte(PixelPtr), BytePerPixel);
     666        end;
     667        Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);
    642668      end;
     669    finally
     670      FBitmap.EndUpdate(False);
    643671    end;
    644672    FRedrawPending := False;
  • trunk/tunneler.lpi

    r7 r8  
    4242      </Item3>
    4343    </RequiredPackages>
    44     <Units Count="40">
     44    <Units Count="41">
    4545      <Unit0>
    4646        <Filename Value="tunneler.lpr"/>
     
    5050        <TopLine Value="1"/>
    5151        <CursorPos X="14" Y="8"/>
    52         <UsageCount Value="58"/>
     52        <UsageCount Value="60"/>
    5353      </Unit0>
    5454      <Unit1>
     
    5858        <ResourceBaseClass Value="Form"/>
    5959        <UnitName Value="UMainForm"/>
    60         <IsVisibleTab Value="True"/>
    61         <EditorIndex Value="13"/>
    62         <WindowIndex Value="0"/>
    63         <TopLine Value="22"/>
    64         <CursorPos X="20" Y="36"/>
    65         <UsageCount Value="58"/>
     60        <EditorIndex Value="7"/>
     61        <WindowIndex Value="0"/>
     62        <TopLine Value="81"/>
     63        <CursorPos X="3" Y="90"/>
     64        <UsageCount Value="60"/>
    6665        <Loaded Value="True"/>
    6766        <LoadedDesigner Value="True"/>
     
    7170        <IsPartOfProject Value="True"/>
    7271        <UnitName Value="UCore"/>
     72        <IsVisibleTab Value="True"/>
    7373        <EditorIndex Value="0"/>
    7474        <WindowIndex Value="0"/>
    75         <TopLine Value="317"/>
    76         <CursorPos X="44" Y="326"/>
    77         <UsageCount Value="58"/>
     75        <TopLine Value="229"/>
     76        <CursorPos X="1" Y="250"/>
     77        <UsageCount Value="60"/>
    7878        <Loaded Value="True"/>
    7979      </Unit2>
     
    114114        <EditorIndex Value="1"/>
    115115        <WindowIndex Value="0"/>
    116         <TopLine Value="1293"/>
    117         <CursorPos X="15" Y="1310"/>
     116        <TopLine Value="2417"/>
     117        <CursorPos X="3" Y="2459"/>
    118118        <UsageCount Value="12"/>
    119119        <Loaded Value="True"/>
     
    121121      <Unit8>
    122122        <Filename Value="../../../lazarus/lcl/include/rasterimage.inc"/>
    123         <EditorIndex Value="2"/>
    124123        <WindowIndex Value="0"/>
    125124        <TopLine Value="548"/>
    126125        <CursorPos X="22" Y="552"/>
    127126        <UsageCount Value="10"/>
    128         <Loaded Value="True"/>
    129127      </Unit8>
    130128      <Unit9>
     
    145143      <Unit11>
    146144        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericMatrix.inc"/>
    147         <EditorIndex Value="14"/>
     145        <EditorIndex Value="8"/>
    148146        <WindowIndex Value="0"/>
    149147        <TopLine Value="52"/>
     
    155153        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Specialized/SpecializedMatrix.pas"/>
    156154        <UnitName Value="SpecializedMatrix"/>
    157         <EditorIndex Value="16"/>
     155        <EditorIndex Value="10"/>
    158156        <WindowIndex Value="0"/>
    159157        <TopLine Value="16"/>
     
    179177      <Unit15>
    180178        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericList.inc"/>
    181         <EditorIndex Value="11"/>
     179        <EditorIndex Value="5"/>
    182180        <WindowIndex Value="0"/>
    183181        <TopLine Value="473"/>
     
    239237      <Unit23>
    240238        <Filename Value="../../../lazarus/lcl/include/lclintfh.inc"/>
    241         <EditorIndex Value="6"/>
    242239        <WindowIndex Value="0"/>
    243240        <TopLine Value="85"/>
    244241        <CursorPos X="10" Y="102"/>
    245242        <UsageCount Value="10"/>
    246         <Loaded Value="True"/>
    247243      </Unit23>
    248244      <Unit24>
    249245        <Filename Value="../../../lazarus/lcl/include/lclintf.inc"/>
    250         <EditorIndex Value="7"/>
    251246        <WindowIndex Value="0"/>
    252247        <TopLine Value="157"/>
    253248        <CursorPos X="3" Y="159"/>
    254249        <UsageCount Value="10"/>
    255         <Loaded Value="True"/>
    256250      </Unit24>
    257251      <Unit25>
     
    275269        <ResourceBaseClass Value="Form"/>
    276270        <UnitName Value="UMapForm"/>
    277         <EditorIndex Value="12"/>
     271        <EditorIndex Value="6"/>
    278272        <WindowIndex Value="0"/>
    279273        <TopLine Value="15"/>
    280         <CursorPos X="1" Y="38"/>
    281         <UsageCount Value="37"/>
     274        <CursorPos X="20" Y="39"/>
     275        <UsageCount Value="39"/>
    282276        <Loaded Value="True"/>
    283277      </Unit27>
     
    305299      <Unit31>
    306300        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericListObject.inc"/>
    307         <EditorIndex Value="17"/>
     301        <EditorIndex Value="11"/>
    308302        <WindowIndex Value="0"/>
    309303        <TopLine Value="1"/>
     
    315309        <Filename Value="../../../lazarus/lcl/intfgraphics.pas"/>
    316310        <UnitName Value="IntfGraphics"/>
    317         <EditorIndex Value="3"/>
    318         <WindowIndex Value="0"/>
    319         <TopLine Value="106"/>
    320         <CursorPos X="30" Y="113"/>
    321         <UsageCount Value="10"/>
    322         <Loaded Value="True"/>
     311        <WindowIndex Value="0"/>
     312        <TopLine Value="3371"/>
     313        <CursorPos X="24" Y="3388"/>
     314        <UsageCount Value="10"/>
    323315      </Unit32>
    324316      <Unit33>
    325317        <Filename Value="/usr/share/fpcsrc/2.4.0/packages/fcl-image/src/fpimage.pp"/>
    326318        <UnitName Value="FPimage"/>
    327         <EditorIndex Value="5"/>
    328319        <WindowIndex Value="0"/>
    329320        <TopLine Value="104"/>
    330321        <CursorPos X="3" Y="91"/>
    331322        <UsageCount Value="10"/>
    332         <Loaded Value="True"/>
    333323      </Unit33>
    334324      <Unit34>
     
    342332        <Filename Value="../../../lazarus/lcl/graphtype.pp"/>
    343333        <UnitName Value="GraphType"/>
    344         <EditorIndex Value="4"/>
    345334        <WindowIndex Value="0"/>
    346335        <TopLine Value="191"/>
    347336        <CursorPos X="3" Y="188"/>
    348337        <UsageCount Value="10"/>
    349         <Loaded Value="True"/>
    350338      </Unit35>
    351339      <Unit36>
    352340        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericBitmap.inc"/>
    353         <UnitName Value="GenericBitmap"/>
    354         <EditorIndex Value="10"/>
     341        <EditorIndex Value="4"/>
    355342        <WindowIndex Value="0"/>
    356343        <TopLine Value="9"/>
     
    362349        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Specialized/SpecializedBitmap.pas"/>
    363350        <UnitName Value="SpecializedBitmap"/>
    364         <EditorIndex Value="8"/>
     351        <EditorIndex Value="2"/>
    365352        <WindowIndex Value="0"/>
    366353        <TopLine Value="3"/>
     
    372359        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Specialized/SpecializedList.pas"/>
    373360        <UnitName Value="SpecializedList"/>
    374         <EditorIndex Value="9"/>
     361        <EditorIndex Value="3"/>
    375362        <WindowIndex Value="0"/>
    376363        <TopLine Value="91"/>
     
    381368      <Unit39>
    382369        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericListString.inc"/>
    383         <EditorIndex Value="15"/>
     370        <EditorIndex Value="9"/>
    384371        <WindowIndex Value="0"/>
    385372        <TopLine Value="1"/>
     
    388375        <Loaded Value="True"/>
    389376      </Unit39>
     377      <Unit40>
     378        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/objpash.inc"/>
     379        <WindowIndex Value="0"/>
     380        <TopLine Value="158"/>
     381        <CursorPos X="23" Y="175"/>
     382        <UsageCount Value="10"/>
     383      </Unit40>
    390384    </Units>
    391     <JumpHistory Count="27" HistoryIndex="26">
     385    <JumpHistory Count="29" HistoryIndex="28">
    392386      <Position1>
    393         <Filename Value="UCore.pas"/>
    394         <Caret Line="615" Column="8" TopLine="607"/>
     387        <Filename Value="UMainForm.pas"/>
     388        <Caret Line="67" Column="6" TopLine="48"/>
    395389      </Position1>
    396390      <Position2>
    397391        <Filename Value="UCore.pas"/>
    398         <Caret Line="634" Column="1" TopLine="607"/>
     392        <Caret Line="126" Column="14" TopLine="109"/>
    399393      </Position2>
    400394      <Position3>
    401395        <Filename Value="UCore.pas"/>
    402         <Caret Line="635" Column="1" TopLine="607"/>
     396        <Caret Line="99" Column="24" TopLine="82"/>
    403397      </Position3>
    404398      <Position4>
    405399        <Filename Value="UCore.pas"/>
    406         <Caret Line="636" Column="1" TopLine="608"/>
     400        <Caret Line="530" Column="28" TopLine="530"/>
    407401      </Position4>
    408402      <Position5>
    409403        <Filename Value="UCore.pas"/>
    410         <Caret Line="637" Column="1" TopLine="609"/>
     404        <Caret Line="99" Column="39" TopLine="95"/>
    411405      </Position5>
    412406      <Position6>
    413407        <Filename Value="UCore.pas"/>
    414         <Caret Line="626" Column="29" TopLine="610"/>
     408        <Caret Line="530" Column="50" TopLine="530"/>
    415409      </Position6>
    416410      <Position7>
    417411        <Filename Value="UCore.pas"/>
    418         <Caret Line="324" Column="21" TopLine="317"/>
     412        <Caret Line="629" Column="24" TopLine="612"/>
    419413      </Position7>
    420414      <Position8>
    421415        <Filename Value="UCore.pas"/>
    422         <Caret Line="432" Column="8" TopLine="417"/>
     416        <Caret Line="98" Column="6" TopLine="93"/>
    423417      </Position8>
    424418      <Position9>
    425419        <Filename Value="UCore.pas"/>
    426         <Caret Line="434" Column="10" TopLine="417"/>
     420        <Caret Line="105" Column="15" TopLine="94"/>
    427421      </Position9>
    428422      <Position10>
    429         <Filename Value="UMainForm.pas"/>
    430         <Caret Line="87" Column="27" TopLine="61"/>
     423        <Filename Value="UCore.pas"/>
     424        <Caret Line="632" Column="59" TopLine="615"/>
    431425      </Position10>
    432426      <Position11>
    433         <Filename Value="UMainForm.pas"/>
    434         <Caret Line="86" Column="27" TopLine="60"/>
     427        <Filename Value="UCore.pas"/>
     428        <Caret Line="634" Column="32" TopLine="616"/>
    435429      </Position11>
    436430      <Position12>
    437         <Filename Value="UMainForm.pas"/>
    438         <Caret Line="87" Column="27" TopLine="61"/>
     431        <Filename Value="UCore.pas"/>
     432        <Caret Line="637" Column="14" TopLine="620"/>
    439433      </Position12>
    440434      <Position13>
    441         <Filename Value="UMainForm.pas"/>
    442         <Caret Line="67" Column="6" TopLine="48"/>
     435        <Filename Value="UCore.pas"/>
     436        <Caret Line="638" Column="38" TopLine="621"/>
    443437      </Position13>
    444438      <Position14>
    445         <Filename Value="UCore.pas"/>
    446         <Caret Line="126" Column="14" TopLine="109"/>
     439        <Filename Value="UMainForm.pas"/>
     440        <Caret Line="174" Column="1" TopLine="153"/>
    447441      </Position14>
    448442      <Position15>
    449         <Filename Value="UCore.pas"/>
    450         <Caret Line="99" Column="24" TopLine="82"/>
     443        <Filename Value="UMainForm.pas"/>
     444        <Caret Line="175" Column="1" TopLine="154"/>
    451445      </Position15>
    452446      <Position16>
    453447        <Filename Value="UCore.pas"/>
    454         <Caret Line="530" Column="28" TopLine="530"/>
     448        <Caret Line="639" Column="38" TopLine="616"/>
    455449      </Position16>
    456450      <Position17>
    457451        <Filename Value="UCore.pas"/>
    458         <Caret Line="99" Column="39" TopLine="95"/>
     452        <Caret Line="634" Column="1" TopLine="622"/>
    459453      </Position17>
    460454      <Position18>
    461455        <Filename Value="UCore.pas"/>
    462         <Caret Line="530" Column="50" TopLine="530"/>
     456        <Caret Line="636" Column="1" TopLine="622"/>
    463457      </Position18>
    464458      <Position19>
    465459        <Filename Value="UCore.pas"/>
    466         <Caret Line="629" Column="24" TopLine="612"/>
     460        <Caret Line="637" Column="1" TopLine="622"/>
    467461      </Position19>
    468462      <Position20>
    469463        <Filename Value="UCore.pas"/>
    470         <Caret Line="98" Column="6" TopLine="93"/>
     464        <Caret Line="638" Column="1" TopLine="622"/>
    471465      </Position20>
    472466      <Position21>
    473467        <Filename Value="UCore.pas"/>
    474         <Caret Line="105" Column="15" TopLine="94"/>
     468        <Caret Line="632" Column="83" TopLine="622"/>
    475469      </Position21>
    476470      <Position22>
    477471        <Filename Value="UCore.pas"/>
    478         <Caret Line="632" Column="59" TopLine="615"/>
     472        <Caret Line="594" Column="41" TopLine="577"/>
    479473      </Position22>
    480474      <Position23>
    481475        <Filename Value="UCore.pas"/>
    482         <Caret Line="634" Column="32" TopLine="616"/>
     476        <Caret Line="641" Column="10" TopLine="612"/>
    483477      </Position23>
    484478      <Position24>
    485479        <Filename Value="UCore.pas"/>
    486         <Caret Line="637" Column="14" TopLine="620"/>
     480        <Caret Line="629" Column="1" TopLine="621"/>
    487481      </Position24>
    488482      <Position25>
    489483        <Filename Value="UCore.pas"/>
    490         <Caret Line="638" Column="38" TopLine="621"/>
     484        <Caret Line="9" Column="54" TopLine="1"/>
    491485      </Position25>
    492486      <Position26>
    493         <Filename Value="UMainForm.pas"/>
    494         <Caret Line="174" Column="1" TopLine="153"/>
     487        <Filename Value="UCore.pas"/>
     488        <Caret Line="628" Column="15" TopLine="622"/>
    495489      </Position26>
    496490      <Position27>
    497         <Filename Value="UMainForm.pas"/>
    498         <Caret Line="175" Column="1" TopLine="154"/>
     491        <Filename Value="UCore.pas"/>
     492        <Caret Line="647" Column="32" TopLine="633"/>
    499493      </Position27>
     494      <Position28>
     495        <Filename Value="UCore.pas"/>
     496        <Caret Line="649" Column="49" TopLine="617"/>
     497      </Position28>
     498      <Position29>
     499        <Filename Value="UMapForm.pas"/>
     500        <Caret Line="39" Column="20" TopLine="15"/>
     501      </Position29>
    500502    </JumpHistory>
    501503  </ProjectOptions>
Note: See TracChangeset for help on using the changeset viewer.