- implemented the framework for freeform network commands.

Unlike ZDoom this uses callbacks for implementation to keep game specific parts encapsulated to the game code.
This commit is contained in:
Christoph Oelckers 2020-09-02 23:27:02 +02:00
parent b3d89a6a0b
commit 66d8eae8e1
2 changed files with 24 additions and 27 deletions

View file

@ -1931,45 +1931,35 @@ uint8_t *FDynamicBuffer::GetData (int *len)
}
NetCommandHandler nethandlers[DEM_MAX];
void Net_SetCommandHandler(EDemoCommand cmd, NetCommandHandler handler) noexcept
{
assert(cmd >= 0 && cmd < DEM_MAX);
if (cmd >= 0 && cmd < DEM_MAX) nethandlers[cmd] = handler;
}
// [RH] Execute a special "ticcmd". The type byte should
// have already been read, and the stream is positioned
// at the beginning of the command's actual data.
void Net_DoCommand (int type, uint8_t **stream, int player)
void Net_DoCommand (int cmd, uint8_t **stream, int player)
{
#if 0
uint8_t pos = 0;
char *s = NULL;
int i;
switch (type)
assert(cmd >= 0 && cmd < DEM_MAX);
if (cmd >= 0 && cmd < DEM_MAX && nethandlers[cmd])
{
default:
I_Error ("Unknown net command: %d", type);
break;
nethandlers[cmd](stream, false);
}
if (s)
delete[] s;
#endif
else
I_Error("Unknown net command: %d", cmd);
}
void Net_SkipCommand (int type, uint8_t **stream)
void Net_SkipCommand (int cmd, uint8_t **stream)
{
#if 0
uint8_t t;
size_t skip = 0;
switch (type)
if (cmd >= 0 && cmd < DEM_MAX && nethandlers[cmd])
{
default:
return;
nethandlers[cmd](stream, true);
}
*stream += skip;
#endif
}
// Reset the network ticker after finishing a lengthy operation.

View file

@ -88,8 +88,15 @@ enum EDemoCommand
DEM_BAD, // 0 Bad command
DEM_USERCMD,
DEM_EMPTYUSERCMD,
DEM_CHEAT_GOD,
DEM_MAX
};
typedef void(*NetCommandHandler)(uint8_t **stream, bool skip);
void Net_SetCommandHandler(EDemoCommand cmd, NetCommandHandler handler) noexcept;
void StartChunk (int id, uint8_t **stream);
void FinishChunk (uint8_t **stream);
void SkipChunk (uint8_t **stream);