
    8JjC.                        d Z ddlmZ ddlZddlmZ ddlmZ  ee      j                         j                  d   Zedz  ZddZdd	Zdd
ZddZedk(  r e e             y)a:  Build a compact field-vs-battle render pipeline model review.

This report does not introduce a new speculative renderer.  It consolidates
already-grounded DirectDraw, field tile redraw, and battle helper/object evidence
into one active artifact so later CNS rect/source-rect work can share the same
mental model.
    )annotationsN)Path)Any   outc                    t         | z  }|j                         sdd|  dS t        j                  |j	                  d            S )NTout/)missingpathutf-8encoding)OUTexistsjsonloads	read_text)namer   s     +tools/build_render_pipeline_model_review.py	read_jsonr      s?    :D;;=4v77::dnngn677    c                    d|  |j                  d       |j                  d      |j                  d      xs |j                  d      dS )Nr	   r
   kindstatuspromotionStatus)r   r   r   r   )get)r   payloads     r   artifact_statusr      sK    tfkk),,F#++h'I7;;7H+I	 r   c                 ,   t        d      } t        d      }t        d      }t        d      }t        d      }| j                  d      xs i }| j                  d      xs i }|j                  d      xs i }|j                  d      xs i }|j                  d      xs i }	|j                  d      xs i }
| j                  d	      xs g }|D cg c]  }|j                  d
      du s| }}ddg ddddd|j                  d      xs dt        |      t        |      d|j                  d      |	j                  d      |	j                  d      |	j                  d      |
j                  d      dddt        d|       t        d|      t        d|      t        d|      t        d|      gd|j                  d      xs d|j                  d      xs g d d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d2d5d6d2d7d8d2d9d:d2d;d<d2gd=d>d?d@dA|j                  dB      |j                  dC      |j                  dD      |j                  dE      |j                  dF      dGdHdIdJdKdLdMdNdOdPdQdRdSdTd2dUdVd2dWdXd2dYdZd2g|	j                  d      |	j                  d[      |	j                  d      |	j                  d\      |	j                  d      |	j                  d]      |
j                  d^      |
j                  d_      d`dadbdcdddedfdgdedhdidedjdkdegdl	S c c}w )mNzdirectdraw_flow.jsonz)map_animation_redraw_consumer_review.jsonz-map_animation_draw_tile_transform_review.jsonz battle_effect_object_review.jsonz-battle_child_lifecycle_draw_order_review.jsonsurfacesverificationsummaryvtableCallsverifiedTz#hwanse-render-pipeline-model-reviewz"field-battle-render-model-grounded)zout/directdraw_flow.jsonz-out/map_animation_redraw_consumer_review.jsonz1out/map_animation_draw_tile_transform_review.jsonz$out/battle_effect_object_review.jsonz1out/battle_child_lifecycle_draw_order_review.jsonz(docs/map3_active_object_overlay_notes.mdzdocs/DIRECTDRAW_NOTES.md	640x480x8z$DirectDraw surface/palette copy pathz437x21 visible tile grid plus dirty/occlusion bufferszBactive object/sprite/effect display objects over battle backgroundsurfaceTableBaseHex
0x0055abd8zLconfirmed redraw invalidation consumer; visible frame producer still unbound#drawTimeVisibleMotionTransformFoundhelpershelpersWithSpawnTreehelpersWithMotionSteptotalDirectSpawnEvents)r)   r*   r+   r,   zTransparency must be tracked as draw-call/context state.  A source CNS transparent color alone is not sufficient unless the Blt/BltFast path requests source color key handling.)displayResolutionsharedApiSurfacefieldDrawUnitbattleDrawUnitsurfaceWrapperTabledirectDrawVerifiedCallCountdirectDrawTotalCallCountfieldAnimatedFlag0x40MeaningfieldDrawTimeTileTransformFoundbattleHelperCoveragecolorKeyConclusionzgrounded-call-surfaceprimarySurfaceSlotsz640, 480, 8z%primary/offscreen/backbuffer wrappersz256-entry palette pathz/fullscreen and copy/windowed presentation paths)SetDisplayModeCreateSurfacez#CreatePalette/SetPalette/SetEntrieszFlip/BltzThis proves the Win32/DirectDraw presentation surface, not the full game-engine draw ordering. Field and battle diverge before these DirectDraw calls.)evidenceStatusr1   primarySlotsconfirmedMethodsboundaryz&tilemap-dirty-render-consumer-groundedz%tile row renderer over 37x21 viewportz0x005957d0 + y * 37 + xz0x0058d7d0 + index * 2z0x00595af0 + index * 2
0x004576dc
0x004576de
0x00595ada)dirtyVisibleGridliveLayer1FlagsliveLayer0TileIdsviewXviewYmapWidth
0x00425403z"37x21 viewport dirty scan wrapper.)vaHexmeaning
0x00425494z/Reads layer1 flags and tests low byte bit 0x40.
0x004254a5z0Marks matching visible dirty cell with bit 0x01.
0x00425163z.Dirty row renderer reads live layer0 tile ids.
0x004175d3zKPacks draw descriptor into temporary object +0x28 and x/y into +0x1c/+0x20.
0x004199a0zUConverts low-word tile/frame index to source rect using wrapper width/height/columns.zsprite/tile cell widthzsprite/tile cell heightcolumnszgroup table candidate)z+0x2ez+0x30z+0x32z+0x34usesLayer1AnimatedFlag0x40usesFrameCounterusesPerMapAnimationSequencealternateTileSelectionFoundvisibleMotionProducerFound)drawTimeUsesLayer1Flag0x40drawTimeUsesFrameCounter#drawTimeUsesPerMapAnimationSequence+alternateTileSelectionFoundInRedrawConsumer*visibleMotionProducerFoundInRedrawConsumerzField animation flag 0x40 is a redraw invalidation/input to dirty rendering.  The visible motion source is still not proven in the generic tile converter; if motion is tile-id based, a producer must mutate 0x00595af0 before redraw.)r;   drawUnitglobalsconfirmedStepswrapperFieldsnegativeEvidencecurrentConclusionz#object-sprite-helper-model-groundedz:active object / battle actor / helper child display object
0x0055a800z0x0055abd8 + slot * 4zPpacked draw-source selector; low word frame/source index, high word surface slotzprojected x, fixed 16.16zprojected y, fixed 16.16zEdraw/object flags candidate; exact bit roles still need focused proof)currentObjectr1   zobject+0x28zobject+0x1czobject+0x20zobject+0x2c
0x00416ce2z+Common active-object rect/draw-source path.z0x00416ceb..0x00416cf6z8Uses object+0x28 low word as source rect/frame selector.z0x00416cf9..0x00416d07zBUses object+0x28 high word as surface slot and indexes 0x0055abd8.z0x00416d11..0x00416d3dz5Uses object+0x1c/+0x20 as projected draw coordinates.helpersWithDirectFrameScripthelpersWithRandomRangeframeScriptSpriteCountsrendererReadinessCountsdrawOrderStatusCounts)r)   rd   r*   re   r+   rf   rg   rh   zBattle rendering is not a visible tile grid pass.  It composes a battle background and object/helper frame streams, with source selection routed through object+0x28 and surface wrapper metadata.)r;   r[   globalsAndFieldsr]   helperEvidencer`   zfield animation producerzSearch for live layer0 0x00595af0 mutation tied to map tick/frame counter, or prove a specialized draw path outside 0x004199a0.)areaworkzwrapper validationzoDump wrapper +0x2e/+0x30/+0x32/+0x34 for loaded CNS slots and compare against the CNS rect/source-rect catalog.zdraw flags / color keyz~Decode object+0x2c and Blt/BltFast flag consumers to separate opaque copy, source-color-key copy, and palette/context effects.zbattle object placementzKeep battle actor/helper position opcodes separate from field tilemap placement; do not reuse map_*3 assumptions for battle effects.)	r   r   sourcer"   artifactStatusessharedDirectDrawModelfieldPipelinebattlePipelinenextFrontier)r   r   lenr   )
directdrawredrawdraw_transformbattle_objectbattle_lifecycledirectdraw_surfacesdirectdraw_verificationredraw_summarytransform_summarybattle_object_summarybattle_lifecycle_summarydirectdraw_callsrowdirectdraw_verified_callss                 r   build_reportr   $   s:   12JBCFNON@AM !PQ$..4:(nn^<BZZ	*0bN&**95;)--i8>B/33I>D"!~~m4:0@ `CGGJDW[_D_ ` ` 66
 "- FSb#6#:#:;P#Q#aUa+./H+I(+,<(=,z/@/D/DEj/k044Y?(=(A(ABX(Y)>)B)BCZ)[*B*F*FG_*`	%R#
