Search in sources :

Example 1 with Settings

use of gaiasky.util.Settings in project gaiasky by langurmonkey.

the class GlobalClock method update.

/**
 * Update function
 *
 * @param dt Delta time in seconds
 */
public void update(double dt) {
    this.dt = dt;
    Settings settings = Settings.settings;
    dt = settings.runtime.timeOn ? this.dt : 0;
    if (dt != 0) {
        // In case we are in constant rate mode
        if (fps > 0) {
            dt = 1 / fps;
        }
        int sign = (int) Math.signum(timeWarp);
        double h = Math.abs(dt * timeWarp * Nature.S_TO_H);
        hDiff = h * sign;
        double ms = sign * h * Nature.H_TO_MS;
        long currentTime = time.toEpochMilli();
        lastTime = currentTime;
        long newTime = currentTime + (long) ms;
        // Check target time
        if (targetTime != null) {
            long target = targetTime.toEpochMilli();
            if ((timeWarp > 0 && currentTime <= target && newTime > target) || (timeWarp < 0 && currentTime >= target && newTime < target)) {
                newTime = target;
                // Unset target time
                targetTime = null;
                // STOP!
                setTimeWarp(0);
            }
        }
        if (newTime > settings.runtime.maxTimeMs) {
            if (currentTime < settings.runtime.maxTimeMs) {
                logger.info("Maximum time reached (" + (settings.runtime.maxTimeMs * Nature.MS_TO_Y) + " years)!");
                // Turn off time
                EventManager.publish(Event.TIME_STATE_CMD, this, false);
            }
            newTime = settings.runtime.maxTimeMs;
            time = Instant.ofEpochMilli(newTime);
            EventManager.publish(Event.TIME_CHANGE_INFO, this, time);
            lastUpdate = 0;
        } else if (newTime < settings.runtime.minTimeMs) {
            if (currentTime > settings.runtime.minTimeMs) {
                logger.info("Minimum time reached (" + (settings.runtime.minTimeMs * Nature.MS_TO_Y) + " years)!");
                // Turn off time
                EventManager.publish(Event.TIME_STATE_CMD, this, false);
            }
            newTime = settings.runtime.minTimeMs;
            time = Instant.ofEpochMilli(newTime);
            EventManager.publish(Event.TIME_CHANGE_INFO, this, time);
            lastUpdate = 0;
        } else {
            time = Instant.ofEpochMilli(newTime);
        }
        // Post event each 1/2 second
        lastUpdate += dt;
        if (lastUpdate > .5) {
            EventManager.publish(Event.TIME_CHANGE_INFO, this, time);
            lastUpdate = 0;
        }
    } else if (time.toEpochMilli() - lastTime != 0) {
        hDiff = (time.toEpochMilli() - lastTime) * Nature.MS_TO_H;
        lastTime = time.toEpochMilli();
    } else {
        hDiff = 0d;
    }
}
Also used : Settings(gaiasky.util.Settings)

Example 2 with Settings

use of gaiasky.util.Settings in project gaiasky by langurmonkey.

the class LightPositionUpdater method run.

@Override
public void run(AbstractRenderSystem renderSystem, Array<IRenderable> renderables, ICamera camera) {
    synchronized (lock) {
        int size = renderables.size;
        if (PostProcessorFactory.instance.getPostProcessor().isLightScatterEnabled()) {
            Settings settings = Settings.settings;
            // Compute light positions for light scattering or light
            // glow
            int lightIndex = 0;
            float angleEdgeDeg = camera.getAngleEdge() * MathUtils.radDeg;
            for (int i = size - 1; i >= 0; i--) {
                IRenderable s = renderables.get(i);
                if (s instanceof Star) {
                    Star p = (Star) s;
                    double angle = GaiaSky.instance.cameraManager.getDirection().angle(p.translation);
                    if (lightIndex < nLights && (settings.program.modeCubemap.active || settings.runtime.openVr || angle < angleEdgeDeg)) {
                        Vector3d pos3d = p.translation.put(auxD);
                        // Aberration
                        GlobalResources.applyRelativisticAberration(pos3d, camera);
                        // GravWaves
                        RelativisticEffectsManager.getInstance().gravitationalWavePos(pos3d);
                        Vector3 pos3 = pos3d.put(auxV);
                        float w = settings.graphics.resolution[0];
                        float h = settings.graphics.resolution[1];
                        camera.getCamera().project(pos3, 0, 0, w, h);
                        // Here we **need** to use
                        // Gdx.graphics.getWidth/Height() because we use
                        // camera.project() which uses screen
                        // coordinates only
                        positions[lightIndex * 2] = auxV.x / w;
                        positions[lightIndex * 2 + 1] = auxV.y / h;
                        viewAngles[lightIndex] = (float) p.viewAngleApparent;
                        colors[lightIndex * 3] = p.cc[0];
                        colors[lightIndex * 3 + 1] = p.cc[1];
                        colors[lightIndex * 3 + 2] = p.cc[2];
                        lightIndex++;
                    }
                }
            }
            EventManager.publish(Event.LIGHT_POS_2D_UPDATE, this, lightIndex, positions, viewAngles, colors, glowTex);
        } else {
            EventManager.publish(Event.LIGHT_POS_2D_UPDATE, this, 0, positions, viewAngles, colors, glowTex);
        }
    }
}
Also used : IRenderable(gaiasky.render.IRenderable) Star(gaiasky.scenegraph.Star) Vector3d(gaiasky.util.math.Vector3d) Vector3(com.badlogic.gdx.math.Vector3) Settings(gaiasky.util.Settings)

