mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Further reduce use of LocalPlayer_Instance
This commit is contained in:
parent
335279a634
commit
fcc903016b
20
src/Entity.c
20
src/Entity.c
@ -938,26 +938,20 @@ cc_bool LocalPlayer_CheckCanZoom(struct LocalPlayer* p) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer_MoveToSpawn(struct LocalPlayer* p) {
|
void LocalPlayer_MoveToSpawn(struct LocalPlayer* p, struct LocationUpdate* update) {
|
||||||
struct LocationUpdate update;
|
p->Base.VTABLE->SetLocation(&p->Base, update);
|
||||||
|
|
||||||
update.flags = LU_HAS_POS | LU_HAS_YAW | LU_HAS_PITCH;
|
|
||||||
update.pos = p->Spawn;
|
|
||||||
update.yaw = p->SpawnYaw;
|
|
||||||
update.pitch = p->SpawnPitch;
|
|
||||||
|
|
||||||
p->Base.VTABLE->SetLocation(&p->Base, &update);
|
|
||||||
/* TODO: This needs to be before new map... */
|
/* TODO: This needs to be before new map... */
|
||||||
Camera.CurrentPos = Camera.Active->GetPosition(p, 0.0f);
|
Camera.CurrentPos = Camera.Active->GetPosition(p, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer_CalcDefaultSpawn(struct LocalPlayer* p) {
|
void LocalPlayer_CalcDefaultSpawn(struct LocalPlayer* p, struct LocationUpdate* update) {
|
||||||
float x = (World.Width / 2) + 0.5f;
|
float x = (World.Width / 2) + 0.5f;
|
||||||
float z = (World.Length / 2) + 0.5f;
|
float z = (World.Length / 2) + 0.5f;
|
||||||
|
|
||||||
p->Spawn = Respawn_FindSpawnPosition(x, z, p->Base.Size);
|
update->flags = LU_HAS_POS | LU_HAS_YAW | LU_HAS_PITCH;
|
||||||
p->SpawnYaw = 0.0f;
|
update->pos = Respawn_FindSpawnPosition(x, z, p->Base.Size);
|
||||||
p->SpawnPitch = 0.0f;
|
update->yaw = 0.0f;
|
||||||
|
update->pitch = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,8 +245,8 @@ void LocalPlayer_SetInterpPosition(struct LocalPlayer* p, float t);
|
|||||||
void LocalPlayer_ResetJumpVelocity(struct LocalPlayer* p);
|
void LocalPlayer_ResetJumpVelocity(struct LocalPlayer* p);
|
||||||
cc_bool LocalPlayer_CheckCanZoom(struct LocalPlayer* p);
|
cc_bool LocalPlayer_CheckCanZoom(struct LocalPlayer* p);
|
||||||
/* Moves local player back to spawn point. */
|
/* Moves local player back to spawn point. */
|
||||||
void LocalPlayer_MoveToSpawn(struct LocalPlayer* p);
|
void LocalPlayer_MoveToSpawn(struct LocalPlayer* p, struct LocationUpdate* update);
|
||||||
void LocalPlayer_CalcDefaultSpawn(struct LocalPlayer* p);
|
void LocalPlayer_CalcDefaultSpawn(struct LocalPlayer* p, struct LocationUpdate* update);
|
||||||
|
|
||||||
cc_bool LocalPlayer_HandleRespawn(struct LocalPlayer* p);
|
cc_bool LocalPlayer_HandleRespawn(struct LocalPlayer* p);
|
||||||
cc_bool LocalPlayer_HandleSetSpawn(struct LocalPlayer* p);
|
cc_bool LocalPlayer_HandleSetSpawn(struct LocalPlayer* p);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#ifdef CC_BUILD_FILESYSTEM
|
#ifdef CC_BUILD_FILESYSTEM
|
||||||
|
static struct LocationUpdate* spawn_point;
|
||||||
static cc_bool calcDefaultSpawn;
|
static cc_bool calcDefaultSpawn;
|
||||||
static struct MapImporter* imp_head;
|
static struct MapImporter* imp_head;
|
||||||
static struct MapImporter* imp_tail;
|
static struct MapImporter* imp_tail;
|
||||||
@ -63,12 +64,13 @@ struct MapImporter* MapImporter_Find(const cc_string* path) {
|
|||||||
|
|
||||||
cc_result Map_LoadFrom(const cc_string* path) {
|
cc_result Map_LoadFrom(const cc_string* path) {
|
||||||
cc_string relPath, fileName, fileExt;
|
cc_string relPath, fileName, fileExt;
|
||||||
|
struct LocationUpdate update = { 0 };
|
||||||
struct MapImporter* imp;
|
struct MapImporter* imp;
|
||||||
struct Stream stream;
|
struct Stream stream;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
Game_Reset();
|
Game_Reset();
|
||||||
|
|
||||||
calcDefaultSpawn = false;
|
spawn_point = &update;
|
||||||
res = Stream_OpenFile(&stream, path);
|
res = Stream_OpenFile(&stream, path);
|
||||||
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
|
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
|
||||||
|
|
||||||
@ -84,8 +86,8 @@ cc_result Map_LoadFrom(const cc_string* path) {
|
|||||||
if (res) Logger_SysWarn2(res, "decoding", path);
|
if (res) Logger_SysWarn2(res, "decoding", path);
|
||||||
|
|
||||||
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
||||||
if (calcDefaultSpawn) LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance);
|
if (!spawn_point) LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance, &update);
|
||||||
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance);
|
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance, &update);
|
||||||
|
|
||||||
relPath = *path;
|
relPath = *path;
|
||||||
Utils_UNSAFE_GetFilename(&relPath);
|
Utils_UNSAFE_GetFilename(&relPath);
|
||||||
@ -184,7 +186,6 @@ static cc_result Lvl_Load(struct Stream* stream) {
|
|||||||
cc_result res;
|
cc_result res;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
|
||||||
struct Stream compStream;
|
struct Stream compStream;
|
||||||
struct InflateState state;
|
struct InflateState state;
|
||||||
Inflate_MakeStream2(&compStream, &state, stream);
|
Inflate_MakeStream2(&compStream, &state, stream);
|
||||||
@ -197,11 +198,12 @@ static cc_result Lvl_Load(struct Stream* stream) {
|
|||||||
World.Length = Stream_GetU16_LE(&header[4]);
|
World.Length = Stream_GetU16_LE(&header[4]);
|
||||||
World.Height = Stream_GetU16_LE(&header[6]);
|
World.Height = Stream_GetU16_LE(&header[6]);
|
||||||
|
|
||||||
p->Spawn.x = Stream_GetU16_LE(&header[8]);
|
spawn_point->flags = LU_HAS_POS | LU_HAS_YAW | LU_HAS_PITCH;
|
||||||
p->Spawn.z = Stream_GetU16_LE(&header[10]);
|
spawn_point->pos.x = Stream_GetU16_LE(&header[8]);
|
||||||
p->Spawn.y = Stream_GetU16_LE(&header[12]);
|
spawn_point->pos.z = Stream_GetU16_LE(&header[10]);
|
||||||
p->SpawnYaw = Math_Packed2Deg(header[14]);
|
spawn_point->pos.y = Stream_GetU16_LE(&header[12]);
|
||||||
p->SpawnPitch = Math_Packed2Deg(header[15]);
|
spawn_point->yaw = Math_Packed2Deg(header[14]);
|
||||||
|
spawn_point->pitch = Math_Packed2Deg(header[15]);
|
||||||
/* (2) pervisit, perbuild permissions */
|
/* (2) pervisit, perbuild permissions */
|
||||||
|
|
||||||
if ((res = Map_ReadBlocks(&compStream))) return res;
|
if ((res = Map_ReadBlocks(&compStream))) return res;
|
||||||
@ -271,7 +273,6 @@ static cc_result Fcm_Load(struct Stream* stream) {
|
|||||||
cc_result res;
|
cc_result res;
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
|
||||||
struct Stream compStream;
|
struct Stream compStream;
|
||||||
struct InflateState state;
|
struct InflateState state;
|
||||||
Inflate_MakeStream2(&compStream, &state, stream);
|
Inflate_MakeStream2(&compStream, &state, stream);
|
||||||
@ -284,11 +285,12 @@ static cc_result Fcm_Load(struct Stream* stream) {
|
|||||||
World.Height = Stream_GetU16_LE(&header[7]);
|
World.Height = Stream_GetU16_LE(&header[7]);
|
||||||
World.Length = Stream_GetU16_LE(&header[9]);
|
World.Length = Stream_GetU16_LE(&header[9]);
|
||||||
|
|
||||||
p->Spawn.x = ((int)Stream_GetU32_LE(&header[11])) / 32.0f;
|
spawn_point->flags = LU_HAS_POS | LU_HAS_YAW | LU_HAS_PITCH;
|
||||||
p->Spawn.y = ((int)Stream_GetU32_LE(&header[15])) / 32.0f;
|
spawn_point->pos.x = ((int)Stream_GetU32_LE(&header[11])) / 32.0f;
|
||||||
p->Spawn.z = ((int)Stream_GetU32_LE(&header[19])) / 32.0f;
|
spawn_point->pos.y = ((int)Stream_GetU32_LE(&header[15])) / 32.0f;
|
||||||
p->SpawnYaw = Math_Packed2Deg(header[23]);
|
spawn_point->pos.z = ((int)Stream_GetU32_LE(&header[19])) / 32.0f;
|
||||||
p->SpawnPitch = Math_Packed2Deg(header[24]);
|
spawn_point->yaw = Math_Packed2Deg(header[23]);
|
||||||
|
spawn_point->pitch = Math_Packed2Deg(header[24]);
|
||||||
|
|
||||||
/* header[25] (4) date modified */
|
/* header[25] (4) date modified */
|
||||||
/* header[29] (4) date created */
|
/* header[29] (4) date created */
|
||||||
@ -677,19 +679,18 @@ static void Cw_Callback_1(struct NbtTag* tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Cw_Callback_2(struct NbtTag* tag) {
|
static void Cw_Callback_2(struct NbtTag* tag) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
|
||||||
|
|
||||||
if (IsTag(tag->parent, "MapGenerator")) {
|
if (IsTag(tag->parent, "MapGenerator")) {
|
||||||
if (IsTag(tag, "Seed")) { World.Seed = NbtTag_I32(tag); return; }
|
if (IsTag(tag, "Seed")) { World.Seed = NbtTag_I32(tag); return; }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!IsTag(tag->parent, "Spawn")) return;
|
if (!IsTag(tag->parent, "Spawn")) return;
|
||||||
|
spawn_point->flags = LU_HAS_POS | LU_HAS_YAW | LU_HAS_PITCH;
|
||||||
|
|
||||||
if (IsTag(tag, "X")) { p->Spawn.x = NbtTag_I16(tag); return; }
|
if (IsTag(tag, "X")) { spawn_point->pos.x = NbtTag_I16(tag); return; }
|
||||||
if (IsTag(tag, "Y")) { p->Spawn.y = NbtTag_I16(tag); return; }
|
if (IsTag(tag, "Y")) { spawn_point->pos.y = NbtTag_I16(tag); return; }
|
||||||
if (IsTag(tag, "Z")) { p->Spawn.z = NbtTag_I16(tag); return; }
|
if (IsTag(tag, "Z")) { spawn_point->pos.z = NbtTag_I16(tag); return; }
|
||||||
if (IsTag(tag, "H")) { p->SpawnYaw = Math_Packed2Deg(NbtTag_U8(tag)); return; }
|
if (IsTag(tag, "H")) { spawn_point->yaw = Math_Packed2Deg(NbtTag_U8(tag)); return; }
|
||||||
if (IsTag(tag, "P")) { p->SpawnPitch = Math_Packed2Deg(NbtTag_U8(tag)); return; }
|
if (IsTag(tag, "P")) { spawn_point->pitch = Math_Packed2Deg(NbtTag_U8(tag)); return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockID cw_curID;
|
static BlockID cw_curID;
|
||||||
@ -1238,7 +1239,7 @@ Classic 0.15 to Classic 0.30:
|
|||||||
|
|
||||||
static void Dat_Format0And1(void) {
|
static void Dat_Format0And1(void) {
|
||||||
/* Formats 0 and 1 don't store spawn position, so use default of map centre */
|
/* Formats 0 and 1 don't store spawn position, so use default of map centre */
|
||||||
calcDefaultSpawn = true;
|
spawn_point = NULL;
|
||||||
|
|
||||||
/* Similiar env to how it appears in preclassic - 0.13 classic client */
|
/* Similiar env to how it appears in preclassic - 0.13 classic client */
|
||||||
Env.CloudsHeight = -30000;
|
Env.CloudsHeight = -30000;
|
||||||
@ -1286,7 +1287,6 @@ static cc_result Dat_LoadFormat1(struct Stream* stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cc_result Dat_LoadFormat2(struct Stream* stream) {
|
static cc_result Dat_LoadFormat2(struct Stream* stream) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
|
||||||
struct JClassDesc classes[CLASS_CAPACITY];
|
struct JClassDesc classes[CLASS_CAPACITY];
|
||||||
cc_uint8 header[2 + 2];
|
cc_uint8 header[2 + 2];
|
||||||
struct JUnion obj;
|
struct JUnion obj;
|
||||||
@ -1326,11 +1326,14 @@ static cc_result Dat_LoadFormat2(struct Stream* stream) {
|
|||||||
World.Blocks = field->Value.Array.Ptr;
|
World.Blocks = field->Value.Array.Ptr;
|
||||||
World.Volume = field->Value.Array.Size;
|
World.Volume = field->Value.Array.Size;
|
||||||
} else if (String_CaselessEqualsConst(&fieldName, "xSpawn")) {
|
} else if (String_CaselessEqualsConst(&fieldName, "xSpawn")) {
|
||||||
p->Spawn.x = (float)Java_I32(field);
|
spawn_point->pos.x = (float)Java_I32(field);
|
||||||
|
spawn_point->flags = LU_HAS_POS;
|
||||||
} else if (String_CaselessEqualsConst(&fieldName, "ySpawn")) {
|
} else if (String_CaselessEqualsConst(&fieldName, "ySpawn")) {
|
||||||
p->Spawn.y = (float)Java_I32(field);
|
spawn_point->pos.y = (float)Java_I32(field);
|
||||||
|
spawn_point->flags = LU_HAS_POS;
|
||||||
} else if (String_CaselessEqualsConst(&fieldName, "zSpawn")) {
|
} else if (String_CaselessEqualsConst(&fieldName, "zSpawn")) {
|
||||||
p->Spawn.z = (float)Java_I32(field);
|
spawn_point->pos.z = (float)Java_I32(field);
|
||||||
|
spawn_point->flags = LU_HAS_POS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1447,11 +1450,12 @@ static void MCLevel_Callback_3(struct NbtTag* tag) {
|
|||||||
struct NbtTag* field = tag->parent;
|
struct NbtTag* field = tag->parent;
|
||||||
|
|
||||||
if (IsTag(group, "Map") && IsTag(field, "spawn")) {
|
if (IsTag(group, "Map") && IsTag(field, "spawn")) {
|
||||||
cc_int16 value = NbtTag_I16(tag);
|
cc_int16 value = NbtTag_I16(tag);
|
||||||
|
spawn_point->flags = LU_HAS_POS;
|
||||||
|
|
||||||
if (tag->listIndex == 0) LocalPlayer_Instance.Spawn.x = value;
|
if (tag->listIndex == 0) spawn_point->pos.x = value;
|
||||||
if (tag->listIndex == 1) LocalPlayer_Instance.Spawn.y = value - 1.0f;
|
if (tag->listIndex == 1) spawn_point->pos.y = value - 1.0f;
|
||||||
if (tag->listIndex == 2) LocalPlayer_Instance.Spawn.z = value;
|
if (tag->listIndex == 2) spawn_point->pos.z = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1996,14 +1996,15 @@ static void GeneratingScreen_Free(void* screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void GeneratingScreen_EndGeneration(void) {
|
static void GeneratingScreen_EndGeneration(void) {
|
||||||
|
struct LocationUpdate update;
|
||||||
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
||||||
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
||||||
|
|
||||||
Gen_Blocks = NULL;
|
Gen_Blocks = NULL;
|
||||||
World.Seed = Gen_Seed;
|
World.Seed = Gen_Seed;
|
||||||
|
|
||||||
LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance);
|
LocalPlayer_CalcDefaultSpawn(&LocalPlayer_Instance, &update);
|
||||||
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance);
|
LocalPlayer_MoveToSpawn(&LocalPlayer_Instance, &update);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GeneratingScreen_Update(void* screen, double delta) {
|
static void GeneratingScreen_Update(void* screen, double delta) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user