ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-world.ext
(Generate patch)

Comparing deliantra/server/ext/map-world.ext (file contents):
Revision 1.3 by root, Sun Jan 21 13:08:36 2007 UTC vs.
Revision 1.45 by root, Wed May 4 16:12:15 2011 UTC

1#! perl # OPTIONAL 1#! perl # mandatory
2 2
3# optional plug-in to speed up worldmap rendering by dynamically 3# manages the worldmap by directing to other handlers
4# generating it out of a image
5# - saves loading time (less data to read)
6# - saves temporary space (only overlay stuff needs to be saved)
7 4
8our $WORLD = Storable::retrieve cf::datadir . "/world.pst" 5cf::map->register (qr{^/world/world_(-?\d+)_(-?\d+)(?:_(-?\d+))?$}, 100);
9 or die "unable to load world.pst";
10 6
11$WORLD->{version} == 1 7# universal
12 or die "world.pst version mismatch, expected version 1, got $WORLD->{version}"; 8our $TILE_W = 50;
9our $TILE_H = 50;
13 10
14cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); 11# registry
12our @AREAS;
13
14sub register($$$$$$$@) {
15 my $meta = {
16 pkg => shift,
17 x0 => shift, y0 => shift, z0 => shift,
18 x1 => shift, y1 => shift, z1 => shift,
19 @_
20 };
21
22 my $pkg = $meta->{pkg};
23
24 @AREAS = sort { $b->{pri} <=> $a->{pri} }
25 $meta,
26 grep $pkg ne $_->{pkg},
27 @AREAS;
28
29 my $isa = \@{"$pkg\::ISA"};
30
31 @$isa = (
32 __PACKAGE__,
33 grep __PACKAGE__ ne $_, @$isa
34 );
35}
36
37sub format_xyz($$;$) {
38 sprintf "/world/world_%03d_%03d%s",
39 $_[0], $_[1],
40 $_[2] ? sprintf "_%03d", $_[2] : "";
41}
42
43#############################################################################
15 44
16sub init { 45sub init {
17 my ($self) = @_; 46 my ($self) = @_;
18 47
48 my ($x, $y, $z) = @$self{qw(x y z)} = ($1, $2, $3+0);
49
50 # find handler for this area
51 for my $meta (@AREAS) {
52 if ( $meta->{x0} <= $x && $x <= $meta->{x1}
53 && $meta->{y0} <= $y && $y <= $meta->{y1}
54 && $meta->{z0} <= $z && $z <= $meta->{z1}
55 ) {
56 $self->{ox} = $x - $meta->{x0};
57 $self->{oy} = $y - $meta->{y0};
58 $self->{oz} = $z - $meta->{z0};
59
60 bless $self, $meta->{pkg};
61
62 $self->init_worldmap ($meta);
63
64 last;
65 }
19 1 66 }
67
68 $self->SUPER::init;
20} 69}
21 70
22sub wxwy { 71sub init_worldmap {
23 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} 72 # only for handlers
24 ? ($1, $2)
25 : (0, 0)
26} 73}
27 74
28sub load_header_orig { 75sub load_header_orig {
29 my ($self) = @_; 76 my ($self) = @_;
30 77
31 $self->width ($WORLD->{tilew}); 78 my ($x, $y, $z) = @$self{qw(x y z)};
32 $self->height ($WORLD->{tileh});
33 79
34 my ($x, $y) = $self->wxwy; 80 $self->width ($TILE_W);
81 $self->height ($TILE_H);
35 82
36 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 83 $self->name (sprintf "'The World' at %+d%+d%+d", $x, $y, $z);
37 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; 84 $self->msg ("worldmap dynamically created by map-world extension");
38 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; 85 $self->outdoor ($self->{z} >= 0);
39 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; 86 $self->default_region (cf::region::find "wilderness");
40 87
41 $self->outdoor (1); 88 # all possible worldmap tiles also exist
89 $self->tile_path (0, format_xyz $x, $y - 1, $z);
90 $self->tile_path (1, format_xyz $x + 1, $y, $z);
91 $self->tile_path (2, format_xyz $x, $y + 1, $z);
92 $self->tile_path (3, format_xyz $x - 1, $y, $z);
93 $self->tile_path (4, format_xyz $x, $y, $z + 1);
94 $self->tile_path (5, format_xyz $x, $y, $z - 1);
42 95
43 $self->msg ("worldmap dynamically created by map-world extension"); 96 # an overlay always wins
97 my $overlay = sprintf "%s/%s.map", $cf::MAPDIR, format_xyz $x, $y, $z;
44 98
45 #TODO: region 99 $self->{load_path} = $overlay
46 100 unless Coro::AIO::aio_stat $overlay;
47 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y
48 if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
49 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
50 101
102 $self->{need_create_treasure} = 1;
51 103
52 1 104 1
53} 105}
54 106
55sub load { 107# fill map with "default" data - first region and first archetype from palette
108# used when we have no map data from elsewhere
109sub fill {
56 my ($self) = @_; 110 my ($self) = @_;
57 111
58 if ($self->{load_path}) { 112 if ($self->{z} > 0) {
59 $self->SUPER::load; 113 # hmmm... air? :)
114 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["blocked"]);
115 } elsif ($self->{z} < 0) {
116 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["blocked"]);
60 } else { 117 } else {
61 $self->alloc; 118 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["deep_sea"]);
62
63 for my $X (0 .. $WORLD->{tilew} - 1) {
64 Coro::cede;
65 for my $Y (0 .. $WORLD->{tileh} - 1) {
66 my $ob = cf::object::new "deep_sea";
67 $self->insert ($ob, $X, $Y);
68 }
69 }
70 $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1);
71
72 $self->in_memory (cf::MAP_IN_MEMORY);
73 } 119 }
74} 120}
75 121
122#sub load {
123# my ($self) = @_;
124#
125# if ($self->{load_path}) {
126# warn "load $self\n";#d#
127# $self->SUPER::load;
128# } else {
129# warn "fill $self\n";#d#
130# my $guard = cf::lock_acquire "map_data:$self->{path}";
131#
132# $self->alloc;
133# $self->fill;
134# $self->state (cf::MAP_ACTIVE);
135# $self->activate;
136# $self->post_load;
137# }
138#}
139
140# MUST be overwritten to call at least ->fill
76sub post_load { 141sub post_load {
77 my ($self) = @_; 142 my ($self) = @_;
78 143
79 my ($x, $y) = $self->wxwy; 144 $self->create_region_treasure
80 145 if delete $self->{need_create_treasure};
81 my $stride = ($WORLD->{maxx} - $WORLD->{minx} + 1) * $WORLD->{tilew};
82 my $top = ($y - $WORLD->{miny}) * $WORLD->{tileh} * $stride
83 + ($x - $WORLD->{minx}) * $WORLD->{tilew};
84
85 for my $Y (0 .. $WORLD->{tileh} - 1) {
86 Coro::cede;
87 my $row = substr $WORLD->{data}, $top + $Y * $stride, $WORLD->{tilew};
88 for my $X (0 .. $WORLD->{tilew} - 1) {
89 next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y);
90 my $ob = cf::object::new $WORLD->{arch}[ord substr $row, $X];
91 $ob->flag (cf::FLAG_NO_MAP_SAVE, 1);
92 $self->insert ($ob, $X, $Y);
93 }
94 }
95} 146}
96 147
971
98

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines