1 //**************************************************************************
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
10 //** Copyright (C) 1999-2006 Jānis Legzdiņš
11 //** Copyright (C) 2018-2023 Ketmar Dark
13 //** This program is free software: you can redistribute it and/or modify
14 //** it under the terms of the GNU General Public License as published by
15 //** the Free Software Foundation, version 3 of the License ONLY.
17 //** This program is distributed in the hope that it will be useful,
18 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 //** GNU General Public License for more details.
22 //** You should have received a copy of the GNU General Public License
23 //** along with this program. If not, see <http://www.gnu.org/licenses/>.
25 //**************************************************************************
27 //#include "gamedefs.h"
28 //#include "network.h"
31 //==========================================================================
33 // VNetObjectsMap::VNetObjectsMap
35 //==========================================================================
36 VNetObjectsMap::VNetObjectsMap () : Connection(nullptr) {
40 //==========================================================================
42 // VNetObjectsMap::VNetObjectsMap
44 //==========================================================================
45 VNetObjectsMap::VNetObjectsMap (VNetConnection
*AConnection
) : Connection(AConnection
) {
49 //==========================================================================
51 // VNetObjectsMap::SetUpClassLookup
53 //==========================================================================
54 void VNetObjectsMap::SetUpClassLookup () {
55 NameMap
.setLength(VName::GetNumNames());
56 NameLookup
.setLength(VName::GetNumNames());
57 for (int i
= 0; i
< VName::GetNumNames(); ++i
) {
59 NameLookup
[i
] = *(VName
*)&i
;
63 ClassLookup
.append(nullptr);
64 for (int i
= 0; i
< VMemberBase::GMembers
.length(); ++i
) {
65 if (VMemberBase::GMembers
[i
]->MemberType
== MEMBER_Class
) {
66 VClass
*cls
= static_cast<VClass
*>(VMemberBase::GMembers
[i
]);
67 if (cls
->IsChildOf(/*VThinker*/VObject::StaticClass())) {
68 ClassMap
.put(cls
, ClassLookup
.length());
69 ClassLookup
.Append(cls
);
76 //==========================================================================
78 // VNetObjectsMap::CanSerialiseObject
80 //==========================================================================
81 bool VNetObjectsMap::CanSerialiseObject (VObject
*obj
) {
82 //VThinker *Thinker = Cast<VThinker>(Obj);
83 VObject
*Thinker
= obj
;
85 // thinker can be serialised only if it has an open channel
86 //return !!Connection->ThinkerChannels.FindPtr(Thinker);
89 // we can always serialise nullptr object
95 //==========================================================================
97 // VNetObjectsMap::SerialiseName
99 //==========================================================================
100 bool VNetObjectsMap::SerialiseName (VStream
&Strm
, VName
&Name
) {
101 if (Strm
.IsLoading()) {
103 Strm
.SerialiseInt(NameIndex
/*, NameLookup.length()+1*/);
104 if ((vint32
)NameIndex
== NameLookup
.length()) {
107 Name
= NameLookup
[NameIndex
];
111 vuint32 NameIndex
= (Name
.GetIndex() < NameMap
.length() ? NameMap
[Name
.GetIndex()] : NameLookup
.length());
112 Strm
.SerialiseInt(NameIndex
/*, NameLookup.length()+1*/);
113 return ((vint32
)NameIndex
!= NameLookup
.length());
118 //==========================================================================
120 // VNetObjectsMap::SerialiseObject
122 //==========================================================================
123 bool VNetObjectsMap::SerialiseObject (VStream
&Strm
, VObject
*&obj
) {
125 if (Strm
.IsLoading()) {
127 vuint8 IsThinker
= 0;
128 Strm
.SerialiseBits(&IsThinker
, 1);
130 // it's a thinker that has an open channel
132 Strm
.SerialiseInt(Index
, MAX_CHANNELS
);
133 VChannel
*Chan
= Connection
->Channels
[Index
];
134 if (Chan
&& Chan
->Type
== CHANNEL_Thinker
&& !Chan
->Closing
) {
135 obj
= ((VThinkerChannel
*)Chan
)->Thinker
;
140 VThinker
*Thinker
= Cast
<VThinker
>(obj
);
141 vuint8 IsThinker
= !!Thinker
;
142 Strm
.SerialiseBits(&IsThinker
, 1);
144 // it's a thinker. if it has an open channel we can use it's
145 // channel number to identify it, otherwise we can't serialise it.
148 VThinkerChannel
*Chan
= Connection
->ThinkerChannels
.FindPtr(Thinker
);
151 Ret
= (Chan
->OpenAcked
? true : false);
153 Strm
.SerialiseInt(Index
, MAX_CHANNELS
);
165 //==========================================================================
167 // VNetObjectsMap::SerialiseClass
169 //==========================================================================
170 bool VNetObjectsMap::SerialiseClass (VStream
&Strm
, VClass
*&Class
) {
171 if (Strm
.IsLoading()) {
173 Strm
.SerialiseInt(ClassId
/*, ClassLookup.length()*/);
175 Class
= ClassLookup
[ClassId
];
181 vuint32
*ClassId
= ClassMap
.get(Class
);
182 Strm
.SerialiseInt(*ClassId
/*, ClassLookup.length()*/);
185 Strm
.SerialiseInt(NoClass
/*, ClassLookup.length()*/);
192 //==========================================================================
194 // VNetObjectsMap::SerialiseState
196 //==========================================================================
197 bool VNetObjectsMap::SerialiseState (VStream
&Strm
, VState
*&State
) {
198 if (Strm
.IsLoading()) {
200 Strm
.SerialiseInt(ClassId
/*, ClassLookup.length()*/);
203 Strm
.SerialiseInt(StateId
/*, ClassLookup[ClassId]->StatesLookup.length()*/);
204 State
= ClassLookup
[ClassId
]->StatesLookup
[StateId
];
210 vuint32
*ClassId
= ClassMap
.get((VClass
*)State
->Outer
);
211 vuint32 StateId
= State
->NetId
;
213 Strm
.SerialiseInt(*ClassId
/*, ClassLookup.length()*/);
214 Strm
.SerialiseInt(StateId
/*, ((VClass *)State->Outer)->StatesLookup.length()*/);
217 Strm
.SerialiseInt(NoClass
/*, ClassLookup.length()*/);