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