ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/DB.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/DB.pm (file contents):
Revision 1.19 by root, Mon Aug 20 16:16:06 2007 UTC vs.
Revision 1.20 by root, Tue Aug 28 20:07:18 2007 UTC

70} 70}
71 71
72our $tilemap; 72our $tilemap;
73 73
74sub get_tile_id_sync($) { 74sub get_tile_id_sync($) {
75 my ($hash) = @_; 75 my ($name) = @_;
76 76
77 # fetch the full face table first 77 # fetch the full face table first
78 unless ($tilemap) { 78 unless ($tilemap) {
79 CFPlus::DB::Server::req (table => facemap => sub { $tilemap = $_[0] }); 79 CFPlus::DB::Server::req (table => facemap => sub {
80 $tilemap = $_[0];
81 delete $tilemap->{id};
82 my %maptile = reverse %$tilemap;#d#
83 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d#
84 $tilemap = { };#d#
85 CFPlus::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d#
86 }#d#
87 });
80 sync; 88 sync;
81 } 89 }
82 90
83 $tilemap->{$hash} ||= do { 91 $tilemap->{$name} ||= do {
84 my $id; 92 my $id;
85 CFPlus::DB::Server::req (get_tile_id => $hash, sub { $id = $_[0] }); 93 CFPlus::DB::Server::req (get_tile_id => $name, sub { $id = $_[0] });
86 sync; 94 sync;
87 $id 95 $id
88 } 96 }
89} 97}
90 98
248 256
249 \%kv 257 \%kv
250} 258}
251 259
252sub do_get_tile_id { 260sub do_get_tile_id {
253 my ($hash) = @_; 261 my ($name) = @_;
254 262
255 my $id; 263 my $id;
256 my $table = table "facemap"; 264 my $table = table "facemap";
257 265
258 return $id 266 return $id
259 if $table->db_get ($hash, $id) == 0; 267 if $table->db_get ($name, $id) == 0;
260 268
261 for (1..100) { 269 for (1..100) {
262 my $txn = $DB_ENV->txn_begin; 270 my $txn = $DB_ENV->txn_begin;
263 my $status = $table->db_get (id => $id); 271 my $status = $table->db_get (id => $id);
264 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { 272 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
265 $id = ($id || 64) + 1; 273 $id = ($id || 64) + 1;
266 if ($table->db_put (id => $id) == 0 274 if ($table->db_put (id => $id) == 0
267 && $table->db_put ($hash => $id) == 0) { 275 && $table->db_put ($name => $id) == 0) {
268 $txn->txn_commit; 276 $txn->txn_commit;
269 277
270 return $id; 278 return $id;
271 } 279 }
272 } 280 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines