From 3b0f54bc6a9f6115ff43d752b8054704555d218e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 27 Jun 2024 00:11:26 +1000 Subject: [PATCH] WIP fixing exiting splitscreen mode breaking --- src/Entity.c | 11 +++++++---- src/Entity.h | 2 +- src/Server.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 952c60979..7e3453f0a 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -483,7 +483,7 @@ static void Entities_ContextLost(void* obj) { } /* No OnContextCreated, skin textures remade when needed */ -void Entities_Remove(EntityID id) { +void Entities_Remove(int id) { struct Entity* e = Entities.List[id]; if (!e) return; @@ -492,7 +492,7 @@ void Entities_Remove(EntityID id) { Entities.List[id] = NULL; /* TODO: Move to EntityEvents.Removed callback instead */ - if (TabList_EntityLinked_Get(id)) { + if (id < TABLIST_MAX_NAMES && TabList_EntityLinked_Get(id)) { TabList_Remove(id); TabList_EntityLinked_Reset(id); } @@ -756,7 +756,6 @@ static void LocalPlayer_Init(struct LocalPlayer* p, int index) { p->index = index; hacks->Enabled = !Game_PureClassic && Options_GetBool(OPT_HACKS_ENABLED, true); - /* p->Base.Health = 20; TODO: survival mode stuff */ if (Game_ClassicMode) return; hacks->SpeedMultiplier = Options_GetFloat(OPT_SPEED_FACTOR, 0.1f, 50.0f, 10.0f); @@ -1087,6 +1086,10 @@ static void Entities_Init(void) { LocalPlayer_Init(&LocalPlayer_Instances[i], i); Entities.List[MAX_NET_PLAYERS + i] = &LocalPlayer_Instances[i].Base; } + for (; i < MAX_LOCAL_PLAYERS; i++) + { + Entities.List[MAX_NET_PLAYERS + i] = NULL; + } Entities.CurPlayer = &LocalPlayer_Instances[0]; LocalPlayer_HookBinds(); } @@ -1095,7 +1098,7 @@ static void Entities_Free(void) { int i; for (i = 0; i < ENTITIES_MAX_COUNT; i++) { - Entities_Remove((EntityID)i); + Entities_Remove(i); } sources_head = NULL; } diff --git a/src/Entity.h b/src/Entity.h index 64d64ad12..3992f6e9d 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -179,7 +179,7 @@ void Entities_Tick(struct ScheduledTask* task); /* Renders all entities */ void Entities_RenderModels(float delta, float t); /* Removes the given entity, raising EntityEvents.Removed event */ -void Entities_Remove(EntityID id); +void Entities_Remove(int id); /* Gets the ID of the closest entity to the given entity */ /* Returns -1 if there is no other entity nearby */ int Entities_GetClosest(struct Entity* src); diff --git a/src/Server.c b/src/Server.c index 212727714..506e246a9 100644 --- a/src/Server.c +++ b/src/Server.c @@ -499,7 +499,7 @@ static void OnNewMap(void) { /* wipe all existing entities */ for (i = 0; i < MAX_NET_PLAYERS; i++) { - Entities_Remove((EntityID)i); + Entities_Remove(i); } }