Merge remote-tracking branch 'origin/lossless_compression' into dev

This commit is contained in:
hiker 2018-11-13 23:04:38 +11:00
commit 4a4bc7248c
10 changed files with 81 additions and 49 deletions

View File

@ -426,7 +426,6 @@ void IconButtonWidget::setLabelFont()
}
// -----------------------------------------------------------------------------
void IconButtonWidget::setVisible(bool visible)
{
Widget::setVisible(visible);
@ -434,3 +433,9 @@ void IconButtonWidget::setVisible(bool visible)
if (m_label != NULL)
m_label->setVisible(visible);
}
// -----------------------------------------------------------------------------
void IconButtonWidget::setText(const wchar_t *s)
{
m_label->setText(s);
}

View File

@ -170,6 +170,8 @@ namespace GUIEngine
Widget::elementRemoved();
m_label = NULL;
}
// --------------------------------------------------------------------
virtual void setText(const wchar_t *s) OVERRIDE;
};
}

View File

@ -2291,7 +2291,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
const LinearWorld *lw = dynamic_cast<LinearWorld*>(World::getWorld());
if(m_kart_properties->getTerrainImpulseType()
==KartProperties::IMPULSE_NORMAL &&
m_vehicle->getCentralImpulseTime()<=0 )
m_vehicle->getCentralImpulseTicks()<=0 )
{
// Restrict impule to plane defined by gravity (i.e. X/Z plane).
// This avoids the problem that karts can be pushed up, e.g. above
@ -2312,7 +2312,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
m_bounce_back_ticks = 0;
impulse = Vec3(0, 0, 0);
//m_vehicle->setTimedCentralImpulse(0.1f, impulse);
m_vehicle->setTimedCentralImpulse(0.0, impulse);
m_vehicle->setTimedCentralImpulse(0, impulse);
}
// If there is a quad graph, push the kart towards the previous
// graph node center (we have to use the previous point since the
@ -2320,7 +2320,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
// would be pushed forward).
else if(m_kart_properties->getTerrainImpulseType()
==KartProperties::IMPULSE_TO_DRIVELINE &&
lw && m_vehicle->getCentralImpulseTime()<=0 &&
lw && m_vehicle->getCentralImpulseTicks()<=0 &&
Track::getCurrentTrack()->isPushBackEnabled())
{
int sector = lw->getSectorForKart(this);
@ -2338,7 +2338,8 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
impulse = Vec3(0, 0, -1); // Arbitrary
impulse *= m_kart_properties->getCollisionTerrainImpulse();
m_bounce_back_ticks = stk_config->time2Ticks(0.2f);
m_vehicle->setTimedCentralImpulse(0.1f, impulse);
m_vehicle->setTimedCentralImpulse(
(uint16_t)stk_config->time2Ticks(0.1f), impulse);
}
}

14
src/karts/kart_rewinder.cpp Normal file → Executable file
View File

