Skip to content

Commit

Permalink
Adjusted the grammar system to engine changes...
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar committed Mar 11, 2016
1 parent 624dea5 commit 2e48a04
Show file tree
Hide file tree
Showing 29 changed files with 798 additions and 435 deletions.
8 changes: 6 additions & 2 deletions module.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"id" : "GrammarSystem",
"version" : "0.1.0",
"version" : "0.2.0-SNAPSHOT",
"author" : "Skaldarnar",
"displayName" : "Grammar System",
"description" : "Grammar System for procedural structure generation. Basis for the Procedural Architecture Grammar",
"dependencies" : [],
"dependencies" : [
{
"id": "Core", "minVersion": "1.0.0"
}
],
"isServerSideOnly" : false
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ assignment
)
{
if (p >= 0) {
$succ = new SetSuccessor($block_uri.uri, p);
$succ = new SetSuccessor($block_uri.urn, p);
}
else {
$succ = new SetSuccessor($block_uri.uri);
$succ = new SetSuccessor($block_uri.urn);
}
}
// second alternative: the successor is a subdiv command
Expand Down Expand Up @@ -177,7 +177,7 @@ direction returns [Direction direction]
/* Contsructs a BlockUri from the given String.
* For parsing the constructor of BlockUri is used.
*/
block_uri returns [BlockUri uri]
block_uri returns [BlockUri urn]
: {StringBuilder b = new StringBuilder();}
^(BLOCK_URI packageName=ID familyName=ID
{ b.append($packageName.text + ':' + $familyName.text); }
Expand All @@ -188,7 +188,7 @@ block_uri returns [BlockUri uri]
{ b.append( '.' + $blockIdentifier.text); }
)?
)
{ $uri = new BlockUri(b.toString()); }
{ $urn = new BlockUri(b.toString()); }
;


Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package org.terasology.grammarSystem.logic.grammar;
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar;

import org.terasology.grammarSystem.logic.grammar.shapes.Shape;
import org.terasology.grammarSystem.logic.grammar.shapes.ShapeSymbol;
import org.terasology.grammar.logic.grammar.shapes.Shape;
import org.terasology.grammar.logic.grammar.shapes.ShapeSymbol;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.assets;

import com.google.common.base.Preconditions;
import org.terasology.assets.AssetData;
import org.terasology.assets.ResourceUrn;
import org.terasology.grammar.logic.grammar.ProductionSystem;

