Beispiel #1
0
void NetDemo::writeMessages()
{
    if (!isRecording())
    {
        return;
    }

    if (connected && gamestate == GS_LEVEL)
    {
        // Write the player's ticcmd
        buf_t netbuf_localcmd(128);
        writeLocalCmd(&netbuf_localcmd);
        captured.push_back(netbuf_localcmd);

        if ((gametic - header.first_gametic) % header.snapshot_spacing == 0
                && (unsigned)gametic > header.first_gametic)
        {
            buf_t netbuf_snapshot(NetDemo::MAX_SNAPSHOT_SIZE);
            writeSnapshot(&netbuf_snapshot);
            captured.push_front(netbuf_snapshot);
        }
    }


    byte *output_buf = new byte[captured.size() * MAX_UDP_PACKET];

    uint32_t output_len = 0;
    while (!captured.empty())
    {
        buf_t netbuf(captured.front());
        uint32_t len = netbuf.BytesLeftToRead();

        byte *chunk = netbuf.ReadChunk(len);
        memcpy(output_buf + output_len, chunk, len);
        output_len += len;

        captured.pop_front();
    }

    uint32_t le_output_len = LONG(output_len);
    uint32_t le_gametic = LONG(gametic);

    // write a blank message even if there is no data in order to preserve
    // timing of the netdemo
    if (header.first_gametic == 0)
        header.first_gametic = gametic;

    size_t cnt = 0;
    cnt += sizeof(le_output_len) * fwrite(&le_output_len, sizeof(le_output_len), 1, demofp);
    cnt += sizeof(le_gametic) * fwrite(&le_gametic, sizeof(le_gametic), 1, demofp);

    cnt += fwrite(output_buf, 1, output_len, demofp);

    delete [] output_buf;
}
void NetDemo::writeMessages()
{
    if (!isRecording())
        return;

    static buf_t netbuf_localcmd(1024);

    if (atSnapshotInterval())
    {
        size_t length;
        writeSnapshotData(snapbuf, length);
        writeSnapshotIndexEntry();

        writeChunk(snapbuf, length, NetDemo::msg_snapshot);
    }

    if (connected)
    {
        // Write the console player's game data
        SZ_Clear(&netbuf_localcmd);
        writeLocalCmd(&netbuf_localcmd);
        captured.push_back(netbuf_localcmd);
    }

    byte *output_buf = new byte[captured.size() * MAX_UDP_PACKET];

    uint32_t output_len = 0;
    while (!captured.empty())
    {
        buf_t netbuf(captured.front());
        uint32_t len = netbuf.BytesLeftToRead();

        byte *chunk = netbuf.ReadChunk(len);
        memcpy(output_buf + output_len, chunk, len);
        output_len += len;

        captured.pop_front();
    }

    writeChunk(output_buf, output_len, NetDemo::msg_packet);

    delete [] output_buf;
}