More player refactoring

This commit is contained in:
UnknownShadow200 2024-04-25 16:10:15 +10:00
parent fcc903016b
commit ca195d161f
11 changed files with 100 additions and 97 deletions

View File

@ -261,13 +261,13 @@ static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
}
static void OnHacksChanged(void* obj) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
struct HacksComp* h = &Entities.CurPlayer->Hacks;
/* Leave third person if not allowed anymore */
if (!h->CanUseThirdPerson || !h->Enabled) Camera_CycleActive();
}
void Camera_CycleActive(void) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
if (Game_ClassicMode) return;
Camera.Active = Camera.Active->next;

View File

@ -367,7 +367,7 @@ static void Entity_CheckSkin(struct Entity* e) {
if (!e->SkinFetchState) {
first = Entity_FirstOtherWithSameSkinAndFetchedSkin(e);
flags = e == &LocalPlayer_Instance.Base ? HTTP_FLAG_NOCACHE : 0;
flags = e == &LocalPlayer_Instances[0].Base ? HTTP_FLAG_NOCACHE : 0;
if (!first) {
e->_skinReqID = Http_AsyncGetSkin(&skin, flags);
@ -497,24 +497,24 @@ void Entities_Remove(EntityID id) {
}
}
EntityID Entities_GetClosest(struct Entity* src) {
int Entities_GetClosest(struct Entity* src) {
Vec3 eyePos = Entity_GetEyePosition(src);
Vec3 dir = Vec3_GetDirVector(src->Yaw * MATH_DEG2RAD, src->Pitch * MATH_DEG2RAD);
float closestDist = -200; /* NOTE: was previously positive infinity */
EntityID targetID = ENTITIES_SELF_ID;
int targetID = -1;
float t0, t1;
int i;
for (i = 0; i < ENTITIES_SELF_ID; i++) /* because we don't want to pick against local player */
for (i = 0; i < ENTITIES_MAX_COUNT; i++) /* because we don't want to pick against local player */
{
struct Entity* entity = Entities.List[i];
if (!entity) continue;
if (!Intersection_RayIntersectsRotatedBox(eyePos, dir, entity, &t0, &t1)) continue;
struct Entity* e = Entities.List[i];
if (!e || e == &Entities.CurPlayer->Base) continue;
if (!Intersection_RayIntersectsRotatedBox(eyePos, dir, e, &t0, &t1)) continue;
if (targetID == ENTITIES_SELF_ID || t0 < closestDist) {
if (targetID == -1 || t0 < closestDist) {
closestDist = t0;
targetID = (EntityID)i;
targetID = i;
}
}
return targetID;
@ -613,7 +613,7 @@ struct IGameComponent TabList_Component = {
/*########################################################################################################################*
*------------------------------------------------------LocalPlayer--------------------------------------------------------*
*#########################################################################################################################*/
struct LocalPlayer LocalPlayer_Instance;
struct LocalPlayer LocalPlayer_Instances[MAX_LOCAL_PLAYERS];
static cc_bool hackPermMsgs;
static struct LocalPlayerInput* sources_head;
static struct LocalPlayerInput* sources_tail;
@ -664,7 +664,7 @@ static void LocalPlayer_HandleInput(struct LocalPlayer* p, float* xMoving, float
}
static void LocalPlayer_InputSet(int key, cc_bool pressed) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &LocalPlayer_Instances[0].Hacks;
if (pressed && !hacks->Enabled) return;
if (KeyBind_Claims(KEYBIND_SPEED, key)) hacks->Speeding = pressed;
@ -682,7 +682,7 @@ static void LocalPlayer_InputUp(void* obj, int key) {
static void LocalPlayer_SetLocation(struct Entity* e, struct LocationUpdate* update) {
struct LocalPlayer* p = (struct LocalPlayer*)e;
LocalInterpComp_SetLocation(&p->Interp, update);
LocalInterpComp_SetLocation(&p->Interp, update, e);
}
static void LocalPlayer_Tick(struct Entity* e, double delta) {
@ -736,7 +736,7 @@ static cc_bool LocalPlayer_ShouldRenderName(struct Entity* e) {
}
static void LocalPlayer_CheckJumpVelocity(void* obj) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
if (!HacksComp_CanJumpHigher(&p->Hacks)) {
p->Physics.JumpVel = p->Physics.ServerJumpVel;
}
@ -787,14 +787,14 @@ void LocalPlayer_ResetJumpVelocity(struct LocalPlayer* p) {
}
static void LocalPlayer_Reset(void) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
p->ReachDistance = 5.0f;
Vec3_Set(p->Base.Velocity, 0,0,0);
LocalPlayer_ResetJumpVelocity(p);
}
static void LocalPlayer_OnNewMap(void) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
Vec3_Set(p->Base.Velocity, 0,0,0);
Vec3_Set(p->OldVelocity, 0,0,0);
@ -1020,9 +1020,9 @@ static void Entities_Init(void) {
ShadowMode_Names, Array_Elems(ShadowMode_Names));
if (Game_ClassicMode) Entities.ShadowsMode = SHADOW_MODE_NONE;
Entities.List[ENTITIES_SELF_ID] = &LocalPlayer_Instance.Base;
Entities.CurPlayer = &LocalPlayer_Instance;
LocalPlayer_Init(&LocalPlayer_Instance);
Entities.List[ENTITIES_SELF_ID] = &LocalPlayer_Instances[0].Base;
Entities.CurPlayer = &LocalPlayer_Instances[0];
LocalPlayer_Init(&LocalPlayer_Instances[0]);
}
static void Entities_Free(void) {

View File

@ -16,9 +16,10 @@ struct LocalPlayer;
extern struct IGameComponent TabList_Component;
extern struct IGameComponent Entities_Component;
#define MAX_LOCAL_PLAYERS 1
/* Offset used to avoid floating point roundoff errors. */
#define ENTITY_ADJUSTMENT 0.001f
#define ENTITIES_MAX_COUNT 256
#define ENTITIES_MAX_COUNT (255 + MAX_LOCAL_PLAYERS)
#define ENTITIES_SELF_ID 255
enum NameMode {
@ -174,7 +175,8 @@ void Entities_RenderModels(double delta, float t);
/* Removes the given entity, raising EntityEvents.Removed event */
void Entities_Remove(EntityID id);
/* Gets the ID of the closest entity to the given entity */
EntityID Entities_GetClosest(struct Entity* src);
/* Returns -1 if there is no other entity nearby */
int Entities_GetClosest(struct Entity* src);
#define TABLIST_MAX_NAMES 256
/* Data for all entries in tab list */
@ -237,7 +239,7 @@ struct LocalPlayer {
cc_bool _warnedRespawn, _warnedFly, _warnedNoclip, _warnedZoom;
};
extern struct LocalPlayer LocalPlayer_Instance;
extern struct LocalPlayer LocalPlayer_Instances[MAX_LOCAL_PLAYERS];
/* Returns how high (in blocks) the player can jump. */
float LocalPlayer_JumpHeight(struct LocalPlayer* p);
/* Interpolates current position and orientation between Interp.Prev and Interp.Next */

View File

@ -425,8 +425,7 @@ void NetInterpComp_AdvanceState(struct NetInterpComp* interp, struct Entity* e)
/*########################################################################################################################*
*-----------------------------------------------LocalInterpolationComponent-----------------------------------------------*
*#########################################################################################################################*/
static void LocalInterpComp_SetPosition(struct LocationUpdate* update, int mode) {
struct Entity* e = &LocalPlayer_Instance.Base;
static void LocalInterpComp_SetPosition(struct Entity* e, struct LocationUpdate* update, int mode) {
float yOffset;
if (mode == LU_POS_ABSOLUTE_INSTANT || mode == LU_POS_ABSOLUTE_SMOOTH) {
@ -453,15 +452,14 @@ static void LocalInterpComp_Angle(float* prev, float* next, float value, cc_bool
if (!interpolate) *prev = value;
}
void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdate* update) {
struct Entity* e = &LocalPlayer_Instance.Base;
void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdate* update, struct Entity* e) {
struct EntityLocation* prev = &e->prev;
struct EntityLocation* next = &e->next;
cc_uint8 flags = update->flags;
cc_bool interpolate = flags & LU_ORI_INTERPOLATE;
if (flags & LU_HAS_POS) {
LocalInterpComp_SetPosition(update, flags & LU_POS_MODEMASK);
LocalInterpComp_SetPosition(e, update, flags & LU_POS_MODEMASK);
}
if (flags & LU_HAS_PITCH) {
LocalInterpComp_Angle(&prev->pitch, &next->pitch, update->pitch, interpolate);

View File

@ -82,7 +82,7 @@ float HacksComp_CalcSpeedFactor(struct HacksComp* hacks, cc_bool canSpeed);
/* Base entity component that performs interpolation of position and orientation */
struct InterpComp { InterpComp_Layout };
void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdate* update);
void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdate* update, struct Entity* e);
void LocalInterpComp_AdvanceState(struct InterpComp* interp, struct Entity* e);
/* Represents a network orientation state */

View File

@ -242,6 +242,7 @@ static void EntityShadows_MakeTexture(void) {
}
void EntityShadows_Render(void) {
struct Entity* e;
int i;
if (Entities.ShadowsMode == SHADOW_MODE_NONE) return;
@ -256,13 +257,13 @@ void EntityShadows_Render(void) {
Gfx_SetAlphaBlending(true);
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
EntityShadow_Draw(Entities.List[ENTITIES_SELF_ID]);
EntityShadow_Draw(&Entities.CurPlayer->Base);
if (Entities.ShadowsMode == SHADOW_MODE_CIRCLE_ALL) {
for (i = 0; i < ENTITIES_SELF_ID; i++)
for (i = 0; i < ENTITIES_MAX_COUNT; i++)
{
if (!Entities.List[i] || !Entities.List[i]->ShouldRender) continue;
EntityShadow_Draw(Entities.List[i]);
if (!e || !e->ShouldRender || e == &Entities.CurPlayer->Base) continue;
EntityShadow_Draw(e);
}
}
@ -373,7 +374,7 @@ void EntityNames_Delete(struct Entity* e) {
/*########################################################################################################################*
*-----------------------------------------------------Names rendering-----------------------------------------------------*
*#########################################################################################################################*/
static EntityID closestEntityId;
static int closestEntityId;
void EntityNames_Render(void) {
struct LocalPlayer* p = Entities.CurPlayer;
@ -391,9 +392,7 @@ void EntityNames_Render(void) {
for (i = 0; i < ENTITIES_MAX_COUNT; i++)
{
if (!Entities.List[i]) continue;
if (i != closestEntityId || i == ENTITIES_SELF_ID) {
DrawName(Entities.List[i]);
}
if (i != closestEntityId) DrawName(Entities.List[i]);
}
Gfx_SetAlphaTest(false);
@ -417,7 +416,7 @@ void EntityNames_RenderHovered(void) {
for (i = 0; i < ENTITIES_MAX_COUNT; i++)
{
if (!Entities.List[i]) continue;
if ((i == closestEntityId || allNames) && i != ENTITIES_SELF_ID) {
if ((i == closestEntityId || allNames) && Entities.List[i] != &p->Base) {
DrawName(Entities.List[i]);
}
}

View File

@ -86,8 +86,8 @@ cc_result Map_LoadFrom(const cc_string* path) {
if (res) Logger_SysWarn2(res, "decoding", path);
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
if (!spawn_point) LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance, &update);
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance, &update);
if (!spawn_point) LocalPlayer_CalcDefaultSpawn(Entities.CurPlayer, &update);
LocalPlayer_MoveToSpawn(&LocalPlayer_Instances[0], &update);
relPath = *path;
Utils_UNSAFE_GetFilename(&relPath);
@ -703,7 +703,7 @@ static PackedCol Cw_ParseColor(PackedCol defValue) {
static void Cw_Callback_4(struct NbtTag* tag) {
BlockID id = cw_curID;
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
if (!IsTag(tag->parent->parent, "CPE")) return;
if (!IsTag(tag->parent->parent->parent, "Metadata")) return;
@ -1572,9 +1572,9 @@ static cc_result Cw_WriteBockDef(struct Stream* stream, int b) {
}
cc_result Cw_Save(struct Stream* stream) {
struct LocalPlayer* p = Entities.CurPlayer;
cc_uint8 buffer[2048];
cc_uint8* cur;
struct LocalPlayer* p = &LocalPlayer_Instance;
cc_result res;
int b;
@ -1622,7 +1622,7 @@ cc_result Cw_Save(struct Stream* stream) {
{
cur = Nbt_WriteDict(cur, "ClickDistance");
{
cur = Nbt_WriteUInt16(cur, "Distance", (cc_uint16)(LocalPlayer_Instance.ReachDistance * 32));
cur = Nbt_WriteUInt16(cur, "Distance", (cc_uint16)(p->ReachDistance * 32));
} *cur++ = NBT_END;
cur = Nbt_WriteDict(cur, "EnvWeatherType");
@ -1739,9 +1739,9 @@ static const struct JField {
{ JFIELD_I32, false, "width", &World.Width },
{ JFIELD_I32, false, "depth", &World.Height },
{ JFIELD_I32, false, "height", &World.Length },
{ JFIELD_I32, true, "xSpawn", &LocalPlayer_Instance.Base.Position.x },
{ JFIELD_I32, true, "ySpawn", &LocalPlayer_Instance.Base.Position.y },
{ JFIELD_I32, true, "zSpawn", &LocalPlayer_Instance.Base.Position.z },
{ JFIELD_I32, true, "xSpawn", &LocalPlayer_Instances[0].Base.Position.x },
{ JFIELD_I32, true, "ySpawn", &LocalPlayer_Instances[0].Base.Position.y },
{ JFIELD_I32, true, "zSpawn", &LocalPlayer_Instances[0].Base.Position.z },
{ JFIELD_ARRAY,0, "blocks" }
/* TODO classic only blocks */
};

View File

@ -684,6 +684,9 @@ static void MouseStateUpdate(int button, cc_bool pressed) {
if (input_pickingId == -1) {
p = &Entities.CurPlayer->Base;
input_pickingId = Entities_GetClosest(p);
if (input_pickingId == -1)
input_pickingId = ENTITIES_SELF_ID;
}
input_buttonsDown[button] = pressed;
@ -779,9 +782,10 @@ static cc_bool IntersectsOthers(Vec3 pos, BlockID block) {
Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]);
Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]);
for (id = 0; id < ENTITIES_SELF_ID; id++) {
for (id = 0; id < ENTITIES_MAX_COUNT; id++)
{
e = Entities.List[id];
if (!e) continue;
if (!e || e == &Entities.CurPlayer->Base) continue;
Entity_GetBounds(e, &entityBB);
entityBB.Min.y += 1.0f / 32.0f; /* when player is exactly standing on top of ground */
@ -948,7 +952,7 @@ static void InputHandler_Toggle(int key, cc_bool* target, const char* enableMsg,
}
cc_bool InputHandler_SetFOV(int fov) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
struct HacksComp* h = &Entities.CurPlayer->Hacks;
if (!h->Enabled || !h->CanUseThirdPerson) return false;
Camera.ZoomFov = fov;
@ -964,7 +968,7 @@ cc_bool Input_HandleMouseWheel(float delta) {
if (!hotbar && Camera.Active->Zoom(delta)) return true;
if (!KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) return false;
h = &LocalPlayer_Instance.Hacks;
h = &Entities.CurPlayer->Hacks;
if (!h->Enabled || !h->CanUseThirdPerson) return false;
if (input_fovIndex == -1.0f) input_fovIndex = (float)Camera.ZoomFov;
@ -975,7 +979,7 @@ cc_bool Input_HandleMouseWheel(float delta) {
}
static void InputHandler_CheckZoomFov(void* obj) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
struct HacksComp* h = &Entities.CurPlayer->Hacks;
if (!h->Enabled || !h->CanUseThirdPerson) Camera_SetFov(Camera.DefaultFov);
}
@ -1067,7 +1071,7 @@ static void HandleHotkeyDown(int key) {
}
static cc_bool HandleLocalPlayerKey(int key) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = Entities.CurPlayer;
if (KeyBind_Claims(KEYBIND_RESPAWN, key)) {
return LocalPlayer_HandleRespawn(p);

View File

@ -530,7 +530,7 @@ static void PauseScreen_CheckHacksAllowed(void* screen) {
if (Gui.ClassicMenu) return;
Widget_SetDisabled(&s->btns[4],
!LocalPlayer_Instance.Hacks.CanAnyHacks); /* select texture pack */
!Entities.CurPlayer->Hacks.CanAnyHacks); /* select texture pack */
s->dirty = true;
}
@ -702,7 +702,7 @@ static const struct SimpleButtonDesc optsGroup_btns[8] = {
static void OptionsGroupScreen_CheckHacksAllowed(void* screen) {
struct OptionsGroupScreen* s = (struct OptionsGroupScreen*)screen;
Widget_SetDisabled(&s->btns[6],
!LocalPlayer_Instance.Hacks.CanAnyHacks); /* env settings */
!Entities.CurPlayer->Hacks.CanAnyHacks); /* env settings */
s->dirty = true;
}
@ -2758,10 +2758,10 @@ static void ClassicOptionsScreen_SetShowFPS(const cc_string* v) { Gui.ShowFPS =
static void ClassicOptionsScreen_GetViewBob(cc_string* v) { Menu_GetBool(v, Game_ViewBobbing); }
static void ClassicOptionsScreen_SetViewBob(const cc_string* v) { Game_ViewBobbing = Menu_SetBool(v, OPT_VIEW_BOBBING); }
static void ClassicOptionsScreen_GetHacks(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); }
static void ClassicOptionsScreen_GetHacks(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.Enabled); }
static void ClassicOptionsScreen_SetHacks(const cc_string* v) {
LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v, OPT_HACKS_ENABLED);
HacksComp_Update(&LocalPlayer_Instance.Hacks);
Entities.CurPlayer->Hacks.Enabled = Menu_SetBool(v, OPT_HACKS_ENABLED);
HacksComp_Update(&Entities.CurPlayer->Hacks);
}
static void ClassicOptionsScreen_RecreateExtra(struct MenuOptionsScreen* s) {
@ -3130,15 +3130,15 @@ void GuiOptionsScreen_Show(void) {
/*########################################################################################################################*
*---------------------------------------------------HacksSettingsScreen---------------------------------------------------*
*#########################################################################################################################*/
static void HacksSettingsScreen_GetHacks(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); }
static void HacksSettingsScreen_GetHacks(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.Enabled); }
static void HacksSettingsScreen_SetHacks(const cc_string* v) {
LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v,OPT_HACKS_ENABLED);
HacksComp_Update(&LocalPlayer_Instance.Hacks);
Entities.CurPlayer->Hacks.Enabled = Menu_SetBool(v,OPT_HACKS_ENABLED);
HacksComp_Update(&Entities.CurPlayer->Hacks);
}
static void HacksSettingsScreen_GetSpeed(cc_string* v) { String_AppendFloat(v, LocalPlayer_Instance.Hacks.SpeedMultiplier, 2); }
static void HacksSettingsScreen_GetSpeed(cc_string* v) { String_AppendFloat(v, Entities.CurPlayer->Hacks.SpeedMultiplier, 2); }
static void HacksSettingsScreen_SetSpeed(const cc_string* v) {
LocalPlayer_Instance.Hacks.SpeedMultiplier = Menu_Float(v);
Entities.CurPlayer->Hacks.SpeedMultiplier = Menu_Float(v);
Options_Set(OPT_SPEED_FACTOR, v);
}
@ -3148,14 +3148,14 @@ static void HacksSettingsScreen_SetClipping(const cc_string* v) {
}
static void HacksSettingsScreen_GetJump(cc_string* v) {
String_AppendFloat(v, LocalPlayer_JumpHeight(&LocalPlayer_Instance), 3);
String_AppendFloat(v, LocalPlayer_JumpHeight(Entities.CurPlayer), 3);
}
static void HacksSettingsScreen_SetJump(const cc_string* v) {
cc_string str; char strBuffer[STRING_SIZE];
struct PhysicsComp* physics;
physics = &LocalPlayer_Instance.Physics;
physics = &Entities.CurPlayer->Physics;
physics->JumpVel = PhysicsComp_CalcJumpVelocity(Menu_Float(v));
physics->UserJumpVel = physics->JumpVel;
@ -3164,19 +3164,19 @@ static void HacksSettingsScreen_SetJump(const cc_string* v) {
Options_Set(OPT_JUMP_VELOCITY, &str);
}
static void HacksSettingsScreen_GetWOMHacks(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.WOMStyleHacks); }
static void HacksSettingsScreen_GetWOMHacks(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.WOMStyleHacks); }
static void HacksSettingsScreen_SetWOMHacks(const cc_string* v) {
LocalPlayer_Instance.Hacks.WOMStyleHacks = Menu_SetBool(v, OPT_WOM_STYLE_HACKS);
Entities.CurPlayer->Hacks.WOMStyleHacks = Menu_SetBool(v, OPT_WOM_STYLE_HACKS);
}
static void HacksSettingsScreen_GetFullStep(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.FullBlockStep); }
static void HacksSettingsScreen_GetFullStep(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.FullBlockStep); }
static void HacksSettingsScreen_SetFullStep(const cc_string* v) {
LocalPlayer_Instance.Hacks.FullBlockStep = Menu_SetBool(v, OPT_FULL_BLOCK_STEP);
Entities.CurPlayer->Hacks.FullBlockStep = Menu_SetBool(v, OPT_FULL_BLOCK_STEP);
}
static void HacksSettingsScreen_GetPushback(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.PushbackPlacing); }
static void HacksSettingsScreen_GetPushback(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.PushbackPlacing); }
static void HacksSettingsScreen_SetPushback(const cc_string* v) {
LocalPlayer_Instance.Hacks.PushbackPlacing = Menu_SetBool(v, OPT_PUSHBACK_PLACING);
Entities.CurPlayer->Hacks.PushbackPlacing = Menu_SetBool(v, OPT_PUSHBACK_PLACING);
}
static void HacksSettingsScreen_GetLiquids(cc_string* v) { Menu_GetBool(v, Game_BreakableLiquids); }
@ -3184,9 +3184,9 @@ static void HacksSettingsScreen_SetLiquids(const cc_string* v) {
Game_BreakableLiquids = Menu_SetBool(v, OPT_MODIFIABLE_LIQUIDS);
}
static void HacksSettingsScreen_GetSlide(cc_string* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.NoclipSlide); }
static void HacksSettingsScreen_GetSlide(cc_string* v) { Menu_GetBool(v, Entities.CurPlayer->Hacks.NoclipSlide); }
static void HacksSettingsScreen_SetSlide(const cc_string* v) {
LocalPlayer_Instance.Hacks.NoclipSlide = Menu_SetBool(v, OPT_NOCLIP_SLIDE);
Entities.CurPlayer->Hacks.NoclipSlide = Menu_SetBool(v, OPT_NOCLIP_SLIDE);
}
static void HacksSettingsScreen_GetFOV(cc_string* v) { String_AppendInt(v, Camera.Fov); }
@ -3201,7 +3201,7 @@ static void HacksSettingsScreen_SetFOV(const cc_string* v) {
static void HacksSettingsScreen_CheckHacksAllowed(struct MenuOptionsScreen* s) {
struct Widget** widgets = s->widgets;
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = Entities.CurPlayer;
cc_bool disabled = !p->Hacks.Enabled;
Widget_SetDisabled(widgets[3], disabled || !p->Hacks.CanSpeed);
@ -3263,8 +3263,8 @@ void HacksSettingsScreen_Show(void) {
/*########################################################################################################################*
*----------------------------------------------------MiscOptionsScreen----------------------------------------------------*
*#########################################################################################################################*/
static void MiscOptionsScreen_GetReach(cc_string* v) { String_AppendFloat(v, LocalPlayer_Instance.ReachDistance, 2); }
static void MiscOptionsScreen_SetReach(const cc_string* v) { LocalPlayer_Instance.ReachDistance = Menu_Float(v); }
static void MiscOptionsScreen_GetReach(cc_string* v) { String_AppendFloat(v, Entities.CurPlayer->ReachDistance, 2); }
static void MiscOptionsScreen_SetReach(const cc_string* v) { Entities.CurPlayer->ReachDistance = Menu_Float(v); }
static void MiscOptionsScreen_GetMusic(cc_string* v) { String_AppendInt(v, Audio_MusicVolume); }
static void MiscOptionsScreen_SetMusic(const cc_string* v) {

View File

@ -251,8 +251,8 @@ void Picking_CalcPickedBlock(const Vec3* origin, const Vec3* dir, float reach, s
}
void Picking_ClipCameraPos(const Vec3* origin, const Vec3* dir, float reach, struct RayTracer* t) {
cc_bool noClip = (!Camera.Clipping || LocalPlayer_Instance.Hacks.Noclip)
&& LocalPlayer_Instance.Hacks.CanNoclip;
cc_bool noClip = (!Camera.Clipping || Entities.CurPlayer->Hacks.Noclip)
&& Entities.CurPlayer->Hacks.CanNoclip;
if (noClip || !World.Loaded || !RayTrace(t, origin, dir, reach, ClipCamera)) {
RayTracer_SetInvalid(t);
Vec3_Mul1(&t->intersect, dir, reach); /* intersect = dir * reach */

View File

@ -135,7 +135,7 @@ static void HUDScreen_BuildPosition(struct HUDScreen* s, struct VertexTextured*
tex.width = atlas->offset;
Gfx_Make2DQuad(&tex, PACKEDCOL_WHITE, &cur);
IVec3_Floor(&pos, &LocalPlayer_Instance.Base.Position);
IVec3_Floor(&pos, &Entities.CurPlayer->Base.Position);
atlas->curX = tex.x + tex.width;
/* Make (X, Y, Z) suffix */
@ -151,14 +151,14 @@ static void HUDScreen_BuildPosition(struct HUDScreen* s, struct VertexTextured*
}
static cc_bool HUDScreen_HasHacksChanged(struct HUDScreen* s) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &Entities.CurPlayer->Hacks;
float speed = HacksComp_CalcSpeedFactor(hacks, hacks->CanSpeed);
return speed != s->lastSpeed || Camera.Fov != s->lastFov || s->hacksChanged;
}
static void HUDScreen_RemakeLine2(struct HUDScreen* s) {
cc_string status; char statusBuffer[STRING_SIZE * 2];
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &Entities.CurPlayer->Hacks;
float speed;
s->dirty = true;
@ -340,7 +340,7 @@ static void HUDScreen_Update(void* screen, double delta) {
if (HUDScreen_HasHacksChanged(s)) HUDScreen_RemakeLine2(s);
}
IVec3_Floor(&pos, &LocalPlayer_Instance.Base.Position);
IVec3_Floor(&pos, &Entities.CurPlayer->Base.Position);
if (pos.x != s->lastX || pos.y != s->lastY || pos.z != s->lastZ)
s->dirty = true;
}
@ -2003,8 +2003,8 @@ static void GeneratingScreen_EndGeneration(void) {
Gen_Blocks = NULL;
World.Seed = Gen_Seed;
LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance, &update);
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance, &update);
LocalPlayer_CalcDefaultSpawn(Entities.CurPlayer, &update);
LocalPlayer_MoveToSpawn(&LocalPlayer_Instances[0], &update);
}
static void GeneratingScreen_Update(void* screen, double delta) {
@ -2232,10 +2232,10 @@ static struct Widget* touch_widgets[ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS + 2] =
#define TOUCH_MAX_VERTICES (THUMBSTICKWIDGET_MAX + TOUCH_MAX_BTNS * BUTTONWIDGET_MAX)
static void TouchScreen_ChatClick(void* s, void* w) { ChatScreen_OpenInput(&String_Empty); }
static void TouchScreen_RespawnClick(void* s, void* w) { LocalPlayer_HandleRespawn(&LocalPlayer_Instance); }
static void TouchScreen_SetSpawnClick(void* s, void* w) { LocalPlayer_HandleSetSpawn(&LocalPlayer_Instance); }
static void TouchScreen_FlyClick(void* s, void* w) { LocalPlayer_HandleFly(&LocalPlayer_Instance); }
static void TouchScreen_NoclipClick(void* s, void* w) { LocalPlayer_HandleNoclip(&LocalPlayer_Instance); }
static void TouchScreen_RespawnClick(void* s, void* w) { LocalPlayer_HandleRespawn(Entities.CurPlayer); }
static void TouchScreen_SetSpawnClick(void* s, void* w) { LocalPlayer_HandleSetSpawn(Entities.CurPlayer); }
static void TouchScreen_FlyClick(void* s, void* w) { LocalPlayer_HandleFly(Entities.CurPlayer); }
static void TouchScreen_NoclipClick(void* s, void* w) { LocalPlayer_HandleNoclip(Entities.CurPlayer); }
static void TouchScreen_CameraClick(void* s, void* w) { Camera_CycleActive(); }
static void TouchScreen_MoreClick(void* s, void* w) { TouchMoreScreen_Show(); }
static void TouchScreen_SwitchClick(void* s, void* w) { Inventory_SwitchHotbar(); }
@ -2253,11 +2253,11 @@ static void TouchScreen_TabClick(void* s, void* w) {
}
static void TouchScreen_SpeedClick(void* s, void* w) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &Entities.CurPlayer->Hacks;
if (hacks->Enabled) hacks->Speeding = !hacks->Speeding;
}
static void TouchScreen_HalfClick(void* s, void* w) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &Entities.CurPlayer->Hacks;
if (hacks->Enabled) hacks->HalfSpeeding = !hacks->HalfSpeeding;
}
@ -2272,13 +2272,13 @@ static void TouchScreen_BindClick(void* screen, void* widget) {
static const struct TouchButtonDesc onscreenDescs[ONSCREEN_MAX_BTNS] = {
{ "Chat", 0,0,0, TouchScreen_ChatClick },
{ "Tablist", 0,0,0, TouchScreen_TabClick },
{ "Respawn", 0,0,0, TouchScreen_RespawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
{ "Set spawn", 0,0,0, TouchScreen_SetSpawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
{ "Fly", 0,0,0, TouchScreen_FlyClick, &LocalPlayer_Instance.Hacks.CanFly },
{ "Noclip", 0,0,0, TouchScreen_NoclipClick, &LocalPlayer_Instance.Hacks.CanNoclip },
{ "Speed", 0,0,0, TouchScreen_SpeedClick, &LocalPlayer_Instance.Hacks.CanSpeed },
{ "\xabSpeed", 0,0,0, TouchScreen_HalfClick, &LocalPlayer_Instance.Hacks.CanSpeed },
{ "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson },
{ "Respawn", 0,0,0, TouchScreen_RespawnClick, &Entities.CurPlayer->Hacks.CanRespawn },
{ "Set spawn", 0,0,0, TouchScreen_SetSpawnClick, &Entities.CurPlayer->Hacks.CanRespawn },
{ "Fly", 0,0,0, TouchScreen_FlyClick, &Entities.CurPlayer->Hacks.CanFly },
{ "Noclip", 0,0,0, TouchScreen_NoclipClick, &Entities.CurPlayer->Hacks.CanNoclip },
{ "Speed", 0,0,0, TouchScreen_SpeedClick, &Entities.CurPlayer->Hacks.CanSpeed },
{ "\xabSpeed", 0,0,0, TouchScreen_HalfClick, &Entities.CurPlayer->Hacks.CanSpeed },
{ "Camera", 0,0,0, TouchScreen_CameraClick, &Entities.CurPlayer->Hacks.CanUseThirdPerson },
{ "Delete", 0,0,0, TouchScreen_DeleteClick },
{ "Pick", 0,0,0, TouchScreen_PickClick },
{ "Place", 0,0,0, TouchScreen_PlaceClick },
@ -2294,7 +2294,7 @@ static const struct TouchButtonDesc hackDescs[2] = {
#define TOUCHSCREEN_BTN_COLOR PackedCol_Make(255, 255, 255, 220)
static void TouchScreen_InitButtons(struct TouchScreen* s) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
struct HacksComp* hacks = &Entities.CurPlayer->Hacks;
const struct TouchButtonDesc* desc;
int i, j;
for (i = 0; i < ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS; i++) s->widgets[i] = NULL;