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

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.35 by root, Sat Apr 15 22:55:59 2006 UTC vs.
Revision 1.38 by root, Mon Apr 17 06:50:26 2006 UTC

100 -Verbose => 1, 100 -Verbose => 1,
101 -Flags => DB_CREATE | DB_JOINENV | DB_RECOVER_FATAL | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, 101 -Flags => DB_CREATE | DB_JOINENV | DB_RECOVER_FATAL | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN,
102 or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; 102 or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error";
103 103
104sub db_table($) { 104sub db_table($) {
105 my ($table) = @_;
106
107 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
108
105 new CFClient::Database 109 new CFClient::Database
106 -Env => $DB_ENV, 110 -Env => $DB_ENV,
111 -Filename => $table,
107 -Filename => "database", 112# -Filename => "database",
108 -Subname => $_[0], 113# -Subname => $table,
109 -Flags => DB_CREATE | DB_UPGRADE, 114 -Flags => DB_CREATE | DB_UPGRADE,
110 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; 115 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error";
111} 116}
112 117
113package CFClient::Database; 118package CFClient::Database;
117sub get($$) { 122sub get($$) {
118 my $data; 123 my $data;
119 124
120 $_[0]->db_get ($_[1], $data) == 0 125 $_[0]->db_get ($_[1], $data) == 0
121 ? $data 126 ? $data
122 : (); 127 : ()
123} 128}
124 129
125my %DB_SYNC; 130my %DB_SYNC;
126 131
127sub put($$$) { 132sub put($$$) {
128 my ($db, $key, $data) = @_; 133 my ($db, $key, $data) = @_;
129 134
130 $db->db_put ($key => $data);
131
132 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); 135 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
133 136
137 $db->db_put ($key => $data)
134} 138}
135 139
136package CFClient::Texture; 140package CFClient::Texture;
137 141
138use strict; 142use strict;
140use Scalar::Util; 144use Scalar::Util;
141 145
142use SDL::OpenGL; 146use SDL::OpenGL;
143 147
144my %TEXTURES; 148my %TEXTURES;
145my @NAMES;
146 149
147sub new { 150sub new {
148 my ($class, %data) = @_; 151 my ($class, %data) = @_;
149 152
150 my $self = bless { 153 my $self = bless {
262 } 265 }
263 266
264 $self->{s} = $self->{w} / $tw; 267 $self->{s} = $self->{w} / $tw;
265 $self->{t} = $self->{h} / $th; 268 $self->{t} = $self->{h} / $th;
266 269
267 $self->{name} ||= (pop @NAMES) || (glGenTextures 1)->[0]; 270 $self->{name} ||= (glGenTextures 1)->[0];
268 271
269 glBindTexture GL_TEXTURE_2D, $self->{name}; 272 glBindTexture GL_TEXTURE_2D, $self->{name};
270 273
271 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; 274 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
272 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; 275 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
295sub DESTROY { 298sub DESTROY {
296 my ($self) = @_; 299 my ($self) = @_;
297 300
298 delete $TEXTURES{$self+0}; 301 delete $TEXTURES{$self+0};
299 302
300 if (my $name = delete $self->{name}) { 303 glDeleteTextures delete $self->{name}
301 glDeleteTextures $name; 304 if $self->{name};
302 push @NAMES, $name;
303 }
304
305} 305}
306 306
307sub restore_state{ 307sub restore_state{
308 $_->upload 308 $_->upload
309 for grep $_, values %TEXTURES; 309 for values %TEXTURES;
310}; 310};
311 311
3121; 3121;
313 313
314=back 314=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines