tennis.map: Texture tweak
[neverball] / ball / demo_dir.c
1 /*
2  * Copyright (C) 2003-2010 Neverball authors
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <assert.h>
18
19 #include "array.h"
20 #include "common.h"
21 #include "demo.h"
22 #include "demo_dir.h"
23 #include "fs.h"
24
25 /*---------------------------------------------------------------------------*/
26
27 static void free_item(struct dir_item *item)
28 {
29     if (item->data)
30     {
31         demo_free(item->data);
32         item->data = NULL;
33     }
34 }
35
36 static void load_item(struct dir_item *item)
37 {
38     if (!item->data)
39         item->data = demo_load(item->path);
40 }
41
42 static int scan_item(struct dir_item *item)
43 {
44     return str_ends_with(item->path, ".nbr");
45 }
46
47 /*---------------------------------------------------------------------------*/
48
49 Array demo_dir_scan(void)
50 {
51     return fs_dir_scan("Replays", scan_item);
52 }
53
54 void demo_dir_load(Array items, int lo, int hi)
55 {
56     int i;
57
58     assert(lo >= 0  && lo < array_len(items));
59     assert(hi >= lo && hi < array_len(items));
60
61     for (i = lo; i <= hi; i++)
62         load_item(array_get(items, i));
63 }
64
65 void demo_dir_free(Array items)
66 {
67     int i;
68
69     for (i = 0; i < array_len(items); i++)
70         free_item(array_get(items, i));
71
72     dir_free(items);
73 }
74
75 /*---------------------------------------------------------------------------*/