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

# User Rev Content
1 root 1.27 #! perl # optional
2 root 1.1
3     # optional plug-in to speed up worldmap rendering by dynamically
4 root 1.8 # generating it out of an image
5 root 1.1 # - saves loading time (less data to read)
6     # - saves temporary space (only overlay stuff needs to be saved)
7 root 1.8 # - might get reused as a generic tiled map
8 root 1.1
9 root 1.30 cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
10    
11 root 1.8 use Coro::Handle;
12     use Coro::AIO;
13 root 1.1
14 root 1.40 my $TILE_W = 50;
15     my $TILE_H = 50;
16 root 1.1
17 root 1.40 my $GRID_W = 30;
18     my $GRID_H = 30;
19 root 1.8
20 root 1.40 our $ARCH;
21     our $REGN;
22 root 1.11
23 root 1.22 sub reload() {
24 root 1.40 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 root 1.1 }
29    
30 root 1.35 {
31 root 1.8 my $guard = cf::lock_acquire "ext::world_gridmap";
32 root 1.35
33     cf::post_init {
34     cf::async_ext {
35     $Coro::current->{desc} = "worldmap loader";
36     reload;
37     undef $guard;
38     };
39 root 1.23 };
40 root 1.35 }
41 root 1.8
42 root 1.1 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 root 1.8 my ($x, $y) = $self->wxwy;
52 root 1.1
53 root 1.8 my $guard = cf::lock_acquire "ext::world_gridmap";
54 root 1.1
55 root 1.40 $self->width ($TILE_W);
56     $self->height ($TILE_H);
57 root 1.3
58 root 1.6 $self->name ("'The World' at +$x+$y");
59 root 1.1 $self->msg ("worldmap dynamically created by map-world extension");
60 root 1.8 $self->outdoor (1);
61 root 1.20 $self->default_region (cf::region::find "wilderness");
62 root 1.1
63 root 1.12 $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 root 1.7
68 root 1.29 my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y;
69 root 1.28
70     $self->{load_path} = $overlay
71     unless Coro::AIO::aio_stat $overlay;
72 root 1.1
73 root 1.24 $self->{need_create_treasure} = 1;
74    
75 root 1.1 1
76     }
77    
78 root 1.13 sub fill {
79     my ($self) = @_;
80    
81 root 1.40 $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 root 1.13 }
84    
85 root 1.1 sub load {
86     my ($self) = @_;
87    
88     if ($self->{load_path}) {
89     $self->SUPER::load;
90     } else {
91 root 1.2 $self->alloc;
92 root 1.13 $self->fill;
93 root 1.33 $self->in_memory (cf::MAP_ACTIVE);
94 root 1.26 $self->activate;
95 root 1.1 }
96     }
97    
98 root 1.3 sub post_load {
99 root 1.1 my ($self) = @_;
100    
101 root 1.26 {
102     my $guard = cf::lock_acquire "ext::world_gridmap";
103 root 1.8
104 root 1.26 my ($x, $y) = $self->wxwy;
105 root 1.1
106 root 1.26 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
107 root 1.40 my $stride = $GRID_W * $TILE_W;
108     my $top = ($y - 100) * $TILE_H * $stride
109     + ($x - 100) * $TILE_W;
110 root 1.26
111 root 1.40 $self->add_underlay ($ARCH->{tbl}, $top, $stride, $ARCH->{plt});
112     $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt});
113 root 1.26
114     } else {
115     $self->fill;
116     }
117 root 1.1 }
118 root 1.24
119 root 1.26 $self->create_region_treasure
120     if delete $self->{need_create_treasure};
121 root 1.1 }
122