From 2b9a7a2016a74733b30839f3886eea4ef62b8afc Mon Sep 17 00:00:00 2001 From: Flakebi Date: Wed, 15 Apr 2015 09:01:23 +0200 Subject: [PATCH] More work --- src/karts/abstract_characteristics.hpp | 126 ++----------------------- tools/create_kart_properties.py | 119 ++++++++++++----------- 2 files changed, 73 insertions(+), 172 deletions(-) diff --git a/src/karts/abstract_characteristics.hpp b/src/karts/abstract_characteristics.hpp index de1042143..c19146c1d 100755 --- a/src/karts/abstract_characteristics.hpp +++ b/src/karts/abstract_characteristics.hpp @@ -40,14 +40,15 @@ class SkiddingProperties; */ class AbstractCharacteristics { + //FIXME is wheelPosition needed?? /* The following lines are the input for a script that generates code for this class Suspension: stiffness, rest, travelCm, expSpringResponse, maxForce Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse - Turn: radius, timeFullSteer, timeResetSteer + Turn: radius(InterpolationArray), timeFullSteer, timeResetSteer, timeFullSteer(InterpolationArray) Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio - Gear: switchRatio, powerIncrease + Gear: switchRatio(std::vector/floatVector), powerIncrease(std::vector/floatVector) Mass - Wheels: dampingRelaxation, dampingCompression, wheelRadius + Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector/floatVector) Skidding Camera: distance, forwardUpAngle, backwardUpAngle Jump: animationTime @@ -58,7 +59,7 @@ class AbstractCharacteristics Zipper: duration, force, speedGain, speedIncrease, fadeOutTime Swatter: duration, distance, squashDuration, squashSlowdown Plunger: maxLength, force, duration, speedIncrease, fadeOutTime, inFaceTime - Startup: time, boost + Startup: time(std::vector/floatVector), boost(std::vector/floatVector) Rescue: duration, vertOffset, height Explosion: duration, radius, invulnerabilityTime Nitro: duration, engineForce, consumption, smallContainer, bigContainer, maxSpeedIncrease, fadeOutTime, max @@ -68,129 +69,16 @@ class AbstractCharacteristics public: enum CharacteristicType { - // Suspension - 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, + // Script-generated content // Count CHARACTERISTIC_COUNT }; private: - // Turn - /*InterpolationArray m_turn_radius; - InterpolationArray m_turn_time_full_steer; - - // Gear - std::vector m_gear_switch_ratio; - std::vector m_gear_power_increase; - - // Wheels - std::vector m_wheel_position;*/ - - // Skid /** The skididing properties for this kart, as a separate object in order * to reduce dependencies (and therefore compile time) when changing * any skidding property. */ - /*SkiddingProperties *m_skidding; - - // Startup - std::vector m_startup_time; - std::vector m_startup_boost;*/ + //SkiddingProperties *m_skidding; public: AbstractCharacteristics(); diff --git a/tools/create_kart_properties.py b/tools/create_kart_properties.py index 9d6dedddb..0006eac0a 100755 --- a/tools/create_kart_properties.py +++ b/tools/create_kart_properties.py @@ -20,13 +20,54 @@ # This script takes the list from abstract_characteristics.hpp and creates the code # 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/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: def __init__(self, baseName): self.baseName = baseName - self.subNames = [] + self.members = [] - def addName(self, name): - self.subNames.append(name) + def addMember(self, content): + self.members.append(GroupMember.parse(content)) + + """E.g. engine: power, gears(std::vector/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""" def toList(name): @@ -43,8 +84,8 @@ def toList(name): """titleCase: true = result is titlecase false = result has underscores""" -def joinSubName(g, subName, titleCase): - words = toList(g.baseName) + toList(subName) +def joinSubName(group, member, titleCase): + words = toList(group.baseName) + toList(member.name) first = True if titleCase: words = map(lambda w: w.title(), words) @@ -60,54 +101,39 @@ def main(): line = input() if len(line) == 0: break - - # 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) + groups.append(Group.parse(line)) # Find longest name to align the function bodies nameLengthTitle = 0 nameLengthUnderscore = 0 for g in groups: - for n in g.subNames: - l = len(joinSubName(g, n, True)) + for m in g.members: + l = len(joinSubName(g, m, True)) if l > nameLengthTitle: nameLengthTitle = l - l = len(joinSubName(g, n, False)) + l = len(joinSubName(g, m, False)) if l > nameLengthUnderscore: nameLengthUnderscore = l # Print the results - print("Variables ****************************************") + print("Enum ****************************************") for g in groups: + print() print(" // {0}".format(g.baseName.title())) - for n in g.subNames: - print(" {0},".format(joinSubName(g, n, False).upper())) + for m in g.members: + 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 """print("Variables ****************************************") @@ -137,19 +163,6 @@ def main(): line += "1;" 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("Setters ****************************************")