-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
918a789
commit 3798dfc
Showing
4 changed files
with
62 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
commons/src/main/com/mbrlabs/mundus/commons/utils/Pools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.mbrlabs.mundus.commons.utils; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
import com.badlogic.gdx.math.Vector3; | ||
import com.badlogic.gdx.utils.Pool; | ||
|
||
/** | ||
* Pooling of commonly used objects. | ||
* | ||
* @author JamesTKhan | ||
* @version May 14, 2023 | ||
*/ | ||
public class Pools { | ||
|
||
public final static Pool<Vector2> vector2Pool = new Pool<Vector2>() { | ||
@Override | ||
protected Vector2 newObject () { | ||
return new Vector2(); | ||
} | ||
|
||
@Override | ||
protected void reset(Vector2 object) { | ||
object.set(0, 0); | ||
} | ||
}; | ||
|
||
public final static Pool<Vector3> vector3Pool = new Pool<Vector3>() { | ||
@Override | ||
protected Vector3 newObject () { | ||
return new Vector3(); | ||
} | ||
|
||
@Override | ||
protected void reset(Vector3 object) { | ||
object.set(0,0,0); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* Convenience method, free array of objects | ||
* @param objects objects to free | ||
*/ | ||
public static void free(Vector2... objects ) { | ||
for (Vector2 object : objects) { | ||
vector2Pool.free(object); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters