Skip to content

Commit

Permalink
A bit of cleansing of constants and keywords
Browse files Browse the repository at this point in the history
- Reorganizes IKeyword.java and removes unused keywords
- Clarifies the status of the "name" of lights and cameras (now they are
strings, and not labels anymore)
- Adds the #default constant in GAML. (value = "default").
- Removes the #regular constant so that default cameras and lights use
the same keyword (#default or "default")
- Deprecates "draw_env" in display in favor of "axes"
- Makes sure 'ambient_light' is transformed into an equivalent 'light
#ambient..' statement.
  • Loading branch information
AlexisDrogoul committed Mar 7, 2022
1 parent e665ff7 commit d661da1
Show file tree
Hide file tree
Showing 47 changed files with 437 additions and 492 deletions.
6 changes: 3 additions & 3 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayData.java
Expand Up @@ -660,15 +660,15 @@ public void initWith(final IScope scope, final IDescription desc) {
toolbarColor = Cast.asColor(scope, toolbar.value(scope));
}
}
final IExpression fps = facets.getExpr(IKeyword.SHOWFPS);
final IExpression fps = facets.getExpr("show_fps");
if (fps != null) { setShowfps(Cast.asBool(scope, fps.value(scope))); }

final IExpression nZ = facets.getExpr("z_near");
if (nZ != null) { setZNear(Cast.asFloat(scope, nZ.value(scope))); }

final IExpression fZ = facets.getExpr("z_far");
if (fZ != null) { setZFar(Cast.asFloat(scope, fZ.value(scope))); }
final IExpression denv = facets.getExpr(IKeyword.DRAWENV);
final IExpression denv = facets.getExpr("draw_env", "axes");
if (denv != null) { setDrawEnv(Cast.asBool(scope, denv.value(scope))); }

