| 258 | } |
| 259 | |
| 260 | CScriptGrid::CScriptGrid(asITypeInfo *ti, void *buf) |
| 261 | { |
| 262 | refCount = 1; |
| 263 | gcFlag = false; |
| 264 | objType = ti; |
| 265 | objType->AddRef(); |
| 266 | buffer = 0; |
| 267 | subTypeId = objType->GetSubTypeId(); |
| 268 | |
| 269 | asIScriptEngine *engine = ti->GetEngine(); |
| 270 | |
| 271 | // Determine element size |
| 272 | if( subTypeId & asTYPEID_MASK_OBJECT ) |
| 273 | elementSize = sizeof(asPWORD); |
| 274 | else |
| 275 | elementSize = engine->GetSizeOfPrimitiveType(subTypeId); |
| 276 | |
| 277 | // Determine the initial size from the buffer |
| 278 | asUINT height = *(asUINT*)buf; |
| 279 | asUINT width = height ? *(asUINT*)((char*)(buf)+4) : 0; |
| 280 | |
| 281 | // Make sure the grid size isn't too large for us to handle |
| 282 | if( !CheckMaxSize(width, height) ) |
| 283 | { |
| 284 | // Don't continue with the initialization |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | // Skip the height value at the start of the buffer |
| 289 | buf = (asUINT*)(buf)+1; |
| 290 | |
| 291 | // Copy the values of the grid elements from the buffer |
| 292 | if( (ti->GetSubTypeId() & asTYPEID_MASK_OBJECT) == 0 ) |
| 293 | { |
| 294 | CreateBuffer(&buffer, width, height); |
| 295 | |
| 296 | // Copy the values of the primitive type into the internal buffer |
| 297 | for( asUINT y = 0; y < height; y++ ) |
| 298 | { |
| 299 | // Skip the length value at the start of each row |
| 300 | buf = (asUINT*)(buf)+1; |
| 301 | |
| 302 | // Copy the line |
| 303 | if( width > 0 ) |
| 304 | memcpy(At(0,y), buf, width*elementSize); |
| 305 | |
| 306 | // Move to next line |
| 307 | buf = (char*)(buf) + width*elementSize; |
| 308 | |
| 309 | // Align to 4 byte boundary |
| 310 | if( asPWORD(buf) & 0x3 ) |
| 311 | buf = (char*)(buf) + 4 - (asPWORD(buf) & 0x3); |
| 312 | } |
| 313 | } |
| 314 | else if( ti->GetSubTypeId() & asTYPEID_OBJHANDLE ) |
| 315 | { |
| 316 | CreateBuffer(&buffer, width, height); |
| 317 | |