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