misc/libphyslayer/physfslualoader.c
author sheepluva
Fri, 06 Dec 2013 23:53:35 +0100
changeset 9760 395ca7fe6362
parent 8524 a65e9bcf0a03
child 9991 3858d99476f5
permissions -rw-r--r--
It seems that at the current state it is necessary to protect sending stats/ending game from multiple execution, as that can happen if you e.g. fail a mission more than once in the same tick (e.g. destroying two essential crates at the same time) Otherwise you can get a blank / stuck frontend (e.g. when using deagle to shoot the two last crates at the same time)! the best approach might be to never call the function that sends stats and ends game from any event handler directly, but instead have a flag 'isFailed' that is set to true when any of the possible fails happen and to check that flag every tick to send stats and end game if true
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8074
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
     1
#include "lua.h"
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
     2
#include "physfs.h"
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     3
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     4
#define BUFSIZE 1024
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     5
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
     6
void *physfsReaderBuffer;
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     7
8119
257ffa847aa2 physfs: no carbon depency on osx, add cdecl attributes on extra functions
koda
parents: 8074
diff changeset
     8
PHYSFS_DECL const char * physfsReader(lua_State *L, PHYSFS_File *f, size_t *size)
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     9
{
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    10
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    11
    if(PHYSFS_eof(f))
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    12
    {
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    13
        return NULL;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    14
    }
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    15
    else
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    16
    {
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    17
        *size = PHYSFS_readBytes(f, physfsReaderBuffer, BUFSIZE);
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    18
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    19
        if(*size == 0)
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    20
            return NULL;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    21
        else
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    22
            return physfsReaderBuffer;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    23
    }
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    24
}
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    25
8119
257ffa847aa2 physfs: no carbon depency on osx, add cdecl attributes on extra functions
koda
parents: 8074
diff changeset
    26
PHYSFS_DECL void physfsReaderSetBuffer(void *buffer)
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    27
{
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    28
    physfsReaderBuffer = buffer;
8074
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
    29
}
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
    30