mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-25 23:35:21 +02:00
Add a very simple image pool to limit the amount of new images loaded. Hoping it will fix the screen sometimes stopping.
This commit is contained in:
23
res/app/components/stf/screen/imagepool.js
Normal file
23
res/app/components/stf/screen/imagepool.js
Normal file
@@ -0,0 +1,23 @@
|
||||
function ImagePool(size) {
|
||||
this.size = size
|
||||
this.images = []
|
||||
this.counter = 0
|
||||
}
|
||||
|
||||
ImagePool.prototype.next = function() {
|
||||
if (this.images.length < this.size) {
|
||||
var image = new Image()
|
||||
this.images.push(image)
|
||||
return image
|
||||
}
|
||||
else {
|
||||
if (this.counter >= this.size) {
|
||||
// Reset for unlikely but theoretically possible overflow.
|
||||
this.counter = 0
|
||||
}
|
||||
|
||||
return this.images[this.counter++ % this.size]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ImagePool
|
||||
Reference in New Issue
Block a user