v0.7.4b: Initial LibGDX commit! more details below:
Large sections of game logic are now working through libgdx instead of android libraries. There is still work to do but this is the first major step. Big changes include: - Graphics code is now through LibGDX (except for text rendering) - Initialization and screen-handling logic is now mostly through LibGDX - Audio is now through LibGDX - Input handling is now through LibGDX - Most misc functions are now through LibGDX
This commit is contained in:
@@ -21,12 +21,10 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.watabou.noosa.Game;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BitmapCache {
|
||||
@@ -35,18 +33,11 @@ public class BitmapCache {
|
||||
|
||||
private static HashMap<String,Layer> layers = new HashMap<String, BitmapCache.Layer>();
|
||||
|
||||
private static BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
static {
|
||||
opts.inDither = false;
|
||||
}
|
||||
|
||||
public static Context context;
|
||||
|
||||
public static Bitmap get( String assetName ) {
|
||||
public static Pixmap get( String assetName ) {
|
||||
return get( DEFAULT, assetName );
|
||||
}
|
||||
|
||||
public static Bitmap get( String layerName, String assetName ) {
|
||||
public static Pixmap get( String layerName, String assetName ) {
|
||||
|
||||
Layer layer;
|
||||
if (!layers.containsKey( layerName )) {
|
||||
@@ -61,22 +52,24 @@ public class BitmapCache {
|
||||
} else {
|
||||
|
||||
try {
|
||||
InputStream stream = context.getResources().getAssets().open( assetName );
|
||||
Bitmap bmp = BitmapFactory.decodeStream( stream, null, opts );
|
||||
Pixmap bmp = new Pixmap( Gdx.files.internal(assetName) );
|
||||
layer.put( assetName, bmp );
|
||||
return bmp;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
Game.reportException( e );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap get( int resID ) {
|
||||
//Unused, LibGDX does not support resource Ids
|
||||
/*
|
||||
public static Pixmap get( int resID ) {
|
||||
return get( DEFAULT, resID );
|
||||
}
|
||||
|
||||
public static Bitmap get( String layerName, int resID ) {
|
||||
public static Pixmap get( String layerName, int resID ) {
|
||||
|
||||
Layer layer;
|
||||
if (!layers.containsKey( layerName )) {
|
||||
@@ -95,7 +88,7 @@ public class BitmapCache {
|
||||
return bmp;
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void clear( String layerName ) {
|
||||
if (layers.containsKey( layerName )) {
|
||||
@@ -112,12 +105,12 @@ public class BitmapCache {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class Layer extends HashMap<Object,Bitmap> {
|
||||
private static class Layer extends HashMap<Object,Pixmap> {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (Bitmap bmp:values()) {
|
||||
bmp.recycle();
|
||||
for (Pixmap bmp:values()) {
|
||||
bmp.dispose();
|
||||
}
|
||||
super.clear();
|
||||
}
|
||||
|
||||
@@ -21,27 +21,26 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BitmapFilm {
|
||||
|
||||
public Bitmap bitmap;
|
||||
public Pixmap bitmap;
|
||||
|
||||
protected HashMap<Object,Rect> frames = new HashMap<Object, Rect>();
|
||||
|
||||
public BitmapFilm( Bitmap bitmap ) {
|
||||
public BitmapFilm( Pixmap bitmap ) {
|
||||
this.bitmap = bitmap;
|
||||
add( null, new Rect( 0, 0, bitmap.getWidth(), bitmap.getHeight() ) );
|
||||
}
|
||||
|
||||
public BitmapFilm( Bitmap bitmap, int width ) {
|
||||
public BitmapFilm( Pixmap bitmap, int width ) {
|
||||
this( bitmap, width, bitmap.getHeight() );
|
||||
}
|
||||
|
||||
public BitmapFilm( Bitmap bitmap, int width, int height ) {
|
||||
public BitmapFilm( Pixmap bitmap, int width, int height ) {
|
||||
this.bitmap = bitmap;
|
||||
int cols = bitmap.getWidth() / width;
|
||||
int rows = bitmap.getHeight() / height;
|
||||
|
||||
@@ -21,22 +21,31 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.watabou.BuildConfig;
|
||||
import com.watabou.noosa.Game;
|
||||
|
||||
public class DeviceCompat {
|
||||
|
||||
public static boolean supportsFullScreen(){
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
switch (Gdx.app.getType()){
|
||||
case Android:
|
||||
//Android 4.4 KitKat and later, this is for immersive mode
|
||||
return Gdx.app.getVersion() >= 19;
|
||||
default:
|
||||
//TODO implement functionality for other platforms here
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean legacyDevice(){
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN;
|
||||
switch (Gdx.app.getType()){
|
||||
case Android:
|
||||
//Devices prior to Android 4.1 Jelly Bean
|
||||
return Gdx.app.getVersion() < 16;
|
||||
default:
|
||||
//TODO implement functionality for other platforms here
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDebug(){
|
||||
@@ -44,12 +53,11 @@ public class DeviceCompat {
|
||||
}
|
||||
|
||||
public static void openURI( String URI ){
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( URI ) );
|
||||
Game.instance.startActivity( intent );
|
||||
Gdx.net.openURI( URI );
|
||||
}
|
||||
|
||||
public static void log( String tag, String message ){
|
||||
Log.i( tag, message );
|
||||
Gdx.app.log( tag, message );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,18 +21,17 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import com.watabou.noosa.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
|
||||
public class GameSettings {
|
||||
|
||||
private static SharedPreferences prefs;
|
||||
private static Preferences prefs;
|
||||
|
||||
private static SharedPreferences get() {
|
||||
private static Preferences get() {
|
||||
if (prefs == null) {
|
||||
prefs = Game.instance.getPreferences( Game.MODE_PRIVATE );
|
||||
//TODO might want to rename this file. this is the auto-generated name for android atm
|
||||
prefs = Gdx.app.getPreferences("ShatteredPixelDungeon");
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
@@ -47,7 +46,7 @@ public class GameSettings {
|
||||
|
||||
public static int getInt( String key, int defValue, int min, int max ) {
|
||||
try {
|
||||
int i = get().getInt( key, defValue );
|
||||
int i = get().getInteger( key, defValue );
|
||||
if (i < min || i > max){
|
||||
int val = (int)GameMath.gate(min, i, max);
|
||||
put(key, val);
|
||||
@@ -93,15 +92,18 @@ public class GameSettings {
|
||||
}
|
||||
|
||||
public static void put( String key, int value ) {
|
||||
get().edit().putInt(key, value).apply();
|
||||
get().putInteger(key, value);
|
||||
get().flush();
|
||||
}
|
||||
|
||||
public static void put( String key, boolean value ) {
|
||||
get().edit().putBoolean(key, value).apply();
|
||||
get().putBoolean(key, value);
|
||||
get().flush();
|
||||
}
|
||||
|
||||
public static void put( String key, String value ) {
|
||||
get().edit().putString(key, value).apply();
|
||||
get().putString(key, value);
|
||||
get().flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
@SuppressLint("FloatMath")
|
||||
public class PointF {
|
||||
|
||||
public static final float PI = 3.1415926f;
|
||||
|
||||
@@ -21,26 +21,18 @@
|
||||
|
||||
package com.watabou.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SparseArray<T> extends android.util.SparseArray<T> {
|
||||
public class SparseArray<T> extends IntMap<T> {
|
||||
|
||||
public int[] keyArray() {
|
||||
int size = size();
|
||||
int[] array = new int[size];
|
||||
for (int i=0; i < size; i++) {
|
||||
array[i] = keyAt( i );
|
||||
}
|
||||
return array;
|
||||
return keys().toArray().toArray();
|
||||
}
|
||||
|
||||
public List<T> values() {
|
||||
int size = size();
|
||||
ArrayList<T> list = new ArrayList<T>( size );
|
||||
for (int i=0; i < size; i++) {
|
||||
list.add( i, valueAt( i ) );
|
||||
}
|
||||
return list;
|
||||
public List<T> toList() {
|
||||
return Arrays.asList(values().toArray().toArray());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user