c++ - 没有已知的 SFML Vector2i 转换

标签 c++ arrays networking game-engine sfml

我完全厌倦了这个,但为什么我得到:

client.cpp: In member function 'void Client::netRead(int, int)':
client.cpp:158:57: error: no matching function for call to 'Client::nextGameUpdate(sf::Vector2i [0], int [0], sf::IpAddress [0], int&)'
client.cpp:158:57: note: candidate is:
client.cpp:85:6: note: void Client::nextGameUpdate(sf::Vector2i, int, sf::IpAddress, int)
client.cpp:85:6: note:   no known conversion for argument 1 from 'sf::Vector2i [0] {aka sf::Vector2<int> [0]}' to 'sf::Vector2i {aka sf::Vector2<int>}'
[Finished in 4.7s]

    void Client::nextGameUpdate(sf::Vector2i qq, int ww, sf::IpAddress cc, int dataSize)
    {
        pListIP[dataSize] = cc;
        pListVec[dataSize] = qq;
        pListRot[dataSize] = ww;

        int num_pListIP = sizeof(pListIP)/sizeof(sf::IpAddress);
        if (num_pListIP == lastPlayerCount)
        {
            return;
        }
        else if (num_pListIP > lastPlayerCount)
        {
            int new_players = num_pListIP - lastPlayerCount;
            for (new_players; new_players>0; new_players--)
            {
                addPlayer();


}
    }
    else if (num_pListIP < lastPlayerCount)
    {
        int dc_players = lastPlayerCount - num_pListIP;
        for (dc_players; dc_players>0; dc_players--)
        {
            removePlayer();
        }
    }
    lastPlayerCount = num_pListIP;
}

void Client::netRead(int net_step, int dataSize)
{
    sf::Packet player_vectors;
    sf::Packet player_rotations;
    sf::Packet player_ips;

    switch (net_step)
    {
        case 1:
            if (socket.receive(player_vectors, sender, senderPort) != sf::Socket::Done)
                return;
            while (dataSize>0)
            {
                sf::Vector2i tmp_vec;
                player_vectors >> tmp_vec.x >> tmp_vec.y;
                pListVec[dataSize] = tmp_vec;
                dataSize--;
            }
            break;
        case 2:
            if (socket.receive(player_rotations, sender, senderPort) != sf::Socket::Done)
                return;
            while (dataSize>0)
            {
                int tmp_rot;
                player_rotations >> tmp_rot;
                pListRot[dataSize] = tmp_rot;
                dataSize--;
            }
            break;
        case 3:
            if (socket.receive(player_ips, sender, senderPort) != sf::Socket::Done)
                return;
            while (dataSize>0)
            {
                std::string tmp_str;
                player_ips >> tmp_str;
                sf::IpAddress tmp_ips = tmp_str;
                pListIP[dataSize] = tmp_ips;
                dataSize--;
            }
            break;
    }
    nextGameUpdate(pListVec, pListRot, pListIP, dataSize);
}

标题

private:
sf::Vector2i pListVec[];
sf::IpAddress pListIP[];
int pListRot[];

我觉得这与我试图用 sf::Vector2i 填充的数组有关.../我茫然地盯着屏幕

非常简单。 netRead 从另一个非常基本的函数获取信息。然后交换机经过net_step int...

在游戏收到继续运行所需的所有数据包后,我们触发 nextGameUpdate() 并向其发送 3 个数组和一个 dataSize int 变量。

如果您解决了这个问题,请提前致谢。 ^^

最佳答案

您正在尝试将 pListVec 传递给 qq,其中前者是 Vector2i 的数组,后者是单个 Vector2i

但是你的逻辑也有问题。将 pListVec 替换为更新函数中的 qq,第二条语句为:

pListVec[dataSize] = pListVec;

那不可能是你想要做的。


此外,由于 pListVec 是您类的私有(private)字段,因此无需将其作为成员函数之间的参数传递(至少在您的情况下,两个方法在同一个对象上调用实例)。

关于c++ - 没有已知的 SFML Vector2i 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440353/

相关文章:

c++ - 重载运算符有地址吗?

python - 你可以使用 python 套接字进行 docker 容器通信吗?

java - 为什么这个简短的套接字代码示例会生成损坏的文件?

c++ - 为内存和外部依赖管理重新组织 C++ 代码

c++ - 使用 yaml cpp 解析 yaml

c++ - 如何编写具有单独的源目录和头目录的 Makefile?

javascript - 从数组追加和加载

c - 动态数组是在没有 malloc 的情况下分配的

arrays - 如果存在则将对象插入数组,否则在 MongoDB 中设置对象

linux - 可以在不同的 CPU 内核上执行相同网络数据包的硬和软 IRQ 吗?