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.33 by root, Sat Apr 15 01:13:45 2006 UTC vs.
Revision 1.36 by root, Sat Apr 15 23:24:59 2006 UTC

19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFClient", $VERSION;
22} 22}
23 23
24use AnyEvent;
25use BerkeleyDB;
24use SDL::OpenGL; 26use SDL::OpenGL;
25 27
26our %GL_EXT; 28our %GL_EXT;
27our $GL_VERSION; 29our $GL_VERSION;
28 30
86 } 88 }
87 89
88 close CFG; 90 close CFG;
89} 91}
90 92
93mkdir "$Crossfire::VARDIR/pclient", 0777;
94
95our $DB_ENV = new BerkeleyDB::Env
96 -Home => "$Crossfire::VARDIR/pclient",
97 -Cachesize => 1_000_000,
98 -ErrFile => "/proc/self/fd/2",
99 -ErrPrefix => "DATABASE",
100 -Verbose => 1,
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";
103
104sub db_table($) {
105 new CFClient::Database
106 -Env => $DB_ENV,
107 -Filename => "database",
108 -Subname => $_[0],
109 -Flags => DB_CREATE | DB_UPGRADE,
110 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error";
111}
112
113package CFClient::Database;
114
115our @ISA = BerkeleyDB::Btree::;
116
117sub get($$) {
118 my $data;
119
120 $_[0]->db_get ($_[1], $data) == 0
121 ? $data
122 : ();
123}
124
125my %DB_SYNC;
126
127sub put($$$) {
128 my ($db, $key, $data) = @_;
129
130 $db->db_put ($key => $data);
131
132 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
133
134}
135
91package CFClient::Texture; 136package CFClient::Texture;
92 137
93use strict; 138use strict;
94 139
95use Scalar::Util; 140use Scalar::Util;
96 141
97use SDL::OpenGL; 142use SDL::OpenGL;
98 143
99my @textures; 144my %TEXTURES;
100 145
101sub new { 146sub new {
102 my ($class, %data) = @_; 147 my ($class, %data) = @_;
103 148
104 my $self = bless { 149 my $self = bless {
106 format => GL_RGBA, 151 format => GL_RGBA,
107 type => GL_UNSIGNED_BYTE, 152 type => GL_UNSIGNED_BYTE,
108 %data, 153 %data,
109 }, $class; 154 }, $class;
110 155
111 push @textures, $self; 156 Scalar::Util::weaken ($TEXTURES{$self+0} = $self);
112 Scalar::Util::weaken $textures[-1];
113 157
114 $self->upload; 158 $self->upload;
115 159
116 $self 160 $self
117} 161}
248} 292}
249 293
250sub DESTROY { 294sub DESTROY {
251 my ($self) = @_; 295 my ($self) = @_;
252 296
253 return unless exists $self->{name}; 297 delete $TEXTURES{$self+0};
254 298
255 glDeleteTextures delete $self->{name}; 299 glDeleteTextures delete $self->{name}
300 if $self->{name};
256} 301}
257 302
258sub restore_state{ 303sub restore_state{
259 $_->upload 304 $_->upload
260 for grep $_, @textures; 305 for values %TEXTURES;
261}; 306};
262 307
2631; 3081;
264 309
265=back 310=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines