use of gaiasky.assets.SGLoader.SGLoaderParameter in project gaiasky by langurmonkey.
the class GaiaSky method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
switch(event) {
case LOAD_DATA_CMD:
// Init components that need assets in data folder
reinitialiseGUI1();
postProcessor.initialize(assetManager);
// Initialise loading screen
loadingGui = new LoadingGui(globalResources.getSkin(), graphics, 1f / settings.program.ui.scale, false);
loadingGui.initialize(assetManager, globalResources.getSpriteBatch());
Gdx.input.setInputProcessor(loadingGui.getGuiStage());
// Also VR
if (settings.runtime.openVr) {
loadingGuiVR = new VRGui<>(LoadingGui.class, (int) (settings.graphics.backBufferResolution[0] / 4f), globalResources.getSkin(), graphics, 1f / settings.program.ui.scale);
loadingGuiVR.initialize(assetManager, globalResources.getSpriteBatch());
}
this.renderProcess = runnableLoadingGui;
/* LOAD SCENE GRAPH */
if (sceneGraph == null) {
dataLoadString = "SceneGraphData";
final String[] dataFilesToLoad = new String[settings.data.dataFiles.size()];
int i = 0;
// Our resolver in the SGLoader itself will resolve their full paths
for (String dataFile : settings.data.dataFiles) {
dataFilesToLoad[i] = dataFile;
i++;
}
assetManager.load(dataLoadString, ISceneGraph.class, new SGLoaderParameter(dataFilesToLoad, time, settings.performance.multithreading, settings.performance.getNumberOfThreads()));
}
break;
case TOGGLE_AMBIENT_LIGHT:
// TODO No better place to put this??
ModelComponent.toggleAmbientLight((Boolean) data[1]);
break;
case AMBIENT_LIGHT_CMD:
ModelComponent.setAmbientLight((float) data[0]);
break;
case RECORD_CAMERA_CMD:
if (data != null && data.length > 0) {
camRecording = (Boolean) data[0];
} else {
camRecording = !camRecording;
}
break;
case CAMERA_MODE_CMD:
// Register/unregister GUI
final CameraMode mode = (CameraMode) data[0];
if (settings.program.modeStereo.isStereoHalfViewport()) {
guiRegistry.change(stereoGui);
} else if (mode == CameraMode.SPACECRAFT_MODE) {
guiRegistry.change(spacecraftGui);
} else {
guiRegistry.change(mainGui);
}
break;
case STEREOSCOPIC_CMD:
final boolean stereoMode = (Boolean) data[0];
if (stereoMode && guiRegistry.current != stereoGui) {
guiRegistry.change(stereoGui);
} else if (!stereoMode && guiRegistry.previous != stereoGui) {
IGui prev = guiRegistry.current != null ? guiRegistry.current : mainGui;
guiRegistry.change(guiRegistry.previous, prev);
}
// Post a message to the screen
if (stereoMode) {
resetDynamicResolution();
String[] keysStrToggle = KeyBindings.instance.getStringArrayKeys("action.toggle/element.stereomode");
String[] keysStrProfile = KeyBindings.instance.getStringArrayKeys("action.switchstereoprofile");
final ModePopupInfo mpi = new ModePopupInfo();
mpi.title = I18n.txt("gui.stereo.title");
mpi.header = I18n.txt("gui.stereo.notice.header");
;
mpi.addMapping(I18n.txt("gui.stereo.notice.back"), keysStrToggle);
mpi.addMapping(I18n.txt("gui.stereo.notice.profile"), keysStrProfile);
EventManager.publish(Event.MODE_POPUP_CMD, this, mpi, "stereo", 120f);
} else {
EventManager.publish(Event.MODE_POPUP_CMD, this, null, "stereo");
}
break;
case CUBEMAP_CMD:
boolean cubemapMode = (Boolean) data[0];
if (cubemapMode) {
resetDynamicResolution();
}
break;
case SCREENSHOT_SIZE_UPDATE:
case FRAME_SIZE_UPDATE:
// });
break;
case SCENE_GRAPH_ADD_OBJECT_CMD:
final SceneGraphNode nodeToAdd = (SceneGraphNode) data[0];
final boolean addToIndex = data.length == 1 || (Boolean) data[1];
if (sceneGraph != null) {
postRunnable(() -> {
try {
sceneGraph.insert(nodeToAdd, addToIndex);
} catch (Exception e) {
logger.error(e);
}
});
}
break;
case SCENE_GRAPH_ADD_OBJECT_NO_POST_CMD:
final SceneGraphNode nodeToAddp = (SceneGraphNode) data[0];
final boolean addToIndexp = data.length == 1 || (Boolean) data[1];
if (sceneGraph != null) {
try {
sceneGraph.insert(nodeToAddp, addToIndexp);
} catch (Exception e) {
logger.error(e);
}
}
break;
case SCENE_GRAPH_REMOVE_OBJECT_CMD:
SceneGraphNode aux;
if (data[0] instanceof String) {
aux = sceneGraph.getNode((String) data[0]);
if (aux == null)
return;
} else {
aux = (SceneGraphNode) data[0];
}
final SceneGraphNode nodeToRemove = aux;
final boolean removeFromIndex = data.length == 1 || (Boolean) data[1];
if (sceneGraph != null) {
postRunnable(() -> sceneGraph.remove(nodeToRemove, removeFromIndex));
}
break;
case UI_SCALE_CMD:
if (guis != null) {
float uiScale = (Float) data[0];
for (IGui gui : guis) {
gui.updateUnitsPerPixel(1f / uiScale);
}
}
break;
case HOME_CMD:
goHome();
break;
case PER_OBJECT_VISIBILITY_CMD:
final IVisibilitySwitch vs = (IVisibilitySwitch) data[0];
String name = (String) data[1];
boolean state = (boolean) data[2];
vs.setVisible(state, name.toLowerCase());
logger.info(I18n.txt("notif.visibility.object.set", vs.getName(), I18n.txt("gui." + state)));
break;
case FORCE_OBJECT_LABEL_CMD:
final SceneGraphNode forceLabelObject = (SceneGraphNode) data[0];
name = (String) data[1];
state = (boolean) data[2];
forceLabelObject.setForceLabel(state, name.toLowerCase());
logger.info(I18n.txt("notif.object.flag", "forceLabel", forceLabelObject.getName(), I18n.txt("gui." + state)));
break;
case LABEL_COLOR_CMD:
final SceneGraphNode labelColorObject = (SceneGraphNode) data[0];
name = (String) data[1];
float[] labelColor = (float[]) data[2];
labelColorObject.setLabelcolor(labelColor, name);
break;
case PARK_RUNNABLE:
synchronized (parkedRunnables) {
final String key = (String) data[0];
final Runnable runnable = (Runnable) data[1];
parkRunnable(key, runnable);
}
break;
case UNPARK_RUNNABLE:
synchronized (parkedRunnables) {
final String key = (String) data[0];
removeRunnable(key);
}
break;
case REINITIALIZE_POSTPROCESSOR:
if (postProcessor != null) {
postProcessor.dispose();
} else {
postProcessor = PostProcessorFactory.instance.getPostProcessor();
}
// Initialize
postProcessor.initialize(assetManager);
// Set up
postProcessor.doneLoading(assetManager);
break;
case REINITIALIZE_RENDERER:
sgr.setRendering(false);
logger.info("Re-initializing main renderer");
if (sgr != null) {
sgr.dispose();
}
// Initialize and load
sgr.doneLoading(assetManager);
sgr.resize(graphics.getWidth(), graphics.getHeight(), (int) Math.round(graphics.getWidth() * settings.graphics.backBufferScale), (int) Math.round(graphics.getHeight() * settings.graphics.backBufferScale));
sgr.setRendering(true);
break;
default:
break;
}
}
Aggregations