final IExpression ortho = facets.getExpr(IKeyword.ORTHOGRAPHIC_PROJECTION);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ public void resetRotation() {
private final Map<String, ILightDefinition> lights = new LinkedHashMap<>() {
{
put(ILightDefinition.ambient, new GenericLightDefinition(ILightDefinition.ambient, -1, 127));
put(ILightDefinition.regular, new GenericLightDefinition(ILightDefinition.regular, 0, 127));
put(IKeyword.DEFAULT, new GenericLightDefinition(IKeyword.DEFAULT, 0, 127));
}
};

Expand Down
60 changes: 34 additions & 26 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayOutput.java
Expand Up @@ -156,16 +156,23 @@
value = "Allows to display a scale bar in the overlay. Accepts true/false or an unit name",
deprecated = "Not functional anymore. Scale is now displayed by default")),
@facet (
name = IKeyword.SHOWFPS,
name = "show_fps",
internal = true,
type = IType.BOOL,
optional = true,
doc = @doc ("Allows to enable/disable the drawing of the number of frames per second")),
@facet (
name = IKeyword.DRAWENV,
name = "axes",
type = IType.BOOL,
optional = true,
doc = @doc ("Allows to enable/disable the drawing of the world shape and the ordinate axes. Default can be configured in Preferences")),
@facet (
name = "draw_env",
type = IType.BOOL,
optional = true,
doc = @doc (
deprecated = "Use 'axes' instead",
value = "Allows to enable/disable the drawing of the world shape and the ordinate axes. Default can be configured in Preferences")),
@facet (
name = IKeyword.ORTHOGRAPHIC_PROJECTION,
internal = true,
Expand All @@ -175,21 +182,21 @@

/// LIGHT FACETS
@facet (
name = IKeyword.AMBIENT_LIGHT,
name = "ambient_light",
type = { IType.INT, IType.COLOR },
optional = true,
doc = @doc (
deprecated = "Define a statement 'light #ambient intensity: ...;' instead",
value = "Allows to define the value of the ambient light either using an int (ambient_light:(125)) or a rgb color ((ambient_light:rgb(255,255,255)). default is rgb(127,127,127,255)")),
@facet (
name = IKeyword.DIFFUSE_LIGHT,
name = "diffuse_light",
type = { IType.INT, IType.COLOR },
optional = true,
doc = @doc (
value = "Allows to define the value of the diffuse light either using an int (diffuse_light:(125)) or a rgb color ((diffuse_light:rgb(255,255,255)). default is (127,127,127,255)",
deprecated = "Use statement \"light\" instead to define a new light and its intensity")),
deprecated = "Use statement \"light\" instead with a #point or #direction light, to define a new light and its intensity")),
@facet (
name = IKeyword.DIFFUSE_LIGHT_POS,
name = "diffuse_light_pos",
type = IType.POINT,
optional = true,
doc = @doc (
Expand All @@ -199,9 +206,9 @@
name = IKeyword.IS_LIGHT_ON,
type = IType.BOOL,
optional = true,
doc = @doc ("Allows to enable/disable the light. Default is true")),
doc = @doc ("Allows to enable/disable the light at once. Default is true")),
@facet (
name = IKeyword.DRAW_DIFFUSE_LIGHT,
name = "draw_diffuse_light",
type = IType.BOOL,
optional = true,
doc = @doc (
Expand All @@ -211,12 +218,12 @@
/// CAMERA FACETS
@facet (
name = IKeyword.CAMERA,
type = { IType.STRING },
type = IType.STRING,
optional = true,
doc = @doc ("Allows to define the name of the camera to use. Default value is 'default'. "
+ "Accepted values are (1) the name of one of the cameras defined using the 'camera' statement or "
+ "(2) one of the preset cameras, accessible using constants: #from_above, #from_left, #from_right, "
+ "#from_up_left, #from_up_right, #from_front, #from_up_front")),
+ "#from_up_left, #from_up_right, #from_front, #from_up_front, #isometric")),
@facet (
name = "camera_pos",
type = { IType.POINT, IType.AGENT },
Expand All @@ -225,14 +232,14 @@
deprecated = "Define a separate camera instead in the body of the display using the 'camera' statement and attach the 'location:' facet to it",
value = "Allows to define the position of the camera")),
@facet (
name = IKeyword.CAMERA_LOCATION,
name = "camera_location",
type = { IType.POINT, IType.AGENT },
optional = true,
doc = @doc (
deprecated = "Define a separate camera instead in the body of the display using the 'camera' statement and attach the 'location:' facet to it",
value = "Allows to define the location of the camera, the origin being the center of the model")),
@facet (
name = IKeyword.CAMERA_TARGET,
name = "camera_target",
type = IType.POINT,
optional = true,
doc = @doc (
Expand All @@ -246,7 +253,7 @@
deprecated = "Define a separate camera instead in the body of the display using the 'camera' statement and attach the 'target:' facet to it",
value = "Allows to define the direction of the camera")),
@facet (
name = IKeyword.CAMERA_ORIENTATION,
name = "camera_orientation",
type = IType.POINT,
optional = true,
doc = @doc (
Expand All @@ -260,15 +267,15 @@
deprecated = "This facet is not used anymore. The orientation of the camera is computed automatically by GAMA",
value = "Allows to define the orientation of the 'up-vector' of the camera")),
@facet (
name = IKeyword.CAMERA_LENS,
name = "camera_lens",
internal = true,
type = IType.INT,
optional = true,
doc = @doc (
deprecated = "Define a separate camera instead in the body of the display using the 'camera' statement and attach the 'lens:' facet to it",
value = "Allows to define the lens of the camera")),
@facet (
name = IKeyword.CAMERA_INTERACTION,
name = "camera_interaction",
type = IType.BOOL,
optional = true,
doc = @doc (
Expand Down Expand Up @@ -434,13 +441,14 @@ public void validate(final IDescription d) {
d.setFacet(TYPE, LabelExpressionDescription.create(LayeredDisplayData.OPENGL));
}

final String camera = d.firstFacetFoundAmong(CAMERA_LOCATION, CAMERA_TARGET, CAMERA_ORIENTATION,
CAMERA_LENS, "z_near", "z_far", IKeyword.CAMERA);
if (!isOpenGLWanted && camera != null) {
d.warning(
"camera-related facets will have no effect on 2D displays. Use 'focus:' instead if you want to change the default zoom and position.",
IGamlIssue.UNUSED, camera);
}
// final String camera = d.firstFacetFoundAmong(CAMERA_LOCATION, CAMERA_TARGET, CAMERA_ORIENTATION,
// CAMERA_LENS, "z_near", "z_far", IKeyword.CAMERA);
// if (!isOpenGLWanted && camera != null) {
// d.warning(
// "camera-related facets will have no effect on 2D displays. Use 'focus:' instead if you want to change the
// default zoom and position.",
// IGamlIssue.UNUSED, camera);
// }

// AD: addressing the deprecation of the "trace:" facet
final IExpressionDescription trace = d.getFacet(TRACE);
Expand All @@ -456,11 +464,11 @@ public void validate(final IDescription d) {
// IExpressionDescription up = d.getFacet("camera_up_vector");
// if (target == null) { target = d.getFacet(CAMERA_ORIENTATION); }
IExpressionDescription target = d.getFacet("camera_look_pos");
if (target == null) { target = d.getFacet(CAMERA_TARGET); }
if (target == null) { target = d.getFacet("camera_target"); }
IExpressionDescription location = d.getFacet("camera_pos");
if (location == null) { location = d.getFacet(CAMERA_LOCATION); }
IExpressionDescription lens = d.getFacet(CAMERA_LENS);
IExpressionDescription locked = d.getFacet(CAMERA_INTERACTION);
if (location == null) { location = d.getFacet("camera_location"); }
IExpressionDescription lens = d.getFacet("camera_lens");
IExpressionDescription locked = d.getFacet("camera_interaction");
String lockedString = locked == null ? "false" : locked.equalsString("true") ? "false" : "true";

// d.removeFacets("camera_pos", "camera_look_pos", "camera_up_vector",CAMERA_LOCATION,
Expand Down
Expand Up @@ -10,6 +10,7 @@
********************************************************************************************************/
package msi.gama.outputs.layers.properties;

import msi.gama.common.interfaces.IKeyword;
import msi.gama.runtime.IScope;
import msi.gaml.compilation.ISymbol;
import msi.gaml.statements.draw.AttributeHolder;
Expand All @@ -34,7 +35,7 @@ public abstract class AbstractDefinition extends AttributeHolder {
*/
public AbstractDefinition(final ISymbol symbol) {
super(symbol);
dynamic = create("dynamic", Types.BOOL, getDefaultDynamicValue());
dynamic = create(IKeyword.DYNAMIC, Types.BOOL, getDefaultDynamicValue());
}

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ public final void init(final IScope scope) {

@Override
public final void refresh(final IScope scope) {
dynamic.refresh("dynamic", scope);
dynamic.refresh(IKeyword.DYNAMIC, scope);
if (shouldRefresh()) {
super.refresh(scope);
this.update(scope);
Expand Down
Expand Up @@ -13,8 +13,6 @@
import msi.gama.common.interfaces.IKeyword;
import msi.gama.outputs.LayeredDisplayOutput;
import msi.gama.outputs.layers.AbstractLayerStatement;
import msi.gama.outputs.layers.ILayerStatement;
import msi.gama.outputs.layers.ILayerStatement.LayerType;
import msi.gama.precompiler.GamlAnnotations.doc;
import msi.gama.precompiler.GamlAnnotations.facet;
import msi.gama.precompiler.GamlAnnotations.facets;
Expand All @@ -41,14 +39,14 @@
@facets (
value = { @facet (
name = IKeyword.NAME,
type = IType.LABEL,
type = IType.STRING,
optional = false,
doc = @doc ("The name of the camera. Either a string or a plain label. Will be used to populate a menu with the other camera presets. "
doc = @doc ("The name of the camera. Will be used to populate a menu with the other camera presets. "
+ "Can provide a value to the 'camera:' facet of the display, which specifies which camera to use."
+ "Using the name 'default' will make it the default of the surrounding display")),
+ "Using the special constant #default will make it the default of the surrounding display")),

@facet (
name = "dynamic",
name = IKeyword.DYNAMIC,
type = IType.BOOL,
optional = true,
doc = @doc ("If true, the location, distance and target are automatically recomputed every step. Default is false. When true, will also set 'locked' to true, to avoid interferences from users")),
Expand Down Expand Up @@ -87,7 +85,7 @@
@doc (
value = "`" + IKeyword.CAMERA
+ "` allows the modeler to define a camera. The display will then be able to choose among the camera defined (either within this statement or globally in GAMA) in a dynamic way. "
+ "Several preset cameras are provided and accessible in the preferences (to choose the default) or in GAML using the keywords #from_above, #from_left, #from_right, #from_up_right, #from_up_left, #from_front, #from_up_front."
+ "Several preset cameras are provided and accessible in the preferences (to choose the default) or in GAML using the keywords #from_above, #from_left, #from_right, #from_up_right, #from_up_left, #from_front, #from_up_front, #isometric."
+ "These cameras are unlocked (so that they can be manipulated by the user), look at the center of the world from a symbolic position, and the distance between this position and the target is equal to the maximum of the width and height of the world's shape. "
+ "These preset cameras can be reused when defining new cameras, since their names can become symbolic positions for them. For instance: camera 'my_camera' location: #from_top distance: 10; will lower (or extend) the distance between the camera and the center of the world to 10. "
+ "camera 'my_camera' locked: true location: #from_up_front target: people(0); will continuously follow the first agent of the people species from the up-front position. ",
Expand Down
Expand Up @@ -41,11 +41,6 @@ public interface ILightDefinition extends INamed {
category = IOperatorCategory.THREED,
doc = @doc ("Represent the 'ambient' type of light")) String ambient = "Ambient light";

/** The regular. */
@constant (
value = "regular",
category = IOperatorCategory.THREED,
doc = @doc ("Represent the 'regular' -- default -- type of light")) String regular = "Regular light source";
/** The direction. */
@constant (
value = "direction",
Expand Down
Expand Up @@ -113,7 +113,7 @@ public LightDefinition(final LightStatement lightStatement) {
public String getName() { return symbol.getName(); }

@Override
public int getId() { return regular.equals(getName()) ? 0 : id; }
public int getId() { return IKeyword.DEFAULT.equals(getName()) ? 0 : id; }

/**
* Sets the id.
Expand Down
Expand Up @@ -47,12 +47,12 @@
omissible = IKeyword.NAME,
value = { @facet (
name = IKeyword.NAME,
type = IType.LABEL,
type = IType.STRING,
optional = false,
doc = @doc ("The name of the light source, must be unique (otherwise the last definition prevails). "
+ "Either a string or a plain label. Will be used to populate a menu where light sources can be easily turned on and off"
+ "Using the name #ambient will allow to redefine or control the ambient light intensity and presence"
+ "Using the name 'default' will replace the default directional light of the surrounding display")),
+ "Will be used to populate a menu where light sources can be easily turned on and off. Special names can be used:"
+ "Using the special constant #ambient will allow to redefine or control the ambient light intensity and presence"
+ "Using the special constant #default will replace the default directional light of the surrounding display")),
@facet (
name = IKeyword.POSITION,
type = IType.POINT,
Expand All @@ -76,7 +76,7 @@
optional = true,
doc = @doc ("the direction of the light (only for direction and spot light). (default value : {0.5,0.5,-1})")),
@facet (
name = IKeyword.SPOT_ANGLE,
name = "spot_angle",
type = IType.FLOAT,
optional = true,
doc = @doc (
Expand All @@ -90,7 +90,7 @@
deprecated = "use 'intensity:' instead",
value = "")),
@facet (
name = IKeyword.DRAW_LIGHT,
name = "draw_light",
type = { IType.BOOL },
optional = true,
doc = @doc (
Expand Down Expand Up @@ -134,16 +134,16 @@
optional = true,
doc = @doc ("If true, draws the light source. (default value if not specified : false).")),
@facet (
name = "dynamic",
name = IKeyword.DYNAMIC,
type = { IType.BOOL },
optional = true,
doc = @doc ("specify if the parameters of the light need to be updated every cycle or treated as constants. (default value : true).")) })
@doc (
value = "`light` allows to define diffusion lights in your 3D display. They must be given a name, which will help track them in the UI. Two names have however special meanings: #ambient, "
+ "which designates the ambient luminosity and color of the scene (with a default intensity of (127,127,127,255)) and #regular, "
+ "which designates the ambient luminosity and color of the scene (with a default intensity of (127,127,127,255)) and #default, "
+ "which designates the default directional light applied to a scene (with a default medium intensity of (127,127,127,255) in the direction given by (0.5,0.5,1)). Redefining a light named #ambient or #regular "
+ "will then modify these default lights (for example changing their color or decactivating them). To be more precise, and given all the default values of the facets, the existence of these two lights is effectively equivalent to redefining:"
+ "light #ambient intensity: 127; light #regular type: #direction intensity: 127 direction: {0.5,0.5,-1};",
+ "will then modify these default lights (for example changing their color or deactivating them). To be more precise, and given all the default values of the facets, the existence of these two lights is effectively equivalent to redefining:"
+ "light #ambient intensity: 127; light #default type: #direction intensity: 127 direction: {0.5,0.5,-1};",
usages = { @usage (
value = "The general syntax is:",
examples = { @example (
Expand Down Expand Up @@ -174,13 +174,13 @@ public void validate(final IDescription desc) {
// Taking care of deprecations
swap(desc, IKeyword.POSITION, IKeyword.LOCATION);
swap(desc, IKeyword.COLOR, "intensity");
swap(desc, IKeyword.SPOT_ANGLE, "angle");
swap(desc, IKeyword.UPDATE, "dynamic");
swap(desc, IKeyword.DRAW_LIGHT, "show");
swap(desc, "spot_angle", IKeyword.ANGLE);
swap(desc, IKeyword.UPDATE, IKeyword.DYNAMIC);
swap(desc, "draw_light", "show");

final IExpressionDescription position = desc.getFacet(IKeyword.LOCATION);
final IExpressionDescription direction = desc.getFacet(IKeyword.DIRECTION);
final IExpressionDescription spotAngle = desc.getFacet("angle");
final IExpressionDescription spotAngle = desc.getFacet(IKeyword.ANGLE);
final IExpressionDescription linearAttenuation = desc.getFacet(IKeyword.LINEAR_ATTENUATION);
final IExpressionDescription quadraticAttenuation = desc.getFacet(IKeyword.QUADRATIC_ATTENUATION);

Expand Down Expand Up @@ -235,17 +235,38 @@ public LightStatement(final IDescription desc) throws GamaRuntimeException {
definition = new LightDefinition(this);
}

/**
* Inits the.
*
* @param scope
* the scope
* @return true, if successful
*/
@Override
protected boolean _init(final IScope scope) {
definition.refresh(scope);
return true;
}

/**
* Gets the type.
*
* @param output
* the output
* @return the type
*/
@Override
public LayerType getType(final LayeredDisplayOutput output) {
return LayerType.LIGHT;
}

/**
* Step.
*
* @param scope
* the scope
* @return true, if successful
*/
@Override
protected boolean _step(final IScope scope) {
definition.refresh(scope);
Expand Down
Expand Up @@ -40,7 +40,7 @@
value = {

@facet (
name = "dynamic",
name = IKeyword.DYNAMIC,
type = IType.BOOL,
optional = true,
doc = @doc ("If true, the rotation is applied every step. Default is false.")),
Expand Down

0 comments on commit d661da1

Please sign in to comment.