ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/game.pl
(Generate patch)

Comparing kgsueme/kgsueme/game.pl (file contents):
Revision 1.26 by pcg, Sun Jun 1 13:09:47 2003 UTC vs.
Revision 1.27 by pcg, Sun Jun 1 15:43:01 2003 UTC

44 44
45 $self->{set} = sub { $self->{time} = $_[0] }; 45 $self->{set} = sub { $self->{time} = $_[0] };
46 46
47 $self->{format} = sub { 47 $self->{format} = sub {
48 if ($_[0] > $low) { 48 if ($_[0] > $low) {
49 format_time $_[0]; 49 format_time $_[0] - $low;
50 } else { 50 } else {
51 sprintf "%s (%d)", (format_time int ($_[0] % $interval) || $interval), $_[0] / $interval; 51 sprintf "%s (%d)", (format_time int ($_[0] % $interval) || $interval), $_[0] / $interval;
52 } 52 }
53 }; 53 };
54 54
57 57
58 $self->{set} = sub { $self->{time} = $_[0]; $self->{moves} = $_[1] }; 58 $self->{set} = sub { $self->{time} = $_[0]; $self->{moves} = $_[1] };
59 59
60 $self->{format} = sub { 60 $self->{format} = sub {
61 if ($_[0] > $low) { 61 if ($_[0] > $low) {
62 format_time $_[0]; 62 format_time $_[0] - $low;
63 } else { 63 } else {
64 sprintf "%s / %d", (format_time int($_[0] % $interval) || $interval), $self->{moves}; 64 sprintf "%s / %d", (format_time int($_[0] % $interval) || $interval), $self->{moves};
65 } 65 }
66 }; 66 };
67 67
81} 81}
82 82
83sub set_time { 83sub set_time {
84 my ($self, $time) = @_; 84 my ($self, $time) = @_;
85 85
86 $self->{start} = $time->[0]; 86 # we ignore requests to re-set the time of a running clock.
87 # this is the easiest way to ensure that commentary etc.
88 # doesn't re-set the clock. yes, this is frickle design,
89 # but I think the protoocl is to blame here, which gives
90 # very little time information. (cgoban2 also has had quite
91 # a lot of small time update problems...)
92 unless ($self->{timeout}) {
87 $self->{set}->($time->[1], $time->[2]); 93 $self->{set}->($time->[0], $time->[1]);
88 94 $self->refresh ($self->{start});
89 $self->refresh ($time->[0]); 95 }
90} 96}
91 97
92sub start { 98sub start {
93 my ($self) = @_; 99 my ($self) = @_;
94 100
95 return if $self->{timeout}; 101 return if $self->{timeout};
96 102
103 # this is correct, since we assume the last message triggered a start
104 $self->{start} = $KGS::Protocol::NOW;
105
97 my $timeout; $timeout = sub { 106 my $timeout; $timeout = sub {
107 # -100 means we run the timer a bit earlier to avoid 10.99 => 10s roundings.
108 # we "could" cheat by precalculating the time, but I feel uneasy about both
109 # ways to cheat.
98 my $next = int ($self->refresh (Time::HiRes::time) * 1000); 110 my $next = int ($self->refresh (Time::HiRes::time) * 1000) - 100;
111 $next += 1000 if $next < 0;
99 $self->{timeout} = add Glib::Timeout $next, $timeout; 112 $self->{timeout} = add Glib::Timeout $next, $timeout;
100 0; 113 0;
101 }; 114 };
102 115
103 $timeout->(); 116 $timeout->();
152} 165}
153 166
154sub set_state { 167sub set_state {
155 my ($self, $captures, $timer, $running) = @_; 168 my ($self, $captures, $timer, $running) = @_;
156 169
170 $self->{clock}->stop unless $running;
157 $self->{clock}->set_time ($timer); 171 $self->{clock}->set_time ($timer);
158 $running ? $self->{clock}->start : $self->{clock}->stop; 172 $self->{clock}->start if $running;
173
159 $self->{info}->set_text ("$captures pris."); 174 $self->{info}->set_text ("$captures pris.");
160} 175}
161 176
162package game; 177package game;
163 178
334 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) { 349 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) {
335 my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 0x00000000; 350 my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 0x00000000;
336 351
337 # zeroeth the shadow 352 # zeroeth the shadow
338 if ($mark & (MARK_B | MARK_W)) { 353 if ($mark & (MARK_B | MARK_W)) {
354 # the -0.5's are a mystery to me
339 $::shadow_img->composite ( 355 $::shadow_img->composite (
340 $base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5, 356 $base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5,
341 $size / $stone->get_width, $size / $stone->get_height, 357 $size / $::shadow_img->get_width, $size / $::shadow_img->get_height,
342 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 358 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
343 ); 359 );
344 } 360 }
345 361
346 # first the big stones (handicap stones different for effect) 362 # first the big stones (handicap stones different for effect)
362 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]], 378 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]],
363 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) { 379 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) {
364 my ($mask, $img) = @$_; 380 my ($mask, $img) = @$_;
365 if ($mark & $mask) { 381 if ($mark & $mask) {
366 $img->composite ( 382 $img->composite (
367 $base, (ceil ($size / 4)) x2, (ceil ($size / 2)) x2, (ceil ($size / 4)) x2, 383 $base, (int ($size / 4)) x2, (ceil ($size / 2 + 1)) x2, ($size / 4) x2,
368 $size / $img->get_width / 2, $size / $img->get_height / 2, 384 $size / $img->get_width / 2, $size / $img->get_height / 2,
369 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224 385 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224
370 ); 386 );
371 } 387 }
372 } 388 }
378 [MARK_TRIANGLE, $::triangle_img[$dark_bg]], 394 [MARK_TRIANGLE, $::triangle_img[$dark_bg]],
379 [MARK_SQUARE, $::square_img[$dark_bg]]) { 395 [MARK_SQUARE, $::square_img[$dark_bg]]) {
380 my ($mask, $img) = @$_; 396 my ($mask, $img) = @$_;
381 if ($mark & $mask) { 397 if ($mark & $mask) {
382 $img->composite ( 398 $img->composite (
383 $base, 0, 0, $size, $size, -0.5, -0.5, 399 $base, 0, 0, $size, $size, 0, 0,
384 $size / $img->get_width, $size / $img->get_height, 400 $size / $img->get_width, $size / $img->get_height,
385 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255 401 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
386 ); 402 );
387 } 403 }
388 } 404 }
389 405
390 push @$$c, $base; 406 push @$$c, $base;
476 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0); 492 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
477 } else { 493 } else {
478 $pixbuf = scale_pixbuf $::board_img, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_TILES; 494 $pixbuf = scale_pixbuf $::board_img, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_TILES;
479 } 495 }
480 496
481 my $linew = int ($s / 25 / $size); 497 my $linew = int ($s / 40 / $size);
482 498
483 # ornamental border... we have time to waste :/ 499 # ornamental border... we have time to waste :/
484 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $s-1, $linew, 255; 500 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $s-1, $linew, 255;
485 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $s-1, 255; 501 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $s-1, 255;
486 pixbuf_rect $pixbuf,0xffcc7700, $s-$linew-1, 0, $s-1, $s-1, 255; 502 pixbuf_rect $pixbuf, 0xffcc7700, $s-$linew-1, 0, $s-1, $s-1, 255;
487 pixbuf_rect $pixbuf,0xffcc7700, 0, $s-$linew-1, $s-1, $s-1, 255; 503 pixbuf_rect $pixbuf, 0xffcc7700, 0, $s-$linew-1, $s-1, $s-1, 255;
488 504
489 for my $i (1 .. $size) { 505 for my $i (1 .. $size) {
490 pixbuf_rect $pixbuf, 0x44111100, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew, 192; 506 pixbuf_rect $pixbuf, 0x44111100, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew, 192;
491 pixbuf_rect $pixbuf, 0x44111100, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew, 192; 507 pixbuf_rect $pixbuf, 0x44111100, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew, 192;
492 508
499 pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1; 515 pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1;
500 pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1; 516 pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1;
501 517
502 $a++; 518 $a++;
503 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... 519 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
520 }
521
522 # hoshi points
523 my $hoshi = sub {
524 my ($x, $y) = @_;
525 my $hs = int ($edge / 4) | 1;
526 $x = $k[$x] - $hs / 2; $y = $k[$y] - $hs / 2;
527
528 # we use the shadow mask... not perfect, but I want to finish this
529 $::shadow_img->composite ($pixbuf,
530 $x, $y, $hs + 1, $hs + 1, $x, $y,
531 $hs / $::shadow_img->get_width, $hs / $::shadow_img->get_height,
532 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255);
533 };
534
535 my $h1 = $size < 10 ? 3 : 4; # corner / edge offset
536 $hoshi->($h1, $h1);
537 $hoshi->($size - $h1 + 1, $h1);
538 $hoshi->($h1, $size - $h1 + 1);
539 $hoshi->($size - $h1 + 1, $size - $h1 + 1);
540
541 if ($size % 2) { # on odd boards, also the remaining 5
542 my $h2 = ($size + 1) / 2;
543 if ($size > 10) {
544 $hoshi->($h1, $h2);
545 $hoshi->($size - $h1 + 1, $h2);
546 $hoshi->($h2, $size - $h1 + 1);
547 $hoshi->($h2, $h1);
548 }
549 # the tengen
550 $hoshi->($h2, $h2);
504 } 551 }
505 552
506 unless ($::config->{conserve_memory} > 1) { 553 unless ($::config->{conserve_memory} > 1) {
507 $self->{background} = $pixbuf; 554 $self->{background} = $pixbuf;
508 $pixbuf = $pixbuf->copy; 555 $pixbuf = $pixbuf->copy;
557 } 604 }
558 pixbuf_text $pixbuf, $white, 605 pixbuf_text $pixbuf, $white,
559 $k[$x], $k[$y], $ofs * 0.7, 606 $k[$x], $k[$y], $ofs * 0.7,
560 $self->{board}{label}[$x-1][$y-1]; 607 $self->{board}{label}[$x-1][$y-1];
561 } 608 }
562
563 # old pixmap&mask-way. that was fast ;(
564 #my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 );
565
566 #$gc->set_clip_mask ($bm);
567 #$gc->set_clip_origin ($dx, $dy);
568 #$pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge);
569 } 609 }
570 } 610 }
571 } 611 }
572 612
573 $self->{board_shown} = Storable::dclone $self->{board}; 613 $self->{board_shown} = Storable::dclone $self->{board};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines