Skip to content

Commit

Permalink
Merge branch 'master' into be
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Oct 2, 2024
2 parents 9130440 + 66ae776 commit 5ed3082
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion arc-core/src/arc/audio/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void load(Fi file){
public int play(float volume, float pitch, float pan, boolean loop, boolean checkFrame){
if(handle == 0 || (checkFrame && framePlayed == Core.graphics.getFrameId()) || bus == null || !Core.audio.initialized) return -1;
framePlayed = Core.graphics.getFrameId();
return sourcePlayBus(handle, bus.handle, volume, pitch * Core.audio.globalPitch, pan, loop);
return sourcePlayBus(handle, bus.handle, volume, Mathf.clamp(pitch * Core.audio.globalPitch, 0.0001f, 10f), Mathf.clamp(pan, -1f, 1f), loop);
}

/** Sets the bus that will be used for the next play of this SFX. */
Expand Down
2 changes: 1 addition & 1 deletion arc-core/src/arc/graphics/g2d/Lines.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public static void rect(Rect rect){
rect(rect.x, rect.y, rect.width, rect.height, 0);
}

public static void rect(float x, float y, float width, float height, int space){
public static void rect(float x, float y, float width, float height, float space){
rect(x, y, width, height, space, space);
}

Expand Down
2 changes: 1 addition & 1 deletion arc-core/src/arc/graphics/g2d/SpriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SpriteBatch extends Batch{
private static final float[] emptyVertices = new float[0];

static ForkJoinHolder commonPool;
boolean multithreaded = (Core.app.getVersion() >= 21 && !Core.app.isIOS()) || Core.app.isDesktop();
boolean multithreaded = Core.app != null && ((Core.app.getVersion() >= 21 && !Core.app.isIOS()) || Core.app.isDesktop());

protected Mesh mesh;
protected FloatBuffer buffer;
Expand Down
6 changes: 3 additions & 3 deletions arc-core/src/arc/math/geom/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static <T extends Position> T findClosest(float x, float y, T[] list){
T closest = null;
float cdist = 0f;
for(T t : list){
float dst = t.dst(x, y);
float dst = t.dst2(x, y);
if(closest == null || dst < cdist){
closest = t;
cdist = dst;
Expand All @@ -104,7 +104,7 @@ public static <T extends Position> T findClosest(float x, float y, Iterable<T> l
T closest = null;
float cdist = 0f;
for(T t : list){
float dst = t.dst(x, y);
float dst = t.dst2(x, y);
if(closest == null || dst < cdist){
closest = t;
cdist = dst;
Expand All @@ -117,7 +117,7 @@ public static <T extends Position> T findFurthest(float x, float y, Iterable<T>
T furthest = null;
float fdist = 0f;
for(T t : list){
float dst = t.dst(x, y);
float dst = t.dst2(x, y);
if(furthest == null || dst > fdist){
furthest = t;
fdist = dst;
Expand Down
7 changes: 4 additions & 3 deletions arc-core/src/arc/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ public void registerStyles(Class<?> type){

public void registerStyles(Object obj){
Seq.with(obj.getClass().getFields())
.each(f -> f.getName().startsWith("default"), f -> addStyle(f.getType(), Reflect.get(obj, f)));
.each(f -> f.getName().startsWith("default"), f -> addStyle(f.getType(), Reflect.get(obj, f)));
}

public @Nullable Element getHoverElement(){
return mouseOverElement;
//TODO: this is slow, use mouseOverElement instead?
return hit(Core.input.mouseX(), Core.input.mouseY(), true);
}

public boolean hasField(){
return getKeyboardFocus() instanceof TextField;
}

public boolean hasMouse(){
return mouseOverElement != null;
return getHoverElement() != null;
}

public boolean hasMouse(float mousex, float mousey){
Expand Down
22 changes: 11 additions & 11 deletions arc-core/src/arc/scene/ui/TextArea.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package arc.scene.ui;

import arc.Core;
import arc.struct.IntSeq;
import arc.graphics.g2d.Font;
import arc.graphics.g2d.GlyphLayout;
import arc.input.KeyCode;
import arc.scene.Scene;
import arc.scene.event.InputEvent;
import arc.scene.event.InputListener;
import arc.scene.style.Drawable;
import arc.util.Align;
import arc.util.pooling.Pools;
import arc.*;
import arc.graphics.g2d.*;
import arc.input.*;
import arc.math.*;
import arc.scene.*;
import arc.scene.event.*;
import arc.scene.style.*;
import arc.struct.*;
import arc.util.*;
import arc.util.pooling.*;

/** A multiple-line text input field, entirely based on {@link TextField} */
public class TextArea extends TextField{
Expand Down Expand Up @@ -364,6 +363,7 @@ protected void setCursorPosition(float x, float y){

cursorLine = (int)Math.floor((height - y) / font.getLineHeight()) + firstLineShowing;
cursorLine = Math.max(0, Math.min(cursorLine, getLines() - 1));
cursorLine = Mathf.clamp(cursorLine, firstLineShowing, firstLineShowing + linesShowing - 1);

super.setCursorPosition(x, y);
updateCurrentLine();
Expand Down
57 changes: 36 additions & 21 deletions extensions/packer/src/arc/packer/MaxRectsPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private Page packPage(Seq<Rect> inputRects){
throw new RuntimeException("Image does not fit with max page width " + settings.maxWidth + paddingMessage + ": "
+ rect.name + "[" + width + "," + height + "]");
}
if(height > maxHeight && (!settings.rotation || width > maxHeight)){
if(height > maxHeight){
String paddingMessage = edgePadY ? (" and Y edge padding " + paddingY + "*2") : "";
throw new RuntimeException("Image does not fit in max page height " + settings.maxHeight + paddingMessage + ": "
+ rect.name + "[" + width + "," + height + "]");
Expand Down Expand Up @@ -192,16 +192,16 @@ private Page packPage(Seq<Rect> inputRects){
*/
private Page packAtSize(boolean fully, int width, int height, Seq<Rect> inputRects){
Page bestResult = null;
for(int i = 0, n = methods.length; i < n; i++){
for(FreeRectChoiceHeuristic method : methods){
maxRects.init(width, height);
Page result;
if(!settings.fast){
result = maxRects.pack(inputRects, methods[i]);
result = maxRects.pack(inputRects, method);
}else{
Seq<Rect> remaining = new Seq();
for(int ii = 0, nn = inputRects.size; ii < nn; ii++){
Rect rect = inputRects.get(ii);
if(maxRects.insert(rect, methods[i]) == null){
if(maxRects.insert(rect, method) == null){
while(ii < nn)
remaining.add(inputRects.get(ii++));
}
Expand Down Expand Up @@ -274,8 +274,9 @@ public int next(boolean result){
*/
class MaxRects{
private int binWidth, binHeight;
private final Seq<Rect> usedRectangles = new Seq();
private final Seq<Rect> freeRectangles = new Seq();
private final Seq<Rect> usedRectangles = new Seq<>();
private final Seq<Rect> freeRectangles = new Seq<>();
private final Seq<Rect> rectanglesToCheckWhenPruning = new Seq<>();

public void init(int width, int height){
binWidth = width;
Expand Down Expand Up @@ -672,6 +673,7 @@ private boolean splitFreeNode(Rect freeNode, Rect usedNode){
Rect newNode = new Rect(freeNode);
newNode.height = usedNode.y - newNode.y;
freeRectangles.add(newNode);
rectanglesToCheckWhenPruning.add(newNode);
}

// New node at the bottom side of the used node.
Expand All @@ -680,6 +682,7 @@ private boolean splitFreeNode(Rect freeNode, Rect usedNode){
newNode.y = usedNode.y + usedNode.height;
newNode.height = freeNode.y + freeNode.height - (usedNode.y + usedNode.height);
freeRectangles.add(newNode);
rectanglesToCheckWhenPruning.add(newNode);
}
}

Expand All @@ -689,6 +692,7 @@ private boolean splitFreeNode(Rect freeNode, Rect usedNode){
Rect newNode = new Rect(freeNode);
newNode.width = usedNode.x - newNode.x;
freeRectangles.add(newNode);
rectanglesToCheckWhenPruning.add(newNode);
}

// New node at the right side of the used node.
Expand All @@ -697,31 +701,42 @@ private boolean splitFreeNode(Rect freeNode, Rect usedNode){
newNode.x = usedNode.x + usedNode.width;
newNode.width = freeNode.x + freeNode.width - (usedNode.x + usedNode.width);
freeRectangles.add(newNode);
rectanglesToCheckWhenPruning.add(newNode);
}
}

return true;
}

private void pruneFreeList(){
// Go through each pair and remove any rectangle that is redundant.
Seq<Rect> freeRectangles = this.freeRectangles;
for(int i = 0, n = freeRectangles.size; i < n; i++)
for(int j = i + 1; j < n; ++j){
Rect rect1 = freeRectangles.get(i);
Rect rect2 = freeRectangles.get(j);
if(isContainedIn(rect1, rect2)){
freeRectangles.remove(i);
--i;
--n;
break;
IntSet freeRectanglesToRemove = new IntSet();

for(Rect checkingRectangle : rectanglesToCheckWhenPruning){
for(int i = 0; i < freeRectangles.size; i++){
Rect rect = freeRectangles.get(i);
if(rect == checkingRectangle){
continue;
}
if(isContainedIn(rect2, rect1)){
freeRectangles.remove(j);
--j;
--n;
if(isContainedIn(rect, checkingRectangle)){
freeRectanglesToRemove.add(i);
}
}
}

rectanglesToCheckWhenPruning.clear();

if(freeRectanglesToRemove.isEmpty()){
return;
}

Seq<Rect> temporaryFreeRectangles = new Seq<>(freeRectangles);

freeRectangles.clear();
for(int i = 0; i < temporaryFreeRectangles.size; i++){
if(!freeRectanglesToRemove.contains(i)){
freeRectangles.add(temporaryFreeRectangles.get(i));
}
}
}

private boolean isContainedIn(Rect a, Rect b){
Expand Down

0 comments on commit 5ed3082

Please sign in to comment.