misc/libopenalbridge/wrappers.c
author sheepluva
Wed, 25 Apr 2012 08:23:48 +0200
changeset 6928 9562ace15141
parent 3697 d5b30d6373fc
permissions -rw-r--r--
nemo said I was boring for removing the "hello" randomizer on room join. That was actually an accident, fixed by this commit. Now find an actual reason to call me boring (there are many to choose from :P) nemo!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     1
/*
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     2
* OpenAL Bridge - a simple portable library for OpenAL interface
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     3
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     4
*
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     5
* This program is free software; you can redistribute it and/or modify
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     6
* it under the terms of the GNU Lesser General Public License as published by
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     7
* the Free Software Foundation; version 2 of the License
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     8
*
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     9
* This program is distributed in the hope that it will be useful,
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    12
* GNU Lesser General Public License for more details.
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    13
*
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    14
* You should have received a copy of the GNU Lesser General Public License
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    15
* along with this program; if not, write to the Free Software
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    17
*/
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    18
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    19
#include "wrappers.h"
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    20
#include "openalbridge_t.h"
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    21
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    22
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    23
void *Malloc (size_t nbytes) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    24
    void *aptr;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    25
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    26
    if ((aptr = malloc(nbytes)) == NULL) {
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3487
diff changeset
    27
        fprintf(stderr,"(Bridge FATAL) - not enough memory\n");
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    28
        abort();
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    29
    }
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3487
diff changeset
    30
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    31
    return aptr;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    32
}
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    33
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    34
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    35
void *Realloc (void *aptr, size_t nbytes) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    36
    aptr = realloc(aptr, nbytes);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    37
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    38
    if (aptr == NULL) {
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3487
diff changeset
    39
        fprintf(stderr,"(Bridge FATAL) - not enough memory\n");
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    40
        abort();
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3362
diff changeset
    41
    }
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    42
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    43
    return aptr;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    44
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    45
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    46
3529
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    47
FILE *Fopen (const char *fname, char *mode) {
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    48
    FILE *fp;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    49
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    50
    fp = fopen(fname,mode);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    51
    if (fp == NULL)
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3487
diff changeset
    52
        fprintf(stderr,"(Bridge Error) - can't open file %s in mode '%s'\n", fname, mode);
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    53
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    54
    return fp;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    55
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    56
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    57
3529
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    58
al_sound_t new_sound_el (void) {
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    59
    al_sound_t sound;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3529
diff changeset
    60
3529
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    61
    sound.filename = NULL;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    62
    sound.buffer = -1;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    63
    sound.source_index = -1;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    64
    sound.is_used = AL_FALSE;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    65
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    66
    return sound;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    67
}
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    68
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    69
al_sound_t init_sound_el (const char *str) {
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    70
    al_sound_t sound;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3529
diff changeset
    71
3529
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    72
    sound.filename = str;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    73
    sound.source_index = -1;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    74
    sound.is_used = AL_TRUE;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    75
    alGenBuffers(1, &sound.buffer);
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    76
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    77
    return sound;
0e968ba12a84 memory management for openalbridge
koda
parents: 3514
diff changeset
    78
}