-
Notifications
You must be signed in to change notification settings - Fork 20
/
Moves.cpp
100 lines (77 loc) · 2.06 KB
/
Moves.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "StdAfx.h"
#include "WeenieObject.h"
#include "PhysicsObj.h"
#include "World.h"
#include "ObjectMsgs.h"
void CPhysicsObj::Movement_Init()
{
_next_move_think = 0.0;
}
void CPhysicsObj::Movement_Shutdown()
{
}
void CPhysicsObj::Movement_Think()
{
if (parent)
return;
if (_next_move_think < Timer::cur_time)
{
if (m_Position.objcell_id != _last_move_position.objcell_id || !m_Position.frame.is_vector_equal(_last_move_position.frame))
{
Movement_UpdatePos();
// Animation_Update();
}
else if (!m_Position.frame.is_quaternion_equal(_last_move_position.frame))
{
Movement_UpdatePos();
}
_next_move_think = Timer::cur_time + 1.0;
}
}
void CPhysicsObj::Movement_SendUpdate(DWORD dwCell)
{
if (CWeenieObject *pWeenie = GetWeenie())
{
BinaryWriter* poo = MoveUpdate(pWeenie);
g_pWorld->BroadcastPVS(dwCell, poo->GetData(), poo->GetSize());
delete poo;
}
}
void CPhysicsObj::Movement_UpdatePos()
{
if (parent)
return;
//QUICKFIX: Broadcast to the old landblock that we've moved from.
//This sends duplicates if the block is near the other.
_position_timestamp++;
_last_update_pos = Timer::cur_time;
DWORD dwNewCell = GetLandcell();
DWORD dwOldCell = _last_move_position.objcell_id;
if (BLOCK_WORD(dwOldCell) != BLOCK_WORD(dwNewCell))
{
Movement_SendUpdate(dwOldCell);
}
Movement_SendUpdate(dwNewCell);
_last_move_position = m_Position;
/*
GetWeenie()->EmoteLocal(csprintf("Sending position update. Pos: %.1f %.1f %.1f v: %.1f %.1f %.1f",
m_Position.frame.m_origin.x, m_Position.frame.m_origin.y, m_Position.frame.m_origin.z,
m_velocityVector.x, m_velocityVector.y, m_velocityVector.z));
*/
}
void CPhysicsObj::Movement_UpdateVector()
{
if (parent)
return;
BinaryWriter moveMsg;
moveMsg.Write<DWORD>(0xF74E);
moveMsg.Write<DWORD>(id);
// velocity
Vector localVel = m_velocityVector;
localVel.Pack(&moveMsg);
// omega
m_Omega.Pack(&moveMsg);
moveMsg.Write<WORD>(_instance_timestamp);
moveMsg.Write<WORD>(++_vector_timestamp);
g_pWorld->BroadcastPVS(this, moveMsg.GetData(), moveMsg.GetSize(), OBJECT_MSG);
}