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;
}
}