Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scriptgrid.h « scriptgrid « add_on « angelscript « Scripting « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: feeb167f692aca20e298c72c24e69bbaae3986c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef SCRIPTGRID_H
#define SCRIPTGRID_H

#ifndef ANGELSCRIPT_H 
// Avoid having to inform include path if header is already include before
#include <angelscript.h>
#endif

BEGIN_AS_NAMESPACE

struct SGridBuffer;

class CScriptGrid
{
public:
	// Set the memory functions that should be used by all CScriptGrids
	static void SetMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);

	// Factory functions
	static CScriptGrid *Create(asITypeInfo *ot);
	static CScriptGrid *Create(asITypeInfo *ot, asUINT width, asUINT height);
	static CScriptGrid *Create(asITypeInfo *ot, asUINT width, asUINT height, void *defaultValue);
	static CScriptGrid *Create(asITypeInfo *ot, void *listBuffer);

	// Memory management
	void AddRef() const;
	void Release() const;

	// Type information
	asITypeInfo *GetGridObjectType() const;
	int          GetGridTypeId() const;
	int          GetElementTypeId() const;

	// Size
	asUINT GetWidth() const;
	asUINT GetHeight() const;
	void   Resize(asUINT width, asUINT height);

	// Get a pointer to an element. Returns 0 if out of bounds
	void       *At(asUINT x, asUINT y);
	const void *At(asUINT x, asUINT y) const;

	// Set value of an element
	// Remember, if the grid holds handles the value parameter should be the 
	// address of the handle. The refCount of the object will also be incremented
	void  SetValue(asUINT x, asUINT y, void *value);

	// GC methods
	int  GetRefCount();
	void SetFlag();
	bool GetFlag();
	void EnumReferences(asIScriptEngine *engine);
	void ReleaseAllHandles(asIScriptEngine *engine);

protected:
	mutable int     refCount;
	mutable bool    gcFlag;
	asITypeInfo    *objType;
	SGridBuffer    *buffer;
	int             elementSize;
	int             subTypeId;

	// Constructors
	CScriptGrid(asITypeInfo *ot, void *initBuf); // Called from script when initialized with list
	CScriptGrid(asUINT w, asUINT h, asITypeInfo *ot);
	CScriptGrid(asUINT w, asUINT h, void *defVal, asITypeInfo *ot);
	virtual ~CScriptGrid();

	bool  CheckMaxSize(asUINT x, asUINT y);
	void  CreateBuffer(SGridBuffer **buf, asUINT w, asUINT h);
	void  DeleteBuffer(SGridBuffer *buf);
	void  Construct(SGridBuffer *buf);
	void  Destruct(SGridBuffer *buf);
	void  SetValue(SGridBuffer *buf, asUINT x, asUINT y, void *value);
	void *At(SGridBuffer *buf, asUINT x, asUINT y);
};

void RegisterScriptGrid(asIScriptEngine *engine);

END_AS_NAMESPACE

#endif