ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-world.ext
Revision: 1.7
Committed: Fri Jan 26 20:59:57 2007 UTC (17 years, 3 months ago) by root
Branch: MAIN
Changes since 1.6: +9 -6 lines
Log Message:
- tame the map/map-world.ext a bit to avoid potential memleaks for now
- object refcounting was borked, fixed, again :)
- add cf::attacahble::mortals_size
- disable reset-after-load, this is unsafe due to locking issues, so don't do it
- make map-scheduler configurable
- improve emergency swap mode
- prepare_random_map must be a sync job for now :(
- do not keep object reference in enter_exit, the object might have been gone already.
- nuke cf::object::mortals.

File Contents

# Content
1 #! perl # OPTIONAL
2
3 # optional plug-in to speed up worldmap rendering by dynamically
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
8 our $WORLD = Storable::retrieve cf::datadir . "/world.pst"
9 or die "unable to load world.pst";
10
11 $WORLD->{version} == 1
12 or die "world.pst version mismatch, expected version 1, got $WORLD->{version}";
13
14 cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
15
16 sub init {
17 my ($self) = @_;
18
19 1
20 }
21
22 sub wxwy {
23 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$}
24 ? ($1, $2)
25 : (0, 0)
26 }
27
28 sub load_header_orig {
29 my ($self) = @_;
30
31 $self->width ($WORLD->{tilew});
32 $self->height ($WORLD->{tileh});
33
34 my ($x, $y) = $self->wxwy;
35
36 $self->outdoor (1);
37
38 $self->name ("'The World' at +$x+$y");
39 $self->msg ("worldmap dynamically created by map-world extension");
40
41 # $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0;
42 # $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999;
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
50 #TODO: region
51
52 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y
53 if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
54 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
55
56 1
57 }
58
59 sub load {
60 my ($self) = @_;
61
62 if ($self->{load_path}) {
63 $self->SUPER::load;
64 } else {
65 $self->alloc;
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 }
78 }
79
80 sub post_load {
81 my ($self) = @_;
82
83 my ($x, $y) = $self->wxwy;
84
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 }
104
105 1
106