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.86 by root, Sun Oct 8 21:54:20 2006 UTC vs.
Revision 1.91 by root, Tue Nov 7 22:41:27 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 my ($pid, $fh); 85 CFPlus::background {
86 unless ($pid = open $fh, "-|:utf8", "-") {
87 $SIG{__DIE__} = sub {
88 warn "FATAL: @_\n";
89 CFPlus::_exit 99;
90 };
91
92 open STDERR, ">&STDOUT";
93 binmode STDOUT, ":utf8";
94 binmode STDERR, ":utf8";
95 close $fh;
96
97 $| = 1;
98 print "preparing editor startup...\n"; 86 print "preparing editor startup...\n";
99 CFPlus::set_proxy; 87 CFPlus::set_proxy;
100 88
101 my $server = $editsup->{gameserver} || "default"; 89 my $server = $editsup->{gameserver} || "default";
102 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 90 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
124 } 112 }
125 113
126 if (1) { # upload a map 114 if (1) { # upload a map
127 my $mapname = $::CONN->{map_info}[0]; 115 my $mapname = $::CONN->{map_info}[0];
128 116
117 my $mappath = "$mapdir/$mapname";
118
119 -e $mappath and die "$mappath already exists\n";
120
129 print "getting map revision for $mapname...\n"; 121 print "getting map revision for $mapname...\n";
130 122
131 # try to get the most recent head revision, what a hack, 123 # try to get the most recent head revision, what a hack,
132 # this should have been returned while downloading *sigh* 124 # this should have been returned while downloading *sigh*
133 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;
144 path => $mapname, 136 path => $mapname,
145 revision => $rev, 137 revision => $rev,
146 cf_login => $::PROFILE->{user}, 138 cf_login => $::PROFILE->{user},
147 }; 139 };
148 140
149 my $mappath = "$mapdir/$mapname";
150
151 require File::Basename; 141 require File::Basename;
152 require File::Path; 142 require File::Path;
153 143
154 File::Path::mkpath (File::Basename::dirname ($mappath)); 144 File::Path::mkpath (File::Basename::dirname ($mappath));
155 open my $fh, ">:raw:perlio", "$mappath.meta" 145 open my $fh, ">:raw:perlio", "$mappath.meta"
156 or die "$mappath.meta: $!"; 146 or die "$mappath.meta: $!\n";
157 print $fh CFPlus::to_json $meta; 147 print $fh CFPlus::to_json $meta;
158 close $fh; 148 close $fh;
159 open my $fh, ">:raw:perlio:utf8", $mappath 149 open my $fh, ">:raw:perlio:utf8", $mappath
160 or die "$mappath: $!"; 150 or die "$mappath: $!\n";
161 print $fh $map; 151 print $fh $map;
162 close $fh; 152 close $fh;
163 153
164 print "saved as $mappath\n"; 154 print "saved as $mappath\n";
165 155
193# } 183# }
194 } else { 184 } else {
195 die "viewvc parse error, unable to detect revision\n"; 185 die "viewvc parse error, unable to detect revision\n";
196 } 186 }
197 } 187 }
198
199 CFPlus::_exit;
200 }
201
202 my $buffer;
203
204 Event->io (fd => $fh, poll => 'r', cb => sub {
205 unless (sysread $fh, $buffer, 4096, length $buffer) {
206 $_[0]->w->cancel;
207 $buffer .= "done\n";
208 }
209
210 while ($buffer =~ s/^(.*)\n//) {
211 ::message ({
212 markup => "editor($pid): " . CFPlus::asxml $1,
213 });
214 }
215 }); 188 }
216} 189}
217 190
218sub invoke_button_down { 191sub invoke_button_down {
219 my ($self, $ev, $x, $y) = @_; 192 my ($self, $ev, $x, $y) = @_;
220 193
221 if ($ev->{button} == 1) { 194 if ($ev->{button} == 1) {
222 $self->grab_focus; 195 $self->grab_focus;
223 return unless $::CONN; 196 return unless $::CONN;
224 197
225 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};
226 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};
227 200
228 $x -= int 0.5 * $self->{sw}; 201 $x -= CFPlus::floor $::MAP->w * 0.5;
229 $y -= int 0.5 * $self->{sh}; 202 $y -= CFPlus::floor $::MAP->h * 0.5;
230 203
231 $::CONN->lookat ($x, $y) 204 $::CONN->lookat ($x, $y)
232 if $::CONN; 205 if $::CONN;
233 206
234 } elsif ($ev->{button} == 2) { 207 } elsif ($ev->{button} == 2) {
495 unless $focused || !$::FAST; 468 unless $focused || !$::FAST;
496 469
497 if (delete $self->{need_update}) { 470 if (delete $self->{need_update}) {
498 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 471 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
499 472
473 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
474 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
475
500 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 476 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
501 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 477 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
502 478
503 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 479 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
504 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 480 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
505 481
506 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 482 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
507 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 483 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
508 484
509 if ($::CFG->{fow_enable}) { 485 if ($::CFG->{fow_enable}) {
510 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);
511 487
512 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
513 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 489 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
514 glConvolutionFilter2D ( 490 glConvolutionFilter2D (
515 GL_CONVOLUTION_2D, 491 GL_CONVOLUTION_2D,
537 513
538 glPushMatrix; 514 glPushMatrix;
539 glTranslate $sx0, $sy0; 515 glTranslate $sx0, $sy0;
540 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 516 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
541 517
542 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 518 $::MAP->draw ($dx, $dy, $sw, $sh);
543 519
544 glScale 32, 32; 520 glScale 32, 32;
545 521
546 if (my $tex = $self->{fow_texture}) { 522 if (my $tex = $self->{fow_texture}) {
547 glEnable GL_TEXTURE_2D; 523 glEnable GL_TEXTURE_2D;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines