More work

This commit is contained in:
Flakebi 2015-04-15 09:01:23 +02:00
parent 78b4634363
commit 2b9a7a2016
2 changed files with 73 additions and 172 deletions

View File

@ -40,14 +40,15 @@ class SkiddingProperties;
*/ */
class AbstractCharacteristics class AbstractCharacteristics
{ {
//FIXME is wheelPosition needed??
/* The following lines are the input for a script that generates code for this class /* The following lines are the input for a script that generates code for this class
Suspension: stiffness, rest, travelCm, expSpringResponse, maxForce Suspension: stiffness, rest, travelCm, expSpringResponse, maxForce
Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse
Turn: radius, timeFullSteer, timeResetSteer Turn: radius(InterpolationArray), timeFullSteer, timeResetSteer, timeFullSteer(InterpolationArray)
Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio
Gear: switchRatio, powerIncrease Gear: switchRatio(std::vector<float>/floatVector), powerIncrease(std::vector<float>/floatVector)
Mass Mass
Wheels: dampingRelaxation, dampingCompression, wheelRadius Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector<float>/floatVector)
Skidding Skidding
Camera: distance, forwardUpAngle, backwardUpAngle Camera: distance, forwardUpAngle, backwardUpAngle
Jump: animationTime Jump: animationTime
@ -58,7 +59,7 @@ class AbstractCharacteristics
Zipper: duration, force, speedGain, speedIncrease, fadeOutTime Zipper: duration, force, speedGain, speedIncrease, fadeOutTime
Swatter: duration, distance, squashDuration, squashSlowdown Swatter: duration, distance, squashDuration, squashSlowdown
Plunger: maxLength, force, duration, speedIncrease, fadeOutTime, inFaceTime Plunger: maxLength, force, duration, speedIncrease, fadeOutTime, inFaceTime
Startup: time, boost Startup: time(std::vector<float>/floatVector), boost(std::vector<float>/floatVector)
Rescue: duration, vertOffset, height Rescue: duration, vertOffset, height
Explosion: duration, radius, invulnerabilityTime Explosion: duration, radius, invulnerabilityTime
Nitro: duration, engineForce, consumption, smallContainer, bigContainer, maxSpeedIncrease, fadeOutTime, max Nitro: duration, engineForce, consumption, smallContainer, bigContainer, maxSpeedIncrease, fadeOutTime, max
@ -68,129 +69,16 @@ class AbstractCharacteristics
public: public:
enum CharacteristicType enum CharacteristicType
{ {
// Suspension // Script-generated content
SUSPENSION_STIFFNESS,
SUSPENSION_REST,
SUSPENSION_TRAVEL_CM,
SUSPENSION_EXP_SPRING_RESPONSE,
SUSPENSION_MAX_FORCE,
// Stability
STABILITY_ROLL_INFLUENCE,
STABILITY_CHASSIS_LINEAR_DAMPING,
STABILITY_CHASSIS_ANGULAR_DAMPING,
STABILITY_DOWNWARD_IMPULSE_FACTOR,
STABILITY_TRACK_CONNECTION_ACCEL,
STABILITY_SMOOTH_FLYING_IMPULSE,
// Turn
TURN_TIME_RESET_STEER,
// Engine
ENGINE_POWER,
ENGINE_MAX_SPEED,
ENGINE_BRAKE_FACTOR,
ENGINE_BRAKE_TIME_INCREASE,
ENGINE_MAX_SPEED_REVERSE_RATIO,
// Mass
MASS,
// Wheels
WHEELS_DAMPING_RELAXATION,
WHEELS_DAMPING_COMPRESSION,
WHEELS_WHEEL_RADIUS,
// Camera
CAMERA_DISTANCE,
CAMERA_FORWARD_UP_ANGLE,
CAMERA_BACKWARD_UP_ANGLE,
// Jump
JUMP_ANIMATION_TIME,
// Lean
LEAN_MAX,
LEAN_SPEED,
// Anvil
ANVIL_DURATION,
ANVIL_WEIGHT,
ANVIL_SPEED_FACTOR,
// Parachute
PARACHUTE_FRICTION,
PARACHUTE_DURATION,
PARACHUTE_DURATION_OTHER,
PARACHUTE_LBOUND_FRANCTION,
PARACHUTE_UBOUND_FRANCTION,
PARACHUTE_MAX_SPEED,
// Bubblegum
BUBBLEGUM_DURATION,
BUBBLEGUM_SPEED_FRACTION,
BUBBLEGUM_TORQUE,
BUBBLEGUM_FADE_IN_TIME,
BUBBLEGUM_SHIELD_DURATION,
// Zipper
ZIPPER_DURATION,
ZIPPER_FORCE,
ZIPPER_SPEED_GAIN,
ZIPPER_SPEED_INCREASE,
ZIPPER_FADE_OUT_TIME,
// Swatter
SWATTER_DURATION,
SWATTER_DISTANCE,
SWATTER_SQUASH_DURATION,
SWATTER_SQUASH_SLOWDOWN,
// Plunger
PLUNGER_MAX_LENGTH,
PLUNGER_FORCE,
PLUNGER_DURATION,
PLUNGER_SPEED_INCREASE,
PLUNGER_FADE_OUT_TIME,
PLUNGER_IN_FACE_TIME,
// Rescue
RESCUE_DURATION,
RESCUE_VERT_OFFSET,
RESCUE_HEIGHT,
// Explosion
EXPLOSION_DURATION,
EXPLOSION_RADIUS,
EXPLOSION_INVULNERABILITY_TIME,
// Nitro
NITRO_DURATION,
NITRO_ENGINE_FORCE,
NITRO_CONSUMPTION,
NITRO_SMALL_CONTAINER,
NITRO_BIG_CONTAINER,
NITRO_MAX_SPEED_INCREASE,
NITRO_FADE_OUT_TIME,
NITRO_MAX,
// Slipstream
SLIPSTREAM_DURATION,
SLIPSTREAM_LENGTH,
SLIPSTREAM_WIDTH,
SLIPSTREAM_COLLECT_TIME,
SLIPSTREAM_USE_TIME,
SLIPSTREAM_ADD_POWER,
SLIPSTREAM_MIN_SPEED,
SLIPSTREAM_MAX_SPEED_INCREASE,
SLIPSTREAM_FADE_OUT_TIME,
// Count // Count
CHARACTERISTIC_COUNT CHARACTERISTIC_COUNT
}; };
private: private:
// Turn
/*InterpolationArray m_turn_radius;
InterpolationArray m_turn_time_full_steer;
// Gear
std::vector<float> m_gear_switch_ratio;
std::vector<float> m_gear_power_increase;
// Wheels
std::vector<Vec3> m_wheel_position;*/
// Skid
/** The skididing properties for this kart, as a separate object in order /** The skididing properties for this kart, as a separate object in order
* to reduce dependencies (and therefore compile time) when changing * to reduce dependencies (and therefore compile time) when changing
* any skidding property. */ * any skidding property. */
/*SkiddingProperties *m_skidding; //SkiddingProperties *m_skidding;
// Startup
std::vector<float> m_startup_time;
std::vector<float> m_startup_boost;*/
public: public:
AbstractCharacteristics(); AbstractCharacteristics();

View File

@ -20,13 +20,54 @@
# This script takes the list from abstract_characteristics.hpp and creates the code # This script takes the list from abstract_characteristics.hpp and creates the code
# An empty line is expected to end the input # An empty line is expected to end the input
class GroupMember:
def __init__(self, name, typeC, typeStr):
self.name = name
self.typeC = typeC
self.typeStr = typeStr
"""E.g. power(std::vector<float>/floatVector)
or speed(InterpolationArray)
The default type is float"""
def parse(content):
typeC = "float"
typeStr = typeC
name = content.strip()
pos = content.find("(")
end = content.find(")", pos)
if pos != -1 and end != -1:
name = content[:pos].strip()
pos2 = content.find("/", pos, end)
if pos2 != -1:
typeC = content[pos + 1:pos2].strip()
typeStr = content[pos2 + 1:end].strip()
else:
typeC = content[pos + 1:end].strip()
typeStr = typeC
return GroupMember(name, typeC, typeStr)
class Group: class Group:
def __init__(self, baseName): def __init__(self, baseName):
self.baseName = baseName self.baseName = baseName
self.subNames = [] self.members = []
def addName(self, name): def addMember(self, content):
self.subNames.append(name) self.members.append(GroupMember.parse(content))
"""E.g. engine: power, gears(std::vector<Gear>/Gears)
or mass(float) or only mass"""
def parse(content):
pos = content.find(":")
if pos == -1:
group = Group("")
group.addMember(content)
return group
else:
group = Group(content[:pos].strip())
for m in content[pos + 1:].split(","):
group.addMember(m)
return group
"""Creates a list of words from a titlecase string""" """Creates a list of words from a titlecase string"""
def toList(name): def toList(name):
@ -43,8 +84,8 @@ def toList(name):
"""titleCase: true = result is titlecase """titleCase: true = result is titlecase
false = result has underscores""" false = result has underscores"""
def joinSubName(g, subName, titleCase): def joinSubName(group, member, titleCase):
words = toList(g.baseName) + toList(subName) words = toList(group.baseName) + toList(member.name)
first = True first = True
if titleCase: if titleCase:
words = map(lambda w: w.title(), words) words = map(lambda w: w.title(), words)
@ -60,54 +101,39 @@ def main():
line = input() line = input()
if len(line) == 0: if len(line) == 0:
break break
groups.append(Group.parse(line))
# Search base name
pos = line.find(":")
if pos != -1:
group = Group(line[:pos].strip())
# Find all subnames
while True:
pos2 = line.find(",", pos + 1)
# Are we already at the end?
if pos2 == -1:
part = line[pos + 1:].strip()
else:
part = line[pos + 1:pos2].strip()
if len(part) != 0:
group.addName(part)
# Find the next one
pos, pos2 = pos2, pos
# We are at the end, so stop searching
if pos == -1:
break
groups.append(group)
else:
# There is not base name, so use the whole line as one word
group = Group(line.strip())
group.addName("")
groups.append(group)
# Find longest name to align the function bodies # Find longest name to align the function bodies
nameLengthTitle = 0 nameLengthTitle = 0
nameLengthUnderscore = 0 nameLengthUnderscore = 0
for g in groups: for g in groups:
for n in g.subNames: for m in g.members:
l = len(joinSubName(g, n, True)) l = len(joinSubName(g, m, True))
if l > nameLengthTitle: if l > nameLengthTitle:
nameLengthTitle = l nameLengthTitle = l
l = len(joinSubName(g, n, False)) l = len(joinSubName(g, m, False))
if l > nameLengthUnderscore: if l > nameLengthUnderscore:
nameLengthUnderscore = l nameLengthUnderscore = l
# Print the results # Print the results
print("Variables ****************************************") print("Enum ****************************************")
for g in groups: for g in groups:
print()
print(" // {0}".format(g.baseName.title())) print(" // {0}".format(g.baseName.title()))
for n in g.subNames: for m in g.members:
print(" {0},".format(joinSubName(g, n, False).upper())) print(" {0},".format(joinSubName(g, m, False).upper()))
print()
print()
print("Getters ****************************************")
for g in groups:
print()
for m in g.members:
nameTitle = joinSubName(g, m, True)
nameUnderscore = joinSubName(g, m, False)
print(" {0} get{1}() const {{ return m_{2}; }}".
format(m.typeC, nameTitle, nameUnderscore))
# Commented out code # Commented out code
"""print("Variables ****************************************") """print("Variables ****************************************")
@ -137,19 +163,6 @@ def main():
line += "1;" line += "1;"
print(line) print(line)
print()
print()
print("Getters ****************************************")
for g in groups:
print()
for n in g.subNames:
nameTitle = joinSubName(g, n, True)
nameUnderscore = joinSubName(g, n, False)
print(" float get{0}(){2} const {{ return m_{1};{3} }}".
format(nameTitle, nameUnderscore, " " * (nameLengthTitle - len(nameTitle)),
" " * (nameLengthUnderscore - len(nameUnderscore))))
print() print()
print() print()
print("Setters ****************************************") print("Setters ****************************************")