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.6 by root, Wed Jan 24 03:13:21 2007 UTC vs.
Revision 1.42 by root, Fri Apr 22 06:19:07 2011 UTC

1#! perl # OPTIONAL 1#! perl # optional
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 }
66
19 1 67 }
68
69 $self->SUPER::init;
20} 70}
21 71
22sub wxwy { 72sub init_worldmap {
23 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} 73 # only for handlers
24 ? ($1, $2)
25 : (0, 0)
26} 74}
27 75
28sub load_header_orig { 76sub load_header_orig {
29 my ($self) = @_; 77 my ($self) = @_;
30 78
31 $self->width ($WORLD->{tilew}); 79 my ($x, $y, $z) = @$self{qw(x y z)};
32 $self->height ($WORLD->{tileh});
33 80
34 my ($x, $y) = $self->wxwy; 81 $self->width ($TILE_W);
82 $self->height ($TILE_H);
35 83
36 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 84 $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; 85 $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; 86 $self->outdoor ($self->{z} >= 0);
39 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; 87 $self->default_region (cf::region::find "wilderness");
40 88
41 $self->outdoor (1); 89 # all possible worldmap tiles also exist
90 $self->tile_path (0, format_xyz $x, $y - 1, $z);
91 $self->tile_path (1, format_xyz $x + 1, $y, $z);
92 $self->tile_path (2, format_xyz $x, $y + 1, $z);
93 $self->tile_path (3, format_xyz $x - 1, $y, $z);
94 $self->tile_path (4, format_xyz $x, $y, $z + 1);
95 $self->tile_path (5, format_xyz $x, $y, $z - 1);
42 96
43 $self->name ("'The World' at +$x+$y"); 97 # an overlay always wins
44 $self->msg ("worldmap dynamically created by map-world extension"); 98 my $overlay = sprintf "%s/%s.map", $cf::MAPDIR, format_xyz $x, $y, $z;
45 99
46 #TODO: region 100 $self->{load_path} = $overlay
47 101 unless Coro::AIO::aio_stat $overlay;
48 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y
49 if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
50 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
51 102
103 $self->{need_create_treasure} = 1;
52 104
53 1 105 1
106}
107
108# fill map with "default" data - first region and first archetype from palette
109# used when we have no map data from elsewhere
110sub fill {
111 my ($self) = @_;
112
113 if ($self->{z} > 0) {
114 # hmmm... air? :)
115 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["blocked"]);
116 } elsif ($self->{z} < 0) {
117 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["blocked"]);
118 } else {
119 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["deep_sea"]);
120 }
54} 121}
55 122
56sub load { 123sub load {
57 my ($self) = @_; 124 my ($self) = @_;
58 125
59 if ($self->{load_path}) { 126 if ($self->{load_path}) {
60 $self->SUPER::load; 127 $self->SUPER::load;
61 } else { 128 } else {
62 $self->alloc; 129 $self->alloc;
63 130 $self->fill;
64 for my $X (0 .. $WORLD->{tilew} - 1) {
65 Coro::cede;
66 for my $Y (0 .. $WORLD->{tileh} - 1) {
67 my $ob = cf::object::new "deep_sea";
68 $self->insert ($ob, $X, $Y);
69 }
70 }
71 $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1);
72
73 $self->in_memory (cf::MAP_IN_MEMORY); 131 $self->in_memory (cf::MAP_ACTIVE);
132 $self->activate;
74 } 133 }
75} 134}
76 135
136# MUST be overwritten to call at least ->fill
77sub post_load { 137sub post_load {
78 my ($self) = @_; 138 my ($self) = @_;
79 139
80 my ($x, $y) = $self->wxwy; 140 $self->create_region_treasure
81 141 if delete $self->{need_create_treasure};
82 return
83 unless $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
84 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
85
86 my $stride = ($WORLD->{maxx} - $WORLD->{minx} + 1) * $WORLD->{tilew};
87 my $top = ($y - $WORLD->{miny}) * $WORLD->{tileh} * $stride
88 + ($x - $WORLD->{minx}) * $WORLD->{tilew};
89
90 for my $Y (0 .. $WORLD->{tileh} - 1) {
91 Coro::cede;
92 my $row = substr $WORLD->{data}, $top + $Y * $stride, $WORLD->{tilew};
93 for my $X (0 .. $WORLD->{tilew} - 1) {
94 next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y);
95 my $ob = cf::object::new $WORLD->{arch}[ord substr $row, $X];
96 $ob->flag (cf::FLAG_NO_MAP_SAVE, 1);
97 $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY);
98 }
99 }
100} 142}
101 143
1021
103

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines