… | |
… | |
396 | } |
396 | } |
397 | |
397 | |
398 | sub scroll { |
398 | sub scroll { |
399 | my ($self, $dx, $dy) = @_; |
399 | my ($self, $dx, $dy) = @_; |
400 | |
400 | |
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; |
401 | $self->movement_update; |
408 | |
402 | |
409 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
403 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
410 | $self->{sdy} += $dy * $self->{tilesize}; |
404 | $self->{sdy} += $dy * $self->{tilesize}; |
|
|
405 | |
|
|
406 | # save old fow texture, if applicable |
|
|
407 | $self->{last_fow_texture} = $self->{fow_texture} |
|
|
408 | if $::CFG->{smooth_transitions}; |
|
|
409 | $self->{lfdx} = $dx; |
|
|
410 | $self->{lfdy} = $dy; |
|
|
411 | $self->{lmdx} = $self->{dx}; |
|
|
412 | $self->{lmdy} = $self->{dy}; |
|
|
413 | |
|
|
414 | $::MAP->scroll ($dx, $dy); |
411 | } |
415 | } |
412 | |
416 | |
413 | sub set_magicmap { |
417 | sub set_magicmap { |
414 | my ($self, $w, $h, $x, $y, $data) = @_; |
418 | my ($self, $w, $h, $x, $y, $data) = @_; |
415 | |
419 | |
… | |
… | |
486 | |
490 | |
487 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
491 | 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; |
492 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
489 | |
493 | |
490 | if ($::CFG->{fow_enable}) { |
494 | if ($::CFG->{fow_enable}) { |
491 | my ($sdx_t, $sdy_t);#d# do not anchor at player |
|
|
492 | |
|
|
493 | my ($w, $h, $data) = $::MAP->fow_texture ( |
495 | 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 | |
496 | |
500 | $self->{fow_texture} = new DC::Texture |
497 | $self->{fow_texture} = new DC::Texture |
501 | w => $w, |
498 | w => $w, |
502 | h => $h, |
499 | h => $h, |
503 | data => $data, |
500 | data => $data, |
… | |
… | |
517 | $::MAP->draw ($dx, $dy, $sw, $sh, |
514 | $::MAP->draw ($dx, $dy, $sw, $sh, |
518 | $self->{tilesize}, |
515 | $self->{tilesize}, |
519 | $::CONN->{player}{tag}, |
516 | $::CONN->{player}{tag}, |
520 | -$self->{sdx}, -$self->{sdy}); |
517 | -$self->{sdx}, -$self->{sdy}); |
521 | |
518 | |
522 | #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player |
|
|
523 | glScale $self->{tilesize}, $self->{tilesize}; |
519 | glScale $self->{tilesize}, $self->{tilesize}; |
524 | |
520 | |
525 | if (my $tex = $self->{fow_texture}) { |
521 | 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}) { |
522 | if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) {#d# |
535 | my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; |
523 | my $d1 = DC::distance $self->{sdx}, $self->{sdy}; |
536 | my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; |
524 | my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; |
537 | |
525 | |
538 | if ($d1 * $d2) { |
526 | if ($d1 * $d2) { |
539 | my $a2 = $d1 / $d2; |
527 | 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; |
528 | $::CFG->{fow_intensity}, |
560 | glPushMatrix; |
529 | @{$self->{fow_texture}}{qw(name s t w h)}, |
561 | glTranslate $sdx_t, $sdy_t; # anchor at player |
530 | (min 1, $d1 / $d2), |
562 | glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize; |
531 | $self->{lmdx} - $dx - $self->{lfdx}, |
563 | glScale 1/3, 1/3; |
532 | $self->{lmdy} - $dy - $self->{lfdy}, |
564 | $self->{last_fow_texture}->draw_quad_alpha (0, 0); |
533 | @{$self->{last_fow_texture}}{qw(name s t w h)}; |
565 | glPopMatrix; |
|
|
566 | } else { |
534 | } else { |
567 | delete $self->{last_fow_texture}; |
535 | delete $self->{last_fow_texture}; |
568 | } |
536 | } |
569 | } |
537 | } |
570 | |
538 | |
571 | glColor +($::CFG->{fow_intensity}) x 3, $a1; |
539 | unless ($self->{last_fow_texture}) { |
572 | glPushMatrix; |
540 | DC::Texture::draw_fow_texture |
573 | #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player |
541 | $::CFG->{fow_intensity}, |
574 | glScale 1/3, 1/3; |
542 | @{$self->{fow_texture}}{qw(name s t w h)}; |
575 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
543 | } |
576 | glPopMatrix; |
|
|
577 | |
|
|
578 | glBlendEquation GL_FUNC_ADD; |
|
|
579 | glDisable GL_TEXTURE_2D; |
|
|
580 | glDisable GL_BLEND; |
|
|
581 | } |
544 | } |
582 | |
545 | |
583 | if ($self->{magicmap}) { |
546 | if ($self->{magicmap}) { |
584 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
547 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
585 | |
548 | |
586 | $x += $::MAP->ox + $self->{dx}; |
549 | $x += $::MAP->ox + $self->{dx}; |
587 | $y += $::MAP->oy + $self->{dy}; |
550 | $y += $::MAP->oy + $self->{dy}; |
588 | |
551 | |
589 | glTranslate - $x - 1, - $y - 1; |
552 | glTranslate - $x - 1, - $y - 1; |
590 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
553 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
591 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
554 | $::MAP->draw_magicmap ($w, $h, $data); |
592 | } |
555 | } |
593 | |
556 | |
594 | glPopMatrix; |
557 | glPopMatrix; |
595 | glEndList; |
558 | glEndList; |
596 | } |
559 | } |