ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.88 by root, Mon Oct 9 01:06:36 2006 UTC vs.
Revision 1.93 by root, Thu Nov 16 19:42:45 2006 UTC

67 ::stop_game (); 67 ::stop_game ();
68 local $::PROFILE->{host} = $server; 68 local $::PROFILE->{host} = $server;
69 ::start_game (); 69 ::start_game ();
70} 70}
71 71
72sub check_lwp($) {
73 my ($res) = @_;
74
75 $res->is_error
76 and die $res->status_line;
77
78 $res
79}
80
81sub editor_invoke { 72sub editor_invoke {
82 my $editsup = $::CONN && $::CONN->{editor_support} 73 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return; 74 or return;
84 75
85 CFPlus::background { 76 CFPlus::background {
86 print "preparing editor startup...\n"; 77 print "preparing editor startup...\n";
87 CFPlus::set_proxy;
88 78
89 my $server = $editsup->{gameserver} || "default"; 79 my $server = $editsup->{gameserver} || "default";
90 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 80 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
91 81
92 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; 82 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
93 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; 83 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
94 84
95 print "map directory is $mapdir\n"; 85 print "map directory is $mapdir\n";
96 print "lib directory is $libdir\n"; 86 print "lib directory is $libdir\n";
97 87
98 require LWP::UserAgent; 88 my $ua = CFPlus::lwp_useragent;
99
100 my $ua = LWP::UserAgent->new (
101 agent => "cfplus $CFPlus::VERSION",
102 keep_alive => 1,
103 env_proxy => 1,
104 timeout => 30,
105 );
106 89
107 for my $file (qw(archetypes crossfire.0)) { 90 for my $file (qw(archetypes crossfire.0)) {
108 my $url = "$editsup->{lib_root}$file"; 91 my $url = "$editsup->{lib_root}$file";
109 print "mirroring $url...\n"; 92 print "mirroring $url...\n";
110 check_lwp $ua->mirror ($url, "$libdir/$file"); 93 CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file");
111 printf "%s size %d octets\n", $file, -s "$libdir/$file"; 94 printf "%s size %d octets\n", $file, -s "$libdir/$file";
112 } 95 }
113 96
114 if (1) { # upload a map 97 if (1) { # upload a map
115 my $mapname = $::CONN->{map_info}[0]; 98 my $mapname = $::CONN->{map_info}[0];
120 103
121 print "getting map revision for $mapname...\n"; 104 print "getting map revision for $mapname...\n";
122 105
123 # try to get the most recent head revision, what a hack, 106 # try to get the most recent head revision, what a hack,
124 # this should have been returned while downloading *sigh* 107 # this should have been returned while downloading *sigh*
125 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; 108 my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
126 109
127 if ($log =~ /\?rev=(\d+\.\d+)"/) { 110 if ($log =~ /\?rev=(\d+\.\d+)"/) {
128 my $rev = $1; 111 my $rev = $1;
129 112
130 print "downloading revision $rev...\n"; 113 print "downloading revision $rev...\n";
131 114
132 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; 115 my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
133 116
134 my $meta = { 117 my $meta = {
135 %$editsup, 118 %$editsup,
136 path => $mapname, 119 path => $mapname,
137 revision => $rev, 120 revision => $rev,
193 176
194 if ($ev->{button} == 1) { 177 if ($ev->{button} == 1) {
195 $self->grab_focus; 178 $self->grab_focus;
196 return unless $::CONN; 179 return unless $::CONN;
197 180
198 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 181 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize};
199 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 182 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize};
200 183
201 $x -= int 0.5 * $self->{sw}; 184 $x -= CFPlus::floor $::MAP->w * 0.5;
202 $y -= int 0.5 * $self->{sh}; 185 $y -= CFPlus::floor $::MAP->h * 0.5;
203 186
204 $::CONN->lookat ($x, $y) 187 $::CONN->lookat ($x, $y)
205 if $::CONN; 188 if $::CONN;
206 189
207 } elsif ($ev->{button} == 2) { 190 } elsif ($ev->{button} == 2) {
446} 429}
447 430
448sub set_magicmap { 431sub set_magicmap {
449 my ($self, $w, $h, $x, $y, $data) = @_; 432 my ($self, $w, $h, $x, $y, $data) = @_;
450 433
451 $x -= $::MAP->ox + int 0.5 * $::MAP->w; 434 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
452 $y -= $::MAP->oy + int 0.5 * $::MAP->h; 435 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
453 436
454 $self->{magicmap} = [$x, $y, $w, $h, $data]; 437 $self->{magicmap} = [$x, $y, $w, $h, $data];
455 438
456 $self->update; 439 $self->update;
457} 440}
468 unless $focused || !$::FAST; 451 unless $focused || !$::FAST;
469 452
470 if (delete $self->{need_update}) { 453 if (delete $self->{need_update}) {
471 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 454 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
472 455
456 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
457 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
458
473 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 459 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
474 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 460 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
475 461
476 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 462 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
477 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 463 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
478 464
479 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 465 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
480 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 466 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
481 467
482 if ($::CFG->{fow_enable}) { 468 if ($::CFG->{fow_enable}) {
483 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 469 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
484 470
485 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 471 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
486 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 472 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
487 glConvolutionFilter2D ( 473 glConvolutionFilter2D (
488 GL_CONVOLUTION_2D, 474 GL_CONVOLUTION_2D,
510 496
511 glPushMatrix; 497 glPushMatrix;
512 glTranslate $sx0, $sy0; 498 glTranslate $sx0, $sy0;
513 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 499 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
514 500
515 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 501 $::MAP->draw ($dx, $dy, $sw, $sh);
516 502
517 glScale 32, 32; 503 glScale 32, 32;
518 504
519 if (my $tex = $self->{fow_texture}) { 505 if (my $tex = $self->{fow_texture}) {
520 glEnable GL_TEXTURE_2D; 506 glEnable GL_TEXTURE_2D;
527 } 513 }
528 514
529 if ($self->{magicmap}) { 515 if ($self->{magicmap}) {
530 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 516 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
531 517
532 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); 518 $x += $::MAP->ox + $self->{dx};
533 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); 519 $y += $::MAP->oy + $self->{dy};
534 520
535 glTranslate - $x - 1, - $y - 1; 521 glTranslate - $x - 1, - $y - 1;
536 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 522 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
537 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 523 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
538 } 524 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines