mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
fix memory tracking computation
compute the probable Texture usaga
This commit is contained in:
@@ -41,7 +41,6 @@ public class FrameRate implements Disposable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(int loadedCardSize, float toAlloc) {
|
public void update(int loadedCardSize, float toAlloc) {
|
||||||
if (toAlloc > 300f)
|
|
||||||
allocT = (int) toAlloc;
|
allocT = (int) toAlloc;
|
||||||
cardsLoaded = loadedCardSize;
|
cardsLoaded = loadedCardSize;
|
||||||
long delta = TimeUtils.timeSinceMillis(lastTimeCounted);
|
long delta = TimeUtils.timeSinceMillis(lastTimeCounted);
|
||||||
@@ -55,7 +54,7 @@ public class FrameRate implements Disposable{
|
|||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
batch.begin();
|
batch.begin();
|
||||||
font.draw(batch, (int)frameRate + " FPS | " + cardsLoaded + " cards re/loaded - " + allocT + " vMem", 3, Gdx.graphics.getHeight() - 3);
|
font.draw(batch, (int)frameRate + " FPS | " + cardsLoaded + " cards re/loaded | " + allocT + " MB", 3, Gdx.graphics.getHeight() - 3);
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ public class Assets implements Disposable {
|
|||||||
public Skin skin;
|
public Skin skin;
|
||||||
public BitmapFont advDefaultFont, advBigFont;
|
public BitmapFont advDefaultFont, advBigFont;
|
||||||
private Texture defaultImage, dummy;
|
private Texture defaultImage, dummy;
|
||||||
private TextureParameter parameter;
|
private TextureParameter textureParameter;
|
||||||
|
private int cGen = 0, cGenVal = 0, cFB = 0, cFBVal = 0, cTM, cTMVal = 0;
|
||||||
public Assets() {
|
public Assets() {
|
||||||
//init titlebg fallback
|
//init titlebg fallback
|
||||||
fallback_skins.put(0, new Texture(GuiBase.isAndroid()
|
fallback_skins.put(0, new Texture(GuiBase.isAndroid()
|
||||||
@@ -165,18 +166,18 @@ public class Assets implements Disposable {
|
|||||||
return tmxMap;
|
return tmxMap;
|
||||||
}
|
}
|
||||||
public TextureParameter getTextureFilter() {
|
public TextureParameter getTextureFilter() {
|
||||||
if (parameter == null)
|
if (textureParameter == null)
|
||||||
parameter = new TextureParameter();
|
textureParameter = new TextureParameter();
|
||||||
if (Forge.isTextureFilteringEnabled()) {
|
if (Forge.isTextureFilteringEnabled()) {
|
||||||
parameter.genMipMaps = true;
|
textureParameter.genMipMaps = true;
|
||||||
parameter.minFilter = Texture.TextureFilter.MipMapLinearLinear;
|
textureParameter.minFilter = Texture.TextureFilter.MipMapLinearLinear;
|
||||||
parameter.magFilter = Texture.TextureFilter.Linear;
|
textureParameter.magFilter = Texture.TextureFilter.Linear;
|
||||||
} else {
|
} else {
|
||||||
parameter.genMipMaps = false;
|
textureParameter.genMipMaps = false;
|
||||||
parameter.minFilter = Texture.TextureFilter.Nearest;
|
textureParameter.minFilter = Texture.TextureFilter.Nearest;
|
||||||
parameter.magFilter = Texture.TextureFilter.Nearest;
|
textureParameter.magFilter = Texture.TextureFilter.Nearest;
|
||||||
}
|
}
|
||||||
return parameter;
|
return textureParameter;
|
||||||
}
|
}
|
||||||
public Texture getDefaultImage() {
|
public Texture getDefaultImage() {
|
||||||
if (defaultImage == null) {
|
if (defaultImage == null) {
|
||||||
@@ -213,10 +214,8 @@ public class Assets implements Disposable {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private int calculateTextureSize(AssetManager assetManager, String fileName, Class type) {
|
private int calculateTextureSize(AssetManager assetManager, String fileName, Class type) {
|
||||||
if (memoryPerFile.containsKey(fileName)) {
|
if (!Forge.showFPS)
|
||||||
return memoryPerFile.get(fileName);
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
Texture texture = (Texture) assetManager.get(fileName, type);
|
Texture texture = (Texture) assetManager.get(fileName, type);
|
||||||
TextureData textureData = texture.getTextureData();
|
TextureData textureData = texture.getTextureData();
|
||||||
int textureSize = textureData.getWidth() * textureData.getHeight();
|
int textureSize = textureData.getWidth() * textureData.getHeight();
|
||||||
@@ -236,18 +235,73 @@ public class Assets implements Disposable {
|
|||||||
textureSize *= 4;
|
textureSize *= 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryPerFile.put(fileName, textureSize);
|
memoryPerFile.put(fileName, textureSize);
|
||||||
|
|
||||||
return textureSize;
|
int sum = memoryPerFile.values().stream().mapToInt(Integer::intValue).sum()
|
||||||
|
+ calculateObjectMaps(generatedCards()) + calculateObjectMaps(fallback_skins()) + calculateObjectMaps(tmxMap());
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private int calculateObjectMaps(ObjectMap<?, Texture> objectMap) {
|
||||||
|
if (!Forge.showFPS)
|
||||||
|
return 0;
|
||||||
|
if (objectMap == null || objectMap.isEmpty())
|
||||||
|
return 0;
|
||||||
|
if (objectMap == generatedCards) {
|
||||||
|
if (cGen == objectMap.size)
|
||||||
|
return cGenVal;
|
||||||
|
else
|
||||||
|
cGen = objectMap.size;
|
||||||
|
}
|
||||||
|
if (objectMap == tmxMap) {
|
||||||
|
if (cTM == objectMap.size)
|
||||||
|
return cTMVal;
|
||||||
|
else
|
||||||
|
cTM = objectMap.size;
|
||||||
|
}
|
||||||
|
if (objectMap == fallback_skins) {
|
||||||
|
if (cFB == objectMap.size)
|
||||||
|
return cFBVal;
|
||||||
|
else
|
||||||
|
cFB = objectMap.size;
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (Texture texture : objectMap.values()) {
|
||||||
|
TextureData textureData = texture.getTextureData();
|
||||||
|
int textureSize = textureData.getWidth() * textureData.getHeight();
|
||||||
|
if (Forge.isTextureFilteringEnabled())
|
||||||
|
textureSize = textureSize + (textureSize/3);
|
||||||
|
switch (textureData.getFormat()) {
|
||||||
|
case RGB565:
|
||||||
|
textureSize *= 2;
|
||||||
|
break;
|
||||||
|
case RGB888:
|
||||||
|
textureSize *= 3;
|
||||||
|
break;
|
||||||
|
case RGBA4444:
|
||||||
|
textureSize *= 2;
|
||||||
|
break;
|
||||||
|
case RGBA8888:
|
||||||
|
textureSize *= 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sum += textureSize;
|
||||||
|
}
|
||||||
|
if (objectMap == generatedCards)
|
||||||
|
cGenVal = sum;
|
||||||
|
if (objectMap == tmxMap)
|
||||||
|
cTMVal = sum;
|
||||||
|
if (objectMap == fallback_skins)
|
||||||
|
cFBVal = sum;
|
||||||
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public synchronized <T> void load(String fileName, Class<T> type) {
|
public synchronized <T> void load(String fileName, Class<T> type, AssetLoaderParameters<T> parameter) {
|
||||||
if (type.equals(Texture.class)) {
|
if (type.equals(Texture.class)) {
|
||||||
if (parameter == null) {
|
if (parameter == null) {
|
||||||
parameter = getTextureFilter();
|
parameter = (AssetLoaderParameters<T>) getTextureFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
final AssetLoaderParameters.LoadedCallback prevCallback = parameter.loadedCallback;
|
final AssetLoaderParameters.LoadedCallback prevCallback = parameter.loadedCallback;
|
||||||
@@ -256,19 +310,19 @@ public class Assets implements Disposable {
|
|||||||
prevCallback.finishedLoading(assetManager, fileName1, type1);
|
prevCallback.finishedLoading(assetManager, fileName1, type1);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentMemory += calculateTextureSize(assetManager, fileName1, type1);
|
currentMemory = calculateTextureSize(assetManager, fileName1, type1);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.load(fileName, type);
|
super.load(fileName, type, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void unload(String fileName) {
|
public synchronized void unload(String fileName) {
|
||||||
super.unload(fileName);
|
super.unload(fileName);
|
||||||
if (memoryPerFile.containsKey(fileName)) {
|
if (memoryPerFile.containsKey(fileName)) {
|
||||||
currentMemory -= memoryPerFile.get(fileName);
|
memoryPerFile.remove(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user