… | |
… | |
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; |
1461 | |
1462 | |
1462 | my $mx = $::CONN->{mapx}; |
|
|
1463 | my $my = $::CONN->{mapy}; |
|
|
1464 | |
|
|
1465 | my $map = $::CONN->{map}; |
|
|
1466 | |
|
|
1467 | my ($xofs, $yofs); |
|
|
1468 | |
|
|
1469 | my $sw = 1 + int $::WIDTH / 32; |
1463 | my $sw = int $::WIDTH / 32; |
1470 | my $sh = 1 + int $::HEIGHT / 32; |
1464 | my $sh = int $::HEIGHT / 32; |
1471 | |
1465 | |
1472 | if ($::CONN->{mapw} > $sw) { |
1466 | if ($::MAP) { |
1473 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
1467 | my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); |
1474 | } else { |
|
|
1475 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
|
|
1476 | } |
|
|
1477 | |
1468 | |
1478 | if ($::CONN->{maph} > $sh) { |
1469 | if ($::CFG->{fow_enable}) { |
1479 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
1470 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1480 | } else { |
1471 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1481 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
1472 | glConvolutionFilter2D |
1482 | } |
1473 | GL_CONVOLUTION_2D, |
1483 | |
1474 | GL_ALPHA, |
1484 | glEnable GL_TEXTURE_2D; |
1475 | 3, 3, |
1485 | glEnable GL_BLEND; |
1476 | GL_ALPHA, GL_FLOAT, |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1477 | pack "f*", |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1478 | 0.1, 0.1, 0.1, |
1488 | |
1479 | 0.1, 0.2, 0.1, |
1489 | my $sw4 = ($sw + 3) & ~3; |
1480 | 0.1, 0.1, 0.1, |
1490 | my $darkness = "\x00" x ($sw4 * $sh); |
|
|
1491 | |
|
|
1492 | for my $x (0 .. $sw - 1) { |
|
|
1493 | my $row = $map->[$x + $xofs]; |
|
|
1494 | for my $y (0 .. $sh - 1) { |
|
|
1495 | |
|
|
1496 | my $cell = $row->[$y + $yofs] |
|
|
1497 | or next; |
1481 | ; |
1498 | |
1482 | glEnable GL_CONVOLUTION_2D; |
1499 | my $dark = $cell->[0]; |
|
|
1500 | if ($dark < 0) { |
|
|
1501 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
1502 | } else { |
|
|
1503 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
|
|
1504 | } |
1483 | } |
1505 | |
1484 | |
1506 | for my $num (grep $_, @$cell[1,2,3]) { |
1485 | my $tex = new CFClient::Texture |
1507 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1486 | w => $w, |
1508 | |
1487 | h => $h, |
1509 | my ($w, $h) = @$tex{qw(w h)}; |
1488 | data => $data, |
|
|
1489 | internalformat => GL_ALPHA, |
|
|
1490 | format => GL_ALPHA; |
1510 | |
1491 | |
1511 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1492 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1512 | } |
1493 | |
|
|
1494 | glEnable GL_BLEND; |
|
|
1495 | glEnable GL_TEXTURE_2D; |
|
|
1496 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1497 | |
|
|
1498 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1499 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1500 | |
|
|
1501 | glDisable GL_TEXTURE_2D; |
|
|
1502 | glDisable GL_BLEND; |
1513 | } |
1503 | } |
1514 | } |
1504 | } |
1515 | |
|
|
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; |
|
|
1527 | |
|
|
1528 | $darkness = new CFClient::Texture |
|
|
1529 | w => $sw4, |
|
|
1530 | h => $sh, |
|
|
1531 | data => $darkness, |
|
|
1532 | internalformat => GL_ALPHA, |
|
|
1533 | format => GL_ALPHA; |
|
|
1534 | |
|
|
1535 | glColor 0.45, 0.45, 0.45, 1; |
|
|
1536 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1537 | |
|
|
1538 | glDisable GL_TEXTURE_2D; |
|
|
1539 | glDisable GL_BLEND; |
|
|
1540 | |
1505 | |
1541 | glEndList; |
1506 | glEndList; |
1542 | } |
1507 | } |
1543 | |
1508 | |
1544 | glCallList $self->{list}; |
1509 | glCallList $self->{list}; |
… | |
… | |
1577 | |
1542 | |
1578 | my $mod = $ev->key_mod; |
1543 | my $mod = $ev->key_mod; |
1579 | my $sym = $ev->key_sym; |
1544 | my $sym = $ev->key_sym; |
1580 | |
1545 | |
1581 | if ($sym == SDLK_KP5) { |
1546 | if ($sym == SDLK_KP5) { |
1582 | $::CONN->send ("command stay fire"); |
1547 | $::CONN->user_send ("command stay fire"); |
1583 | } elsif ($sym == SDLK_a) { |
1548 | } elsif ($sym == SDLK_a) { |
1584 | $::CONN->send ("command apply"); |
1549 | $::CONN->user_send ("command apply"); |
1585 | } elsif (exists $DIR{$sym}) { |
1550 | } elsif (exists $DIR{$sym}) { |
1586 | if ($mod & KMOD_SHIFT) { |
1551 | if ($mod & KMOD_SHIFT) { |
1587 | $self->{shft}++; |
1552 | $self->{shft}++; |
1588 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1553 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1589 | } elsif ($mod & KMOD_CTRL) { |
1554 | } elsif ($mod & KMOD_CTRL) { |
1590 | $self->{ctrl}++; |
1555 | $self->{ctrl}++; |
1591 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1556 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1592 | } else { |
1557 | } else { |
1593 | $::CONN->send ("command $DIR{$sym}[1]"); |
1558 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1594 | } |
1559 | } |
1595 | } |
1560 | } |
1596 | } |
1561 | } |
1597 | |
1562 | |
1598 | sub key_up { |
1563 | sub key_up { |
… | |
… | |
1600 | |
1565 | |
1601 | my $mod = $ev->key_mod; |
1566 | my $mod = $ev->key_mod; |
1602 | my $sym = $ev->key_sym; |
1567 | my $sym = $ev->key_sym; |
1603 | |
1568 | |
1604 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1569 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1605 | $::CONN->send ("command fire_stop"); |
1570 | $::CONN->user_send ("command fire_stop"); |
1606 | } |
1571 | } |
1607 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1572 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1608 | $::CONN->send ("command run_stop"); |
1573 | $::CONN->user_send ("command run_stop"); |
1609 | } |
1574 | } |
1610 | } |
1575 | } |
1611 | |
1576 | |
1612 | ############################################################################# |
1577 | ############################################################################# |
1613 | |
1578 | |