project_files/frontlib/ipc/mapconn.c
author Wuzzy <Wuzzy2@mail.ru>
Sat, 11 May 2019 04:58:11 +0200
changeset 14917 3a53309e684b
parent 10017 de822cd3df3a
permissions -rw-r--r--
Set default SD fallback music for themes: sdmusic.ogg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     1
/*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     2
 * Hedgewars, a free turn based strategy game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     4
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     5
 * This program is free software; you can redistribute it and/or
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     6
 * modify it under the terms of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     8
 * of the License, or (at your option) any later version.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
     9
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    13
 * GNU General Public License for more details.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    14
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    15
 * You should have received a copy of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    16
 * along with this program; if not, write to the Free Software
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    18
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    19
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    20
#include "mapconn.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    21
#include "ipcbase.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    22
#include "ipcprotocol.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    23
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    24
#include "../util/logging.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    25
#include "../util/buffer.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    26
#include "../util/util.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    27
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    28
#include <stdlib.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    29
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    30
typedef enum {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    31
    AWAIT_CONNECTION,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    32
    AWAIT_REPLY,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    33
    AWAIT_CLOSE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    34
    FINISHED
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    35
} mapconn_state;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    36
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    37
struct _flib_mapconn {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    38
    uint8_t mapBuffer[IPCBASE_MAPMSG_BYTES];
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    39
    flib_ipcbase *ipcBase;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    40
    flib_vector *configBuffer;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    41
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    42
    mapconn_state progress;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    43
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    44
    void (*onSuccessCb)(void*, const uint8_t*, int);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    45
    void *onSuccessCtx;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    46
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    47
    void (*onFailureCb)(void*, const char*);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    48
    void *onFailureCtx;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    49
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    50
    bool running;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    51
    bool destroyRequested;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    52
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    53
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    54
static void noop_handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    55
static void noop_handleFailure(void *context, const char *errormessage) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    56
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    57
static void clearCallbacks(flib_mapconn *conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    58
    conn->onSuccessCb = &noop_handleSuccess;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    59
    conn->onFailureCb = &noop_handleFailure;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    60
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    61
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    62
static flib_vector *createConfigBuffer(const flib_map *mapdesc) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    63
    flib_vector *result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    64
    flib_vector *tempbuffer = flib_vector_create();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    65
    if(tempbuffer) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    66
        bool error = false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    67
        error |= flib_ipc_append_mapconf(tempbuffer, mapdesc, true);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    68
        error |= flib_ipc_append_message(tempbuffer, "!");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    69
        if(!error) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    70
            result = tempbuffer;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    71
            tempbuffer = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    72
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    73
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    74
    flib_vector_destroy(tempbuffer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    75
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    76
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    77
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    78
flib_mapconn *flib_mapconn_create(const flib_map *mapdesc) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    79
    if(log_badargs_if(mapdesc==NULL)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    80
        return NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    81
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    82
    flib_mapconn *result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    83
    flib_mapconn *tempConn = flib_calloc(1, sizeof(flib_mapconn));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    84
    if(tempConn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    85
        tempConn->ipcBase = flib_ipcbase_create();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    86
        tempConn->configBuffer = createConfigBuffer(mapdesc);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    87
        if(tempConn->ipcBase && tempConn->configBuffer) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    88
            tempConn->progress = AWAIT_CONNECTION;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    89
            clearCallbacks(tempConn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    90
            result = tempConn;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    91
            tempConn = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    92
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    93
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    94
    flib_mapconn_destroy(tempConn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    95
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    96
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    97
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    98
void flib_mapconn_destroy(flib_mapconn *conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
    99
    if(conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   100
        if(conn->running) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   101
            /*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   102
             * The function was called from a callback, so the tick function is still running
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   103
             * and we delay the actual destruction. We ensure no further callbacks will be
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   104
             * sent to prevent surprises.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   105
             */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   106
            clearCallbacks(conn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   107
            conn->destroyRequested = true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   108
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   109
            flib_ipcbase_destroy(conn->ipcBase);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   110
            flib_vector_destroy(conn->configBuffer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   111
            free(conn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   112
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   113
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   114
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   115
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   116
int flib_mapconn_getport(flib_mapconn *conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   117
    if(log_badargs_if(conn==NULL)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   118
        return 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   119
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   120
    return flib_ipcbase_port(conn->ipcBase);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   121
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   122
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   123
void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   124
    if(!log_badargs_if(conn==NULL)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   125
        conn->onSuccessCb = callback ? callback : &noop_handleSuccess;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   126
        conn->onSuccessCtx = context;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   127
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   128
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   129
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   130
void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   131
    if(!log_badargs_if(conn==NULL)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   132
        conn->onFailureCb = callback ? callback : &noop_handleFailure;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   133
        conn->onFailureCtx = context;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   134
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   135
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   136
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   137
static void flib_mapconn_wrappedtick(flib_mapconn *conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   138
    if(conn->progress == AWAIT_CONNECTION) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   139
        flib_ipcbase_accept(conn->ipcBase);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   140
        switch(flib_ipcbase_state(conn->ipcBase)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   141
        case IPC_CONNECTED:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   142
            {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   143
                flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   144
                if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   145
                    conn->progress = FINISHED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   146
                    conn->onFailureCb(conn->onFailureCtx, "Error sending map information to the engine.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   147
                    return;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   148
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   149
                    conn->progress = AWAIT_REPLY;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   150
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   151
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   152
            break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   153
        case IPC_NOT_CONNECTED:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   154
            conn->progress = FINISHED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   155
            conn->onFailureCb(conn->onFailureCtx, "Engine connection closed unexpectedly.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   156
            return;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   157
        default:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   158
            break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   159
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   160
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   161
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   162
    if(conn->progress == AWAIT_REPLY) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   163
        if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   164
            conn->progress = AWAIT_CLOSE;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   165
        } else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   166
            conn->progress = FINISHED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   167
            conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   168
            return;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   169
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   170
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   171
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   172
    if(conn->progress == AWAIT_CLOSE) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   173
        // Just do throwaway reads so we find out when the engine disconnects
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   174
        uint8_t buf[256];
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   175
        flib_ipcbase_recv_message(conn->ipcBase, buf);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   176
        if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   177
            conn->progress = FINISHED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   178
            conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   179
            return;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   180
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   181
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   182
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   183
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   184
void flib_mapconn_tick(flib_mapconn *conn) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   185
    if(!log_badargs_if(conn==NULL)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   186
            && !log_w_if(conn->running, "Call to flib_mapconn_tick from a callback")
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   187
            && !log_w_if(conn->progress == FINISHED, "We are already done.")) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   188
        conn->running = true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   189
        flib_mapconn_wrappedtick(conn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   190
        conn->running = false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   191
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   192
        if(conn->destroyRequested) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   193
            flib_mapconn_destroy(conn);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   194
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   195
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7576
diff changeset
   196
}