Skip to content

Instantly share code, notes, and snippets.

View doriancransac's full-sized avatar

Dorian Cransac doriancransac

View GitHub Profile
@doriancransac
doriancransac / MemoryUsageOptimizedClient.java
Created April 10, 2022 14:02
Optimized version of the mass sprite sheet loading where no memory spike happens
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@doriancransac
doriancransac / MemoryUsageDebuggingClient.java
Last active April 10, 2022 13:59
A quick client implementation loading a sprite sheet 500 times and checking the global memory usage on the host after loading and drawing the textures
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
package default;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import org.lwjgl.Sys;
public class FPSDropApp extends Game {
@doriancransac
doriancransac / ClasspathFileHandle.java
Created December 3, 2020 17:36
An extension version of FileHandle for Java 9 compatibility in Scene2d's Json Skin loader
package com.projectvisionaries.assets.loader;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.projectvisionaries.assets.binary.InitModule;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@doriancransac
doriancransac / HijackedBaseTmxMapLoader.java
Last active November 20, 2020 23:59
A hijacked TileMap loader for libgdx which works in headless context (i.e without ANY Gdx context)
import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetLoaderParameters;
import com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.TextureLoader;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.*;