Example 3 with Settings

use of gaiasky.util.Settings in project gaiasky by langurmonkey.

the class GlobalClock method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case TARGET_TIME_CMD:
            if (data.length > 0) {
                targetTime = (Instant) data[0];
            } else {
                targetTime = null;
            }
            break;
        case TIME_WARP_CMD:
            // Update pace
            setTimeWarp((Double) data[0]);
            break;
        case TIME_WARP_INCREASE_CMD:
            double tw;
            if (timeWarp == 0) {
                tw = 0.125;
            } else if (timeWarp == -0.125) {
                tw = 0;
            } else if (timeWarp < 0) {
                tw = timeWarp / 2.0;
            } else {
                tw = timeWarp * 2.0;
            }
            setTimeWarp(tw);
            break;
        case TIME_WARP_DECREASE_CMD:
            if (timeWarp == 0.125) {
                tw = 0;
            } else if (timeWarp == 0) {
                tw = -0.125;
            } else if (timeWarp < 0) {
                tw = timeWarp * 2.0;
            } else {
                tw = timeWarp / 2.0;
            }
            setTimeWarp(tw);
            break;
        case TIME_CHANGE_CMD:
            // Update time
            Instant newinstant = ((Instant) data[0]);
            long newt = newinstant.toEpochMilli();
            boolean updt = false;
            Settings settings = Settings.settings;
            if (newt > settings.runtime.maxTimeMs) {
                newt = settings.runtime.maxTimeMs;
                logger.info("Time overflow, set to maximum (" + (settings.runtime.maxTimeMs * Nature.MS_TO_Y) + " years)");
                updt = true;
            }
            if (newt < settings.runtime.minTimeMs) {
                newt = settings.runtime.minTimeMs;
                logger.info("Time overflow, set to minimum (" + (settings.runtime.minTimeMs * Nature.MS_TO_Y) + " years)");
                updt = true;
            }
            if (updt) {
                this.time = Instant.ofEpochMilli(newt);
            } else {
                this.time = newinstant;
            }
            break;
        default:
            break;
    }
}
Also used : Instant(java.time.Instant) Settings(gaiasky.util.Settings)

Example 4 with Settings

use of gaiasky.util.Settings in project gaiasky by langurmonkey.

the class Particle method update.

/**
 * Re-implementation of update method of {@link CelestialBody} and
 * {@link SceneGraphNode}.
 */
@Override
public void update(ITimeFrameProvider time, final Vector3b parentTransform, ICamera camera, float opacity) {
    this.updateLocalValues(time, camera);
    translation.set(parentTransform).add(pos);
    this.opacity = opacity;
    this.opacity *= this.getVisibilityOpacityFactor();
    if (hasPm) {
        Vector3d pmv = D31.get().set(pm).scl(AstroUtils.getMsSince(time.getTime(), AstroUtils.JD_J2015_5) * Nature.MS_TO_Y);
        translation.add(pmv);
    }
    distToCamera = translation.lend();
    Settings settings = Settings.settings;
    if (!copy) {
        viewAngle = (radius / distToCamera);
        viewAngleApparent = viewAngle * settings.scene.star.brightness / camera.getFovFactor();
        addToRenderLists(camera);
    }
    // Compute nested
    if (children != null) {
        for (int i = 0; i < children.size; i++) {
            SceneGraphNode child = children.get(i);
            child.update(time, translation, camera, opacity);
        }
    }
    innerRad = 0.01f * DISC_FACTOR + settings.scene.star.pointSize * 0.005f;
}
Also used : Vector3d(gaiasky.util.math.Vector3d) Settings(gaiasky.util.Settings)

