Skip to content

Commit

Permalink
v0.7.5e: implemented a very basic first desktop module and launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
00-Evan committed Oct 24, 2019
1 parent 4dd73f0 commit 7670bc1
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ https://github.com/00-Evan/pixel-dungeon-gradle

# Compiling Shattered Pixel Dungeon

**Note that Shattered Pixel Dungeon is currently in the process of being converted to use the multiplatform game library LibGDX. The codebase is fully functional, but still contains some code which depends on Android, and so cannot be built for other platforms yet.**
**Note that Shattered Pixel Dungeon is currently in the process of being converted to use the multiplatform game library LibGDX. The game currently compiles for desktop but is missing several important desktop features. Desktop compiling is suitable for debugging but releasing desktop builds from this codebase is not advised at the moment.**

To compile Shattered Pixel Dungeon you will need:
- A computer which meets the [system requirements for Android Studio](https://developer.android.com/studio#Requirements)
Expand Down
7 changes: 7 additions & 0 deletions SPD-classes/src/main/java/com/watabou/noosa/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package com.watabou.noosa;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.TimeUtils;
Expand Down Expand Up @@ -119,6 +120,12 @@ public void resize(int width, int height) {
Game.width = width;
Game.height = height;

//TODO might be better to put this in platform support
if (Gdx.app.getType() != Application.ApplicationType.Android){
Game.dispWidth = Game.width;
Game.dispHeight = Game.height;
}

resetScene();
}
}
Expand Down
47 changes: 47 additions & 0 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

apply plugin: "java"

sourceSets.main.java.srcDirs = [ "src/" ]

project.ext.mainClassName = "com.shatteredpixel.shatteredpixeldungeon.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/src/main/assets")

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
workingDir = project.assetsDir
ignoreExitValue = true
}

//TODO add dist task to generate a .JAR

dependencies {
implementation project(':core')

implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

package com.shatteredpixel.shatteredpixeldungeon.desktop;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.noosa.Game;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JOptionPane;

public class DesktopLauncher {
public static void main (String[] arg) {

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
pw.flush();
JOptionPane.showMessageDialog(null, "Shattered Pixel Dungeon has crashed! Sorry about that!\n\n" +
"If you could, please email this error message to me and I'll get it fixed (Evan@ShatteredPixel.com):\n\n" +
sw.toString());
Gdx.app.exit();
}
});

String version = DesktopLauncher.class.getPackage().getSpecificationVersion();
if (version == null) {
Game.version = "0.7.5d";
}

try {
Game.versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion());
} catch (NumberFormatException e) {
Game.versionCode = 372;
}

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();

config.width = 1920;
config.height = 1080;

//uncapped (but vsynced) framerate when focused, paused when not focused
config.foregroundFPS = 0;
config.backgroundFPS = -1;

config.title = "Shattered Pixel Dungeon";

new LwjglApplication(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

package com.shatteredpixel.shatteredpixeldungeon.desktop;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.watabou.utils.PlatformSupport;

import java.util.HashMap;
import java.util.regex.Pattern;

public class DesktopPlatformSupport extends PlatformSupport {

@Override
public void updateDisplaySize() {

}

@Override
public void updateSystemUI() {

}

@Override
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) {

}

private int pageSize;
private PixmapPacker packer;
private boolean systemfont;

//droid sans / roboto, or a custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator basicFontGenerator;
private static HashMap<Integer, BitmapFont> basicFonts = new HashMap<>();

@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
if (basicFontGenerator != null && this.pageSize == pageSize && this.systemfont == systemfont){
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;

if (basicFontGenerator != null){
for (BitmapFont f : basicFonts.values()){
f.dispose();
}
basicFonts.clear();
basicFontGenerator.dispose();
if (packer != null){
for (PixmapPacker.Page p : packer.getPages()){
p.getTexture().dispose();
}
packer.dispose();
}
}

basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("pixel_font.ttf"));

packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}

@Override
public void resetGenerators() {
if (basicFontGenerator != null) {
for (BitmapFont f : basicFonts.values()) {
f.dispose();
}
basicFonts.clear();
basicFontGenerator.dispose();

if (packer != null) {
for (PixmapPacker.Page p : packer.getPages()) {
p.getTexture().dispose();
}
packer.dispose();
}
}
basicFontGenerator = null;
setupFontGenerators(pageSize, systemfont);
}

@Override
public BitmapFont getFont(int size, String text) {
FreeTypeFontGenerator generator = basicFontGenerator;

if (!basicFonts.containsKey(size)) {
FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameters.size = size;
parameters.flip = true;
parameters.borderWidth = parameters.size / 10f;
parameters.renderCount = 3;
parameters.hinting = FreeTypeFontGenerator.Hinting.None;
parameters.spaceX = -(int) parameters.borderWidth;
parameters.incremental = true;
parameters.characters = "";
parameters.packer = packer;

BitmapFont font = generator.generateFont(parameters);
font.getData().missingGlyph = font.getData().getGlyph('�');
basicFonts.put(size, font);
}

return basicFonts.get(size);
}

//splits on newlines, underscores, and chinese/japaneses characters
private Pattern regularsplitter = Pattern.compile(
"(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})");

//additionally splits on words, so that each word can be arranged individually
private Pattern regularsplitterMultiline = Pattern.compile(
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})");

@Override
public String[] splitforTextBlock(String text, boolean multiline) {
if (multiline) {
return regularsplitterMultiline.split(text);
} else {
return regularsplitter.split(text);
}
}

}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':core', ':SPD-classes', ':android'
include ':core', ':SPD-classes', ':android', ':desktop'

0 comments on commit 7670bc1

Please sign in to comment.