Search in sources :

Example 61 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class ParticleEffectLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, ParticleEffectLoadParameter parameter) {
    Json json = new Json();
    ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file);
    Array<AssetData> assets = null;
    synchronized (items) {
        ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>();
        entry.key = fileName;
        entry.value = data;
        items.add(entry);
        assets = data.getAssets();
    }
    Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>();
    for (AssetData<?> assetData : assets) {
        // If the asset doesn't exist try to load it from loading effect directory
        if (!resolve(assetData.filename).exists()) {
            assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path();
        }
        if (assetData.type == ParticleEffect.class) {
            descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter));
        } else
            descriptors.add(new AssetDescriptor(assetData.filename, assetData.type));
    }
    return descriptors;
}
Also used : AssetData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.AssetData) Json(com.badlogic.gdx.utils.Json) Array(com.badlogic.gdx.utils.Array) ObjectMap(com.badlogic.gdx.utils.ObjectMap) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 62 with Array

use of com.badlogic.gdx.utils.Array in project libgdx-inGameConsole by StrongJoshua.

the class AbstractConsole method execCommand.

/* (non-Javadoc)
	 * @see com.strongjoshua.console.Console#execCommand(java.lang.String)
	 */
@Override
public void execCommand(String command) {
    if (disabled)
        return;
    log(command, LogLevel.COMMAND);
    String[] parts = command.split(" ");
    String methodName = parts[0];
    String[] sArgs = null;
    if (parts.length > 1) {
        sArgs = new String[parts.length - 1];
        for (int i = 1; i < parts.length; i++) {
            sArgs[i - 1] = parts[i];
        }
    }
    Class<? extends CommandExecutor> clazz = exec.getClass();
    Method[] methods = ClassReflection.getMethods(clazz);
    Array<Integer> possible = new Array<Integer>();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getName().equalsIgnoreCase(methodName) && ConsoleUtils.canExecuteCommand(this, method)) {
            possible.add(i);
        }
    }
    if (possible.size <= 0) {
        log("No such method found.", LogLevel.ERROR);
        return;
    }
    int size = possible.size;
    int numArgs = sArgs == null ? 0 : sArgs.length;
    for (int i = 0; i < size; i++) {
        Method m = methods[possible.get(i)];
        Class<?>[] params = m.getParameterTypes();
        if (numArgs == params.length) {
            try {
                Object[] args = null;
                try {
                    if (sArgs != null) {
                        args = new Object[numArgs];
                        for (int j = 0; j < params.length; j++) {
                            Class<?> param = params[j];
                            final String value = sArgs[j];
                            if (param.equals(String.class)) {
                                args[j] = value;
                            } else if (param.equals(Boolean.class) || param.equals(boolean.class)) {
                                args[j] = Boolean.parseBoolean(value);
                            } else if (param.equals(Byte.class) || param.equals(byte.class)) {
                                args[j] = Byte.parseByte(value);
                            } else if (param.equals(Short.class) || param.equals(short.class)) {
                                args[j] = Short.parseShort(value);
                            } else if (param.equals(Integer.class) || param.equals(int.class)) {
                                args[j] = Integer.parseInt(value);
                            } else if (param.equals(Long.class) || param.equals(long.class)) {
                                args[j] = Long.parseLong(value);
                            } else if (param.equals(Float.class) || param.equals(float.class)) {
                                args[j] = Float.parseFloat(value);
                            } else if (param.equals(Double.class) || param.equals(double.class)) {
                                args[j] = Double.parseDouble(value);
                            }
                        }
                    }
                } catch (Exception e) {
                    // Error occurred trying to parse parameter, continue to next function
                    continue;
                }
                m.setAccessible(true);
                m.invoke(exec, args);
                return;
            } catch (ReflectionException e) {
                String msg = e.getMessage();
                if (msg == null || msg.length() <= 0 || msg.equals("")) {
                    msg = "Unknown Error";
                    e.printStackTrace();
                }
                log(msg, LogLevel.ERROR);
                return;
            }
        }
    }
    log("Bad parameters. Check your code.", LogLevel.ERROR);
}
Also used : ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) Method(com.badlogic.gdx.utils.reflect.Method) ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) Array(com.badlogic.gdx.utils.Array)

Example 63 with Array

use of com.badlogic.gdx.utils.Array in project libgdx-inGameConsole by StrongJoshua.

the class CommandCompleter method getAllMethods.

private Array<Method> getAllMethods(CommandExecutor ce) {
    Array<Method> methods = new Array<>();
    Method[] ms = ClassReflection.getDeclaredMethods(ce.getClass());
    for (Method m : ms) {
        if (m.isPublic()) {
            methods.add(m);
        }
    }
    ms = ClassReflection.getDeclaredMethods(ce.getClass().getSuperclass());
    for (Method m : ms) {
        if (m.isPublic()) {
            methods.add(m);
        }
    }
    return methods;
}
Also used : Array(com.badlogic.gdx.utils.Array) Method(com.badlogic.gdx.utils.reflect.Method)

Example 64 with Array

use of com.badlogic.gdx.utils.Array in project nhglib by VoidZombie.

the class GraphicsSystem method rebuildCache.

private void rebuildCache(RenderableProvider... renderableProviders) {
    Array<ModelCache> previousModelCaches = new Array<>(staticCaches);
    for (int i = 0; i < cameras.size; i++) {
        ModelCache previousModelCache = previousModelCaches.get(i);
        ModelCache staticCache = staticCaches.get(i);
        Camera camera = cameras.get(i);
        previousModelCache.begin(camera);
        previousModelCache.add(staticCache);
        previousModelCache.end();
        staticCache.begin(camera);
        staticCache.add(previousModelCache);
        for (RenderableProvider provider : renderableProviders) {
            staticCache.add(provider);
        }
        staticCache.end();
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) RenderableProvider(com.badlogic.gdx.graphics.g3d.RenderableProvider) Camera(com.badlogic.gdx.graphics.Camera) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Example 65 with Array

use of com.badlogic.gdx.utils.Array in project nhglib by VoidZombie.

the class SceneManager method loadAssets.

private void loadAssets(Integer entity) {
    final ModelComponent modelComponent = modelMapper.get(entity);
    // Group all assets
    final Array<Asset> allAssets = new Array<>();
    final Asset modelAsset = modelComponent.asset;
    for (PbrMaterial mat : modelComponent.pbrMaterials) {
        if (mat.albedoAsset != null) {
            allAssets.add(mat.albedoAsset);
        }
        if (mat.metalnessAsset != null) {
            allAssets.add(mat.metalnessAsset);
        }
        if (mat.roughnessAsset != null) {
            allAssets.add(mat.roughnessAsset);
        }
        if (mat.normalAsset != null) {
            allAssets.add(mat.normalAsset);
        }
        if (mat.ambientOcclusionAsset != null) {
            allAssets.add(mat.ambientOcclusionAsset);
        }
    }
    // Start loading them
    assets.queueAsset(modelAsset);
    // Wait for them
    messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {

        @Override
        public void accept(Message message) throws Exception {
            Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
            if (asset != null) {
                if (asset.is(modelAsset.alias)) {
                    Model model = assets.get(asset);
                    modelComponent.model = new ModelInstance(model);
                    if (modelComponent.model.animations.size > 0) {
                        modelComponent.animationController = new AnimationController(modelComponent.model);
                    }
                    assets.queueAssets(allAssets);
                } else {
                    if (allAssets.contains(asset, false)) {
                        temporaryLoadedAssets.add(asset);
                        allAssets.removeValue(asset, false);
                        Bundle bundle = new Bundle();
                        bundle.put("size", allAssets.size);
                        bundle.put("modelComponent", modelComponent);
                        sizeSubject.onNext(bundle);
                    }
                }
            }
        }
    });
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) Bundle(io.github.voidzombie.nhglib.utils.data.Bundle) Array(com.badlogic.gdx.utils.Array) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model) Asset(io.github.voidzombie.nhglib.assets.Asset) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

Aggregations

Array (com.badlogic.gdx.utils.Array)67 FileHandle (com.badlogic.gdx.files.FileHandle)18 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)16 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)9 Texture (com.badlogic.gdx.graphics.Texture)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 Element (com.badlogic.gdx.utils.XmlReader.Element)7 IOException (java.io.IOException)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 JsonValue (com.badlogic.gdx.utils.JsonValue)5 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 Color (com.badlogic.gdx.graphics.Color)4 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)4 Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)4 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)4 Json (com.badlogic.gdx.utils.Json)4 TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)3 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3