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.7 by root, Fri Jan 26 20:59:57 2007 UTC vs.
Revision 1.44 by root, Wed May 4 07:41:13 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 }
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->outdoor (1); 84 $self->name (sprintf "'The World' at %+d%+d%+d", $x, $y, $z);
85 $self->msg ("worldmap dynamically created by map-world extension");
86 $self->outdoor ($self->{z} >= 0);
87 $self->default_region (cf::region::find "wilderness");
37 88
38 $self->name ("'The World' at +$x+$y"); 89 # all possible worldmap tiles also exist
39 $self->msg ("worldmap dynamically created by map-world extension"); 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);
40 96
41# $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 97 # an overlay always wins
42# $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; 98 my $overlay = sprintf "%s/%s.map", $cf::MAPDIR, format_xyz $x, $y, $z;
43# $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999;
44# $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0;
45 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 100;
46 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 129;
47 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 129;
48 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 100;
49 99
50 #TODO: region 100 $self->{load_path} = $overlay
51 101 unless Coro::AIO::aio_stat $overlay;
52 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y 102
53 if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx} 103 $self->{need_create_treasure} = 1;
54 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
55 104
56 1 105 1
57} 106}
58 107
59sub load { 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 {
60 my ($self) = @_; 111 my ($self) = @_;
61 112
62 if ($self->{load_path}) { 113 if ($self->{z} > 0) {
63 $self->SUPER::load; 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"]);
64 } else { 118 } else {
65 $self->alloc; 119 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, ["deep_sea"]);
66
67 for my $X (0 .. $WORLD->{tilew} - 1) {
68 Coro::cede;
69 for my $Y (0 .. $WORLD->{tileh} - 1) {
70 my $ob = cf::object::new "deep_sea";
71 $self->insert ($ob, $X, $Y);
72 }
73 }
74 $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1);
75
76 $self->in_memory (cf::MAP_IN_MEMORY);
77 } 120 }
78} 121}
79 122
123#sub load {
124# my ($self) = @_;
125#
126# if ($self->{load_path}) {
127# warn "load $self\n";#d#
128# $self->SUPER::load;
129# } else {
130# warn "fill $self\n";#d#
131# my $guard = cf::lock_acquire "map_data:$self->{path}";
132#
133# $self->alloc;
134# $self->fill;
135# $self->state (cf::MAP_ACTIVE);
136# $self->activate;
137# $self->post_load;
138# }
139#}
140
141# MUST be overwritten to call at least ->fill
80sub post_load { 142sub post_load {
81 my ($self) = @_; 143 my ($self) = @_;
82 144
83 my ($x, $y) = $self->wxwy; 145 $self->create_region_treasure
84 146 if delete $self->{need_create_treasure};
85 return
86 unless $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
87 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
88
89 my $stride = ($WORLD->{maxx} - $WORLD->{minx} + 1) * $WORLD->{tilew};
90 my $top = ($y - $WORLD->{miny}) * $WORLD->{tileh} * $stride
91 + ($x - $WORLD->{minx}) * $WORLD->{tilew};
92
93 for my $Y (0 .. $WORLD->{tileh} - 1) {
94 Coro::cede;
95 my $row = substr $WORLD->{data}, $top + $Y * $stride, $WORLD->{tilew};
96 for my $X (0 .. $WORLD->{tilew} - 1) {
97 next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y);
98 my $ob = cf::object::new $WORLD->{arch}[ord substr $row, $X];
99 $ob->flag (cf::FLAG_NO_MAP_SAVE, 1);
100 $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY);
101 }
102 }
103} 147}
104 148
1051
106

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines