61#include <fmt/format.h>
69 : m_dt_remainder(0.0f)
70 , m_forced_awake(false)
71 , m_physics_steps(2000)
72 , m_simulation_speed(1.0f)
96 LOG(
" == Spawning vehicle: " + def->name);
131 vehicle_position.x += vehicle_position.x - actor->
ar_bounding_box.getCenter().x;
132 vehicle_position.z += vehicle_position.z - actor->
ar_bounding_box.getCenter().z;
138 miny = vehicle_position.y;
149 actor->
resetPosition(vehicle_position.x, vehicle_position.z,
true, miny);
160 Vector3 gpos = Vector3(vehicle_position.x, 0.0f, vehicle_position.z);
211 if (!subMeshGroundModelName.empty())
340 for (
RigDef::Script const& script_def : def->root_module->scripts)
345 LOG(
" ===== DONE LOADING VEHICLE");
371 if (actor->ar_net_source_id == sourceid)
405 std::string filename = args->
arg5ex;
413 std::string reg_filename;
414 std::string reg_bundlename;
416 if (reg_filename == filename)
418 RoR::LogFormat(
"[RoR] Retrying STREAM_REGISTER for user id %d, stream id %d, filename '%s'",
447 std::stable_sort(packet_buffer.begin(), packet_buffer.end(),
449 { return a.header.source > b.header.source; });
451 auto it = std::unique(packet_buffer.rbegin(), packet_buffer.rend(),
453 { return !memcmp(&a.header, &b.header, sizeof(RoRnet::Header)) &&
454 a.header.command == RoRnet::MSG2_STREAM_DATA; });
455 packet_buffer.erase(packet_buffer.begin(), it.base());
456 for (
auto& packet : packet_buffer)
466 std::string filename;
467 std::string bundlename;
478 else if (filename.empty())
487 text <<
_L(
"spawned a new vehicle: ") << filename;
500 _L(
"Mod not installed: ") + filename);
501 RoR::LogFormat(
"[RoR] Cannot create remote actor (not installed), filename: '%s'", filename_maybe_bundlequalified.c_str());
507 RoR::LogFormat(
"[RoR] Creating remote actor (user id %d, stream id %d) with filename '%s'",
524 int sourceid = packet.header.source;
525 actor->ar_net_stream_results[sourceid] = reg->
status;
530 case 1: message =
"successfully loaded stream";
break;
531 case -2: message =
"detected mismatch stream";
break;
532 default: message =
"could not load stream";
break;
542 this->
RemoveStream(packet.header.source, packet.header.streamid);
554 if (packet.header.source == actor->ar_net_source_id && packet.header.streamid == actor->ar_net_stream_id)
556 actor->pushNetwork(packet.buffer, packet.header.size);
604 return search->second;
627 if (actor->ar_net_source_id == sourceid)
645 int stream_result = actor->ar_net_stream_results[sourceid];
646 if (stream_result == -1 || stream_result == -2)
648 if (stream_result == 1)
659 if (actor->ar_net_source_id == source_id && actor->ar_net_stream_id == stream_id)
670 if (
m_actors[a]->ar_collision_bounding_boxes.empty() &&
m_actors[b]->ar_collision_bounding_boxes.empty())
674 else if (
m_actors[a]->ar_collision_bounding_boxes.empty())
676 for (
const auto& bbox_b :
m_actors[b]->ar_collision_bounding_boxes)
677 if (bbox_b.intersects(
m_actors[a]->ar_bounding_box))
680 else if (
m_actors[b]->ar_collision_bounding_boxes.empty())
682 for (
const auto& bbox_a :
m_actors[a]->ar_collision_bounding_boxes)
683 if (bbox_a.intersects(
m_actors[b]->ar_bounding_box))
688 for (
const auto& bbox_a :
m_actors[a]->ar_collision_bounding_boxes)
689 for (
const auto& bbox_b :
m_actors[b]->ar_collision_bounding_boxes)
690 if (bbox_a.intersects(bbox_b))
699 if (
m_actors[a]->ar_predicted_coll_bounding_boxes.empty() &&
m_actors[b]->ar_predicted_coll_bounding_boxes.empty())
701 return m_actors[a]->ar_predicted_bounding_box.intersects(
m_actors[b]->ar_predicted_bounding_box);
703 else if (
m_actors[a]->ar_predicted_coll_bounding_boxes.empty())
705 for (
const auto& bbox_b :
m_actors[b]->ar_predicted_coll_bounding_boxes)
706 if (bbox_b.intersects(
m_actors[a]->ar_predicted_bounding_box))
709 else if (
m_actors[b]->ar_predicted_coll_bounding_boxes.empty())
711 for (
const auto& bbox_a :
m_actors[a]->ar_predicted_coll_bounding_boxes)
712 if (bbox_a.intersects(
m_actors[b]->ar_predicted_bounding_box))
717 for (
const auto& bbox_a :
m_actors[a]->ar_predicted_coll_bounding_boxes)
718 for (
const auto& bbox_b :
m_actors[b]->ar_predicted_coll_bounding_boxes)
719 if (bbox_a.intersects(bbox_b))
733 for (
unsigned int t = 0; t <
m_actors.size(); t++)
735 if (t == j || visited[t])
739 m_actors[t]->ar_sleep_counter = 0.0f;
744 m_actors[t]->ar_sleep_counter = 0.0f;
760 (actor->getPosition().distance(source_actor->
getPosition()) <
766 actor->ar_sleep_counter = 0.0f;
772 if (std::find(linked_actors.begin(), linked_actors.end(), actor) == linked_actors.end())
779 actor->ar_command_key[j].playerInputValue = std::max(source_actor->
ar_command_key[j].playerInputValue,
804 for (
auto hook : source_actor->
ar_hooks)
806 if (!hook.hk_locked_actor || hook.hk_locked_actor == source_actor)
810 hook.hk_locked_actor->ar_brake = source_actor->
ar_brake;
813 hook.hk_locked_actor->parkingbrakeToggle();
826 auto& actor_pair = entry.second;
827 if ((actor_pair.first == a1 && actor_pair.second == a2) ||
828 (actor_pair.first == a2 && actor_pair.second == a1))
844 if (actor->ar_driveable ==
AI)
846 if (actor->getVelocity().squaredLength() > 0.01f)
848 actor->ar_sleep_counter = 0.0f;
852 actor->ar_sleep_counter += dt;
854 if (actor->ar_sleep_counter >= 10.0f)
866 std::vector<bool> visited(
m_actors.size());
874 for (
unsigned int t = 0; t <
m_actors.size(); t++)
888 actor->ar_sleep_counter = 0.0f;
911 if (collisions->
isInside(actor->ar_nodes[0].AbsPosition, inst, box))
927 if (actor !=
nullptr)
941 float min_squared_distance = std::numeric_limits<float>::max();
944 float squared_distance = position.squaredDistance(actor->ar_nodes[0].AbsPosition);
945 if (squared_distance < min_squared_distance)
947 min_squared_distance = squared_distance;
948 nearest_actor = actor;
951 return std::make_pair(nearest_actor, std::sqrt(min_squared_distance));
982 { return b->ar_net_source_id == actor->ar_net_source_id; }) == 1)
991 std::vector<ScriptUnitID_t> unload_list;
994 if (pair.second.associatedActor == actor)
995 unload_list.push_back(pair.first);
1007 [actor](
FreeForce& item) { return item.ffc_base_actor == actor || item.ffc_target_actor == actor; }),
1016 for (
unsigned int i = 0; i <
m_actors.size(); i++)
1025 if (player !=
nullptr)
1027 else if (prev_player !=
nullptr)
1052 for (
int i = pivot_index + 1; i <
m_actors.size(); i++)
1058 for (
int i = 0; i < pivot_index; i++)
1064 if (pivot_index >= 0)
1077 for (
int i = pivot_index - 1; i >= 0; i--)
1083 for (
int i =
static_cast<int>(
m_actors.size()) - 1; i > pivot_index; i--)
1089 if (pivot_index >= 0)
1104 if (actor->ar_rescuer_flag)
1117 dt = std::min(dt, 1.0f / 20.0f);
1137 actor->HandleInputEvents(dt);
1138 actor->HandleAngelScriptEvents(dt);
1140#ifdef USE_ANGELSCRIPT
1141 if (actor->ar_vehicle_ai && actor->ar_vehicle_ai->isActive())
1142 actor->ar_vehicle_ai->update(dt, 0);
1145 if (actor->ar_engine)
1147 if (actor->ar_driveable ==
TRUCK)
1153 actor->ar_engine->UpdateEngine(dt, 1);
1155 actor->ar_engine->UpdateEngineAudio();
1159 actor->updateDashBoards(dt);
1162 actor->updateFlareStates(dt);
1166 actor->updateVisual(dt);
1169 actor->updateSkidmarks();
1176 actor->calcNetwork();
1178 actor->sendStreamData();
1182 if (player_actor !=
nullptr)
1216 auto func = std::function<void()>([
this]()
1232 if (actor->ar_instance_id == actor_id)
1249 std::vector<std::function<void()>> tasks;
1252 if (actor->ar_update_physics = actor->CalcForcesEulerPrepare(i == 0))
1254 auto func = std::function<void()>([
this, i, &actor]()
1258 tasks.push_back(func);
1264 if (actor->ar_update_physics)
1266 actor->CalcBeamsInterActor();
1271 std::vector<std::function<void()>> tasks;
1274 if (actor->m_inter_point_col_detector !=
nullptr && (actor->ar_update_physics ||
1277 auto func = std::function<void()>([
this, &actor]()
1279 actor->m_inter_point_col_detector->UpdateInterPoint();
1280 if (actor->ar_collision_relevant)
1282 ResolveInterActorCollisions(PHYSICS_DT,
1283 *actor->m_inter_point_col_detector,
1284 actor->ar_num_collcabs,
1287 actor->ar_inter_collcabrate,
1289 actor->ar_collision_range,
1290 *actor->ar_submesh_ground_model);
1293 tasks.push_back(func);
1304 actor->m_ongoing_reset =
false;
1307 Vector3 camera_gforces = actor->m_camera_gforces_accu /
m_physics_steps;
1308 actor->m_camera_gforces_accu = Vector3::ZERO;
1309 actor->m_camera_gforces = actor->m_camera_gforces * 0.5f + camera_gforces * 0.5f;
1310 actor->calculateLocalGForces();
1311 actor->calculateAveragePosition();
1312 actor->m_avg_node_velocity = actor->m_avg_node_position - actor->m_avg_node_position_prev;
1314 actor->m_avg_node_position_prev = actor->m_avg_node_position;
1315 actor->ar_top_speed = std::max(actor->ar_top_speed, actor->ar_nodes[0].Velocity.length());
1329 msg <<
"Failed to load '" << filename <<
"' (type: '" << type <<
"'), message: " << exception_msg;
1360 if (!stream || !stream->isReadable())
1375 LOG(
" == Validating vehicle: " + def->name);
1378 validator.
Setup(def);
1387 Ogre::StringUtil::toLowerCase(file_extension);
1388 if ((file_extension ==
".load") || (file_extension ==
".fixed"))
1396 def->hash =
Sha1Hash(stream->getAsString());
1401 catch (Ogre::Exception& oex)
1406 catch (std::exception& stex)
1422 Ogre::ResourceGroupManager& rgm = Ogre::ResourceGroupManager::getSingleton();
1425 Ogre::DataStreamPtr stream = rgm.createResource(filename, rg_name,
true);
1426 if (stream.isNull() || !stream->isWriteable())
1428 OGRE_EXCEPT(Ogre::Exception::ERR_CANNOT_WRITE_TO_FILE,
1429 "Stream NULL or not writeable, filename: '" + filename
1430 +
"', resource group: '" + rg_name +
"'");
1441 catch (Ogre::Exception& oex)
1444 fmt::format(
_LC(
"Truck",
"Failed to export truck '{}' to resource group '{}', message: {}"),
1445 filename, rg_name, oex.getFullDescription()));
1451 std::vector<ActorPtr> actors;
1455 actors.push_back(actor);
1470 String ssmsg =
_L(
"New simulation speed: ") +
TOSTRING(
Round(simulation_speed * 100.0f, 1)) +
"%";
1479 String ssmsg =
_L(
"New simulation speed: ") +
TOSTRING(
Round(simulation_speed * 100.0f, 1)) +
"%";
1487 if (simulation_speed != 1.0f)
1491 std::string ssmsg =
_L(
"Simulation speed reset.");
1517 String ssmsg =
_L(
"Physics paused");
1522 String ssmsg =
_L(
"Physics unpaused");
1554#ifdef USE_ANGELSCRIPT
1566 Ogre::Degree pitchAngle = Ogre::Radian(asin(dirDiff.dotProduct(Ogre::Vector3::UNIT_Y)));
1568 if (std::abs(pitchAngle.valueDegrees()) > 2.0f)
1576 float downhill_force = std::abs(sin(pitchAngle.valueRadians()) * vehicle->
getTotalMass()) * g;
1578 float ratio = std::max(0.0f, 1.0f - (engine_force / downhill_force));
1600 if (engine && engine->
getGear() != 0)
1603 engine->
setAcc(Ogre::Math::Clamp(accl, 0.0f, engine->
getAcc()));
1616 ROR_ASSERT(freeforce.ffc_base_actor !=
nullptr);
1619 ROR_ASSERT(freeforce.ffc_base_node <= freeforce.ffc_base_actor->ar_num_nodes);
1622 switch (freeforce.ffc_type)
1625 freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node].Forces += freeforce.ffc_force_magnitude * freeforce.ffc_force_const_direction;
1630 const Vector3 force_direction = (freeforce.ffc_target_coords - freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node].AbsPosition).normalisedCopy();
1631 freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node].Forces += freeforce.ffc_force_magnitude * force_direction;
1638 ROR_ASSERT(freeforce.ffc_target_actor !=
nullptr);
1641 ROR_ASSERT(freeforce.ffc_target_node <= freeforce.ffc_target_actor->ar_num_nodes);
1643 const Vector3 force_direction = (freeforce.ffc_target_actor->ar_nodes[freeforce.ffc_target_node].AbsPosition - freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node].AbsPosition).normalisedCopy();
1644 freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node].Forces += freeforce.ffc_force_magnitude * force_direction;
1652 ROR_ASSERT(freeforce.ffc_target_actor !=
nullptr);
1655 ROR_ASSERT(freeforce.ffc_target_node <= freeforce.ffc_target_actor->ar_num_nodes);
1660 node_t* p1 = &freeforce.ffc_base_actor->ar_nodes[freeforce.ffc_base_node];
1661 node_t* p2 = &freeforce.ffc_target_actor->ar_nodes[freeforce.ffc_target_node];
1664 Real dislen = dis.squaredLength();
1667 dislen *= inverted_dislen;
1670 Real difftoBeamL = dislen - freeforce.ffc_halfb_L;
1672 Real k = freeforce.ffc_halfb_spring;
1673 Real d = freeforce.ffc_halfb_damp;
1684 float slen = -k * (difftoBeamL)-d * v.dotProduct(dis) * inverted_dislen;
1685 freeforce.ffc_halfb_stress = slen;
1688 float len = std::abs(slen);
1689 if (len > freeforce.ffc_halfb_minmaxposnegstress)
1694 if (slen > freeforce.ffc_halfb_maxposstress && difftoBeamL < 0.0f)
1696 Real yield_length = freeforce.ffc_halfb_maxposstress / k;
1697 Real deform = difftoBeamL + yield_length * (1.0f - freeforce.ffc_halfb_plastic_coef);
1698 Real Lold = freeforce.ffc_halfb_L;
1699 freeforce.ffc_halfb_L += deform;
1700 freeforce.ffc_halfb_L = std::max(
MIN_BEAM_LENGTH, freeforce.ffc_halfb_L);
1701 slen = slen - (slen - freeforce.ffc_halfb_maxposstress) * 0.5f;
1703 if (freeforce.ffc_halfb_L > 0.0f && Lold > freeforce.ffc_halfb_L)
1705 freeforce.ffc_halfb_maxposstress *= Lold / freeforce.ffc_halfb_L;
1706 freeforce.ffc_halfb_minmaxposnegstress = std::min(freeforce.ffc_halfb_maxposstress, -freeforce.ffc_halfb_maxnegstress);
1707 freeforce.ffc_halfb_minmaxposnegstress = std::min(freeforce.ffc_halfb_minmaxposnegstress, freeforce.ffc_halfb_strength);
1714 fmt::format(
"{}", slen), fmt::format(
"{}", freeforce.ffc_halfb_maxposstress));
1716 else if (slen < freeforce.ffc_halfb_maxnegstress && difftoBeamL > 0.0f)
1718 Real yield_length = freeforce.ffc_halfb_maxnegstress / k;
1719 Real deform = difftoBeamL + yield_length * (1.0f - freeforce.ffc_halfb_plastic_coef);
1720 Real Lold = freeforce.ffc_halfb_L;
1721 freeforce.ffc_halfb_L += deform;
1722 slen = slen - (slen - freeforce.ffc_halfb_maxnegstress) * 0.5f;
1724 if (Lold > 0.0f && freeforce.ffc_halfb_L > Lold)
1726 freeforce.ffc_halfb_maxnegstress *= freeforce.ffc_halfb_L / Lold;
1727 freeforce.ffc_halfb_minmaxposnegstress = std::min(freeforce.ffc_halfb_maxposstress, -freeforce.ffc_halfb_maxnegstress);
1728 freeforce.ffc_halfb_minmaxposnegstress = std::min(freeforce.ffc_halfb_minmaxposnegstress, freeforce.ffc_halfb_strength);
1730 freeforce.ffc_halfb_strength -= deform * k;
1733 fmt::format(
"{}", slen), fmt::format(
"{}", freeforce.ffc_halfb_maxnegstress));
1738 if (len > freeforce.ffc_halfb_strength)
1748 fmt::format(
"{}", len), fmt::format(
"{}", freeforce.ffc_halfb_strength));
1754 f *= (slen * inverted_dislen);
1784 fmt::format(
"Cannot add free force with ID {} to actor {}: Base actor not found or disposed", freeforce.
ffc_id, rq->
ffr_base_actor));
1810 fmt::format(
"Cannot add free force of type 'TOWARDS_NODE' with ID {} to actor {}: Target actor not found or disposed", freeforce.
ffc_id, rq->
ffr_target_actor));
1843 freeforce.
ffc_halfb_L = target_pos.distance(base_pos);
1859 ActorManager::FreeForceVec_t::iterator it;
1863 fmt::format(
"Cannot add free force with ID {}: ID already in use", rq->
ffr_id));
1877 ActorManager::FreeForceVec_t::iterator it;
1881 fmt::format(
"Cannot modify free force with ID {}: ID not found", rq->
ffr_id));
1895 ActorManager::FreeForceVec_t::iterator it;
1899 fmt::format(
"Cannot remove free force with ID {}: ID not found",
id));
int FindPivotActorId(ActorPtr player, ActorPtr prev_player)
static bool ProcessFreeForce(FreeForceRequest *rq, FreeForce &freeforce)
void HandleErrorLoadingTruckfile(std::string filename, std::string exception_msg)
void HandleErrorLoadingFile(std::string type, std::string filename, std::string exception_msg)
bool ShouldIncludeActorInList(const ActorPtr &actor)
Central state/object manager and communications hub.
#define ROR_ASSERT(_EXPR)
void LOG(const char *msg)
Legacy alias - formerly a macro.
float fast_invSqrt(const float v)
void BITMASK_SET(BitMask_t &mask, BitMask_t flag, bool val)
A database of user-installed content alias 'mods' (vehicles, terrains...)
Game state manager and message-queue provider.
This creates a billboarding object that displays a text.
static const int MAX_COMMANDS
maximum number of commands per actor
#define SOUND_PLAY_ONCE(_ACTOR_, _TRIG_)
#define SOUND_MODULATE(_ACTOR_, _MOD_, _VALUE_)
Checks the rig-def file syntax and pulls data to File object.
RigDef::DocumentPtr GetFile()
void ProcessOgreStream(Ogre::DataStream *stream, Ogre::String resource_group)
Serializes the RigDef::File data structure to string.
std::string GetOutput() const
Performs a formal validation of the file (missing required parts, conflicts of modules,...
void Setup(RigDef::DocumentPtr file)
Prepares the validation.
void SetCheckBeams(bool check_beams)
Softbody object; can be anything from soda can to a space shuttle Constructed from a truck definition...
bool ar_import_commands
Sim state.
std::vector< float > ar_orig_minimass
minimum node mass in Kg - original unscaled values
Ogre::AxisAlignedBox ar_bounding_box
standard bounding box (surrounds all nodes of an actor)
int m_wheel_node_count
Static attr; filled at spawn.
size_t m_net_total_buffer_size
For incoming/outgoing traffic; calculated on spawn.
BitMask_t getLightStateMask() const
std::vector< float > ar_minimass
minimum node mass in Kg - can be scaled in-game via NBUtil
float ar_dry_mass
User-defined (editable via NBUtil); from 'globals' arg#1 - default for all nodes.
bool ar_forward_commands
Sim state.
void calcNodeConnectivityGraph()
float ar_wheel_speed
Physics state; wheel speed in m/s.
BuoyCachedNodeID_t ar_cabs_buoy_cache_ids[MAX_CABS]
CmdKeyArray ar_command_key
BEWARE: commandkeys are indexed 1-MAX_COMMANDS!
void dispose()
Effectively destroys the object but keeps it in memory to satisfy shared pointers.
float ar_original_load_mass
Un-edited value from 'globals' arg#2.
void updateVisual(float dt=0)
int ar_buoycabs[MAX_CABS]
bool m_disable_default_sounds
Spawner context; TODO: remove.
void NotifyActorCameraChanged()
Logic: sound, display; Notify this vehicle that camera changed;.
float ar_sleep_counter
Sim state; idle time counter.
float ar_original_dry_mass
Un-edited value from 'globals' arg#1.
ground_model_t * ar_submesh_ground_model
float ar_initial_total_mass
Calculated; total mass in Kg (snapshot at spawn)
bool m_preloaded_with_terrain
Spawn context (TODO: remove!)
std::vector< std::pair< float, float > > ar_initial_beam_defaults
unsigned int ar_vector_index
Sim attr; actor element index in std::vector<m_actors>
Replay * m_replay_handler
bool ar_physics_paused
Actor physics individually paused by user.
Ogre::Vector3 getPosition()
void ForceFeedbackStep(int steps)
bool ar_toggle_ropes
Sim state.
std::vector< Ogre::Vector3 > ar_initial_node_positions
Absolute world positions, for resetting to pristine state.
void UpdatePhysicsOrigin()
int ar_net_source_id
Unique ID of remote player who spawned this actor.
void recalculateNodeMasses()
std::unique_ptr< Buoyance > m_buoyance
std::string m_net_username
bool sl_enabled
Speed limiter;.
float getAvgPropedWheelRadius()
float ar_load_mass
User-defined (editable via NBUtil); from 'globals' arg#2 - only applies to nodes with 'l' flag.
Ogre::Vector3 ar_origin
Physics state; base position for softbody nodes.
size_t m_net_wheel_buf_size
For incoming/outgoing traffic; calculated on spawn.
Ogre::Vector3 getDirection()
average actor velocity, calculated using the actor positions of the last two frames
size_t m_net_propanimkey_buf_size
For incoming/outgoing traffic; calculated on spawn.
bool isBeingReset() const
float ar_total_mass
Calculated; total mass in Kg.
void WriteDiagnosticDump(std::string const &filename)
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
ActorPtrVec ar_linked_actors
BEWARE: Includes indirect links, see DetermineLinkedActors(); Other actors linked using 'hooks/ties/r...
float ar_avg_wheel_speed
Physics state; avg wheel speed in m/s.
std::vector< PropAnimKeyState > m_prop_anim_key_states
Ogre::Real ar_brake
Physics state; braking intensity.
bool isPreloadedWithTerrain() const
std::string ar_filename
Attribute; filled at spawn.
Ogre::Real m_min_camera_radius
int ar_num_cinecams
Sim attr;.
TyrePressure & getTyrePressure()
std::string m_section_config
Classic 'sectionconfig' in truck file.
bool cc_mode
Cruise Control.
VehicleAIPtr ar_vehicle_ai
BitMask_t m_lightmask
RoRnet::Lightmask.
float getTotalMass(bool withLocked=true)
void calculateAveragePosition()
std::vector< hook_t > ar_hooks
void UpdateBoundingBoxes()
void UpdateCruiseControl(float dt)
Defined in 'gameplay/CruiseControl.cpp'.
int m_net_first_wheel_node
Network attr; Determines data buffer layout; calculated on spawn.
Ogre::Vector3 m_avg_node_position
average node position
size_t m_net_node_buf_size
For incoming/outgoing traffic; calculated on spawn.
bool ar_trailer_parking_brake
bool ar_toggle_ties
Sim state.
std::vector< float > ar_initial_node_masses
void resetPosition(Ogre::Vector3 translation, bool setInitPosition)
Moves the actor to given world coords (pivot point is node 0).
float sl_speed_limit
Speed limiter;.
ActorPtrVec & GetActors()
void UpdateSleepingState(ActorPtr player_actor, float dt)
RigDef::DocumentPtr FetchActorDef(RoR::ActorSpawnRequest &rq)
float m_simulation_time
Amount of time the physics simulation is going to be advanced.
void SetSimulationSpeed(float speed)
void RequestSpawnRemoteActor(RoRnet::ActorStreamRegister *reg, const CacheEntryPtr &cache_entry, const RoRnet::UserInfo &userinfo, BitMask_t peeropts)
void DeleteActorInternal(ActorPtr actor)
Do not call directly; use GameContext::DeleteActor()
RoRnet::UiStreamsHealth CheckNetworkStreamsOk(int sourceid)
RoRnet::UiStreamsHealth CheckNetRemoteStreamsOk(int sourceid)
const ActorPtr & FetchNextVehicleOnList(ActorPtr player, ActorPtr prev_player)
void UpdatePhysicsSimulation()
std::map< beam_t *, std::pair< ActorPtr, ActorPtr > > inter_actor_links
void RemoveFreeForce(FreeForceID_t id)
std::shared_ptr< Task > m_sim_task
void ModifyFreeForce(FreeForceRequest *rq)
std::map< int, std::set< int > > m_stream_mismatches
Networking: A set of streams without a corresponding actor in the actor-array for each stream source.
const ActorPtr & GetActorByNetworkLinks(int source_id, int stream_id)
void UpdateTruckFeatures(ActorPtr vehicle, float dt)
float m_simulation_speed
slow motion < 1.0 < fast motion
void CleanUpSimulation()
Call this after simulation loop finishes.
ActorPtrVec m_actors
Use MSG_SIM_{SPAWN/DELETE}_ACTOR_REQUESTED
bool CheckActorCollAabbIntersect(int a, int b)
Returns whether or not the bounding boxes of truck a and truck b intersect. Based on the truck collis...
const ActorPtr & FetchPreviousVehicleOnList(ActorPtr player, ActorPtr prev_player)
void RemoveStreamSource(int sourceid)
bool PredictActorCollAabbIntersect(int a, int b)
Returns whether or not the bounding boxes of truck a and truck b might intersect during the next fram...
void UpdateNetTimeOffset(int sourceid, int offset)
void SendAllActorsSleeping()
void ForwardCommands(ActorPtr source_actor)
Fowards things to trailers.
bool m_forced_awake
disables sleep counters
void ExportActorDef(RigDef::DocumentPtr def, std::string filename, std::string rg_name)
ActorPtr FindActorInsideBox(Collisions *collisions, const Ogre::String &inst, const Ogre::String &box)
void UpdateActors(ActorPtr player_actor)
FreeForceVec_t m_free_forces
Global forces added ad-hoc by scripts.
void RetryFailedStreamRegistrations(ScriptEventArgs *args)
float GetSimulationSpeed() const
int GetNetTimeOffset(int sourceid)
const ActorPtr & GetActorById(ActorInstanceID_t actor_id)
void RemoveStream(int sourceid, int streamid)
ActorPtr CreateNewActor(ActorSpawnRequest rq, RigDef::DocumentPtr def)
void AddStreamMismatch(RoRnet::ActorStreamRegister *reg)
void HandleActorStreamData(std::vector< RoR::NetRecvPacket > packet)
std::pair< ActorPtr, float > GetNearestActor(Ogre::Vector3 position)
void UpdateInputEvents(float dt)
float m_last_simulation_speed
previously used time ratio between real time (evt.timeSinceLastFrame) and physics time ('dt' used in ...
void AddFreeForce(FreeForceRequest *rq)
std::map< int, int > m_stream_time_offsets
Networking: A network time offset for each stream source.
void RecursiveActivation(int j, std::vector< bool > &visited)
ActorInstanceID_t GetActorNextInstanceId()
Script proxy: game.getActorNextInstanceId()
void RepairActor(Collisions *collisions, const Ogre::String &inst, const Ogre::String &box, bool keepPosition=false)
void CalcFreeForces()
Apply FreeForces - intentionally as a separate pass over all actors.
const ActorPtr & FetchRescueVehicle()
std::vector< RoRnet::ActorStreamRegister > m_stream_mismatched_regs
Networking: Remember mismatched stream regs to re-process after downloading the missing mods.
std::vector< ActorPtr > GetLocalActors()
float m_dt_remainder
Keeps track of the rounding error in the time step calculation.
bool FindFreeForce(FreeForceID_t id, FreeForceVec_t::iterator &out_itor)
std::unique_ptr< ThreadPool > m_sim_thread_pool
static const ActorPtr ACTORPTR_NULL
bool AreActorsDirectlyLinked(const ActorPtr &a1, const ActorPtr &a2)
Processes a RigDef::Document (parsed from 'truck' file format) into a simulated gameplay object (Acto...
void ConfigureAssetPacks(ActorPtr actor)
void ConfigureAddonParts(ActorPtr actor)
void ConfigureSections(Ogre::String const §ionconfig, RigDef::DocumentPtr def)
void ProcessNewActor(ActorPtr actor, ActorSpawnRequest rq, RigDef::DocumentPtr def)
std::string GetSubmeshGroundmodelName()
ActorMemoryRequirements const & GetMemoryRequirements()
static void SetupDefaultSoundSources(ActorPtr const &actor)
Ogre::String fname
filename
Ogre::String resource_group
Resource group of the loaded bundle. Empty if not loaded yet.
RigDef::DocumentPtr actor_def
Cached actor definition (aka truckfile) after first spawn.
CacheEntryPtr FindEntryByFilename(RoR::LoaderType type, bool partial, const std::string &_filename_maybe_bundlequalified)
Returns NULL if none found; "Bundle-qualified" format also specifies the ZIP/directory in modcache,...
CacheEntryPtr FetchSkinByName(std::string const &skin_name)
CacheEntryPtr GetEntryByNumber(int modid)
void LoadResource(CacheEntryPtr &t)
Loads the associated resource bundle if not already done.
ground_model_t * getGroundModelByString(const Ogre::String name)
ground_model_t * defaultgm
bool isInside(Ogre::Vector3 pos, const Ogre::String &inst, const Ogre::String &box, float border=0)
void putNetMessage(int user_id, MessageType type, const char *text)
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
@ CONSOLE_MSGTYPE_INFO
Generic message.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
SimGearboxMode getAutoMode()
void startEngine()
Quick engine start. Plays sounds.
void offStart()
Quick start of vehicle engine.
bool hasContact()
Ignition.
const TerrainPtr & GetTerrain()
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
ActorManager * GetActorManager()
void UpdateWheelVisuals()
void FinishFlexbodyTasks()
void UpdateSimDataBuffer()
Copies sim. data from Actor to GfxActor for later update.
void UpdateProps(float dt, bool is_player_actor)
void SetDebugView(DebugViewType dv)
void FinishWheelUpdates()
void RegisterGfxActor(RoR::GfxActor *gfx_actor)
bool GetUserPeerOpts(int uid, BitMask_t &result)
void AddPacket(int streamid, int type, int len, const char *content)
ScriptUnitID_t loadScript(Ogre::String filename, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="")
Loads a script.
ScriptUnitMap const & getScriptUnits() const
void unloadScript(ScriptUnitID_t unique_id)
Unloads a script.
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
const char * ToCStr() const
Collisions * GetCollisions()
Facilitates execution of (small) tasks on separate threads.
void Parallelize(const std::vector< std::function< void()> > &task_funcs)
Run collection of tasks in parallel and wait until all have finished.
bool ModifyTyrePressure(float v)
bool isActive()
Returns the status of the AI.
@ TRUCK
its a truck (or other land vehicle)
@ AI
machine controlled by an Artificial Intelligence
@ MSG_SIM_ACTOR_LINKING_REQUESTED
Payload = RoR::ActorLinkingRequest* (owner)
@ MSG_SIM_SPAWN_ACTOR_REQUESTED
Payload = RoR::ActorSpawnRequest* (owner)
@ MSG_SIM_DELETE_ACTOR_REQUESTED
Payload = RoR::ActorPtr* (owner)
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
static const float MIN_BEAM_LENGTH
minimum beam lenght is 10 centimeters
@ TOWARDS_COORDS
Constant force directed towards ffc_target_coords
@ HALFBEAM_ROPE
Like TOWARDS_NODE, but parametrized like a rope-beam in truck fileformat.
@ CONSTANT
Constant force given by direction and magnitude.
@ HALFBEAM_GENERIC
Like TOWARDS_NODE, but parametrized like a beam in truck fileformat.
@ TOWARDS_NODE
Constant force directed towards ffc_target_node
@ LOCAL_SIMULATED
simulated (local) actor
@ LOCAL_SLEEPING
sleeping (local) actor
@ NETWORKED_OK
not simulated (remote) actor
@ DISPOSED
removed from simulation, still in memory to satisfy pointers.
@ NETWORKED_HIDDEN
not simulated, not updated (remote)
void TRIGGER_EVENT_ASYNC(scriptEvents type, int arg1, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
Asynchronously (via MSG_SIM_SCRIPT_EVENT_TRIGGERED) invoke script function eventCallbackEx(),...
@ ACTOR
Defined in truck file under 'scripts', contains global variable BeamClass@ thisActor.
std::shared_ptr< Document > DocumentPtr
InputEngine * GetInputEngine()
ThreadPool * GetThreadPool()
CVar * mp_cyclethru_net_actors
Include remote actors when cycling through with CTRL + [ and CTRL + ].
GameContext * GetGameContext()
CVar * sim_realistic_commands
CVar * mp_pseudo_collisions
ScriptEngine * GetScriptEngine()
CacheSystem * GetCacheSystem()
CVar * sim_replay_enabled
CVar * gfx_skidmarks_mode
static const NodeNum_t NODENUM_INVALID
@ MODCACHEACTIVITY_ENTRY_ADDED
Args: #1 type, #2 entry number, –, –, #5 fname, #6 fext.
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
int FreeForceID_t
Unique sequentially generated ID of FreeForce; use ActorManager::GetFreeForceNextId().
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
int ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
static const ActorInstanceID_t ACTORINSTANCEID_INVALID
@ FREEFORCESACTIVITY_ADDED
@ FREEFORCESACTIVITY_MODIFIED
@ FREEFORCESACTIVITY_BROKEN
Only with HALFBEAM_* types; arg #5 (string containing float) the applied force, arg #6 (string contai...
@ FREEFORCESACTIVITY_DEFORMED
Only with HALFBEAM_* types; arg #5 (string containing float) the actual stress, arg #6 (string contai...
@ FREEFORCESACTIVITY_REMOVED
RefCountingObjectPtr< Actor > ActorPtr
@ SE_GENERIC_FREEFORCES_ACTIVITY
Triggered on freeforce add/update/delete or breaking; args: #1 freeForcesActivityType,...
@ SE_GENERIC_NEW_TRUCK
triggered when the user spawns a new actor, the argument refers to the actor ID
@ SE_GENERIC_MODCACHE_ACTIVITY
Triggered when status of modcache changes, args: #1 type, #2 entry number, for other args see RoR::mo...
std::string SanitizeUtf8CString(const char *start, const char *end=nullptr)
void EraseIf(std::vector< T, A > &c, Predicate pred)
static const NodeNum_t NODENUM_MAX
std::string Sha1Hash(std::string const &data)
void SplitBundleQualifiedFilename(const std::string &bundleQualifiedFilename, std::string &out_bundleName, std::string &out_filename)
std::string tryConvertUTF(const char *buffer)
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Ogre::Real Round(Ogre::Real value, unsigned short ndigits=0)
@ LIGHTMASK_REVERSE
reverse light on
@ LIGHTMASK_BRAKES
brake lights on
@ MSG2_STREAM_REGISTER_RESULT
result of a stream creation
@ MSG2_USER_LEAVE
user leaves
@ MSG2_STREAM_UNREGISTER
remove stream
@ MSG2_STREAM_DATA
stream data
@ MSG2_STREAM_REGISTER
create new stream
@ ALL_OK
Stream is OK - no errors loading the mods.
@ MISMATCHES
Loading errors - some mods could not be loaded (probably not installed)
@ IDLE
Player has no active streams.
Estabilishing a physics linkage between 2 actors modifies a global linkage table and triggers immedia...
ActorLinkingRequestType alr_type
ActorInstanceID_t alr_actor_instance_id
ActorInstanceID_t amr_actor
std::string asr_net_username
CacheEntryPtr asr_cache_entry
Optional, overrides 'asr_filename' and 'asr_cache_entry_num'.
Ogre::Vector3 asr_position
CacheEntryPtr asr_skin_entry
ActorInstanceID_t asr_instance_id
Optional; see ActorManager::GetActorNextInstanceID();.
std::string asr_filename
Can be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck".
Ogre::Quaternion asr_rotation
@ CONFIG_FILE
'Preselected vehicle' in RoR.cfg or command line
@ NETWORK
Remote controlled.
@ TERRN_DEF
Preloaded with terrain.
BitMask_t asr_net_peeropts
RoRnet::PeerOptions to be applied after spawn.
collision_box_t * asr_spawnbox
bool asr_free_position
Disables the automatic spawn position adjustment.
Global force affecting particular (base) node of particular (base) actor; added ad-hoc by scripts.
float ffc_halfb_minmaxposnegstress
Ogre::Vector3 ffc_force_const_direction
Expected to be normalized; only effective with FreeForceType::CONSTANT
Ogre::Vector3 ffc_target_coords
float ffc_force_magnitude
float ffc_halfb_L
Length at rest, including permanent deformations.
ActorPtr ffc_target_actor
float ffc_halfb_maxposstress
float ffc_halfb_maxnegstress
float ffc_halfb_strength
Breaking threshold.
float ffc_halfb_plastic_coef
NodeNum_t ffc_target_node
Common for ADD and MODIFY requests; tailored for use with AngelScript thru GameScript::pushMessage().
double ffr_force_magnitude
double ffr_halfb_strength
Ogre::Vector3 ffr_target_coords
double ffr_halfb_plastic_coef
double ffr_halfb_diameter
Ogre::Vector3 ffr_force_const_direction
Unified game event system - all requests and state changes are reported using a message.
Args for eventCallbackEx() queued via MSG_SIM_SCRIPT_EVENT_TRIGGERED See descriptions at enum RoR::sc...
float default_beam_deform
for reset
float initial_beam_strength
for reset
Ogre::Vector3 hi
absolute collision box
Ogre::Vector3 relo
relative collision box
Ogre::Vector3 center
center of rotation
Ogre::Vector3 lo
absolute collision box
Physics: A vertex in the softbody structure.
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)
bool nd_rim_node
Attr; This node is part of a rim (only wheel types with separate rim nodes)
Ogre::Vector3 RelPosition
relative to the local physics origin (one origin per actor) (shaky)
bool nd_tyre_node
Attr; This node is part of a tyre (note some wheel types don't use rim nodes at all)
< Must preserve mem. layout of RoRnet::StreamRegister
char sectionconfig[60]
section configuration
char name[128]
truck file name
int32_t origin_sourceid
origin sourceid
int32_t origin_streamid
origin streamid
int32_t time
initial time stamp
< Sent from the client to server and vice versa, to broadcast a new stream
int32_t type
0 = Actor, 1 = Character, 3 = ChatSystem
int32_t origin_streamid
origin streamid
int32_t origin_sourceid
origin sourceid
int32_t status
initial stream status
char username[RORNET_MAX_USERNAME_LEN]
the nickname of the user (UTF-8)
int32_t colournum
colour set by server