public class Grammar implements AssetData {

private ResourceUrn urn;

private ProductionSystem productionSystem;

//TODO: store additional header information somehow

/**
* A new grammar object is created with the given production system..
*
* @param productionSystem the production system - not null.
*/
public Grammar(ProductionSystem productionSystem) {
Preconditions.checkArgument(productionSystem != null);
this.productionSystem = productionSystem;
}

public ProductionSystem getProductionSystem() {
return productionSystem;
}

public ResourceUrn getUrn() {
return urn;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package org.terasology.grammarSystem.logic.grammar.shapes;
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.shapes;

import org.terasology.math.Matrix4i;
import org.terasology.math.Vector3i;
import org.terasology.math.geom.Matrix4i;
import org.terasology.math.geom.Vector3i;

/**
* @author Tobias 'skaldarnar' Nett <p/> A shape is the basis for structure generation. </p> Shapes have a dimension and a relative
Expand Down Expand Up @@ -149,17 +164,26 @@ public void move(Vector3i translation) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Shape)) return false;
if (this == o) {
return true;
}
if (!(o instanceof Shape)) {
return false;
}

Shape shape = (Shape) o;

if (active != shape.active) return false;
if (Float.compare(shape.probability, probability) != 0) return false;
if (dimension != null ? !dimension.equals(shape.dimension) : shape.dimension != null) return false;
if (matrix != null ? !matrix.equals(shape.matrix) : shape.matrix != null) return false;
if (active != shape.active) {
return false;
}
if (Float.compare(shape.probability, probability) != 0) {
return false;
}
if (dimension != null ? !dimension.equals(shape.dimension) : shape.dimension != null) {
return false;
}
return matrix != null ? matrix.equals(shape.matrix) : shape.matrix == null;

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
package org.terasology.grammarSystem.logic.grammar.shapes;
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.shapes;

import org.terasology.math.Matrix4i;
import org.terasology.math.TeraMath;
import org.terasology.math.Vector3i;
import org.terasology.math.geom.Matrix4i;
import org.terasology.math.geom.Vector3i;

/**
* A shape symbol describes a org.terasology.logic.grammar element that can be derived directly via a org.terasology.logic.grammar rule.
Expand Down Expand Up @@ -68,15 +83,20 @@ public String getLabel() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ShapeSymbol)) return false;
if (!super.equals(o)) return false;
if (this == o) {
return true;
}
if (!(o instanceof ShapeSymbol)) {
return false;
}
if (!super.equals(o)) {
return false;
}

ShapeSymbol that = (ShapeSymbol) o;

if (!label.equals(that.label)) return false;
return label.equals(that.label);

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package org.terasology.grammarSystem.logic.grammar.shapes;
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.shapes;

import org.terasology.math.Vector3i;
import org.terasology.model.structures.BlockCollection;
import org.terasology.model.structures.BlockPosition;
import org.terasology.grammar.world.block.BlockCollection;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.CoreRegistry;
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.BlockUri;
import org.terasology.world.block.management.BlockManager;

/**
* @author Tobias 'skaldarnar' Nett
Expand All @@ -16,6 +31,8 @@ public class TerminalShape extends Shape {
/** The block collection this TerminalShape represents. */
private BlockCollection value;

private BlockManager blockManager = CoreRegistry.get(BlockManager.class);

/**
* Instantiates a new TerminalShape with the given {@link org.terasology.world.block.Block}. This will generate the BlockCollection
* value by filling its dimension with the specific block type.
Expand All @@ -29,7 +46,7 @@ public TerminalShape(BlockUri blockType) {
for (int c = 0; c < dimension.z; c++) {
Vector3i pos = new Vector3i(a, b, c);
matrix.transformPoint(pos);
value.addBlock(new BlockPosition(pos.x, pos.y, pos.z), BlockManager.getInstance().getBlock(blockType));
value.setBlock(new Vector3i(pos.x, pos.y, pos.z), blockManager.getBlock(blockType));
}
}
}
Expand Down Expand Up @@ -64,14 +81,17 @@ public BlockCollection getValue() {
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TerminalShape)) return false;
if (this == o) {
return true;
}
if (!(o instanceof TerminalShape)) {
return false;
}

TerminalShape that = (TerminalShape) o;

if (value != null ? !value.equals(that.value) : that.value != null) return false;
return value != null ? value.equals(that.value) : that.value == null;

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.shapes.complex;

import org.terasology.grammar.logic.grammar.shapes.Shape;

import java.util.List;

/** @author Tobias 'skaldarnar' Nett */
public abstract class ComplexRule extends Shape {

/**
* Returns the successor elements of this complex shape.
* <p/>
* The successor elements of a complex shape are for example the arguments of a _divide_ or _repeat_ rule. The successor elements cannot
* be simply looked up in the org.terasology.logic.grammar rules but rather depend on the specific complex shape rule/command they
* belong to.
*
* @return the successor elements of the complex shape rule
*/
public abstract List<Shape> getElements();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
package org.terasology.grammarSystem.logic.grammar.shapes.complex;

import org.terasology.grammarSystem.logic.grammar.shapes.Shape;
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.grammar.logic.grammar.shapes.complex;

import org.terasology.grammar.logic.grammar.shapes.Shape;

/** @author Tobias 'skaldarnar' Nett */
public class DivideArg {
Expand Down
Loading

0 comments on commit 2e48a04

Please sign in to comment.