Search in sources :

Example 1 with ITimeFrameProvider

use of gaiasky.util.time.ITimeFrameProvider in project gaiasky by langurmonkey.

the class EventScriptingInterface method getSimulationTimeArr.

@Override
public int[] getSimulationTimeArr() {
    ITimeFrameProvider time = GaiaSky.instance.time;
    Instant instant = time.getTime();
    LocalDateTime c = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
    int[] result = new int[7];
    result[0] = c.get(ChronoField.YEAR_OF_ERA);
    result[1] = c.getMonthValue();
    result[2] = c.getDayOfMonth();
    result[3] = c.getHour();
    result[4] = c.getMinute();
    result[5] = c.getSecond();
    result[6] = c.get(ChronoField.MILLI_OF_SECOND);
    return result;
}
Also used : LocalDateTime(java.time.LocalDateTime) Instant(java.time.Instant) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider)

Example 2 with ITimeFrameProvider

use of gaiasky.util.time.ITimeFrameProvider in project gaiasky by langurmonkey.

the class CamRecorder method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case RECORD_CAMERA_CMD:
            // Start recording
            RecorderState m;
            if (data[0] != null) {
                if ((Boolean) data[0]) {
                    m = RecorderState.RECORDING;
                } else {
                    m = RecorderState.IDLE;
                }
            } else {
                m = (mode == RecorderState.RECORDING) ? RecorderState.IDLE : RecorderState.RECORDING;
            }
            if (m == RecorderState.RECORDING) {
                String filename;
                if (data.length > 1 && data[1] != null && !((String) data[1]).isBlank()) {
                    filename = (String) data[1];
                } else {
                    filename = df.format(new Date());
                }
                // We start recording, prepare buffer!
                if (mode == RecorderState.RECORDING) {
                    logger.info(I18n.txt("error.camerarecord.already"));
                    return;
                }
                // Annotate by date
                f = SysUtils.getDefaultCameraDir().resolve(filename + ".gsc");
                if (Files.exists(f)) {
                    try {
                        Files.delete(f);
                    } catch (IOException e) {
                        logger.error(e);
                    }
                }
                try {
                    Files.createFile(f);
                    os = new BufferedWriter(new FileWriter(f.toFile()));
                    // Print header
                    os.append("#time_ms").append(sep).append("pos_x").append(sep).append("pos_y").append(sep).append("pos_z").append(sep);
                    os.append("dir_x").append(sep).append("dir_y").append(sep).append("dir_z").append(sep);
                    os.append("up_x").append(sep).append("up_y").append(sep).append("up_z").append(sep);
                    os.append("\n");
                } catch (IOException e) {
                    logger.error(e);
                    return;
                }
                logger.info(I18n.txt("notif.camerarecord.start"));
                startMs = System.currentTimeMillis();
                time = 0;
                mode = RecorderState.RECORDING;
            } else if (m == RecorderState.IDLE) {
                // Flush and close
                if (mode == RecorderState.IDLE) {
                    // No recording to cancel
                    return;
                }
                try {
                    os.close();
                } catch (IOException e) {
                    logger.error(e);
                }
                os = null;
                long elapsed = System.currentTimeMillis() - startMs;
                startMs = 0;
                float secs = elapsed / 1000f;
                logger.info(I18n.txt("notif.camerarecord.done", f.toAbsolutePath(), secs));
                EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.camerarecord.done", f.toAbsolutePath(), secs));
                f = null;
                mode = RecorderState.IDLE;
            }
            break;
        case PLAY_CAMERA_CMD:
            // Start playing
            if (is != null) {
                logger.warn("Hey, we are already playing another movie!");
            }
            if (mode != RecorderState.IDLE) {
                throw new RuntimeException("The recorder is busy! The current mode is " + mode);
            }
            Object f = data[0];
            Path file;
            if (f instanceof String) {
                file = Paths.get((String) f);
            } else {
                file = (Path) f;
            }
            try {
                is = new BufferedReader(new InputStreamReader(Files.newInputStream(file)));
                logger.info(I18n.txt("notif.cameraplay.start", file));
                EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.cameraplay.start", file));
                mode = RecorderState.PLAYING;
                // Issue message informing playing has started
                EventManager.publish(Event.CAMERA_PLAY_INFO, this, true);
                // Enable frame output if option is on
                if (Settings.settings.camrecorder.auto) {
                    // Stop frame output if it is on!
                    EventManager.publish(Event.FRAME_OUTPUT_CMD, this, true);
                }
            } catch (Exception e) {
                logger.error(e);
            }
            break;
        case UPDATE_CAM_RECORDER:
            // Update with current position
            ITimeFrameProvider dt = (ITimeFrameProvider) data[0];
            Vector3b pos = (Vector3b) data[1];
            Vector3d dir = (Vector3d) data[2];
            Vector3d up = (Vector3d) data[3];
            update(dt, pos, dir, up);
            break;
        case STOP_CAMERA_PLAY:
            // Stop playing
            mode = RecorderState.IDLE;
            // Stop camera
            EventManager.publish(Event.CAMERA_STOP, this);
            // Post notification
            logger.info(I18n.txt("notif.cameraplay.done"));
            EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.cameraplay.done"));
            // Issue message informing playing has stopped
            EventManager.publish(Event.CAMERA_PLAY_INFO, this, false);
            // Stop frame output if it is on!
            EventManager.publish(Event.FRAME_OUTPUT_CMD, this, false);
            break;
        default:
            break;
    }
}
Also used : Path(java.nio.file.Path) Date(java.util.Date) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider)

