source: abuse/trunk/src/imlib/specs.hpp @ 57

Last change on this file since 57 was 57, checked in by Sam Hocevar, 11 years ago
  • Move each header to the same directory as its corresponding source, to get a better idea of which files are likely to export symbols.
File size: 7.1 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#ifndef __SPECS_HPP_
11#define __SPECS_HPP_
12#include "linked.hpp"
13#include <stdio.h>
14#include "jmalloc.hpp"
15#include "system.h"
16#include <fcntl.h>
17#include <stdlib.h>
18#include <stdint.h>
19
20extern char const *spec_types[];
21
22#define SPEC_INVALID_TYPE    0
23#define SPEC_COLOR_TABLE     1
24#define SPEC_PALETTE         2
25#define SPEC_IMAGE           4
26#define SPEC_FORETILE        5
27#define SPEC_BACKTILE        6
28#define SPEC_CHARACTER       7
29#define SPEC_MORPH_POINTS_8  8
30#define SPEC_MORPH_POINTS_16 9
31#define SPEC_GRUE_OBJS       10
32#define SPEC_EXTERN_SFX      11
33#define SPEC_DMX_MUS         12
34#define SPEC_PATCHED_MORPH   13
35#define SPEC_NORMAL_FILE     14
36#define SPEC_COMPRESS1_FILE  15
37#define SPEC_VECTOR_IMAGE    16
38#define SPEC_LIGHT_LIST      17
39#define SPEC_GRUE_FGMAP      18
40#define SPEC_GRUE_BGMAP      19
41#define SPEC_DATA_ARRAY      20
42#define SPEC_CHARACTER2      21
43#define SPEC_PARTICLE        22
44#define SPEC_EXTERNAL_LCACHE 23
45
46
47#define SPEC_SIGNATURE    "SPEC1.0"
48#define SPEC_SIG_SIZE     8
49
50#define SPEC_FLAG_LINK    1
51
52#define SPEC_SEARCH_INSIDE_OUTSIDE 1
53#define SPEC_SEARCH_OUTSIDE_INSIDE 2
54#define SPEC_SEARCH_INSIDE_ONLY    3
55
56/* file specs
57              8   signature
58              2   number entries
59                  [entries]
60              1      entry type
61              1      entry name length
62              X      entry name (with null terminator)
63              1      flags
64                     if (flags&LINK)
65              1        link filename length
66              X        link filename
67                     else
68              4        data size
69              4        offset
70*/
71
72void set_spec_main_file(char const *filename, int search_order=SPEC_SEARCH_OUTSIDE_INSIDE);
73
74void set_filename_prefix(char const *prefix);
75char *get_filename_prefix();
76void set_save_filename_prefix(char const *prefix);
77char *get_save_filename_prefix();
78#define JFILE_CLONED 1
79
80class bFILE     // base file type which other files should be derived from (jFILE & NFS for now)
81{
82  protected :
83  unsigned char *rbuf,*wbuf;
84  unsigned long rbuf_start,rbuf_end,rbuf_size,
85                wbuf_end,wbuf_size;                // can't seek while writing!
86  int flush_writes();                             // returns 0 on failure, else # of bytes written
87
88  virtual int unbuffered_read(void *buf, size_t count)  = 0;
89  virtual int unbuffered_write(void const *buf, size_t count) = 0;
90  virtual int unbuffered_tell()                         = 0;
91  virtual int unbuffered_seek(long offset, int whence)  = 0;   // whence=SEEK_SET, SEEK_CUR,
92                                                               // SEEK_END, ret=0=success
93  virtual int allow_read_buffering();
94  virtual int allow_write_buffering();
95  public :
96  bFILE();
97  virtual int open_failure() = 0;
98  int read(void *buf, size_t count);        // returns number of bytes read, calls unbuffer_read
99  int write(void const *buf, size_t count); // returns number of bytes written
100  int seek(long offset, int whence);        // whence=SEEK_SET, SEEK_CUR, SEEK_END, ret=0=success
101  int tell();
102  virtual int file_size() = 0;
103
104  virtual ~bFILE();
105
106
107  // these read and writes, allways read/write Intel endian-ness
108  uint16_t read_uint16();
109  uint32_t read_uint32();
110  uint8_t read_uint8();
111  double read_double();
112  void write_uint16(uint16_t x);
113  void write_uint32(uint32_t x);
114  void write_uint8(uint8_t x);
115  void write_double(double x);
116  void set_read_buffer_size(long size);
117} ;
118
119class jFILE : public bFILE     // this file type will use virtual opens inside of a spe
120{
121  char *fname;
122  char *tmp_write_name;
123  int access;
124  int fd,flags;
125  long start_offset,file_length;    // offset of file from actual file begining
126
127  long current_offset;  // current offset
128 
129public :
130        int get_fd() const { return fd; }
131
132  void open_internal(char const *filename, char const *mode, int flags);
133  void open_external(char const *filename, char const *mode, int flags);
134
135  jFILE(char const *filename, char const *access_string);      // same as fopen parameters
136  jFILE(FILE *file_pointer);                      // assumes fp is at begining of file
137  virtual int open_failure() { return fd<0; }
138  virtual int unbuffered_read(void *buf, size_t count);       // returns number of bytes read
139  virtual int unbuffered_write(void const *buf, size_t count);     // returns number of bytes written
140  virtual int unbuffered_seek(long offset, int whence);      // whence=SEEK_SET, SEEK_CUR,
141                                                             // SEEK_END, ret=0=success
142  virtual int unbuffered_tell();
143  virtual int file_size() { return file_length; }
144  virtual ~jFILE();
145} ;
146
147class spec_entry
148{
149public :
150  char *name;
151  unsigned long size,offset;
152  unsigned char type;
153 
154  spec_entry(unsigned char spec_type,
155             char const *object_name,
156             char const *link_filename,
157             unsigned long data_size,
158             unsigned long data_offset)
159  { type=spec_type;
160    name=strcpy((char *)jmalloc(strlen(object_name)+1,"spec_entry::name"),object_name);
161    size=data_size; offset=data_offset;
162  } 
163  void print();
164  ~spec_entry() { if (name) jfree(name); }
165} ;
166
167
168class spec_directory
169{
170public :
171  void startup(bFILE *fp);
172
173  int total;
174  spec_entry **entries;
175  void *data;
176  long size;
177//  spec_directory(char *filename);  ;; not allowed anymore, user must construct file first!
178  spec_directory(FILE *fp);
179  spec_directory(bFILE *fp);
180  spec_directory();
181  spec_entry *find(char const *name);
182  spec_entry *find(char const *name, int type);
183  spec_entry *find(int type);
184  long find_number(char const *name);
185  long find_number(int type);
186  void remove(spec_entry *e);
187  void add_by_hand(spec_entry *e);
188  void calc_offsets();
189  long data_start_offset();  // returns the firsyt offset past directory items
190  long data_end_offset();    // this should be the end of the file
191  long type_total(int type);
192  jFILE *write(char const *filename);
193  int    write(bFILE *fp);
194  void print();
195  void delete_entries();   // if the directory was created by hand instead of by file
196  ~spec_directory();
197} ;
198
199/*jFILE *add_directory_entry(char *filename,
200                         unsigned short data_type,
201                         char *data_name,
202                         unsigned long data_size,
203                         char *link_filename=NULL);*/
204
205uint16_t read_uint16(FILE *fp);
206uint32_t read_uint32(FILE *fp);
207uint32_t read_other_uint32(FILE *fp);
208uint16_t read_other_uint16(FILE *fp);
209uint8_t read_uint8(FILE *fp);
210
211void write_uint16(FILE *fp, uint16_t x);
212void write_uint32(FILE *fp, uint32_t x);
213void write_other_uint16(FILE *fp, uint16_t x);
214void write_other_uint32(FILE *fp, uint32_t x);
215void write_uint8(FILE *fp, uint8_t x);
216
217void set_spec_main_file(char *filename, int Search_order);
218void set_file_opener(bFILE *(*open_fun)(char const *, char const *));
219void set_no_space_handler(void (*handle_fun)());
220bFILE *open_file(char const *filename, char const *mode);
221#endif
222
223
224
225
226
227
228
Note: See TracBrowser for help on using the repository browser.