mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 21:41:03 +00:00
Added wrapper functions for adding and reading arrays
This commit is contained in:
parent
202d0d747f
commit
b8b322f4ce
2 changed files with 122 additions and 0 deletions
116
src/events.cpp
116
src/events.cpp
|
@ -934,6 +934,67 @@ DEFINE_ACTION_FUNCTION(FNetworkCommand, ReadVector3)
|
||||||
ACTION_RETURN_VEC3(vec);
|
ACTION_RETURN_VEC3(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkCommand, ReadIntArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkCommand);
|
||||||
|
PARAM_OUTPOINTER(values, TArray<int>);
|
||||||
|
PARAM_INT(type)
|
||||||
|
|
||||||
|
unsigned int size = self->ReadLong();
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case NET_BYTE:
|
||||||
|
values->Push(self->ReadByte());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NET_WORD:
|
||||||
|
values->Push(self->ReadWord());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
values->Push(self->ReadLong());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkCommand, ReadFloatArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkCommand);
|
||||||
|
PARAM_OUTPOINTER(values, TArray<double>);
|
||||||
|
|
||||||
|
unsigned int size = self->ReadLong();
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
values->Push(self->ReadFloat());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkCommand, ReadStringArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkCommand);
|
||||||
|
PARAM_OUTPOINTER(values, TArray<FString>);
|
||||||
|
PARAM_BOOL(skipEmpty);
|
||||||
|
|
||||||
|
unsigned int size = self->ReadLong();
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
{
|
||||||
|
FString res = {};
|
||||||
|
auto str = self->ReadString();
|
||||||
|
if (str != nullptr)
|
||||||
|
res = str;
|
||||||
|
|
||||||
|
if (!skipEmpty || !res.IsEmpty())
|
||||||
|
values->Push(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddByte)
|
DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddByte)
|
||||||
{
|
{
|
||||||
PARAM_SELF_STRUCT_PROLOGUE(FNetworkBuffer);
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkBuffer);
|
||||||
|
@ -1004,6 +1065,61 @@ DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddVector3)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddIntArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkBuffer);
|
||||||
|
PARAM_POINTER(values, TArray<int>);
|
||||||
|
PARAM_INT(type);
|
||||||
|
|
||||||
|
unsigned int size = values->Size();
|
||||||
|
self->AddLong(size);
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case NET_BYTE:
|
||||||
|
self->AddByte((*values)[i]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NET_WORD:
|
||||||
|
self->AddWord((*values)[i]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
self->AddLong((*values)[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddFloatArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkBuffer);
|
||||||
|
PARAM_POINTER(values, TArray<double>);
|
||||||
|
|
||||||
|
unsigned int size = values->Size();
|
||||||
|
self->AddLong(size);
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
self->AddFloat((*values)[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FNetworkBuffer, AddStringArray)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FNetworkBuffer);
|
||||||
|
PARAM_POINTER(values, TArray<FString>);
|
||||||
|
|
||||||
|
unsigned int size = values->Size();
|
||||||
|
self->AddLong(size);
|
||||||
|
for (unsigned int i = 0u; i < size; ++i)
|
||||||
|
self->AddString((*values)[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
|
DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
|
||||||
{
|
{
|
||||||
PARAM_SELF_PROLOGUE(DStaticEventHandler);
|
PARAM_SELF_PROLOGUE(DStaticEventHandler);
|
||||||
|
|
|
@ -22,6 +22,9 @@ struct NetworkCommand native play version("4.12")
|
||||||
native Name ReadName();
|
native Name ReadName();
|
||||||
native Vector2 ReadVector2();
|
native Vector2 ReadVector2();
|
||||||
native Vector3 ReadVector3();
|
native Vector3 ReadVector3();
|
||||||
|
native void ReadIntArray(out Array<int> values, ENetCmd intSize = NET_LONG);
|
||||||
|
native void ReadFloatArray(out Array<double> values);
|
||||||
|
native void ReadStringArray(out Array<string> values, bool skipEmpty = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NetworkBuffer native version("4.12")
|
struct NetworkBuffer native version("4.12")
|
||||||
|
@ -36,6 +39,9 @@ struct NetworkBuffer native version("4.12")
|
||||||
native void AddName(Name value);
|
native void AddName(Name value);
|
||||||
native void AddVector2(Vector2 value);
|
native void AddVector2(Vector2 value);
|
||||||
native void AddVector3(Vector3 value);
|
native void AddVector3(Vector3 value);
|
||||||
|
native void AddIntArray(Array<int> values, ENetCmd intSize = NET_LONG);
|
||||||
|
native void AddFloatArray(Array<double> values);
|
||||||
|
native void AddStringArray(Array<string> values);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RenderEvent native ui version("2.4")
|
struct RenderEvent native ui version("2.4")
|
||||||
|
|
Loading…
Reference in a new issue