screp --act to create an animated image of replay actions
authorShiar <shiar@shiar.org>
Wed, 14 Nov 2007 07:55:33 +0000 (08:55 +0100)
committerShiar <shiar@shiar.org>
Tue, 27 Nov 2007 19:23:54 +0000 (20:23 +0100)
Creates an animated GIF using GD, with pixels set at move/attack/builds
locations for each player per time period. Could use some love.

screp

diff --git a/screp b/screp
index 93eb14fe56449aaf977e6663cc2b70839a182a0e..5e754adaaa9e34826c4f31262a4b63be9e7d4cee 100755 (executable)
--- a/screp
+++ b/screp
@@ -4,12 +4,14 @@ use warnings;
 use Data::Dumper;
 
 my $SHOWWARN = 0;
+my $ACTGIF = undef;
 my $APMSVG = undef;
 
 use Getopt::Long;
 GetOptions(
        "verbose|v!" => \$SHOWWARN,
        "apm|a=s" => \$APMSVG,
+       "act" => \$ACTGIF,
 );
 
 use constant { APM_FIRSTFRAME => 80 / .042 };
@@ -559,6 +561,53 @@ for my $player (sort keys %stats) {
        ) if 0;
 }
 
+if ($ACTGIF) {
+       open my $imgfile, '>', "test.gif" or die;
+       binmode $imgfile;
+       select $imgfile;
+
+       use GD;
+       my $ani = GD::Image->new($head->{width}, $head->{height});
+       my $bg = $ani->colorAllocate(0, 0, 0);
+       my @plot = (
+               $ani->colorAllocate(255, 0, 0),
+               $ani->colorAllocate(255, 255, 0),
+               $ani->colorAllocate(0, 255, 0),
+               $ani->colorAllocate(0, 255, 255),
+               $ani->colorAllocate(0, 0, 255),
+               $ani->colorAllocate(255, 0, 255),
+       );
+
+       print $ani->gifanimbegin;
+#      print $ani->gifanimadd;
+       {
+               my $frame = GD::Image->new($ani->getBounds);
+               print $frame->gifanimadd;
+               my $length = 30 / .042;
+               my $last = 0;
+               for (@$map) {
+                       my ($time, $player, $cmd, @data) = @$_;
+#$time < $length * 10 or last;
+                       while ($time > $last + $length) {
+                               $last += $length;
+                               print $frame->gifanimadd(0, 0, 0, 32);
+#                              $frame = GD::Image->new($ani->getBounds);
+                       }
+                       if ($cmd eq "build") {
+                               $frame->setPixel($data[1]>>5, $data[2]>>5, $plot[$player]);
+                       }
+                       elsif ($cmd eq "move" or $cmd eq "attack") {
+                               $frame->setPixel($data[0]>>5, $data[1]>>5, $plot[$player]);
+#                                      if $data[2] == 0xFFFF_FFFF;
+                       }
+               }
+#              add_frame_data($frame);
+               print $frame->gifanimadd;
+       }
+       print $ani->gifanimend;
+       select STDOUT;
+}
+
 if ($APMSVG) {
        my @seq;  # player => time (s) => actions
        $seq[$_->[1]][$_->[0] * .042]++ for @$map;