ScummVM API documentation
cc_ags_dynamic_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// This is a collection of common implementations of the IScriptObject
25// interface. Intended to be used as parent classes for majority of the
26// script object managers.
27//
28// CCBasicObject: parent for managers that treat object contents as raw
29// byte buffer.
30//
31// AGSCCDynamicObject, extends CCBasicObject: parent for built-in dynamic
32// object managers; provides simpler serialization methods working with
33// streams instead of a raw memory buffer.
34//
35// AGSCCStaticObject, extends CCBasicObject: a formal stub, intended as
36// a parent for built-in static object managers.
37//
38//=============================================================================
39
40#ifndef AGS_ENGINE_AC_DYNOBJ_CCDYNAMIC_OBJECT_H
41#define AGS_ENGINE_AC_DYNOBJ_CCDYNAMIC_OBJECT_H
42
43#include "ags/engine/ac/dynobj/cc_script_object.h"
44
45namespace AGS3 {
46
47namespace AGS { namespace Shared { class Stream; } }
48
49// CCBasicObject: basic implementation of the script object interface,
50// intended to be used as a parent for object/manager classes that do not
51// require specific implementation.
52// * Dispose ignored, never deletes any data on its own;
53// * Serialization skipped, does not save or load anything;
54// * Provides default implementation for reading and writing data fields,
55// treats the contents of an object as a raw byte buffer.
57public:
58 virtual ~CCBasicObject() = default;
59
60 // Dispose the object
61 int Dispose(void * /*address*/, bool /*force*/) override;
62 // Serialize the object into BUFFER (which is BUFSIZE bytes)
63 // return number of bytes used
64 int Serialize(void * /*address*/, uint8_t * /*buffer*/, int /*bufsize*/) override;
65
66 //
67 // Legacy support for reading and writing object fields by their relative offset
68 //
69 void *GetFieldPtr(void *address, intptr_t offset) override;
70 void Read(void *address, intptr_t offset, uint8_t *dest, size_t size) override;
71 uint8_t ReadInt8(void *address, intptr_t offset) override;
72 int16_t ReadInt16(void *address, intptr_t offset) override;
73 int32_t ReadInt32(void *address, intptr_t offset) override;
74 float ReadFloat(void *address, intptr_t offset) override;
75 void Write(void *address, intptr_t offset, const uint8_t *src, size_t size) override;
76 void WriteInt8(void *address, intptr_t offset, uint8_t val) override;
77 void WriteInt16(void *address, intptr_t offset, int16_t val) override;
78 void WriteInt32(void *address, intptr_t offset, int32_t val) override;
79 void WriteFloat(void *address, intptr_t offset, float val) override;
80};
81
82
83// AGSCCDynamicObject: standard parent implementation for the built-in
84// script objects/manager.
85// * Serialization from a raw buffer; provides a virtual function that
86// accepts Stream, to be implemented in children instead.
87// * Provides Unserialize interface that accepts Stream.
89public:
90 virtual ~AGSCCDynamicObject() = default;
91
92 // TODO: pass savegame format version
93 int Serialize(void *address, uint8_t *buffer, int bufsize) override;
94 // Try unserializing the object from the given input stream
95 virtual void Unserialize(int index, AGS::Shared::Stream *in, size_t data_sz) = 0;
96
97protected:
98 // Savegame serialization
99 // Calculate and return required space for serialization, in bytes
100 virtual size_t CalcSerializeSize(const void *address) = 0;
101 // Write object data into the provided stream
102 virtual void Serialize(const void *address, AGS::Shared::Stream *out) = 0;
103};
104
105// CCStaticObject is a base class for managing static global objects in script.
106// The static objects can never be disposed, and do not support serialization
107// through IScriptObject interface.
109public:
110 virtual ~AGSCCStaticObject() = default;
111
112 const char *GetType() override { return "StaticObject"; }
113};
114
115} // namespace AGS3
116
117#endif
Definition: stream.h:52
Definition: cc_ags_dynamic_object.h:88
Definition: cc_ags_dynamic_object.h:108
Definition: cc_ags_dynamic_object.h:56
Definition: cc_script_object.h:60