use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project TooCruelPixelDungeon by juh9870.
the class AndroidPlatformSupport method setupFontGenerators.
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
// don't bother doing anything if nothing has changed
if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont) {
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;
resetGenerators(false);
fonts = new HashMap<>();
basicFontGenerator = KRFontGenerator = SCFontGenerator = JPFontGenerator = null;
if (systemfont && Gdx.files.absolute("/system/fonts/Roboto-Regular.ttf").exists()) {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/Roboto-Regular.ttf"));
} else if (systemfont && Gdx.files.absolute("/system/fonts/DroidSans.ttf").exists()) {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf"));
} else {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
}
// android 7.0+. all asian fonts are nicely contained in one spot
if (Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc").exists()) {
// typefaces are 0-JP, 1-KR, 2-SC, 3-TC.
int typeFace;
switch(SPDSettings.language()) {
case JAPANESE:
typeFace = 0;
break;
case KOREAN:
typeFace = 1;
break;
case CHINESE:
default:
typeFace = 2;
}
KRFontGenerator = SCFontGenerator = JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc"), typeFace);
// otherwise we have to go over a few possibilities.
} else {
// Korean font generators
if (Gdx.files.absolute("/system/fonts/NanumGothic.ttf").exists()) {
KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf"));
} else if (Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf").exists()) {
KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf"));
koreanAndroid6OTF = true;
}
// Chinese font generators
if (Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf").exists()) {
SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf"));
} else if (Gdx.files.absolute("/system/fonts/NotoSansHans-Regular.otf").exists()) {
SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansHans-Regular.otf"));
}
// Japaneses font generators
if (Gdx.files.absolute("/system/fonts/NotoSansJP-Regular.otf").exists()) {
JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansJP-Regular.otf"));
}
// set up a fallback generator for any remaining fonts
FreeTypeFontGenerator fallbackGenerator;
if (Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf").exists()) {
fallbackGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
} else {
// no fallback font, just set to null =/
fallbackGenerator = null;
}
if (KRFontGenerator == null)
KRFontGenerator = fallbackGenerator;
if (SCFontGenerator == null)
SCFontGenerator = fallbackGenerator;
if (JPFontGenerator == null)
JPFontGenerator = fallbackGenerator;
}
if (basicFontGenerator != null)
fonts.put(basicFontGenerator, new HashMap<>());
if (KRFontGenerator != null)
fonts.put(KRFontGenerator, new HashMap<>());
if (SCFontGenerator != null)
fonts.put(SCFontGenerator, new HashMap<>());
if (JPFontGenerator != null)
fonts.put(JPFontGenerator, new HashMap<>());
// would be nice to use RGBA4444 to save memory, but this causes problems on some gpus =S
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project TooCruelPixelDungeon by juh9870.
the class IOSPlatformSupport method setupFontGenerators.
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
// don't bother doing anything if nothing has changed
if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont) {
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;
resetGenerators(false);
fonts = new HashMap<>();
if (systemfont) {
basicFontGenerator = asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
} else {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
}
fonts.put(basicFontGenerator, new HashMap<>());
fonts.put(asianFontGenerator, new HashMap<>());
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.
the class FreeBitmapFont method createForEmoji.
private void createForEmoji(String characters, boolean haveMinPageSize) {
// characters = characters.replaceAll("[\\t\\n\\x0B\\f\\r]", "");
cs.clear();
char[] chars = characters.toCharArray();
for (int i = 0, len = chars.length; i < len; i++) {
char ch = chars[i];
String txt = String.valueOf(ch);
boolean isEmoji = isEmojiCharacter(ch);
if (isEmoji) {
if (i + 1 < len) {
txt += chars[i + 1];
i++;
}
}
if (charSet.add(txt))
cs.add(txt);
}
// 根据字符参数和字符数量计算一个最小尺寸
if (haveMinPageSize) {
pageWidth = (paint.getTextSize() + 2) * (int) (Math.sqrt(cs.size) + 1);
}
if (packer == null) {
packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 4, false);
}
for (int i = 0; i < cs.size; i++) {
String txt = cs.get(i);
char c;
if (txt.length() == 1) {
// 判断该符号是否在key库中
boolean isNotKey = emojiKey.indexOf(txt) < 0;
if (isNotKey) {
c = txt.charAt(0);
if (data.getGlyph(c) != null)
continue;
} else {
// 如果是key库的一员,那么给它映射一下
boolean isCreated = isCreatedEmoji2(txt);
// 如果创建过的,就跳过
if (isCreated)
continue;
if (ekid > emojiKey.length() - 1)
continue;
// 如果没有创建过,就取一个key来用
String key = emojiKey.substring(ekid++, ekid);
c = key.charAt(0);
Emoji emoj = new Emoji();
emoj.text = txt;
emoj.key = key;
emojis2.add(emoj);
// Gdx.app.log("aaaaaaa", "keyd=" + emoj.key);
}
} else {
// 说明是emoji
boolean isCreated = isCreatedEmoji4(txt);
// 如果创建过的,就跳过
if (isCreated)
continue;
if (ekid > emojiKey.length() - 1)
continue;
// 如果没有创建过,就取一个key来用
String key = emojiKey.substring(ekid++, ekid);
c = key.charAt(0);
Emoji emoj = new Emoji();
emoj.text = txt;
emoj.key = key;
emojis4.add(emoj);
}
if (data.getGlyph(c) != null)
continue;
putGlyph(c, listener.getFontPixmap(txt, paint));
}
upData();
// 如果只有一张纹理,则设置使用一张纹理,提高运行速度
if (getRegions().size == 1) {
setOwnsTexture(true);
} else {
setOwnsTexture(false);
}
}
use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.
the class FreeBitmapFont method create.
private void create(String characters, boolean haveMinPageSize) {
if (!isEmoji) {
characters = characters.replaceAll("[\\t\\n\\x0B\\f\\r]", "");
cs.clear();
char[] chars = characters.toCharArray();
for (char c : chars) {
if (charSet.add(c + "")) {
cs.add(c + "");
}
}
// 根据字符参数和字符数量计算一个最小尺寸
if (haveMinPageSize) {
pageWidth = (paint.getTextSize() + 2) * (int) (Math.sqrt(cs.size) + 1);
}
if (packer == null) {
packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 4, false);
}
for (int i = 0; i < cs.size; i++) {
String txt = cs.get(i);
char c = txt.charAt(0);
// 如果该字符存在于emoji地址库里,则创建这个emoji的纹理
String css = c + "";
if (emojiSet.get(css) != null) {
charSet.remove(css);
EmojiDate date = emojiSet.get(css);
appendEmoji("" + c, date.path, date.size);
continue;
}
putGlyph(c, listener.getFontPixmap(txt, paint));
}
// updataSize(size);
upData();
// 如果只有一张纹理,则设置使用一张纹理,提高运行速度
if (getRegions().size == 1) {
setOwnsTexture(true);
} else {
setOwnsTexture(false);
}
} else {
createForEmoji(characters, haveMinPageSize);
}
}
use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.
the class VGame method render.
public void render() {
if (isLoading) {
if (backgroundColor != null)
clean(backgroundColor);
if (assets.update()) {
Array<Texture> out = new Array<Texture>();
assets.getAll(Texture.class, out);
for (Texture tex : out) {
tex.setFilter(filter, filter);
}
if (isProtect && !isReProtect) {
Array<PixmapPro> outPixmapPro = new Array<PixmapPro>();
assets.getAll(PixmapPro.class, outPixmapPro);
if (outPixmapPro.size > 0) {
if (atlas == null)
atlas = new TextureAtlas();
for (PixmapPro pix : outPixmapPro) {
Texture texture = pix.getTextrue();
texture.setFilter(filter, filter);
atlas.addRegion(pix.getName(), new TextureRegion(texture));
assets.unload(pix.getName());
}
}
}
if (inpacks.size > 0) {
// 将散图打包到大图
if (packer == null)
packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, true);
if (atlas == null)
atlas = new TextureAtlas();
for (String path : inpacks) {
try {
Pixmap pixmap;
if (isProtect && !isReProtect) {
pixmap = assets.get(path, PixmapPro.class).getPixmap();
} else {
pixmap = assets.get(path, Pixmap.class);
}
packer.pack(path, pixmap);
assets.unload(path);
} catch (Exception e) {
}
}
packer.updateTextureAtlas(atlas, filter, filter, false);
for (Page page : packer.getPages()) {
page.getPixmap().dispose();
}
packer.dispose();
packer = null;
inpacks.clear();
}
if (inModels.size > 0) {
// 将散模型打包到模型库
if (packer == null)
packer = new PixmapPacker(pageWidthModel, pageWidthModel, Format.RGBA8888, 2, true);
if (atlas == null)
atlas = new TextureAtlas();
for (String path : inModels) {
Model addModel = assets.get(path);
if (model == null) {
model = addModel;
packRegion(model.materials, path);
} else {
packRegion(addModel.materials, path);
model.nodes.addAll(addModel.nodes);
model.animations.addAll(addModel.animations);
model.materials.addAll(addModel.materials);
model.meshes.addAll(addModel.meshes);
model.meshParts.addAll(addModel.meshParts);
}
}
// 移除所有动画里面的所属前缀
Array<Animation> animations = model.animations;
for (Animation animation : animations) {
animation.id = animation.id.substring(animation.id.lastIndexOf("|") + 1);
}
packer.dispose();
packer = null;
inModels.clear();
}
if (stage != null) {
stage.init();
stage.show();
stage.act();
stage.draw();
stageStartTime = System.currentTimeMillis();
}
isLoading = false;
}
if (stageLoad != null) {
stageLoad.act(assets.getProgress());
stageLoad.draw();
}
} else {
if (stage != null) {
if (backgroundColor != null)
clean(backgroundColor);
stage.act();
stage.draw();
}
stageTop.act();
stageTop.draw();
Batch batch = stageTop.getBatch();
if (iphoneX != null) {
batch.begin();
batch.setColor(Color.WHITE);
batch.draw(iphoneX, 0, 0, WIDTH, HEIGHT);
batch.end();
}
if (isShowFps) {
switch(Gdx.app.getType()) {
case Android:
refushFps();
break;
case Desktop:
Display.setTitle(getHeap());
break;
case iOS:
break;
}
}
if (soundRuns.size > 0) {
// 从音效池里拖一个音效出来播放,该构造避免同一帧播放过多音效导致播放失败
soundRuns.removeIndex(0).run();
}
}
}
Aggregations