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