| AngelScript |

Loading...
Searching...
No Matches
grid template object

Path: /sdk/add_on/scriptgrid/

The `grid` type is a template object that allow the scripts to declare 2D grids of any type. In many ways it is similar to the array template object, but it is specialized for use with areas.

The type is registered with `RegisterScriptGrid(asIScriptEngine *engine)`.

# Public C++ interface

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 *gridType);
static CScriptGrid *Create(asITypeInfo *gridType, asUINT width, asUINT height);
static CScriptGrid *Create(asITypeInfo *gridType, asUINT width, asUINT height, void *defaultValue);
static CScriptGrid *Create(asITypeInfo *gridType, 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.
// The value arg should be a pointer to the value that will be copied to the 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);
};
asALLOCFUNC_t
void *(* asALLOCFUNC_t)(size_t)
The function signature for the custom memory allocation function.
Definition: angelscript.h:645
asUINT
unsigned int asUINT
32 bit unsigned integer
Definition: angelscript.h:610
asFREEFUNC_t
void(* asFREEFUNC_t)(void *)
The function signature for the custom memory deallocation function.
Definition: angelscript.h:647
asITypeInfo
The interface for describing types This interface is used to describe the types in the script engine.
Definition: angelscript.h:3704

# Public script interface

      class grid<T>
      {
        grid();
        grid(uint width, uint height);
        grid(uint width, uint height, const T &in fillValue);

        uint width() const;
        uint height() const;
        void resize(uint w, uint h);

        T &opIndex(uint x, uint y);
        const T &opIndex(uint x, uint y) const;
      }

grid()
grid(uint width, uint height)
grid(uint width, height, const T &in fillValue)

The constructors initializes the grid object. The default constructor will create an zero sized grid.

uint width() const
uint height() const

Returns the width and height of the grid.

void resize(uint w, uint h)

Resizes the grid to the new dimension. The elements that still fit in the grid will keep their values.

T &opIndex(uint x, uint y)
const T &opIndex(uint x, uint y) const

The index operator returns a reference to one of the elements. If the index is out of bounds a script exception will be raised.

# Example usage in script

      // Initialize a 5x5 map
      grid<int> map = {{1,0,1,1,1},
                       {0,0,1,0,0},
                       {0,1,1,0,1},
                       {0,1,1,0,1},
                       {0,0,0,0,1}};

      // A function to verify if the next area is walkable
      bool canWalk(uint x, uint y)
      {
        // If the map in the destination is
        // clear, it is possible to wark there
        return map[x,y] == 0;
      }