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

Last change on this file since 112 was 112, checked in by Sam Hocevar, 11 years ago
  • Fix spelling errors all over the place.
File size: 7.1 KB
RevLine 
[56]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
[2]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>
[7]18#include <stdint.h>
[2]19
[39]20extern char const *spec_types[];
[2]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
[39]72void set_spec_main_file(char const *filename, int search_order=SPEC_SEARCH_OUTSIDE_INSIDE);
[2]73
[39]74void set_filename_prefix(char const *prefix);
[2]75char *get_filename_prefix();
[39]76void set_save_filename_prefix(char const *prefix);
[2]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;
[39]89  virtual int unbuffered_write(void const *buf, size_t count) = 0;
[2]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;
[39]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
[2]101  int tell();
102  virtual int file_size() = 0;
103
104  virtual ~bFILE();
105
[112]106    // read and write using little-endianness
107    uint16_t read_uint16();
108    uint32_t read_uint32();
109    uint8_t read_uint8();
110    double read_double();
111    void write_uint16(uint16_t x);
112    void write_uint32(uint32_t x);
113    void write_uint8(uint8_t x);
114    void write_double(double x);
115    void set_read_buffer_size(long size);
116};
[2]117
118class jFILE : public bFILE     // this file type will use virtual opens inside of a spe
119{
120  char *fname;
121  char *tmp_write_name;
122  int access;
123  int fd,flags;
124  long start_offset,file_length;    // offset of file from actual file begining
125
126  long current_offset;  // current offset
127 
128public :
129        int get_fd() const { return fd; }
130
[39]131  void open_internal(char const *filename, char const *mode, int flags);
132  void open_external(char const *filename, char const *mode, int flags);
[2]133
[39]134  jFILE(char const *filename, char const *access_string);      // same as fopen parameters
[2]135  jFILE(FILE *file_pointer);                      // assumes fp is at begining of file
136  virtual int open_failure() { return fd<0; }
137  virtual int unbuffered_read(void *buf, size_t count);       // returns number of bytes read
[39]138  virtual int unbuffered_write(void const *buf, size_t count);     // returns number of bytes written
[2]139  virtual int unbuffered_seek(long offset, int whence);      // whence=SEEK_SET, SEEK_CUR,
140                                                             // SEEK_END, ret=0=success
141  virtual int unbuffered_tell();
142  virtual int file_size() { return file_length; }
143  virtual ~jFILE();
144} ;
145
146class spec_entry
147{
148public :
149  char *name;
150  unsigned long size,offset;
151  unsigned char type;
152 
153  spec_entry(unsigned char spec_type,
[39]154             char const *object_name,
155             char const *link_filename,
[2]156             unsigned long data_size,
157             unsigned long data_offset)
158  { type=spec_type;
159    name=strcpy((char *)jmalloc(strlen(object_name)+1,"spec_entry::name"),object_name);
160    size=data_size; offset=data_offset;
161  } 
162  void print();
163  ~spec_entry() { if (name) jfree(name); }
164} ;
165
166
167class spec_directory
168{
169public :
170  void startup(bFILE *fp);
171
172  int total;
173  spec_entry **entries;
174  void *data;
175  long size;
176//  spec_directory(char *filename);  ;; not allowed anymore, user must construct file first!
177  spec_directory(FILE *fp);
178  spec_directory(bFILE *fp);
179  spec_directory();
[39]180  spec_entry *find(char const *name);
181  spec_entry *find(char const *name, int type);
[2]182  spec_entry *find(int type);
[39]183  long find_number(char const *name);
[2]184  long find_number(int type);
185  void remove(spec_entry *e);
186  void add_by_hand(spec_entry *e);
187  void calc_offsets();
[112]188  long data_start_offset();  // returns the first offset past directory items
[2]189  long data_end_offset();    // this should be the end of the file
190  long type_total(int type);
[39]191  jFILE *write(char const *filename);
[2]192  int    write(bFILE *fp);
193  void print();
194  void delete_entries();   // if the directory was created by hand instead of by file
195  ~spec_directory();
196} ;
197
198/*jFILE *add_directory_entry(char *filename,
199                         unsigned short data_type,
200                         char *data_name,
201                         unsigned long data_size,
202                         char *link_filename=NULL);*/
203
[17]204uint16_t read_uint16(FILE *fp);
205uint32_t read_uint32(FILE *fp);
206uint32_t read_other_uint32(FILE *fp);
207uint16_t read_other_uint16(FILE *fp);
208uint8_t read_uint8(FILE *fp);
[2]209
[17]210void write_uint16(FILE *fp, uint16_t x);
211void write_uint32(FILE *fp, uint32_t x);
212void write_other_uint16(FILE *fp, uint16_t x);
213void write_other_uint32(FILE *fp, uint32_t x);
214void write_uint8(FILE *fp, uint8_t x);
[2]215
216void set_spec_main_file(char *filename, int Search_order);
[39]217void set_file_opener(bFILE *(*open_fun)(char const *, char const *));
[2]218void set_no_space_handler(void (*handle_fun)());
[39]219bFILE *open_file(char const *filename, char const *mode);
[2]220#endif
221
222
223
224
225
226
227
Note: See TracBrowser for help on using the repository browser.