@@ -296,19 +296,21 @@ struct AGSGameInfo {
296
296
297
297
// File open modes
298
298
// Opens existing file, fails otherwise
299
- #define AGSSTREAM_FILE_OPEN 0
299
+ #define AGSSTREAM_FILE_OPEN 1
300
300
// Opens existing file, creates one if it did not exist
301
- #define AGSSTREAM_FILE_CREATE 1
301
+ #define AGSSTREAM_FILE_CREATE 2
302
302
// Always creates a new file, completely overwrites any existing one
303
- #define AGSSTREAM_FILE_CREATEALWAYS 2
303
+ #define AGSSTREAM_FILE_CREATEALWAYS 3
304
304
305
305
// Stream work modes
306
306
// Read-only
307
- #define AGSSTREAM_MODE_READ 0x1
307
+ #define AGSSTREAM_MODE_READ 0x01
308
308
// Write-only
309
- #define AGSSTREAM_MODE_WRITE 0x2
310
- // Support both read and write
309
+ #define AGSSTREAM_MODE_WRITE 0x02
310
+ // Supports both read and write
311
311
#define AGSSTREAM_MODE_READWRITE (AGSSTREAM_MODE_READ | AGSSTREAM_MODE_WRITE)
312
+ // Supports seeking
313
+ #define AGSSTREAM_MODE_SEEK 0x04
312
314
313
315
// Stream seek origins
314
316
// Seek from the beginning of a stream (towards positive offset)
@@ -320,31 +322,56 @@ struct AGSGameInfo {
320
322
321
323
class IAGSStream {
322
324
public:
323
- // Flushes and closes the stream, deallocates the stream object.
324
- // After calling this the IAGSStream pointer becomes INVALID.
325
- virtual void Close () = 0;
325
+ // Tells which mode the stream is working in, which defines
326
+ // supported io operations, such as reading, writing, seeking, etc.
327
+ // Returns combination of AGSSTREAM_MODE_* flags.
328
+ // Invalid or non-functional streams return 0.
329
+ virtual int GetMode () const = 0;
326
330
// Returns an optional stream's source description.
327
- // This may be a file path, or a resource name, or anything of that kind.
328
- virtual const char *GetPath () = 0;
331
+ // This may be a file path, or a resource name, or anything of that kind,
332
+ // and is purely for diagnostic purposes.
333
+ virtual const char *GetPath () const = 0;
334
+ // Tells whether this stream's position is at its end;
335
+ // note that unlike standard C feof this does not wait for a read attempt
336
+ // past the stream end, and reports positive when position = length.
337
+ virtual bool EOS () const = 0;
338
+ // Tells if there were errors during previous io operation(s);
339
+ // the call to GetError() *resets* the error record.
340
+ virtual bool GetError () const = 0;
341
+ // Returns the total stream's length in bytes
342
+ virtual int64_t GetLength () const = 0;
343
+ // Returns stream's position
344
+ virtual int64_t GetPosition () const = 0;
345
+
329
346
// Reads number of bytes into the provided buffer
330
347
virtual size_t Read (void *buffer, size_t len) = 0;
348
+ // ReadByte conforms to standard C fgetc behavior:
349
+ // - on success returns an *unsigned char* packed in the int32
350
+ // - on failure (EOS or other error), returns -1
351
+ virtual int32_t ReadByte () = 0;
331
352
// Writes number of bytes from the provided buffer
332
- virtual size_t Write (void *buffer, size_t len) = 0;
333
- // Returns the total stream's length in bytes
334
- virtual int64_t GetLength () = 0;
335
- // Returns stream's position
336
- virtual int64_t GetPosition () = 0;
337
- // Tells whether the stream's position is at its end
338
- virtual bool EOS () = 0;
353
+ virtual size_t Write (const void *buffer, size_t len) = 0;
354
+ // WriteByte conforms to standard C fputc behavior:
355
+ // - on success, returns the written unsigned char packed in the int32
356
+ // - on failure, returns -1
357
+ virtual int32_t WriteByte (uint8_t b) = 0;
339
358
// Seeks to offset from the origin defined by AGSSTREAM_SEEK_* constants:
340
359
// * AGSSTREAM_SEEK_SET - seek from the beginning;
341
360
// * AGSSTREAM_SEEK_CUR - seek from the current position;
342
361
// * AGSSTREAM_SEEK_END - seek from the end (pass negative offset)
343
362
// Returns new position in stream, or -1 on error.
344
- virtual int64_t Seek (int64_t offset, int origin) = 0;
363
+ virtual bool Seek (int64_t offset, int origin) = 0;
345
364
// Flushes stream, forcing it to write any buffered data to the
346
365
// underlying device. Note that the effect may depend on implementation.
347
- virtual void Flush () = 0;
366
+ virtual bool Flush () = 0;
367
+ // Flushes and closes the stream.
368
+ // Usually you do not have to call this, use Dispose() to close
369
+ // and delete stream object instead.
370
+ virtual void Close () = 0;
371
+
372
+ // Closes the stream and deallocates the stream object.
373
+ // After calling this the IAGSStream pointer becomes INVALID.
374
+ virtual void Dispose () = 0;
348
375
349
376
protected:
350
377
IAGSStream () = default ;
@@ -616,11 +643,13 @@ class IAGSEngine {
616
643
// Opens a data stream, resolving a script path.
617
644
// File mode should contain one of the AGSSTREAM_FILE_* values,
618
645
// work mode should contain flag set of the AGSSTREAM_MODE_* values.
619
- // Returns IAGSStream object, or null on failure.
620
- // IAGSStream must be disposed by calling its Close () function .
646
+ // Returns IAGSStream object, or null on failure. The returned stream object
647
+ // is owned by the caller, and must be deleted by calling its Dispose () method .
621
648
AGSIFUNC (IAGSStream*) OpenFileStream(const char *script_path, int file_mode, int work_mode);
622
649
// Returns IAGSStream object identified by the given stream handle.
623
650
// This lets to retrieve IAGSStream object from a handle received in a event callback.
651
+ // *IMPORTANT*: The returned stream's ownership is NOT passed to the caller;
652
+ // this stream should not be closed or disposed, doing so will lead to errors in the engine.
624
653
// Returns null if handle is invalid.
625
654
AGSIFUNC (IAGSStream*) GetFileStreamByHandle(int32 fhandle);
626
655
};
@@ -665,8 +694,9 @@ DLLEXPORT void AGS_EngineShutdown (void);
665
694
DLLEXPORT int AGS_EngineOnEvent (int , int );
666
695
DLLEXPORT int AGS_EngineDebugHook (const char *, int , int );
667
696
DLLEXPORT void AGS_EngineInitGfx (const char * driverID, void *data);
668
- // We export this to verify that we are an AGS Plugin
669
- DLLEXPORT int AGS_PluginV2 ();
697
+ // Export this to let engine verify that this is a compatible AGS Plugin;
698
+ // exact return value is not essential, but should be non-zero for consistency.
699
+ DLLEXPORT int AGS_PluginV2 ();
670
700
671
701
#endif // THIS_IS_THE_PLUGIN
672
702
0 commit comments