/// <summary> /// Inserts a value at a certain position. The valid index is [0, num] /// </summary> public static void ccCArrayInsertValueAtIndex(ccCArray arr, int value, int index) { Debug.Assert(index < arr.max, "ccCArrayInsertValueAtIndex: invalid index"); int remaining = arr.num - index; // make sure it has enough capacity if (arr.num + 1 == arr.max) { ccCArrayDoubleCapacity(arr); } //int[] temp = new int[arr.arr.Length]; // last Value doesn't need to be moved if (remaining > 0) { // tex coordinates //Array.Copy(arr.arr, temp, arr.arr.Length); //Array.Copy(arr.arr, index, temp, index + 1, remaining); for (int i = arr.arr.Length - 1; i > index; i--) { arr.arr[i] = arr.arr[i - 1]; } } arr.num++; //temp[index] = value; arr.arr[index] = value;// temp; }
/// <summary> /// Removes value at specified index and pushes back all subsequent values. /// Behaviour undefined if index outside [0, num-1]. /// </summary> public static void ccCArrayRemoveValueAtIndex(ccCArray arr, int index) { for (int last = --arr.num; index < last; index++) { arr.arr[index] = arr.arr[index + 1]; } }
public static void ccCArrayDoubleCapacity(ccCArray arr) { ccCArray _ccCArray = arr; _ccCArray.max = _ccCArray.max * 2; int[] numArray = new int[arr.max]; Array.Copy(arr.arr, numArray, (int)arr.arr.Length); arr.arr = numArray; }
/// <summary> /// Doubles C array capacity /// </summary> public static void ccCArrayDoubleCapacity(ccCArray arr) { arr.max *= 2; int[] newArr = new int[arr.max]; Array.Copy(arr.arr, newArr, arr.arr.Length); // will fail when there's not enough memory Debug.Assert(newArr != null, "ccArrayDoubleCapacity failed. Not enough memory"); arr.arr = newArr; }
public void releaseMap() { if (this.m_pTiles != null) { this.m_pTiles = null; } if (this.m_pAtlasIndexArray != null) { this.m_pAtlasIndexArray = null; } }
/// <summary> /// initializes a CCTMXLayer with a tileset info, a layer info and a map info /// </summary> public bool initWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { // XXX: is 35% a good estimate ? CCSize size = layerInfo.m_tLayerSize; float totalNumberOfTiles = size.width * size.height; float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ? CCTexture2D texture = null; if (tilesetInfo != null) { texture = CCTextureCache.sharedTextureCache().addImage(tilesetInfo.m_sSourceImage); } if (base.initWithTexture(texture, (int)capacity)) { // layerInfo m_sLayerName = layerInfo.m_sName; m_tLayerSize = layerInfo.m_tLayerSize; m_pTiles = layerInfo.m_pTiles; m_uMinGID = layerInfo.m_uMinGID; m_uMaxGID = layerInfo.m_uMaxGID; m_cOpacity = layerInfo.m_cOpacity; m_pProperties = layerInfo.Properties; // m_pProperties = CCStringToStringDictionary::dictionaryWithDictionary(layerInfo->getProperties()); m_fContentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; // tilesetInfo m_pTileSet = tilesetInfo; //CC_SAFE_RETAIN(m_pTileSet); // mapInfo m_tMapTileSize = mapInfo.TileSize; m_uLayerOrientation = (CCTMXOrientatio)mapInfo.Orientation; // offset (after layer orientation is set); CCPoint offset = this.calculateLayerOffset(layerInfo.m_tOffset); this.position = offset; m_pAtlasIndexArray = ccCArray.ccCArrayNew((int)totalNumberOfTiles); this.contentSizeInPixels = new CCSize(m_tLayerSize.width * m_tMapTileSize.width, m_tLayerSize.height * m_tMapTileSize.height); m_tMapTileSize.width /= m_fContentScaleFactor; m_tMapTileSize.height /= m_fContentScaleFactor; m_bUseAutomaticVertexZ = false; m_nVertexZvalue = 0; m_fAlphaFuncValue = 0; return(true); } return(false); }
/// <summary> /// Allocates and initializes a new C array with specified capacity /// </summary> public static ccCArray ccCArrayNew(int capacity) { if (capacity == 0) { capacity = 1; } ccCArray arr = new ccCArray(); arr.num = 0; arr.arr = new int[capacity]; arr.max = capacity; return arr; }
public int[] arr; //equals CCObject** arr; /// <summary> /// Allocates and initializes a new C array with specified capacity /// </summary> public static ccCArray ccCArrayNew(int capacity) { if (capacity == 0) { capacity = 1; } ccCArray arr = new ccCArray(); arr.num = 0; arr.arr = new int[capacity]; arr.max = capacity; return(arr); }
public static void ccCArrayRemoveValueAtIndex(ccCArray arr, int index) { ccCArray _ccCArray = arr; int num = _ccCArray.num - 1; int num1 = num; _ccCArray.num = num; int num2 = num1; while (index < num2) { arr.arr[index] = arr.arr[index + 1]; index++; } }
public static ccCArray ccCArrayNew(int capacity) { if (capacity == 0) { capacity = 1; } ccCArray _ccCArray = new ccCArray() { num = 0, arr = new int[capacity], max = capacity }; return(_ccCArray); }
public static void ccCArrayInsertValueAtIndex(ccCArray arr, int value, int index) { int num = arr.num - index; if (arr.num + 1 == arr.max) { ccCArray.ccCArrayDoubleCapacity(arr); } if (num > 0) { for (int i = (int)arr.arr.Length - 1; i > index; i--) { arr.arr[i] = arr.arr[i - 1]; } } ccCArray _ccCArray = arr; _ccCArray.num = _ccCArray.num + 1; arr.arr[index] = value; }
public bool initWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCSize mTLayerSize = layerInfo.m_tLayerSize; float single = mTLayerSize.width * mTLayerSize.height; float single1 = single * 0.35f + 1f; CCTexture2D cCTexture2D = null; if (tilesetInfo != null) { cCTexture2D = CCTextureCache.sharedTextureCache().addImage(tilesetInfo.m_sSourceImage); } if (!base.initWithTexture(cCTexture2D, (int)single1)) { return(false); } this.m_sLayerName = layerInfo.m_sName; this.m_tLayerSize = layerInfo.m_tLayerSize; this.m_pTiles = layerInfo.m_pTiles; this.m_uMinGID = layerInfo.m_uMinGID; this.m_uMaxGID = layerInfo.m_uMaxGID; this.m_cOpacity = layerInfo.m_cOpacity; this.m_pProperties = layerInfo.Properties; this.m_fContentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; this.m_pTileSet = tilesetInfo; this.m_tMapTileSize = mapInfo.TileSize; this.m_uLayerOrientation = (CCTMXOrientatio)mapInfo.Orientation; this.position = this.calculateLayerOffset(layerInfo.m_tOffset); this.m_pAtlasIndexArray = ccCArray.ccCArrayNew((int)single); base.contentSizeInPixels = new CCSize(this.m_tLayerSize.width * this.m_tMapTileSize.width, this.m_tLayerSize.height * this.m_tMapTileSize.height); CCSize mTMapTileSize = this.m_tMapTileSize; mTMapTileSize.width = mTMapTileSize.width / this.m_fContentScaleFactor; CCSize mFContentScaleFactor = this.m_tMapTileSize; mFContentScaleFactor.height = mFContentScaleFactor.height / this.m_fContentScaleFactor; this.m_bUseAutomaticVertexZ = false; this.m_nVertexZvalue = 0; this.m_fAlphaFuncValue = 0f; return(true); }
/// <summary> /// initializes a CCTMXLayer with a tileset info, a layer info and a map info /// </summary> public bool initWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { // XXX: is 35% a good estimate ? CCSize size = layerInfo.m_tLayerSize; float totalNumberOfTiles = size.width * size.height; float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ? CCTexture2D texture = null; if (tilesetInfo != null) { texture = CCTextureCache.sharedTextureCache().addImage(tilesetInfo.m_sSourceImage); } if (base.initWithTexture(texture, (int)capacity)) { // layerInfo m_sLayerName = layerInfo.m_sName; m_tLayerSize = layerInfo.m_tLayerSize; m_pTiles = layerInfo.m_pTiles; m_uMinGID = layerInfo.m_uMinGID; m_uMaxGID = layerInfo.m_uMaxGID; m_cOpacity = layerInfo.m_cOpacity; m_pProperties = layerInfo.Properties; // m_pProperties = CCStringToStringDictionary::dictionaryWithDictionary(layerInfo->getProperties()); m_fContentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; // tilesetInfo m_pTileSet = tilesetInfo; //CC_SAFE_RETAIN(m_pTileSet); // mapInfo m_tMapTileSize = mapInfo.TileSize; m_uLayerOrientation = (CCTMXOrientatio)mapInfo.Orientation; // offset (after layer orientation is set); CCPoint offset = this.calculateLayerOffset(layerInfo.m_tOffset); this.position = offset; m_pAtlasIndexArray = ccCArray.ccCArrayNew((int)totalNumberOfTiles); this.contentSizeInPixels = new CCSize(m_tLayerSize.width * m_tMapTileSize.width, m_tLayerSize.height * m_tMapTileSize.height); m_tMapTileSize.width /= m_fContentScaleFactor; m_tMapTileSize.height /= m_fContentScaleFactor; m_bUseAutomaticVertexZ = false; m_nVertexZvalue = 0; m_fAlphaFuncValue = 0; return true; } return false; }
/// <summary> /// dealloc the map that contains the tile position from memory. /// Unless you want to know at runtime the tiles positions, you can safely call this method. /// If you are going to call layer->tileGIDAt() then, don't release the map /// </summary> public void releaseMap() { if (m_pTiles != null) { m_pTiles = null; } if (m_pAtlasIndexArray != null) { m_pAtlasIndexArray = null; } }