| 30 |
30 |
| 31 // ============================================================================ |
31 // ============================================================================ |
| 32 // |
32 // |
| 33 DataBuffer::DataBuffer (int size) |
33 DataBuffer::DataBuffer (int size) |
| 34 { |
34 { |
| 35 SetBuffer (new byte[size]); |
35 SetBuffer (new char[size]); |
| 36 SetPosition (&GetBuffer()[0]); |
36 SetPosition (&GetBuffer()[0]); |
| 37 SetAllocatedSize (size); |
37 SetAllocatedSize (size); |
| 38 } |
38 } |
| 39 |
39 |
| 40 // ============================================================================ |
40 // ============================================================================ |
| 144 mark->pos += offset; |
144 mark->pos += offset; |
| 145 } |
145 } |
| 146 |
146 |
| 147 // ============================================================================ |
147 // ============================================================================ |
| 148 // |
148 // |
| 149 void DataBuffer::WriteFloat (float a) |
|
| 150 { |
|
| 151 // TODO: Find a way to store the number without decimal loss. |
|
| 152 WriteDWord (dhPushNumber); |
|
| 153 WriteDWord (abs (a)); |
|
| 154 |
|
| 155 if (a < 0) |
|
| 156 WriteDWord (dhUnaryMinus); |
|
| 157 } |
|
| 158 |
|
| 159 // ============================================================================ |
|
| 160 // |
|
| 161 void DataBuffer::WriteStringIndex (const String& a) |
149 void DataBuffer::WriteStringIndex (const String& a) |
| 162 { |
150 { |
| 163 WriteDWord (dhPushStringIndex); |
151 WriteDWord (DH_PushStringIndex); |
| 164 WriteDWord (GetStringTableIndex (a)); |
152 WriteDWord (GetStringTableIndex (a)); |
| 165 } |
153 } |
| 166 |
154 |
| 167 // ============================================================================ |
155 // ============================================================================ |
| 168 // |
156 // |
| 191 // for the stuff we're going to write, as well as a bit |
179 // for the stuff we're going to write, as well as a bit |
| 192 // of leeway so we don't have to resize immediately again. |
180 // of leeway so we don't have to resize immediately again. |
| 193 int newsize = GetAllocatedSize() + bytes + 512; |
181 int newsize = GetAllocatedSize() + bytes + 512; |
| 194 |
182 |
| 195 delete GetBuffer(); |
183 delete GetBuffer(); |
| 196 SetBuffer (new byte[newsize]); |
184 SetBuffer (new char[newsize]); |
| 197 SetAllocatedSize (newsize); |
185 SetAllocatedSize (newsize); |
| 198 |
186 |
| 199 // Now, copy the stuff back. |
187 // Now, copy the stuff back. |
| 200 memcpy (mBuffer, copy, GetAllocatedSize()); |
188 memcpy (mBuffer, copy, GetAllocatedSize()); |
| 201 SetPosition (GetBuffer() + writesize); |
189 SetPosition (GetBuffer() + writesize); |