mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Don't crash the game if socket() fails
Not that it every should anyways
This commit is contained in:
parent
15ca271e98
commit
e933ec2298
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
||||||
int MapRenderer_1DUsedCount, MapRenderer_ChunksCount;
|
int MapRenderer_1DUsedCount, MapRenderer_ChunksCount;
|
||||||
int MapRenderer_MaxUpdates;
|
|
||||||
struct ChunkPartInfo* MapRenderer_PartsNormal;
|
struct ChunkPartInfo* MapRenderer_PartsNormal;
|
||||||
struct ChunkPartInfo* MapRenderer_PartsTranslucent;
|
struct ChunkPartInfo* MapRenderer_PartsTranslucent;
|
||||||
|
|
||||||
@ -44,10 +43,8 @@ static struct ChunkInfo** renderChunks;
|
|||||||
static int renderChunksCount;
|
static int renderChunksCount;
|
||||||
/* Distance of each chunk from the camera. */
|
/* Distance of each chunk from the camera. */
|
||||||
static cc_uint32* distances;
|
static cc_uint32* distances;
|
||||||
|
/* Maximum number of chunk updates that can be performed in one frame. */
|
||||||
/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) * 2 parts in the buffer,
|
static int maxChunkUpdates;
|
||||||
with parts for 'normal' buffer being in lower half. */
|
|
||||||
static struct ChunkPartInfo* partsBuffer_Raw;
|
|
||||||
|
|
||||||
struct ChunkInfo* MapRenderer_GetChunk(int cx, int cy, int cz) {
|
struct ChunkInfo* MapRenderer_GetChunk(int cx, int cy, int cz) {
|
||||||
return &mapChunks[MapRenderer_Pack(cx, cy, cz)];
|
return &mapChunks[MapRenderer_Pack(cx, cy, cz)];
|
||||||
@ -314,8 +311,7 @@ void MapRenderer_RenderTranslucent(double delta) {
|
|||||||
*----------------------------------------------------Chunks mangagement---------------------------------------------------*
|
*----------------------------------------------------Chunks mangagement---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void FreeParts(void) {
|
static void FreeParts(void) {
|
||||||
Mem_Free(partsBuffer_Raw);
|
Mem_Free(MapRenderer_PartsNormal);
|
||||||
partsBuffer_Raw = NULL;
|
|
||||||
MapRenderer_PartsNormal = NULL;
|
MapRenderer_PartsNormal = NULL;
|
||||||
MapRenderer_PartsTranslucent = NULL;
|
MapRenderer_PartsTranslucent = NULL;
|
||||||
}
|
}
|
||||||
@ -333,11 +329,12 @@ static void FreeChunks(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void AllocateParts(void) {
|
static void AllocateParts(void) {
|
||||||
cc_uint32 count = MapRenderer_ChunksCount * MapRenderer_1DUsedCount;
|
struct ChunkPartInfo* ptr;
|
||||||
partsBuffer_Raw = (struct ChunkPartInfo*)Mem_AllocCleared(count * 2, sizeof(struct ChunkPartInfo), "chunk parts");
|
cc_uint32 count = MapRenderer_ChunksCount * MapRenderer_1DUsedCount;
|
||||||
|
|
||||||
MapRenderer_PartsNormal = partsBuffer_Raw;
|
ptr = (struct ChunkPartInfo*)Mem_AllocCleared(count * 2, sizeof(struct ChunkPartInfo), "chunk parts");
|
||||||
MapRenderer_PartsTranslucent = partsBuffer_Raw + count;
|
MapRenderer_PartsNormal = ptr;
|
||||||
|
MapRenderer_PartsTranslucent = ptr + count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AllocateChunks(void) {
|
static void AllocateChunks(void) {
|
||||||
@ -421,7 +418,8 @@ void MapRenderer_Refresh(void) {
|
|||||||
ResetPartCounts();
|
ResetPartCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRenderer_RefreshBorders(int maxHeight) {
|
/* Refreshes chunks on the border of the map whose y is less than 'maxHeight'. */
|
||||||
|
static void RefreshBorderChunks(int maxHeight) {
|
||||||
int cx, cy, cz;
|
int cx, cy, cz;
|
||||||
cc_bool onBorder;
|
cc_bool onBorder;
|
||||||
|
|
||||||
@ -543,7 +541,7 @@ static void UpdateChunks(double delta) {
|
|||||||
|
|
||||||
/* Build more chunks if 30 FPS or over, otherwise slowdown */
|
/* Build more chunks if 30 FPS or over, otherwise slowdown */
|
||||||
chunksTarget += delta < CHUNK_TARGET_TIME ? 1 : -1;
|
chunksTarget += delta < CHUNK_TARGET_TIME ? 1 : -1;
|
||||||
Math_Clamp(chunksTarget, 4, MapRenderer_MaxUpdates);
|
Math_Clamp(chunksTarget, 4, maxChunkUpdates);
|
||||||
|
|
||||||
p = &LocalPlayer_Instance;
|
p = &LocalPlayer_Instance;
|
||||||
samePos = Vec3_Equals(&Camera.CurrentPos, &lastCamPos)
|
samePos = Vec3_Equals(&Camera.CurrentPos, &lastCamPos)
|
||||||
@ -717,7 +715,7 @@ static void OnEnvVariableChanged(void* obj, int envVar) {
|
|||||||
Builder_EdgeLevel = max(0, Env.EdgeHeight);
|
Builder_EdgeLevel = max(0, Env.EdgeHeight);
|
||||||
|
|
||||||
/* Only need to refresh chunks on map borders up to highest edge level.*/
|
/* Only need to refresh chunks on map borders up to highest edge level.*/
|
||||||
MapRenderer_RefreshBorders(max(oldClip, Builder_EdgeLevel));
|
RefreshBorderChunks(max(oldClip, Builder_EdgeLevel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,7 +787,7 @@ static void MapRenderer_Init(void) {
|
|||||||
/* This = 87 fixes map being invisible when no textures */
|
/* This = 87 fixes map being invisible when no textures */
|
||||||
MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */
|
MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */
|
||||||
chunkPos = IVec3_MaxValue();
|
chunkPos = IVec3_MaxValue();
|
||||||
MapRenderer_MaxUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30);
|
maxChunkUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30);
|
||||||
CalcViewDists();
|
CalcViewDists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ extern int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
|||||||
extern int MapRenderer_1DUsedCount;
|
extern int MapRenderer_1DUsedCount;
|
||||||
/* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
|
/* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
|
||||||
extern int MapRenderer_ChunksCount;
|
extern int MapRenderer_ChunksCount;
|
||||||
/* Maximum number of chunk updates that can be performed in one frame. */
|
|
||||||
extern int MapRenderer_MaxUpdates;
|
|
||||||
|
|
||||||
/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) parts in the buffer,
|
/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) parts in the buffer,
|
||||||
with parts for 'normal' buffer being in lower half. */
|
with parts for 'normal' buffer being in lower half. */
|
||||||
@ -89,9 +87,6 @@ void MapRenderer_DeleteChunk(struct ChunkInfo* info);
|
|||||||
/* NOTE: This method also adjusts internal state, so do not bypass this. */
|
/* NOTE: This method also adjusts internal state, so do not bypass this. */
|
||||||
void MapRenderer_BuildChunk(struct ChunkInfo* info, int* chunkUpdates);
|
void MapRenderer_BuildChunk(struct ChunkInfo* info, int* chunkUpdates);
|
||||||
|
|
||||||
/* Refreshes chunks on the border of the map. */
|
|
||||||
/* NOTE: Only refreshes border chunks whose y is less than 'maxHeight'. */
|
|
||||||
void MapRenderer_RefreshBorders(int maxHeight);
|
|
||||||
/* Deletes all chunks and resets internal state. */
|
/* Deletes all chunks and resets internal state. */
|
||||||
void MapRenderer_Refresh(void);
|
void MapRenderer_Refresh(void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -861,11 +861,9 @@ void Platform_LoadSysFonts(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Socket----------------------------------------------------------*
|
*---------------------------------------------------------Socket----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Socket_Create(SocketHandle* socketResult) {
|
cc_result Socket_Create(SocketHandle* socketResult) {
|
||||||
*socketResult = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
*socketResult = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (*socketResult == -1) {
|
return *socketResult == -1 ? Socket__Error() : 0;
|
||||||
Logger_Abort2(Socket__Error(), "Failed to create socket");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result Socket_ioctl(SocketHandle socket, cc_uint32 cmd, int* data) {
|
static cc_result Socket_ioctl(SocketHandle socket, cc_uint32 cmd, int* data) {
|
||||||
|
@ -193,7 +193,7 @@ CC_API void Waitable_WaitFor(void* handle, cc_uint32 milliseconds);
|
|||||||
void Platform_LoadSysFonts(void);
|
void Platform_LoadSysFonts(void);
|
||||||
|
|
||||||
/* Allocates a new socket. */
|
/* Allocates a new socket. */
|
||||||
CC_API void Socket_Create(SocketHandle* socket);
|
CC_API cc_result Socket_Create(SocketHandle* socket);
|
||||||
/* Returns how much data is available to be read from the given socket. */
|
/* Returns how much data is available to be read from the given socket. */
|
||||||
CC_API cc_result Socket_Available(SocketHandle socket, cc_uint32* available);
|
CC_API cc_result Socket_Available(SocketHandle socket, cc_uint32* available);
|
||||||
/* Sets whether operations on the given socket block the calling thread. */
|
/* Sets whether operations on the given socket block the calling thread. */
|
||||||
|
@ -301,7 +301,8 @@ static void MPConnection_BeginConnect(void) {
|
|||||||
cc_result res;
|
cc_result res;
|
||||||
String_InitArray(title, titleBuffer);
|
String_InitArray(title, titleBuffer);
|
||||||
|
|
||||||
Socket_Create(&net_socket);
|
res = Socket_Create(&net_socket);
|
||||||
|
if (res) { MPConnection_FailConnect(res); return; }
|
||||||
Server.Disconnected = false;
|
Server.Disconnected = false;
|
||||||
|
|
||||||
Socket_SetBlocking(net_socket, false);
|
Socket_SetBlocking(net_socket, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user