fix: 修正SDL初始化条件判断和Windows平台编译兼容性

- 将SDL初始化条件从`< 0`改为`!= 0`以正确处理SDL_Init返回值
- 为Windows平台的#pragma comment添加_MSC_VER条件编译,提升跨编译器兼容性
- 统一网络函数参数声明中的指针星号位置,保持代码风格一致
This commit is contained in:
2026-02-09 20:16:52 +08:00
parent 17d7079c41
commit a0944f8e16
2 changed files with 8 additions and 6 deletions
+7 -5
View File
@@ -18,7 +18,9 @@
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#endif
#else
#include <sys/socket.h>
#include <netinet/in.h>
@@ -59,7 +61,7 @@ bool create_server(int port);
* @return true 连接成功
* @return false 连接失败
*/
bool connect_to_server(const char* ip, int port);
bool connect_to_server(const char *ip, int port);
/**
* @brief 发送网络消息
@@ -67,7 +69,7 @@ bool connect_to_server(const char* ip, int port);
* @return true 发送成功
* @return false 发送失败
*/
bool send_network_message(const NetworkMessage* msg);
bool send_network_message(const NetworkMessage *msg);
/**
* @brief 接收网络消息
@@ -76,7 +78,7 @@ bool send_network_message(const NetworkMessage* msg);
* @return true 接收成功
* @return false 接收失败或超时
*/
bool receive_network_message(NetworkMessage* msg, int timeout_ms);
bool receive_network_message(NetworkMessage *msg, int timeout_ms);
/**
* @brief 断开网络连接
@@ -97,7 +99,7 @@ bool is_network_connected();
* @return true 获取成功
* @return false 获取失败
*/
bool get_local_ip(char* ip_buffer, int buffer_size);
bool get_local_ip(char *ip_buffer, int buffer_size);
/**
* @brief 发送落子消息
@@ -115,7 +117,7 @@ bool send_move(int x, int y, int player_id);
* @return true 发送成功
* @return false 发送失败
*/
bool send_chat_message(const char* message);
bool send_chat_message(const char *message);
/**
* @brief 发送认输消息
+1 -1
View File
@@ -29,7 +29,7 @@
*/
int init_gui()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
if (!SDL_Init(SDL_INIT_VIDEO))
{
printf("SDL初始化失败: %s\n", SDL_GetError());
return -1;