Skip to content

Commit 3c6df26

Browse files
Goober5000claude
andcommitted
remove redundant waypoint position by delegating to the game object
The waypoint class stored its position in m_position separately from the game object's pos field, requiring callers to manually keep both in sync. Now get_pos() and set_pos() delegate to the object position when the game object exists, falling back to the parsed position only if the object does not exist. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9958531 commit 3c6df26

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

code/object/waypoint.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const int INVALID_WAYPOINT_POSITION = INT_MAX;
2020
//********************CLASS MEMBERS********************
2121
waypoint::waypoint()
2222
{
23-
this->m_position.xyz.x = 0.0f;
24-
this->m_position.xyz.y = 0.0f;
25-
this->m_position.xyz.z = 0.0f;
23+
this->m_parsed_position.xyz.x = 0.0f;
24+
this->m_parsed_position.xyz.y = 0.0f;
25+
this->m_parsed_position.xyz.z = 0.0f;
2626

2727
this->m_objnum = -1;
2828
}
@@ -31,9 +31,9 @@ waypoint::waypoint(const vec3d *position)
3131
{
3232
Assert(position != NULL);
3333

34-
this->m_position.xyz.x = position->xyz.x;
35-
this->m_position.xyz.y = position->xyz.y;
36-
this->m_position.xyz.z = position->xyz.z;
34+
this->m_parsed_position.xyz.x = position->xyz.x;
35+
this->m_parsed_position.xyz.y = position->xyz.y;
36+
this->m_parsed_position.xyz.z = position->xyz.z;
3737

3838
this->m_objnum = -1;
3939
}
@@ -45,7 +45,10 @@ waypoint::~waypoint()
4545

4646
const vec3d *waypoint::get_pos() const
4747
{
48-
return &m_position;
48+
if (m_objnum >= 0)
49+
return &Objects[m_objnum].pos;
50+
51+
return &m_parsed_position;
4952
}
5053

5154
int waypoint::get_objnum() const
@@ -90,7 +93,11 @@ int waypoint::get_index() const
9093
void waypoint::set_pos(const vec3d *pos)
9194
{
9295
Assert(pos != NULL);
93-
this->m_position = *pos;
96+
97+
if (m_objnum >= 0)
98+
Objects[m_objnum].pos = *pos;
99+
else
100+
this->m_parsed_position = *pos;
94101
}
95102

96103
waypoint_list::waypoint_list()

code/object/waypoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class waypoint
2626
void set_pos(const vec3d *pos);
2727

2828
private:
29-
vec3d m_position;
29+
vec3d m_parsed_position; // only relevant until the game object is created, after which the waypoint delegates to the object position
3030
int m_objnum;
3131

3232
friend void waypoint_create_game_object(waypoint *wpt, int list_index, int wpt_index);

code/parse/sexp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9512,7 +9512,6 @@ void sexp_set_object_position(int n)
95129512

95139513
case OSWPT_TYPE_WAYPOINT:
95149514
{
9515-
oswpt.objp()->pos = target_vec;
95169515
oswpt.waypointp()->set_pos(&target_vec);
95179516
Current_sexp_network_packet.start_callback();
95189517
Current_sexp_network_packet.send_ushort(oswpt.objp()->net_signature);
@@ -9600,7 +9599,6 @@ void multi_sexp_set_object_position()
96009599
Current_sexp_network_packet.get_float(wp_vec.xyz.z);
96019600
objp = multi_get_network_object(obj_sig);
96029601
if (objp->type == OBJ_WAYPOINT) {
9603-
objp->pos = wp_vec;
96049602
waypoint *wpt = find_waypoint_with_instance(objp->instance);
96059603
wpt->set_pos(&wp_vec);
96069604
}

code/scripting/api/objs/object.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ ADE_VIRTVAR(Position, l_Object, "vector", "Object world position (World vector)"
175175
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
176176

177177
if(ADE_SETTING_VAR && v3 != NULL) {
178-
objh->objp()->pos = *v3;
179178
if (objh->objp()->type == OBJ_WAYPOINT) {
180179
waypoint *wpt = find_waypoint_with_instance(objh->objp()->instance);
181180
wpt->set_pos(v3);
181+
} else {
182+
objh->objp()->pos = *v3;
182183
}
183184

184185
if (objh->objp()->flags[Object::Object_Flags::Collides])

0 commit comments

Comments
 (0)