com.badlogic.gdx.utils.IntArray Java Examples

The following examples show how to use com.badlogic.gdx.utils.IntArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private static IntArray readFaces (BufferedReader in) throws NumberFormatException, IOException {
	int numFaces = readInt(in);
	IntArray faceIndices = new IntArray();
	IntArray triangles = new IntArray();
	IntArray indices = new IntArray();

	for (int face = 0; face < numFaces; face++) {
		readIntArray(in, faceIndices);
		int numIndices = faceIndices.get(0);
		triangles.clear();
		int baseIndex = faceIndices.get(1);
		for (int i = 2; i < numIndices; i++) {
			triangles.add(baseIndex);
			triangles.add(faceIndices.items[i]);
			triangles.add(faceIndices.items[i + 1]);
		}
		indices.addAll(triangles);
	}

	indices.shrink();
	return indices;
}
 
Example #2
Source File: DialogTenPatch.java    From skin-composer with MIT License 6 votes vote down vote up
public int[] sanitizeStretchAreas(IntArray stretchAreas, boolean horizontal) {
    var max = horizontal ? tenPatchDrawable.getRegion().getRegionWidth() - 1 : tenPatchDrawable.getRegion().getRegionHeight() - 1;
    var stretches = new IntArray(stretchAreas);
    
    if (stretches.size == 0) {
        stretches.add(0);
        stretches.add(max);
    }
    
    for (int i = 0; i < stretches.size; i++) {
        var value = stretches.get(i);
        if (value < 0) {
            stretches.set(i, 0);
        } else if (value > max) {
            stretches.set(i, max);
        }
    }
    
    stretches.sort();
    
    return stretches.toArray();
}
 
Example #3
Source File: DialogTenPatch.java    From skin-composer with MIT License 6 votes vote down vote up
public void set(TenPatchData other) {
    horizontalStretchAreas = new IntArray(other.horizontalStretchAreas);
    verticalStretchAreas = new IntArray(other.verticalStretchAreas);
    contentLeft = other.contentLeft;
    contentRight = other.contentRight;
    contentTop = other.contentTop;
    contentBottom = other.contentBottom;
    tile = other.tile;
    colorName = other.colorName;
    color1Name = other.color1Name;
    color2Name = other.color2Name;
    color3Name = other.color3Name;
    color4Name = other.color4Name;
    offsetX = other.offsetX;
    offsetY = other.offsetY;
    offsetXspeed = other.offsetXspeed;
    offsetYspeed = other.offsetYspeed;
    frameDuration = other.frameDuration;
    regionNames = new Array<>(other.regionNames);
    regions = other.regions == null ? null : new Array<>(other.regions);
    playMode = other.playMode;
}
 
Example #4
Source File: PatternModifier.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 変更対象のレーン番号が格納された配列を返す
 * @param mode
 * プレイモード
 * @param containsScratch
 * スクラッチレーンを含むか
 * @return レーン番号の配列
 */
protected int[] getKeys(Mode mode, boolean containsScratch) {
	int key = (modifyTargetSide == SIDE_2P)
			? mode.key / mode.player
			: 0;
	if (key == mode.key) {
		return new int[0];
	} else {
		IntArray keys = new IntArray();
		for (int i = 0; i < mode.key / mode.player; i++) {
			if (containsScratch || !mode.isScratchKey(key + i)) {
				keys.add(key + i);
			}
		}
		return keys.toArray();
	}
}
 
Example #5
Source File: CenteredTableBuilder.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void fillTable (final Table table) {
	final IntArray rowSizes = getRowSizes();
	final int widgetsInRow = getLowestCommonMultiple(rowSizes);

	for (int rowIndex = 0, widgetIndex = 0; rowIndex < rowSizes.size; rowIndex++) {
		final int rowSize = rowSizes.get(rowIndex);
		final int currentWidgetColspan = widgetsInRow / rowSize;
		boolean isFirst = shouldExpand(rowSize);

		for (final int totalWidgetsBeforeRowEnd = widgetIndex + rowSize; widgetIndex < totalWidgetsBeforeRowEnd; widgetIndex++) {
			final Cell<?> cell =
					getWidget(widgetIndex).buildCell(table, getDefaultWidgetPadding()).colspan(
							currentWidgetColspan);
			// Keeping widgets together - expanding X for first and last widget, setting alignments:
			if (isFirst) {
				isFirst = false;
				cell.expandX().right();
			} else if (isLast(widgetIndex, rowSize, totalWidgetsBeforeRowEnd)) {
				cell.expandX().left();
			}
		}
		table.row();
	}
}
 
