ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-world.ext
Revision: 1.40
Committed: Fri Apr 22 02:03:11 2011 UTC (13 years, 1 month ago) by root
Branch: MAIN
Changes since 1.39: +19 -78 lines
Log Message:
move gridmap to arch, refactor cf.pm a bit

File Contents

# Content
1 #! perl # optional
2
3 # optional plug-in to speed up worldmap rendering by dynamically
4 # generating it out of an image
5 # - saves loading time (less data to read)
6 # - saves temporary space (only overlay stuff needs to be saved)
7 # - might get reused as a generic tiled map
8
9 cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
10
11 use Coro::Handle;
12 use Coro::AIO;
13
14 my $TILE_W = 50;
15 my $TILE_H = 50;
16
17 my $GRID_W = 30;
18 my $GRID_H = 30;
19
20 our $ARCH;
21 our $REGN;
22
23 sub reload() {
24 cf::trace "loading world+100+100 table.\n";
25 $ARCH = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.arch";
26 $REGN = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.regn";
27 cf::trace "loaded world+100+100 table.\n";
28 }
29
30 {
31 my $guard = cf::lock_acquire "ext::world_gridmap";
32
33 cf::post_init {
34 cf::async_ext {
35 $Coro::current->{desc} = "worldmap loader";
36 reload;
37 undef $guard;
38 };
39 };
40 }
41
42 sub wxwy {
43 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$}
44 ? ($1, $2)
45 : (0, 0)
46 }
47
48 sub load_header_orig {
49 my ($self) = @_;
50
51 my ($x, $y) = $self->wxwy;
52
53 my $guard = cf::lock_acquire "ext::world_gridmap";
54
55 $self->width ($TILE_W);
56 $self->height ($TILE_H);
57
58 $self->name ("'The World' at +$x+$y");
59 $self->msg ("worldmap dynamically created by map-world extension");
60 $self->outdoor (1);
61 $self->default_region (cf::region::find "wilderness");
62
63 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0;
64 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999;
65 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999;
66 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0;
67
68 my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y;
69
70 $self->{load_path} = $overlay
71 unless Coro::AIO::aio_stat $overlay;
72
73 $self->{need_create_treasure} = 1;
74
75 1
76 }
77
78 sub fill {
79 my ($self) = @_;
80
81 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, $ARCH->{plt});
82 $self->default_region (cf::region::find $REGN->{plt}[0]);
83 }
84
85 sub load {
86 my ($self) = @_;
87
88 if ($self->{load_path}) {
89 $self->SUPER::load;
90 } else {
91 $self->alloc;
92 $self->fill;
93 $self->in_memory (cf::MAP_ACTIVE);
94 $self->activate;
95 }
96 }
97
98 sub post_load {
99 my ($self) = @_;
100
101 {
102 my $guard = cf::lock_acquire "ext::world_gridmap";
103
104 my ($x, $y) = $self->wxwy;
105
106 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
107 my $stride = $GRID_W * $TILE_W;
108 my $top = ($y - 100) * $TILE_H * $stride
109 + ($x - 100) * $TILE_W;
110
111 $self->add_underlay ($ARCH->{tbl}, $top, $stride, $ARCH->{plt});
112 $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt});
113
114 } else {
115 $self->fill;
116 }
117 }
118
119 $self->create_region_treasure
120 if delete $self->{need_create_treasure};
121 }
122