Example 5 with Settings

use of gaiasky.util.Settings in project gaiasky by langurmonkey.

the class LoadingGui method initialize.

@Override
public void initialize(AssetManager assetManager, SpriteBatch sb) {
    interfaces = new Array<>();
    float pad30 = 48f;
    float pad10 = 16f;
    final Settings settings = Settings.settings;
    // User interface
    ScreenViewport vp = new ScreenViewport();
    vp.setUnitsPerPixel(unitsPerPixel);
    ui = new Stage(vp, sb);
    if (vr) {
        vp.update(settings.graphics.backBufferResolution[0], settings.graphics.backBufferResolution[1], true);
    } else {
        vp.update(GaiaSky.instance.graphics.getWidth(), GaiaSky.instance.graphics.getHeight(), true);
    }
    center = new Table(skin);
    if (!vr) {
        Texture tex = new Texture(Gdx.files.internal("img/splash/splash.jpg"));
        Drawable bg = new SpriteDrawable(new Sprite(tex));
        center.setBackground(bg);
    }
    center.setFillParent(true);
    center.center();
    if (hoffset > 0)
        center.padLeft(hoffset);
    else if (hoffset < 0)
        center.padRight(-hoffset);
    HorizontalGroup titleGroup = new HorizontalGroup();
    titleGroup.space(pad30 * 2f);
    OwnLabel gaiaSky = new OwnLabel(Settings.getApplicationTitle(settings.runtime.openVr), skin, "main-title");
    OwnLabel version = new OwnLabel(Settings.settings.version.version, skin, "main-title");
    version.setColor(skin.getColor("theme"));
    titleGroup.addActor(gaiaSky);
    titleGroup.addActor(version);
    // Funny text
    lastFunnyTime = 0;
    i = -1;
    m1 = BigInteger.ZERO;
    m2 = BigInteger.ZERO;
    spin = new OwnLabel("0", skin, "main-title-xs");
    spin.setColor(skin.getColor("theme"));
    center.add(titleGroup).center().padBottom(pad10 * 2f).row();
    center.add(spin).padBottom(pad30).row();
    // Tips
    tipGenerator = new TipGenerator(skin);
    tip = new HorizontalGroup();
    tip.space(pad10);
    bottomMiddle = new Table(skin);
    bottomMiddle.setFillParent(true);
    bottomMiddle.center().bottom();
    bottomMiddle.padLeft(pad30).padBottom(pad10);
    bottomMiddle.add(tip);
    // Version and build
    topLeft = new VersionLineTable(skin);
    // SCREEN MODE BUTTON - TOP RIGHT
    screenMode = new Table(skin);
    screenMode.setFillParent(true);
    screenMode.top().right();
    screenMode.pad(pad10);
    OwnTextIconButton screenModeButton = new OwnTextIconButton("", skin, "screen-mode");
    screenModeButton.addListener(event -> {
        if (event instanceof ChangeEvent) {
            settings.graphics.fullScreen.active = !settings.graphics.fullScreen.active;
            EventManager.publish(Event.SCREEN_MODE_CMD, screenModeButton);
            return true;
        }
        return false;
    });
    screenMode.add(screenModeButton);
    // MESSAGE INTERFACE - BOTTOM
    notificationsInterface = new NotificationsInterface(skin, lock, false, false, false);
    center.add(notificationsInterface);
    interfaces.add(notificationsInterface);
    rebuildGui();
}
Also used : OwnTextIconButton(gaiasky.util.scene2d.OwnTextIconButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Texture(com.badlogic.gdx.graphics.Texture) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Stage(com.badlogic.gdx.scenes.scene2d.Stage) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) OwnLabel(gaiasky.util.scene2d.OwnLabel) TipGenerator(gaiasky.util.TipGenerator) Settings(gaiasky.util.Settings)

Aggregations

Settings (gaiasky.util.Settings)6 Vector3d (gaiasky.util.math.Vector3d)2 Texture (com.badlogic.gdx.graphics.Texture)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 Vector3 (com.badlogic.gdx.math.Vector3)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)1 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SequenceWriter (com.fasterxml.jackson.databind.SequenceWriter)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Feature (com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature)1 PathType (gaiasky.desktop.util.camera.CameraKeyframeManager.PathType)1 IRenderable (gaiasky.render.IRenderable)1 Star (gaiasky.scenegraph.Star)1