… | |
… | |
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 | |
72 | sub check_lwp($) { |
|
|
73 | my ($res) = @_; |
|
|
74 | |
|
|
75 | $res->is_error |
|
|
76 | and die $res->status_line; |
|
|
77 | |
|
|
78 | $res |
|
|
79 | } |
|
|
80 | |
|
|
81 | sub editor_invoke { |
72 | sub 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 | my ($pid, $fh); |
76 | 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"; |
77 | print "preparing editor startup...\n"; |
99 | CFPlus::set_proxy; |
|
|
100 | |
78 | |
101 | my $server = $editsup->{gameserver} || "default"; |
79 | my $server = $editsup->{gameserver} || "default"; |
102 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
80 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
103 | |
81 | |
104 | 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; |
105 | 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; |
106 | |
84 | |
107 | print "map directory is $mapdir\n"; |
85 | print "map directory is $mapdir\n"; |
108 | print "lib directory is $libdir\n"; |
86 | print "lib directory is $libdir\n"; |
109 | |
87 | |
110 | require LWP::UserAgent; |
88 | my $ua = CFPlus::lwp_useragent; |
111 | |
|
|
112 | my $ua = LWP::UserAgent->new ( |
|
|
113 | agent => "cfplus $CFPlus::VERSION", |
|
|
114 | keep_alive => 1, |
|
|
115 | env_proxy => 1, |
|
|
116 | timeout => 30, |
|
|
117 | ); |
|
|
118 | |
89 | |
119 | for my $file (qw(archetypes crossfire.0)) { |
90 | for my $file (qw(archetypes crossfire.0)) { |
120 | my $url = "$editsup->{lib_root}$file"; |
91 | my $url = "$editsup->{lib_root}$file"; |
121 | print "mirroring $url...\n"; |
92 | print "mirroring $url...\n"; |
122 | check_lwp $ua->mirror ($url, "$libdir/$file"); |
93 | CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file"); |
123 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
94 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
124 | } |
95 | } |
125 | |
96 | |
126 | if (1) { # upload a map |
97 | if (1) { # upload a map |
127 | my $mapname = $::CONN->{map_info}[0]; |
98 | my $mapname = $::CONN->{map_info}[0]; |
128 | |
99 | |
|
|
100 | my $mappath = "$mapdir/$mapname"; |
|
|
101 | |
|
|
102 | -e $mappath and die "$mappath already exists\n"; |
|
|
103 | |
129 | print "getting map revision for $mapname...\n"; |
104 | print "getting map revision for $mapname...\n"; |
130 | |
105 | |
131 | # try to get the most recent head revision, what a hack, |
106 | # try to get the most recent head revision, what a hack, |
132 | # this should have been returned while downloading *sigh* |
107 | # 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; |
108 | my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
134 | |
109 | |
135 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
110 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
136 | my $rev = $1; |
111 | my $rev = $1; |
137 | |
112 | |
138 | print "downloading revision $rev...\n"; |
113 | print "downloading revision $rev...\n"; |
139 | |
114 | |
140 | 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; |
141 | |
116 | |
142 | my $meta = { |
117 | my $meta = { |
143 | %$editsup, |
118 | %$editsup, |
144 | path => $mapname, |
119 | path => $mapname, |
145 | revision => $rev, |
120 | revision => $rev, |
146 | cf_login => $::PROFILE->{user}, |
121 | cf_login => $::PROFILE->{user}, |
147 | }; |
122 | }; |
148 | |
123 | |
149 | my $mappath = "$mapdir/$mapname"; |
|
|
150 | |
|
|
151 | require File::Basename; |
124 | require File::Basename; |
152 | require File::Path; |
125 | require File::Path; |
153 | |
126 | |
154 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
127 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
155 | open my $fh, ">:raw:perlio", "$mappath.meta" |
128 | open my $fh, ">:raw:perlio", "$mappath.meta" |
156 | or die "$mappath.meta: $!"; |
129 | or die "$mappath.meta: $!\n"; |
157 | print $fh CFPlus::to_json $meta; |
130 | print $fh CFPlus::to_json $meta; |
158 | close $fh; |
131 | close $fh; |
159 | open my $fh, ">:raw:perlio:utf8", $mappath |
132 | open my $fh, ">:raw:perlio:utf8", $mappath |
160 | or die "$mappath: $!"; |
133 | or die "$mappath: $!\n"; |
161 | print $fh $map; |
134 | print $fh $map; |
162 | close $fh; |
135 | close $fh; |
163 | |
136 | |
164 | print "saved as $mappath\n"; |
137 | print "saved as $mappath\n"; |
165 | |
138 | |
… | |
… | |
193 | # } |
166 | # } |
194 | } else { |
167 | } else { |
195 | die "viewvc parse error, unable to detect revision\n"; |
168 | die "viewvc parse error, unable to detect revision\n"; |
196 | } |
169 | } |
197 | } |
170 | } |
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 | }); |
171 | } |
216 | } |
172 | } |
217 | |
173 | |
218 | sub invoke_button_down { |
174 | sub invoke_button_down { |
219 | my ($self, $ev, $x, $y) = @_; |
175 | my ($self, $ev, $x, $y) = @_; |
220 | |
176 | |
221 | if ($ev->{button} == 1) { |
177 | if ($ev->{button} == 1) { |
222 | $self->grab_focus; |
178 | $self->grab_focus; |
223 | return unless $::CONN; |
179 | return unless $::CONN; |
224 | |
180 | |
225 | 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}; |
226 | 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}; |
227 | |
183 | |
228 | $x -= int 0.5 * $self->{sw}; |
184 | $x -= CFPlus::floor $::MAP->w * 0.5; |
229 | $y -= int 0.5 * $self->{sh}; |
185 | $y -= CFPlus::floor $::MAP->h * 0.5; |
230 | |
186 | |
231 | $::CONN->lookat ($x, $y) |
187 | $::CONN->lookat ($x, $y) |
232 | if $::CONN; |
188 | if $::CONN; |
233 | |
189 | |
234 | } elsif ($ev->{button} == 2) { |
190 | } elsif ($ev->{button} == 2) { |
… | |
… | |
473 | } |
429 | } |
474 | |
430 | |
475 | sub set_magicmap { |
431 | sub set_magicmap { |
476 | my ($self, $w, $h, $x, $y, $data) = @_; |
432 | my ($self, $w, $h, $x, $y, $data) = @_; |
477 | |
433 | |
478 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
434 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
479 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
435 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
480 | |
436 | |
481 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
437 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
482 | |
438 | |
483 | $self->update; |
439 | $self->update; |
484 | } |
440 | } |
… | |
… | |
495 | unless $focused || !$::FAST; |
451 | unless $focused || !$::FAST; |
496 | |
452 | |
497 | if (delete $self->{need_update}) { |
453 | if (delete $self->{need_update}) { |
498 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
454 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
499 | |
455 | |
|
|
456 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
|
|
457 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
|
|
458 | |
500 | my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
459 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
501 | my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
460 | my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
502 | |
461 | |
503 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
462 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
504 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
463 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
505 | |
464 | |
506 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
465 | my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
507 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
466 | my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
508 | |
467 | |
509 | if ($::CFG->{fow_enable}) { |
468 | if ($::CFG->{fow_enable}) { |
510 | 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); |
511 | |
470 | |
512 | 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 |
513 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
472 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
514 | glConvolutionFilter2D ( |
473 | glConvolutionFilter2D ( |
515 | GL_CONVOLUTION_2D, |
474 | GL_CONVOLUTION_2D, |
… | |
… | |
537 | |
496 | |
538 | glPushMatrix; |
497 | glPushMatrix; |
539 | glTranslate $sx0, $sy0; |
498 | glTranslate $sx0, $sy0; |
540 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
499 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
541 | |
500 | |
542 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
501 | $::MAP->draw ($dx, $dy, $sw, $sh); |
543 | |
502 | |
544 | glScale 32, 32; |
503 | glScale 32, 32; |
545 | |
504 | |
546 | if (my $tex = $self->{fow_texture}) { |
505 | if (my $tex = $self->{fow_texture}) { |
547 | glEnable GL_TEXTURE_2D; |
506 | glEnable GL_TEXTURE_2D; |
… | |
… | |
554 | } |
513 | } |
555 | |
514 | |
556 | if ($self->{magicmap}) { |
515 | if ($self->{magicmap}) { |
557 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
516 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
558 | |
517 | |
559 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
518 | $x += $::MAP->ox + $self->{dx}; |
560 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
519 | $y += $::MAP->oy + $self->{dy}; |
561 | |
520 | |
562 | glTranslate - $x - 1, - $y - 1; |
521 | glTranslate - $x - 1, - $y - 1; |
563 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
522 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
564 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
523 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
565 | } |
524 | } |