ScummVM API documentation
script_user_object.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Managed object, which size and contents are defined by user script
25 //
26 //=============================================================================
27 
28 #ifndef AGS_ENGINE_DYNOBJ__SCRIPTUSERSTRUCT_H
29 #define AGS_ENGINE_DYNOBJ__SCRIPTUSERSTRUCT_H
30 
31 #include "ags/engine/ac/dynobj/cc_ags_dynamic_object.h"
32 
33 namespace AGS3 {
34 
36 public:
38 
39 protected:
40  virtual ~ScriptUserObject();
41 
42 public:
43  static ScriptUserObject *CreateManaged(size_t size);
44  void Create(const char *data, AGS::Shared::Stream *in, size_t size);
45 
46  // return the type name of the object
47  const char *GetType() override;
48  int Dispose(const char *address, bool force) override;
49  // serialize the object into BUFFER (which is BUFSIZE bytes)
50  // return number of bytes used
51  int Serialize(const char *address, char *buffer, int bufsize) override;
52  void Unserialize(int index, AGS::Shared::Stream *in, size_t data_sz);
53 
54  // Support for reading and writing object values by their relative offset
55  const char *GetFieldPtr(const char *address, intptr_t offset) override;
56  void Read(const char *address, intptr_t offset, void *dest, int size) override;
57  uint8_t ReadInt8(const char *address, intptr_t offset) override;
58  int16_t ReadInt16(const char *address, intptr_t offset) override;
59  int32_t ReadInt32(const char *address, intptr_t offset) override;
60  float ReadFloat(const char *address, intptr_t offset) override;
61  void Write(const char *address, intptr_t offset, void *src, int size) override;
62  void WriteInt8(const char *address, intptr_t offset, uint8_t val) override;
63  void WriteInt16(const char *address, intptr_t offset, int16_t val) override;
64  void WriteInt32(const char *address, intptr_t offset, int32_t val) override;
65  void WriteFloat(const char *address, intptr_t offset, float val) override;
66 
67 private:
68  // NOTE: we use signed int for Size at the moment, because the managed
69  // object interface's Serialize() function requires the object to return
70  // negative value of size in case the provided buffer was not large
71  // enough. Since this interface is also a part of Plugin API, we would
72  // need more significant change to program before we could use different
73  // approach.
74  int32_t _size;
75  char *_data;
76 };
77 
78 
79 // Helper functions for setting up custom managed structs based on ScriptUserObject.
80 namespace ScriptStructHelpers {
81 // Creates a managed Point object, represented as a pair of X and Y coordinates.
82 ScriptUserObject *CreatePoint(int x, int y);
83 } // namespace ScriptStructHelpers
84 
85 } // namespace AGS3
86 
87 #endif
Definition: cc_dynamic_object.h:51
Definition: stream.h:52
Definition: script_user_object.h:35
Definition: ags.h:40