… | |
… | |
1454 | } |
1454 | } |
1455 | |
1455 | |
1456 | sub draw { |
1456 | sub draw { |
1457 | my ($self) = @_; |
1457 | my ($self) = @_; |
1458 | |
1458 | |
|
|
1459 | $self->{need_update}++;#d# |
1459 | if (delete $self->{need_update}) { |
1460 | if (delete $self->{need_update}) { |
1460 | glNewList $self->{list}, GL_COMPILE; |
1461 | glNewList $self->{list}, GL_COMPILE; |
|
|
1462 | |
|
|
1463 | my $sw = int $::WIDTH / 32; |
|
|
1464 | my $sh = int $::HEIGHT / 32; |
|
|
1465 | |
|
|
1466 | $::MAP->draw (0, 0, $sw, $sh) if $::MAP; |
|
|
1467 | |
|
|
1468 | if (0) { |
1461 | |
1469 | |
1462 | my $mx = $::CONN->{mapx}; |
1470 | my $mx = $::CONN->{mapx}; |
1463 | my $my = $::CONN->{mapy}; |
1471 | my $my = $::CONN->{mapy}; |
1464 | |
1472 | |
1465 | my $map = $::CONN->{map}; |
1473 | my $map = $::CONN->{map}; |
… | |
… | |
1483 | |
1491 | |
1484 | glEnable GL_TEXTURE_2D; |
1492 | glEnable GL_TEXTURE_2D; |
1485 | glEnable GL_BLEND; |
1493 | glEnable GL_BLEND; |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1494 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1495 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1496 | glColor 1, 1, 1, 1; |
1488 | |
1497 | |
1489 | my $sw4 = ($sw + 3) & ~3; |
1498 | my $sw4 = ($sw + 3) & ~3; |
1490 | my $darkness = "\x00" x ($sw4 * $sh); |
1499 | my $darkness = "\x00" x ($sw4 * $sh); |
1491 | |
1500 | |
1492 | for my $x (0 .. $sw - 1) { |
1501 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1511 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1520 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1512 | } |
1521 | } |
1513 | } |
1522 | } |
1514 | } |
1523 | } |
1515 | |
1524 | |
1516 | # if (1) { # higher quality darkness |
|
|
1517 | # $lighting =~ s/(.)/$1$1$1/gs; |
|
|
1518 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
|
|
1519 | # |
|
|
1520 | # $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); |
|
|
1521 | # |
|
|
1522 | # $lighting = $pb->get_pixels; |
|
|
1523 | # $lighting =~ s/(.)../$1/gs; |
|
|
1524 | # } |
|
|
1525 | |
|
|
1526 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1525 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1526 | |
|
|
1527 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1528 | my @conv = ( |
|
|
1529 | 0.1, 0.1, 0.1, |
|
|
1530 | 0.1, 0.2, 0.1, |
|
|
1531 | 0.1, 0.1, 0.1, |
|
|
1532 | ); |
|
|
1533 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1534 | glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1535 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1536 | pack "f*", @conv; |
|
|
1537 | glEnable GL_CONVOLUTION_2D; |
|
|
1538 | } |
1527 | |
1539 | |
1528 | $darkness = new CFClient::Texture |
1540 | $darkness = new CFClient::Texture |
1529 | w => $sw4, |
1541 | w => $sw4, |
1530 | h => $sh, |
1542 | h => $sh, |
1531 | data => $darkness, |
1543 | data => $darkness, |
1532 | internalformat => GL_ALPHA, |
1544 | internalformat => GL_ALPHA, |
1533 | format => GL_ALPHA; |
1545 | format => GL_ALPHA; |
1534 | |
1546 | |
1535 | glColor 0.45, 0.45, 0.45, 1; |
1547 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1536 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
1548 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1549 | |
|
|
1550 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1537 | |
1551 | |
1538 | glDisable GL_TEXTURE_2D; |
1552 | glDisable GL_TEXTURE_2D; |
1539 | glDisable GL_BLEND; |
1553 | glDisable GL_BLEND; |
|
|
1554 | } |
1540 | |
1555 | |
1541 | glEndList; |
1556 | glEndList; |
1542 | } |
1557 | } |
1543 | |
1558 | |
1544 | glCallList $self->{list}; |
1559 | glCallList $self->{list}; |
… | |
… | |
1577 | |
1592 | |
1578 | my $mod = $ev->key_mod; |
1593 | my $mod = $ev->key_mod; |
1579 | my $sym = $ev->key_sym; |
1594 | my $sym = $ev->key_sym; |
1580 | |
1595 | |
1581 | if ($sym == SDLK_KP5) { |
1596 | if ($sym == SDLK_KP5) { |
1582 | $::CONN->send ("command stay fire"); |
1597 | $::CONN->user_send ("command stay fire"); |
1583 | } elsif ($sym == SDLK_a) { |
1598 | } elsif ($sym == SDLK_a) { |
1584 | $::CONN->send ("command apply"); |
1599 | $::CONN->user_send ("command apply"); |
1585 | } elsif (exists $DIR{$sym}) { |
1600 | } elsif (exists $DIR{$sym}) { |
1586 | if ($mod & KMOD_SHIFT) { |
1601 | if ($mod & KMOD_SHIFT) { |
1587 | $self->{shft}++; |
1602 | $self->{shft}++; |
1588 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1603 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1589 | } elsif ($mod & KMOD_CTRL) { |
1604 | } elsif ($mod & KMOD_CTRL) { |
1590 | $self->{ctrl}++; |
1605 | $self->{ctrl}++; |
1591 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1606 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1592 | } else { |
1607 | } else { |
1593 | $::CONN->send ("command $DIR{$sym}[1]"); |
1608 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1594 | } |
1609 | } |
1595 | } |
1610 | } |
1596 | } |
1611 | } |
1597 | |
1612 | |
1598 | sub key_up { |
1613 | sub key_up { |
… | |
… | |
1600 | |
1615 | |
1601 | my $mod = $ev->key_mod; |
1616 | my $mod = $ev->key_mod; |
1602 | my $sym = $ev->key_sym; |
1617 | my $sym = $ev->key_sym; |
1603 | |
1618 | |
1604 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1619 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1605 | $::CONN->send ("command fire_stop"); |
1620 | $::CONN->user_send ("command fire_stop"); |
1606 | } |
1621 | } |
1607 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1622 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1608 | $::CONN->send ("command run_stop"); |
1623 | $::CONN->user_send ("command run_stop"); |
1609 | } |
1624 | } |
1610 | } |
1625 | } |
1611 | |
1626 | |
1612 | ############################################################################# |
1627 | ############################################################################# |
1613 | |
1628 | |