… | |
… | |
9 | use DC::OpenGL; |
9 | use DC::OpenGL; |
10 | use DC::UI; |
10 | use DC::UI; |
11 | use DC::Macro; |
11 | use DC::Macro; |
12 | |
12 | |
13 | our @ISA = DC::UI::Base::; |
13 | our @ISA = DC::UI::Base::; |
|
|
14 | |
|
|
15 | our @TEX_HIDDEN = map { |
|
|
16 | new_from_resource DC::Texture # MUST be POT |
|
|
17 | "hidden-$_.png", mipmap => 1, wrap => 1 |
|
|
18 | } 0, 1, 2; |
14 | |
19 | |
15 | my $magicmap_tex = |
20 | my $magicmap_tex = |
16 | new_from_resource DC::Texture "magicmap.png", |
21 | new_from_resource DC::Texture "magicmap.png", |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
22 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
18 | |
23 | |
… | |
… | |
396 | } |
401 | } |
397 | |
402 | |
398 | sub scroll { |
403 | sub scroll { |
399 | my ($self, $dx, $dy) = @_; |
404 | my ($self, $dx, $dy) = @_; |
400 | |
405 | |
401 | $::MAP->scroll ($dx, $dy); |
|
|
402 | |
|
|
403 | $self->{last_fow_texture} = $self->{fow_texture}; |
|
|
404 | $self->{ldx} = $self->{sdx} + $dx * $self->{tilesize}; # smooth displacement |
|
|
405 | $self->{ldy} = $self->{sdy} + $dy * $self->{tilesize}; |
|
|
406 | |
|
|
407 | $self->movement_update; |
406 | $self->movement_update; |
408 | |
407 | |
409 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
408 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
410 | $self->{sdy} += $dy * $self->{tilesize}; |
409 | $self->{sdy} += $dy * $self->{tilesize}; |
|
|
410 | |
|
|
411 | # save old fow texture, if applicable |
|
|
412 | $self->{last_fow_texture} = $self->{fow_texture} |
|
|
413 | if $::CFG->{smooth_transitions}; |
|
|
414 | $self->{lfdx} = $dx; |
|
|
415 | $self->{lfdy} = $dy; |
|
|
416 | $self->{lmdx} = $self->{dx}; |
|
|
417 | $self->{lmdy} = $self->{dy}; |
|
|
418 | |
|
|
419 | $::MAP->scroll ($dx, $dy); |
411 | } |
420 | } |
412 | |
421 | |
413 | sub set_magicmap { |
422 | sub set_magicmap { |
414 | my ($self, $w, $h, $x, $y, $data) = @_; |
423 | my ($self, $w, $h, $x, $y, $data) = @_; |
415 | |
424 | |
… | |
… | |
486 | |
495 | |
487 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
496 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
488 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
497 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
489 | |
498 | |
490 | if ($::CFG->{fow_enable}) { |
499 | if ($::CFG->{fow_enable}) { |
491 | my ($sdx_t, $sdy_t);#d# do not anchor at player |
500 | # draw_fow_texture REQUIRES the fow texture to stay the same size. |
492 | |
|
|
493 | my ($w, $h, $data) = $::MAP->fow_texture ( |
501 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
494 | $dx + (min 0, $sdx_t), |
|
|
495 | $dy + (min 0, $sdy_t), |
|
|
496 | $sw + abs $sdx_t, |
|
|
497 | $sh + abs $sdy_t |
|
|
498 | ); |
|
|
499 | |
502 | |
500 | $self->{fow_texture} = new DC::Texture |
503 | $self->{fow_texture} = new DC::Texture |
501 | w => $w, |
504 | w => $w, |
502 | h => $h, |
505 | h => $h, |
503 | data => $data, |
506 | data => $data, |
… | |
… | |
517 | $::MAP->draw ($dx, $dy, $sw, $sh, |
520 | $::MAP->draw ($dx, $dy, $sw, $sh, |
518 | $self->{tilesize}, |
521 | $self->{tilesize}, |
519 | $::CONN->{player}{tag}, |
522 | $::CONN->{player}{tag}, |
520 | -$self->{sdx}, -$self->{sdy}); |
523 | -$self->{sdx}, -$self->{sdy}); |
521 | |
524 | |
522 | #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player |
|
|
523 | glScale $self->{tilesize}, $self->{tilesize}; |
525 | glScale $self->{tilesize}, $self->{tilesize}; |
524 | |
526 | |
525 | if (my $tex = $self->{fow_texture}) { |
527 | if (my $tex = $self->{fow_texture}) { |
526 | glEnable GL_TEXTURE_2D; |
|
|
527 | glEnable GL_BLEND; |
|
|
528 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
529 | glBlendEquation GL_FUNC_REVERSE_SUBTRACT; |
|
|
530 | glBlendFunc GL_ONE, GL_ZERO; |
|
|
531 | |
|
|
532 | my $a1 = 0.9; |
|
|
533 | |
|
|
534 | if (0 && $self->{last_fow_texture}) { |
528 | if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) { |
535 | my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; |
529 | my $d1 = DC::distance $self->{sdx}, $self->{sdy}; |
536 | my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; |
530 | my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; |
537 | |
531 | |
538 | if ($d1 * $d2) { |
532 | if ($d1 * $d2) { |
539 | my $a2 = $d1 / $d2; |
533 | DC::Texture::draw_fow_texture |
540 | |
|
|
541 | $a1 = 1 - $a2; |
|
|
542 | |
|
|
543 | #$a1 *= 0.9; |
|
|
544 | #$a2 *= 0.9; |
|
|
545 | |
|
|
546 | printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d# |
|
|
547 | |
|
|
548 | #$a1 = 1 - (1-$a1) * 0.707; |
|
|
549 | #$a2 = 1 - (1-$a2) * 0.707; |
|
|
550 | |
|
|
551 | glColor 1,0,0,1; |
|
|
552 | glBegin GL_QUADS; |
|
|
553 | glVertex 10 + $sdx_t, 10; |
|
|
554 | glVertex 11 + $sdx_t, 10; |
|
|
555 | glVertex 11 + $sdx_t, 11; |
|
|
556 | glVertex 10 + $sdx_t, 11; |
|
|
557 | glEnd; |
|
|
558 | |
|
|
559 | glColor +($::CFG->{fow_intensity}) x 3, $a2; |
534 | $::CFG->{fow_intensity}, |
560 | glPushMatrix; |
535 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
561 | glTranslate $sdx_t, $sdy_t; # anchor at player |
536 | @{$self->{fow_texture}}{qw(name data s t w h)}, |
562 | glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize; |
537 | (min 1, $d1 / $d2), |
563 | glScale 1/3, 1/3; |
538 | $self->{lmdx} - $dx - $self->{lfdx}, |
564 | $self->{last_fow_texture}->draw_quad_alpha (0, 0); |
539 | $self->{lmdy} - $dy - $self->{lfdy}, |
565 | glPopMatrix; |
540 | @{$self->{last_fow_texture}}{qw(name data)}; |
566 | } else { |
541 | } else { |
567 | delete $self->{last_fow_texture}; |
542 | delete $self->{last_fow_texture}; |
568 | } |
543 | } |
569 | } |
544 | } |
570 | |
545 | |
571 | glColor +($::CFG->{fow_intensity}) x 3, $a1; |
546 | unless ($self->{last_fow_texture}) { |
572 | glPushMatrix; |
547 | DC::Texture::draw_fow_texture |
573 | #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player |
548 | $::CFG->{fow_intensity}, |
574 | glScale 1/3, 1/3; |
549 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
575 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
550 | @{$self->{fow_texture}}{qw(name data s t w h)}; |
576 | glPopMatrix; |
551 | } |
577 | |
|
|
578 | glBlendEquation GL_FUNC_ADD; |
|
|
579 | glDisable GL_TEXTURE_2D; |
|
|
580 | glDisable GL_BLEND; |
|
|
581 | } |
552 | } |
582 | |
553 | |
583 | if ($self->{magicmap}) { |
554 | if ($self->{magicmap}) { |
584 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
555 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
585 | |
556 | |
586 | $x += $::MAP->ox + $self->{dx}; |
557 | $x += $::MAP->ox + $self->{dx}; |
587 | $y += $::MAP->oy + $self->{dy}; |
558 | $y += $::MAP->oy + $self->{dy}; |
588 | |
559 | |
589 | glTranslate - $x - 1, - $y - 1; |
560 | glTranslate - $x - 1, - $y - 1; |
590 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
561 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
591 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
562 | $::MAP->draw_magicmap ($w, $h, $data); |
592 | } |
563 | } |
593 | |
564 | |
594 | glPopMatrix; |
565 | glPopMatrix; |
595 | glEndList; |
566 | glEndList; |
596 | } |
567 | } |
597 | } else { |
568 | } else { |
|
|
569 | delete $self->{last_fow_texture}; |
|
|
570 | delete $self->{fow_texture}; |
|
|
571 | |
598 | glDeleteList delete $self->{list} |
572 | glDeleteList delete $self->{list} |
599 | if $self->{list}; |
573 | if $self->{list}; |
600 | } |
574 | } |
601 | } |
575 | } |
602 | |
576 | |