Thanks for visualizing that. I never thought of doing that and it helped a good bit to show me that i really need to reverse the tiles array.

As for OpenGL primitives, they won't be much help to me anyhow. Each tile can be a variety of things, either a full cube, a ramp, stairs, a door, a tree, etc. As such i'll need to construct objects for each tile anyhow, and what makes it worse: The exact visual of each tile is highly dependant on the tiles around it, for example in the case of ramps.

As for the type constant: Each tile actually has 3 datasets. The type, which consists of two bytes, and binary flags for designation and occupation, which are stored in 4 byte values. Right now i'm ignoring those, but later on i'll need to add them in, and i figured there won't be much of a difference between doing it as pseudo-hash built by using constants or by creating 3 arrays for each of these datasets.

"then you could do the assignments using array slices 16 values at a time."
I'm not 100% sure what you mean by this, but it denotes some kind of bulk operation, right? I'm not too sure that that would be very useful, given that i don't only need to transfer the data, but also need to check whether the input data is different than the already existing data.

This may help a bit in understanding it: http://i34.tinypic.com/20j2pep.jpg

Update: Argh, changing around got it to $tiles[$bz][type][$rx][$ry] now, but can't figure out a good way how to swap x and y, as that turns the cells by 90° and would need correction ... somewhere else too.

Update 2: I was being stupid and shouldn't have changed the order of parameters in the function that actually draws the tile. The code looks as follows now:
my ($rx,$ry,$y,$x,$xScaled); my $bxScaled = $bx * 16; my $byScaled = $by * 16; my $tile_index=0; my (@realx,@realy); for $x ( 0..15 ) { $rx = $bxScaled+$x; for $y ( 0..15 ) { $ry = $byScaled+$y; if ( !defined $tiles[$bz][type][$ry][$rx] || $tiles[$bz][type][$ry][$rx] != $type_data[$tile_index] ) { $changed = 1; $tiles[$bz][type][$ry][$rx] = $type_data[$tile_index]; } ++$tile_index; } }
Next step will be to play around with getting the reference to either $tiles[$bz][type] or $tiles[$bz][type][$by] at the appropiate places and see if that gives some kind of speed-up.

Update 3: Damn, references actually give me a speed boost of 40% over what we already head. Right now i'm only wondering if there is a visually more pleasing way to dereference that.
my ($rx,$ry,$y,$x,$xScaled); my $bxScaled = $bx * 16; my $byScaled = $by * 16; my $tile_index=0; my (@realx,@realy); my $tile = \$tiles[$bz][type]; for $x ( 0..15 ) { $rx = $bxScaled+$x; for $y ( 0..15 ) { $ry = $byScaled+$y; if ( !defined $$tile->[$ry][$rx] || $$tile->[$ry][$rx] != $type_data[$tile_index] ) { $changed = 1; $$tile->[$ry][$rx] = $type_data[$tile_index]; } ++$tile_index; } }

In reply to Re^2: How to speed up a nested loop? by Xenofur
in thread How to speed up a nested loop? by Xenofur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.