ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.108 by root, Wed Apr 25 01:12:31 2007 UTC vs.
Revision 1.111 by root, Thu Jul 19 14:54:50 2007 UTC

22 my $self = $class->SUPER::new ( 22 my $self = $class->SUPER::new (
23 z => -1, 23 z => -1,
24 can_focus => 1, 24 can_focus => 1,
25 list => glGenList, 25 list => glGenList,
26 tilesize => 32, 26 tilesize => 32,
27
28 smooth_matrix => [
29 0.05, 0.13, 0.05,
30 0.13, 0.30, 0.13,
31 0.05, 0.13, 0.05,
32 ],
33
34 @_ 27 @_
35 ); 28 );
36 29
37 $self->{completer} = new CFPlus::MapWidget::Command:: 30 $self->{completer} = new CFPlus::MapWidget::Command::
38 command => $self->{command}, 31 command => $self->{command},
430 } 423 }
431 424
432 $res 425 $res
433} 426}
434 427
428sub invoke_visibility_change {
429 my ($self) = @_;
430
431 $self->refresh_hook;
432
433 0
434}
435
435sub set_magicmap { 436sub set_magicmap {
436 my ($self, $w, $h, $x, $y, $data) = @_; 437 my ($self, $w, $h, $x, $y, $data) = @_;
437 438
438 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; 439 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
439 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; 440 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
441 $self->{magicmap} = [$x, $y, $w, $h, $data]; 442 $self->{magicmap} = [$x, $y, $w, $h, $data];
442 443
443 $self->update; 444 $self->update;
444} 445}
445 446
446sub draw { 447sub refresh_hook {
447 my ($self) = @_; 448 my ($self) = @_;
448 449
449 return unless $::MAP; 450 return unless $::MAP;
450
451 my $focused = $CFPlus::UI::FOCUS == $self
452 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
453
454 return
455 unless $focused || !$::FAST;
456 451
457 if (delete $self->{need_update}) { 452 if (delete $self->{need_update}) {
458 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 453 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
459 454
460 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 455 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
469 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 464 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
470 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; 465 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
471 466
472 if ($::CFG->{fow_enable}) { 467 if ($::CFG->{fow_enable}) {
473 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); 468 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
474
475 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
476 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
477 glConvolutionFilter2D (
478 GL_CONVOLUTION_2D,
479 GL_ALPHA,
480 3, 3,
481 GL_ALPHA, GL_FLOAT,
482 (pack "f*", @{ $self->{smooth_matrix} }),
483 );
484 glEnable GL_CONVOLUTION_2D;
485 }
486 469
487 $self->{fow_texture} = new CFPlus::Texture 470 $self->{fow_texture} = new CFPlus::Texture
488 w => $w, 471 w => $w,
489 h => $h, 472 h => $h,
490 data => $data, 473 data => $data,
491 internalformat => GL_ALPHA, 474 internalformat => GL_ALPHA,
492 format => GL_ALPHA; 475 format => GL_ALPHA;
493
494 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
495 } else { 476 } else {
496 delete $self->{fow_texture}; 477 delete $self->{fow_texture};
497 } 478 }
498 479
499 glNewList $self->{list}; 480 glNewList $self->{list};
505 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); 486 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
506 487
507 glScale $self->{tilesize}, $self->{tilesize}; 488 glScale $self->{tilesize}, $self->{tilesize};
508 489
509 if (my $tex = $self->{fow_texture}) { 490 if (my $tex = $self->{fow_texture}) {
491 glPushMatrix;
492 glScale 1/3, 1/3;
510 glEnable GL_TEXTURE_2D; 493 glEnable GL_TEXTURE_2D;
511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 494 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
512 495
513 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 496 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
514 $self->{fow_texture}->draw_quad_alpha (0, 0); 497 $self->{fow_texture}->draw_quad_alpha (0, 0);
515 498
516 glDisable GL_TEXTURE_2D; 499 glDisable GL_TEXTURE_2D;
500 glPopMatrix;
517 } 501 }
518 502
519 if ($self->{magicmap}) { 503 if ($self->{magicmap}) {
520 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 504 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
521 505
528 } 512 }
529 513
530 glPopMatrix; 514 glPopMatrix;
531 glEndList; 515 glEndList;
532 } 516 }
517
518}
519
520sub draw {
521 my ($self) = @_;
522
523 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
524
525 return unless $self->{list};
526
527 my $focused = $CFPlus::UI::FOCUS == $self
528 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
529
530 return
531 unless $focused || !$::FAST;
533 532
534 glCallList $self->{list}; 533 glCallList $self->{list};
535 534
536 # TNT2 emulates logops in software (or worse :) 535 # TNT2 emulates logops in software (or worse :)
537 unless ($focused) { 536 unless ($focused) {
565 564
566use Time::HiRes qw(time); 565use Time::HiRes qw(time);
567use CFPlus::OpenGL; 566use CFPlus::OpenGL;
568 567
569sub size_request { 568sub size_request {
570 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 569 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
571} 570}
572 571
573sub invoke_size_allocate { 572sub refresh_hook {
574 my ($self, $w, $h) = @_; 573 my ($self) = @_;
575 574
576 $self->update; 575 if ($::MAP && $self->{texture_atime} < time) {
577
578 1
579}
580
581sub update {
582 my ($self) = @_;
583
584 delete $self->{texture_atime};
585 $self->SUPER::update;
586}
587
588sub _draw {
589 my ($self) = @_;
590
591 $::MAP or return;
592
593 my ($w, $h) = @$self{qw(w h)}; 576 my ($w, $h) = @$self{qw(w h)};
594 577
595 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 578 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
596 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 579 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
597 580
581 my $ox = 0.5 * ($w - $sw);
582 my $oy = 0.5 * ($h - $sh);
583
598 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; 584 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
599 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; 585 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
600 586
601 my $ox = 0.5 * ($w - $sw); 587 #TODO: map scale is completely borked
602 my $oy = 0.5 * ($h - $sh);
603 588
604 glEnable GL_BLEND; 589 my $x0 = int $ox - $sx + 0.5;
605 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 590 my $y0 = int $oy - $sy + 0.5;
606 glEnable GL_TEXTURE_2D;
607 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
608 591
609 if ($self->{texture_atime} < time) { 592 $self->{sw} = $sw;
593 $self->{sh} = $sh;
594
595 $self->{x0} = $x0;
596 $self->{y0} = $y0;
597
610 $self->{texture_atime} = time + 1/3; 598 $self->{texture_atime} = time + 1/3;
611 599
612 $self->{texture} = 600 $self->{texture} =
613 new CFPlus::Texture 601 new CFPlus::Texture
614 w => $w, 602 w => $w,
615 h => $h, 603 h => $h,
616 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 604 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
617 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 605 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
618 } 606 }
607}
608
609sub invoke_visibility_change {
610 my ($self) = @_;
611
612 $self->refresh_hook;
613
614 0
615}
616
617sub invoke_size_allocate {
618 my ($self, $w, $h) = @_;
619
620 $self->update;
621
622 1
623}
624
625sub update {
626 my ($self) = @_;
627
628 delete $self->{texture_atime};
629 $self->SUPER::update;
630}
631
632sub _draw {
633 my ($self) = @_;
634
635 $self->{root}->on_post_alloc (texture => sub { $self->refresh_hook });
636
637 $self->{texture} or return;
638
639 glEnable GL_BLEND;
640 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
641 glEnable GL_TEXTURE_2D;
642 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
619 643
620 $self->{texture}->draw_quad (0, 0); 644 $self->{texture}->draw_quad (0, 0);
621 645
622 glDisable GL_TEXTURE_2D; 646 glDisable GL_TEXTURE_2D;
623 647
624 glTranslate 0.375, 0.375; 648 glTranslate 0.375, 0.375;
625
626 #TODO: map scale is completely borked
627
628 my $x0 = int $ox - $sx + 0.5;
629 my $y0 = int $oy - $sy + 0.5;
630 649
631 glColor 1, 1, 0, 1; 650 glColor 1, 1, 0, 1;
632 glBegin GL_LINE_LOOP; 651 glBegin GL_LINE_LOOP;
633 glVertex $x0 , $y0 ; 652 glVertex $self->{x0} , $self->{y0} ;
634 glVertex $x0 , $y0 + $sh; 653 glVertex $self->{x0} , $self->{y0} + $self->{sh};
635 glVertex $x0 + $sw, $y0 + $sh; 654 glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh};
636 glVertex $x0 + $sw, $y0 ; 655 glVertex $self->{x0} + $self->{sw}, $self->{y0} ;
637 glEnd; 656 glEnd;
638 657
639 glDisable GL_BLEND; 658 glDisable GL_BLEND;
640} 659}
641 660

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines