From ddb850b149fb56416f575911c40170f22339acb2 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Thu, 16 Apr 2015 17:50:17 +0200 Subject: [PATCH] Add new files --- src/karts/abstract_characteristics.cpp | 1075 +++++++++++++++++++++++- src/karts/abstract_characteristics.hpp | 303 ++++++- src/karts/cached_characteristics.cpp | 170 ++++ src/karts/cached_characteristics.hpp | 55 ++ src/karts/combined_characteristics.cpp | 42 + src/karts/combined_characteristics.hpp | 37 + src/karts/xml_characteristics.cpp | 45 + src/karts/xml_characteristics.hpp | 43 + tools/create_kart_properties.py | 142 +++- 9 files changed, 1823 insertions(+), 89 deletions(-) create mode 100644 src/karts/cached_characteristics.cpp create mode 100644 src/karts/cached_characteristics.hpp create mode 100644 src/karts/combined_characteristics.cpp create mode 100644 src/karts/combined_characteristics.hpp create mode 100644 src/karts/xml_characteristics.cpp create mode 100644 src/karts/xml_characteristics.hpp diff --git a/src/karts/abstract_characteristics.cpp b/src/karts/abstract_characteristics.cpp index 11d543133..c2d03744f 100755 --- a/src/karts/abstract_characteristics.cpp +++ b/src/karts/abstract_characteristics.cpp @@ -19,6 +19,7 @@ #include "karts/abstract_characteristics.hpp" #include "utils/log.hpp" +#include "utils/interpolation_array.hpp" #include @@ -26,36 +27,1080 @@ AbstractCharacteristics::AbstractCharacteristics() { } -float AbstractCharacteristics::processFloat(CharacteristicType type, float value) const +const SkiddingProperties* AbstractCharacteristics::getSkiddingProperties() const { - return getFloat(type); + return nullptr; } -std::vector AbstractCharacteristics::processFloatVector(CharacteristicType type, const std::vector &value) const +void AbstractCharacteristics::process(CharacteristicType type, Value value, bool &isSet) const { - return getFloatVector(type); + Log::warn("AbstractCharacteristics", "This type does not do anything"); } -InterpolationArray AbstractCharacteristics::processInterpolationArray(CharacteristicType type, const InterpolationArray &value) const + +AbstractCharacteristics::ValueType AbstractCharacteristics::getType(CharacteristicType type) { - return getInterpolationArray(type); + switch (type) + { + case CHARACTERISTIC_COUNT: + Log::fatal("AbstractCharacteristics::getType", "Can't get type of COUNT"); + break; + // Script-generated content + case SUSPENSION_STIFFNESS: + return TYPE_FLOAT; + case SUSPENSION_REST: + return TYPE_FLOAT; + case SUSPENSION_TRAVEL_CM: + return TYPE_FLOAT; + case SUSPENSION_EXP_SPRING_RESPONSE: + return TYPE_FLOAT; + case SUSPENSION_MAX_FORCE: + return TYPE_FLOAT; + case STABILITY_ROLL_INFLUENCE: + return TYPE_FLOAT; + case STABILITY_CHASSIS_LINEAR_DAMPING: + return TYPE_FLOAT; + case STABILITY_CHASSIS_ANGULAR_DAMPING: + return TYPE_FLOAT; + case STABILITY_DOWNWARD_IMPULSE_FACTOR: + return TYPE_FLOAT; + case STABILITY_TRACK_CONNECTION_ACCEL: + return TYPE_FLOAT; + case STABILITY_SMOOTH_FLYING_IMPULSE: + return TYPE_FLOAT; + case TURN_RADIUS: + return TYPE_INTERPOLATION_ARRAY; + case TURN_TIME_RESET_STEER: + return TYPE_FLOAT; + case TURN_TIME_FULL_STEER: + return TYPE_INTERPOLATION_ARRAY; + case ENGINE_POWER: + return TYPE_FLOAT; + case ENGINE_MAX_SPEED: + return TYPE_FLOAT; + case ENGINE_BRAKE_FACTOR: + return TYPE_FLOAT; + case ENGINE_BRAKE_TIME_INCREASE: + return TYPE_FLOAT; + case ENGINE_MAX_SPEED_REVERSE_RATIO: + return TYPE_FLOAT; + case GEAR_SWITCH_RATIO: + return TYPE_FLOAT_VECTOR; + case GEAR_POWER_INCREASE: + return TYPE_FLOAT_VECTOR; + case MASS: + return TYPE_FLOAT; + case WHEELS_DAMPING_RELAXATION: + return TYPE_FLOAT; + case WHEELS_DAMPING_COMPRESSION: + return TYPE_FLOAT; + case WHEELS_RADIUS: + return TYPE_FLOAT; + case WHEELS_POSITION: + return TYPE_FLOAT_VECTOR; + case CAMERA_DISTANCE: + return TYPE_FLOAT; + case CAMERA_FORWARD_UP_ANGLE: + return TYPE_FLOAT; + case CAMERA_BACKWARD_UP_ANGLE: + return TYPE_FLOAT; + case JUMP_ANIMATION_TIME: + return TYPE_FLOAT; + case LEAN_MAX: + return TYPE_FLOAT; + case LEAN_SPEED: + return TYPE_FLOAT; + case ANVIL_DURATION: + return TYPE_FLOAT; + case ANVIL_WEIGHT: + return TYPE_FLOAT; + case ANVIL_SPEED_FACTOR: + return TYPE_FLOAT; + case PARACHUTE_FRICTION: + return TYPE_FLOAT; + case PARACHUTE_DURATION: + return TYPE_FLOAT; + case PARACHUTE_DURATION_OTHER: + return TYPE_FLOAT; + case PARACHUTE_LBOUND_FRANCTION: + return TYPE_FLOAT; + case PARACHUTE_UBOUND_FRANCTION: + return TYPE_FLOAT; + case PARACHUTE_MAX_SPEED: + return TYPE_FLOAT; + case BUBBLEGUM_DURATION: + return TYPE_FLOAT; + case BUBBLEGUM_SPEED_FRACTION: + return TYPE_FLOAT; + case BUBBLEGUM_TORQUE: + return TYPE_FLOAT; + case BUBBLEGUM_FADE_IN_TIME: + return TYPE_FLOAT; + case BUBBLEGUM_SHIELD_DURATION: + return TYPE_FLOAT; + case ZIPPER_DURATION: + return TYPE_FLOAT; + case ZIPPER_FORCE: + return TYPE_FLOAT; + case ZIPPER_SPEED_GAIN: + return TYPE_FLOAT; + case ZIPPER_SPEED_INCREASE: + return TYPE_FLOAT; + case ZIPPER_FADE_OUT_TIME: + return TYPE_FLOAT; + case SWATTER_DURATION: + return TYPE_FLOAT; + case SWATTER_DISTANCE: + return TYPE_FLOAT; + case SWATTER_SQUASH_DURATION: + return TYPE_FLOAT; + case SWATTER_SQUASH_SLOWDOWN: + return TYPE_FLOAT; + case PLUNGER_MAX_LENGTH: + return TYPE_FLOAT; + case PLUNGER_FORCE: + return TYPE_FLOAT; + case PLUNGER_DURATION: + return TYPE_FLOAT; + case PLUNGER_SPEED_INCREASE: + return TYPE_FLOAT; + case PLUNGER_FADE_OUT_TIME: + return TYPE_FLOAT; + case PLUNGER_IN_FACE_TIME: + return TYPE_FLOAT; + case STARTUP_TIME: + return TYPE_FLOAT_VECTOR; + case STARTUP_BOOST: + return TYPE_FLOAT_VECTOR; + case RESCUE_DURATION: + return TYPE_FLOAT; + case RESCUE_VERT_OFFSET: + return TYPE_FLOAT; + case RESCUE_HEIGHT: + return TYPE_FLOAT; + case EXPLOSION_DURATION: + return TYPE_FLOAT; + case EXPLOSION_RADIUS: + return TYPE_FLOAT; + case EXPLOSION_INVULNERABILITY_TIME: + return TYPE_FLOAT; + case NITRO_DURATION: + return TYPE_FLOAT; + case NITRO_ENGINE_FORCE: + return TYPE_FLOAT; + case NITRO_CONSUMPTION: + return TYPE_FLOAT; + case NITRO_SMALL_CONTAINER: + return TYPE_FLOAT; + case NITRO_BIG_CONTAINER: + return TYPE_FLOAT; + case NITRO_MAX_SPEED_INCREASE: + return TYPE_FLOAT; + case NITRO_FADE_OUT_TIME: + return TYPE_FLOAT; + case NITRO_MAX: + return TYPE_FLOAT; + case SLIPSTREAM_DURATION: + return TYPE_FLOAT; + case SLIPSTREAM_LENGTH: + return TYPE_FLOAT; + case SLIPSTREAM_WIDTH: + return TYPE_FLOAT; + case SLIPSTREAM_COLLECT_TIME: + return TYPE_FLOAT; + case SLIPSTREAM_USE_TIME: + return TYPE_FLOAT; + case SLIPSTREAM_ADD_POWER: + return TYPE_FLOAT; + case SLIPSTREAM_MIN_SPEED: + return TYPE_FLOAT; + case SLIPSTREAM_MAX_SPEED_INCREASE: + return TYPE_FLOAT; + case SLIPSTREAM_FADE_OUT_TIME: + return TYPE_FLOAT; + } + Log::fatal("AbstractCharacteristics::getType", "Unknown type"); + return TYPE_FLOAT; } -float AbstractCharacteristics::getFloat(CharacteristicType type) const +// Script-generated getter +float AbstractCharacteristics::getSuspensionStiffness() const { - Log::fatal("AbstractCharacteristics", "This type does not support getFloat"); - return NAN; + float result; + bool isSet = false; + process(SUSPENSION_STIFFNESS, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SUSPENSION_STIFFNESS"); + return result; } -std::vector AbstractCharacteristics::getFloatVector(CharacteristicType type) const +float AbstractCharacteristics::getSuspensionRest() const { - Log::fatal("AbstractCharacteristics", "This type does not support getFloatVector"); - return std::vector(); + float result; + bool isSet = false; + process(SUSPENSION_REST, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SUSPENSION_REST"); + return result; } -InterpolationArray AbstractCharacteristics::getInterpolationArray(CharacteristicType type) const +float AbstractCharacteristics::getSuspensionTravelCm() const { - Log::fatal("AbstractCharacteristics", "This type does not support getInterpolationArray"); - return InterpolationArray(); + float result; + bool isSet = false; + process(SUSPENSION_TRAVEL_CM, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SUSPENSION_TRAVEL_CM"); + return result; +} + +float AbstractCharacteristics::getSuspensionExpSpringResponse() const +{ + float result; + bool isSet = false; + process(SUSPENSION_EXP_SPRING_RESPONSE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SUSPENSION_EXP_SPRING_RESPONSE"); + return result; +} + +float AbstractCharacteristics::getSuspensionMaxForce() const +{ + float result; + bool isSet = false; + process(SUSPENSION_MAX_FORCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SUSPENSION_MAX_FORCE"); + return result; +} + + +float AbstractCharacteristics::getStabilityRollInfluence() const +{ + float result; + bool isSet = false; + process(STABILITY_ROLL_INFLUENCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_ROLL_INFLUENCE"); + return result; +} + +float AbstractCharacteristics::getStabilityChassisLinearDamping() const +{ + float result; + bool isSet = false; + process(STABILITY_CHASSIS_LINEAR_DAMPING, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_CHASSIS_LINEAR_DAMPING"); + return result; +} + +float AbstractCharacteristics::getStabilityChassisAngularDamping() const +{ + float result; + bool isSet = false; + process(STABILITY_CHASSIS_ANGULAR_DAMPING, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_CHASSIS_ANGULAR_DAMPING"); + return result; +} + +float AbstractCharacteristics::getStabilityDownwardImpulseFactor() const +{ + float result; + bool isSet = false; + process(STABILITY_DOWNWARD_IMPULSE_FACTOR, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_DOWNWARD_IMPULSE_FACTOR"); + return result; +} + +float AbstractCharacteristics::getStabilityTrackConnectionAccel() const +{ + float result; + bool isSet = false; + process(STABILITY_TRACK_CONNECTION_ACCEL, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_TRACK_CONNECTION_ACCEL"); + return result; +} + +float AbstractCharacteristics::getStabilitySmoothFlyingImpulse() const +{ + float result; + bool isSet = false; + process(STABILITY_SMOOTH_FLYING_IMPULSE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STABILITY_SMOOTH_FLYING_IMPULSE"); + return result; +} + + +InterpolationArray&& AbstractCharacteristics::getTurnRadius() const +{ + InterpolationArray result; + bool isSet = false; + process(TURN_RADIUS, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic TURN_RADIUS"); + return std::move(result); +} + +float AbstractCharacteristics::getTurnTimeResetSteer() const +{ + float result; + bool isSet = false; + process(TURN_TIME_RESET_STEER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic TURN_TIME_RESET_STEER"); + return result; +} + +InterpolationArray&& AbstractCharacteristics::getTurnTimeFullSteer() const +{ + InterpolationArray result; + bool isSet = false; + process(TURN_TIME_FULL_STEER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic TURN_TIME_FULL_STEER"); + return std::move(result); +} + + +float AbstractCharacteristics::getEnginePower() const +{ + float result; + bool isSet = false; + process(ENGINE_POWER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ENGINE_POWER"); + return result; +} + +float AbstractCharacteristics::getEngineMaxSpeed() const +{ + float result; + bool isSet = false; + process(ENGINE_MAX_SPEED, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ENGINE_MAX_SPEED"); + return result; +} + +float AbstractCharacteristics::getEngineBrakeFactor() const +{ + float result; + bool isSet = false; + process(ENGINE_BRAKE_FACTOR, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ENGINE_BRAKE_FACTOR"); + return result; +} + +float AbstractCharacteristics::getEngineBrakeTimeIncrease() const +{ + float result; + bool isSet = false; + process(ENGINE_BRAKE_TIME_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ENGINE_BRAKE_TIME_INCREASE"); + return result; +} + +float AbstractCharacteristics::getEngineMaxSpeedReverseRatio() const +{ + float result; + bool isSet = false; + process(ENGINE_MAX_SPEED_REVERSE_RATIO, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ENGINE_MAX_SPEED_REVERSE_RATIO"); + return result; +} + + +std::vector&& AbstractCharacteristics::getGearSwitchRatio() const +{ + std::vector result; + bool isSet = false; + process(GEAR_SWITCH_RATIO, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic GEAR_SWITCH_RATIO"); + return std::move(result); +} + +std::vector&& AbstractCharacteristics::getGearPowerIncrease() const +{ + std::vector result; + bool isSet = false; + process(GEAR_POWER_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic GEAR_POWER_INCREASE"); + return std::move(result); +} + + +float AbstractCharacteristics::getMass() const +{ + float result; + bool isSet = false; + process(MASS, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic MASS"); + return result; +} + + +float AbstractCharacteristics::getWheelsDampingRelaxation() const +{ + float result; + bool isSet = false; + process(WHEELS_DAMPING_RELAXATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic WHEELS_DAMPING_RELAXATION"); + return result; +} + +float AbstractCharacteristics::getWheelsDampingCompression() const +{ + float result; + bool isSet = false; + process(WHEELS_DAMPING_COMPRESSION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic WHEELS_DAMPING_COMPRESSION"); + return result; +} + +float AbstractCharacteristics::getWheelsRadius() const +{ + float result; + bool isSet = false; + process(WHEELS_RADIUS, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic WHEELS_RADIUS"); + return result; +} + +std::vector&& AbstractCharacteristics::getWheelsPosition() const +{ + std::vector result; + bool isSet = false; + process(WHEELS_POSITION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic WHEELS_POSITION"); + return std::move(result); +} + + +float AbstractCharacteristics::getCameraDistance() const +{ + float result; + bool isSet = false; + process(CAMERA_DISTANCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic CAMERA_DISTANCE"); + return result; +} + +float AbstractCharacteristics::getCameraForwardUpAngle() const +{ + float result; + bool isSet = false; + process(CAMERA_FORWARD_UP_ANGLE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic CAMERA_FORWARD_UP_ANGLE"); + return result; +} + +float AbstractCharacteristics::getCameraBackwardUpAngle() const +{ + float result; + bool isSet = false; + process(CAMERA_BACKWARD_UP_ANGLE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic CAMERA_BACKWARD_UP_ANGLE"); + return result; +} + + +float AbstractCharacteristics::getJumpAnimationTime() const +{ + float result; + bool isSet = false; + process(JUMP_ANIMATION_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic JUMP_ANIMATION_TIME"); + return result; +} + + +float AbstractCharacteristics::getLeanMax() const +{ + float result; + bool isSet = false; + process(LEAN_MAX, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic LEAN_MAX"); + return result; +} + +float AbstractCharacteristics::getLeanSpeed() const +{ + float result; + bool isSet = false; + process(LEAN_SPEED, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic LEAN_SPEED"); + return result; +} + + +float AbstractCharacteristics::getAnvilDuration() const +{ + float result; + bool isSet = false; + process(ANVIL_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ANVIL_DURATION"); + return result; +} + +float AbstractCharacteristics::getAnvilWeight() const +{ + float result; + bool isSet = false; + process(ANVIL_WEIGHT, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ANVIL_WEIGHT"); + return result; +} + +float AbstractCharacteristics::getAnvilSpeedFactor() const +{ + float result; + bool isSet = false; + process(ANVIL_SPEED_FACTOR, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ANVIL_SPEED_FACTOR"); + return result; +} + + +float AbstractCharacteristics::getParachuteFriction() const +{ + float result; + bool isSet = false; + process(PARACHUTE_FRICTION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_FRICTION"); + return result; +} + +float AbstractCharacteristics::getParachuteDuration() const +{ + float result; + bool isSet = false; + process(PARACHUTE_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_DURATION"); + return result; +} + +float AbstractCharacteristics::getParachuteDurationOther() const +{ + float result; + bool isSet = false; + process(PARACHUTE_DURATION_OTHER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_DURATION_OTHER"); + return result; +} + +float AbstractCharacteristics::getParachuteLboundFranction() const +{ + float result; + bool isSet = false; + process(PARACHUTE_LBOUND_FRANCTION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_LBOUND_FRANCTION"); + return result; +} + +float AbstractCharacteristics::getParachuteUboundFranction() const +{ + float result; + bool isSet = false; + process(PARACHUTE_UBOUND_FRANCTION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_UBOUND_FRANCTION"); + return result; +} + +float AbstractCharacteristics::getParachuteMaxSpeed() const +{ + float result; + bool isSet = false; + process(PARACHUTE_MAX_SPEED, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PARACHUTE_MAX_SPEED"); + return result; +} + + +float AbstractCharacteristics::getBubblegumDuration() const +{ + float result; + bool isSet = false; + process(BUBBLEGUM_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic BUBBLEGUM_DURATION"); + return result; +} + +float AbstractCharacteristics::getBubblegumSpeedFraction() const +{ + float result; + bool isSet = false; + process(BUBBLEGUM_SPEED_FRACTION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic BUBBLEGUM_SPEED_FRACTION"); + return result; +} + +float AbstractCharacteristics::getBubblegumTorque() const +{ + float result; + bool isSet = false; + process(BUBBLEGUM_TORQUE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic BUBBLEGUM_TORQUE"); + return result; +} + +float AbstractCharacteristics::getBubblegumFadeInTime() const +{ + float result; + bool isSet = false; + process(BUBBLEGUM_FADE_IN_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic BUBBLEGUM_FADE_IN_TIME"); + return result; +} + +float AbstractCharacteristics::getBubblegumShieldDuration() const +{ + float result; + bool isSet = false; + process(BUBBLEGUM_SHIELD_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic BUBBLEGUM_SHIELD_DURATION"); + return result; +} + + +float AbstractCharacteristics::getZipperDuration() const +{ + float result; + bool isSet = false; + process(ZIPPER_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ZIPPER_DURATION"); + return result; +} + +float AbstractCharacteristics::getZipperForce() const +{ + float result; + bool isSet = false; + process(ZIPPER_FORCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ZIPPER_FORCE"); + return result; +} + +float AbstractCharacteristics::getZipperSpeedGain() const +{ + float result; + bool isSet = false; + process(ZIPPER_SPEED_GAIN, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ZIPPER_SPEED_GAIN"); + return result; +} + +float AbstractCharacteristics::getZipperSpeedIncrease() const +{ + float result; + bool isSet = false; + process(ZIPPER_SPEED_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ZIPPER_SPEED_INCREASE"); + return result; +} + +float AbstractCharacteristics::getZipperFadeOutTime() const +{ + float result; + bool isSet = false; + process(ZIPPER_FADE_OUT_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic ZIPPER_FADE_OUT_TIME"); + return result; +} + + +float AbstractCharacteristics::getSwatterDuration() const +{ + float result; + bool isSet = false; + process(SWATTER_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SWATTER_DURATION"); + return result; +} + +float AbstractCharacteristics::getSwatterDistance() const +{ + float result; + bool isSet = false; + process(SWATTER_DISTANCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SWATTER_DISTANCE"); + return result; +} + +float AbstractCharacteristics::getSwatterSquashDuration() const +{ + float result; + bool isSet = false; + process(SWATTER_SQUASH_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SWATTER_SQUASH_DURATION"); + return result; +} + +float AbstractCharacteristics::getSwatterSquashSlowdown() const +{ + float result; + bool isSet = false; + process(SWATTER_SQUASH_SLOWDOWN, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SWATTER_SQUASH_SLOWDOWN"); + return result; +} + + +float AbstractCharacteristics::getPlungerMaxLength() const +{ + float result; + bool isSet = false; + process(PLUNGER_MAX_LENGTH, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_MAX_LENGTH"); + return result; +} + +float AbstractCharacteristics::getPlungerForce() const +{ + float result; + bool isSet = false; + process(PLUNGER_FORCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_FORCE"); + return result; +} + +float AbstractCharacteristics::getPlungerDuration() const +{ + float result; + bool isSet = false; + process(PLUNGER_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_DURATION"); + return result; +} + +float AbstractCharacteristics::getPlungerSpeedIncrease() const +{ + float result; + bool isSet = false; + process(PLUNGER_SPEED_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_SPEED_INCREASE"); + return result; +} + +float AbstractCharacteristics::getPlungerFadeOutTime() const +{ + float result; + bool isSet = false; + process(PLUNGER_FADE_OUT_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_FADE_OUT_TIME"); + return result; +} + +float AbstractCharacteristics::getPlungerInFaceTime() const +{ + float result; + bool isSet = false; + process(PLUNGER_IN_FACE_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic PLUNGER_IN_FACE_TIME"); + return result; +} + + +std::vector&& AbstractCharacteristics::getStartupTime() const +{ + std::vector result; + bool isSet = false; + process(STARTUP_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STARTUP_TIME"); + return std::move(result); +} + +std::vector&& AbstractCharacteristics::getStartupBoost() const +{ + std::vector result; + bool isSet = false; + process(STARTUP_BOOST, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic STARTUP_BOOST"); + return std::move(result); +} + + +float AbstractCharacteristics::getRescueDuration() const +{ + float result; + bool isSet = false; + process(RESCUE_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic RESCUE_DURATION"); + return result; +} + +float AbstractCharacteristics::getRescueVertOffset() const +{ + float result; + bool isSet = false; + process(RESCUE_VERT_OFFSET, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic RESCUE_VERT_OFFSET"); + return result; +} + +float AbstractCharacteristics::getRescueHeight() const +{ + float result; + bool isSet = false; + process(RESCUE_HEIGHT, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic RESCUE_HEIGHT"); + return result; +} + + +float AbstractCharacteristics::getExplosionDuration() const +{ + float result; + bool isSet = false; + process(EXPLOSION_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic EXPLOSION_DURATION"); + return result; +} + +float AbstractCharacteristics::getExplosionRadius() const +{ + float result; + bool isSet = false; + process(EXPLOSION_RADIUS, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic EXPLOSION_RADIUS"); + return result; +} + +float AbstractCharacteristics::getExplosionInvulnerabilityTime() const +{ + float result; + bool isSet = false; + process(EXPLOSION_INVULNERABILITY_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic EXPLOSION_INVULNERABILITY_TIME"); + return result; +} + + +float AbstractCharacteristics::getNitroDuration() const +{ + float result; + bool isSet = false; + process(NITRO_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_DURATION"); + return result; +} + +float AbstractCharacteristics::getNitroEngineForce() const +{ + float result; + bool isSet = false; + process(NITRO_ENGINE_FORCE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_ENGINE_FORCE"); + return result; +} + +float AbstractCharacteristics::getNitroConsumption() const +{ + float result; + bool isSet = false; + process(NITRO_CONSUMPTION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_CONSUMPTION"); + return result; +} + +float AbstractCharacteristics::getNitroSmallContainer() const +{ + float result; + bool isSet = false; + process(NITRO_SMALL_CONTAINER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_SMALL_CONTAINER"); + return result; +} + +float AbstractCharacteristics::getNitroBigContainer() const +{ + float result; + bool isSet = false; + process(NITRO_BIG_CONTAINER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_BIG_CONTAINER"); + return result; +} + +float AbstractCharacteristics::getNitroMaxSpeedIncrease() const +{ + float result; + bool isSet = false; + process(NITRO_MAX_SPEED_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_MAX_SPEED_INCREASE"); + return result; +} + +float AbstractCharacteristics::getNitroFadeOutTime() const +{ + float result; + bool isSet = false; + process(NITRO_FADE_OUT_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_FADE_OUT_TIME"); + return result; +} + +float AbstractCharacteristics::getNitroMax() const +{ + float result; + bool isSet = false; + process(NITRO_MAX, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic NITRO_MAX"); + return result; +} + + +float AbstractCharacteristics::getSlipstreamDuration() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_DURATION, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_DURATION"); + return result; +} + +float AbstractCharacteristics::getSlipstreamLength() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_LENGTH, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_LENGTH"); + return result; +} + +float AbstractCharacteristics::getSlipstreamWidth() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_WIDTH, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_WIDTH"); + return result; +} + +float AbstractCharacteristics::getSlipstreamCollectTime() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_COLLECT_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_COLLECT_TIME"); + return result; +} + +float AbstractCharacteristics::getSlipstreamUseTime() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_USE_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_USE_TIME"); + return result; +} + +float AbstractCharacteristics::getSlipstreamAddPower() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_ADD_POWER, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_ADD_POWER"); + return result; +} + +float AbstractCharacteristics::getSlipstreamMinSpeed() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_MIN_SPEED, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_MIN_SPEED"); + return result; +} + +float AbstractCharacteristics::getSlipstreamMaxSpeedIncrease() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_MAX_SPEED_INCREASE, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_MAX_SPEED_INCREASE"); + return result; +} + +float AbstractCharacteristics::getSlipstreamFadeOutTime() const +{ + float result; + bool isSet = false; + process(SLIPSTREAM_FADE_OUT_TIME, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic SLIPSTREAM_FADE_OUT_TIME"); + return result; } diff --git a/src/karts/abstract_characteristics.hpp b/src/karts/abstract_characteristics.hpp index c19146c1d..755c1878f 100755 --- a/src/karts/abstract_characteristics.hpp +++ b/src/karts/abstract_characteristics.hpp @@ -19,12 +19,10 @@ #ifndef HEADER_ABSTRACT_CHARACTERISTICS_HPP #define HEADER_ABSTRACT_CHARACTERISTICS_HPP -#include "utils/interpolation_array.hpp" -#include "utils/vec3.hpp" - #include class SkiddingProperties; +class InterpolationArray; /** * Characteristics are the properties of a kart that influence @@ -40,36 +38,156 @@ 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(InterpolationArray), timeFullSteer, timeResetSteer, timeFullSteer(InterpolationArray) - Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio - Gear: switchRatio(std::vector/floatVector), powerIncrease(std::vector/floatVector) - Mass - Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector/floatVector) - Skidding - Camera: distance, forwardUpAngle, backwardUpAngle - Jump: animationTime - Lean: max, speed - Anvil: duration, weight, speedFactor - Parachute: friction, duration, durationOther, lboundFranction, uboundFranction, maxSpeed - Bubblegum: duration, speedFraction, torque, fadeInTime, shieldDuration - Zipper: duration, force, speedGain, speedIncrease, fadeOutTime - Swatter: duration, distance, squashDuration, squashSlowdown - Plunger: maxLength, force, duration, speedIncrease, fadeOutTime, inFaceTime - 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 - Slipstream: duration, length, width, collectTime, useTime, addPower, minSpeed, maxSpeedIncrease, fadeOutTime - */ - public: + union Value + { + float *f; + std::vector *fv; + InterpolationArray *ia; + + Value(float *f) : f(f) {} + Value(std::vector *fv) : fv(fv) {} + Value(InterpolationArray *ia) : ia(ia) {} + }; + + enum ValueType + { + TYPE_FLOAT, + TYPE_FLOAT_VECTOR, + TYPE_INTERPOLATION_ARRAY + }; + enum CharacteristicType { // Script-generated content + // 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_RADIUS, + TURN_TIME_FULL_STEER, + TURN_TIME_RESET_STEER, + + // Engine + ENGINE_POWER, + ENGINE_MAX_SPEED, + ENGINE_BRAKE_FACTOR, + ENGINE_BRAKE_TIME_INCREASE, + ENGINE_MAX_SPEED_REVERSE_RATIO, + + // Gear + GEAR_SWITCH_RATIO, + GEAR_POWER_INCREASE, + + // Mass + MASS, + + // Wheels + WHEELS_DAMPING_RELAXATION, + WHEELS_DAMPING_COMPRESSION, + WHEELS_RADIUS, + WHEELS_POSITION, + + // 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, + + // Startup + STARTUP_TIME, + STARTUP_BOOST, + + // 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 CHARACTERISTIC_COUNT @@ -85,15 +203,126 @@ public: virtual const SkiddingProperties* getSkiddingProperties() const; - virtual float processFloat(CharacteristicType type, float value) const; - virtual std::vector processFloatVector(CharacteristicType type, - const std::vector &value) const; - virtual InterpolationArray processInterpolationArray(CharacteristicType type, - const InterpolationArray &value) const; + /** + * TODO + * + * \param type The characteristic that should be modified. + * \param value The current value and result at the same time. + * \param isSet If the current value was already set (so it can be used + * for computations. + */ + virtual void process(CharacteristicType type, Value value, bool &isSet) const; - virtual float getFloat(CharacteristicType type) const; - virtual std::vector getFloatVector(CharacteristicType type) const; - virtual InterpolationArray getInterpolationArray(CharacteristicType type) const; + static ValueType getType(CharacteristicType type); + + // Script-generated content + float getSuspensionStiffness() const; + float getSuspensionRest() const; + float getSuspensionTravelCm() const; + float getSuspensionExpSpringResponse() const; + float getSuspensionMaxForce() const; + + float getStabilityRollInfluence() const; + float getStabilityChassisLinearDamping() const; + float getStabilityChassisAngularDamping() const; + float getStabilityDownwardImpulseFactor() const; + float getStabilityTrackConnectionAccel() const; + float getStabilitySmoothFlyingImpulse() const; + + InterpolationArray&& getTurnRadius() const; + float getTurnTimeResetSteer() const; + InterpolationArray&& getTurnTimeFullSteer() const; + + float getEnginePower() const; + float getEngineMaxSpeed() const; + float getEngineBrakeFactor() const; + float getEngineBrakeTimeIncrease() const; + float getEngineMaxSpeedReverseRatio() const; + + std::vector&& getGearSwitchRatio() const; + std::vector&& getGearPowerIncrease() const; + + float getMass() const; + + float getWheelsDampingRelaxation() const; + float getWheelsDampingCompression() const; + float getWheelsRadius() const; + std::vector&& getWheelsPosition() const; + + float getCameraDistance() const; + float getCameraForwardUpAngle() const; + float getCameraBackwardUpAngle() const; + + float getJumpAnimationTime() const; + + float getLeanMax() const; + float getLeanSpeed() const; + + float getAnvilDuration() const; + float getAnvilWeight() const; + float getAnvilSpeedFactor() const; + + float getParachuteFriction() const; + float getParachuteDuration() const; + float getParachuteDurationOther() const; + float getParachuteLboundFranction() const; + float getParachuteUboundFranction() const; + float getParachuteMaxSpeed() const; + + float getBubblegumDuration() const; + float getBubblegumSpeedFraction() const; + float getBubblegumTorque() const; + float getBubblegumFadeInTime() const; + float getBubblegumShieldDuration() const; + + float getZipperDuration() const; + float getZipperForce() const; + float getZipperSpeedGain() const; + float getZipperSpeedIncrease() const; + float getZipperFadeOutTime() const; + + float getSwatterDuration() const; + float getSwatterDistance() const; + float getSwatterSquashDuration() const; + float getSwatterSquashSlowdown() const; + + float getPlungerMaxLength() const; + float getPlungerForce() const; + float getPlungerDuration() const; + float getPlungerSpeedIncrease() const; + float getPlungerFadeOutTime() const; + float getPlungerInFaceTime() const; + + std::vector&& getStartupTime() const; + std::vector&& getStartupBoost() const; + + float getRescueDuration() const; + float getRescueVertOffset() const; + float getRescueHeight() const; + + float getExplosionDuration() const; + float getExplosionRadius() const; + float getExplosionInvulnerabilityTime() const; + + float getNitroDuration() const; + float getNitroEngineForce() const; + float getNitroConsumption() const; + float getNitroSmallContainer() const; + float getNitroBigContainer() const; + float getNitroMaxSpeedIncrease() const; + float getNitroFadeOutTime() const; + float getNitroMax() const; + + float getSlipstreamDuration() const; + float getSlipstreamLength() const; + float getSlipstreamWidth() const; + float getSlipstreamCollectTime() const; + float getSlipstreamUseTime() const; + float getSlipstreamAddPower() const; + float getSlipstreamMinSpeed() const; + float getSlipstreamMaxSpeedIncrease() const; + float getSlipstreamFadeOutTime() const; }; #endif + diff --git a/src/karts/cached_characteristics.cpp b/src/karts/cached_characteristics.cpp new file mode 100644 index 000000000..1a3dd4d1f --- /dev/null +++ b/src/karts/cached_characteristics.cpp @@ -0,0 +1,170 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "karts/cached_characteristics.hpp" + +#include "utils/interpolation_array.hpp" + +CachedCharacteristics::CachedCharacteristics(const AbstractCharacteristics *origin) : + m_values(CHARACTERISTIC_COUNT), + m_origin(origin) +{ + updateSource(); +} + +CachedCharacteristics::~CachedCharacteristics() +{ + // Delete all not-null values + for (int i = 0; i < CHARACTERISTIC_COUNT; i++) + { + SaveValue &v = m_values[i]; + if (v.content) + { + switch (getType(static_cast(i))) + { + case TYPE_FLOAT: + delete static_cast(v.content); + break; + case TYPE_FLOAT_VECTOR: + delete static_cast*>(v.content); + break; + case TYPE_INTERPOLATION_ARRAY: + delete static_cast(v.content); + break; + } + v.content = nullptr; + } + } +} + +void CachedCharacteristics::updateSource() +{ + for (int i = 0; i < CHARACTERISTIC_COUNT; i++) + { + SaveValue &v = m_values[i]; + + bool isSet = false; + switch (getType(static_cast(i))) + { + case TYPE_FLOAT: + { + float value; + float *ptr = static_cast(v.content); + m_origin->process(static_cast(i), &value, isSet); + if (isSet) + { + if (!ptr) + { + float *newPtr = new float(); + v.content = newPtr; + ptr = newPtr; + } + *ptr = value; + } + else + { + if (ptr) + { + delete ptr; + v.content = nullptr; + } + } + break; + } + case TYPE_FLOAT_VECTOR: + { + std::vector value; + std::vector *ptr = static_cast*>(v.content); + m_origin->process(static_cast(i), &value, isSet); + if (isSet) + { + if (!ptr) + { + std::vector *newPtr = new std::vector(); + v.content = newPtr; + ptr = newPtr; + } + *ptr = value; + } + else + { + if (ptr) + { + delete ptr; + v.content = nullptr; + } + } + break; + } + break; + case TYPE_INTERPOLATION_ARRAY: + { + InterpolationArray value; + InterpolationArray *ptr = static_cast(v.content); + m_origin->process(static_cast(i), &value, isSet); + if (isSet) + { + if (!ptr) + { + InterpolationArray *newPtr = new InterpolationArray(); + v.content = newPtr; + ptr = newPtr; + } + *ptr = value; + } + else + { + if (ptr) + { + delete ptr; + v.content = nullptr; + } + } + break; + } + break; + } + } +} + +const SkiddingProperties* CachedCharacteristics::getSkiddingProperties() const +{ + return m_origin->getSkiddingProperties(); +} + +void CachedCharacteristics::process(CharacteristicType type, Value value, bool &isSet) const +{ + void *v = m_values[type].content; + if (v) + { + switch (getType(type)) + { + case TYPE_FLOAT: + *value.f = *static_cast(v); + break; + case TYPE_FLOAT_VECTOR: + *value.fv = *static_cast*>(v); + break; + case TYPE_INTERPOLATION_ARRAY: + *value.ia = *static_cast(v); + break; + } + isSet = true; + } +} + diff --git a/src/karts/cached_characteristics.hpp b/src/karts/cached_characteristics.hpp new file mode 100644 index 000000000..dafcb5fce --- /dev/null +++ b/src/karts/cached_characteristics.hpp @@ -0,0 +1,55 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_CACHED_CHARACTERISTICS_HPP +#define HEADER_CACHED_CHARACTERISTICS_HPP + +#include "karts/abstract_characteristics.hpp" + +class CachedCharacteristics : public AbstractCharacteristics +{ +private: + /** Used to store a value. */ + struct SaveValue + { + void *content; + + SaveValue() : content(nullptr) {} + SaveValue(void *content) : content(content) {} + }; + + /** All values for a characteristic. A nullptr means it is not set. */ + std::vector m_values; + + /** The characteristics that hold the original values. */ + const AbstractCharacteristics *m_origin; + +public: + CachedCharacteristics(const AbstractCharacteristics *origin); + CachedCharacteristics(const CachedCharacteristics &characteristics) = delete; + virtual ~CachedCharacteristics(); + + /** Fetches all cached values from the original source. */ + void updateSource(); + + virtual const SkiddingProperties* getSkiddingProperties() const; + virtual void process(CharacteristicType type, Value value, bool &isSet) const; +}; + +#endif + diff --git a/src/karts/combined_characteristics.cpp b/src/karts/combined_characteristics.cpp new file mode 100644 index 000000000..adbe0db11 --- /dev/null +++ b/src/karts/combined_characteristics.cpp @@ -0,0 +1,42 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "karts/combined_characteristics.hpp" + +void CombinedCharacteristics::addCharacteristic(const AbstractCharacteristics *characteristic) +{ + m_childs.push_back(characteristic); +} + +const SkiddingProperties* CombinedCharacteristics::getSkiddingProperties() const +{ + for (const AbstractCharacteristics *characteristic : m_childs) + { + const SkiddingProperties *skid = characteristic->getSkiddingProperties(); + if (skid) + return skid; + } + return nullptr; +} + +void CombinedCharacteristics::process(CharacteristicType type, Value value, bool &isSet) const +{ + for (const AbstractCharacteristics *characteristic : m_childs) + characteristic->process(type, value, isSet); +} + diff --git a/src/karts/combined_characteristics.hpp b/src/karts/combined_characteristics.hpp new file mode 100644 index 000000000..35d0455a1 --- /dev/null +++ b/src/karts/combined_characteristics.hpp @@ -0,0 +1,37 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_COMBINDED_CHARACTERISTICS_HPP +#define HEADER_COMBINDED_CHARACTERISTICS_HPP + +#include "karts/abstract_characteristics.hpp" + +class CombinedCharacteristics : public AbstractCharacteristics +{ +private: + std::vector m_childs; + +public: + void addCharacteristic(const AbstractCharacteristics *characteristic); + + virtual const SkiddingProperties* getSkiddingProperties() const; + virtual void process(CharacteristicType type, Value value, bool &isSet) const; +}; + +#endif + diff --git a/src/karts/xml_characteristics.cpp b/src/karts/xml_characteristics.cpp new file mode 100644 index 000000000..9648467dd --- /dev/null +++ b/src/karts/xml_characteristics.cpp @@ -0,0 +1,45 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "karts/xml_characteristics.hpp" + +#include "io/xml_node.hpp" + +XmlCharacteristics::XmlCharacteristics(const std::string &filename) : + m_values(CHARACTERISTIC_COUNT), + m_skidding(nullptr) +{ + if (!filename.empty()) + load(filename); +} + +const SkiddingProperties* XmlCharacteristics::getSkiddingProperties() const +{ + return m_skidding; +} + +void XmlCharacteristics::process(CharacteristicType type, Value value, bool &isSet) const +{ + //TODO +} + +void XmlCharacteristics::load(const std::string &filename) +{ + const XMLNode* root = new XMLNode(filename); +} + diff --git a/src/karts/xml_characteristics.hpp b/src/karts/xml_characteristics.hpp new file mode 100644 index 000000000..c13da504b --- /dev/null +++ b/src/karts/xml_characteristics.hpp @@ -0,0 +1,43 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_XML_CHARACTERISTICS_HPP +#define HEADER_XML_CHARACTERISTICS_HPP + +#include "karts/abstract_characteristics.hpp" + +#include + +class XmlCharacteristics : public AbstractCharacteristics +{ +private: + /** The computation that was read from an xml file */ + std::vector m_values; + SkiddingProperties *m_skidding; + +public: + XmlCharacteristics(const std::string &filename = ""); + + virtual const SkiddingProperties* getSkiddingProperties() const; + virtual void process(CharacteristicType type, Value value, bool &isSet) const; + + void load(const std::string &filename); +}; + +#endif + diff --git a/tools/create_kart_properties.py b/tools/create_kart_properties.py index 0006eac0a..327d7dc64 100755 --- a/tools/create_kart_properties.py +++ b/tools/create_kart_properties.py @@ -17,8 +17,36 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# This script takes the list from abstract_characteristics.hpp and creates the code -# An empty line is expected to end the input +# This script creates the output for the AbstractCharacteristics +# It takes an argument that specifies what the output of the script should be. +# Possibilities are enum, defs, getter and getType + +import sys + +# Input data +#FIXME is wheelPosition needed?? +characteristics = """Suspension: stiffness, rest, travelCm, expSpringResponse, maxForce +Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse +Turn: radius(InterpolationArray), timeResetSteer, timeFullSteer(InterpolationArray) +Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio +Gear: switchRatio(std::vector/floatVector), powerIncrease(std::vector/floatVector) +Mass +Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector/floatVector) +Camera: distance, forwardUpAngle, backwardUpAngle +Jump: animationTime +Lean: max, speed +Anvil: duration, weight, speedFactor +Parachute: friction, duration, durationOther, lboundFranction, uboundFranction, maxSpeed +Bubblegum: duration, speedFraction, torque, fadeInTime, shieldDuration +Zipper: duration, force, speedGain, speedIncrease, fadeOutTime +Swatter: duration, distance, squashDuration, squashSlowdown +Plunger: maxLength, force, duration, speedIncrease, fadeOutTime, inFaceTime +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 +Slipstream: duration, length, width, collectTime, useTime, addPower, minSpeed, maxSpeedIncrease, fadeOutTime""" + class GroupMember: def __init__(self, name, typeC, typeStr): @@ -26,6 +54,9 @@ class GroupMember: self.typeC = typeC self.typeStr = typeStr + def shouldMove(self): + return self.typeC != "float" + """E.g. power(std::vector/floatVector) or speed(InterpolationArray) The default type is float""" @@ -55,6 +86,11 @@ class Group: def addMember(self, content): self.members.append(GroupMember.parse(content)) + def getBaseName(self): + if len(self.baseName) == 0 and len(self.members) > 0: + return self.members[0].name + return self.baseName + """E.g. engine: power, gears(std::vector/Gears) or mass(float) or only mass""" def parse(content): @@ -88,52 +124,83 @@ def joinSubName(group, member, titleCase): words = toList(group.baseName) + toList(member.name) first = True if titleCase: - words = map(lambda w: w.title(), words) + words = [w.title() for w in words] return "".join(words) else: return "_".join(words) def main(): - # All variables are saved here in titlecase - groups = [] - # Read in lines - while True: - line = input() - if len(line) == 0: - break - groups.append(Group.parse(line)) + # Find out what to do + if len(sys.argv) == 1: + print("Please specify what you want to know [enum/defs/getter/getType]") + return + task = sys.argv[1] + + groups = [Group.parse(line) for line in characteristics.split("\n")] # Find longest name to align the function bodies - nameLengthTitle = 0 - nameLengthUnderscore = 0 - for g in groups: - for m in g.members: - l = len(joinSubName(g, m, True)) - if l > nameLengthTitle: - nameLengthTitle = l - l = len(joinSubName(g, m, False)) - if l > nameLengthUnderscore: - nameLengthUnderscore = l + #nameLengthTitle = 0 + #nameLengthUnderscore = 0 + #for g in groups: + # for m in g.members: + # l = len(joinSubName(g, m, True)) + # if l > nameLengthTitle: + # nameLengthTitle = l + # l = len(joinSubName(g, m, False)) + # if l > nameLengthUnderscore: + # nameLengthUnderscore = l # Print the results - print("Enum ****************************************") - for g in groups: - print() - print(" // {0}".format(g.baseName.title())) - for m in g.members: - print(" {0},".format(joinSubName(g, m, False).upper())) + if task == "enum": + for g in groups: + print() + print(" // {0}".format(g.getBaseName().title())) + for m in g.members: + print(" {0},".format(joinSubName(g, m, False).upper())) + elif task == "defs": + for g in groups: + print() + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + if m.shouldMove(): + typeC = m.typeC + "&&" + else: + typeC = m.typeC - print() - print() - print("Getters ****************************************") + print(" {0} get{1}() const;". + format(typeC, nameTitle, nameUnderscore)) + elif task == "getter": + for g in groups: + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + if m.shouldMove(): + typeC = m.typeC + "&&" + result = "std::move(result)" + else: + typeC = m.typeC + result = "result" - 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)) + print("""{3} AbstractCharacteristics::get{1}() const +{{ + {0} result; + bool isSet = false; + process({2}, &result, isSet); + if (!isSet) + Log::fatal("AbstractCharacteristics", "Can't get characteristic {2}"); + return {4}; +}} +""".format(m.typeC, nameTitle, nameUnderscore.upper(), typeC, result)) + elif task == "getType": + for g in groups: + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + print(""" case {0}:\n return TYPE_{1};""". + format(nameUnderscore.upper(), "_".join(toList(m.typeStr)).upper())) + else: + print("Unknown task") # Commented out code """print("Variables ****************************************") @@ -177,3 +244,4 @@ def main(): if __name__ == '__main__': main() +