… | |
… | |
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.30, 0.50, 0.30, |
|
|
30 | 0.50, 0.50, 0.50, |
|
|
31 | 0.30, 0.50, 0.30, |
|
|
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 | |
|
|
428 | sub invoke_visibility_change { |
|
|
429 | my ($self) = @_; |
|
|
430 | |
|
|
431 | $self->refresh_hook; |
|
|
432 | |
|
|
433 | 0 |
|
|
434 | } |
|
|
435 | |
435 | sub set_magicmap { |
436 | sub 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 | |
446 | sub draw { |
447 | sub 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; |
… | |
… | |
468 | |
463 | |
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 ( |
468 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
474 | $dx, $dy, $sw, $sh, |
|
|
475 | $::CFG->{fow_smooth}, |
|
|
476 | pack "f*", @{ $self->{smooth_matrix} }, |
|
|
477 | ); |
|
|
478 | |
469 | |
479 | $self->{fow_texture} = new CFPlus::Texture |
470 | $self->{fow_texture} = new CFPlus::Texture |
480 | w => $w, |
471 | w => $w, |
481 | h => $h, |
472 | h => $h, |
482 | data => $data, |
473 | data => $data, |
… | |
… | |
496 | |
487 | |
497 | glScale $self->{tilesize}, $self->{tilesize}; |
488 | glScale $self->{tilesize}, $self->{tilesize}; |
498 | |
489 | |
499 | if (my $tex = $self->{fow_texture}) { |
490 | if (my $tex = $self->{fow_texture}) { |
500 | glPushMatrix; |
491 | glPushMatrix; |
501 | #glScale 1/3, 1/3 if $::CFG->{fow_smooth}; |
492 | glScale 1/3, 1/3; |
502 | glEnable GL_TEXTURE_2D; |
493 | glEnable GL_TEXTURE_2D; |
503 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
494 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
504 | |
495 | |
505 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
496 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
506 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
497 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
… | |
… | |
521 | } |
512 | } |
522 | |
513 | |
523 | glPopMatrix; |
514 | glPopMatrix; |
524 | glEndList; |
515 | glEndList; |
525 | } |
516 | } |
|
|
517 | |
|
|
518 | } |
|
|
519 | |
|
|
520 | sub 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; |
526 | |
532 | |
527 | glCallList $self->{list}; |
533 | glCallList $self->{list}; |
528 | |
534 | |
529 | # TNT2 emulates logops in software (or worse :) |
535 | # TNT2 emulates logops in software (or worse :) |
530 | unless ($focused) { |
536 | unless ($focused) { |
… | |
… | |
558 | |
564 | |
559 | use Time::HiRes qw(time); |
565 | use Time::HiRes qw(time); |
560 | use CFPlus::OpenGL; |
566 | use CFPlus::OpenGL; |
561 | |
567 | |
562 | sub size_request { |
568 | sub size_request { |
563 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
569 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
564 | } |
570 | } |
565 | |
571 | |
566 | sub invoke_size_allocate { |
572 | sub refresh_hook { |
567 | my ($self, $w, $h) = @_; |
573 | my ($self) = @_; |
568 | |
574 | |
569 | $self->update; |
575 | if ($::MAP && $self->{texture_atime} < time) { |
570 | |
|
|
571 | 1 |
|
|
572 | } |
|
|
573 | |
|
|
574 | sub update { |
|
|
575 | my ($self) = @_; |
|
|
576 | |
|
|
577 | delete $self->{texture_atime}; |
|
|
578 | $self->SUPER::update; |
|
|
579 | } |
|
|
580 | |
|
|
581 | sub _draw { |
|
|
582 | my ($self) = @_; |
|
|
583 | |
|
|
584 | $::MAP or return; |
|
|
585 | |
|
|
586 | my ($w, $h) = @$self{qw(w h)}; |
576 | my ($w, $h) = @$self{qw(w h)}; |
587 | |
577 | |
588 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
578 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
589 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
579 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
590 | |
580 | |
|
|
581 | my $ox = 0.5 * ($w - $sw); |
|
|
582 | my $oy = 0.5 * ($h - $sh); |
|
|
583 | |
591 | my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; |
584 | my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; |
592 | my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; |
585 | my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; |
593 | |
586 | |
594 | my $ox = 0.5 * ($w - $sw); |
587 | #TODO: map scale is completely borked |
595 | my $oy = 0.5 * ($h - $sh); |
|
|
596 | |
588 | |
597 | glEnable GL_BLEND; |
589 | my $x0 = int $ox - $sx + 0.5; |
598 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
590 | my $y0 = int $oy - $sy + 0.5; |
599 | glEnable GL_TEXTURE_2D; |
|
|
600 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
601 | |
591 | |
602 | if ($self->{texture_atime} < time) { |
592 | $self->{sw} = $sw; |
|
|
593 | $self->{sh} = $sh; |
|
|
594 | |
|
|
595 | $self->{x0} = $x0; |
|
|
596 | $self->{y0} = $y0; |
|
|
597 | |
603 | $self->{texture_atime} = time + 1/3; |
598 | $self->{texture_atime} = time + 1/3; |
604 | |
599 | |
605 | $self->{texture} = |
600 | $self->{texture} = |
606 | new CFPlus::Texture |
601 | new CFPlus::Texture |
607 | w => $w, |
602 | w => $w, |
608 | h => $h, |
603 | h => $h, |
609 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
604 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
610 | 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; |
611 | } |
606 | } |
|
|
607 | } |
|
|
608 | |
|
|
609 | sub invoke_visibility_change { |
|
|
610 | my ($self) = @_; |
|
|
611 | |
|
|
612 | $self->refresh_hook; |
|
|
613 | |
|
|
614 | 0 |
|
|
615 | } |
|
|
616 | |
|
|
617 | sub invoke_size_allocate { |
|
|
618 | my ($self, $w, $h) = @_; |
|
|
619 | |
|
|
620 | $self->update; |
|
|
621 | |
|
|
622 | 1 |
|
|
623 | } |
|
|
624 | |
|
|
625 | sub update { |
|
|
626 | my ($self) = @_; |
|
|
627 | |
|
|
628 | delete $self->{texture_atime}; |
|
|
629 | $self->SUPER::update; |
|
|
630 | } |
|
|
631 | |
|
|
632 | sub _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; |
612 | |
643 | |
613 | $self->{texture}->draw_quad (0, 0); |
644 | $self->{texture}->draw_quad (0, 0); |
614 | |
645 | |
615 | glDisable GL_TEXTURE_2D; |
646 | glDisable GL_TEXTURE_2D; |
616 | |
647 | |
617 | glTranslate 0.375, 0.375; |
648 | glTranslate 0.375, 0.375; |
618 | |
|
|
619 | #TODO: map scale is completely borked |
|
|
620 | |
|
|
621 | my $x0 = int $ox - $sx + 0.5; |
|
|
622 | my $y0 = int $oy - $sy + 0.5; |
|
|
623 | |
649 | |
624 | glColor 1, 1, 0, 1; |
650 | glColor 1, 1, 0, 1; |
625 | glBegin GL_LINE_LOOP; |
651 | glBegin GL_LINE_LOOP; |
626 | glVertex $x0 , $y0 ; |
652 | glVertex $self->{x0} , $self->{y0} ; |
627 | glVertex $x0 , $y0 + $sh; |
653 | glVertex $self->{x0} , $self->{y0} + $self->{sh}; |
628 | glVertex $x0 + $sw, $y0 + $sh; |
654 | glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh}; |
629 | glVertex $x0 + $sw, $y0 ; |
655 | glVertex $self->{x0} + $self->{sw}, $self->{y0} ; |
630 | glEnd; |
656 | glEnd; |
631 | |
657 | |
632 | glDisable GL_BLEND; |
658 | glDisable GL_BLEND; |
633 | } |
659 | } |
634 | |
660 | |