MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiDoAdjustPosition

Function MultiDoAdjustPosition

Descent3/multi.cpp:8863–8947  ·  view source on GitHub ↗

The server is telling me to adjust my position

Source from the content-addressed store, hash-verified

8861
8862// The server is telling me to adjust my position
8863void MultiDoAdjustPosition(uint8_t *data) {
8864 int count = 0;
8865 SKIP_HEADER(data, &count);
8866
8867 float timestamp = MultiGetFloat(data, &count);
8868
8869 vector newpos, newvel;
8870
8871 // memcpy (&newpos,&data[count],sizeof(vector));
8872 // count+=sizeof(vector);
8873 newpos = MultiGetVector(data, &count);
8874 // memcpy (&newvel,&data[count],sizeof(vector));
8875 // count+=sizeof(vector);
8876 newvel = MultiGetVector(data, &count);
8877
8878 int roomnum = MultiGetInt(data, &count);
8879
8880 object *obj = &Objects[Players[Player_num].objnum];
8881
8882 ObjSetPos(obj, &newpos, roomnum, &obj->orient, true);
8883 obj->mtype.phys_info.velocity = newvel;
8884
8885 float save_frametime = Frametime;
8886 int start_move = -1, end_move = -1;
8887
8888 // Now go through and adjust our position based on our saved moves
8889 for (int i = 0; i < MAX_SAVED_MOVES; i++) {
8890 int next = i + 1;
8891 int prev = i - 1;
8892
8893 if (next == MAX_SAVED_MOVES)
8894 next = 0;
8895 if (prev == -1)
8896 prev = MAX_SAVED_MOVES - 1;
8897
8898 if (start_move == -1 && SavedMoves[prev].timestamp < timestamp && SavedMoves[i].timestamp >= timestamp)
8899 start_move = i;
8900 if (end_move == -1 && SavedMoves[i].timestamp >= timestamp && SavedMoves[next].timestamp < timestamp)
8901 end_move = i;
8902 }
8903
8904 ASSERT(start_move != -1); // HUH? We don't have a copy of this move in our list
8905 ASSERT(end_move != -1);
8906
8907 int cur_move = start_move;
8908 int done = 0;
8909
8910 vector save_thrust, save_rotthrust;
8911 save_thrust = obj->mtype.phys_info.thrust;
8912 save_rotthrust = obj->mtype.phys_info.rotthrust;
8913
8914 while (!done) {
8915 int next = cur_move + 1;
8916 int next_end = end_move + 1;
8917
8918 if (next == MAX_SAVED_MOVES)
8919 next = 0;
8920

Callers 1

MultiProcessDataFunction · 0.85

Calls 6

SKIP_HEADERFunction · 0.85
MultiGetFloatFunction · 0.85
MultiGetVectorFunction · 0.85
MultiGetIntFunction · 0.85
ObjSetPosFunction · 0.85
do_physics_simFunction · 0.85

Tested by

no test coverage detected