--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 13:38:22 1.64 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 14:04:27 1.65 @@ -75,7 +75,12 @@ sub new { my $class = shift; - bless { @_ }, $class + bless { + x => 0, + y => 0, + z => 0, + @_ + }, $class } sub move { @@ -221,7 +226,7 @@ my $children = delete $arg{children} || []; - my $self = $class->SUPER::new (children => []); + my $self = $class->SUPER::new (children => [], %arg); $self->add ($_) for @$children; $self @@ -788,7 +793,11 @@ sub new { my $class = shift; - $class->SUPER::new (z => -1, @_) + $class->SUPER::new ( + z => -1, + list => (glGenLists 1), + @_ + ) } sub key_down { @@ -805,62 +814,71 @@ ) } +sub update { + my ($self) = @_; + + $self->{need_update} = 1; +} + sub _draw { my ($self) = @_; - my $mx = $::CONN->{mapx}; - my $my = $::CONN->{mapy}; + if (delete $self->{need_update}) { + glNewList $self->{list}, GL_COMPILE; - my $map = $::CONN->{map}; + my $mx = $::CONN->{mapx}; + my $my = $::CONN->{mapy}; - my ($xofs, $yofs); + my $map = $::CONN->{map}; - my $sw = 1 + int $::WIDTH / 32; - my $sh = 1 + int $::HEIGHT / 32; + my ($xofs, $yofs); - if ($::CONN->{mapw} > $sw) { - $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; - } else { - $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; - } + my $sw = 1 + int $::WIDTH / 32; + my $sh = 1 + int $::HEIGHT / 32; - if ($::CONN->{maph} > $sh) { - $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; - } else { - $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; - } + if ($::CONN->{mapw} > $sw) { + $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; + } else { + $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; + } - glEnable GL_TEXTURE_2D; - glEnable GL_BLEND; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + if ($::CONN->{maph} > $sh) { + $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; + } else { + $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; + } - my $sw4 = ($sw + 3) & ~3; - my $darkness = "\x00" x ($sw4 * $sh); + glEnable GL_TEXTURE_2D; + glEnable GL_BLEND; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - for my $x (0 .. $sw - 1) { - my $row = $map->[$x + $xofs]; - for my $y (0 .. $sh - 1) { - - my $cell = $row->[$y + $yofs] - or next; - - my $dark = $cell->[0]; - if ($dark < 0) { - substr $darkness, $y * $sw4 + $x, 1, chr 224; - } else { - substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; - } + my $sw4 = ($sw + 3) & ~3; + my $darkness = "\x00" x ($sw4 * $sh); - for my $num (grep $_, @$cell[1,2,3]) { - my $tex = $::CONN->{face}[$num]{texture} || next; - - my $w = $tex->{width}; - my $h = $tex->{height}; + for my $x (0 .. $sw - 1) { + my $row = $map->[$x + $xofs]; + for my $y (0 .. $sh - 1) { + + my $cell = $row->[$y + $yofs] + or next; + + my $dark = $cell->[0]; + if ($dark < 0) { + substr $darkness, $y * $sw4 + $x, 1, chr 224; + } else { + substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; + } + + for my $num (grep $_, @$cell[1,2,3]) { + my $tex = $::CONN->{face}[$num]{texture} || next; + + my $w = $tex->{width}; + my $h = $tex->{height}; - $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); + $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); + } } } - } # if (1) { # higher quality darkness # $lighting =~ s/(.)/$1$1$1/gs; @@ -872,21 +890,26 @@ # $lighting =~ s/(.)../$1/gs; # } - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - $darkness = new CFClient::Texture - width => $sw4, - height => $sh, - data => $darkness, - internalformat => GL_ALPHA, - format => GL_ALPHA; + $darkness = new CFClient::Texture + width => $sw4, + height => $sh, + data => $darkness, + internalformat => GL_ALPHA, + format => GL_ALPHA; - glColor 0.45, 0.45, 0.45, 1; - $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); + glColor 0.45, 0.45, 0.45, 1; + $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); - glDisable GL_TEXTURE_2D; - glDisable GL_BLEND; + glDisable GL_TEXTURE_2D; + glDisable GL_BLEND; + + glEndList; + } + + glCallList $self->{list}; } my %DIR = (