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.85 by root, Sun Oct 8 21:22:30 2006 UTC vs.
Revision 1.92 by root, Wed Nov 8 01:22:00 2006 UTC

80 80
81sub editor_invoke { 81sub editor_invoke {
82 my $editsup = $::CONN && $::CONN->{editor_support} 82 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return; 83 or return;
84 84
85 # putting the password into the env is somewhat tasteless 85 CFPlus::background {
86# local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user};
87# local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
88# local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
89
90 my ($pid, $fh);
91 unless ($pid = open $fh, "-|:utf8", "-") {
92 $SIG{__DIE__} = sub {
93 warn "@_\n";
94 CFPlus::_exit 99;
95 };
96
97 open STDERR, ">&STDOUT";
98 binmode STDOUT, ":utf8";
99 binmode STDERR, ":utf8";
100 close $fh;
101
102 $| = 1;
103 print "preparing editor startup...\n"; 86 print "preparing editor startup...\n";
104 CFPlus::set_proxy; 87 CFPlus::set_proxy;
105 88
106 my $server = $editsup->{gameserver} || "default"; 89 my $server = $editsup->{gameserver} || "default";
107 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 90 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
129 } 112 }
130 113
131 if (1) { # upload a map 114 if (1) { # upload a map
132 my $mapname = $::CONN->{map_info}[0]; 115 my $mapname = $::CONN->{map_info}[0];
133 116
117 my $mappath = "$mapdir/$mapname";
118
119 -e $mappath and die "$mappath already exists\n";
120
134 print "getting map revision for $mapname...\n"; 121 print "getting map revision for $mapname...\n";
135 122
136 # try to get the most recent head revision, what a hack, 123 # try to get the most recent head revision, what a hack,
137 # this should have been returned while downloading *sigh* 124 # this should have been returned while downloading *sigh*
138 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; 125 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
141 my $rev = $1; 128 my $rev = $1;
142 129
143 print "downloading revision $rev...\n"; 130 print "downloading revision $rev...\n";
144 131
145 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; 132 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
133
134 my $meta = {
135 %$editsup,
136 path => $mapname,
137 revision => $rev,
138 cf_login => $::PROFILE->{user},
139 };
140
141 require File::Basename;
142 require File::Path;
143
144 File::Path::mkpath (File::Basename::dirname ($mappath));
145 open my $fh, ">:raw:perlio", "$mappath.meta"
146 or die "$mappath.meta: $!\n";
147 print $fh CFPlus::to_json $meta;
148 close $fh;
149 open my $fh, ">:raw:perlio:utf8", $mappath
150 or die "$mappath: $!\n";
151 print $fh $map;
152 close $fh;
153
154 print "saved as $mappath\n";
155
156 print "invoking editor...\n";
157 exec "/root/s2/gce $mappath";#d#
146 158
147 # now upload it 159 # now upload it
148# require HTTP::Request::Common; 160# require HTTP::Request::Common;
149# 161#
150# my $res = $ua->post ( 162# my $res = $ua->post (
171# } 183# }
172 } else { 184 } else {
173 die "viewvc parse error, unable to detect revision\n"; 185 die "viewvc parse error, unable to detect revision\n";
174 } 186 }
175 } 187 }
176
177 print "invoking editor...\n";
178 exec "/root/s2/gce";#d#
179
180 CFPlus::_exit;
181 }
182
183 my $buffer;
184
185 Event->io (fd => $fh, poll => 'r', cb => sub {
186 unless (sysread $fh, $buffer, 4096, length $buffer) {
187 $_[0]->w->cancel;
188 $buffer .= "done\n";
189 }
190
191 while ($buffer =~ s/^(.*)\n//) {
192 ::message ({
193 markup => "editor($pid): " . CFPlus::asxml $1,
194 });
195 }
196 }); 188 }
197} 189}
198 190
199sub invoke_button_down { 191sub invoke_button_down {
200 my ($self, $ev, $x, $y) = @_; 192 my ($self, $ev, $x, $y) = @_;
201 193
202 if ($ev->{button} == 1) { 194 if ($ev->{button} == 1) {
203 $self->grab_focus; 195 $self->grab_focus;
204 return unless $::CONN; 196 return unless $::CONN;
205 197
206 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 198 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize};
207 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 199 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize};
208 200
209 $x -= int 0.5 * $self->{sw}; 201 $x -= CFPlus::floor $::MAP->w * 0.5;
210 $y -= int 0.5 * $self->{sh}; 202 $y -= CFPlus::floor $::MAP->h * 0.5;
211 203
212 $::CONN->lookat ($x, $y) 204 $::CONN->lookat ($x, $y)
213 if $::CONN; 205 if $::CONN;
214 206
215 } elsif ($ev->{button} == 2) { 207 } elsif ($ev->{button} == 2) {
454} 446}
455 447
456sub set_magicmap { 448sub set_magicmap {
457 my ($self, $w, $h, $x, $y, $data) = @_; 449 my ($self, $w, $h, $x, $y, $data) = @_;
458 450
459 $x -= $::MAP->ox + int 0.5 * $::MAP->w; 451 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
460 $y -= $::MAP->oy + int 0.5 * $::MAP->h; 452 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
461 453
462 $self->{magicmap} = [$x, $y, $w, $h, $data]; 454 $self->{magicmap} = [$x, $y, $w, $h, $data];
463 455
464 $self->update; 456 $self->update;
465} 457}
476 unless $focused || !$::FAST; 468 unless $focused || !$::FAST;
477 469
478 if (delete $self->{need_update}) { 470 if (delete $self->{need_update}) {
479 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 471 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
480 472
473 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
474 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
475
481 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 476 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
482 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 477 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
483 478
484 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 479 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
485 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 480 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
486 481
487 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 482 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
488 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 483 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
489 484
490 if ($::CFG->{fow_enable}) { 485 if ($::CFG->{fow_enable}) {
491 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 486 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
492 487
493 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 488 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
494 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 489 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
495 glConvolutionFilter2D ( 490 glConvolutionFilter2D (
496 GL_CONVOLUTION_2D, 491 GL_CONVOLUTION_2D,
518 513
519 glPushMatrix; 514 glPushMatrix;
520 glTranslate $sx0, $sy0; 515 glTranslate $sx0, $sy0;
521 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 516 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
522 517
523 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 518 $::MAP->draw ($dx, $dy, $sw, $sh);
524 519
525 glScale 32, 32; 520 glScale 32, 32;
526 521
527 if (my $tex = $self->{fow_texture}) { 522 if (my $tex = $self->{fow_texture}) {
528 glEnable GL_TEXTURE_2D; 523 glEnable GL_TEXTURE_2D;
535 } 530 }
536 531
537 if ($self->{magicmap}) { 532 if ($self->{magicmap}) {
538 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 533 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
539 534
540 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); 535 $x += $::MAP->ox + $self->{dx};
541 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); 536 $y += $::MAP->oy + $self->{dy};
542 537
543 glTranslate - $x - 1, - $y - 1; 538 glTranslate - $x - 1, - $y - 1;
544 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 539 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
545 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 540 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
546 } 541 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines