Skip to content

Commit

Permalink
yet another shared_str replacement (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-dex committed Nov 6, 2017
1 parent ee987c8 commit ec1ea28
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 131 deletions.
9 changes: 4 additions & 5 deletions code/engine/xrEngine/SkeletonMotions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void CPartition::load(IKinematics* V, LPCSTR model_name) {
}
}

u16 find_bone_id(vecBones* bones, shared_str nm) {
u16 find_bone_id(vecBones* bones, const std::string_view nm) {
for (u16 i = 0; i < (u16)bones->size(); i++)
if (bones->at(i)->name == nm)
return i;
Expand Down Expand Up @@ -216,11 +216,10 @@ BOOL motions_value::load(LPCSTR N, IReader* data, vecBones* bones) {
return bRes;
}

MotionVec* motions_value::bone_motions(shared_str bone_name) {
auto I = m_motions.find(bone_name);
// VERIFY (I != m_motions.end());
MotionVec* motions_value::bone_motions(const std::string& bone_name) {
const auto I = m_motions.find(bone_name);
if (I == m_motions.end())
return (0);
return nullptr;

return (&(*I).second);
}
Expand Down
7 changes: 3 additions & 4 deletions code/engine/xrEngine/SkeletonMotions.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ using MotionDefVec = xr_vector<CMotionDef>;

using MotionVec = xr_vector<CMotion>;
using BoneMotionsVec = xr_vector<MotionVec*>;
using BoneMotionMap = xr_map<shared_str, MotionVec>;
using BoneMotionMap = xr_map<std::string, MotionVec>;

// partition
class ENGINE_API CPartDef {
Expand Down Expand Up @@ -193,7 +193,7 @@ struct ENGINE_API motions_value {
shared_str m_id;

BOOL load(LPCSTR N, IReader* data, vecBones* bones);
MotionVec* bone_motions(shared_str bone_name);
MotionVec* bone_motions(const std::string& bone_name);

u32 mem_usage() {
u32 sz = sizeof(*this) + m_motion_map.size() * 6 + m_partition.mem_usage();
Expand Down Expand Up @@ -259,8 +259,7 @@ class ENGINE_API shared_motions {
bool operator==(shared_motions const& rhs) const { return (p_ == rhs.p_); }

// misc func
MotionVec* bone_motions(shared_str bone_name) {
VERIFY(p_);
MotionVec* bone_motions(const std::string& bone_name) const {
return p_->bone_motions(bone_name);
}
accel_map* motion_map() {
Expand Down
2 changes: 1 addition & 1 deletion code/engine/xrEngine/ai_script_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef lua_State CLuaVirtualMachine;
struct SMemberCallback {
luabind::functor<void>* m_lua_function;
luabind::object* m_lua_object;
shared_str m_method_name;
std::string m_method_name;
};

#include "ai_script_lua_space.h"
2 changes: 1 addition & 1 deletion code/engine/xrEngine/bone.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "stdafx.h"
#pragma hdrstop

#include "bone.h"
#include "gamemtllib.h"

// TODO: [imdex] use string_view
u16 CBone::get_game_mtl_idx() const { return GMLib.GetMaterialIdx(game_mtl.c_str()); }

static const Fobb dummy = Fobb().identity();
Expand Down
83 changes: 43 additions & 40 deletions code/engine/xrEngine/bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ class CBone;
using BoneVec = xr_vector<CBone*>;

class ECORE_API CBone : public CBoneInstance, public IBoneData {
shared_str name;
shared_str parent_name;
shared_str wmap;
std::string name;
std::string parent_name;
std::string wmap;
Fvector rest_offset;
Fvector rest_rotate; // XYZ format (Game format)
float rest_length;
Expand Down Expand Up @@ -325,7 +325,7 @@ class ECORE_API CBone : public CBoneInstance, public IBoneData {
flSelected = (1 << 0),
};
SJointIKData IK_data;
shared_str game_mtl;
std::string game_mtl;
SBoneShape shape;

float mass;
Expand All @@ -335,43 +335,46 @@ class ECORE_API CBone : public CBoneInstance, public IBoneData {
CBone();
virtual ~CBone();

// TODO: [imdex] use string_view
void SetName(const char* p) {
name = p;
name = p ? p : "";
xr_strlwr(name);
}
// TODO: [imdex] use string_view
void SetParentName(const char* p) {
parent_name = p;
parent_name = p ? p : "";
xr_strlwr(parent_name);
}
void SetWMap(const char* p) { wmap = p; }
// TODO: [imdex] use string_view
void SetWMap(const char* p) { wmap = p ? p : ""; }
void SetRestParams(float length, const Fvector& offset, const Fvector& rotate) {
rest_offset.set(offset);
rest_rotate.set(rotate);
rest_length = length;
};

shared_str Name() { return name; }
shared_str ParentName() { return parent_name; }
shared_str WMap() { return wmap; }
IC CBone* Parent() { return parent; }
IC BOOL IsRoot() { return (parent == 0); }
shared_str& NameRef() { return name; }
const std::string& Name() const { return name; }
const std::string& ParentName() const { return parent_name; }
const std::string& WMap() const { return wmap; }
CBone* Parent() { return parent; }
BOOL IsRoot() { return parent == nullptr; }
std::string& NameRef() { return name; }

// transformation
const Fvector& _Offset() { return mot_offset; }
const Fvector& _Rotate() { return mot_rotate; }
float _Length() { return mot_length; }
IC Fmatrix& _RTransform() { return rest_transform; }
IC Fmatrix& _RITransform() { return rest_i_transform; }
IC Fmatrix& _LRTransform() { return local_rest_transform; }
IC Fmatrix& _MTransform() { return mot_transform; }
Fmatrix& _RTransform() { return rest_transform; }
Fmatrix& _RITransform() { return rest_i_transform; }
Fmatrix& _LRTransform() { return local_rest_transform; }
Fmatrix& _MTransform() { return mot_transform; }

IC Fmatrix& _LTransform() { return mTransform; } //{return last_transform;}
IC const Fmatrix& _LTransform() const { return mTransform; }
Fmatrix& _LTransform() { return mTransform; } //{return last_transform;}
const Fmatrix& _LTransform() const { return mTransform; }

IC Fmatrix& _RenderTransform() { return mRenderTransform; } //{return render_transform;}
IC Fvector& _RestOffset() { return rest_offset; }
IC Fvector& _RestRotate() { return rest_rotate; }
Fmatrix& _RenderTransform() { return mRenderTransform; } //{return render_transform;}
Fvector& _RestOffset() { return rest_offset; }
Fvector& _RestRotate() { return rest_rotate; }

void _Update(const Fvector& T, const Fvector& R) {
mot_offset.set(T);
Expand All @@ -389,11 +392,11 @@ class ECORE_API CBone : public CBoneInstance, public IBoneData {
void Load_0(IReader& F);
void Load_1(IReader& F);

IC float _BCL engine_lo_limit(u8 k) const { return -IK_data.limits[k].limit.y; }
IC float _BCL engine_hi_limit(u8 k) const { return -IK_data.limits[k].limit.x; }
float engine_lo_limit(u8 k) const { return -IK_data.limits[k].limit.y; }
float engine_hi_limit(u8 k) const { return -IK_data.limits[k].limit.x; }

IC float _BCL editor_lo_limit(u8 k) const { return IK_data.limits[k].limit.x; }
IC float _BCL editor_hi_limit(u8 k) const { return IK_data.limits[k].limit.y; }
float editor_lo_limit(u8 k) const { return IK_data.limits[k].limit.x; }
float editor_hi_limit(u8 k) const { return IK_data.limits[k].limit.y; }

void SaveData(IWriter& F);
void LoadData(IReader& F);
Expand All @@ -419,26 +422,26 @@ class ECORE_API CBone : public CBoneInstance, public IBoneData {
bool ExportOGF(IWriter& F);
#endif
private:
IBoneData& _BCL GetChild(u16 id) { return *children[id]; }
const IBoneData& _BCL GetChild(u16 id) const { return *children[id]; }
u16 _BCL GetSelfID() const { return (u16)SelfID; }
u16 _BCL GetNumChildren() const { return u16(children.size()); }
const SJointIKData& _BCL get_IK_data() const { return IK_data; }
const Fmatrix& _BCL get_bind_transform() const { return local_rest_transform; }
const SBoneShape& _BCL get_shape() const { return shape; }
IBoneData& GetChild(u16 id) { return *children[id]; }
const IBoneData& GetChild(u16 id) const { return *children[id]; }
u16 GetSelfID() const { return (u16)SelfID; }
u16 GetNumChildren() const { return u16(children.size()); }
const SJointIKData& get_IK_data() const { return IK_data; }
const Fmatrix& get_bind_transform() const { return local_rest_transform; }
const SBoneShape& get_shape() const { return shape; }

const Fobb& _BCL get_obb() const;
const Fvector& _BCL get_center_of_mass() const { return center_of_mass; }
float _BCL get_mass() const { return mass; }
const Fvector& get_center_of_mass() const { return center_of_mass; }
float get_mass() const { return mass; }
u16 _BCL get_game_mtl_idx() const;
u16 _BCL GetParentID() const {
u16 GetParentID() const {
if (parent)
return u16(parent->SelfID);
else
return u16(-1);
};
float _BCL lo_limit(u8 k) const { return engine_lo_limit(k); }
float _BCL hi_limit(u8 k) const { return engine_hi_limit(k); }
float lo_limit(u8 k) const { return engine_lo_limit(k); }
float hi_limit(u8 k) const { return engine_hi_limit(k); }
};

//*** Shared Bone Data ****************************************************************************
Expand All @@ -453,14 +456,14 @@ class ENGINE_API CBoneData : public IBoneData {
u16 ParentID;

public:
shared_str name;
std::string name;

Fobb obb;

Fmatrix bind_transform;
Fmatrix m2b_transform; // model to bone conversion transform
SBoneShape shape;
shared_str game_mtl_name;
std::string game_mtl_name;
u16 game_mtl_idx;
SJointIKData IK_data;
float mass;
Expand Down
6 changes: 4 additions & 2 deletions code/engine/xrGame/BoneProtections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void SBoneProtections::reload(const shared_str& bone_sect, IKinematics* kinemati
if (!xr_strcmp(i->first.c_str(), "hit_fraction"))
continue;

s16 bone_id = kinematics->LL_BoneID(i->first);
// TODO: [imdex] remove shared_str
s16 bone_id = kinematics->LL_BoneID(*i->first);
R_ASSERT2(BI_NONE != bone_id, i->first.c_str());
m_bones_koeff.insert(std::make_pair(bone_id, BP));
}
Expand All @@ -80,7 +81,8 @@ void SBoneProtections::add(const shared_str& bone_sect, IKinematics* kinematics)
BP.koeff += (float)atof(_GetItem(i->second.c_str(), 0, buffer));
BP.armor += (float)atof(_GetItem(i->second.c_str(), 1, buffer));
} else {
s16 bone_id = kinematics->LL_BoneID(i->first);
// TODO: [imdex] remove shared_str
s16 bone_id = kinematics->LL_BoneID(*i->first);
R_ASSERT2(BI_NONE != bone_id, i->first.c_str());
BoneProtection& BP = m_bones_koeff[bone_id];
BP.koeff += (float)atof(_GetItem(i->second.c_str(), 0, buffer));
Expand Down
3 changes: 2 additions & 1 deletion code/engine/xrGame/CarInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ bool CCar::bfAssignObject(CScriptEntityAction* tpEntityAction) {
if (l_tObjectAction.m_bCompleted || !xr_strlen(l_tObjectAction.m_caBoneName))
return ((l_tObjectAction.m_bCompleted = true) == false);

s16 l_sBoneID = smart_cast<IKinematics*>(Visual())->LL_BoneID(l_tObjectAction.m_caBoneName);
// TODO: [imdex] remove shared_str
s16 l_sBoneID = smart_cast<IKinematics*>(Visual())->LL_BoneID(*l_tObjectAction.m_caBoneName);
if (is_Door(l_sBoneID)) {
switch (l_tObjectAction.m_tGoalType) {
case MonsterSpace::eObjectActionActivate: {
Expand Down
5 changes: 3 additions & 2 deletions code/engine/xrGame/GamePersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ void CGamePersistent::RegisterModel(IRenderVisual* V) {
int cnt = K->LL_BoneCount();
for (u16 k = 0; k < cnt; k++) {
CBoneData& bd = K->LL_GetData(k);
if (*(bd.game_mtl_name)) {
bd.game_mtl_idx = GMLib.GetMaterialIdx(*bd.game_mtl_name);
if (!bd.game_mtl_name.empty()) {
// TODO: [imdex] use string_view
bd.game_mtl_idx = GMLib.GetMaterialIdx(bd.game_mtl_name.c_str());
R_ASSERT2(GMLib.GetMaterialByIdx(bd.game_mtl_idx)->Flags.is(SGameMtl::flDynamic),
"Required dynamic game material");
} else {
Expand Down
3 changes: 2 additions & 1 deletion code/engine/xrGame/Torch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ void CTorch::Switch(bool light_on) {
if (*light_trace_bone) {
IKinematics* pVisual = smart_cast<IKinematics*>(Visual());
VERIFY(pVisual);
u16 bi = pVisual->LL_BoneID(light_trace_bone);
// TODO: [imdex] remove shared_str
u16 bi = pVisual->LL_BoneID(*light_trace_bone);

pVisual->LL_SetBoneVisible(bi, light_on, TRUE);
pVisual->CalculateBones(TRUE);
Expand Down
9 changes: 6 additions & 3 deletions code/engine/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,8 @@ void CWeapon::UpdateAddonsVisibility() {

pWeaponVisual->CalculateBones_Invalidate();

bone_id = pWeaponVisual->LL_BoneID(wpn_scope);
// TODO: [imdex] remove shared_str
bone_id = pWeaponVisual->LL_BoneID(*wpn_scope);
if (ScopeAttachable()) {
if (IsScopeAttached()) {
if (!pWeaponVisual->LL_GetBoneVisible(bone_id))
Expand All @@ -1149,7 +1150,8 @@ void CWeapon::UpdateAddonsVisibility() {
pWeaponVisual->LL_SetBoneVisible(bone_id, FALSE, TRUE);
// Log("scope", pWeaponVisual->LL_GetBoneVisible (bone_id));
}
bone_id = pWeaponVisual->LL_BoneID(wpn_silencer);
// TODO: [imdex] remove shared_str
bone_id = pWeaponVisual->LL_BoneID(*wpn_silencer);
if (SilencerAttachable()) {
if (IsSilencerAttached()) {
if (!pWeaponVisual->LL_GetBoneVisible(bone_id))
Expand All @@ -1165,7 +1167,8 @@ void CWeapon::UpdateAddonsVisibility() {
// Log("silencer", pWeaponVisual->LL_GetBoneVisible (bone_id));
}

bone_id = pWeaponVisual->LL_BoneID(wpn_grenade_launcher);
// TODO: [imdex] remove shared_str
bone_id = pWeaponVisual->LL_BoneID(*wpn_grenade_launcher);
if (GrenadeLauncherAttachable()) {
if (IsGrenadeLauncherAttached()) {
if (!pWeaponVisual->LL_GetBoneVisible(bone_id))
Expand Down
6 changes: 4 additions & 2 deletions code/engine/xrGame/WeaponKnife.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ void CWeaponKnife::OnRender() {
renderer.draw_ellipse (sphere, D3DCOLOR_XRGB(255, 0, 0));
renderer.draw_line (Fidentity, m_dbg_data.m_pos, m_dbg_data.m_endpos,
D3DCOLOR_XRGB(255, 255, 0));
sphere.c = m_dbg_data.m_endpos;
renderer.draw_ellipse (sphere, D3DCOLOR_XRGB(100, 255, 0));*/
// Fvector victim_end (m_dbg_data.m_pos);
Expand Down Expand Up @@ -473,7 +474,8 @@ void CWeaponKnife::GetVictimPos(CEntityAlive* victim, Fvector& pos_dest) {
tmp_box.get_CD(pos_dest, tmp_fake_vec);
pos_dest.add(victim->Position());
}
CBoneData& tmp_bone_data = tmp_kinem->LL_GetData(hit_bone_id);
Fmatrix & tmp_xform = victim->XFORM();
CBoneInstance &bi = tmp_kinem->LL_GetBoneInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,6 @@ void CBaseMonster::fill_bones_body_parts(LPCSTR body_part, CriticalWoundType wou
auto E = body_part_section.Data.cend();
for (; I != E; ++I)
m_bones_body_parts.insert(
std::make_pair(kinematics->LL_BoneID((*I).first), u32(wound_type)));
// TODO: [imdex] remove shared_str
std::make_pair(kinematics->LL_BoneID(*(*I).first), u32(wound_type)));
}
6 changes: 4 additions & 2 deletions code/engine/xrGame/ai/stalker/ai_stalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ void CAI_Stalker::fill_bones_body_parts(LPCSTR bone_id, const ECriticalWoundType
auto E = body_part_section.Data.cend();
for (; I != E; ++I)
m_bones_body_parts.insert(
std::make_pair(kinematics->LL_BoneID((*I).first), u32(wound_type)));
// TODO: [imdex] remove shared_str
std::make_pair(kinematics->LL_BoneID(*(*I).first), u32(wound_type)));
}

void CAI_Stalker::on_before_change_team() {
Expand Down Expand Up @@ -1471,7 +1472,8 @@ void aim_target(shared_str const& aim_bone_id, Fvector& result, const CGameObjec
IKinematics* kinematics = smart_cast<IKinematics*>(object->Visual());
VERIFY(kinematics);

u16 bone_id = kinematics->LL_BoneID(aim_bone_id);
// TODO: [imdex] remove shared_str
u16 bone_id = kinematics->LL_BoneID(*aim_bone_id);
VERIFY2(bone_id != BI_NONE, make_string("Cannot find bone %s", bone_id));

Fmatrix const& bone_matrix = kinematics->LL_GetTransform(bone_id);
Expand Down
3 changes: 2 additions & 1 deletion code/engine/xrGame/ai/stalker/ai_stalker_script_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ bool CAI_Stalker::bfAssignWatch(CScriptEntityAction* tpEntityAction) {
smart_cast<IKinematics*>(l_tWatchAction.m_tpObjectToWatch->Visual())
->LL_GetBoneInstance(
smart_cast<IKinematics*>(l_tWatchAction.m_tpObjectToWatch->Visual())
->LL_BoneID(l_tWatchAction.m_bone_to_watch));
// TODO: [imdex] remove shared_str
->LL_BoneID(*l_tWatchAction.m_bone_to_watch));
Fmatrix l_tMatrix;

l_tMatrix = l_tBoneInstance.mTransform;
Expand Down
6 changes: 4 additions & 2 deletions code/engine/xrGame/attachment_owner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ void CAttachmentOwner::attach(CInventoryItem* inventory_item) {
if (m_attached_objects.empty())
game_object->add_visual_callback(AttachmentCallback);
attachable_item->set_bone_id(smart_cast<IKinematics*>(game_object->Visual())
->LL_BoneID(attachable_item->bone_name()));
// TODO: [imdex] remove shared_str
->LL_BoneID(*attachable_item->bone_name()));
m_attached_objects.push_back(smart_cast<CAttachableItem*>(inventory_item));

inventory_item->object().setVisible(true);
Expand Down Expand Up @@ -153,7 +154,8 @@ void CAttachmentOwner::reattach_items() {
CAttachableItem* attachable_item = *I;
VERIFY(attachable_item);
attachable_item->set_bone_id(smart_cast<IKinematics*>(game_object->Visual())
->LL_BoneID(attachable_item->bone_name()));
// TODO: [imdex] remove shared_str
->LL_BoneID(*attachable_item->bone_name()));
}
}

Expand Down
Loading

0 comments on commit ec1ea28

Please sign in to comment.