… | |
… | |
10 | use CFPlus::UI; |
10 | use CFPlus::UI; |
11 | use CFPlus::Macro; |
11 | use CFPlus::Macro; |
12 | |
12 | |
13 | our @ISA = CFPlus::UI::Base::; |
13 | our @ISA = CFPlus::UI::Base::; |
14 | |
14 | |
15 | sub ::T() { 32 } |
|
|
16 | |
|
|
17 | my $magicmap_tex = |
15 | my $magicmap_tex = |
18 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
16 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
19 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
20 | |
18 | |
21 | sub new { |
19 | sub new { |
… | |
… | |
23 | |
21 | |
24 | my $self = $class->SUPER::new ( |
22 | my $self = $class->SUPER::new ( |
25 | z => -1, |
23 | z => -1, |
26 | can_focus => 1, |
24 | can_focus => 1, |
27 | list => glGenList, |
25 | list => glGenList, |
28 | |
26 | tilesize => 32, |
29 | smooth_matrix => [ |
|
|
30 | 0.05, 0.13, 0.05, |
|
|
31 | 0.13, 0.30, 0.13, |
|
|
32 | 0.05, 0.13, 0.05, |
|
|
33 | ], |
|
|
34 | |
|
|
35 | @_ |
27 | @_ |
36 | ); |
28 | ); |
37 | |
29 | |
38 | $self->{completer} = new CFPlus::MapWidget::Command:: |
30 | $self->{completer} = new CFPlus::MapWidget::Command:: |
39 | command => $self->{command}, |
31 | command => $self->{command}, |
40 | tooltip => "#completer_help", |
32 | tooltip => "#completer_help", |
41 | ; |
33 | ; |
42 | |
34 | |
43 | $self |
35 | $self |
|
|
36 | } |
|
|
37 | |
|
|
38 | sub set_tilesize { |
|
|
39 | my ($self, $tilesize) = @_; |
|
|
40 | |
|
|
41 | $self->{tilesize} = $tilesize; |
44 | } |
42 | } |
45 | |
43 | |
46 | sub add_command { |
44 | sub add_command { |
47 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
45 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
48 | |
46 | |
… | |
… | |
179 | |
177 | |
180 | if ($ev->{button} == 1) { |
178 | if ($ev->{button} == 1) { |
181 | $self->grab_focus; |
179 | $self->grab_focus; |
182 | return unless $::CONN; |
180 | return unless $::CONN; |
183 | |
181 | |
184 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize}; |
182 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
185 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize}; |
183 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
186 | |
184 | |
187 | $x -= CFPlus::floor $::MAP->w * 0.5; |
185 | $x -= CFPlus::floor $::MAP->w * 0.5; |
188 | $y -= CFPlus::floor $::MAP->h * 0.5; |
186 | $y -= CFPlus::floor $::MAP->h * 0.5; |
189 | |
187 | |
190 | if ($::CONN) { |
188 | if ($::CONN) { |
… | |
… | |
287 | |
285 | |
288 | 1 |
286 | 1 |
289 | } |
287 | } |
290 | |
288 | |
291 | sub size_request { |
289 | sub size_request { |
|
|
290 | my ($self) = @_; |
|
|
291 | |
292 | ( |
292 | ( |
293 | ::T * CFPlus::ceil $::WIDTH / ::T, |
293 | $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize}, |
294 | ::T * CFPlus::ceil $::HEIGHT / ::T, |
294 | $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize}, |
295 | ) |
295 | ) |
296 | } |
296 | } |
297 | |
297 | |
298 | sub update { |
298 | sub update { |
299 | my ($self) = @_; |
299 | my ($self) = @_; |
… | |
… | |
301 | $self->{need_update} = 1; |
301 | $self->{need_update} = 1; |
302 | $self->SUPER::update; |
302 | $self->SUPER::update; |
303 | } |
303 | } |
304 | |
304 | |
305 | my %DIR = ( |
305 | my %DIR = ( |
|
|
306 | CFPlus::SDLK_KP5, [0, "stay fire"], |
306 | CFPlus::SDLK_KP8, [1, "north"], |
307 | CFPlus::SDLK_KP8, [1, "north"], |
307 | CFPlus::SDLK_KP9, [2, "northeast"], |
308 | CFPlus::SDLK_KP9, [2, "northeast"], |
308 | CFPlus::SDLK_KP6, [3, "east"], |
309 | CFPlus::SDLK_KP6, [3, "east"], |
309 | CFPlus::SDLK_KP3, [4, "southeast"], |
310 | CFPlus::SDLK_KP3, [4, "southeast"], |
310 | CFPlus::SDLK_KP2, [5, "south"], |
311 | CFPlus::SDLK_KP2, [5, "south"], |
… | |
… | |
342 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
343 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
343 | $::SETUP_DIALOG->toggle_visibility; |
344 | $::SETUP_DIALOG->toggle_visibility; |
344 | } elsif (!$::CONN) { |
345 | } elsif (!$::CONN) { |
345 | return 0; # bindings further down need a valid connection |
346 | return 0; # bindings further down need a valid connection |
346 | |
347 | |
347 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
|
|
348 | $::CONN->user_send ("stay fire"); |
|
|
349 | } elsif ($uni == ord ",") { |
348 | } elsif ($uni == ord ",") { |
350 | $::CONN->user_send ("take"); |
349 | $::CONN->user_send ("take"); |
351 | } elsif ($uni == ord " ") { |
350 | } elsif ($uni == ord " ") { |
352 | $::CONN->user_send ("apply"); |
351 | $::CONN->user_send ("apply"); |
353 | } elsif ($uni == 13) { |
352 | } elsif ($uni == 13) { |
… | |
… | |
424 | } |
423 | } |
425 | |
424 | |
426 | $res |
425 | $res |
427 | } |
426 | } |
428 | |
427 | |
|
|
428 | sub invoke_visibility_change { |
|
|
429 | my ($self) = @_; |
|
|
430 | |
|
|
431 | $self->refresh_hook; |
|
|
432 | |
|
|
433 | 0 |
|
|
434 | } |
|
|
435 | |
429 | sub set_magicmap { |
436 | sub set_magicmap { |
430 | my ($self, $w, $h, $x, $y, $data) = @_; |
437 | my ($self, $w, $h, $x, $y, $data) = @_; |
431 | |
438 | |
432 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
439 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
433 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
440 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
… | |
… | |
435 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
442 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
436 | |
443 | |
437 | $self->update; |
444 | $self->update; |
438 | } |
445 | } |
439 | |
446 | |
440 | sub draw { |
447 | sub refresh_hook { |
441 | my ($self) = @_; |
448 | my ($self) = @_; |
442 | |
449 | |
443 | return unless $::MAP; |
450 | return unless $::MAP; |
444 | |
451 | |
445 | my $focused = $CFPlus::UI::FOCUS == $self |
|
|
446 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
|
|
447 | |
|
|
448 | return |
|
|
449 | unless $focused || !$::FAST; |
|
|
450 | |
|
|
451 | if (delete $self->{need_update}) { |
452 | if (delete $self->{need_update}) { |
452 | my $tilesize = $self->{tilesize} = int ::T * $::CFG->{map_scale}; |
453 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
453 | |
454 | |
454 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
455 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
455 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
456 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
456 | |
457 | |
457 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
458 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
… | |
… | |
463 | 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; |
464 | 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; |
465 | |
466 | |
466 | if ($::CFG->{fow_enable}) { |
467 | if ($::CFG->{fow_enable}) { |
467 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
468 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
468 | |
|
|
469 | if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
470 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
471 | glConvolutionFilter2D ( |
|
|
472 | GL_CONVOLUTION_2D, |
|
|
473 | GL_ALPHA, |
|
|
474 | 3, 3, |
|
|
475 | GL_ALPHA, GL_FLOAT, |
|
|
476 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
477 | ); |
|
|
478 | glEnable GL_CONVOLUTION_2D; |
|
|
479 | } |
|
|
480 | |
469 | |
481 | $self->{fow_texture} = new CFPlus::Texture |
470 | $self->{fow_texture} = new CFPlus::Texture |
482 | w => $w, |
471 | w => $w, |
483 | h => $h, |
472 | h => $h, |
484 | data => $data, |
473 | data => $data, |
485 | internalformat => GL_ALPHA, |
474 | internalformat => GL_ALPHA, |
486 | format => GL_ALPHA; |
475 | format => GL_ALPHA; |
487 | |
|
|
488 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
489 | } else { |
476 | } else { |
490 | delete $self->{fow_texture}; |
477 | delete $self->{fow_texture}; |
491 | } |
478 | } |
492 | |
479 | |
493 | glNewList $self->{list}; |
480 | glNewList $self->{list}; |
494 | |
481 | |
495 | glPushMatrix; |
482 | glPushMatrix; |
496 | glTranslate $sx0, $sy0; |
483 | glTranslate $sx0, $sy0; |
497 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
484 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
498 | |
485 | |
499 | $::MAP->draw ($dx, $dy, $sw, $sh, ::T); |
486 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
500 | |
487 | |
501 | glScale ::T, ::T; |
488 | glScale $self->{tilesize}, $self->{tilesize}; |
502 | |
489 | |
503 | if (my $tex = $self->{fow_texture}) { |
490 | if (my $tex = $self->{fow_texture}) { |
|
|
491 | glPushMatrix; |
|
|
492 | glScale 1/3, 1/3; |
504 | glEnable GL_TEXTURE_2D; |
493 | glEnable GL_TEXTURE_2D; |
505 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
494 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
506 | |
495 | |
507 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
496 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
508 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
497 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
509 | |
498 | |
510 | glDisable GL_TEXTURE_2D; |
499 | glDisable GL_TEXTURE_2D; |
|
|
500 | glPopMatrix; |
511 | } |
501 | } |
512 | |
502 | |
513 | if ($self->{magicmap}) { |
503 | if ($self->{magicmap}) { |
514 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
504 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
515 | |
505 | |
… | |
… | |
522 | } |
512 | } |
523 | |
513 | |
524 | glPopMatrix; |
514 | glPopMatrix; |
525 | glEndList; |
515 | glEndList; |
526 | } |
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; |
527 | |
532 | |
528 | glCallList $self->{list}; |
533 | glCallList $self->{list}; |
529 | |
534 | |
530 | # TNT2 emulates logops in software (or worse :) |
535 | # TNT2 emulates logops in software (or worse :) |
531 | unless ($focused) { |
536 | unless ($focused) { |
… | |
… | |
550 | $self->SUPER::DESTROY; |
555 | $self->SUPER::DESTROY; |
551 | } |
556 | } |
552 | |
557 | |
553 | package CFPlus::MapWidget::MapMap; |
558 | package CFPlus::MapWidget::MapMap; |
554 | |
559 | |
|
|
560 | use strict; |
|
|
561 | use utf8; |
|
|
562 | |
555 | our @ISA = CFPlus::UI::Base::; |
563 | our @ISA = CFPlus::UI::Base::; |
556 | |
564 | |
557 | use Time::HiRes qw(time); |
565 | use Time::HiRes qw(time); |
558 | use CFPlus::OpenGL; |
566 | use CFPlus::OpenGL; |
559 | |
567 | |
560 | sub size_request { |
568 | sub size_request { |
561 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
569 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
562 | } |
570 | } |
563 | |
571 | |
564 | sub invoke_size_allocate { |
572 | sub refresh_hook { |
565 | my ($self, $w, $h) = @_; |
573 | my ($self) = @_; |
566 | |
574 | |
567 | $self->update; |
575 | if ($::MAP && $self->{texture_atime} < time) { |
568 | |
|
|
569 | 1 |
|
|
570 | } |
|
|
571 | |
|
|
572 | sub update { |
|
|
573 | my ($self) = @_; |
|
|
574 | |
|
|
575 | delete $self->{texture_atime}; |
|
|
576 | $self->SUPER::update; |
|
|
577 | } |
|
|
578 | |
|
|
579 | sub _draw { |
|
|
580 | my ($self) = @_; |
|
|
581 | |
|
|
582 | $::MAP or return; |
|
|
583 | |
|
|
584 | my ($w, $h) = @$self{qw(w h)}; |
576 | my ($w, $h) = @$self{qw(w h)}; |
585 | |
577 | |
586 | my $sw = int $::WIDTH / (::T * $::CFG->{map_scale}) + 0.99; |
578 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
587 | my $sh = int $::HEIGHT / (::T * $::CFG->{map_scale}) + 0.99; |
579 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
588 | |
580 | |
589 | my $sx = int $::CFG->{map_shift_x} / ::T; |
|
|
590 | my $sy = int $::CFG->{map_shift_y} / ::T; |
|
|
591 | |
|
|
592 | my $ox = 0.5 * ($w - $sw); |
581 | my $ox = 0.5 * ($w - $sw); |
593 | my $oy = 0.5 * ($h - $sh); |
582 | my $oy = 0.5 * ($h - $sh); |
594 | |
583 | |
595 | glEnable GL_BLEND; |
584 | my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; |
596 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
585 | my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; |
597 | glEnable GL_TEXTURE_2D; |
|
|
598 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
599 | |
586 | |
600 | if ($self->{texture_atime} < time) { |
587 | #TODO: map scale is completely borked |
|
|
588 | |
|
|
589 | my $x0 = int $ox - $sx + 0.5; |
|
|
590 | my $y0 = int $oy - $sy + 0.5; |
|
|
591 | |
|
|
592 | $self->{sw} = $sw; |
|
|
593 | $self->{sh} = $sh; |
|
|
594 | |
|
|
595 | $self->{x0} = $x0; |
|
|
596 | $self->{y0} = $y0; |
|
|
597 | |
601 | $self->{texture_atime} = time + 1/3; |
598 | $self->{texture_atime} = time + 1/3; |
602 | |
599 | |
603 | $self->{texture} = |
600 | $self->{texture} = |
604 | new CFPlus::Texture |
601 | new CFPlus::Texture |
605 | w => $w, |
602 | w => $w, |
606 | h => $h, |
603 | h => $h, |
607 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
604 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
608 | 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; |
609 | } |
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; |
610 | |
643 | |
611 | $self->{texture}->draw_quad (0, 0); |
644 | $self->{texture}->draw_quad (0, 0); |
612 | |
645 | |
613 | glDisable GL_TEXTURE_2D; |
646 | glDisable GL_TEXTURE_2D; |
614 | |
647 | |
615 | glTranslate 0.375, 0.375; |
648 | glTranslate 0.375, 0.375; |
616 | |
|
|
617 | #TODO: map scale is completely borked |
|
|
618 | |
|
|
619 | my $x0 = int $ox - $sx + 0.5; |
|
|
620 | my $y0 = int $oy - $sy + 0.5; |
|
|
621 | |
649 | |
622 | glColor 1, 1, 0, 1; |
650 | glColor 1, 1, 0, 1; |
623 | glBegin GL_LINE_LOOP; |
651 | glBegin GL_LINE_LOOP; |
624 | glVertex $x0 , $y0 ; |
652 | glVertex $self->{x0} , $self->{y0} ; |
625 | glVertex $x0 , $y0 + $sh; |
653 | glVertex $self->{x0} , $self->{y0} + $self->{sh}; |
626 | glVertex $x0 + $sw, $y0 + $sh; |
654 | glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh}; |
627 | glVertex $x0 + $sw, $y0 ; |
655 | glVertex $self->{x0} + $self->{sw}, $self->{y0} ; |
628 | glEnd; |
656 | glEnd; |
629 | |
657 | |
630 | glDisable GL_BLEND; |
658 | glDisable GL_BLEND; |
631 | } |
659 | } |
632 | |
660 | |