ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.115 by root, Sat Apr 15 22:56:00 2006 UTC vs.
Revision 1.116 by root, Sun Apr 16 07:25:30 2006 UTC

13use SDL::OpenGL; 13use SDL::OpenGL;
14 14
15use Crossfire; 15use Crossfire;
16use Crossfire::Protocol; 16use Crossfire::Protocol;
17 17
18use Compress::LZF;
19
18use CFClient; 20use CFClient;
19use CFClient::UI; 21use CFClient::UI;
20 22
21our $VERSION = '0.1'; 23our $VERSION = '0.1';
22 24
23my $MAX_FPS = 60; 25my $MAX_FPS = 60;
24my $MIN_FPS = 5; # unused as of yet 26my $MIN_FPS = 5; # unused as of yet
25 27
26our $META_SERVER = "crossfire.real-time.com:13326"; 28our $META_SERVER = "crossfire.real-time.com:13326";
27 29
30our $FACEMAP;
31our $TILECACHE;
28our $FACECACHE; 32our $MAPCACHE;
29 33
30our $LAST_REFRESH; 34our $LAST_REFRESH;
31our $NOW; 35our $NOW;
32 36
33our $CFG; 37our $CFG;
69 73
70sub start_game { 74sub start_game {
71 status "logging in..."; 75 status "logging in...";
72 76
73 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 77 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
78
79 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
74 80
75 $MAP = new CFClient::Map $mapsize, $mapsize; 81 $MAP = new CFClient::Map $mapsize, $mapsize;
76 82
77 my ($host, $port) = split /:/, $CFG->{host}; 83 my ($host, $port) = split /:/, $CFG->{host};
78 84
303 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
304 expand => 1, 310 expand => 1,
305 fontsize => $::CFG->{log_fontsize}, 311 fontsize => $::CFG->{log_fontsize},
306 ); 312 );
307 313
308 $vbox->add (my $input = new CFClient::UI::LineEntry); 314 $vbox->add (my $input = new CFClient::UI::LineEntry
309 $input->connect (activate => sub { 315 connect_activate => sub {
310 my ($input, $text) = @_; 316 my ($input, $text) = @_;
311 $input->set_text (''); 317 $input->set_text ('');
312 318
313 if ($text =~ /^\/(.*)/) { 319 if ($text =~ /^\/(.*)/) {
314 $::CONN->user_send ("command $1"); 320 $::CONN->user_send ("command $1");
315 } else { 321 } else {
316 my $say_cmd = $::CFG->{say_command} || 'say'; 322 my $say_cmd = $::CFG->{say_command} || 'say';
317 $::CONN->user_send ("command $say_cmd $text"); 323 $::CONN->user_send ("command $say_cmd $text");
318 } 324 }
319 1
320 }); 325 },
321 $input->connect (escape => sub { 326 connect_escape => sub {
322 $MAPWIDGET->focus_in 327 $MAPWIDGET->focus_in
323 }); 328 },
324 $input->focus_in; 329 );
325 330
326 $CONSOLE = { 331 $CONSOLE = {
327 window => $window, 332 window => $window,
328 input => $input 333 input => $input
329 }; 334 };
499 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); 504 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
500 $MAP->map1a_update ($data); 505 $MAP->map1a_update ($data);
501 $MAPWIDGET->update; 506 $MAPWIDGET->update;
502} 507}
503 508
504#sub conn::map_update { 509sub conn::flush_map {
505# my ($self, $dirty) = @_; 510 my ($self) = @_;
506# 511
507# $MAPWIDGET->update; 512 my $map_info = delete $self->{map_info}
508#} 513 or return;
514
515 my ($hash, $x, $y, $w, $h) = @$map_info;
516
517 my $data = $MAP->get_rect ($x, $y, $w, $h);
518 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
519
520 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
521
522}
509 523
510sub conn::map_clear { 524sub conn::map_clear {
511 my ($self) = @_; 525 my ($self) = @_;
512 526
527 $self->flush_map;
528
513 $MAP->clear; 529 $MAP->clear;
514
515# refresh;
516} 530}
517 531
518sub conn::map_info { 532sub conn::map_info {
519 my ($self, $mode, $x, $y, $w, $h, $hash) = @_; 533 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
520 534
521 warn "mapinfo <$mode,$x,$y,$w,$h,$hash>\n";#d# 535 $self->flush_map;
536
537 $x = $::MAP->ox - $x;
538 $y = $::MAP->oy - $y;
539
540 $self->{map_info} = [$hash, $x, $y, $w, $h];
541
542 if (defined (my $data = $MAPCACHE->get ($hash))) {
543 $data = Compress::LZF::decompress $data;
544 warn sprintf "LOADmap[%s] length %d\n", $hash, length $data;#d#
545 for my $id ($MAP->set_rect ($x, $y, $data)) {
546 my $data = $TILECACHE->get ($id)
547 or next;
548
549 $self->set_texture ($id => $data);
550 }
551 }
522} 552}
523 553
524sub conn::face_find { 554sub conn::face_find {
525 my ($self, $face) = @_; 555 my ($self, $facenum, $face) = @_;
526 556
527 my $data; 557 my $hash = "$face->{chksum},$face->{name}";
528 558
529 $FACECACHE->get ("$face->{chksum},$face->{name}") 559 my $id = $FACEMAP->get ($hash);
560
561 unless ($id) {
562 # create new id for face
563 # i love transactions
564 for (1..100) {
565 my $txn = $CFClient::DB_ENV->txn_begin;
566 my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
567 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
568 $id++;
569 if ($FACEMAP->put (id => $id) == 0
570 && $FACEMAP->put ($hash => $id) == 0) {
571 $txn->txn_commit;
572
573 goto gotid;
574 }
575 }
576 $txn->abort;
577 }
578
579 CFClient::fatal "maximum number of transaction retries reached - database problems?";
580 }
581
582gotid:
583 $face->{id} = $id;
584 $MAP->set_face ($facenum => $id);
585 $TILECACHE->get ($id)
530} 586}
531 587
532sub conn::face_update { 588sub conn::face_update {
533 my ($self, $facenum, $face) = @_; 589 my ($self, $facenum, $face) = @_;
534 590
535 $FACECACHE->put ("$face->{chksum},$face->{name}" => $face->{image}); 591 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
536 592
537 my $tex = $face->{texture} = 593 $self->set_texture ($face->{id} => delete $face->{image});
594}
595
596sub conn::set_texture {
597 my ($self, $id, $data) = @_;
598
599 $self->{texture}[$id] ||= do {
600 my $tex =
538 new_from_image CFClient::Texture 601 new_from_image CFClient::Texture
539 delete $face->{image}, minify => 1; 602 $data, minify => 1;
540 603
541 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 604 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
542 $MAPWIDGET->update; 605 $MAPWIDGET->update;
606
607 $tex
608 };
543} 609}
544 610
545sub conn::query { 611sub conn::query {
546 my ($self, $flags, $prompt) = @_; 612 my ($self, $flags, $prompt) = @_;
547 613
553 my ($self, $color, $text) = @_; 619 my ($self, $color, $text) = @_;
554 620
555 my @color = ( 621 my @color = (
556 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 622 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
557 [1.00, 1.00, 1.00], 623 [1.00, 1.00, 1.00],
558 [0.00, 0.00, 0.55], 624 [0.50, 0.50, 1.00], # changed
559 [1.00, 0.00, 0.00], 625 [1.00, 0.00, 0.00],
560 [1.00, 0.54, 0.00], 626 [1.00, 0.54, 0.00],
561 [0.11, 0.56, 1.00], 627 [0.11, 0.56, 1.00],
562 [0.93, 0.46, 0.00], 628 [0.93, 0.46, 0.00],
563 [0.18, 0.54, 0.34], 629 [0.18, 0.54, 0.34],
607 }, 673 },
608); 674);
609 675
610############################################################################# 676#############################################################################
611 677
612$FACECACHE = CFClient::db_table "facecache"; 678$TILECACHE = CFClient::db_table "tilecache";
679$FACEMAP = CFClient::db_table "facemap";
613 680
614CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 681CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
615 682
616my %DEF_CFG = ( 683my %DEF_CFG = (
617 sdl_mode => 0, 684 sdl_mode => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines