Skip to content

Commit

Permalink
Merge branch 'master' into be
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	arc-core/src/arc/graphics/g2d/Batch.java
#	arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java
#	arc-core/src/arc/graphics/g2d/SpriteBatch.java
#	backends/backend-sdl/build.gradle
#	extensions/filedialogs/src/arc/filedialogs/FileDialogs.java
#	extensions/freetype/build.gradle
#	gradle/wrapper/gradle-wrapper.properties
#	natives/natives-filedialogs/libs/arc-filedialogs.dll
#	natives/natives-filedialogs/libs/arc-filedialogs64.dll
#	natives/natives-filedialogs/libs/libarc-filedialogs64.so
  • Loading branch information
buthed010203 committed Sep 2, 2024
2 parents 1706846 + 3284de5 commit 9130440
Show file tree
Hide file tree
Showing 38 changed files with 988 additions and 880 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/verify-gradle-wrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
[![](https://github.com/Anuken/Arc/workflows/Java%20CI/badge.svg)](https://github.com/Anuken/Arc/actions)
Wow a fork of a fork of libgdx no way

# Where's the documentation?

There isn't any. This project is only used as the framework for Mindustry.

# Where's the source code for the native libraries?

Most of it is glue generated by [jnigen](https://github.com/libgdx/gdx-jnigen) from comments in the Java source code. External libraries (freetype, soloud, SDL, Box2D, GLEW, etc) are fetched from various sources at build time - see, for example, [this build script](https://github.com/Anuken/Arc/blob/master/backends/backend-sdl/build.gradle#L18).

# How do I make a game with this framework?

Please don't. While there is nothing stopping you from making other games with this framework, there is no "project setup" tool of any kind, and no guide on how to do anything. In addition, I would discourage anyone from making games in Java at all.

# How does Arc differ from libGDX?

There are too many things to list, but here are some highlights:

- Soloud used as the audio engine across all platforms - faster, more consistent and more capable than libGDX's per-platform abstraction
- SDL used as the desktop backend library instead of LWJGL+GLFW bindings - comes with its own benefits and drawbacks
- Removal of GWT module and all workarounds associated with it
- Proper methods for drawing lines, polygons, etc in one sprite batch
- Global sprite batch, texture atlas, asset manager, etc
- Thin GL abstraction layer, state is cached to prevent unnecessary API calls
- All APIs deal with 2D coordinates instead of attempting to share 2D and 3D classes (cameras, matrices, etc)
- 3D package removed, some small parts moved to an extension
- Java 8 target, heavy usage of lambdas in Scene2D code
- Massive amount of refactored, merged, deleted classes (*especially* deleted)
12 changes: 10 additions & 2 deletions arc-core/src/arc/audio/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ public int at(float x, float y, float pitch){
* Plays this sound at a certain position, with correct panning and volume applied.
* Automatically uses the "sfxvolume" setting.
*/
public int at(float x, float y, float pitch, float volume){
public int at(float x, float y, float pitch, float volume, boolean checkFrame){
float vol = calcVolume(x, y) * volume;
if(vol < 0.01f) return -1; //discard
return play(vol, pitch, calcPan(x, y));
return play(vol, pitch, calcPan(x, y), false, checkFrame);
}

/**
* Plays this sound at a certain position, with correct panning and volume applied.
* Automatically uses the "sfxvolume" setting.
*/
public int at(float x, float y, float pitch, float volume){
return at(x, y, pitch, volume, true);
}

/**
Expand Down
1 change: 1 addition & 0 deletions arc-core/src/arc/graphics/Blending.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** Blending modes, can be instantiated to make custom blending. */
public class Blending{
public static final Blending

normal = new Blending(Gl.srcAlpha, Gl.oneMinusSrcAlpha, Gl.one, Gl.oneMinusSrcAlpha),
additive = new Blending(Gl.srcAlpha, Gl.one, Gl.one, Gl.oneMinusSrcAlpha),
disabled = new Blending(Gl.srcAlpha, Gl.oneMinusSrcAlpha, Gl.one, Gl.oneMinusSrcAlpha){
Expand Down
10 changes: 2 additions & 8 deletions arc-core/src/arc/graphics/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
* </p>
*
* <p>
* Meshes are automatically managed. If the OpenGL context is lost all vertex buffer objects get invalidated and must be reloaded
* when the context is recreated. This only happens on Android when a user switches to another application or receives an incoming
* call. A managed Mesh will be reloaded automagically so you don't have to do this manually.
* </p>
*
* <p>
* A Mesh consists of vertices and optionally indices which specify which vertices define a triangle. Each vertex is composed of
* attributes such as position, normal, color or texture coordinate. Note that not all of this attributes must be given, except
* for position which is non-optional. Each attribute has an alias which is used when rendering a Mesh in OpenGL ES 2.0. The alias
Expand All @@ -34,8 +28,8 @@ public class Mesh implements Disposable{
/** Do not modify. */
public final VertexAttribute[] attributes;

public final VertexData vertices;
public final IndexData indices;
public VertexData vertices;
public IndexData indices;

boolean autoBind = true;

Expand Down
46 changes: 1 addition & 45 deletions arc-core/src/arc/graphics/g2d/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

/** Base batch class. Provides a mesh, texture, shader, and other state. */
public abstract class Batch implements Disposable{
protected Mesh mesh;

protected float z;
protected int sortAscending = 1;
protected int idx = 0;
protected Texture lastTexture = null;

Expand All @@ -25,65 +22,27 @@ public abstract class Batch implements Disposable{
protected Shader shader, customShader = null;
protected boolean ownsShader;

protected final Color color = new Color(1, 1, 1, 1);
protected float colorPacked = Color.whiteFloatBits;

protected final Color mixColor = Color.clear;
protected float mixColorPacked = Color.clearFloatBits;

protected void z(float z){
this.z = z * sortAscending; // sortAscending ? z : -z
this.z = z;
}

/** Enables or disables Z-sorting. Flushes the batch. Only does something on supported batches. */
protected void setSort(boolean sort){

}

/** Sets the sorting order. The batch must be flushed for this to take effect properly. */
protected void setSortAscending(boolean ascend){
sortAscending = Mathf.sign(ascend);
}

protected void setColor(Color tint){
color.set(tint);
colorPacked = tint.toFloatBits();
}

protected void setColor(float r, float g, float b, float a){
color.set(r, g, b, a);
colorPacked = color.toFloatBits();
}

protected Color getColor(){
return color;
}

protected void setPackedColor(float packedColor){
this.color.abgr8888(packedColor);
this.colorPacked = packedColor;
}

protected float getPackedColor(){
return colorPacked;
}

protected void setMixColor(Color tint){
mixColor.set(tint);
mixColorPacked = tint.toFloatBits();
}

protected void setMixColor(float r, float g, float b, float a){
mixColor.set(r, g, b, a);
mixColorPacked = mixColor.toFloatBits();
}

protected Color getMixColor(){
return mixColor;
}

protected void setPackedMixColor(float packedColor){
this.mixColor.abgr8888(packedColor);
this.mixColorPacked = packedColor;
}

Expand Down Expand Up @@ -119,9 +78,6 @@ protected Blending getBlending(){

@Override
public void dispose(){
if(mesh != null){
mesh.dispose();
}
if(ownsShader && shader != null) shader.dispose();
}

Expand Down
11 changes: 0 additions & 11 deletions arc-core/src/arc/graphics/g2d/Bloom.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@ public void render(){
buffer.blit(bloomShader);
}

// these typos bother me that much, yes.
@Deprecated
public void setBloomIntesity(float intensity){
setBloomIntensity(intensity);
}

@Deprecated
public void setOriginalIntesity(float intensity){
setOriginalIntensity(intensity);
}

/**
* Set intensity for bloom. Higher means more brightening for spots that are over threshold.
* @param intensity Multiplier for blurred texture in combining phase. Must be positive.
Expand Down
24 changes: 4 additions & 20 deletions arc-core/src/arc/graphics/g2d/CacheBatch.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package arc.graphics.g2d;

import arc.graphics.Color;
import arc.graphics.Texture;
import arc.graphics.gl.Shader;
import arc.math.Mat;
import arc.graphics.*;
import arc.graphics.gl.*;
import arc.math.*;

public class CacheBatch extends Batch{
SpriteCache cache;
Expand All @@ -22,29 +21,14 @@ public void flush(){
//does nothing, since flushing like this isn't needed
}

@Override
public void setColor(Color tint){
cache.setColor(tint);
}

@Override
public void setColor(float r, float g, float b, float a){
cache.setColor(r, g, b, a);
}

@Override
public void setPackedColor(float color){
cache.setPackedColor(color);
}

@Override
public Color getColor(){
return cache.getColor();
}

@Override
public float getPackedColor(){
return cache.getColor().toFloatBits();
return cache.getPackedColor();
}

@Override
Expand Down
53 changes: 35 additions & 18 deletions arc-core/src/arc/graphics/g2d/Draw.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Draw{
private static final float[] vertices = new float[SpriteBatch.SPRITE_SIZE];
private static @Nullable FloatFloatf zTransformer;
private static float actualZ;
private static Color retColor = new Color(), retPackedColor = new Color();

public static float scl = 1f;
public static float xscl = 1f, yscl = 1f;
Expand Down Expand Up @@ -137,11 +138,6 @@ public static void sort(boolean sort){
batch.setSort(sort);
}

/** Sets sorting order to either be ascending or descending in terms of Z. Default: true. */
public static void sortAscending(boolean ascend){
batch.setSortAscending(ascend);
}

/** Sets a Z-transformer function that will modify subsequent calls to Draw.z. Yep, this is as terrible as it sounds. */
public static void zTransform(FloatFloatf f){
zTransformer = f;
Expand All @@ -160,49 +156,67 @@ public static void z(float z){
Core.batch.z(zTransformer == null ? actualZ = z : zTransformer.get(actualZ = z));
}

public static float getColorAlpha(){
int abgr = Color.floatToIntColor(batch.getPackedColor());
return ((abgr & 0xff000000) >>> 24) / 255f;
}

public static float getColorPacked(){
return batch.getPackedColor();
}

public static float getMixColorPacked(){
return batch.getPackedMixColor();
}

public static Color getColor(){
return Core.batch.getColor();
return retColor.abgr8888(batch.getPackedColor());
}

public static Color getMixColor(){
return Core.batch.getMixColor();
return retPackedColor.abgr8888(batch.getPackedMixColor());
}

public static void mixcol(Color color, float a){
Core.batch.setMixColor(color.r, color.g, color.b, Mathf.clamp(a));
Core.batch.setPackedMixColor(Color.toFloatBits(color.r, color.g, color.b, Mathf.clamp(a)));
}

public static void mixcol(Color a, Color b, float prog){
Core.batch.setMixColor(Tmp.c1.set(a).lerp(b, prog));
Core.batch.setPackedMixColor(Tmp.c1.set(a).lerp(b, prog).toFloatBits());
}

public static void mixcol(){
Core.batch.setPackedMixColor(Color.clearFloatBits);
}

public static void mixcol(float color){
Core.batch.setPackedMixColor(color);
}

public static void tint(Color a, Color b, float s){
Tmp.c1.set(a).lerp(b, s);
Core.batch.setColor(Tmp.c1.r, Tmp.c1.g, Tmp.c1.b, Core.batch.getColor().a);
Tmp.c1.a = getColorAlpha();
color(Tmp.c1);
}

public static void tint(Color color){
Core.batch.setColor(color.r, color.g, color.b, Core.batch.getColor().a);
Core.batch.setPackedColor(Color.toFloatBits(color.r, color.g, color.b, getColorAlpha()));
}

public static void colorMul(Color color, float mul){
color(color.r * mul, color.g * mul, color.b * mul, 1f);
}

public static void color(Color color){
Core.batch.setColor(color);
Core.batch.setPackedColor(color.toFloatBits());
}

public static void color(Color color, float alpha){
Core.batch.setColor(color.r, color.g, color.b, alpha);
Core.batch.setPackedColor(Color.toFloatBits(color.r, color.g, color.b, Mathf.clamp(alpha)));
}

public static void color(int color){
Core.batch.setColor(Tmp.c1.rgba8888(color));
Core.batch.setPackedColor(Tmp.c1.rgba8888(color).toFloatBits());
}

public static void color(float color){
Expand All @@ -218,19 +232,19 @@ public static void color(Color a, Color b, Color c, float progress){

/** Automatically mixes colors. */
public static void color(Color a, Color b, float s){
Core.batch.setColor(Tmp.c1.set(a).lerp(b, s));
Core.batch.setPackedColor(Tmp.c1.set(a).lerp(b, s).toFloatBits());
}

public static void color(){
Core.batch.setPackedColor(Color.whiteFloatBits);
}

public static void color(float r, float g, float b){
Core.batch.setColor(r, g, b, 1f);
Core.batch.setPackedColor(Color.toFloatBits(r, g, b, 1f));
}

public static void color(float r, float g, float b, float a){
Core.batch.setColor(r, g, b, a);
Core.batch.setPackedColor(Color.toFloatBits(r, g, b, Mathf.clamp(a)));
}

/** Lightness color. */
Expand Down Expand Up @@ -263,7 +277,10 @@ public static void reset(){
}

public static void alpha(float alpha){
Core.batch.setColor(Core.batch.getColor().r, Core.batch.getColor().g, Core.batch.getColor().b, alpha);
int abgr = Color.floatToIntColor(batch.getPackedColor());
int rawAlpha = (int)(Mathf.clamp(alpha) * 255);

batch.setPackedColor(Color.intToFloatColor((abgr & 0x00ffffff) | (rawAlpha << 24)));
}

/** Draws a portion of a world-sized texture. */
Expand Down
2 changes: 1 addition & 1 deletion arc-core/src/arc/graphics/g2d/ForkJoinHolder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package arc.graphics.g2d;

import arc.graphics.g2d.SortedSpriteBatch.*;
import arc.graphics.g2d.SpriteBatch.*;

import java.util.concurrent.*;

Expand Down
Loading

0 comments on commit 9130440

Please sign in to comment.