author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2337 | a4587769d43a |
child 2380 | 3b26659b4a9a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
3 |
/** @file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
4 |
* All actions handling saving and loading goes on in this file. The general actions |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
5 |
* are as follows for saving a game (loading is analogous): |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
6 |
* <ol> |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
7 |
* <li>initialize the writer by creating a temporary memory-buffer for it |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
8 |
* <li>go through all to-be saved elements, each 'chunk' (ChunkHandler) prefixed by a label |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
9 |
* <li>use their description array (SaveLoad) to know what elements to save and in what version |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
10 |
* of the game it was active (used when loading) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
11 |
* <li>write all data byte-by-byte to the temporary buffer so it is endian-safe |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
12 |
* <li>when the buffer is full; flush it to the output (eg save to file) (_sl.buf, _sl.bufp, _sl.bufe) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
13 |
* <li>repeat this until everything is done, and flush any remaining output to file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
14 |
* </ol> |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
15 |
* @see ChunkHandler |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
16 |
* @see SaveLoad |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
17 |
*/ |
0 | 18 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1886
diff
changeset
|
19 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1284
diff
changeset
|
20 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2162
diff
changeset
|
21 |
#include "functions.h" |
0 | 22 |
#include "vehicle.h" |
23 |
#include "station.h" |
|
2285
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
24 |
#include "thread.h" |
0 | 25 |
#include "town.h" |
26 |
#include "player.h" |
|
27 |
#include "saveload.h" |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
28 |
#include "variables.h" |
2335
1222aa57deb7
(svn r2861) Move inclusion of setjmp.h into saveload.c, should've been part of r2819
tron
parents:
2295
diff
changeset
|
29 |
#include <setjmp.h> |
0 | 30 |
|
31 |
enum { |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2289
diff
changeset
|
32 |
SAVEGAME_MAJOR_VERSION = 16, |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
33 |
SAVEGAME_MINOR_VERSION = 0, |
0 | 34 |
|
35 |
SAVEGAME_LOADABLE_VERSION = (SAVEGAME_MAJOR_VERSION << 8) + SAVEGAME_MINOR_VERSION |
|
36 |
}; |
|
37 |
||
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
38 |
byte _sl_version; /// the major savegame version identifier |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
39 |
uint16 _sl_full_version; /// the full version of the savegame |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
40 |
|
2337
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
41 |
typedef void WriterProc(uint len); |
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
42 |
typedef uint ReaderProc(void); |
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
43 |
|
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
44 |
typedef uint ReferenceToIntProc(const void *obj, SLRefType rt); |
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
45 |
typedef void *IntToReferenceProc(uint index, SLRefType rt); |
a4587769d43a
(svn r2863) Move some type declarations into saveload.c, should've been part of r2819
tron
parents:
2335
diff
changeset
|
46 |
|
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
47 |
/** The saveload struct, containing reader-writer functions, bufffer, version, etc. */ |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
48 |
static struct { |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
49 |
bool save; /// are we doing a save or a load atm. True when saving |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
50 |
byte need_length; /// ??? |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
51 |
byte block_mode; /// ??? |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
52 |
bool error; /// did an error occur or not |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
53 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
54 |
int obj_len; /// the length of the current object we are busy with |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
55 |
int array_index, last_array_index; /// in the case of an array, the current and last positions |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
56 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
57 |
uint32 offs_base; /// the offset in number of bytes since we started writing data (eg uncompressed savegame size) |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
58 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
59 |
WriterProc *write_bytes; /// savegame writer function |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
60 |
ReaderProc *read_bytes; /// savegame loader function |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
61 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
62 |
ReferenceToIntProc *ref_to_int_proc; /// function to convert pointers to numbers when saving a game |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
63 |
IntToReferenceProc *int_to_ref_proc; /// function to convert numbers to pointers when loading a game |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
64 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
65 |
const ChunkHandler* const *chs; /// the chunk of data that is being processed atm (vehicles, signs, etc.) |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
66 |
const SaveLoad* const *includes; /// the internal layouf of the given chunk |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
67 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
68 |
/** When saving/loading savegames, they are always saved to a temporary memory-place |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
69 |
* to be flushed to file (save) or to final place (load) when full. */ |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
70 |
byte *bufp, *bufe; /// bufp(ointer) gives the current position in the buffer bufe(nd) gives the end of the buffer |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
71 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
72 |
// these 3 may be used by compressor/decompressors. |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
73 |
byte *buf; /// pointer to temporary memory to read/write, initialized by SaveLoadFormat->initread/write |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
74 |
uint bufsize; /// the size of the temporary memory *buf |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
75 |
FILE *fh; /// the file from which is read or written to |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
76 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
77 |
void (*excpt_uninit)(void); /// the function to execute on any encountered error |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
78 |
const char *excpt_msg; /// the error message |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
79 |
jmp_buf excpt; /// @todo used to jump to "exception handler"; really ugly |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
80 |
} _sl; |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
81 |
|
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
82 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
83 |
enum NeedLengthValues {NL_NONE = 0, NL_WANTLENGTH = 1, NL_CALCLENGTH = 2}; |
0 | 84 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
85 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
86 |
* Fill the input buffer by reading from the file with the given reader |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
87 |
*/ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
88 |
static void SlReadFill(void) |
0 | 89 |
{ |
90 |
uint len = _sl.read_bytes(); |
|
91 |
assert(len != 0); |
|
92 |
||
93 |
_sl.bufp = _sl.buf; |
|
94 |
_sl.bufe = _sl.buf + len; |
|
95 |
_sl.offs_base += len; |
|
96 |
} |
|
97 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
98 |
static inline uint32 SlGetOffs(void) {return _sl.offs_base - (_sl.bufe - _sl.bufp);} |
0 | 99 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
100 |
/** Flush the output buffer by writing to disk with the given reader. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
101 |
* If the buffer pointer has not yet been set up, set it up now. Usually |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
102 |
* only called when the buffer is full, or there is no more data to be processed |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
103 |
*/ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
104 |
static void SlWriteFill(void) |
0 | 105 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
106 |
// flush the buffer to disk (the writer) |
0 | 107 |
if (_sl.bufp != NULL) { |
108 |
uint len = _sl.bufp - _sl.buf; |
|
109 |
_sl.offs_base += len; |
|
110 |
if (len) _sl.write_bytes(len); |
|
111 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
112 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
113 |
/* All the data from the buffer has been written away, rewind to the beginning |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
114 |
* to start reading in more data */ |
0 | 115 |
_sl.bufp = _sl.buf; |
116 |
_sl.bufe = _sl.buf + _sl.bufsize; |
|
117 |
} |
|
118 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
119 |
/** Error handler, calls longjmp to simulate an exception. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
120 |
* @todo this was used to have a central place to handle errors, but it is |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
121 |
* pretty ugly, and seriously interferes with any multithreaded approaches */ |
0 | 122 |
static void NORETURN SlError(const char *msg) |
123 |
{ |
|
124 |
_sl.excpt_msg = msg; |
|
125 |
longjmp(_sl.excpt, 0); |
|
126 |
} |
|
127 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
128 |
/** Read in a single byte from file. If the temporary buffer is full, |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
129 |
* flush it to its final destination |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
130 |
* @return return the read byte from file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
131 |
*/ |
1514 | 132 |
static inline int SlReadByteInternal(void) |
0 | 133 |
{ |
134 |
if (_sl.bufp == _sl.bufe) SlReadFill(); |
|
135 |
return *_sl.bufp++; |
|
136 |
} |
|
137 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
138 |
/** Wrapper for SlReadByteInternal */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
139 |
int SlReadByte(void) {return SlReadByteInternal();} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
140 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
141 |
/** Write away a single byte from memory. If the temporary buffer is full, |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
142 |
* flush it to its destination (file) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
143 |
* @param b the byte that is currently written |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
144 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
145 |
static inline void SlWriteByteInternal(byte b) |
1514 | 146 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
147 |
if (_sl.bufp == _sl.bufe) SlWriteFill(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
148 |
*_sl.bufp++ = b; |
1514 | 149 |
} |
150 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
151 |
/** Wrapper for SlWriteByteInternal */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
152 |
void SlWriteByte(byte b) {SlWriteByteInternal(b);} |
0 | 153 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
154 |
static inline int SlReadUint16(void) |
0 | 155 |
{ |
156 |
int x = SlReadByte() << 8; |
|
157 |
return x | SlReadByte(); |
|
158 |
} |
|
159 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
160 |
static inline uint32 SlReadUint32(void) |
0 | 161 |
{ |
162 |
uint32 x = SlReadUint16() << 16; |
|
163 |
return x | SlReadUint16(); |
|
164 |
} |
|
165 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
166 |
static inline uint64 SlReadUint64(void) |
0 | 167 |
{ |
168 |
uint32 x = SlReadUint32(); |
|
169 |
uint32 y = SlReadUint32(); |
|
170 |
return (uint64)x << 32 | y; |
|
171 |
} |
|
172 |
||
2144
011a8b5ddcaa
(svn r2654) SlWriteUint16() should have a uint16 as parameter, not some arbitrary enum
tron
parents:
2141
diff
changeset
|
173 |
static inline void SlWriteUint16(uint16 v) |
0 | 174 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2144
diff
changeset
|
175 |
SlWriteByte(GB(v, 8, 8)); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2144
diff
changeset
|
176 |
SlWriteByte(GB(v, 0, 8)); |
0 | 177 |
} |
178 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
179 |
static inline void SlWriteUint32(uint32 v) |
0 | 180 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2144
diff
changeset
|
181 |
SlWriteUint16(GB(v, 16, 16)); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2144
diff
changeset
|
182 |
SlWriteUint16(GB(v, 0, 16)); |
0 | 183 |
} |
184 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
185 |
static inline void SlWriteUint64(uint64 x) |
0 | 186 |
{ |
187 |
SlWriteUint32((uint32)(x >> 32)); |
|
188 |
SlWriteUint32((uint32)x); |
|
189 |
} |
|
190 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
191 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
192 |
* Read in the header descriptor of an object or an array. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
193 |
* If the highest bit is set (7), then the index is bigger than 127 |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
194 |
* elements, so use the next byte to read in the real value. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
195 |
* The actual value is then both bytes added with the first shifted |
1886 | 196 |
* 8 bits to the left, and dropping the highest bit (which only indicated a big index). |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
197 |
* x = ((x & 0x7F) << 8) + SlReadByte(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
198 |
* @return Return the value of the index |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
199 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
200 |
static uint SlReadSimpleGamma(void) |
0 | 201 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
202 |
uint i = SlReadByte(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
203 |
if (HASBIT(i, 7)) { |
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
204 |
i &= ~0x80; |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
205 |
if (HASBIT(i, 6)) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
206 |
i &= ~0x40; |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
207 |
if (HASBIT(i, 5)) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
208 |
i &= ~0x20; |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
209 |
if (HASBIT(i, 4)) |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
210 |
SlError("Unsupported gamma"); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
211 |
i = (i << 8) | SlReadByte(); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
212 |
} |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
213 |
i = (i << 8) | SlReadByte(); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
214 |
} |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
215 |
i = (i << 8) | SlReadByte(); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
216 |
} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
217 |
return i; |
0 | 218 |
} |
219 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
220 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
221 |
* Write the header descriptor of an object or an array. |
1886 | 222 |
* If the element is bigger than 127, use 2 bytes for saving |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
223 |
* and use the highest byte of the first written one as a notice |
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
224 |
* that the length consists of 2 bytes, etc.. like this: |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
225 |
* 0xxxxxxx |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
226 |
* 10xxxxxx xxxxxxxx |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
227 |
* 110xxxxx xxxxxxxx xxxxxxxx |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
228 |
* 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
229 |
* @param i Index being written |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
230 |
*/ |
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
231 |
|
0 | 232 |
static void SlWriteSimpleGamma(uint i) |
233 |
{ |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
234 |
if (i >= (1 << 7)) { |
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
235 |
if (i >= (1 << 14)) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
236 |
if (i >= (1 << 21)) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
237 |
assert(i < (1 << 28)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
238 |
SlWriteByte((byte)0xE0 | (i>>24)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
239 |
SlWriteByte((byte)(i>>16)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
240 |
} else { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
241 |
SlWriteByte((byte)0xC0 | (i>>16)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
242 |
} |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
243 |
SlWriteByte((byte)(i>>8)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
244 |
} else { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
245 |
SlWriteByte((byte)(0x80 | (i>>8))); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
246 |
} |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
247 |
} |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
248 |
SlWriteByte(i); |
0 | 249 |
} |
250 |
||
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
251 |
/** Return how many bytes used to encode a gamma value */ |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
252 |
static inline uint SlGetGammaLength(uint i) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
253 |
return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
254 |
} |
0 | 255 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
256 |
static inline int SlReadSparseIndex(void) {return SlReadSimpleGamma();} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
257 |
static inline void SlWriteSparseIndex(uint index) {SlWriteSimpleGamma(index);} |
0 | 258 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
259 |
static inline int SlReadArrayLength(void) {return SlReadSimpleGamma();} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
260 |
static inline void SlWriteArrayLength(uint length) {SlWriteSimpleGamma(length);} |
0 | 261 |
|
262 |
void SlSetArrayIndex(uint index) |
|
263 |
{ |
|
264 |
_sl.need_length = NL_WANTLENGTH; |
|
265 |
_sl.array_index = index; |
|
266 |
} |
|
267 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
268 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
269 |
* Iterate through the elements of an array and read the whole thing |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
270 |
* @return The index of the object, or -1 if we have reached the end of current block |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
271 |
*/ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
272 |
int SlIterateArray(void) |
0 | 273 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
274 |
int index; |
0 | 275 |
static uint32 next_offs; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
276 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
277 |
/* After reading in the whole array inside the loop |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
278 |
* we must have read in all the data, so we must be at end of current block. */ |
0 | 279 |
assert(next_offs == 0 || SlGetOffs() == next_offs); |
280 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
281 |
while (true) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
282 |
uint length = SlReadArrayLength(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
283 |
if (length == 0) { |
0 | 284 |
next_offs = 0; |
285 |
return -1; |
|
286 |
} |
|
287 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
288 |
_sl.obj_len = --length; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
289 |
next_offs = SlGetOffs() + length; |
0 | 290 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
291 |
switch (_sl.block_mode) { |
2026 | 292 |
case CH_SPARSE_ARRAY: index = SlReadSparseIndex(); break; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
293 |
case CH_ARRAY: index = _sl.array_index++; break; |
0 | 294 |
default: |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
295 |
DEBUG(misc, 0) ("SlIterateArray: error"); |
0 | 296 |
return -1; // error |
297 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
298 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
299 |
if (length != 0) return index; |
0 | 300 |
} |
301 |
} |
|
302 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
303 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
304 |
* Sets the length of either a RIFF object or the number of items in an array. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
305 |
* This lets us load an object or an array of arbitrary size |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
306 |
* @param length The length of the sought object/array |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
307 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
308 |
void SlSetLength(size_t length) |
0 | 309 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
310 |
switch (_sl.need_length) { |
0 | 311 |
case NL_WANTLENGTH: |
312 |
_sl.need_length = NL_NONE; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
313 |
switch (_sl.block_mode) { |
0 | 314 |
case CH_RIFF: |
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
315 |
// Ugly encoding of >16M RIFF chunks |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
316 |
// The lower 24 bits are normal |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
317 |
// The uppermost 4 bits are bits 24:27 |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
318 |
assert(length < (1<<28)); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
319 |
SlWriteUint32((length & 0xFFFFFF) | ((length >> 24) << 28)); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
320 |
break; |
0 | 321 |
case CH_ARRAY: |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
322 |
assert(_sl.last_array_index <= _sl.array_index); |
0 | 323 |
while (++_sl.last_array_index <= _sl.array_index) |
324 |
SlWriteArrayLength(1); |
|
325 |
SlWriteArrayLength(length + 1); |
|
326 |
break; |
|
327 |
case CH_SPARSE_ARRAY: |
|
328 |
SlWriteArrayLength(length + 1 + SlGetGammaLength(_sl.array_index)); // Also include length of sparse index. |
|
329 |
SlWriteSparseIndex(_sl.array_index); |
|
330 |
break; |
|
331 |
default: NOT_REACHED(); |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
332 |
} break; |
0 | 333 |
case NL_CALCLENGTH: |
334 |
_sl.obj_len += length; |
|
335 |
break; |
|
336 |
} |
|
337 |
} |
|
338 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
339 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
340 |
* Save/Load bytes. These do not need to be converted to Little/Big Endian |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
341 |
* so directly write them or read them to/from file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
342 |
* @param ptr The source or destination of the object being manipulated |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
343 |
* @param length number of bytes this fast CopyBytes lasts |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
344 |
*/ |
410 | 345 |
static void SlCopyBytes(void *ptr, size_t length) |
0 | 346 |
{ |
347 |
byte *p = (byte*)ptr; |
|
348 |
||
349 |
if (_sl.save) { |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
350 |
for (; length != 0; length--) {SlWriteByteInternal(*p++);} |
0 | 351 |
} else { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
352 |
for (; length != 0; length--) {*p++ = SlReadByteInternal();} |
0 | 353 |
} |
354 |
} |
|
355 |
||
1614
4ee38e74afd1
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1576
diff
changeset
|
356 |
#if 0 |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
357 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
358 |
* Read in bytes from the file/data structure but don't do |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
359 |
* anything with them |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
360 |
* NOTICE: currently unused |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
361 |
* @param length The amount of bytes that is being treated this way |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
362 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
363 |
static inline void SlSkipBytes(size_t length) |
0 | 364 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
365 |
for (; length != 0; length--) |
0 | 366 |
SlReadByte(); |
367 |
} |
|
1614
4ee38e74afd1
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1576
diff
changeset
|
368 |
#endif |
0 | 369 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
370 |
/* Get the length of the current object */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
371 |
uint SlGetFieldLength(void) {return _sl.obj_len;} |
0 | 372 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
373 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
374 |
* Handle all conversion and typechecking of variables here. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
375 |
* In the case of saving, read in the actual value from the struct |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
376 |
* and then write them to file, endian safely. Loading a value |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
377 |
* goes exactly the opposite way |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
378 |
* @param ptr The object being filled/read |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
379 |
* @param conv @VarType type of the current element of the struct |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
380 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
381 |
static void SlSaveLoadConv(void *ptr, VarType conv) |
0 | 382 |
{ |
383 |
int64 x = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
384 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
385 |
if (_sl.save) { /* SAVE values */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
386 |
/* Read a value from the struct. These ARE endian safe. */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
387 |
switch ((conv >> 4) & 0xF) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
388 |
case SLE_VAR_I8 >> 4: x = *(int8*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
389 |
case SLE_VAR_U8 >> 4: x = *(byte*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
390 |
case SLE_VAR_I16 >> 4: x = *(int16*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
391 |
case SLE_VAR_U16 >> 4: x = *(uint16*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
392 |
case SLE_VAR_I32 >> 4: x = *(int32*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
393 |
case SLE_VAR_U32 >> 4: x = *(uint32*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
394 |
case SLE_VAR_I64 >> 4: x = *(int64*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
395 |
case SLE_VAR_U64 >> 4: x = *(uint64*)ptr; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
396 |
case SLE_VAR_NULL >> 4: x = 0; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
397 |
default: NOT_REACHED(); |
0 | 398 |
} |
399 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
400 |
// Write the value to the file and check if its value is in the desired range |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
401 |
switch (conv & 0xF) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
402 |
case SLE_FILE_I8: assert(x >= -128 && x <= 127); SlWriteByte(x);break; |
2026 | 403 |
case SLE_FILE_U8: assert(x >= 0 && x <= 255); SlWriteByte(x);break; |
0 | 404 |
case SLE_FILE_I16:assert(x >= -32768 && x <= 32767); SlWriteUint16(x);break; |
405 |
case SLE_FILE_STRINGID: |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
406 |
case SLE_FILE_U16:assert(x >= 0 && x <= 65535); SlWriteUint16(x);break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
407 |
case SLE_FILE_I32: case SLE_FILE_U32: SlWriteUint32((uint32)x);break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
408 |
case SLE_FILE_I64: case SLE_FILE_U64: SlWriteUint64(x);break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
409 |
default: NOT_REACHED(); |
0 | 410 |
} |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
411 |
} else { /* LOAD values */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
412 |
|
0 | 413 |
// Read a value from the file |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
414 |
switch (conv & 0xF) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
415 |
case SLE_FILE_I8: x = (int8)SlReadByte(); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
416 |
case SLE_FILE_U8: x = (byte)SlReadByte(); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
417 |
case SLE_FILE_I16: x = (int16)SlReadUint16(); break; |
0 | 418 |
case SLE_FILE_U16: x = (uint16)SlReadUint16(); break; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
419 |
case SLE_FILE_I32: x = (int32)SlReadUint32(); break; |
0 | 420 |
case SLE_FILE_U32: x = (uint32)SlReadUint32(); break; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
421 |
case SLE_FILE_I64: x = (int64)SlReadUint64(); break; |
0 | 422 |
case SLE_FILE_U64: x = (uint64)SlReadUint64(); break; |
423 |
case SLE_FILE_STRINGID: x = RemapOldStringID((uint16)SlReadUint16()); break; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
424 |
default: NOT_REACHED(); |
0 | 425 |
} |
426 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
427 |
/* Write The value to the struct. These ARE endian safe. */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
428 |
switch ((conv >> 4) & 0xF) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
429 |
case SLE_VAR_I8 >> 4: *(int8*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
430 |
case SLE_VAR_U8 >> 4: *(byte*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
431 |
case SLE_VAR_I16 >> 4: *(int16*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
432 |
case SLE_VAR_U16 >> 4: *(uint16*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
433 |
case SLE_VAR_I32 >> 4: *(int32*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
434 |
case SLE_VAR_U32 >> 4: *(uint32*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
435 |
case SLE_VAR_I64 >> 4: *(int64*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
436 |
case SLE_VAR_U64 >> 4: *(uint64*)ptr = x; break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
437 |
case SLE_VAR_NULL >> 4: break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
438 |
default: NOT_REACHED(); |
0 | 439 |
} |
440 |
} |
|
441 |
} |
|
442 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
443 |
/* Length in bytes of the various datatypes in a savefile. These |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
444 |
* sizes are guaranteed by assert_compiles in stdafx.h */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
445 |
static const byte _conv_lengths[] = {1, 1, 2, 2, 4, 4, 8, 8, 2}; |
0 | 446 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
447 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
448 |
* Return the size in bytes of a certain type of normal/atomic variable |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
449 |
* @param var The variable the size is being asked of (NOTICE: unused) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
450 |
* @param conv @VarType type of variable that is used for calculating the size |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
451 |
* @return Return the size of this type in byes |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
452 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
453 |
static inline size_t SlCalcConvLen(const void *var, VarType conv) {return _conv_lengths[conv & 0xF];} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
454 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
455 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
456 |
* Return the size in bytes of a reference (pointer) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
457 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
458 |
static inline size_t SlCalcRefLen(void) {return 2;} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
459 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
460 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
461 |
* Return the size in bytes of a certain type of atomic array |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
462 |
* @param array The variable the size is being asked of (NOTICE: unused) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
463 |
* @param length The length of the array counted in elements |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
464 |
* @param conv @VarType type of the variable that is used in calculating the size |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
465 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
466 |
static inline size_t SlCalcArrayLen(const void *array, uint length, VarType conv) {return _conv_lengths[conv & 0xF] * length;} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
467 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
468 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
469 |
* Save/Load an array. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
470 |
* @param array The array being manipulated |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
471 |
* @param length The length of the array in elements |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
472 |
* @param conv @VarType type of the atomic array (int, byte, uint64, etc.) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
473 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
474 |
void SlArray(void *array, uint length, VarType conv) |
0 | 475 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
476 |
static const byte conv_mem_size[] = {1, 1, 2, 2, 4, 4, 8, 8, 0}; |
0 | 477 |
|
478 |
// Automatically calculate the length? |
|
479 |
if (_sl.need_length != NL_NONE) { |
|
480 |
SlSetLength(SlCalcArrayLen(array, length, conv)); |
|
481 |
// Determine length only? |
|
482 |
if (_sl.need_length == NL_CALCLENGTH) |
|
483 |
return; |
|
484 |
} |
|
485 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
486 |
/* NOTICE - handle some buggy stuff, in really old versions everything was saved |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
487 |
* as a byte-type. So detect this, and adjust array size accordingly */ |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
488 |
if (!_sl.save && _sl_version == 0) { |
0 | 489 |
if (conv == SLE_INT16 || conv == SLE_UINT16 || conv == SLE_STRINGID) { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
490 |
length *= 2; // int16, uint16 and StringID are 2 bytes in size |
0 | 491 |
conv = SLE_INT8; |
492 |
} else if (conv == SLE_INT32 || conv == SLE_UINT32) { |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
493 |
length *= 4; // int32 and uint32 are 4 bytes in size |
0 | 494 |
conv = SLE_INT8; |
495 |
} |
|
496 |
} |
|
497 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
498 |
/* If the size of elements is 1 byte, no special conversion is needed, |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
499 |
* use specialized copy-to-copy function to speed up things */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
500 |
if (conv == SLE_INT8 || conv == SLE_UINT8) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
501 |
SlCopyBytes(array, length); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
502 |
} else { |
0 | 503 |
byte *a = (byte*)array; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
504 |
for (; length != 0; length --) { |
0 | 505 |
SlSaveLoadConv(a, conv); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
506 |
a += conv_mem_size[(conv >> 4) & 0xF]; // get size |
0 | 507 |
} |
508 |
} |
|
509 |
} |
|
510 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
511 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
512 |
* Calculate the size of an object. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
513 |
* @param object Object that needs its length calculated |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
514 |
* @param sld The @SaveLoad description of the object so we know how to manipulate it |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
515 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
516 |
static size_t SlCalcObjLength(void *object, const SaveLoad *sld) |
0 | 517 |
{ |
518 |
size_t length = 0; |
|
519 |
||
520 |
// Need to determine the length and write a length tag. |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
521 |
for (; sld->cmd != SL_END; sld++) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
522 |
if (sld->cmd < SL_WRITEBYTE) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
523 |
if (HASBIT(sld->cmd, 2)) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
524 |
// check if the field is used in the current savegame version |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
525 |
if (_sl_version < sld->version_from || _sl_version > sld->version_to) |
0 | 526 |
continue; |
527 |
} |
|
528 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
529 |
switch (sld->cmd) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
530 |
case SL_VAR: case SL_CONDVAR: /* Normal Variable */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
531 |
length += SlCalcConvLen(NULL, sld->type); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
532 |
case SL_REF: case SL_CONDREF: /* Reference variable */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
533 |
length += SlCalcRefLen(); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
534 |
case SL_ARR: case SL_CONDARR: /* Array */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
535 |
length += SlCalcArrayLen(NULL, sld->length, sld->type); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
536 |
default: NOT_REACHED(); |
0 | 537 |
} |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
538 |
} else if (sld->cmd == SL_WRITEBYTE) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
539 |
length++; // a byte is logically of size 1 |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
540 |
} else if (sld->cmd == SL_INCLUDE) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
541 |
length += SlCalcObjLength(NULL, _sl.includes[sld->version_from]); |
2026 | 542 |
} else |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
543 |
assert(sld->cmd == SL_END); |
0 | 544 |
} |
545 |
return length; |
|
546 |
} |
|
547 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
548 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
549 |
* Main SaveLoad function. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
550 |
* @param object The object that is being saved or loaded |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
551 |
* @param sld The @SaveLoad description of the object so we know how to manipulate it |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
552 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
553 |
void SlObject(void *object, const SaveLoad *sld) |
0 | 554 |
{ |
555 |
// Automatically calculate the length? |
|
556 |
if (_sl.need_length != NL_NONE) { |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
557 |
SlSetLength(SlCalcObjLength(object, sld)); |
0 | 558 |
if (_sl.need_length == NL_CALCLENGTH) |
559 |
return; |
|
560 |
} |
|
561 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
562 |
for (; sld->cmd != SL_END; sld++) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
563 |
void *ptr = (byte*)object + sld->offset; |
0 | 564 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
565 |
if (sld->cmd < SL_WRITEBYTE) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
566 |
/* CONDITIONAL saveload types depend on the savegame version */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
567 |
if (HASBIT(sld->cmd, 2)) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
568 |
// check if the field is of the right version, if not, proceed to next one |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
569 |
if (_sl_version < sld->version_from || _sl_version > sld->version_to) |
0 | 570 |
continue; |
571 |
} |
|
572 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
573 |
switch (sld->cmd) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
574 |
case SL_VAR: case SL_CONDVAR: /* Normal variable */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
575 |
SlSaveLoadConv(ptr, sld->type); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
576 |
case SL_REF: case SL_CONDREF: /* Reference variable, translate */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
577 |
/// @todo XXX - another artificial limitof 65K elements of pointers? |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
578 |
if (_sl.save) { // XXX - read/write pointer as uint16? What is with higher indeces? |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
579 |
SlWriteUint16(_sl.ref_to_int_proc(*(void**)ptr, sld->type)); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
580 |
} else |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
581 |
*(void**)ptr = _sl.int_to_ref_proc(SlReadUint16(), sld->type); |
0 | 582 |
break; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
583 |
case SL_ARR: case SL_CONDARR: /* Array */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
584 |
SlArray(ptr, sld->length, sld->type); break; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
585 |
default: NOT_REACHED(); |
0 | 586 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
587 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
588 |
/* SL_WRITEBYTE translates a value of a variable to another one upon |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
589 |
* saving or loading. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
590 |
* XXX - variable renaming abuse |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
591 |
* g_value: the value of the variable ingame is abused by sld->version_from |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
592 |
* f_value: the value of the variable in the savegame is abused by sld->version_to */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
593 |
} else if (sld->cmd == SL_WRITEBYTE) { |
0 | 594 |
if (_sl.save) { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
595 |
SlWriteByte(sld->version_to); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
596 |
} else |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
597 |
*(byte*)ptr = sld->version_from; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
598 |
/* SL_INCLUDE loads common code for a type |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
599 |
* XXX - variable renaming abuse |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
600 |
* include_index: common code to include from _desc_includes[], abused by sld->version_from */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
601 |
} else if (sld->cmd == SL_INCLUDE) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
602 |
SlObject(ptr, _sl.includes[sld->version_from]); |
2026 | 603 |
} else |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
604 |
assert(sld->cmd == SL_END); |
0 | 605 |
} |
606 |
} |
|
607 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
608 |
/** Calculate the length of global variables |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
609 |
* @param desc The global variable that we want to know the size of |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
610 |
* @return Returns the length of the sought global object |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
611 |
*/ |
0 | 612 |
static size_t SlCalcGlobListLength(const SaveLoadGlobVarList *desc) |
613 |
{ |
|
614 |
size_t length = 0; |
|
615 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
616 |
for (; desc->address != NULL; desc++) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
617 |
// Of course the global variable must exist in the sought savegame version |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
618 |
if (_sl_version >= desc->from_version && _sl_version <= desc->to_version) |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
619 |
length += SlCalcConvLen(NULL, desc->conv); |
0 | 620 |
} |
621 |
return length; |
|
622 |
} |
|
623 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
624 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
625 |
* Save or Load (a list of) global variables |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
626 |
* @param desc The global variable that is being loaded or saved |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
627 |
*/ |
0 | 628 |
void SlGlobList(const SaveLoadGlobVarList *desc) |
629 |
{ |
|
630 |
if (_sl.need_length != NL_NONE) { |
|
631 |
SlSetLength(SlCalcGlobListLength(desc)); |
|
632 |
if (_sl.need_length == NL_CALCLENGTH) |
|
633 |
return; |
|
634 |
} |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
635 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
636 |
for (; desc->address != NULL; desc++) { |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
637 |
if (_sl_version >= desc->from_version && _sl_version <= desc->to_version) |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
638 |
SlSaveLoadConv(desc->address, desc->conv); |
0 | 639 |
} |
640 |
} |
|
641 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
642 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
643 |
* Do something of which I have no idea what it is :P |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
644 |
* @param proc The callback procedure that is called |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
645 |
* @param arg The variable that will be used for the callback procedure |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
646 |
*/ |
0 | 647 |
void SlAutolength(AutolengthProc *proc, void *arg) |
648 |
{ |
|
649 |
uint32 offs; |
|
650 |
||
651 |
assert(_sl.save); |
|
652 |
||
653 |
// Tell it to calculate the length |
|
654 |
_sl.need_length = NL_CALCLENGTH; |
|
655 |
_sl.obj_len = 0; |
|
656 |
proc(arg); |
|
657 |
||
658 |
// Setup length |
|
659 |
_sl.need_length = NL_WANTLENGTH; |
|
660 |
SlSetLength(_sl.obj_len); |
|
661 |
||
662 |
offs = SlGetOffs() + _sl.obj_len; |
|
663 |
||
664 |
// And write the stuff |
|
665 |
proc(arg); |
|
666 |
||
667 |
assert(offs == SlGetOffs()); |
|
668 |
} |
|
669 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
670 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
671 |
* Load a chunk of data (eg vehicles, stations, etc.) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
672 |
* @param ch The chunkhandler that will be used for the operation |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
673 |
*/ |
0 | 674 |
static void SlLoadChunk(const ChunkHandler *ch) |
675 |
{ |
|
676 |
byte m = SlReadByte(); |
|
677 |
size_t len; |
|
678 |
uint32 endoffs; |
|
679 |
||
680 |
_sl.block_mode = m; |
|
681 |
_sl.obj_len = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
682 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
683 |
switch (m) { |
0 | 684 |
case CH_ARRAY: |
685 |
_sl.array_index = 0; |
|
686 |
ch->load_proc(); |
|
687 |
break; |
|
688 |
case CH_SPARSE_ARRAY: |
|
689 |
ch->load_proc(); |
|
690 |
break; |
|
2041
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
691 |
default: |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
692 |
if ((m & 0xF) == CH_RIFF) { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
693 |
// Read length |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
694 |
len = (SlReadByte() << 16) | ((m >> 4) << 24); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
695 |
len += SlReadUint16(); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
696 |
_sl.obj_len = len; |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
697 |
endoffs = SlGetOffs() + len; |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
698 |
ch->load_proc(); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
699 |
assert(SlGetOffs() == endoffs); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
700 |
} else { |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
701 |
SlError("Invalid chunk type"); |
8b8899617403
(svn r2550) raise 32767 limit of gamma values, and 16MB limit of RIFF chunks in saveload code.
ludde
parents:
2026
diff
changeset
|
702 |
} |
0 | 703 |
break; |
704 |
} |
|
705 |
} |
|
706 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
707 |
/* Stub Chunk handlers to only calculate length and do nothing else */ |
0 | 708 |
static ChunkSaveLoadProc *_tmp_proc_1; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
709 |
static inline void SlStubSaveProc2(void *arg) {_tmp_proc_1();} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
710 |
static void SlStubSaveProc(void) {SlAutolength(SlStubSaveProc2, NULL);} |
0 | 711 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
712 |
/** Save a chunk of data (eg. vehicles, stations, etc.). Each chunk is |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
713 |
* prefixed by an ID identifying it, followed by data, and terminator where appropiate |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
714 |
* @param ch The chunkhandler that will be used for the operation |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
715 |
*/ |
0 | 716 |
static void SlSaveChunk(const ChunkHandler *ch) |
717 |
{ |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
718 |
ChunkSaveLoadProc *proc = ch->save_proc; |
0 | 719 |
|
720 |
SlWriteUint32(ch->id); |
|
721 |
||
722 |
if (ch->flags & CH_AUTO_LENGTH) { |
|
723 |
// Need to calculate the length. Solve that by calling SlAutoLength in the save_proc. |
|
724 |
_tmp_proc_1 = proc; |
|
725 |
proc = SlStubSaveProc; |
|
726 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
727 |
|
0 | 728 |
_sl.block_mode = ch->flags & CH_TYPE_MASK; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
729 |
switch (ch->flags & CH_TYPE_MASK) { |
0 | 730 |
case CH_RIFF: |
731 |
_sl.need_length = NL_WANTLENGTH; |
|
732 |
proc(); |
|
733 |
break; |
|
734 |
case CH_ARRAY: |
|
735 |
_sl.last_array_index = 0; |
|
736 |
SlWriteByte(CH_ARRAY); |
|
737 |
proc(); |
|
738 |
SlWriteArrayLength(0); // Terminate arrays |
|
739 |
break; |
|
740 |
case CH_SPARSE_ARRAY: |
|
741 |
SlWriteByte(CH_SPARSE_ARRAY); |
|
742 |
proc(); |
|
743 |
SlWriteArrayLength(0); // Terminate arrays |
|
744 |
break; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
745 |
default: NOT_REACHED(); |
0 | 746 |
} |
747 |
} |
|
748 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
749 |
/** Save all chunks */ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
750 |
static void SlSaveChunks(void) |
0 | 751 |
{ |
752 |
const ChunkHandler *ch; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
753 |
const ChunkHandler* const *chsc; |
0 | 754 |
uint p; |
755 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
756 |
for (p = 0; p != CH_NUM_PRI_LEVELS; p++) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
757 |
for (chsc = _sl.chs; (ch = *chsc++) != NULL;) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
758 |
while (true) { |
0 | 759 |
if (((ch->flags >> CH_PRI_SHL) & (CH_NUM_PRI_LEVELS - 1)) == p) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
760 |
SlSaveChunk(ch); |
0 | 761 |
if (ch->flags & CH_LAST) |
762 |
break; |
|
763 |
ch++; |
|
764 |
} |
|
765 |
} |
|
766 |
} |
|
767 |
||
768 |
// Terminator |
|
769 |
SlWriteUint32(0); |
|
770 |
} |
|
771 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
772 |
/** Find the ChunkHandler that will be used for processing the found |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
773 |
* chunk in the savegame or in memory |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
774 |
* @param id the chunk in question |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
775 |
* @return returns the appropiate chunkhandler |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
776 |
*/ |
0 | 777 |
static const ChunkHandler *SlFindChunkHandler(uint32 id) |
778 |
{ |
|
779 |
const ChunkHandler *ch; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
780 |
const ChunkHandler *const *chsc; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
781 |
for (chsc = _sl.chs; (ch=*chsc++) != NULL;) { |
0 | 782 |
while(true) { |
783 |
if (ch->id == id) |
|
784 |
return ch; |
|
785 |
if (ch->flags & CH_LAST) |
|
786 |
break; |
|
787 |
ch++; |
|
788 |
} |
|
789 |
} |
|
790 |
return NULL; |
|
791 |
} |
|
792 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
793 |
/** Load all chunks */ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
794 |
static void SlLoadChunks(void) |
0 | 795 |
{ |
796 |
uint32 id; |
|
797 |
const ChunkHandler *ch; |
|
798 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
799 |
for (id = SlReadUint32(); id != 0; id = SlReadUint32()) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
800 |
DEBUG(misc, 1) ("Loading chunk %c%c%c%c", id >> 24, id>>16, id>>8, id); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
801 |
|
0 | 802 |
ch = SlFindChunkHandler(id); |
803 |
if (ch == NULL) SlError("found unknown tag in savegame (sync error)"); |
|
804 |
SlLoadChunk(ch); |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
//******************************************* |
|
809 |
//********** START OF LZO CODE ************** |
|
810 |
//******************************************* |
|
811 |
#define LZO_SIZE 8192 |
|
812 |
||
781
9717ff353c17
(svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents:
762
diff
changeset
|
813 |
#include "minilzo.h" |
0 | 814 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
815 |
static uint ReadLZO(void) |
0 | 816 |
{ |
817 |
byte out[LZO_SIZE + LZO_SIZE / 64 + 16 + 3 + 8]; |
|
818 |
uint32 tmp[2]; |
|
819 |
uint32 size; |
|
820 |
uint len; |
|
821 |
||
822 |
// Read header |
|
823 |
if (fread(tmp, sizeof(tmp), 1, _sl.fh) != 1) SlError("file read failed"); |
|
824 |
||
825 |
// Check if size is bad |
|
826 |
((uint32*)out)[0] = size = tmp[1]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
827 |
|
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
828 |
if (_sl_version != 0) { |
0 | 829 |
tmp[0] = TO_BE32(tmp[0]); |
830 |
size = TO_BE32(size); |
|
831 |
} |
|
832 |
||
833 |
if (size >= sizeof(out)) SlError("inconsistent size"); |
|
834 |
||
835 |
// Read block |
|
836 |
if (fread(out + sizeof(uint32), size, 1, _sl.fh) != 1) SlError("file read failed"); |
|
837 |
||
838 |
// Verify checksum |
|
839 |
if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlError("bad checksum"); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
840 |
|
0 | 841 |
// Decompress |
842 |
lzo1x_decompress(out + sizeof(uint32)*1, size, _sl.buf, &len, NULL); |
|
843 |
return len; |
|
844 |
} |
|
845 |
||
846 |
// p contains the pointer to the buffer, len contains the pointer to the length. |
|
847 |
// len bytes will be written, p and l will be updated to reflect the next buffer. |
|
848 |
static void WriteLZO(uint size) |
|
849 |
{ |
|
850 |
byte out[LZO_SIZE + LZO_SIZE / 64 + 16 + 3 + 8]; |
|
851 |
byte wrkmem[sizeof(byte*)*4096]; |
|
852 |
uint outlen; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
853 |
|
0 | 854 |
lzo1x_1_compress(_sl.buf, size, out + sizeof(uint32)*2, &outlen, wrkmem); |
855 |
((uint32*)out)[1] = TO_BE32(outlen); |
|
856 |
((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out + sizeof(uint32), outlen + sizeof(uint32))); |
|
857 |
if (fwrite(out, outlen + sizeof(uint32)*2, 1, _sl.fh) != 1) SlError("file write failed"); |
|
858 |
} |
|
859 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
860 |
static bool InitLZO(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
861 |
{ |
0 | 862 |
_sl.bufsize = LZO_SIZE; |
863 |
_sl.buf = (byte*)malloc(LZO_SIZE); |
|
864 |
return true; |
|
865 |
} |
|
866 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
867 |
static void UninitLZO(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
868 |
{ |
0 | 869 |
free(_sl.buf); |
870 |
} |
|
871 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
872 |
//********************************************* |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
873 |
//******** START OF NOCOMP CODE (uncompressed)* |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
874 |
//********************************************* |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
875 |
static uint ReadNoComp(void) |
0 | 876 |
{ |
877 |
return fread(_sl.buf, 1, LZO_SIZE, _sl.fh); |
|
878 |
} |
|
879 |
||
880 |
static void WriteNoComp(uint size) |
|
881 |
{ |
|
882 |
fwrite(_sl.buf, 1, size, _sl.fh); |
|
883 |
} |
|
884 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
885 |
static bool InitNoComp(void) |
0 | 886 |
{ |
887 |
_sl.bufsize = LZO_SIZE; |
|
888 |
_sl.buf = (byte*)malloc(LZO_SIZE); |
|
889 |
return true; |
|
890 |
} |
|
891 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
892 |
static void UninitNoComp(void) |
0 | 893 |
{ |
894 |
free(_sl.buf); |
|
895 |
} |
|
896 |
||
897 |
//******************************************** |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
898 |
//********** START OF MEMORY CODE (in ram)**** |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
899 |
//******************************************** |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
900 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
901 |
enum { |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
902 |
SAVE_POOL_BLOCK_SIZE_BITS = 17, |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
903 |
SAVE_POOL_MAX_BLOCKS = 500 |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
904 |
}; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
905 |
|
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
906 |
#include "network.h" |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
907 |
#include "table/strings.h" |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
908 |
#include "table/sprites.h" |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
909 |
#include "gfx.h" |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
910 |
#include "gui.h" |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
911 |
|
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
912 |
typedef struct ThreadedSave { |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
913 |
MemoryPool *save; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
914 |
uint count; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
915 |
bool ff_state; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
916 |
bool saveinprogress; |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1913
diff
changeset
|
917 |
CursorID cursor; |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
918 |
} ThreadedSave; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
919 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
920 |
/* A maximum size of of 128K * 500 = 64.000KB savegames */ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
921 |
static MemoryPool _save_pool = {"Savegame", SAVE_POOL_MAX_BLOCKS, SAVE_POOL_BLOCK_SIZE_BITS, sizeof(byte), NULL, 0, 0, NULL}; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
922 |
static ThreadedSave _ts; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
923 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
924 |
static bool InitMem(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
925 |
{ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
926 |
_ts.save = &_save_pool; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
927 |
_ts.count = 0; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
928 |
|
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
929 |
CleanPool(_ts.save); |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
930 |
AddBlockToPool(_ts.save); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
931 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
932 |
/* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
933 |
_sl.bufsize = _ts.save->total_items; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
934 |
_sl.buf = (byte*)GetItemFromPool(_ts.save, _ts.count); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
935 |
return true; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
936 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
937 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
938 |
static void UnInitMem(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
939 |
{ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
940 |
CleanPool(_ts.save); |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
941 |
_ts.save = NULL; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
942 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
943 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
944 |
static void WriteMem(uint size) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
945 |
{ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
946 |
_ts.count += size; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
947 |
/* Allocate new block and new buffer-pointer */ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
948 |
AddBlockIfNeeded(_ts.save, _ts.count); |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
949 |
_sl.buf = (byte*)GetItemFromPool(_ts.save, _ts.count); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
950 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
951 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
952 |
//******************************************** |
0 | 953 |
//********** START OF ZLIB CODE ************** |
954 |
//******************************************** |
|
955 |
||
956 |
#if defined(WITH_ZLIB) |
|
2138
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
957 |
|
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
958 |
// This is needed to zlib uses the stdcall calling convention on visual studio |
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
959 |
#ifdef _MSC_VER |
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
960 |
#define ZLIB_WINAPI |
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
961 |
#endif |
20c2cf0fb452
(svn r2648) Only use _stdcall calling convention for zlib on win32/msvc.
ludde
parents:
2126
diff
changeset
|
962 |
|
0 | 963 |
#include <zlib.h> |
964 |
static z_stream _z; |
|
965 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
966 |
static bool InitReadZlib(void) |
0 | 967 |
{ |
968 |
memset(&_z, 0, sizeof(_z)); |
|
969 |
if (inflateInit(&_z) != Z_OK) return false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
970 |
|
0 | 971 |
_sl.bufsize = 4096; |
972 |
_sl.buf = (byte*)malloc(4096 + 4096); // also contains fread buffer |
|
973 |
return true; |
|
974 |
} |
|
975 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
976 |
static uint ReadZlib(void) |
0 | 977 |
{ |
978 |
int r; |
|
979 |
||
980 |
_z.next_out = _sl.buf; |
|
981 |
_z.avail_out = 4096; |
|
982 |
||
983 |
do { |
|
984 |
// read more bytes from the file? |
|
985 |
if (_z.avail_in == 0) { |
|
986 |
_z.avail_in = fread(_z.next_in = _sl.buf + 4096, 1, 4096, _sl.fh); |
|
987 |
} |
|
988 |
||
989 |
// inflate the data |
|
990 |
r = inflate(&_z, 0); |
|
991 |
if (r == Z_STREAM_END) |
|
992 |
break; |
|
993 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
994 |
if (r != Z_OK) |
0 | 995 |
SlError("inflate() failed"); |
996 |
} while (_z.avail_out); |
|
997 |
||
998 |
return 4096 - _z.avail_out; |
|
999 |
} |
|
1000 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
1001 |
static void UninitReadZlib(void) |
0 | 1002 |
{ |
1003 |
inflateEnd(&_z); |
|
1004 |
free(_sl.buf); |
|
1005 |
} |
|
1006 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
1007 |
static bool InitWriteZlib(void) |
0 | 1008 |
{ |
1009 |
memset(&_z, 0, sizeof(_z)); |
|
1010 |
if (deflateInit(&_z, 6) != Z_OK) return false; |
|
1011 |
||
1012 |
_sl.bufsize = 4096; |
|
1013 |
_sl.buf = (byte*)malloc(4096); // also contains fread buffer |
|
1014 |
return true; |
|
1015 |
} |
|
1016 |
||
1017 |
static void WriteZlibLoop(z_streamp z, byte *p, uint len, int mode) |
|
1018 |
{ |
|
1884
ae1d6213c6dd
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1881
diff
changeset
|
1019 |
byte buf[1024]; // output buffer |
0 | 1020 |
int r; |
1021 |
uint n; |
|
1022 |
z->next_in = p; |
|
1023 |
z->avail_in = len; |
|
1024 |
do { |
|
1025 |
z->next_out = buf; |
|
1026 |
z->avail_out = sizeof(buf); |
|
2026 | 1027 |
r = deflate(z, mode); |
0 | 1028 |
// bytes were emitted? |
1029 |
if ((n=sizeof(buf) - z->avail_out) != 0) { |
|
1030 |
if (fwrite(buf, n, 1, _sl.fh) != 1) SlError("file write error"); |
|
1031 |
} |
|
1032 |
if (r == Z_STREAM_END) |
|
1033 |
break; |
|
1034 |
if (r != Z_OK) SlError("zlib returned error code"); |
|
1035 |
} while (z->avail_in || !z->avail_out); |
|
1036 |
} |
|
1037 |
||
1038 |
static void WriteZlib(uint len) |
|
1039 |
{ |
|
1040 |
WriteZlibLoop(&_z, _sl.buf, len, 0); |
|
1041 |
} |
|
1042 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
1043 |
static void UninitWriteZlib(void) |
0 | 1044 |
{ |
1045 |
// flush any pending output. |
|
1046 |
if (_sl.fh) WriteZlibLoop(&_z, NULL, 0, Z_FINISH); |
|
1047 |
deflateEnd(&_z); |
|
1048 |
free(_sl.buf); |
|
1049 |
} |
|
1050 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1051 |
#endif /* WITH_ZLIB */ |
0 | 1052 |
|
1053 |
//******************************************* |
|
1054 |
//************* END OF CODE ***************** |
|
1055 |
//******************************************* |
|
1056 |
||
1057 |
// these define the chunks |
|
1058 |
extern const ChunkHandler _misc_chunk_handlers[]; |
|
1059 |
extern const ChunkHandler _player_chunk_handlers[]; |
|
1060 |
extern const ChunkHandler _veh_chunk_handlers[]; |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1537
diff
changeset
|
1061 |
extern const ChunkHandler _waypoint_chunk_handlers[]; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1062 |
extern const ChunkHandler _depot_chunk_handlers[]; |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
950
diff
changeset
|
1063 |
extern const ChunkHandler _order_chunk_handlers[]; |
0 | 1064 |
extern const ChunkHandler _town_chunk_handlers[]; |
1065 |
extern const ChunkHandler _sign_chunk_handlers[]; |
|
1066 |
extern const ChunkHandler _station_chunk_handlers[]; |
|
1067 |
extern const ChunkHandler _industry_chunk_handlers[]; |
|
1068 |
extern const ChunkHandler _engine_chunk_handlers[]; |
|
1069 |
extern const ChunkHandler _economy_chunk_handlers[]; |
|
1070 |
extern const ChunkHandler _animated_tile_chunk_handlers[]; |
|
1071 |
||
1072 |
static const ChunkHandler * const _chunk_handlers[] = { |
|
1073 |
_misc_chunk_handlers, |
|
1074 |
_veh_chunk_handlers, |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1537
diff
changeset
|
1075 |
_waypoint_chunk_handlers, |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1076 |
_depot_chunk_handlers, |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
950
diff
changeset
|
1077 |
_order_chunk_handlers, |
0 | 1078 |
_industry_chunk_handlers, |
1079 |
_economy_chunk_handlers, |
|
1080 |
_engine_chunk_handlers, |
|
1081 |
_town_chunk_handlers, |
|
1082 |
_sign_chunk_handlers, |
|
1083 |
_station_chunk_handlers, |
|
1084 |
_player_chunk_handlers, |
|
1085 |
_animated_tile_chunk_handlers, |
|
1086 |
NULL, |
|
1087 |
}; |
|
1088 |
||
1089 |
// used to include a vehicle desc in another desc. |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1090 |
extern const SaveLoad _common_veh_desc[]; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1091 |
static const SaveLoad* const _desc_includes[] = { |
0 | 1092 |
_common_veh_desc |
1093 |
}; |
|
1094 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1095 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1096 |
* Pointers cannot be saved to a savegame, so this functions gets |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1097 |
* the index of the item, and if not available, it hussles with |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1098 |
* pointers (looks really bad :() |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1099 |
* Remember that a NULL item has value 0, and all |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1100 |
* indeces have +1, so vehicle 0 is saved as index 1. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1101 |
* @param obj The object that we want to get the index of |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1102 |
* @param rt @SLRefType type of the object the index is being sought of |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1103 |
* @return Return the pointer converted to an index of the type pointed to |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1104 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1105 |
static uint ReferenceToInt(const void *obj, SLRefType rt) |
0 | 1106 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1107 |
if (obj == NULL) return 0; |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1108 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1109 |
switch (rt) { |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1110 |
case REF_VEHICLE_OLD: // Old vehicles we save as new onces |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1111 |
case REF_VEHICLE: return ((Vehicle *)obj)->index + 1; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1112 |
case REF_STATION: return ((Station *)obj)->index + 1; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1113 |
case REF_TOWN: return ((Town *)obj)->index + 1; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1114 |
case REF_ORDER: return ((Order *)obj)->index + 1; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1115 |
case REF_ROADSTOPS: return ((RoadStop *)obj)->index + 1; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1116 |
default: NOT_REACHED(); |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1117 |
} |
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1118 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1119 |
return 0; // avoid compiler warning |
0 | 1120 |
} |
1121 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1122 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1123 |
* Pointers cannot be loaded from a savegame, so this function |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1124 |
* gets the index from the savegame and returns the appropiate |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1125 |
* pointer from the already loaded base. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1126 |
* Remember that an index of 0 is a NULL pointer so all indeces |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1127 |
* are +1 so vehicle 0 is saved as 1. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1128 |
* @param index The index that is being converted to a pointer |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1129 |
* @param rt @SLRefType type of the object the pointer is sought of |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1130 |
* @return Return the index converted to a pointer of any type |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1131 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1132 |
static void *IntToReference(uint index, SLRefType rt) |
0 | 1133 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1134 |
/* After version 4.3 REF_VEHICLE_OLD is saved as REF_VEHICLE, |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1135 |
* and should be loaded like that */ |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1136 |
if (rt == REF_VEHICLE_OLD && _sl_full_version >= ((4 << 8) | 4)) |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1137 |
rt = REF_VEHICLE; |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1138 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1139 |
/* No need to look up NULL pointers, just return immediately */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1140 |
if (rt != REF_VEHICLE_OLD && index == 0) |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1141 |
return NULL; |
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1142 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1143 |
index--; // correct for the NULL index |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1144 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1145 |
switch (rt) { |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
1146 |
case REF_ORDER: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1147 |
if (!AddBlockIfNeeded(&_order_pool, index)) |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
1148 |
error("Orders: failed loading savegame: too many orders"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1149 |
return GetOrder(index); |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
1150 |
} |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
1151 |
case REF_VEHICLE: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1152 |
if (!AddBlockIfNeeded(&_vehicle_pool, index)) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
1153 |
error("Vehicles: failed loading savegame: too many vehicles"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1154 |
return GetVehicle(index); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
1155 |
} |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
1156 |
case REF_STATION: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1157 |
if (!AddBlockIfNeeded(&_station_pool, index)) |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
1158 |
error("Stations: failed loading savegame: too many stations"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1159 |
return GetStation(index); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
1160 |
} |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1218
diff
changeset
|
1161 |
case REF_TOWN: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1162 |
if (!AddBlockIfNeeded(&_town_pool, index)) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1218
diff
changeset
|
1163 |
error("Towns: failed loading savegame: too many towns"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1164 |
return GetTown(index); |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1218
diff
changeset
|
1165 |
} |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1282
diff
changeset
|
1166 |
case REF_ROADSTOPS: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1167 |
if (!AddBlockIfNeeded(&_roadstop_pool, index)) |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
1168 |
error("RoadStops: failed loading savegame: too many RoadStops"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1169 |
return GetRoadStop(index); |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1282
diff
changeset
|
1170 |
} |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1171 |
|
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1172 |
case REF_VEHICLE_OLD: { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1173 |
/* Old vehicles were saved differently: |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1174 |
* invalid vehicle was 0xFFFF, |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1175 |
* and the index was not - 1.. correct for this */ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1176 |
index++; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1177 |
if (index == INVALID_VEHICLE) |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1178 |
return NULL; |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
1179 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1180 |
if (!AddBlockIfNeeded(&_vehicle_pool, index)) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
1181 |
error("Vehicles: failed loading savegame: too many vehicles"); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1182 |
return GetVehicle(index); |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1183 |
} |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1184 |
default: NOT_REACHED(); |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1185 |
} |
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1186 |
|
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1187 |
return NULL; |
0 | 1188 |
} |
1189 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1190 |
/** The format for a reader/writer type of a savegame */ |
0 | 1191 |
typedef struct { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1192 |
const char *name; /// name of the compressor/decompressor (debug-only) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1193 |
uint32 tag; /// the 4-letter tag by which it is identified in the savegame |
0 | 1194 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1195 |
bool (*init_read)(void); /// function executed upon initalization of the loader |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1196 |
ReaderProc *reader; /// function that loads the data from the file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1197 |
void (*uninit_read)(void); /// function executed when reading is finished |
0 | 1198 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1199 |
bool (*init_write)(void); /// function executed upon intialization of the saver |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1200 |
WriterProc *writer; /// function that saves the data to the file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1201 |
void (*uninit_write)(void); /// function executed when writing is done |
0 | 1202 |
} SaveLoadFormat; |
1203 |
||
1204 |
static const SaveLoadFormat _saveload_formats[] = { |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1205 |
{"memory", 0, NULL, NULL, NULL, InitMem, WriteMem, UnInitMem}, |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1206 |
{"lzo", TO_BE32X('OTTD'), InitLZO, ReadLZO, UninitLZO, InitLZO, WriteLZO, UninitLZO}, |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1207 |
{"none", TO_BE32X('OTTN'), InitNoComp, ReadNoComp, UninitNoComp, InitNoComp, WriteNoComp, UninitNoComp}, |
0 | 1208 |
#if defined(WITH_ZLIB) |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1209 |
{"zlib", TO_BE32X('OTTZ'), InitReadZlib, ReadZlib, UninitReadZlib, InitWriteZlib, WriteZlib, UninitWriteZlib}, |
0 | 1210 |
#else |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1211 |
{"zlib", TO_BE32X('OTTZ'), NULL, NULL, NULL, NULL, NULL, NULL}, |
0 | 1212 |
#endif |
1213 |
}; |
|
1214 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1215 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1216 |
* Return the savegameformat of the game. Whether it was create with ZLIB compression |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1217 |
* uncompressed, or another type |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1218 |
* @param s Name of the savegame format. If NULL it picks the first available one |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1219 |
* @return Pointer to @SaveLoadFormat struct giving all characteristics of this type of savegame |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1220 |
*/ |
0 | 1221 |
static const SaveLoadFormat *GetSavegameFormat(const char *s) |
1222 |
{ |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1223 |
const SaveLoadFormat *def = endof(_saveload_formats) - 1; |
0 | 1224 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1225 |
// find default savegame format, the highest one with which files can be written |
0 | 1226 |
while (!def->init_write) def--; |
1227 |
||
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1228 |
if (s != NULL && s[0] != '\0') { |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1229 |
const SaveLoadFormat *slf; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1230 |
for (slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1231 |
if (slf->init_write != NULL && strcmp(s, slf->name) == 0) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1232 |
return slf; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1233 |
} |
0 | 1234 |
|
1235 |
ShowInfoF("Savegame format '%s' is not available. Reverting to '%s'.", s, def->name); |
|
1236 |
} |
|
1237 |
return def; |
|
1238 |
} |
|
1239 |
||
1240 |
// actual loader/saver function |
|
2051 | 1241 |
void InitializeGame(uint size_x, uint size_y); |
0 | 1242 |
extern bool AfterLoadGame(uint version); |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
1243 |
extern void BeforeSaveGame(void); |
0 | 1244 |
extern bool LoadOldSaveGame(const char *file); |
1245 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1246 |
/** Small helper function to close the to be loaded savegame an signal error */ |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2159
diff
changeset
|
1247 |
static inline SaveOrLoadResult AbortSaveLoad(void) |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1248 |
{ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1249 |
if (_sl.fh != NULL) fclose(_sl.fh); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1250 |
|
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1251 |
_sl.fh = NULL; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1252 |
return SL_ERROR; |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1253 |
} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1254 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1255 |
/** Update the gui accordingly when starting saving |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1256 |
* and set locks on saveload. Also turn off fast-forward cause with that |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1257 |
* saving takes Aaaaages */ |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1258 |
static inline void SaveFileStart(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1259 |
{ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1260 |
_ts.ff_state = _fast_forward; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1261 |
_fast_forward = false; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1262 |
if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ); |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1263 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1264 |
SendWindowMessage(WC_STATUS_BAR, 0, true, 0, 0); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1265 |
_ts.saveinprogress = true; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1266 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1267 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1268 |
/** Update the gui accordingly when saving is done and release locks |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1269 |
* on saveload */ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1270 |
static inline void SaveFileDone(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1271 |
{ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1272 |
_fast_forward = _ts.ff_state; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1273 |
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1274 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1275 |
SendWindowMessage(WC_STATUS_BAR, 0, false, 0, 0); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1276 |
_ts.saveinprogress = false; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1277 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1278 |
|
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1279 |
/** We have written the whole game into memory, _save_pool, now find |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1280 |
* and appropiate compressor and start writing to file. |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1281 |
*/ |
2286
acb76b379e72
(svn r2810) Threads may now return information when they terminate using a void*.
tron
parents:
2285
diff
changeset
|
1282 |
static void* SaveFileToDisk(void* arg) |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1283 |
{ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1284 |
const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1285 |
/* XXX - backup _sl.buf cause it is used internally by the writer |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1286 |
* and we update it for our own purposes */ |
2141
2566286df545
(svn r2651) - Fix: [ 1220776 ] Removes warning when compiling saveload.c on some GCC versions (glx). This only works as long as there is only 1 saving thread active, as is the case now.
Darkvater
parents:
2138
diff
changeset
|
1287 |
static byte *tmp = NULL; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1288 |
uint32 hdr[2]; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1289 |
|
2141
2566286df545
(svn r2651) - Fix: [ 1220776 ] Removes warning when compiling saveload.c on some GCC versions (glx). This only works as long as there is only 1 saving thread active, as is the case now.
Darkvater
parents:
2138
diff
changeset
|
1290 |
tmp = _sl.buf; |
2566286df545
(svn r2651) - Fix: [ 1220776 ] Removes warning when compiling saveload.c on some GCC versions (glx). This only works as long as there is only 1 saving thread active, as is the case now.
Darkvater
parents:
2138
diff
changeset
|
1291 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1292 |
/* XXX - Setup setjmp error handler if an error occurs anywhere deep during |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1293 |
* loading/saving execute a longjmp() and continue execution here */ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1294 |
if (setjmp(_sl.excpt)) { |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1295 |
AbortSaveLoad(); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1296 |
_sl.buf = tmp; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1297 |
_sl.excpt_uninit(); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1298 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1299 |
ShowInfoF("Save game failed: %s.", _sl.excpt_msg); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1300 |
ShowErrorMessage(STR_4007_GAME_SAVE_FAILED, STR_NULL, 0, 0); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1301 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1302 |
SaveFileDone(); |
2286
acb76b379e72
(svn r2810) Threads may now return information when they terminate using a void*.
tron
parents:
2285
diff
changeset
|
1303 |
return NULL; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1304 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1305 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1306 |
/* We have written our stuff to memory, now write it to file! */ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1307 |
hdr[0] = fmt->tag; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1308 |
hdr[1] = TO_BE32((SAVEGAME_MAJOR_VERSION << 16) + (SAVEGAME_MINOR_VERSION << 8)); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1309 |
if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError("file write failed"); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1310 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1311 |
if (!fmt->init_write()) SlError("cannot initialize compressor"); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1312 |
tmp = _sl.buf; // XXX - init_write can change _sl.buf, so update it |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1313 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1314 |
{ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1315 |
uint i; |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1316 |
uint count = 1 << _ts.save->block_size_bits; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1317 |
|
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1318 |
assert(_ts.count == _sl.offs_base); |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1319 |
for (i = 0; i != _ts.save->current_blocks - 1; i++) { |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1320 |
_sl.buf = _ts.save->blocks[i]; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1321 |
fmt->writer(count); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1322 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1323 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1324 |
/* The last block is (almost) always not fully filled, so only write away |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1325 |
* as much data as it is in there */ |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1326 |
_sl.buf = _ts.save->blocks[i]; |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1327 |
fmt->writer(_ts.count - (i * count)); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1328 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1329 |
_sl.buf = tmp; // XXX - reset _sl.buf to its original value to let it continue its internal usage |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1330 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1331 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1332 |
fmt->uninit_write(); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1333 |
assert(_ts.count == _sl.offs_base); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1334 |
GetSavegameFormat("memory")->uninit_write(); // clean the memorypool |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1335 |
fclose(_sl.fh); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1336 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1337 |
SaveFileDone(); |
2286
acb76b379e72
(svn r2810) Threads may now return information when they terminate using a void*.
tron
parents:
2285
diff
changeset
|
1338 |
return NULL; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1339 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1340 |
|
2285
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1341 |
|
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1342 |
static Thread* save_thread; |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1343 |
|
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1344 |
void WaitTillSaved(void) |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1345 |
{ |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1346 |
OTTDJoinThread(save_thread); |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1347 |
save_thread = NULL; |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1348 |
} |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1349 |
|
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1350 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1351 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1352 |
* Main Save or Load function where the high-level saveload functions are |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1353 |
* handled. It opens the savegame, selects format and checks versions |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1354 |
* @param filename The name of the savegame being created/loaded |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1355 |
* @param mode Save or load. Load can also be a TTD(Patch) game. Use SL_LOAD, SL_OLD_LOAD or SL_SAVE |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1356 |
* @return Return the results of the action. SL_OK, SL_ERROR or SL_REINIT ("unload" the game) |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1357 |
*/ |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2159
diff
changeset
|
1358 |
SaveOrLoadResult SaveOrLoad(const char *filename, int mode) |
0 | 1359 |
{ |
1360 |
uint32 hdr[2]; |
|
1361 |
const SaveLoadFormat *fmt; |
|
1362 |
uint version; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1363 |
|
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1364 |
/* An instance of saving is already active, so wait until it is done */ |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1365 |
if (_ts.saveinprogress) { |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1366 |
if (!_do_autosave) ShowErrorMessage(_error_message, STR_SAVE_STILL_IN_PROGRESS, 0, 0); |
2285
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1367 |
WaitTillSaved(); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1368 |
// nonsense to do an autosave while we were still saving our game, so skip it |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1369 |
if (_do_autosave) return SL_OK; |
2289
b0eb1b7f3eeb
(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
tron
parents:
2286
diff
changeset
|
1370 |
} else { |
b0eb1b7f3eeb
(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
tron
parents:
2286
diff
changeset
|
1371 |
WaitTillSaved(); |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1372 |
} |
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1373 |
|
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1374 |
/* Load a TTDLX or TTDPatch game */ |
0 | 1375 |
if (mode == SL_OLD_LOAD) { |
2051 | 1376 |
InitializeGame(256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused |
0 | 1377 |
if (!LoadOldSaveGame(filename)) return SL_REINIT; |
1378 |
AfterLoadGame(0); |
|
1379 |
return SL_OK; |
|
1380 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1381 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1382 |
_sl.fh = fopen(filename, (mode == SL_SAVE) ? "wb" : "rb"); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1383 |
if (_sl.fh == NULL) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1384 |
DEBUG(misc, 0) ("Cannot open savegame for saving/loading."); |
0 | 1385 |
return SL_ERROR; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1386 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1387 |
|
0 | 1388 |
_sl.bufe = _sl.bufp = NULL; |
1389 |
_sl.offs_base = 0; |
|
1390 |
_sl.int_to_ref_proc = IntToReference; |
|
1391 |
_sl.ref_to_int_proc = ReferenceToInt; |
|
1392 |
_sl.save = mode; |
|
1393 |
_sl.includes = _desc_includes; |
|
1394 |
_sl.chs = _chunk_handlers; |
|
1395 |
||
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1396 |
/* XXX - Setup setjmp error handler if an error occurs anywhere deep during |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1397 |
* loading/saving execute a longjmp() and continue execution here */ |
0 | 1398 |
if (setjmp(_sl.excpt)) { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1399 |
AbortSaveLoad(); |
0 | 1400 |
|
1401 |
// deinitialize compressor. |
|
1402 |
_sl.excpt_uninit(); |
|
1403 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1404 |
/* A saver/loader exception!! reinitialize all variables to prevent crash! */ |
0 | 1405 |
if (mode == SL_LOAD) { |
1406 |
ShowInfoF("Load game failed: %s.", _sl.excpt_msg); |
|
1407 |
return SL_REINIT; |
|
1408 |
} else { |
|
1409 |
ShowInfoF("Save game failed: %s.", _sl.excpt_msg); |
|
1410 |
return SL_ERROR; |
|
1411 |
} |
|
1412 |
} |
|
1413 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1414 |
/* We first initialize here to avoid: "warning: variable `version' might |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1415 |
* be clobbered by `longjmp' or `vfork'" */ |
0 | 1416 |
version = 0; |
1417 |
||
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1418 |
/* General tactic is to first save the game to memory, then use an available writer |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1419 |
* to write it to file, either in threaded mode if possible, or single-threaded */ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1420 |
if (mode == SL_SAVE) { /* SAVE game */ |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1421 |
fmt = GetSavegameFormat("memory"); // write to memory |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1422 |
|
0 | 1423 |
_sl.write_bytes = fmt->writer; |
1424 |
_sl.excpt_uninit = fmt->uninit_write; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1425 |
if (!fmt->init_write()) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1426 |
DEBUG(misc, 0) ("Initializing writer %s failed.", fmt->name); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1427 |
return AbortSaveLoad(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1428 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1429 |
|
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1430 |
_sl_version = SAVEGAME_MAJOR_VERSION; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1431 |
|
0 | 1432 |
BeforeSaveGame(); |
1433 |
SlSaveChunks(); |
|
1434 |
SlWriteFill(); // flush the save buffer |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1435 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1436 |
/* Write to file */ |
2289
b0eb1b7f3eeb
(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
tron
parents:
2286
diff
changeset
|
1437 |
SaveFileStart(); |
2285
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1438 |
if (_network_server || |
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2283
diff
changeset
|
1439 |
(save_thread = OTTDCreateThread(&SaveFileToDisk, NULL)) == NULL) { |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1440 |
DEBUG(misc, 1) ("cannot create savegame thread, reverting to single-threaded mode..."); |
2283
bbf48bc7afda
(svn r2807) Fix two major bugs in the threaded save code:
tron
parents:
2186
diff
changeset
|
1441 |
SaveFileToDisk(NULL); |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1442 |
} |
0 | 1443 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1444 |
} else { /* LOAD game */ |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1445 |
assert(mode == SL_LOAD); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1446 |
|
0 | 1447 |
if (fread(hdr, sizeof(hdr), 1, _sl.fh) != 1) { |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1448 |
DEBUG(misc, 0) ("Cannot read savegame header, aborting."); |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1449 |
return AbortSaveLoad(); |
0 | 1450 |
} |
1451 |
||
1452 |
// see if we have any loader for this type. |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1453 |
for (fmt = _saveload_formats; ; fmt++) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1454 |
/* No loader found, treat as version 0 and use LZO format */ |
0 | 1455 |
if (fmt == endof(_saveload_formats)) { |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1456 |
DEBUG(misc, 0) ("Unknown savegame type, trying to load it as the buggy format."); |
0 | 1457 |
rewind(_sl.fh); |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1458 |
_sl_version = version = 0; |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1459 |
_sl_full_version = 0; |
1913
57f516fa418c
(svn r2419) - Fix: saving no longer changes your cursor if it is in a non-mouse state.
Darkvater
parents:
1891
diff
changeset
|
1460 |
fmt = _saveload_formats + 1; // LZO |
0 | 1461 |
break; |
1462 |
} |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1463 |
|
0 | 1464 |
if (fmt->tag == hdr[0]) { |
1465 |
// check version number |
|
1466 |
version = TO_BE32(hdr[1]) >> 8; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
121
diff
changeset
|
1467 |
|
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1468 |
/* Is the version higher than the current? */ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1469 |
if (version > SAVEGAME_LOADABLE_VERSION) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1470 |
DEBUG(misc, 0) ("Savegame version invalid."); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1471 |
return AbortSaveLoad(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1472 |
} |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
929
diff
changeset
|
1473 |
|
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1474 |
_sl_version = (version >> 8); |
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
1475 |
_sl_full_version = version; |
0 | 1476 |
break; |
1477 |
} |
|
1478 |
} |
|
1479 |
||
1480 |
_sl.read_bytes = fmt->reader; |
|
1481 |
_sl.excpt_uninit = fmt->uninit_read; |
|
1482 |
||
1483 |
// loader for this savegame type is not implemented? |
|
1484 |
if (fmt->init_read == NULL) { |
|
1485 |
ShowInfoF("Loader for '%s' is not available.", fmt->name); |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1486 |
return AbortSaveLoad(); |
0 | 1487 |
} |
1488 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1489 |
if (!fmt->init_read()) { |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1490 |
DEBUG(misc, 0) ("Initializing loader %s failed.", fmt->name); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1491 |
return AbortSaveLoad(); |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1492 |
} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1493 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1494 |
/* Old maps were hardcoded to 256x256 and thus did not contain |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1495 |
* any mapsize information. Pre-initialize to 256x256 to not to |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1496 |
* confuse old games */ |
2051 | 1497 |
InitializeGame(256, 256); |
1218 | 1498 |
|
0 | 1499 |
SlLoadChunks(); |
1500 |
fmt->uninit_read(); |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1501 |
fclose(_sl.fh); |
0 | 1502 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1503 |
/* After loading fix up savegame for any internal changes that |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1504 |
* might've occured since then. If it fails, load back the old game */ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1505 |
if (!AfterLoadGame(version)) return SL_REINIT; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1884
diff
changeset
|
1506 |
} |
0 | 1507 |
|
1508 |
return SL_OK; |
|
1509 |
} |
|
1510 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1511 |
/** Do a save when exiting the game (patch option) _patches.autosave_on_exit */ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
1512 |
void DoExitSave(void) |
643
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
617
diff
changeset
|
1513 |
{ |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
617
diff
changeset
|
1514 |
char buf[200]; |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1515 |
snprintf(buf, sizeof(buf), "%s%sexit.sav", _path.autosave_dir, PATHSEP); |
643
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
617
diff
changeset
|
1516 |
SaveOrLoad(buf, SL_SAVE); |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
617
diff
changeset
|
1517 |
} |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
617
diff
changeset
|
1518 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1519 |
#if 0 |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1520 |
/** |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1521 |
* Function to get the type of the savegame by looking at the file header. |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1522 |
* NOTICE: Not used right now, but could be used if extensions of savegames are garbled |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1523 |
* @param file Savegame to be checked |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1524 |
* @return SL_OLD_LOAD or SL_LOAD of the file |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1525 |
*/ |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1526 |
int GetSavegameType(char *file) |
0 | 1527 |
{ |
1528 |
const SaveLoadFormat *fmt; |
|
1529 |
uint32 hdr; |
|
1530 |
FILE *f; |
|
1531 |
int mode = SL_OLD_LOAD; |
|
1532 |
||
1533 |
f = fopen(file, "rb"); |
|
1534 |
if (fread(&hdr, sizeof(hdr), 1, f) != 1) { |
|
1535 |
printf("Savegame is obsolete or invalid format.\n"); |
|
2026 | 1536 |
mode = SL_LOAD; // don't try to get filename, just show name as it is written |
0 | 1537 |
} |
1538 |
else { |
|
1539 |
// see if we have any loader for this type. |
|
1540 |
for (fmt = _saveload_formats; fmt != endof(_saveload_formats); fmt++) { |
|
1541 |
if (fmt->tag == hdr) { |
|
1542 |
mode = SL_LOAD; // new type of savegame |
|
1543 |
break; |
|
1544 |
} |
|
1545 |
} |
|
1546 |
} |
|
1547 |
||
1548 |
fclose(f); |
|
1549 |
return mode; |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1550 |
} |
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1614
diff
changeset
|
1551 |
#endif |