Example 3 with ITimeFrameProvider

use of gaiasky.util.time.ITimeFrameProvider in project gaiasky by langurmonkey.

the class GaiaSky method create.

@Override
public void create() {
    startTime = TimeUtils.millis();
    // Log level
    Gdx.app.setLogLevel(debugMode ? Application.LOG_DEBUG : Application.LOG_INFO);
    Logger.level = debugMode ? Logger.LoggerLevel.DEBUG : Logger.LoggerLevel.INFO;
    consoleLogger = new ConsoleLogger();
    if (debugMode)
        logger.debug("Logging level set to DEBUG");
    // Init graphics and window
    graphics = Gdx.graphics;
    window = headless ? null : ((Lwjgl3Graphics) graphics).getWindow();
    // Basic info
    logger.info(settings.version.version, I18n.txt("gui.build", settings.version.build));
    logger.info("Display mode", graphics.getWidth() + "x" + graphics.getHeight(), "Fullscreen: " + Gdx.graphics.isFullscreen());
    logger.info("Device", GL30.glGetString(GL30.GL_RENDERER));
    logger.info(I18n.txt("notif.glversion", GL30.glGetString(GL30.GL_VERSION)));
    logger.info(I18n.txt("notif.glslversion", GL30.glGetString(GL30.GL_SHADING_LANGUAGE_VERSION)));
    logger.info(I18n.txt("notif.javaversion", System.getProperty("java.version"), System.getProperty("java.vendor")));
    // Frame buffer map
    frameBufferMap = new HashMap<>();
    // Disable all kinds of input
    EventManager.publish(Event.INPUT_ENABLED_CMD, this, false);
    if (!settings.initialized) {
        logger.error(new RuntimeException(I18n.txt("notif.error", "global configuration not initialized")));
        return;
    }
    // Initialise times
    final ITimeFrameProvider clock = new GlobalClock(1, Instant.now());
    final ITimeFrameProvider real = new RealTimeClock();
    time = settings.runtime.realTime ? real : clock;
    t = 0;
    // Initialise i18n
    I18n.initialize();
    // Tooltips
    TooltipManager.getInstance().initialTime = 1f;
    TooltipManager.getInstance().hideAll();
    // Initialise asset manager
    final FileHandleResolver internalResolver = new InternalFileHandleResolver();
    final FileHandleResolver dataResolver = fileName -> settings.data.dataFileHandle(fileName);
    assetManager = new AssetManager(internalResolver);
    assetManager.setLoader(com.badlogic.gdx.graphics.Texture.class, ".pfm", new PFMTextureLoader(dataResolver));
    assetManager.setLoader(PFMData.class, new PFMDataLoader(dataResolver));
    assetManager.setLoader(ISceneGraph.class, new SGLoader(dataResolver));
    assetManager.setLoader(PointCloudData.class, new OrbitDataLoader(dataResolver));
    assetManager.setLoader(GaiaAttitudeServer.class, new GaiaAttitudeLoader(dataResolver));
    assetManager.setLoader(ExtShaderProgram.class, new ShaderProgramProvider(internalResolver, ".vertex.glsl", ".fragment.glsl"));
    assetManager.setLoader(BitmapFont.class, new BitmapFontLoader(internalResolver));
    assetManager.setLoader(AtmosphereShaderProvider.class, new AtmosphereShaderProviderLoader<>(internalResolver));
    assetManager.setLoader(GroundShaderProvider.class, new GroundShaderProviderLoader<>(internalResolver));
    assetManager.setLoader(TessellationShaderProvider.class, new TessellationShaderProviderLoader<>(internalResolver));
    assetManager.setLoader(RelativisticShaderProvider.class, new RelativisticShaderProviderLoader<>(internalResolver));
    assetManager.setLoader(IntModel.class, ".obj", new OwnObjLoader(new RegularInputStreamProvider(), internalResolver));
    assetManager.setLoader(IntModel.class, ".obj.gz", new OwnObjLoader(new GzipInputStreamProvider(), internalResolver));
    assetManager.setLoader(IntModel.class, ".g3dj", new G3dModelLoader(new JsonReader(), internalResolver));
    assetManager.setLoader(IntModel.class, ".g3db", new G3dModelLoader(new UBJsonReader(), internalResolver));
    // Remove Model loaders
    // Init global resources
    this.globalResources = new GlobalResources(assetManager);
    // Initialize screenshots manager
    new ScreenshotsManager(globalResources);
    // Catalog manager
    this.catalogManager = new CatalogManager();
    this.scripting = new EventScriptingInterface(this.assetManager, this.catalogManager);
    // Initialise master manager
    MasterManager.initialize();
    // Load slave assets
    SlaveManager.load(assetManager);
    // Initialise dataset updater
    this.executorService = new GaiaSkyExecutorService();
    // Bookmarks
    this.bookmarksManager = new BookmarksManager();
    // Location log
    LocationLogManager.initialize();
    // Init timer thread
    Timer.instance();
    // Initialise Cameras
    cameraManager = new CameraManager(assetManager, CameraMode.FOCUS_MODE, vr, globalResources);
    // Set asset manager to asset bean
    AssetBean.setAssetManager(assetManager);
    // Create vr context if possible
    final VRStatus vrStatus = createVR();
    cameraManager.updateFrustumPlanes();
    // Tooltip to 1s
    TooltipManager.getInstance().initialTime = 1f;
    // Initialise Gaia attitudes
    assetManager.load(Constants.ATTITUDE_FOLDER, GaiaAttitudeServer.class, new GaiaAttitudeLoaderParameter());
    // Initialise hidden helper user
    HiddenHelperUser.initialize();
    // Initialise gravitational waves helper
    RelativisticEffectsManager.initialize(time);
    // GUI
    guis = new ArrayList<>(3);
    // Post-processor
    postProcessor = PostProcessorFactory.instance.getPostProcessor();
    // Scene graph renderer
    sgr = new SceneGraphRenderer(vrContext, globalResources);
    sgr.initialize(assetManager);
    // Initialise scripting gateway server
    if (!noScripting)
        ScriptingServer.initialize();
    // Tell the asset manager to load all the assets
    final Set<AssetBean> assets = AssetBean.getAssets();
    for (AssetBean ab : assets) {
        ab.load(assetManager);
    }
    renderBatch = globalResources.getSpriteBatch();
    EventManager.instance.subscribe(this, Event.LOAD_DATA_CMD);
    welcomeGui = new WelcomeGui(globalResources.getSkin(), graphics, 1f / settings.program.ui.scale, skipWelcome, vrStatus);
    welcomeGui.initialize(assetManager, globalResources.getSpriteBatch());
    Gdx.input.setInputProcessor(welcomeGui.getGuiStage());
    if (settings.runtime.openVr) {
        welcomeGuiVR = new VRGui<>(WelcomeGuiVR.class, (int) (settings.graphics.backBufferResolution[0] / 2f), globalResources.getSkin(), graphics, 1f / settings.program.ui.scale);
        welcomeGuiVR.initialize(assetManager, globalResources.getSpriteBatch());
    }
    // GL clear state
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClearDepthf(1f);
}
Also used : ICamera(gaiasky.scenegraph.camera.ICamera) RegularInputStreamProvider(gaiasky.util.gdx.loader.is.RegularInputStreamProvider) SysUtils(gaiasky.desktop.util.SysUtils) Task(com.badlogic.gdx.utils.Timer.Task) TooltipManager(com.badlogic.gdx.scenes.scene2d.ui.TooltipManager) Logger(gaiasky.util.Logger) GL20(com.badlogic.gdx.graphics.GL20) PingPongBuffer(gaiasky.util.gdx.contrib.postprocess.utils.PingPongBuffer) IObserver(gaiasky.event.IObserver) RenderType(gaiasky.render.IPostProcessor.RenderType) VRCompositor(org.lwjgl.openvr.VRCompositor) gaiasky.util.gdx.loader(gaiasky.util.gdx.loader) RelativisticEffectsManager(gaiasky.util.gravwaves.RelativisticEffectsManager) gaiasky.interafce(gaiasky.interafce) GaiaSkyExecutorService(gaiasky.util.ds.GaiaSkyExecutorService) Path(java.nio.file.Path) EventScriptingInterface(gaiasky.script.EventScriptingInterface) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) GzipInputStreamProvider(gaiasky.util.gdx.loader.is.GzipInputStreamProvider) PointCloudData(gaiasky.data.util.PointCloudData) AssetManager(com.badlogic.gdx.assets.AssetManager) SAMPClient(gaiasky.util.samp.SAMPClient) Event(gaiasky.event.Event) VRContext(gaiasky.vr.openvr.VRContext) com.badlogic.gdx(com.badlogic.gdx) Lwjgl3WindowConfiguration(com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowConfiguration) HiddenHelperUser(gaiasky.script.HiddenHelperUser) Instant(java.time.Instant) AssetBean(gaiasky.data.AssetBean) IScriptingInterface(gaiasky.script.IScriptingInterface) Texture(org.lwjgl.openvr.Texture) StreamingOctreeLoader(gaiasky.data.StreamingOctreeLoader) CameraManager(gaiasky.scenegraph.camera.CameraManager) gaiasky.assets(gaiasky.assets) OctreeNode(gaiasky.util.tree.OctreeNode) EventManager(gaiasky.event.EventManager) CrashReporter(gaiasky.desktop.util.CrashReporter) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) java.util(java.util) Attribute(gaiasky.util.gdx.shader.attribute.Attribute) GaiaAttitudeServer(gaiasky.util.gaia.GaiaAttitudeServer) GL30(org.lwjgl.opengl.GL30) PostProcessBean(gaiasky.render.IPostProcessor.PostProcessBean) ScreenshotsManager(gaiasky.screenshot.ScreenshotsManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) Lwjgl3Window(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window) RealTimeClock(gaiasky.util.time.RealTimeClock) gaiasky.scenegraph(gaiasky.scenegraph) ScriptingServer(gaiasky.script.ScriptingServer) com.badlogic.gdx.utils(com.badlogic.gdx.utils) VRDevice(gaiasky.vr.openvr.VRContext.VRDevice) Format(com.badlogic.gdx.graphics.Pixmap.Format) ModelComponent(gaiasky.scenegraph.component.ModelComponent) GlobalClock(gaiasky.util.time.GlobalClock) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) gaiasky.render(gaiasky.render) Lwjgl3Application(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) VRDeviceType(gaiasky.vr.openvr.VRContext.VRDeviceType) Timer(com.badlogic.gdx.utils.Timer) ComponentType(gaiasky.render.ComponentTypes.ComponentType) BitmapFont(gaiasky.util.gdx.g2d.BitmapFont) GaiaAttitudeLoaderParameter(gaiasky.assets.GaiaAttitudeLoader.GaiaAttitudeLoaderParameter) Lwjgl3Graphics(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics) gaiasky.util(gaiasky.util) IntModel(gaiasky.util.gdx.model.IntModel) SGLoaderParameter(gaiasky.assets.SGLoader.SGLoaderParameter) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider) File(java.io.File) VR(org.lwjgl.openvr.VR) VRStatus(gaiasky.vr.openvr.VRStatus) Log(gaiasky.util.Logger.Log) gaiasky.util.gdx.shader(gaiasky.util.gdx.shader) GaiaSkyExecutorService(gaiasky.util.ds.GaiaSkyExecutorService) GaiaAttitudeLoaderParameter(gaiasky.assets.GaiaAttitudeLoader.GaiaAttitudeLoaderParameter) ScreenshotsManager(gaiasky.screenshot.ScreenshotsManager) Lwjgl3Graphics(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) VRStatus(gaiasky.vr.openvr.VRStatus) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider) EventScriptingInterface(gaiasky.script.EventScriptingInterface) AssetManager(com.badlogic.gdx.assets.AssetManager) RealTimeClock(gaiasky.util.time.RealTimeClock) GzipInputStreamProvider(gaiasky.util.gdx.loader.is.GzipInputStreamProvider) CameraManager(gaiasky.scenegraph.camera.CameraManager) AssetBean(gaiasky.data.AssetBean) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) GlobalClock(gaiasky.util.time.GlobalClock) RegularInputStreamProvider(gaiasky.util.gdx.loader.is.RegularInputStreamProvider)

Aggregations

ITimeFrameProvider (gaiasky.util.time.ITimeFrameProvider)2 com.badlogic.gdx (com.badlogic.gdx)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandleResolver (com.badlogic.gdx.assets.loaders.FileHandleResolver)1 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)1 Lwjgl3Application (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application)1 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 Lwjgl3Window (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window)1 Lwjgl3WindowConfiguration (com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowConfiguration)1 GL20 (com.badlogic.gdx.graphics.GL20)1 Format (com.badlogic.gdx.graphics.Pixmap.Format)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)1 TooltipManager (com.badlogic.gdx.scenes.scene2d.ui.TooltipManager)1 com.badlogic.gdx.utils (com.badlogic.gdx.utils)1 Timer (com.badlogic.gdx.utils.Timer)1 Task (com.badlogic.gdx.utils.Timer.Task)1 gaiasky.assets (gaiasky.assets)1 GaiaAttitudeLoaderParameter (gaiasky.assets.GaiaAttitudeLoader.GaiaAttitudeLoaderParameter)1 SGLoaderParameter (gaiasky.assets.SGLoader.SGLoaderParameter)1