Example #6
Source File: RepeatOperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void repeated_operations_are_recycled() {
	IntArray instances = new IntArray();

	World world = new World(
		new WorldConfiguration()
			.register("instances", instances)
			.setSystem(OperationSystem.class));

	repeat(100,
		operation(SelfTrackingOperation.class)
	).register(world, world.create());

	process(world);
	assertEquals(2, instances.size);

	process(world); // just making sure nothing new happens
	assertEquals(2, instances.size);

	assertTrue(instances.contains(
		System.identityHashCode(operation(SelfTrackingOperation.class))));
}
 
Example #7
Source File: SchedulerBase.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Creates a {@code SchedulerBase}.
 * @param dryRunFrames number of frames simulated by the dry run to calculate the phase when adding a schedulable via
 *           {@link #addWithAutomaticPhasing(Schedulable, int)} */
public SchedulerBase (int dryRunFrames) {
	this.schedulableRecords = new Array<T>();
	this.runList = new Array<T>();
	this.phaseCounters = new IntArray();
	this.dryRunFrames = dryRunFrames;
}
 
Example #8
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private int addToTree (Tree displayTree, TaskNode parentNode, Task<E> task, IntArray taskSteps, int taskStepIndex) {
	TaskNode node = new TaskNode(task, this, taskSteps == null ? step - 1 : taskSteps.get(taskStepIndex), getSkin());
	taskNodes.put(task, node);
	if (parentNode == null) {
		displayTree.add(node);
	} else {
		parentNode.add(node);
	}
	taskStepIndex++;
	for (int i = 0; i < task.getChildCount(); i++) {
		Task<E> child = task.getChild(i);
		taskStepIndex = addToTree(displayTree, node, child, taskSteps, taskStepIndex);
	}
	return taskStepIndex;
}
 
Example #9
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void rebuildDisplayTree (IntArray taskSteps) {
	displayTree.clear();
	taskNodes.clear();
	Task<E> root = tree.getChild(0);
	addToTree(displayTree, null, root, taskSteps, 0);
	displayTree.expandAll();
}
 
Example #10
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
public void save () {
	Array<BehaviorTree.Listener<E>> listeners = tree.listeners;
	tree.listeners = null;

	IntArray taskSteps = new IntArray();
	fill(taskSteps, (TaskNode)displayTree.getNodes().get(0));
	KryoUtils.save(new SaveObject<E>(tree, step, taskSteps));

	tree.listeners = listeners;
}
 
Example #11
Source File: CaveGenerator.java    From Cubes with MIT License 5 votes vote down vote up
public Cave generate() {
  int spawnDist = (int) distanceFromSpawn(caveStartX, caveStartZ);
  //Log.debug("Generating new cave at " + caveStartX + "," + caveStartZ + " (" + spawnDist + " blocks from spawn)");
  generateNodes();
  calculateBlocks();

  Cave cave = new Cave(caveStartX, caveStartY, caveStartZ, new HashMap<AreaReference, int[]>() {{
    for (Map.Entry<AreaReference, IntArray> entry : blocks.entrySet()) {
      this.put(entry.getKey(), entry.getValue().toArray());
    }
  }});

  return cave;
}
 
Example #12
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected void initialize () {
	super.initialize();
	writeEnters = true;
	linesBreak = new IntArray();
	cursorLine = 0;
	firstLineShowing = 0;
	moveOffset = -1;
	linesShowing = 0;
}
 
Example #13
Source File: TableBuilder.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * @param values cannot be empty or null.
 * @return lowest common multiple for the given values.
 */
public static int getLowestCommonMultiple (final IntArray values) {
	int lowestCommonMultiple = values.first();
	for (int index = 1; index < values.size; index++) {
		lowestCommonMultiple = getLowestCommonMultiple(lowestCommonMultiple, values.get(index));
	}
	return lowestCommonMultiple;
}
 
Example #14
Source File: TableBuilder.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/** @param defaultWidgetPadding will be applied to all added widgets if no specific padding is given. */
public TableBuilder (final int estimatedWidgetsAmount, final int estimatedRowsAmount,
					 final Padding defaultWidgetPadding) {
	widgets = new Array<CellWidget<? extends Actor>>(estimatedWidgetsAmount);
	rowSizes = new IntArray(estimatedRowsAmount);
	widgetPadding = defaultWidgetPadding;
}
 
Example #15
Source File: StandardTableBuilder.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected void fillTable (final Table table) {
	final IntArray rowSizes = getRowSizes();
	final int widgetsInRow = getLowestCommonMultiple(rowSizes);
	for (int rowIndex = 0, widgetIndex = 0; rowIndex < rowSizes.size; rowIndex++) {
		final int rowSize = rowSizes.get(rowIndex);
		final int currentWidgetColspan = widgetsInRow / rowSize;
		for (final int totalWidgets = widgetIndex + rowSize; widgetIndex < totalWidgets; widgetIndex++) {
			getWidget(widgetIndex).buildCell(table, getDefaultWidgetPadding()).colspan(
					currentWidgetColspan);
		}
		table.row();
	}
}
 
Example #16
Source File: ItemData.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public Array<Item> toItemArray(IntArray items) {
  Array<Item> copy = new Array<>(false, items.size, Item.class);
  int[] cache = items.items;
  for (int i = 0, s = items.size, j; i < s; i++) {
    j = cache[i];
    copy.add(itemData.get(j));
  }
  return copy;
}
 
Example #17
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private static short[] convertToShortArray (IntArray array) {
	short[] shortArray = new short[array.size];
	for (int i = 0; i < array.size; i++) {
		shortArray[i] = (short)array.items[i];
	}
	return shortArray;
}
 
Example #18
Source File: ItemData.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public IntArray getLocation(Location location, StoreLoc storeLoc) {
  Item[] items = itemData.items;
  IntArray copy = new IntArray(items.length);
  for (int i = 0, s = itemData.size; i < s; i++) {
    Item item = items[i];
    if (item.location != location) continue;
    if (location == Location.STORED && item.storeLoc != storeLoc) continue;
    copy.add(i);
  }

  return copy;
}
 
Example #19
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private static void readIntArray (BufferedReader in, IntArray array) throws IOException {
	String[] tokens = read(in).split(",");
	int len = tokens.length;
	array.clear();
	for (int i = 0; i < len; i++) {
		array.add(Integer.parseInt(tokens[i].trim()));
	}
}
 
Example #20
Source File: DieNet.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void highlightMove(Ability ability) {
    IntArray available = new IntArray();
    for (int i = 0; i < die.abilities.size; i++) {
        if (die.abilities.get(i) != ability) available.add(i);
    }
    highlight(available);
}
 
Example #21
Source File: DieNet.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void highlight(IntArray indices) {
    for (int i = 0; i < indices.size; i++) {
        Vector2 pos = iconPositions[indices.get(i)];
        Image image = new Image(Config.skin, "ui/dice-window/net-selection-selected");
        image.setPosition(pos.x - 2, pos.y - 2);
        addActor(image);
        image.toBack();
        image.getColor().a = 0f;
        blink(image);
        highlights.add(image);
    }
}
 
Example #22
Source File: Die.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public IntArray getAvailableIndices(Ability ability) {
    int availableSkill = getTotalSkill() - getUsedSkill();
    IntArray res = new IntArray();
    for (int i = 0; i < abilities.size; i++) {
        Ability check = abilities.get(i);
        if (check == ability)
            continue;
        boolean canBePlaced = check == null ? availableSkill >= ability.skill : availableSkill >= ability.skill - check.skill;
        if (canBePlaced) {
            res.add(i);
        }
    }
    return res;
}
 
Example #23
Source File: KeyBoardInputProcesseor.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public KeyBoardInputProcesseor(BMSPlayerInputProcessor bmsPlayerInputProcessor, KeyboardConfig config, Resolution resolution) {
	super(bmsPlayerInputProcessor, Type.KEYBOARD);
	this.setConfig(config);
	this.resolution = resolution;
	
	reserved = new IntArray();
	reserved.addAll(cover);
	reserved.addAll(function);
	reserved.addAll(numbers);
	reserved.addAll(exit);
	reserved.addAll(enter);
}
 
Example #24
Source File: LR2SkinCSVLoader.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
protected int[] readOffset(String[] str, int startIndex, int[] offset) {
	IntArray result = new IntArray();
	for(int i : offset) {
		result.add(i);
	}
	for (int i = startIndex; i < str.length; i++) {
		String s = str[i].replaceAll("[^0-9-]", "");
		if(s.length() > 0) {
			result.add(Integer.parseInt(s));
		}
	}
	return result.toArray();
}
 
Example #25
Source File: JamepadControllerMonitor.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
private void update() {
    IntArray disconnectedControllers = new IntArray(indexToController.size);
    for (Tuple tuple : indexToController.values()) {
        JamepadController controller = tuple.controller;
        boolean connected = controller.update();

        if (!connected) {
            disconnectedControllers.add(tuple.index.getIndex());
        }
    }

    for (int i = 0; i < disconnectedControllers.size; i++) {
        indexToController.remove(disconnectedControllers.get(i));
    }
}
 
Example #26
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private static StillSubMesh readStillSubMesh (BufferedReader in, boolean flipV) throws IOException {
	String name = readString(in);
	IntArray indices = readFaces(in);
	int numVertices = readInt(in);
	int numAttributes = readInt(in);

	if (!readString(in).equals("position")) throw new GdxRuntimeException("first attribute must be position.");
	int numUvs = 0;
	boolean hasNormals = false;
	for (int i = 1; i < numAttributes; i++) {
		String attributeType = readString(in);

		if (!attributeType.equals("normal") && !attributeType.equals("uv"))
			throw new GdxRuntimeException("attribute name must be normal or uv");

		if (attributeType.equals("normal")) {
			if (i != 1) throw new GdxRuntimeException("attribute normal must be second attribute");
			hasNormals = true;
		}
		if (attributeType.equals("uv")) {
			numUvs++;
		}
	}
	VertexAttribute[] vertexAttributes = createVertexAttributes(hasNormals, numUvs);
	int vertexSize = new VertexAttributes(vertexAttributes).vertexSize / 4;
	float[] vertices = new float[numVertices * vertexSize];
	int idx = 0;
	int uvOffset = hasNormals ? 6 : 3;
	for (int i = 0; i < numVertices; i++) {
		readFloatArray(in, vertices, idx);
		if (flipV) {
			for (int j = idx + uvOffset + 1; j < idx + uvOffset + numUvs * 2; j += 2) {
				vertices[j] = 1 - vertices[j];
			}
		}
		idx += vertexSize;
	}

	Mesh mesh = new Mesh(true, numVertices, indices.size, vertexAttributes);
	mesh.setVertices(vertices);
	mesh.setIndices(convertToShortArray(indices));
	return new StillSubMesh(name, mesh, GL20.GL_TRIANGLES);
}
 
Example #27
Source File: ItemData.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public IntArray getStore(StoreLoc storeLoc) {
  return getLocation(Location.STORED, storeLoc);
}
 
Example #28
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
SaveObject (BehaviorTree<T> tree, int step, IntArray taskSteps) {
	this.tree = tree;
	this.step = step;
	this.taskSteps = taskSteps;
}
 
Example #29
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
private void fill (IntArray taskSteps, TaskNode taskNode) {
	taskSteps.add(taskNode.step);
	for (Node child : taskNode.getChildren()) {
		fill(taskSteps, (TaskNode)child);
	}
}
 
Example #30
Source File: TableBuilder.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/** @return array with sizes of each row. */
protected IntArray getRowSizes () {
	return rowSizes;
}