Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: fabianbergmark/marble
base: 73288d3e42
...
head fork: fabianbergmark/marble
compare: 66571351b4
  • 4 commits
  • 14 files changed
  • 0 commit comments
  • 2 contributors
89 src/main/java/org/marble/Game.java
View
@@ -119,7 +119,7 @@
private Optional<GameSession> currentSession = Optional.absent();
// Currently loaded entities
- private final Set<Entity> entities = Sets.newIdentityHashSet();
+ private ImmutableSet<Entity> entities = ImmutableSet.of();
// Engines to handle.
private final ImmutableSet<Engine<?>> engines;
@@ -164,29 +164,31 @@ public Game(final JmeContext context, final AssetManager assetManager,
}
/**
- * Starts managing an entity.
+ * Starts managing a set of entities.
*
- * @param entity
- * The entity to manage.
- */
- public void addEntity(final Entity entity) {
- entity.initialize(this);
- for (final Engine<?> engine : engines) {
- if (engine.shouldHandle(entity)) {
- engine.addEntity(entity);
+ * @param entities
+ * The set of entities to manage.
+ */
+ public void addEntities(final Set<Entity> entities) {
+ for (final Entity entity : entities) {
+ entity.initialize(this);
+ for (final Engine<?> engine : engines) {
+ if (engine.shouldHandle(entity)) {
+ engine.addEntity(entity);
+ }
}
}
- entities.add(entity);
+ this.entities =
+ ImmutableSet.<Entity> builder().addAll(this.entities)
+ .addAll(entities).build();
}
/**
* Performs deferred destruction of all subsystems.
*/
public void destroy() {
- for (final Entity entity : ImmutableSet.copyOf(entities)) {
- removeEntity(entity);
- }
+ removeAllEntities();
for (final Engine<?> engine : engines) {
engine.destroy();
@@ -225,21 +227,22 @@ public Settings getSettings() {
* Performs deferred initialization of all subsystems.
*/
public void initialize() {
-
Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
Logger.getLogger("").setLevel(Level.SEVERE);
+
for (final Engine<?> engine : engines) {
engine.initialize();
}
- setupGUI();
-
- loadLevelPack(Game.class.getResource("level/core.pack"));
+ setupGUI();
setupControls();
setupSkybox();
setupLighting();
setupCamera();
setupFilters();
+
+ loadLevelPack(Game.class.getResource("level/core.pack"));
+
gotoMenu();
}
@@ -372,18 +375,15 @@ private void setupGUI() {
* The URL to the level pack to try to load.
*/
public void loadLevelPack(final URL levelPack) {
-
- String errorMessage = null;
try {
currentLevelPackURL = levelPack;
currentLevelPack = levelLoader.loadMetaLevelPack(levelPack);
return;
} catch (final IOException e) {
- errorMessage = e.getMessage();
+ handleError(e.getMessage(), e);
} catch (final JSONException e) {
- errorMessage = e.getMessage();
+ handleError(e.getMessage(), e);
}
- throw new RuntimeException(errorMessage);
}
/**
@@ -465,17 +465,19 @@ private void describeParseAlternatives(final StringBuilder builder,
final Set<String> messages) {
if (messages.isEmpty())
return;
+
final int size = messages.size();
int i = 0;
for (final String message : messages) {
- if (i++ > 0) {
+ if (i > 0) {
if (i == size) {
builder.append(" or ");
} else {
builder.append(", ");
}
}
+ i++;
builder.append(message);
}
}
@@ -488,9 +490,7 @@ private void describeParseAlternatives(final StringBuilder builder,
*/
private void load(final ImmutableSet<Entity> level) {
removeAllEntities();
- for (final Entity entity : level) {
- addEntity(entity);
- }
+ addEntities(level);
start();
}
@@ -500,22 +500,25 @@ private void load(final ImmutableSet<Entity> level) {
* @param entity
* The entity to stop managing.
*/
- public void removeEntity(final Entity entity) {
- for (final Engine<?> engine : engines) {
- if (engine.shouldHandle(entity)) {
- engine.removeEntity(entity);
+ public void removeEntities(final Set<Entity> entities) {
+ for (final Entity entity : entities) {
+ for (final Engine<?> engine : engines) {
+ if (engine.shouldHandle(entity)) {
+ engine.removeEntity(entity);
+ }
}
+ entity.destroy();
}
- entities.remove(entity);
- entity.destroy();
+ this.entities =
+ ImmutableSet.copyOf(Sets.difference(this.entities, entities));
}
/**
* Tells the game to halt immediately.
*/
public void stop() {
- context.destroy(false);
+ context.destroy(true);
}
/**
@@ -579,9 +582,7 @@ public void update(final Timer timer) {
* Removes all entities safely.
*/
private void removeAllEntities() {
- for (final Entity entity : ImmutableSet.copyOf(entities)) {
- removeEntity(entity);
- }
+ removeEntities(entities);
}
/**
@@ -703,12 +704,14 @@ private void setupSkybox() {
private void start() {
final Transform ballTransform = new Transform();
ballTransform.setTranslation(0, 0, 2);
+
final PlayerBall ball = new PlayerBall(DEFAULT_BALL_KIND);
- playerBall = Optional.of(ball);
ball.setTransform(ballTransform);
- addEntity(ball);
+
+ addEntities(ImmutableSet.<Entity> of(ball));
trackSpatial(ball.getSpatial());
+ playerBall = Optional.of(ball);
currentSession = Optional.of(new GameSession());
setPause(GameSession.PauseState.Running);
@@ -928,4 +931,12 @@ public void gotoMenu() {
public URL getCurrentLevelPackURL() {
return currentLevelPackURL;
}
+
+ public void removeEntity(final Entity entity) {
+ removeEntities(ImmutableSet.of(entity));
+ }
+
+ public void addEntity(final Entity entity) {
+ addEntities(ImmutableSet.of(entity));
+ }
}
62 src/main/java/org/marble/block/Slab.java
View
@@ -106,39 +106,35 @@ public void initialize(final Game game) {
boolean changed = false;
final TempVars vars = TempVars.get();
- if (slopeX != 0.0f) {
- vars.tempMat4.loadIdentity();
- vars.tempMat4.set(2, 0, slopeX);
- OfflineTransforms.transformNonLinear3D(
- graphicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
- OfflineTransforms.transformNonLinear3D(
- physicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
-
- vars.tempMat4.loadIdentity();
- vars.tempMat4.set(0, 3, -slopeX);
- OfflineTransforms.transformNonLinear3DNorm(
- graphicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
- OfflineTransforms.transformNonLinear3DNorm(
- physicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
- changed = true;
- }
-
- if (slopeY != 0.0f) {
- vars.tempMat4.loadIdentity();
- vars.tempMat4.set(2, 1, slopeY);
- OfflineTransforms.transformNonLinear3D(
- graphicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
- OfflineTransforms.transformNonLinear3D(
- physicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
-
- vars.tempMat4.loadIdentity();
- vars.tempMat4.set(1, 3, -slopeY);
- OfflineTransforms.transformNonLinear3DNorm(
- graphicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
- OfflineTransforms.transformNonLinear3DNorm(
- physicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
- changed = true;
- }
+ vars.tempMat4.loadIdentity();
+ vars.tempMat4.set(2, 0, slopeX);
+ OfflineTransforms.transformNonLinear3D(
+ graphicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
+ OfflineTransforms.transformNonLinear3D(
+ physicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
+
+ vars.tempMat4.loadIdentity();
+ vars.tempMat4.set(0, 3, -slopeX);
+ OfflineTransforms.transformNonLinear3DNorm(
+ graphicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
+ OfflineTransforms.transformNonLinear3DNorm(
+ physicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
+ changed = true;
+
+ vars.tempMat4.loadIdentity();
+ vars.tempMat4.set(2, 1, slopeY);
+ OfflineTransforms.transformNonLinear3D(
+ graphicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
+ OfflineTransforms.transformNonLinear3D(
+ physicalMesh.getFloatBuffer(Type.Position), vars.tempMat4);
+
+ vars.tempMat4.loadIdentity();
+ vars.tempMat4.set(1, 3, -slopeY);
+ OfflineTransforms.transformNonLinear3DNorm(
+ graphicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
+ OfflineTransforms.transformNonLinear3DNorm(
+ physicalMesh.getFloatBuffer(Type.Normal), vars.tempMat4);
+ changed = true;
vars.release();
if (changed) {
5 src/main/java/org/marble/block/Spiral.java
View
@@ -44,6 +44,11 @@ public Spiral(final float radius, final float height, final float angle) {
}
public Spiral(final float radius, final float height, final float angle,
+ final float theta) {
+ this(radius, height, angle, 0, 0, 1, theta);
+ }
+
+ public Spiral(final float radius, final float height, final float angle,
final float x, final float y, final float z, final float theta) {
this(radius, height, angle, 1, 0.1f, x, y, z, theta);
}
2  src/main/java/org/marble/level/LevelParser.java
View
@@ -114,6 +114,8 @@
identifier,
at.next(vector3),
from.next(identifier).optional()
+ .map(new Optionalizer<String>()),
+ dot.next(identifier)
.map(new Optionalizer<String>()))
.sepBy(comma).map(new ListImmutabilizer<Position>()));
// Parses a sequence of statements
7 src/main/java/org/marble/level/LevelStatement.java
View
@@ -214,7 +214,8 @@ public String toString() {
private final Optional<String> relativeTo;
public Position(final Integer location, final String name,
- final Vector3f position, final Optional<String> relativeTo) {
+ final Vector3f position, final Optional<String> relativeTo,
+ final Optional<String> connectorName) {
super(location);
this.name = name;
this.position = position;
@@ -254,6 +255,10 @@ public Vector3f getPosition() {
return relativeTo;
}
+ public Optional<String> getConnector() {
+ retr
+ }
+
@Override
public int hashCode() {
return Objects.hashCode(name, position, relativeTo);
19 src/main/java/org/marble/special/Image.java
View
@@ -3,6 +3,7 @@
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
+import com.jme3.math.Quaternion;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
@@ -14,12 +15,26 @@
public class Image extends AbstractEntity implements Graphical {
private final String imageFile;
private final float width, height;
+ private final float angleX, angleY, angleZ;
private Geometry graphicalQuad;
public Image(final String imageFile, final float width, final float height) {
+ this(imageFile, width, height, 0);
+ }
+
+ public Image(final String imageFile, final float width, final float height,
+ final float inclination) {
+ this(imageFile, width, height, inclination, 0, 0);
+ }
+
+ public Image(final String imageFile, final float width, final float height,
+ final float angleX, final float angleY, final float angleZ) {
this.imageFile = imageFile;
this.width = width;
this.height = height;
+ this.angleX = angleX;
+ this.angleY = angleY;
+ this.angleZ = angleZ;
}
@Override
@@ -30,8 +45,12 @@ public void initialize(final Game game) {
new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
final Texture tex = assetManager.loadTexture(imageFile);
mat.setTexture("DiffuseMap", tex);
+ mat.setBoolean("UseAlpha", true);
+ mat.setFloat("AlphaDiscardThreshold", 0.05f);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
graphicalQuad.setMaterial(mat);
+ graphicalQuad.setLocalRotation(new Quaternion().fromAngles(angleX,
+ angleY, angleZ));
graphicalQuad.setLocalTranslation(0, 0, 0.05f);
getSpatial().attachChild(graphicalQuad);
}
25 src/main/java/org/marble/util/Connectors.java
View
@@ -87,6 +87,9 @@ private Connectors() {
builder.put("end_left",
offsetBy(-width / 2, -(height / 2), 0, 0, 0, pi));
+ builder.put("middle_right", offsetBy(0, height / 2, 0, 0, 0, pi / 2));
+ builder.put("middle_left", offsetBy(0, -height / 2, 0, 0, 0, pi / 2));
+
return builder.build();
}
@@ -137,19 +140,25 @@ private Connectors() {
connectorBuilder.put(
makeConnectorName("north", x, z),
offsetBy(xcoord, yhalf, zcoord + verticalOffset
- + xcoord * slopeX, 0, 0, pihalf));
+ + xcoord * slopeX + yhalf * slopeY, 0, 0,
+ pihalf));
connectorBuilder.put(
makeConnectorName("south", x, z),
offsetBy(xcoord, -yhalf, zcoord + verticalOffset
- + xcoord * slopeX, 0, 0, -pihalf));
+ - xhalf * slopeX - yhalf * slopeY, 0, 0,
+ -pihalf));
}
}
// East/West
- connectorBuilder.put("east_middle",
- offsetBy(xhalf, 0, verticalOffset + xhalf * slopeX, 0, 0, 0));
- connectorBuilder.put("west_middle",
- offsetBy(-xhalf, 0, verticalOffset - xhalf * slopeX, 0, 0, pi));
+ connectorBuilder.put(
+ "east_middle",
+ offsetBy(xhalf, 0, verticalOffset + xhalf * slopeX + yhalf
+ * slopeY, 0, 0, 0));
+ connectorBuilder.put(
+ "west_middle",
+ offsetBy(-xhalf, 0, verticalOffset - xhalf * slopeX - yhalf
+ * slopeY, 0, 0, pi));
for (int y = 0; y < ycount; y++) {
final float ycoord = yborder + y - yhalf;
for (int z = 0; z < zcount; z++) {
@@ -157,11 +166,11 @@ private Connectors() {
connectorBuilder.put(
makeConnectorName("east", y, z),
offsetBy(xhalf, ycoord, zcoord + verticalOffset
- + ycoord * slopeY, 0, 0, 0));
+ + ycoord * slopeY + xhalf * slopeX, 0, 0, 0));
connectorBuilder.put(
makeConnectorName("west", y, z),
offsetBy(-xhalf, ycoord, zcoord + verticalOffset
- + ycoord * slopeY, 0, 0, pi));
+ + ycoord * slopeY + xhalf * slopeX, 0, 0, pi));
}
}
BIN  src/main/resources/Images/checkpoint.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  src/main/resources/Images/goal.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  src/main/resources/Images/lives.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  src/main/resources/Images/points.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 src/main/resources/org/marble/level/core.pack
View
@@ -22,6 +22,11 @@
"name": "Foobar",
"uri": "core/foobar.level",
"uuid": "8f4ba45d-7c1f-448f-b5bc-d9911a461f2c"
+ },
+ {
+ "name": "Advanced",
+ "uri": "core/advanced.level",
+ "uuid": "f4df4905-2dc4-4dac-bf1b-108cf2090491"
}
]
}
56 src/main/resources/org/marble/level/core/advanced.level
View
@@ -0,0 +1,56 @@
+// Import our slab class
+using Slab as org.marble.block.Slab
+using Ball as org.marble.ball.Ball
+using Transformer as org.marble.block.Transformer
+using Lantern as org.marble.block.Lantern
+using Wall as org.marble.block.Wall
+using Rail as org.marble.block.Rail
+using Spiral as org.marble.block.Spiral
+using CheckpointBlock as org.marble.special.CheckpointBlock
+using WinBlock as org.marble.special.WinBlock
+using Pin as org.marble.block.Pin
+using PointOrb as org.marble.special.PointOrb
+using LifeOrb as org.marble.special.LifeOrb
+
+let spawnBlock be Slab(10,10,1)
+
+position spawnBlock at (0,0,0)
+
+let rail be Rail(7)
+
+connect rail.start_middle to spawnBlock.north_middle
+
+let point1 be PointOrb(),
+ point2 be PointOrb(),
+ point3 be PointOrb()
+
+position point1 at (-2, 0, 1) from rail
+position point2 at (0, 0, 1) from rail
+position point3 at (2, 0, 1) from rail
+
+let spiral be Spiral(8,30,360,45)
+let lantern be Lantern((0.5,0.5,0.5))
+
+connect spiral.end_middle to rail.end_middle
+
+let stoneBall be Ball([Stone])
+
+position stoneBall at (-6.8,3.7,28.5) from spiral
+
+position lantern at (0,0,25) from spiral
+
+let rightSlope be Slab(5,300,1,0.45,-0.25),
+ leftSlope be Slab(5,300,1,0.45,0.25)
+
+let p4 be PointOrb(),
+ p5 be PointOrb(),
+ p6 be PointOrb(),
+ p7 be PointOrb()
+
+connect rightSlope.south_0_0 to spiral.start_inner,
+ leftSlope.north_0_0 to spiral.start_inner
+
+position p4 at (0,0,1) from rightSlope
+position p5 at (0,0,2) from rightSlope
+position p6 at (0,0,3) from rightSlope
+position p7 at (0,0,4) from rightSlope
16 src/main/resources/org/marble/level/core/foobar.level
View
@@ -39,15 +39,18 @@ let spiral1 be Spiral(4,4,720),
// Create some bends
let bend1 be Spiral(5,0,180),
+ bend3 be Spiral(5.5,0,180,0),
bend2 be Spiral(8,0,90)
// Create some walls
let wall1 be Wall(12),
wall2 be Wall(15),
wall3 be Wall(15),
- wall4 be Wall(15)
-
-// Create demo balls
+ wall4 be Wall(15),
+ wall5 be Wall(10),
+ wall6 be Wall(10),
+ wall7 be Wall(10),
+ wall8 be Wall(10)
// Transformers
@@ -75,7 +78,12 @@ connect slab2.south_middle to slab1.north_1_0,
wall1.position_0 to slab1.north_3_0,
wall2.position_middle to slab1.west_middle,
wall3.position_middle to slab1.south_middle,
- wall4.position_middle to slab1.east_middle
+ wall4.position_middle to slab1.east_middle,
+ wall5.position_middle to rail4.middle_left,
+ wall6.position_middle to rail4.middle_right,
+ wall7.position_middle to rail3.middle_right,
+ wall8.position_middle to rail3.middle_left,
+ bend3.start_inner to rail1.end_right
position win at (0,0,1) from slab6
position lantern1 at (-2,-2,1) from slab1

No commit comments for this range

Something went wrong with that request. Please try again.