private void onFinishedLoading() { BitmapFont main19Font = assetManager.get(MAIN_FONT_19_PATH()); BitmapFont main22Font = assetManager.get(MAIN_FONT_22_PATH()); BitmapFont letter20Font = assetManager.get(LETTER_FONT_20_PATH()); BitmapFont handwritten20Font = assetManager .get(HANDWRITTEN_FONT_20_PATH()); ObjectMap<String, Object> fontMap = new ObjectMap<String, Object>(); fontMap.put("main-19", main19Font); fontMap.put("main-22", main22Font); fontMap.put("letter-20", letter20Font); fontMap.put("handwritten-20", handwritten20Font); assetManager.load(SKIN_PATH, Skin.class, new SkinLoader.SkinParameter(SKIN_TEXTURE_ATLAS_PATH, fontMap)); assetManager.finishLoadingAsset(SKIN_PATH); // game.setUISkin(assetManager.get(SKIN_PATH)); VisUI.load(); game.setUISkin(VisUI.getSkin()); // Notify loaded screens game.getScreen("serverBrowser").finishLoading(); game.pushScreen("mainMenu"); }
/** Add a Batchable to the queue. */ public void add (T batchable) { if (batchable.isOpaque()) { for (ObjectMap.Entry<T, ObjectSet<T>> entry : opaqueBatchables) { if (batchable.hasEquivalentTextures(entry.key)) { entry.value.add((T)batchable); return; } } ObjectSet<T> set = objectSetPool.obtain(); set.add(batchable); opaqueBatchables.put(batchable, set); } else { blendedBatchables.add(batchable); } needSort = true; }
public void initManagers() { assetManager = new AssetManager(new LocalFileHandleResolver(), true); imagePacks = new ObjectMap<String, Array<String>>(); for (String name : new String[] {"characters", "obstacles", "grounds", "clouds", "bushes", "buildings"}) { imagePacks.put(DATA_PATH + "/" + name, new Array<String>()); } stateManager = new StateManager(this); stateManager.addState("loading", new LoadingState("menu", this)); stateManager.addState("menu", new MenuState(this)); stateManager.addState("game", new GameState(this)); stateManager.addState("credits", new CreditsState(this)); spriteBatch = new SpriteBatch(); pixmapPacker = new PixmapPacker(1024, 1024, Pixmap.Format.RGBA8888, 5, true, new PixmapPacker.GuillotineStrategy()); }
public RenderSystem(DecalBatch decalBatch, AssetManager assetManager, float worldDegree, Assets.LevelAssets assets) { super(Aspect.all(RenderComponent.class, PositionComponent.class)); this.levelAssets = assets; decalMap = new ObjectMap<>(); uiMap = new ObjectMap<>(); this.decalBatch = decalBatch; this.assetManager = assetManager; buffers = new ObjectMap<>(); this.spriteBatch = new SpriteBatch(); this.font = assets.uifont; font.setColor(Color.BLACK); this.uiCamera = new OrthographicCamera(); Viewport viewportUi = new FitViewport(levelAssets.health_bar_gradient.getWidth(), levelAssets.health_bar_gradient.getHeight(), uiCamera); viewportUi.update(viewportUi.getScreenWidth(), viewportUi.getScreenHeight(), true); stateTime = 0; this.worldDegree = worldDegree; gradientShader = new ShaderProgram(Shaders.GradientShader.vertexShader, Shaders.GradientShader.fragmentShader); if (gradientShader.isCompiled() == false) throw new IllegalArgumentException("couldn't compile shader: " + gradientShader.getLog()); shaderBatch = new SpriteBatch(10, gradientShader); }
public GameState(String name, String tmx, StateManager manager) { this.tmx = tmx; setManager(manager); if(name!=null) this.name = name; else this.name = ""; sprites = new ObjectMap<String, Sprite>(); animations = new ObjectMap<String, Animation<String>>(); fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats particle_effects = new ObjectMap<String, ParticleEffectPool>(); pvalues = new Array<String>(); time_scale = 1f; shaders = new ObjectMap<String, ShaderProgram>(); svalues = new Array<String>(); }
public TiledObjectTypes(String file) { xml_reader = new XmlReader(); try { root = xml_reader.parse(Gdx.files.internal(file)); } catch (IOException e) { e.printStackTrace(); } types = new ObjectMap<String, TiledObjectTypes.TiledObjectType>(); if(root == null) throw new GdxRuntimeException(String.format("Unable to parse file %s. make sure it is the correct path.", file)); Array<Element> types = root.getChildrenByName("objecttype"); for (Element element : types) { TiledObjectType tot = new TiledObjectType(element.get("name")); Array<Element> properties = element.getChildrenByName("property"); for (int i = 0; i < properties.size; i++) { Element element2 = properties.get(i); TypeProperty property = new TypeProperty(element2.get("name"), element2.get("type"), element2.hasAttribute("default")?element2.get("default"):""); tot.addProperty(property); } this.types.put(tot.name, tot); } }
private void addScrollPanel(Table table, Element element) { Table tableScroll = new Table(skin); ScrollPane scrollPane = new ScrollPane(tableScroll, skin); Cell<ScrollPane> cell = table.add(scrollPane); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { tableScroll.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); addChildrens(element, tableScroll); actorsMap.put(tableScroll.getName(), tableScroll); }
private void recalculateFormation(ObjectMap<Integer, Tile> formationToRecalculate, int rotationDegrees) { for (Integer i : formation.keys()) { Tile formationPosition = formationToRecalculate.get(i); if (formationPosition == null) { formationPosition = new Tile(); formationToRecalculate.put(i, formationPosition); } formationPosition.set(formation.get(i)); // we only rotate in multiplies of 45 // first we do as many 90 degrees rotations as needed // and then do the final 45 rotation if required int rotAmount = rotationDegrees / 90; for (int j = 0; j < rotAmount; ++j) { formationPosition.rotate90CW(); } if (rotationDegrees % 90 == 45) { rotateTile45CW(formationPosition); } } }
private void addList(Table table, Element element) { Gdx.app.log("JXmlUi", "addList"); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) atrributes = new ObjectMap<String, String>(); List<String> list = new List<String>(skin); list.getSelection().setMultiple(false); ScrollPane scrollPane = new ScrollPane(list, skin); Cell<ScrollPane> cell = table.add(scrollPane); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { list.setName(atrributes.get(key)); scrollPane.setName(atrributes.get(key) + "-scroll-panel"); } } cellPrepare(cell, atrributes); actorsMap.put(list.getName(), list); actorsMap.put(scrollPane.getName(), scrollPane); addElementsInList(element, list); }
public String getText(ObjectMap<String, String> parameters) { if (parameters == null) { parameters = new ObjectMap<String, String>(); } if (dialogue.getPCAtDialogue() != null) { parameters.put(SPECIAL_PCNAME, dialogue.getPCAtDialogue().getName()); parameters.put(SPECIAL_PC_PRONOUN, dialogue.getPCAtDialogue().stats().getGender().getPronoun().toLowerCase(Locale.ENGLISH)); parameters.put(SPECIAL_PC_POSSESIVE_PRONOUN, dialogue.getPCAtDialogue().stats().getGender().getPossesivePronoun().toLowerCase(Locale.ENGLISH)); parameters.put(SPECIAL_PC_OBJECT_PRONOUN, dialogue.getPCAtDialogue().stats().getGender().getObjectPronoun().toLowerCase(Locale.ENGLISH)); } if (dialogue.getNPCAtDialogue() != null) { parameters.put(SPECIAL_NPCNAME, dialogue.getNPCAtDialogue().getName()); parameters.put(SPECIAL_NPC_PRONOUN, dialogue.getNPCAtDialogue().stats().getGender().getPronoun().toLowerCase(Locale.ENGLISH)); parameters.put(SPECIAL_NPC_POSSESIVE_PRONOUN, dialogue.getNPCAtDialogue().stats().getGender().getPossesivePronoun().toLowerCase(Locale.ENGLISH)); parameters.put(SPECIAL_NPC_OBJECT_PRONOUN, dialogue.getNPCAtDialogue().stats().getGender().getObjectPronoun().toLowerCase(Locale.ENGLISH)); } String returnValue = StringUtil.replaceParameters(Strings.getString(text), parameters); returnValue = StringUtil.replaceCharacterNames(returnValue); return returnValue; }
private static void setOverallVolume(float volume) { overallVolume = Math.max(volume, 0); overallVolume = Math.min(volume, 1); if(curSong != null) curSong.setVolume(overallVolume * musicVolume); ObjectMap.Entries<String, SoundEffect> s = sounds.entries(); while(s.hasNext) { s.next().value.sVolume(overallVolume * effectsVolume); } }
public static void endGame() { //Stop the music if(curSong != null) { curSong.stop(); curSong.dispose(); } //Dispose of all Sound Effects ObjectMap.Entries<String, SoundEffect> s = sounds.entries(); while(s.hasNext) { SoundEffect se = s.next().value; se.stop(); se.dispose(); } screams = new Array<String>(); }
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, ThesaurusLoader.ThesaurusParameter parameter) { Constructor constructor = new Constructor(ThesaurusData.class); Yaml yaml = new Yaml(constructor); ObjectMap<String, ThesaurusData> data = new ObjectMap<String, ThesaurusData>(); for (Object o : yaml.loadAll(resolve(fileName).read())) { ThesaurusData description = (ThesaurusData) o; data.put(description.key, description); } if (parameter != null && parameter.other.length > 0) { for (String depName : parameter.other) { Thesaurus dep = manager.get(depName); data.putAll(dep.data); } } thesaurus = new Thesaurus(data); }
public WorldRoom(Tilemap map) { this.destroyed = false; this.prepared = false; this.events = new EventHelper(this); this.bodyQueue = new ObjectSet<>(); this.entrypointQueue = new ObjectSet<>(); this.tilemap = map; this.controller = null; this.obj = new ObjectSet<>(); this.entrypoints = new ObjectMap<>(); this.opacityMapping = new IntFloatMap(); this.collisionLayers = new ObjectMap<>(); this.renderOrder = new Array<>(true, 16); this.disabledCollision = new ObjectSet<>(); }
/** * Loads {@link TextStyle} Lua implementations found * within the given root directory and its subfolders * into this {@link TextStyleManager}. * * @param rootDirectory the root directory to search in */ public void loadStyles(File rootDirectory) { ObjectMap<String, File> files = FileUtil.loadWithIdentifiers(rootDirectory, file -> { return file.getName().endsWith(".lua"); }); files.keys().forEach(key -> { File scriptFile = files.get(key); try { this.styles.put(key, new LuaTextStyle(scripts, scriptFile, key)); } catch (Exception e) { String message = "Could not load style at script file " + scriptFile.getAbsolutePath(); if(e instanceof FileNotFoundException) message += " (file not found)"; if(e instanceof LuaScriptException) message += " (implementation error)"; log.error(message, e); } }); log.info(this.styles.size + " style(s) loaded."); }
public AnimationMap(AnimationMap<T> toCopy) { this.animationInfoMap = new ObjectMap<Integer, Array<AnimationDescription>>(); for (Entry<Integer, Array<AnimationDescription>> entry : toCopy.animationInfoMap.entries()) { Array<AnimationDescription> descriptions = new Array<AnimationDescription>(); animationInfoMap.put(entry.key, descriptions); for (AnimationDescription description : entry.value) { descriptions.add(description); } } frameWidth = toCopy.frameWidth; frameHeight = toCopy.frameHeight; frameDuration = toCopy.frameDuration; animationTexturePath = toCopy.animationTexturePath; middleOffsets = new ObjectMap<T, Vector2>(toCopy.middleOffsets); middleOffset = toCopy.middleOffset; objectWidth = toCopy.objectWidth; objectHeight = toCopy.objectHeight; }
/** * This will spread information about crimes known to fromFaction but * unknown to toFaction from the one to the other. * * @param fromFaction * @param toFaction */ public void spreadCrimeInfo(Faction fromFaction, Faction toFaction) { Array<Crime<?>> crimesKnownToFromFaction = trackedCrimes.get(fromFaction); if (crimesKnownToFromFaction == null) { return; } ObjectMap<Faction, Integer> penalties = new ObjectMap<Faction, Integer>(); for (Crime<?> crime : crimesKnownToFromFaction) { if (addCrime(crime, toFaction)) { Faction perpFaction = crime.getPerpetrator().getFaction(); int penalty = crime.getDispositionPenalty()/2; if (penalties.containsKey(perpFaction)) { penalties.put(perpFaction, penalties.get(perpFaction)+penalty); } else { penalties.put(perpFaction, penalty); } } } for (Entry<Faction, Integer> entry : penalties.entries()) { toFaction.modifyDisposition(entry.key, -entry.value); } }
private void initMatch(PvpPlayState state) { Logger.debug("server: init match "+this.state.session.getMode().name); PvpMode mode = this.state.session.getMode(); LevelDescription level = mode.levels.random(); String levelName = level.name; Array<Fraction> fractions = new Array<Fraction>(level.fractions.size); for (Fraction fraction : level.fractions) { fractions.add(fraction); } Array<String> ids = this.state.session.getAll().keys().toArray(); ids.shuffle(); ObjectMap<String, String> fMap = new ObjectMap<String, String>(); for (int i = 0; i < ids.size; i++) { fMap.put(ids.get(i), fractions.get(i).name); } int seed = MathUtils.random.nextInt(); awaitSpawning(state); sendToAll(new Init(levelName, fMap, seed)); }
@Override public void loadFromXML(Element root) throws IOException { ObjectMap<String, Crime<?>> savedCrimes = new ObjectMap<String, Crime<?>>(); Element crimesElement = root.getChildByName(XML_CRIMES); for (int i = 0; i < crimesElement.getChildCount(); ++i) { Crime<?> crime = Crime.readCrime(crimesElement.getChild(i)); savedCrimes.put(crime.getId(), crime); } Element factionsElement = root.getChildByName(XML_FACTIONS); for (int i = 0; i < factionsElement.getChildCount(); ++i) { Element factionElement = factionsElement.getChild(i); Faction faction = Faction.getFaction(factionElement.getName()); for (int j = 0; j < factionElement.getChildCount(); ++j) { addCrime(savedCrimes.get(factionElement.getChild(j).getText()), faction); } } }
/** * Loads spritesheets found within the given root * directory and its subfolders into this * {@link SpriteSheetManager}. * * @param rootDirectory the root directory to search in */ public void loadSpriteSheets(File rootDirectory) { log.info("Loading spritesheet assets from directory " + rootDirectory.getAbsolutePath()); ObjectMap<String, File> files = FileUtil.loadWithIdentifiers(rootDirectory, file -> { return file.getName().endsWith(".spritesheet"); }); for (String key : files.keys()) { File targetFile = files.get(key); try { this.sheets.put(key, new PackagedSpriteSheetFactory(key, renderer, new ZipFile(targetFile))); log.info( "Loaded packaged spritesheet " + targetFile.getName() + " under key " + key); } catch (Exception e) { String message = "Could not load spritesheet at spritesheet file " + targetFile.getAbsolutePath(); if (e instanceof ZipException) message += " (bad spritesheet file/format)"; log.error(message, e); } } log.info(this.sheets.size + " spritesheet(s) loaded."); }
/** * Gets the effects of this Perk as a human * readable string. * * This does not include any modifiers * associated with this Perk. * * @return null if there are no associated effects, the string otherwise */ public static String getEffectsAsString(EffectContainer ec, Object user) { ObjectMap<Effect, Array<EffectParameter>> effects = ec.getEffects(); if (effects.size == 0) { return null; } StringBuilder fsb = StringUtil.getFSB(); int i = 0; for (Effect effect : effects.keys()) { String desc = effect.getDescription(user, effects.get(effect)); if (desc == null) { continue; } if (i > 0) { fsb.append("\n"); } fsb.append(desc); ++i; } String returnValue = fsb.toString(); StringUtil.freeFSB(fsb); return returnValue; }
public String getText(ObjectMap<String, String> parameters) { String text = null; if (getDialogue().getPCAtDialogue() != null) { text = roleSpecificTexts.get(getDialogue().getPCAtDialogue().getRole().getId()); } if (text == null) { text = roleSpecificTexts.get(ROLE_DEFAULT); } if (text == null) { text = ""; } super.setText(text); return super.getText(parameters); }
public AudioManager(Undertailor undertailor) { if (!AudioManager.audioReplaced) { log.info("Manager will now try to replace the audio system."); if (!LwjglApplicationConfiguration.disableAudio) { try { ((com.badlogic.gdx.backends.lwjgl.audio.OpenALAudio) Gdx.audio).dispose(); LwjglApplicationConfiguration config = undertailor.getApplicationConfiguration(); Gdx.audio = new OpenALAudio(config.audioDeviceSimultaneousSources, config.audioDeviceBufferCount, config.audioDeviceBufferSize); AudioManager.audioReplaced = true; log.info("Success."); } catch (Throwable t) { log.error("Failed.", t); } } } this.masterVolume = new BoundedFloat(0.0F, 1.0F, 1.0F); this.musicVolume = new BoundedFloat(0.0F, 1.0F, 1.0F); this.soundVolume = new BoundedFloat(0.0F, 1.0F, 1.0F); this.sounds = new ObjectMap<>(); this.music = new ObjectMap<>(); }
public void loadProfile(String profile) { final String fileName = profile + SAVE_GAME_SUFFIX; if (!Gdx.files.internal(fileName).exists()) { Gdx.app.debug(TAG, "Trying to load non-existing profile: " + profile); return; } currentProfileName = profile; Gdx.app.debug(TAG, "Loading profile " + currentProfileName + " ..."); ObjectMap<?, ?> loadedProperties = Utils.fromJson(ObjectMap.class, profiles.get(currentProfileName)); profileProperties.clear(); for (Entry<?, ?> entry : loadedProperties.entries()) { profileProperties.put((String) entry.key, entry.value); } fireLoad(this); Gdx.app.debug(TAG, "Loading profile successful!"); }
@SuppressWarnings("unchecked") public void reload () { RavTech.files.loadAsset("keybindings.json", String.class); RavTech.files.finishLoading(); if ((!RavTech.settings.has("keybindings"))) RavTech.settings.setValue("keybindings", RavTech.files.getAsset("keybindings.json", String.class)); this.actionMaps.clear(); Json json = new Json(); ObjectMap<String, JsonValue> serializedActionMaps = json.fromJson(ObjectMap.class, RavTech.settings.getString("keybindings")); for (ObjectMap.Entry<String, JsonValue> entry : serializedActionMaps.entries()) { ActionMap actionMap = new ActionMap(); actionMap.read(json, entry.value); this.actionMaps.put(entry.key, actionMap); } this.actionMaps.putAll(actionMaps); this.players.clear(); Player player = new Player(); for (int i = 0; i < inputDevices.size; i++) player.assignDevice(inputDevices.get(i), this.getActionMapForDevice(inputDevices.get(i))); players.add(player); }
@Override protected void init(final PvpPlayState state) { Logger.debug("client: wait for server to init"); register(Init.class, new IMessageProcessor<Init>() { @Override public void receive(IParticipant from, Init message) { if (message.version > Config.mobileApi.getVersionCode()) { sendToWithCallback(state.server, new UpdateNeeded()).addListener(new IFutureListener<Boolean>() { @Override public void onHappened(Boolean aBoolean) { session.disconnect(false, Config.thesaurus.localize("disconnect-server-needs-update")); } }); return; } else if (message.version < Config.mobileApi.getVersionCode()) { session.disconnect(false, Config.thesaurus.localize("disconnect-update-needed")); return; } LevelDescription level = (LevelDescription) Config.levels.get(message.level); ObjectMap<IParticipant, Fraction> fractions = new ObjectMap<IParticipant, Fraction>(); for (ObjectMap.Entry<String, String> e : message.fractions.entries()) { fractions.put(ClientMessageListener.this.state.session.getAll().get(e.key), Fraction.valueOf(e.value)); } ClientMessageListener.this.state.prepare(level, fractions, message.seed); unregister(Init.class); awaitSpawns(state); } }); }
private void load(TextureAtlasData data) { ObjectMap<TextureAtlasData.Page, Texture> pageToTexture = new ObjectMap<TextureAtlasData.Page, Texture>(); for (TextureAtlasData.Page page : data.getPages()) { Texture texture = TextureDecryptor.loadTexture(crypto, page.textureFile, page.format, page.useMipMaps); texture.setFilter(page.minFilter, page.magFilter); texture.setWrap(page.uWrap, page.vWrap); getTextures().add(texture); pageToTexture.put(page, texture); } // Same as libGDX source for (TextureAtlasData.Region region : data.getRegions()) { int width = region.width; int height = region.height; AtlasRegion atlasRegion = new AtlasRegion(pageToTexture.get(region.page), region.left, region.top, region.rotate ? height : width, region.rotate ? width : height); atlasRegion.index = region.index; atlasRegion.name = region.name; atlasRegion.offsetX = region.offsetX; atlasRegion.offsetY = region.offsetY; atlasRegion.originalHeight = region.originalHeight; atlasRegion.originalWidth = region.originalWidth; atlasRegion.rotate = region.rotate; atlasRegion.splits = region.splits; atlasRegion.pads = region.pads; if (region.flip) atlasRegion.flip(false, true); getRegions().add(atlasRegion); } }
/** Registers a set of variables and their respective replacement values to this label. */ public void setVariables (ObjectMap<String, String> variableMap) { this.variables.clear(); for (Entry<String, String> entry : variableMap.entries()) { this.variables.put(entry.key.toUpperCase(), entry.value); } }
public void write (Kryo kryo, Output output, T map) { int length = map.size; output.writeVarInt(length, true); output.writeBoolean(false); // whether type is written (in case future version of ObjectMap supports type awareness) Serializer keySerializer = null; if (keyGenericType != null) { if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType); keyGenericType = null; } Serializer valueSerializer = null; if (valueGenericType != null) { if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType); valueGenericType = null; } for (Iterator iter = map.iterator(); iter.hasNext();) { ObjectMap.Entry entry = (ObjectMap.Entry)iter.next(); if (keySerializer != null) { kryo.writeObject(output, entry.key, keySerializer); } else kryo.writeClassAndObject(output, entry.key); if (valueSerializer != null) { kryo.writeObjectOrNull(output, entry.value, valueSerializer); } else kryo.writeClassAndObject(output, entry.value); } }
public void write (Kryo kryo, Output output, ArrayMap map) { output.writeBoolean(map.ordered); int length = map.size; output.writeVarInt(length, true); kryo.writeClass(output, map.keys.getClass().getComponentType()); kryo.writeClass(output, map.values.getClass().getComponentType()); Serializer keySerializer = null; if (keyGenericType != null) { if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType); keyGenericType = null; } Serializer valueSerializer = null; if (valueGenericType != null) { if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType); valueGenericType = null; } for (Iterator iter = map.iterator(); iter.hasNext();) { ObjectMap.Entry entry = (ObjectMap.Entry)iter.next(); if (keySerializer != null) { kryo.writeObject(output, entry.key, keySerializer); } else kryo.writeClassAndObject(output, entry.key); if (valueSerializer != null) { kryo.writeObjectOrNull(output, entry.value, valueSerializer); } else kryo.writeClassAndObject(output, entry.value); } }
/** Reads an object using the registered serializer, but does not return it. If the object type is a {@link Disposable}, * uses native memory, or is time consuming to instantiate, it should use an implementation of {@link SkippableSerializer} * to avoid memory leaks or wasted instantiation time. */ public static <T> void skipObsoleteObject (Kryo kryo, Input input, Class<T> type){ com.esotericsoftware.kryo.util.ObjectMap graphContext = kryo.getGraphContext(); final int branchDepth = graphContext.containsKey(OBSOLETE_BRANCH_KEY) ? (Integer)graphContext.get(OBSOLETE_BRANCH_KEY) : 0; graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth + 1); kryo.readObject(input, type); graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth); }
/** Reads an object using the specified serializer, but does not return it. If the object type is a {@link Disposable}, * uses native memory, or is time consuming to instantiate, it should use an implementation of {@link SkippableSerializer} * to avoid memory leaks or wasted instantiation time. */ public static <T> void skipObsoleteObject (Kryo kryo, Input input, Class<T> type, Serializer serializer){ com.esotericsoftware.kryo.util.ObjectMap graphContext = kryo.getGraphContext(); final int branchDepth = graphContext.containsKey(OBSOLETE_BRANCH_KEY) ? (Integer)graphContext.get(OBSOLETE_BRANCH_KEY) : 0; graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth + 1); kryo.readObject(input, type, serializer); graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth); }
/** Reads an object or null using the registered serializer, but does not return it. If the object type is a {@link Disposable}, * uses native memory, or is time consuming to instantiate, it should use an implementation of {@link SkippableSerializer} * to avoid memory leaks or wasted instantiation time. */ public static <T> void skipObsoleteObjectOrNull (Kryo kryo, Input input, Class<T> type){ com.esotericsoftware.kryo.util.ObjectMap graphContext = kryo.getGraphContext(); final int branchDepth = graphContext.containsKey(OBSOLETE_BRANCH_KEY) ? (Integer)graphContext.get(OBSOLETE_BRANCH_KEY) : 0; graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth + 1); kryo.readObjectOrNull(input, type); graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth); }
/** Reads an object or null using the specified serializer, but does not return it. If the object type is a {@link Disposable}, * uses native memory, or is time consuming to instantiate, it should use an implementation of {@link SkippableSerializer} * to avoid memory leaks or wasted instantiation time. */ public static <T> void skipObsoleteObjectOrNull (Kryo kryo, Input input, Class<T> type, Serializer serializer){ com.esotericsoftware.kryo.util.ObjectMap graphContext = kryo.getGraphContext(); final int branchDepth = graphContext.containsKey(OBSOLETE_BRANCH_KEY) ? (Integer)graphContext.get(OBSOLETE_BRANCH_KEY) : 0; graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth + 1); kryo.readObjectOrNull(input, type, serializer); graphContext.put(OBSOLETE_BRANCH_KEY, branchDepth); }
/** * @return Whether the data being read is currently in an obsolete branch of the object graph, as marked by * {@link #skipObsoleteObject(Kryo, Input, Class)} or similar. */ public static boolean isInObsoleteBranch (Kryo kryo){ com.esotericsoftware.kryo.util.ObjectMap graphContext = kryo.getGraphContext(); if (graphContext.containsKey(OBSOLETE_BRANCH_KEY)) return (Integer)graphContext.get(OBSOLETE_BRANCH_KEY) > 0; return false; }
public BatchableSorter (Camera camera, int opaqueIntialTextureCapacity, int opaqueInitialCapacityPerTexture, int blendedInitialCapacity) { this.cameraPosition = camera.position; this.opaqueInitialCapacityPerTexture = opaqueInitialCapacityPerTexture; opaqueBatchables = new ObjectMap<T, ObjectSet<T>>(); for (int i = 0; i < opaqueIntialTextureCapacity; i++) { // seed the pool to avoid delay on first use objectSetPool.free(objectSetPool.obtain()); } blendedBatchables = new Array<T>(blendedInitialCapacity); comparator = new Comparator<T>() { public int compare (T o1, T o2) { return (int)Math.signum(o2.calculateDistanceSquared(cameraPosition) - o1.calculateDistanceSquared(cameraPosition)); } }; }
@Override public synchronized boolean update () { boolean done = super.update(); if (done) { // assign references to Asset fields of queuedContainers for (Object assetContainer : queuedContainers) { ObjectMap<Field, AssetDescriptor<?>> fieldsToAssets = containersFieldsToAssets.get(assetContainer); for (ObjectMap.Entry<Field, AssetDescriptor<?>> fieldEntry : fieldsToAssets) { Field field = fieldEntry.key; makeAccessible(field); try { field.set(assetContainer, get(fieldEntry.value)); } catch (ReflectionException e) { throw new GdxRuntimeException("Failed to assign loaded asset " + field.getName(), e); } } ObjectMap<Object[], AssetDescriptor<?>[]> fieldsToAssetArrays = containersFieldsToAssetArrays.get(assetContainer); for (ObjectMap.Entry<Object[], AssetDescriptor<?>[]> arrayEntry : fieldsToAssetArrays) { Object[] destinationArray = arrayEntry.key; AssetDescriptor<?>[] descriptors = arrayEntry.value; for (int i = 0; i < descriptors.length; i++) { destinationArray[i] = get(descriptors[i]); } } if (assetContainer instanceof AssetContainer) ((AssetContainer) assetContainer).onAssetsLoaded(); } loadedContainers.addAll(queuedContainers); queuedContainers.clear(); } return done; }
public Properties toProperties() { Properties properties = new Properties(); for (ObjectMap.Entries<String, Object> iter = arguments.entries(); iter.hasNext(); ) { ObjectMap.Entry<String, Object> entr = iter.next(); properties.put(entr.key, entr.value); } return properties; }
public StatusEffect(float effectTime, float remainingTime, ObjectMap<StatComponent.BaseStat, Float> flatStats, ObjectMap<StatComponent.BaseStat, Float> percentageStats, ObjectMap<StatComponent.BaseStat, Float> percentageBaseStats, TickHandler tickHandler) { this.effectTime = effectTime; this.remainingTime = remainingTime; this.flatStats = flatStats; this.percentageStats = percentageStats; this.percentageBaseStats = percentageBaseStats; this.tickHandler = tickHandler; }
@Override public void applyPercentage(StatComponent stats) { for (ObjectMap.Entry<StatComponent.BaseStat, Float> percentageChange : percentageStats.entries()) { float value = stats.getCurrentStat(percentageChange.key); stats.setCurrentStat(percentageChange.key, value + value * percentageChange.value); } }