| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
|---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | ### File Specific: |
|---|
| 22 | main-programmer: Christian Meyer |
|---|
| 23 | co-programmer: ... |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | #ifndef _DATA_TANK_H |
|---|
| 27 | #define _DATA_TANK_H |
|---|
| 28 | |
|---|
| 29 | #include <string.h> |
|---|
| 30 | #include <stdio.h> |
|---|
| 31 | #include <stdlib.h> |
|---|
| 32 | |
|---|
| 33 | #define MAX_FILENAME_LENGHT 64 |
|---|
| 34 | #define POSTFIX_LENGHT 5 |
|---|
| 35 | |
|---|
| 36 | typedef struct DataTree |
|---|
| 37 | { |
|---|
| 38 | struct DataTree *up, *down, *parent; |
|---|
| 39 | char filename[MAX_FILENAME_LENGHT]; |
|---|
| 40 | void* resource; |
|---|
| 41 | int type; |
|---|
| 42 | } DataTree; |
|---|
| 43 | |
|---|
| 44 | class DataLoader |
|---|
| 45 | { |
|---|
| 46 | private: |
|---|
| 47 | void*(**load_funcs)(char*); |
|---|
| 48 | void(**free_funcs)(void*); |
|---|
| 49 | char** postfixes; |
|---|
| 50 | void** placeholders; |
|---|
| 51 | |
|---|
| 52 | int ntypes; |
|---|
| 53 | |
|---|
| 54 | public: |
|---|
| 55 | DataLoader(); |
|---|
| 56 | ~DataLoader(); |
|---|
| 57 | |
|---|
| 58 | int add_filetype( char* postfix, void*(*lfunc)(char*), void(*ffunc)(void*), char* placeholderfile); |
|---|
| 59 | void* load_file( char* file, int type); |
|---|
| 60 | int get_type( char* file); |
|---|
| 61 | void* get_placeholder( int type); |
|---|
| 62 | void free_file( void* resource, int type); |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | class DataTank |
|---|
| 66 | { |
|---|
| 67 | private: |
|---|
| 68 | |
|---|
| 69 | // resources stored in binary tree structure |
|---|
| 70 | DataTree* tree; |
|---|
| 71 | |
|---|
| 72 | // data loader |
|---|
| 73 | DataLoader* loader; |
|---|
| 74 | |
|---|
| 75 | // tree functions |
|---|
| 76 | void tree_add( void* r, char* filename, int type); |
|---|
| 77 | DataTree* tree_find( char* file); |
|---|
| 78 | void tree_remove( DataTree* rem); |
|---|
| 79 | void tree_delete(); |
|---|
| 80 | |
|---|
| 81 | public: |
|---|
| 82 | DataTank(); |
|---|
| 83 | ~DataTank(); |
|---|
| 84 | |
|---|
| 85 | void* get( char* file); |
|---|
| 86 | void unload( char* file); |
|---|
| 87 | int add_filetype( char* postfix, void*(*lfunc)(char*), void(*ffunc)(void*), char* placeholderfile); |
|---|
| 88 | void precache( char* resfile, void(*pfunc)(int, float, char*)); |
|---|
| 89 | void save_precache( char* file); |
|---|
| 90 | void save_node( DataTree* act, FILE* out); |
|---|
| 91 | DataTree* tree_highest( DataTree* t); |
|---|
| 92 | DataTree* tree_lowest( DataTree* t); |
|---|
| 93 | }; |
|---|
| 94 | |
|---|
| 95 | #endif |
|---|