mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Clean up ClientEvent hudadd/hudchange internals
This commit is contained in:
parent
dd228fd92e
commit
593d5f4465
@ -52,6 +52,31 @@ enum ClientEventType : u8
|
|||||||
CLIENTEVENT_MAX,
|
CLIENTEVENT_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ClientEventHudAdd
|
||||||
|
{
|
||||||
|
u32 server_id;
|
||||||
|
u8 type;
|
||||||
|
v2f pos, scale;
|
||||||
|
std::string name;
|
||||||
|
std::string text, text2;
|
||||||
|
u32 number, item, dir;
|
||||||
|
v2f align, offset;
|
||||||
|
v3f world_pos;
|
||||||
|
v2s32 size;
|
||||||
|
s16 z_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClientEventHudChange
|
||||||
|
{
|
||||||
|
u32 id;
|
||||||
|
HudElementStat stat;
|
||||||
|
v2f v2fdata;
|
||||||
|
std::string sdata;
|
||||||
|
u32 data;
|
||||||
|
v3f v3fdata;
|
||||||
|
v2s32 v2s32data;
|
||||||
|
};
|
||||||
|
|
||||||
struct ClientEvent
|
struct ClientEvent
|
||||||
{
|
{
|
||||||
ClientEventType type;
|
ClientEventType type;
|
||||||
@ -93,38 +118,12 @@ struct ClientEvent
|
|||||||
{
|
{
|
||||||
u32 id;
|
u32 id;
|
||||||
} delete_particlespawner;
|
} delete_particlespawner;
|
||||||
struct
|
ClientEventHudAdd *hudadd;
|
||||||
{
|
|
||||||
u32 server_id;
|
|
||||||
u8 type;
|
|
||||||
v2f *pos;
|
|
||||||
std::string *name;
|
|
||||||
v2f *scale;
|
|
||||||
std::string *text;
|
|
||||||
u32 number;
|
|
||||||
u32 item;
|
|
||||||
u32 dir;
|
|
||||||
v2f *align;
|
|
||||||
v2f *offset;
|
|
||||||
v3f *world_pos;
|
|
||||||
v2s32 *size;
|
|
||||||
s16 z_index;
|
|
||||||
std::string *text2;
|
|
||||||
} hudadd;
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u32 id;
|
u32 id;
|
||||||
} hudrm;
|
} hudrm;
|
||||||
struct
|
ClientEventHudChange *hudchange;
|
||||||
{
|
|
||||||
u32 id;
|
|
||||||
HudElementStat stat;
|
|
||||||
v2f *v2fdata;
|
|
||||||
std::string *sdata;
|
|
||||||
u32 data;
|
|
||||||
v3f *v3fdata;
|
|
||||||
v2s32 *v2s32data;
|
|
||||||
} hudchange;
|
|
||||||
SkyboxParams *set_sky;
|
SkyboxParams *set_sky;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -2643,48 +2643,32 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
|
|||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
|
||||||
u32 server_id = event->hudadd.server_id;
|
u32 server_id = event->hudadd->server_id;
|
||||||
// ignore if we already have a HUD with that ID
|
// ignore if we already have a HUD with that ID
|
||||||
auto i = m_hud_server_to_client.find(server_id);
|
auto i = m_hud_server_to_client.find(server_id);
|
||||||
if (i != m_hud_server_to_client.end()) {
|
if (i != m_hud_server_to_client.end()) {
|
||||||
delete event->hudadd.pos;
|
delete event->hudadd;
|
||||||
delete event->hudadd.name;
|
|
||||||
delete event->hudadd.scale;
|
|
||||||
delete event->hudadd.text;
|
|
||||||
delete event->hudadd.align;
|
|
||||||
delete event->hudadd.offset;
|
|
||||||
delete event->hudadd.world_pos;
|
|
||||||
delete event->hudadd.size;
|
|
||||||
delete event->hudadd.text2;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HudElement *e = new HudElement;
|
HudElement *e = new HudElement;
|
||||||
e->type = (HudElementType)event->hudadd.type;
|
e->type = static_cast<HudElementType>(event->hudadd->type);
|
||||||
e->pos = *event->hudadd.pos;
|
e->pos = event->hudadd->pos;
|
||||||
e->name = *event->hudadd.name;
|
e->name = event->hudadd->name;
|
||||||
e->scale = *event->hudadd.scale;
|
e->scale = event->hudadd->scale;
|
||||||
e->text = *event->hudadd.text;
|
e->text = event->hudadd->text;
|
||||||
e->number = event->hudadd.number;
|
e->number = event->hudadd->number;
|
||||||
e->item = event->hudadd.item;
|
e->item = event->hudadd->item;
|
||||||
e->dir = event->hudadd.dir;
|
e->dir = event->hudadd->dir;
|
||||||
e->align = *event->hudadd.align;
|
e->align = event->hudadd->align;
|
||||||
e->offset = *event->hudadd.offset;
|
e->offset = event->hudadd->offset;
|
||||||
e->world_pos = *event->hudadd.world_pos;
|
e->world_pos = event->hudadd->world_pos;
|
||||||
e->size = *event->hudadd.size;
|
e->size = event->hudadd->size;
|
||||||
e->z_index = event->hudadd.z_index;
|
e->z_index = event->hudadd->z_index;
|
||||||
e->text2 = *event->hudadd.text2;
|
e->text2 = event->hudadd->text2;
|
||||||
m_hud_server_to_client[server_id] = player->addHud(e);
|
m_hud_server_to_client[server_id] = player->addHud(e);
|
||||||
|
|
||||||
delete event->hudadd.pos;
|
delete event->hudadd;
|
||||||
delete event->hudadd.name;
|
|
||||||
delete event->hudadd.scale;
|
|
||||||
delete event->hudadd.text;
|
|
||||||
delete event->hudadd.align;
|
|
||||||
delete event->hudadd.offset;
|
|
||||||
delete event->hudadd.world_pos;
|
|
||||||
delete event->hudadd.size;
|
|
||||||
delete event->hudadd.text2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam)
|
||||||
@ -2706,77 +2690,52 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
|
|||||||
|
|
||||||
HudElement *e = nullptr;
|
HudElement *e = nullptr;
|
||||||
|
|
||||||
auto i = m_hud_server_to_client.find(event->hudchange.id);
|
auto i = m_hud_server_to_client.find(event->hudchange->id);
|
||||||
if (i != m_hud_server_to_client.end()) {
|
if (i != m_hud_server_to_client.end()) {
|
||||||
e = player->getHud(i->second);
|
e = player->getHud(i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e == nullptr) {
|
if (e == nullptr) {
|
||||||
delete event->hudchange.v3fdata;
|
delete event->hudchange;
|
||||||
delete event->hudchange.v2fdata;
|
|
||||||
delete event->hudchange.sdata;
|
|
||||||
delete event->hudchange.v2s32data;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (event->hudchange.stat) {
|
#define CASE_SET(statval, prop, dataprop) \
|
||||||
case HUD_STAT_POS:
|
case statval: \
|
||||||
e->pos = *event->hudchange.v2fdata;
|
e->prop = event->hudchange->dataprop; \
|
||||||
break;
|
break
|
||||||
|
|
||||||
case HUD_STAT_NAME:
|
switch (event->hudchange->stat) {
|
||||||
e->name = *event->hudchange.sdata;
|
CASE_SET(HUD_STAT_POS, pos, v2fdata);
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_SCALE:
|
CASE_SET(HUD_STAT_NAME, name, sdata);
|
||||||
e->scale = *event->hudchange.v2fdata;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_TEXT:
|
CASE_SET(HUD_STAT_SCALE, scale, v2fdata);
|
||||||
e->text = *event->hudchange.sdata;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_NUMBER:
|
CASE_SET(HUD_STAT_TEXT, text, sdata);
|
||||||
e->number = event->hudchange.data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_ITEM:
|
CASE_SET(HUD_STAT_NUMBER, number, data);
|
||||||
e->item = event->hudchange.data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_DIR:
|
CASE_SET(HUD_STAT_ITEM, item, data);
|
||||||
e->dir = event->hudchange.data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_ALIGN:
|
CASE_SET(HUD_STAT_DIR, dir, data);
|
||||||
e->align = *event->hudchange.v2fdata;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_OFFSET:
|
CASE_SET(HUD_STAT_ALIGN, align, v2fdata);
|
||||||
e->offset = *event->hudchange.v2fdata;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_WORLD_POS:
|
CASE_SET(HUD_STAT_OFFSET, offset, v2fdata);
|
||||||
e->world_pos = *event->hudchange.v3fdata;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_SIZE:
|
CASE_SET(HUD_STAT_WORLD_POS, world_pos, v3fdata);
|
||||||
e->size = *event->hudchange.v2s32data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_Z_INDEX:
|
CASE_SET(HUD_STAT_SIZE, size, v2s32data);
|
||||||
e->z_index = event->hudchange.data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HUD_STAT_TEXT2:
|
CASE_SET(HUD_STAT_Z_INDEX, z_index, data);
|
||||||
e->text2 = *event->hudchange.sdata;
|
|
||||||
break;
|
CASE_SET(HUD_STAT_TEXT2, text2, sdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete event->hudchange.v3fdata;
|
#undef CASE_SET
|
||||||
delete event->hudchange.v2fdata;
|
|
||||||
delete event->hudchange.sdata;
|
delete event->hudchange;
|
||||||
delete event->hudchange.v2s32data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
||||||
|
@ -1041,9 +1041,6 @@ void Client::handleCommand_DeleteParticleSpawner(NetworkPacket* pkt)
|
|||||||
|
|
||||||
void Client::handleCommand_HudAdd(NetworkPacket* pkt)
|
void Client::handleCommand_HudAdd(NetworkPacket* pkt)
|
||||||
{
|
{
|
||||||
std::string datastring(pkt->getString(0), pkt->getSize());
|
|
||||||
std::istringstream is(datastring, std::ios_base::binary);
|
|
||||||
|
|
||||||
u32 server_id;
|
u32 server_id;
|
||||||
u8 type;
|
u8 type;
|
||||||
v2f pos;
|
v2f pos;
|
||||||
@ -1070,22 +1067,23 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
|
|||||||
} catch(PacketError &e) {};
|
} catch(PacketError &e) {};
|
||||||
|
|
||||||
ClientEvent *event = new ClientEvent();
|
ClientEvent *event = new ClientEvent();
|
||||||
event->type = CE_HUDADD;
|
event->type = CE_HUDADD;
|
||||||
event->hudadd.server_id = server_id;
|
event->hudadd = new ClientEventHudAdd();
|
||||||
event->hudadd.type = type;
|
event->hudadd->server_id = server_id;
|
||||||
event->hudadd.pos = new v2f(pos);
|
event->hudadd->type = type;
|
||||||
event->hudadd.name = new std::string(name);
|
event->hudadd->pos = pos;
|
||||||
event->hudadd.scale = new v2f(scale);
|
event->hudadd->name = name;
|
||||||
event->hudadd.text = new std::string(text);
|
event->hudadd->scale = scale;
|
||||||
event->hudadd.number = number;
|
event->hudadd->text = text;
|
||||||
event->hudadd.item = item;
|
event->hudadd->number = number;
|
||||||
event->hudadd.dir = dir;
|
event->hudadd->item = item;
|
||||||
event->hudadd.align = new v2f(align);
|
event->hudadd->dir = dir;
|
||||||
event->hudadd.offset = new v2f(offset);
|
event->hudadd->align = align;
|
||||||
event->hudadd.world_pos = new v3f(world_pos);
|
event->hudadd->offset = offset;
|
||||||
event->hudadd.size = new v2s32(size);
|
event->hudadd->world_pos = world_pos;
|
||||||
event->hudadd.z_index = z_index;
|
event->hudadd->size = size;
|
||||||
event->hudadd.text2 = new std::string(text2);
|
event->hudadd->z_index = z_index;
|
||||||
|
event->hudadd->text2 = text2;
|
||||||
m_client_event_queue.push(event);
|
m_client_event_queue.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1126,14 +1124,15 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt)
|
|||||||
*pkt >> intdata;
|
*pkt >> intdata;
|
||||||
|
|
||||||
ClientEvent *event = new ClientEvent();
|
ClientEvent *event = new ClientEvent();
|
||||||
event->type = CE_HUDCHANGE;
|
event->type = CE_HUDCHANGE;
|
||||||
event->hudchange.id = server_id;
|
event->hudchange = new ClientEventHudChange();
|
||||||
event->hudchange.stat = (HudElementStat)stat;
|
event->hudchange->id = server_id;
|
||||||
event->hudchange.v2fdata = new v2f(v2fdata);
|
event->hudchange->stat = static_cast<HudElementStat>(stat);
|
||||||
event->hudchange.v3fdata = new v3f(v3fdata);
|
event->hudchange->v2fdata = v2fdata;
|
||||||
event->hudchange.sdata = new std::string(sdata);
|
event->hudchange->v3fdata = v3fdata;
|
||||||
event->hudchange.data = intdata;
|
event->hudchange->sdata = sdata;
|
||||||
event->hudchange.v2s32data = new v2s32(v2s32data);
|
event->hudchange->data = intdata;
|
||||||
|
event->hudchange->v2s32data = v2s32data;
|
||||||
m_client_event_queue.push(event);
|
m_client_event_queue.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user