Add new files
This commit is contained in:
parent
2b9a7a2016
commit
ddb850b149
File diff suppressed because it is too large
Load Diff
@ -19,12 +19,10 @@
|
|||||||
#ifndef HEADER_ABSTRACT_CHARACTERISTICS_HPP
|
#ifndef HEADER_ABSTRACT_CHARACTERISTICS_HPP
|
||||||
#define HEADER_ABSTRACT_CHARACTERISTICS_HPP
|
#define HEADER_ABSTRACT_CHARACTERISTICS_HPP
|
||||||
|
|
||||||
#include "utils/interpolation_array.hpp"
|
|
||||||
#include "utils/vec3.hpp"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class SkiddingProperties;
|
class SkiddingProperties;
|
||||||
|
class InterpolationArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Characteristics are the properties of a kart that influence
|
* Characteristics are the properties of a kart that influence
|
||||||
@ -40,36 +38,156 @@ 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
|
|
||||||
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<float>/floatVector), powerIncrease(std::vector<float>/floatVector)
|
|
||||||
Mass
|
|
||||||
Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector<float>/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<float>/floatVector), boost(std::vector<float>/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:
|
public:
|
||||||
|
union Value
|
||||||
|
{
|
||||||
|
float *f;
|
||||||
|
std::vector<float> *fv;
|
||||||
|
InterpolationArray *ia;
|
||||||
|
|
||||||
|
Value(float *f) : f(f) {}
|
||||||
|
Value(std::vector<float> *fv) : fv(fv) {}
|
||||||
|
Value(InterpolationArray *ia) : ia(ia) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ValueType
|
||||||
|
{
|
||||||
|
TYPE_FLOAT,
|
||||||
|
TYPE_FLOAT_VECTOR,
|
||||||
|
TYPE_INTERPOLATION_ARRAY
|
||||||
|
};
|
||||||
|
|
||||||
enum CharacteristicType
|
enum CharacteristicType
|
||||||
{
|
{
|
||||||
// Script-generated content
|
// 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
|
// Count
|
||||||
CHARACTERISTIC_COUNT
|
CHARACTERISTIC_COUNT
|
||||||
@ -85,15 +203,126 @@ public:
|
|||||||
|
|
||||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||||
|
|
||||||
virtual float processFloat(CharacteristicType type, float value) const;
|
/**
|
||||||
virtual std::vector<float> processFloatVector(CharacteristicType type,
|
* TODO
|
||||||
const std::vector<float> &value) const;
|
*
|
||||||
virtual InterpolationArray processInterpolationArray(CharacteristicType type,
|
* \param type The characteristic that should be modified.
|
||||||
const InterpolationArray &value) const;
|
* \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;
|
static ValueType getType(CharacteristicType type);
|
||||||
virtual std::vector<float> getFloatVector(CharacteristicType type) const;
|
|
||||||
virtual InterpolationArray getInterpolationArray(CharacteristicType type) const;
|
// 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<float>&& getGearSwitchRatio() const;
|
||||||
|
std::vector<float>&& getGearPowerIncrease() const;
|
||||||
|
|
||||||
|
float getMass() const;
|
||||||
|
|
||||||
|
float getWheelsDampingRelaxation() const;
|
||||||
|
float getWheelsDampingCompression() const;
|
||||||
|
float getWheelsRadius() const;
|
||||||
|
std::vector<float>&& 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<float>&& getStartupTime() const;
|
||||||
|
std::vector<float>&& 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
|
#endif
|
||||||
|
|
||||||
|
170
src/karts/cached_characteristics.cpp
Normal file
170
src/karts/cached_characteristics.cpp
Normal file
@ -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<CharacteristicType>(i)))
|
||||||
|
{
|
||||||
|
case TYPE_FLOAT:
|
||||||
|
delete static_cast<float*>(v.content);
|
||||||
|
break;
|
||||||
|
case TYPE_FLOAT_VECTOR:
|
||||||
|
delete static_cast<std::vector<float>*>(v.content);
|
||||||
|
break;
|
||||||
|
case TYPE_INTERPOLATION_ARRAY:
|
||||||
|
delete static_cast<InterpolationArray*>(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<CharacteristicType>(i)))
|
||||||
|
{
|
||||||
|
case TYPE_FLOAT:
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
float *ptr = static_cast<float*>(v.content);
|
||||||
|
m_origin->process(static_cast<CharacteristicType>(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<float> value;
|
||||||
|
std::vector<float> *ptr = static_cast<std::vector<float>*>(v.content);
|
||||||
|
m_origin->process(static_cast<CharacteristicType>(i), &value, isSet);
|
||||||
|
if (isSet)
|
||||||
|
{
|
||||||
|
if (!ptr)
|
||||||
|
{
|
||||||
|
std::vector<float> *newPtr = new std::vector<float>();
|
||||||
|
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<InterpolationArray*>(v.content);
|
||||||
|
m_origin->process(static_cast<CharacteristicType>(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<float*>(v);
|
||||||
|
break;
|
||||||
|
case TYPE_FLOAT_VECTOR:
|
||||||
|
*value.fv = *static_cast<std::vector<float>*>(v);
|
||||||
|
break;
|
||||||
|
case TYPE_INTERPOLATION_ARRAY:
|
||||||
|
*value.ia = *static_cast<InterpolationArray*>(v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
isSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
55
src/karts/cached_characteristics.hpp
Normal file
55
src/karts/cached_characteristics.hpp
Normal file
@ -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<SaveValue> 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
|
||||||
|
|
42
src/karts/combined_characteristics.cpp
Normal file
42
src/karts/combined_characteristics.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
37
src/karts/combined_characteristics.hpp
Normal file
37
src/karts/combined_characteristics.hpp
Normal file
@ -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<const AbstractCharacteristics*> m_childs;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void addCharacteristic(const AbstractCharacteristics *characteristic);
|
||||||
|
|
||||||
|
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||||
|
virtual void process(CharacteristicType type, Value value, bool &isSet) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
45
src/karts/xml_characteristics.cpp
Normal file
45
src/karts/xml_characteristics.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
43
src/karts/xml_characteristics.hpp
Normal file
43
src/karts/xml_characteristics.hpp
Normal file
@ -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 <string>
|
||||||
|
|
||||||
|
class XmlCharacteristics : public AbstractCharacteristics
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/** The computation that was read from an xml file */
|
||||||
|
std::vector<std::string> 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
|
||||||
|
|
@ -17,8 +17,36 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# 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
|
# This script creates the output for the AbstractCharacteristics
|
||||||
# An empty line is expected to end the input
|
# 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<float>/floatVector), powerIncrease(std::vector<float>/floatVector)
|
||||||
|
Mass
|
||||||
|
Wheels: dampingRelaxation, dampingCompression, radius, position(std::vector<float>/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<float>/floatVector), boost(std::vector<float>/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:
|
class GroupMember:
|
||||||
def __init__(self, name, typeC, typeStr):
|
def __init__(self, name, typeC, typeStr):
|
||||||
@ -26,6 +54,9 @@ class GroupMember:
|
|||||||
self.typeC = typeC
|
self.typeC = typeC
|
||||||
self.typeStr = typeStr
|
self.typeStr = typeStr
|
||||||
|
|
||||||
|
def shouldMove(self):
|
||||||
|
return self.typeC != "float"
|
||||||
|
|
||||||
"""E.g. power(std::vector<float>/floatVector)
|
"""E.g. power(std::vector<float>/floatVector)
|
||||||
or speed(InterpolationArray)
|
or speed(InterpolationArray)
|
||||||
The default type is float"""
|
The default type is float"""
|
||||||
@ -55,6 +86,11 @@ class Group:
|
|||||||
def addMember(self, content):
|
def addMember(self, content):
|
||||||
self.members.append(GroupMember.parse(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<Gear>/Gears)
|
"""E.g. engine: power, gears(std::vector<Gear>/Gears)
|
||||||
or mass(float) or only mass"""
|
or mass(float) or only mass"""
|
||||||
def parse(content):
|
def parse(content):
|
||||||
@ -88,52 +124,83 @@ def joinSubName(group, member, titleCase):
|
|||||||
words = toList(group.baseName) + toList(member.name)
|
words = toList(group.baseName) + toList(member.name)
|
||||||
first = True
|
first = True
|
||||||
if titleCase:
|
if titleCase:
|
||||||
words = map(lambda w: w.title(), words)
|
words = [w.title() for w in words]
|
||||||
return "".join(words)
|
return "".join(words)
|
||||||
else:
|
else:
|
||||||
return "_".join(words)
|
return "_".join(words)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# All variables are saved here in titlecase
|
# Find out what to do
|
||||||
groups = []
|
if len(sys.argv) == 1:
|
||||||
# Read in lines
|
print("Please specify what you want to know [enum/defs/getter/getType]")
|
||||||
while True:
|
return
|
||||||
line = input()
|
task = sys.argv[1]
|
||||||
if len(line) == 0:
|
|
||||||
break
|
groups = [Group.parse(line) for line in characteristics.split("\n")]
|
||||||
groups.append(Group.parse(line))
|
|
||||||
|
|
||||||
# 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 m in g.members:
|
# for m in g.members:
|
||||||
l = len(joinSubName(g, m, True))
|
# l = len(joinSubName(g, m, True))
|
||||||
if l > nameLengthTitle:
|
# if l > nameLengthTitle:
|
||||||
nameLengthTitle = l
|
# nameLengthTitle = l
|
||||||
l = len(joinSubName(g, m, False))
|
# l = len(joinSubName(g, m, False))
|
||||||
if l > nameLengthUnderscore:
|
# if l > nameLengthUnderscore:
|
||||||
nameLengthUnderscore = l
|
# nameLengthUnderscore = l
|
||||||
|
|
||||||
# Print the results
|
# Print the results
|
||||||
print("Enum ****************************************")
|
if task == "enum":
|
||||||
for g in groups:
|
for g in groups:
|
||||||
print()
|
print()
|
||||||
print(" // {0}".format(g.baseName.title()))
|
print(" // {0}".format(g.getBaseName().title()))
|
||||||
for m in g.members:
|
for m in g.members:
|
||||||
print(" {0},".format(joinSubName(g, m, False).upper()))
|
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(" {0} get{1}() const;".
|
||||||
print()
|
format(typeC, nameTitle, nameUnderscore))
|
||||||
print("Getters ****************************************")
|
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("""{3} AbstractCharacteristics::get{1}() const
|
||||||
print()
|
{{
|
||||||
for m in g.members:
|
{0} result;
|
||||||
nameTitle = joinSubName(g, m, True)
|
bool isSet = false;
|
||||||
nameUnderscore = joinSubName(g, m, False)
|
process({2}, &result, isSet);
|
||||||
print(" {0} get{1}() const {{ return m_{2}; }}".
|
if (!isSet)
|
||||||
format(m.typeC, nameTitle, nameUnderscore))
|
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
|
# Commented out code
|
||||||
"""print("Variables ****************************************")
|
"""print("Variables ****************************************")
|
||||||
@ -177,3 +244,4 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user