@ -154,12 +154,12 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
buffer->add(body->getLinearVelocity());
buffer->add(body->getAngularVelocity());
buffer->addFloat(m_vehicle->getTimedRotationTime());
buffer->addUInt16(m_vehicle->getTimedRotationTicks());
buffer->add(m_vehicle->getTimedRotation());
// For collision rewind
buffer->addUInt16(m_bounce_back_ticks);
buffer->addFloat(m_vehicle->getCentralImpulseTime());
buffer->addUInt16(m_vehicle->getCentralImpulseTicks());
buffer->add(m_vehicle->getAdditionalImpulse());
// 3) Steering and other player controls
@ -261,15 +261,17 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
setTrans(m_transfrom_from_network);
}
float time_rot = buffer->getFloat();
uint16_t time_rot = buffer->getUInt16();
// Set timed rotation divides by time_rot
m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3());
m_vehicle->setTimedRotation(time_rot,
stk_config->ticks2Time(time_rot)
* buffer->getVec3());
// Collision rewind
m_bounce_back_ticks = buffer->getUInt16();
float central_impulse_time = buffer->getFloat();
uint16_t central_impulse_ticks = buffer->getUInt16();
Vec3 additional_impulse = buffer->getVec3();
m_vehicle->setTimedCentralImpulse(central_impulse_time,
m_vehicle->setTimedCentralImpulse(central_impulse_ticks,
additional_impulse, true/*rewind*/);
// For the raycast to determine the current material under the kart

View File

@ -536,7 +536,8 @@ void Skidding::update(int ticks, bool is_on_ground,
t = std::min(t, kp->getSkidRevertVisualTime());
btVector3 rot(0, m_visual_rotation * kp->getSkidPostSkidRotateFactor(), 0);
m_kart->getVehicle()->setTimedRotation(t, rot);
m_kart->getVehicle()->setTimedRotation(
(uint16_t)stk_config->time2Ticks(t), rot);
// skid_time is used to count backwards for the GFX
m_skid_time = stk_config->time2Ticks(t);
if(bonus_time>0)

View File

@ -446,6 +446,7 @@ void ServerLobby::asynchronousUpdate()
{
if (ServerConfig::m_owner_less)
{
m_game_setup->update(true/*remove_disconnected_players*/);
int player_size = m_game_setup->getPlayerCount();
if ((player_size >= ServerConfig::m_min_start_game_players ||
m_game_setup->isGrandPrixStarted()) &&
@ -458,10 +459,14 @@ void ServerLobby::asynchronousUpdate()
else if (player_size < ServerConfig::m_min_start_game_players &&
!m_game_setup->isGrandPrixStarted())
{
resetPeersReady();
m_timeout.store(std::numeric_limits<int64_t>::max());
}
if (m_timeout.load() < (int64_t)StkTime::getRealTimeMs())
if (m_timeout.load() < (int64_t)StkTime::getRealTimeMs() ||
(checkPeersReady() &&
player_size >= ServerConfig::m_min_start_game_players))
{
resetPeersReady();
startSelection();
return;
}
@ -826,6 +831,11 @@ void ServerLobby::startSelection(const Event *event)
m_state.load());
return;
}
if (ServerConfig::m_owner_less)
{
m_peers_ready.at(event->getPeerSP()) = true;
return;
}
if (event->getPeerSP() != m_server_owner.lock())
{
Log::warn("ServerLobby",

View File

@ -120,9 +120,9 @@ void btKart::reset()
m_allow_sliding = false;
m_num_wheels_on_ground = 0;
m_additional_impulse = btVector3(0,0,0);
m_time_additional_impulse = 0;
m_ticks_additional_impulse = 0;
m_additional_rotation = btVector3(0,0,0);
m_time_additional_rotation = 0;
m_ticks_additional_rotation = 0;
m_max_speed = -1.0f;
m_min_speed = 0.0f;
@ -507,23 +507,21 @@ void btKart::updateVehicle( btScalar step )
// Apply additional impulse set by supertuxkart
// --------------------------------------------
if(m_time_additional_impulse>0)
if(m_ticks_additional_impulse>0)
{
float dt = step > m_time_additional_impulse
? m_time_additional_impulse
: step;
// We have fixed timestep
float dt = stk_config->ticks2Time(1);
m_chassisBody->applyCentralImpulse(m_additional_impulse*dt);
m_time_additional_impulse -= dt;
m_ticks_additional_impulse--;
}
// Apply additional rotation set by supertuxkart
// ---------------------------------------------
if(m_time_additional_rotation>0)
if(m_ticks_additional_rotation>0)
{
btTransform &t = m_chassisBody->getWorldTransform();
float dt = step > m_time_additional_rotation
? m_time_additional_rotation
: step;
// We have fixed timestep
float dt = stk_config->ticks2Time(1);
btQuaternion add_rot(m_additional_rotation.getY()*dt,
m_additional_rotation.getX()*dt,
m_additional_rotation.getZ()*dt);
@ -537,7 +535,7 @@ void btKart::updateVehicle( btScalar step )
// kart, or a strongly 'visual jolt' of the kart
btTransform &iwt=m_chassisBody->getInterpolationWorldTransform();
iwt.setRotation(iwt.getRotation()*add_rot);
m_time_additional_rotation -= dt;
m_ticks_additional_rotation--;
}
adjustSpeed(m_min_speed, m_max_speed);
} // updateVehicle
@ -792,7 +790,7 @@ void btKart::updateFriction(btScalar timeStep)
m_forwardImpulse[wheel] = rollingFriction;
if(m_time_additional_impulse>0)
if(m_ticks_additional_impulse>0)
{
sliding = true;
m_wheelInfo[wheel].m_skidInfo = 0.0f;
@ -822,7 +820,7 @@ void btKart::updateFriction(btScalar timeStep)
// Note: don't reset zipper speed, or the kart rewinder will
// get incorrect zipper information.
if (sliding && (m_allow_sliding || m_time_additional_impulse>0) )
if (sliding && (m_allow_sliding || m_ticks_additional_impulse>0) )
{
for (int wheel = 0; wheel < getNumWheels(); wheel++)
{

View File

@ -19,6 +19,8 @@ class btDynamicsWorld;
#include "BulletDynamics/Vehicle/btWheelInfo.h"
#include "BulletDynamics/Dynamics/btActionInterface.h"
#include "config/stk_config.hpp"
class btVehicleTuning;
class Kart;
struct btWheelContactPoint;
@ -79,13 +81,13 @@ private:
btVector3 m_additional_impulse;
/** The time the additional impulse should be applied. */
float m_time_additional_impulse;
uint16_t m_ticks_additional_impulse;
/** Additional rotation that is applied over a certain amount of time. */
btVector3 m_additional_rotation;
/** Duration over which the additional rotation is applied. */
float m_time_additional_rotation;
uint16_t m_ticks_additional_rotation;
/** The rigid body that is the chassis of the kart. */
btRigidBody *m_chassisBody;
@ -218,36 +220,37 @@ public:
unsigned int getNumWheelsOnGround() const {return m_num_wheels_on_ground;}
// ------------------------------------------------------------------------
/** Sets an impulse that is applied for a certain amount of time.
* \param t Time for the impulse to be active.
* \param t Ticks for the impulse to be active.
* \param imp The impulse to apply. */
void setTimedCentralImpulse(float t, const btVector3 &imp,
void setTimedCentralImpulse(uint16_t t, const btVector3 &imp,
bool rewind = false)
{
// Only add impulse if no other impulse is active.
if (m_time_additional_impulse > 0 && !rewind) return;
if (m_ticks_additional_impulse > 0 && !rewind) return;
m_additional_impulse = imp;
m_time_additional_impulse = t;
m_ticks_additional_impulse = t;
} // setTimedImpulse
// ------------------------------------------------------------------------
/** Returns the time an additional impulse is activated. */
float getCentralImpulseTime() const { return m_time_additional_impulse; }
uint16_t getCentralImpulseTicks() const
{ return m_ticks_additional_impulse; }
// ------------------------------------------------------------------------
const btVector3& getAdditionalImpulse() const
{ return m_additional_impulse; }
// ------------------------------------------------------------------------
/** Sets a rotation that is applied over a certain amount of time (to avoid
* a too rapid changes in the kart).
* \param t Time for the rotation to be applied.
* \param t Ticks for the rotation to be applied.
* \param torque The rotation to apply. */
void setTimedRotation(float t, const btVector3 &rot)
void setTimedRotation(uint16_t t, const btVector3 &rot)
{
if(t>0) m_additional_rotation = rot/t;
m_time_additional_rotation = t;
if(t>0) m_additional_rotation = rot / (stk_config->ticks2Time(t));
m_ticks_additional_rotation = t;
} // setTimedTorque
// ------------------------------------------------------------------------
const btVector3& getTimedRotation() const { return m_additional_rotation; }
// ------------------------------------------------------------------------
float getTimedRotationTime() const { return m_time_additional_rotation; }
uint16_t getTimedRotationTicks() const { return m_ticks_additional_rotation; }
// ------------------------------------------------------------------------
/** Sets the maximum speed for this kart. */
void setMaxSpeed(float new_max_speed)

View File

@ -496,27 +496,29 @@ void Physics::KartKartCollision(AbstractKart *kart_a,
// First push one kart to the left (if there is not already
// an impulse happening - one collision might cause more
// than one impulse otherwise)
if(right_kart->getVehicle()->getCentralImpulseTime()<=0)
if(right_kart->getVehicle()->getCentralImpulseTicks()<=0)
{
const KartProperties *kp = left_kart->getKartProperties();
Vec3 impulse(kp->getCollisionImpulse()*f_right, 0, 0);
impulse = right_kart->getTrans().getBasis() * impulse;
right_kart->getVehicle()
->setTimedCentralImpulse(kp->getCollisionImpulseTime(),
impulse);
->setTimedCentralImpulse(
(uint16_t)stk_config->time2Ticks(kp->getCollisionImpulseTime()),
impulse);
right_kart ->getBody()->setAngularVelocity(btVector3(0,0,0));
}
// Then push the other kart to the right (if there is no
// impulse happening atm).
if(left_kart->getVehicle()->getCentralImpulseTime()<=0)
if(left_kart->getVehicle()->getCentralImpulseTicks()<=0)
{
const KartProperties *kp = right_kart->getKartProperties();
Vec3 impulse = Vec3(-kp->getCollisionImpulse()*f_left, 0, 0);
impulse = left_kart->getTrans().getBasis() * impulse;
left_kart->getVehicle()
->setTimedCentralImpulse(kp->getCollisionImpulseTime(),
impulse);
->setTimedCentralImpulse(
(uint16_t)stk_config->time2Ticks(kp->getCollisionImpulseTime()),
impulse);
left_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
}

View File

@ -152,6 +152,7 @@ void NetworkingLobby::init()
//I18N: In the networking lobby
m_header->setText(_("Lobby"), false);
m_server_info_height = GUIEngine::getFont()->getDimension(L"X").Height;
m_start_button->setText(_("Start race"));
m_start_button->setVisible(false);
m_state = LS_CONNECTING;
getWidget("chat")->setVisible(false);
@ -290,9 +291,11 @@ void NetworkingLobby::onUpdate(float delta)
if (remain < 0)
remain = 0;
//I18N: In the networking lobby, display the starting timeout
//for owner-less server
core::stringw msg = _P("Game will start after %d second.",
"Game will start after %d seconds.", (int)remain);
//for owner-less server to begin a game
core::stringw msg = _P("Starting after %d second "
"or everyone pressed 'Ready' button.",
"Starting after %d seconds "
"or everyone pressed 'Ready' button.", (int)remain);
m_timeout_message->setText(msg, true);
}
}
@ -344,7 +347,9 @@ void NetworkingLobby::onUpdate(float delta)
m_text_bubble->setText(total_msg, true);
}
if (STKHost::get()->isAuthorisedToControl())
if (STKHost::get()->isAuthorisedToControl() ||
(m_has_auto_start_in_server &&
m_cur_starting_timer != std::numeric_limits<int64_t>::max()))
{
m_start_button->setVisible(true);
}
@ -571,6 +576,9 @@ void NetworkingLobby::initAutoStartTimer(bool grand_prix_started,
if (min_players == 0 || start_timeout == 0.0f)
return;
//I18N: In the networking lobby, ready button is to allow player to tell
//server that he is ready for next game for owner less server
m_start_button->setText(_("Ready"));
m_has_auto_start_in_server = true;
m_min_start_game_players = grand_prix_started ? 0 : min_players;
m_start_timeout = start_timeout;