… | |
… | |
21 | XSLoader::load "CFClient", $VERSION; |
21 | XSLoader::load "CFClient", $VERSION; |
22 | } |
22 | } |
23 | |
23 | |
24 | use AnyEvent; |
24 | use AnyEvent; |
25 | use BerkeleyDB; |
25 | use BerkeleyDB; |
26 | use SDL::OpenGL; |
26 | use CFClient::OpenGL; |
27 | |
27 | |
28 | our %GL_EXT; |
28 | our %GL_EXT; |
29 | our $GL_VERSION; |
29 | our $GL_VERSION; |
30 | |
30 | |
31 | our $GL_NPOT; |
31 | our $GL_NPOT; |
… | |
… | |
93 | mkdir "$Crossfire::VARDIR/pclient", 0777; |
93 | mkdir "$Crossfire::VARDIR/pclient", 0777; |
94 | |
94 | |
95 | our $DB_ENV = new BerkeleyDB::Env |
95 | our $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 | |
104 | sub db_table($) { |
104 | sub 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 | |
113 | package CFClient::Database; |
118 | package CFClient::Database; |
… | |
… | |
136 | |
141 | |
137 | use strict; |
142 | use strict; |
138 | |
143 | |
139 | use Scalar::Util; |
144 | use Scalar::Util; |
140 | |
145 | |
141 | use SDL::OpenGL; |
146 | use CFClient::OpenGL; |
142 | |
147 | |
143 | my %TEXTURES; |
148 | my %TEXTURES; |
144 | |
149 | |
145 | sub new { |
150 | sub new { |
146 | my ($class, %data) = @_; |
151 | my ($class, %data) = @_; |
… | |
… | |
260 | } |
265 | } |
261 | |
266 | |
262 | $self->{s} = $self->{w} / $tw; |
267 | $self->{s} = $self->{w} / $tw; |
263 | $self->{t} = $self->{h} / $th; |
268 | $self->{t} = $self->{h} / $th; |
264 | |
269 | |
|
|
270 | glGetError; |
|
|
271 | |
265 | $self->{name} ||= (glGenTextures 1)->[0]; |
272 | $self->{name} ||= glGenTexture; |
266 | |
273 | |
267 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
274 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
268 | |
275 | |
269 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
276 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
270 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
277 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
… | |
… | |
277 | $tw, $th, # need to pad texture first |
284 | $tw, $th, # need to pad texture first |
278 | 0, |
285 | 0, |
279 | $self->{format}, |
286 | $self->{format}, |
280 | $self->{type}, |
287 | $self->{type}, |
281 | $data; |
288 | $data; |
282 | 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 | } |
283 | } else { |
293 | } else { |
284 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
294 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
285 | $self->{internalformat}, |
295 | $self->{internalformat}, |
286 | 0, 0, |
296 | 0, 0, |
287 | $tw, $th, |
297 | $tw, $th, |
… | |
… | |
293 | sub DESTROY { |
303 | sub DESTROY { |
294 | my ($self) = @_; |
304 | my ($self) = @_; |
295 | |
305 | |
296 | delete $TEXTURES{$self+0}; |
306 | delete $TEXTURES{$self+0}; |
297 | |
307 | |
298 | glDeleteTextures delete $self->{name} |
308 | glDeleteTexture delete $self->{name} |
299 | if $self->{name}; |
309 | if $self->{name}; |
300 | } |
310 | } |
301 | |
311 | |
302 | sub restore_state{ |
312 | sub restore_state{ |
303 | $_->upload |
313 | $_->upload |