, 2J?GPK^\>NKM]^
 6#6#:#:;P#Q#aUa/334IJPb"/!H7OM	!J"
  G?$=#;%=%%( *C
 *P
 *Q
 *O
 *l
 *v+6 22"0	 /@.C.CD`.a,=,A,ABT,U7H7L7LMj7k?M?Q?QRo?p>L>P>PQm>n!Eg6
p DT!-'>q99f! *L
 6Y
 6c
 6V& 144Y?0E0I0IJh0i(=(A(ABX(Y*?*C*CD\*])>)B)BCZ)[+@+D+DE^+_+C+G+GHa+b)A)E)EF])^	aQ+
\ 3 Z
 - J
 1 Y
 2 _
ul l !as   L(Lc                    t         j                  d       t               } t         dz  j                  t	        j
                  | dd      dz   d	       t        d
       t        t	        j
                  | d   dd             y)NT)exist_okz!render_pipeline_model_review.jsonF   )ensure_asciiindent
r   r   zrender_pipeline_model_review okr"   r   )r   mkdirr   
write_textr   dumpsprint)reports    r   mainr      sp    IItI^F..::

6a84? ;  

+,	$**VI&U1
EFr   __main__)r   strreturndict[str, Any])r   r   r   r   r   r   )r   r   )r   int)__doc__
__future__r   r   pathlibr   typingr   __file__resolveparentsROOTr   r   r   r   r   __name__
SystemExit r   r   <module>r      sr    #    H~''*
Ul8|~	 z
TV
 r   