Skip to content

Commit f3f90e6

Browse files
committed
Updated to fixed plugin API in 3.6.1.14
1 parent edbab02 commit f3f90e6

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

ags_spritevideo/AGSDataSource.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
AGSDataSource::~AGSDataSource()
77
{
8-
_is->Close();
8+
_is->Dispose();
99
}
1010

1111
int AGSDataSource::read(void* output, int nBytes)

ags_spritevideo/ImageHelper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool LoadImageData(const char *filename, std::vector<uint8_t> &data)
3939
data.resize(is->GetLength());
4040
size_t read_num = is->Read(&data[0], data.size());
4141
data.resize(read_num);
42-
is->Close();
42+
is->Dispose();
4343
return true;
4444
}
4545
}

ags_spritevideo/agsplugin.h

+54-24
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,21 @@ struct AGSGameInfo {
296296

297297
// File open modes
298298
// Opens existing file, fails otherwise
299-
#define AGSSTREAM_FILE_OPEN 0
299+
#define AGSSTREAM_FILE_OPEN 1
300300
// Opens existing file, creates one if it did not exist
301-
#define AGSSTREAM_FILE_CREATE 1
301+
#define AGSSTREAM_FILE_CREATE 2
302302
// Always creates a new file, completely overwrites any existing one
303-
#define AGSSTREAM_FILE_CREATEALWAYS 2
303+
#define AGSSTREAM_FILE_CREATEALWAYS 3
304304

305305
// Stream work modes
306306
// Read-only
307-
#define AGSSTREAM_MODE_READ 0x1
307+
#define AGSSTREAM_MODE_READ 0x01
308308
// 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
311311
#define AGSSTREAM_MODE_READWRITE (AGSSTREAM_MODE_READ | AGSSTREAM_MODE_WRITE)
312+
// Supports seeking
313+
#define AGSSTREAM_MODE_SEEK 0x04
312314

313315
// Stream seek origins
314316
// Seek from the beginning of a stream (towards positive offset)
@@ -320,31 +322,56 @@ struct AGSGameInfo {
320322

321323
class IAGSStream {
322324
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;
326330
// 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+
329346
// Reads number of bytes into the provided buffer
330347
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;
331352
// 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;
339358
// Seeks to offset from the origin defined by AGSSTREAM_SEEK_* constants:
340359
// * AGSSTREAM_SEEK_SET - seek from the beginning;
341360
// * AGSSTREAM_SEEK_CUR - seek from the current position;
342361
// * AGSSTREAM_SEEK_END - seek from the end (pass negative offset)
343362
// 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;
345364
// Flushes stream, forcing it to write any buffered data to the
346365
// 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;
348375

349376
protected:
350377
IAGSStream() = default;
@@ -616,11 +643,13 @@ class IAGSEngine {
616643
// Opens a data stream, resolving a script path.
617644
// File mode should contain one of the AGSSTREAM_FILE_* values,
618645
// 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.
621648
AGSIFUNC(IAGSStream*) OpenFileStream(const char *script_path, int file_mode, int work_mode);
622649
// Returns IAGSStream object identified by the given stream handle.
623650
// 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.
624653
// Returns null if handle is invalid.
625654
AGSIFUNC(IAGSStream*) GetFileStreamByHandle(int32 fhandle);
626655
};
@@ -665,8 +694,9 @@ DLLEXPORT void AGS_EngineShutdown (void);
665694
DLLEXPORT int AGS_EngineOnEvent (int, int);
666695
DLLEXPORT int AGS_EngineDebugHook(const char *, int, int);
667696
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 ();
670700

671701
#endif // THIS_IS_THE_PLUGIN
672702

0 commit comments

Comments
 (0)