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.34 by root, Sat Apr 15 21:16:49 2006 UTC vs.
Revision 1.40 by root, Tue Apr 18 01:51:06 2006 UTC

93mkdir "$Crossfire::VARDIR/pclient", 0777; 93mkdir "$Crossfire::VARDIR/pclient", 0777;
94 94
95our $DB_ENV = new BerkeleyDB::Env 95our $DB_ENV = new BerkeleyDB::Env
96 -Home => "$Crossfire::VARDIR/pclient", 96 -Home => "$Crossfire::VARDIR/pclient",
97 -Cachesize => 1_000_000, 97 -Cachesize => 1_000_000,
98 -ErrFile => "/proc/self/fd/2", 98 -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt",
99 -ErrPrefix => "DATABASE", 99# -ErrPrefix => "DATABASE",
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_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;
139 143
140use Scalar::Util; 144use Scalar::Util;
141 145
142use SDL::OpenGL; 146use SDL::OpenGL;
143 147
144my @textures; 148my %TEXTURES;
145 149
146sub new { 150sub new {
147 my ($class, %data) = @_; 151 my ($class, %data) = @_;
148 152
149 my $self = bless { 153 my $self = bless {
151 format => GL_RGBA, 155 format => GL_RGBA,
152 type => GL_UNSIGNED_BYTE, 156 type => GL_UNSIGNED_BYTE,
153 %data, 157 %data,
154 }, $class; 158 }, $class;
155 159
156 push @textures, $self; 160 Scalar::Util::weaken ($TEXTURES{$self+0} = $self);
157 Scalar::Util::weaken $textures[-1];
158 161
159 $self->upload; 162 $self->upload;
160 163
161 $self 164 $self
162} 165}
261 } 264 }
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;
269
270 glGetError;
266 271
267 $self->{name} ||= (glGenTextures 1)->[0]; 272 $self->{name} ||= (glGenTextures 1)->[0];
268 273
269 glBindTexture GL_TEXTURE_2D, $self->{name}; 274 glBindTexture GL_TEXTURE_2D, $self->{name};
270 275
279 $tw, $th, # need to pad texture first 284 $tw, $th, # need to pad texture first
280 0, 285 0,
281 $self->{format}, 286 $self->{format},
282 $self->{type}, 287 $self->{type},
283 $data; 288 $data;
284 glGetError and die; 289 if (my $error = glGetError) {
290 warn sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x\n",
291 $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
292 }
285 } else { 293 } else {
286 glCopyTexImage2D GL_TEXTURE_2D, 0, 294 glCopyTexImage2D GL_TEXTURE_2D, 0,
287 $self->{internalformat}, 295 $self->{internalformat},
288 0, 0, 296 0, 0,
289 $tw, $th, 297 $tw, $th,
293} 301}
294 302
295sub DESTROY { 303sub DESTROY {
296 my ($self) = @_; 304 my ($self) = @_;
297 305
298 return unless exists $self->{name}; 306 delete $TEXTURES{$self+0};
299 307
300 glDeleteTextures delete $self->{name}; 308 glDeleteTextures delete $self->{name}
309 if $self->{name};
301} 310}
302 311
303sub restore_state{ 312sub restore_state{
304 $_->upload 313 $_->upload
305 for grep $_, @textures; 314 for values %TEXTURES;
306}; 315};
307 316
3081; 3171;
309 318
310=back 319=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines