ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.582 by root, Fri Feb 3 03:01:45 2012 UTC vs.
Revision 1.587 by root, Wed Oct 31 19:09:47 2012 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
10# 10#
11# This program is distributed in the hope that it will be useful, 11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details. 14# GNU General Public License for more details.
15# 15#
16# You should have received a copy of the Affero GNU General Public License 16# You should have received a copy of the Affero GNU General Public License
17# and the GNU General Public License along with this program. If not, see 17# and the GNU General Public License along with this program. If not, see
18# <http://www.gnu.org/licenses/>. 18# <http://www.gnu.org/licenses/>.
19# 19#
20# The authors can be reached via e-mail to <support@deliantra.net> 20# The authors can be reached via e-mail to <support@deliantra.net>
21# 21#
22 22
23package cf; 23package cf;
24 24
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35use Carp (); 35use Carp ();
36 36
37use Guard (); 37use AnyEvent ();
38use AnyEvent::IO ();
39use AnyEvent::DNS ();
40
38use Coro (); 41use Coro ();
39use Coro::State; 42use Coro::State;
40use Coro::Handle; 43use Coro::Handle;
41use Coro::EV; 44use Coro::EV;
42use Coro::AnyEvent; 45use Coro::AnyEvent;
48use Coro::AIO; 51use Coro::AIO;
49use Coro::BDB 1.6; 52use Coro::BDB 1.6;
50use Coro::Storable; 53use Coro::Storable;
51use Coro::Util (); 54use Coro::Util ();
52 55
56use Guard ();
53use JSON::XS 2.01 (); 57use JSON::XS 2.01 ();
54use BDB (); 58use BDB ();
55use Data::Dumper; 59use Data::Dumper;
56use Fcntl; 60use Fcntl;
57use YAML::XS (); 61use YAML::XS ();
336)) { 340)) {
337 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 341 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
338} 342}
339 343
340$EV::DIED = sub { 344$EV::DIED = sub {
341 Carp::cluck "error in event callback: @_"; 345 warn "error in event callback: $@";
342}; 346};
343 347
344############################################################################# 348#############################################################################
345 349
346sub fork_call(&@); 350sub fork_call(&@);
3503=cut 3507=cut
3504 3508
3505############################################################################# 3509#############################################################################
3506# the server's init and main functions 3510# the server's init and main functions
3507 3511
3512our %FACEHASH; # hash => idx, #d# HACK for http server
3513
3508sub load_facedata($) { 3514sub load_facedata($) {
3509 my ($path) = @_; 3515 my ($path) = @_;
3510 3516
3511 # HACK to clear player env face cache, we need some signal framework 3517 # HACK to clear player env face cache, we need some signal framework
3512 # for this (global event?) 3518 # for this (global event?)
3531 cf::cede_to_tick; 3537 cf::cede_to_tick;
3532 3538
3533 { 3539 {
3534 my $faces = $facedata->{faceinfo}; 3540 my $faces = $facedata->{faceinfo};
3535 3541
3536 while (my ($face, $info) = each %$faces) { 3542 for my $face (sort keys %$faces) {
3543 my $info = $faces->{$face};
3537 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3544 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3538 3545
3539 cf::face::set_visibility $idx, $info->{visibility}; 3546 cf::face::set_visibility $idx, $info->{visibility};
3540 cf::face::set_magicmap $idx, $info->{magicmap}; 3547 cf::face::set_magicmap $idx, $info->{magicmap};
3541 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3548 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3542 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; 3549 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64};
3543 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; 3550 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ;
3551 $FACEHASH{$info->{hash64}} = $idx;#d#
3544 3552
3545 cf::cede_to_tick; 3553 cf::cede_to_tick;
3546 } 3554 }
3547 3555
3548 while (my ($face, $info) = each %$faces) { 3556 while (my ($face, $info) = each %$faces) {
3582 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3590 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3583 3591
3584 cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; 3592 cf::face::set_data $idx, 0, $info->{data}, $info->{hash};
3585 cf::face::set_type $idx, $type; 3593 cf::face::set_type $idx, $type;
3586 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already 3594 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already
3595 $FACEHASH{$info->{hash}} = $idx;#d#
3587 } else { 3596 } else {
3588# $RESOURCE{$name} = $info; # unused 3597# $RESOURCE{$name} = $info; # unused
3589 } 3598 }
3590 3599
3591 cf::cede_to_tick; 3600 cf::cede_to_tick;
3736 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3745 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3737 3746
3738 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3747 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3739 3748
3740 # we must not ever block the main coroutine 3749 # we must not ever block the main coroutine
3741 local $Coro::idle = sub { 3750 $Coro::idle = sub {
3742 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3751 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3743 (async { 3752 (async {
3744 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3753 $Coro::current->{desc} = "IDLE BUG HANDLER";
3745 EV::loop EV::LOOP_ONESHOT; 3754 EV::loop EV::LOOP_ONESHOT;
3746 })->prio (Coro::PRIO_MAX); 3755 })->prio (Coro::PRIO_MAX);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines