Skip to content

Commit bba4563

Browse files
SmallJokernerzhul
authored andcommitted
Proselytize the network. Use IEEE F32 (#8030)
* Proselytize the network. Use IEEE F32 * Remove unused V2F1000 functions
1 parent ceacff1 commit bba4563

19 files changed

+234
-259
lines changed

doc/lua_api.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5482,9 +5482,9 @@ Used by `ObjectRef` methods. Part of an Entity definition.
54825482
-- 'inventory_image'.
54835483
-- "item" is similar to "wielditem" but ignores the 'wield_image' parameter.
54845484

5485-
visual_size = {x = 1, y = 1},
5486-
-- `x` multiplies horizontal (X and Z) visual size.
5487-
-- `y` multiplies vertical (Y) visual size.
5485+
visual_size = {x = 1, y = 1, z = 1},
5486+
-- Multipliers for the visual size. If `z` is not specified, `x` will be used
5487+
-- to scale the entity along both horizontal axes.
54885488

54895489
mesh = "model",
54905490

src/client/content_cao.cpp

+35-41
Original file line numberDiff line numberDiff line change
@@ -357,24 +357,23 @@ void GenericCAO::initialize(const std::string &data)
357357
void GenericCAO::processInitData(const std::string &data)
358358
{
359359
std::istringstream is(data, std::ios::binary);
360-
int num_messages = 0;
361-
// version
362-
u8 version = readU8(is);
363-
// check version
364-
if (version == 1) { // In PROTOCOL_VERSION 14
365-
m_name = deSerializeString(is);
366-
m_is_player = readU8(is);
367-
m_id = readU16(is);
368-
m_position = readV3F1000(is);
369-
m_rotation = readV3F1000(is);
370-
m_hp = readS16(is);
371-
num_messages = readU8(is);
372-
} else {
373-
errorstream<<"GenericCAO: Unsupported init data version"
374-
<<std::endl;
360+
const u8 version = readU8(is);
361+
362+
if (version < 1) {
363+
errorstream << "GenericCAO: Unsupported init data version"
364+
<< std::endl;
375365
return;
376366
}
377367

368+
// PROTOCOL_VERSION >= 37
369+
m_name = deSerializeString(is);
370+
m_is_player = readU8(is);
371+
m_id = readU16(is);
372+
m_position = readV3F32(is);
373+
m_rotation = readV3F32(is);
374+
m_hp = readS16(is);
375+
const u8 num_messages = readU8(is);
376+
378377
for (int i = 0; i < num_messages; i++) {
379378
std::string message = deSerializeLongString(is);
380379
processMessage(message);
@@ -546,7 +545,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
546545
m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
547546
u8 li = m_last_light;
548547
m_spritenode->setColor(video::SColor(255,li,li,li));
549-
m_spritenode->setSize(m_prop.visual_size*BS);
548+
m_spritenode->setSize(v2f(m_prop.visual_size.X,
549+
m_prop.visual_size.Y) * BS);
550550
{
551551
const float txs = 1.0 / 1;
552552
const float tys = 1.0 / 1;
@@ -622,9 +622,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
622622
m_meshnode->grab();
623623
mesh->drop();
624624

625-
m_meshnode->setScale(v3f(m_prop.visual_size.X,
626-
m_prop.visual_size.Y,
627-
m_prop.visual_size.X));
625+
m_meshnode->setScale(m_prop.visual_size);
628626
u8 li = m_last_light;
629627
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
630628

@@ -643,9 +641,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
643641
m_animated_meshnode->grab();
644642
mesh->drop(); // The scene node took hold of it
645643
m_animated_meshnode->animateJoints(); // Needed for some animations
646-
m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
647-
m_prop.visual_size.Y,
648-
m_prop.visual_size.X));
644+
m_animated_meshnode->setScale(m_prop.visual_size);
649645
u8 li = m_last_light;
650646

651647
// set vertex colors to ensure alpha is set
@@ -683,9 +679,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
683679
m_wield_meshnode->setItem(item, m_client,
684680
(m_prop.visual == "wielditem"));
685681

686-
m_wield_meshnode->setScale(
687-
v3f(m_prop.visual_size.X / 2, m_prop.visual_size.Y / 2,
688-
m_prop.visual_size.X / 2));
682+
m_wield_meshnode->setScale(m_prop.visual_size / 2.0f);
689683
u8 li = m_last_light;
690684
m_wield_meshnode->setColor(video::SColor(255, li, li, li));
691685
} else {
@@ -1393,7 +1387,7 @@ void GenericCAO::processMessage(const std::string &data)
13931387
} else if (cmd == GENERIC_CMD_SET_SPRITE) {
13941388
v2s16 p = readV2S16(is);
13951389
int num_frames = readU16(is);
1396-
float framelength = readF1000(is);
1390+
float framelength = readF32(is);
13971391
bool select_horiz_by_yawpitch = readU8(is);
13981392

13991393
m_tx_basepos = p;
@@ -1403,9 +1397,9 @@ void GenericCAO::processMessage(const std::string &data)
14031397

14041398
updateTexturePos();
14051399
} else if (cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE) {
1406-
float override_speed = readF1000(is);
1407-
float override_jump = readF1000(is);
1408-
float override_gravity = readF1000(is);
1400+
float override_speed = readF32(is);
1401+
float override_jump = readF32(is);
1402+
float override_gravity = readF32(is);
14091403
// these are sent inverted so we get true when the server sends nothing
14101404
bool sneak = !readU8(is);
14111405
bool sneak_glitch = !readU8(is);
@@ -1424,11 +1418,11 @@ void GenericCAO::processMessage(const std::string &data)
14241418
}
14251419
} else if (cmd == GENERIC_CMD_SET_ANIMATION) {
14261420
// TODO: change frames send as v2s32 value
1427-
v2f range = readV2F1000(is);
1421+
v2f range = readV2F32(is);
14281422
if (!m_is_local_player) {
14291423
m_animation_range = v2s32((s32)range.X, (s32)range.Y);
1430-
m_animation_speed = readF1000(is);
1431-
m_animation_blend = readF1000(is);
1424+
m_animation_speed = readF32(is);
1425+
m_animation_blend = readF32(is);
14321426
// these are sent inverted so we get true when the server sends nothing
14331427
m_animation_loop = !readU8(is);
14341428
updateAnimation();
@@ -1437,8 +1431,8 @@ void GenericCAO::processMessage(const std::string &data)
14371431
if(player->last_animation == NO_ANIM)
14381432
{
14391433
m_animation_range = v2s32((s32)range.X, (s32)range.Y);
1440-
m_animation_speed = readF1000(is);
1441-
m_animation_blend = readF1000(is);
1434+
m_animation_speed = readF32(is);
1435+
m_animation_blend = readF32(is);
14421436
// these are sent inverted so we get true when the server sends nothing
14431437
m_animation_loop = !readU8(is);
14441438
}
@@ -1457,12 +1451,12 @@ void GenericCAO::processMessage(const std::string &data)
14571451
}
14581452
}
14591453
} else if (cmd == GENERIC_CMD_SET_ANIMATION_SPEED) {
1460-
m_animation_speed = readF1000(is);
1454+
m_animation_speed = readF32(is);
14611455
updateAnimationSpeed();
14621456
} else if (cmd == GENERIC_CMD_SET_BONE_POSITION) {
14631457
std::string bone = deSerializeString(is);
1464-
v3f position = readV3F1000(is);
1465-
v3f rotation = readV3F1000(is);
1458+
v3f position = readV3F32(is);
1459+
v3f rotation = readV3F32(is);
14661460
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
14671461

14681462
updateBonePosition();
@@ -1482,8 +1476,8 @@ void GenericCAO::processMessage(const std::string &data)
14821476
}
14831477

14841478
m_attachment_bone = deSerializeString(is);
1485-
m_attachment_position = readV3F1000(is);
1486-
m_attachment_rotation = readV3F1000(is);
1479+
m_attachment_position = readV3F32(is);
1480+
m_attachment_rotation = readV3F32(is);
14871481

14881482
// localplayer itself can't be attached to localplayer
14891483
if (!m_is_local_player) {
@@ -1510,7 +1504,7 @@ void GenericCAO::processMessage(const std::string &data)
15101504
// As there is no definition, make a smoke puff
15111505
ClientSimpleObject *simple = createSmokePuff(
15121506
m_smgr, m_env, m_position,
1513-
m_prop.visual_size * BS);
1507+
v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS);
15141508
m_env->addSimpleObject(simple);
15151509
} else if (m_reset_textures_timer < 0) {
15161510
// TODO: Execute defined fast response
@@ -1581,7 +1575,7 @@ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem,
15811575
// As there is no definition, make a smoke puff
15821576
ClientSimpleObject *simple = createSmokePuff(
15831577
m_smgr, m_env, m_position,
1584-
m_prop.visual_size * BS);
1578+
v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS);
15851579
m_env->addSimpleObject(simple);
15861580
}
15871581
// TODO: Execute defined fast response

src/content_sao.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
549549
os << serializeString(""); // name
550550
writeU8(os, 0); // is_player
551551
writeS16(os, getId()); //id
552-
writeV3F1000(os, m_base_position);
553-
writeV3F1000(os, m_rotation);
552+
writeV3F32(os, m_base_position);
553+
writeV3F32(os, m_rotation);
554554
writeS16(os, m_hp);
555555

556556
std::ostringstream msg_os(std::ios::binary);
@@ -873,7 +873,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p
873873
m_prop.pointable = true;
874874
// Start of default appearance, this should be overwritten by Lua
875875
m_prop.visual = "upright_sprite";
876-
m_prop.visual_size = v2f(1, 2);
876+
m_prop.visual_size = v3f(1, 2, 1);
877877
m_prop.textures.clear();
878878
m_prop.textures.emplace_back("player.png");
879879
m_prop.textures.emplace_back("player_back.png");
@@ -947,8 +947,8 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
947947
os << serializeString(m_player->getName()); // name
948948
writeU8(os, 1); // is_player
949949
writeS16(os, getId()); // id
950-
writeV3F1000(os, m_base_position);
951-
writeV3F1000(os, m_rotation);
950+
writeV3F32(os, m_base_position);
951+
writeV3F32(os, m_rotation);
952952
writeS16(os, getHP());
953953

954954
std::ostringstream msg_os(std::ios::binary);

src/genericobject.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ std::string gob_cmd_set_sprite(
8787
// parameters
8888
writeV2S16(os, p);
8989
writeU16(os, num_frames);
90-
writeF1000(os, framelength);
90+
writeF32(os, framelength);
9191
writeU8(os, select_horiz_by_yawpitch);
9292
return os.str();
9393
}
@@ -123,9 +123,9 @@ std::string gob_cmd_update_physics_override(float physics_override_speed, float
123123
// command
124124
writeU8(os, GENERIC_CMD_SET_PHYSICS_OVERRIDE);
125125
// parameters
126-
writeF1000(os, physics_override_speed);
127-
writeF1000(os, physics_override_jump);
128-
writeF1000(os, physics_override_gravity);
126+
writeF32(os, physics_override_speed);
127+
writeF32(os, physics_override_jump);
128+
writeF32(os, physics_override_gravity);
129129
// these are sent inverted so we get true when the server sends nothing
130130
writeU8(os, !sneak);
131131
writeU8(os, !sneak_glitch);
@@ -139,9 +139,9 @@ std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_
139139
// command
140140
writeU8(os, GENERIC_CMD_SET_ANIMATION);
141141
// parameters
142-
writeV2F1000(os, frames);
143-
writeF1000(os, frame_speed);
144-
writeF1000(os, frame_blend);
142+
writeV2F32(os, frames);
143+
writeF32(os, frame_speed);
144+
writeF32(os, frame_blend);
145145
// these are sent inverted so we get true when the server sends nothing
146146
writeU8(os, !frame_loop);
147147
return os.str();
@@ -153,7 +153,7 @@ std::string gob_cmd_update_animation_speed(float frame_speed)
153153
// command
154154
writeU8(os, GENERIC_CMD_SET_ANIMATION_SPEED);
155155
// parameters
156-
writeF1000(os, frame_speed);
156+
writeF32(os, frame_speed);
157157
return os.str();
158158
}
159159

@@ -165,8 +165,8 @@ std::string gob_cmd_update_bone_position(const std::string &bone, v3f position,
165165
writeU8(os, GENERIC_CMD_SET_BONE_POSITION);
166166
// parameters
167167
os<<serializeString(bone);
168-
writeV3F1000(os, position);
169-
writeV3F1000(os, rotation);
168+
writeV3F32(os, position);
169+
writeV3F32(os, rotation);
170170
return os.str();
171171
}
172172

@@ -179,8 +179,8 @@ std::string gob_cmd_update_attachment(int parent_id, const std::string &bone,
179179
// parameters
180180
writeS16(os, parent_id);
181181
os<<serializeString(bone);
182-
writeV3F1000(os, position);
183-
writeV3F1000(os, rotation);
182+
writeV3F32(os, position);
183+
writeV3F32(os, rotation);
184184
return os.str();
185185
}
186186

0 commit comments

Comments
 (0)