source: java/main/src/main/java/com/framsticks/model/Creature.java @ 86

Last change on this file since 86 was 86, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

File size: 4.5 KB
Line 
1package com.framsticks.model;
2
3import com.framsticks.params.annotations.FramsClassAnnotation;
4import com.framsticks.params.annotations.ParamAnnotation;
5import com.framsticks.util.math.Point3d;
6
7import java.util.ArrayList;
8import java.util.List;
9
10@FramsClassAnnotation
11public class Creature {
12
13        @ParamAnnotation
14        public String name;
15
16        @ParamAnnotation
17        public String genotype;
18
19        @ParamAnnotation
20        public String info;
21
22        @ParamAnnotation
23        public Object group;
24
25        @ParamAnnotation(id = "gnum")
26        public int generation;
27
28        @ParamAnnotation(id = "buildproblems")
29        public int buildProblems;
30
31        @ParamAnnotation(id = "energ0")
32        public double startingEnergy;
33
34        @ParamAnnotation(id = "idleen")
35        public double idlePowerConsumption;
36
37        @ParamAnnotation
38        public double energy;
39
40        @ParamAnnotation(id = "energy_p")
41        public double energyIncome;
42
43        @ParamAnnotation(id = "energy_m")
44        public double energyCosts;
45
46        @ParamAnnotation(id = "energy_b")
47        public double energyBalance;
48
49        @ParamAnnotation(id = "perf")
50        public int performanceCalculation;
51
52        @ParamAnnotation(id = "nnenabled")
53        public boolean neuralNetworkEnabled;
54
55        @ParamAnnotation(id = "bodysim")
56        public boolean bodySimulation;
57
58        @ParamAnnotation(id = "selfcol")
59        public boolean selfCollisions;
60
61        @ParamAnnotation(id = "lifespan")
62        public int lifeSpan;
63
64        @ParamAnnotation
65        public double distance;
66
67        @ParamAnnotation(id = "c_velocity")
68        public double currentVelocity;
69
70        @ParamAnnotation(id = "c_vertvelocity")
71        public double currentVerticalVelocity;
72
73        @ParamAnnotation(id = "c_vertpos")
74        public double currentVerticalPosition;
75
76        @ParamAnnotation(id = "velocity")
77        public double averageVelocity;
78
79        @ParamAnnotation(id = "vertvel")
80        public double averageVerticalVelocity;
81
82        @ParamAnnotation(id = "vertpos")
83        public double averageVerticalPosition;
84
85        @ParamAnnotation
86        public double pos_x, pos_y, pos_z;
87
88        public Point3d getPosition() { return new Point3d(pos_x, pos_y, pos_z) ; }
89        public void setPosition(Point3d pos) { pos_x = pos.x; pos_y = pos.y; pos_z = pos.z; }
90
91        @ParamAnnotation
92        public double size_x, size_y, size_z;
93
94        public Point3d getBoundingBox() { return new Point3d(size_x, size_y, size_z) ; }
95        public void setBoundingBox(Point3d size) { size_x = size.x; size_y = size.y; size_z = size.z; }
96
97
98        /** center_x, center_y, center_z*/
99        @ParamAnnotation
100        public double center_x, center_y, center_z;
101
102        public Point3d getCenter() { return new Point3d(center_x, center_y, center_z) ; }
103        public void setCenter(Point3d center) { center_x = center.x; center_y = center.y; center_z = center.z; }
104
105        @ParamAnnotation
106        public int getNumparts() { return parts.size(); }
107        @ParamAnnotation
108        public void setNumparts(int numparts) { }
109
110        @ParamAnnotation
111        public int getNumjoints() { return joints.size(); }
112        @ParamAnnotation
113        public void setNumjoints(int numjoints) { }
114
115        @ParamAnnotation
116        public int getNumneurons() { return neurons.size(); }
117        @ParamAnnotation
118        public void setNumneurons(int numneurons) { }
119
120        public Object[] userFields = new Object[3];
121        @ParamAnnotation
122        public Object getUser1() { return userFields[0]; }
123        @ParamAnnotation
124        public void setUser1(Object user1) { userFields[0] = user1; }
125
126        @ParamAnnotation
127        public Object getUser2() { return userFields[1]; }
128        @ParamAnnotation
129        public void setUser2(Object user2) { userFields[1] = user2; }
130
131        @ParamAnnotation
132        public Object getUser3() { return userFields[2]; }
133        @ParamAnnotation
134        public void setUser3(Object user3) { userFields[2] = user3; }
135
136        @ParamAnnotation(id = "selfmask")
137        public int selfCollisionMask;
138
139        @ParamAnnotation(id = "othermask")
140        public int otherCollisionMask;
141
142        @ParamAnnotation(id = "selfcolstate")
143        public boolean selfCollisionsState;
144
145        @ParamAnnotation
146        public String uid;
147
148        @ParamAnnotation
149        public int index;
150
151        @ParamAnnotation
152        public final List<Part> parts = new ArrayList<Part>();
153        @ParamAnnotation
154        public final List<Joint> joints = new ArrayList<Joint>();
155        @ParamAnnotation
156        public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
157
158        public final List<Part> getParts() { return parts; }
159        public final List<Joint> getJoints() { return joints; }
160        public final List<NeuroDef> getNeuroDefs() { return neurodefs; }
161
162        @ParamAnnotation
163        public final List<MechPart> mechparts = new ArrayList<MechPart>();
164        @ParamAnnotation
165        public final List<MechJoint> mechjoints = new ArrayList<MechJoint>();
166        @ParamAnnotation
167        public final List<Neuro> neurons = new ArrayList<Neuro>();
168
169        public final List<MechPart> getMechParts() { return mechparts; }
170        public final List<MechJoint> getMechJoints() { return mechjoints; }
171        public final List<Neuro> getNeurons() { return neurons; }
172
173}
Note: See TracBrowser for help on using the repository browser.