public int getWidth(string whatchars) { int totalwidth = 0; IntObject intObject = null; int currentChar = 0; for (int i = 0; i < whatchars.Length; i++) { currentChar = whatchars[i]; if (currentChar < 256) { intObject = charArray[currentChar]; } else { intObject = customChars[(char)currentChar]; } if (intObject != null) { totalwidth += intObject.width; } } return(totalwidth); }
public int GetWidth(string s) { int totalWidth = 0; IntObject intObject = null; int currentChar = 0; char[] charList = s.ToCharArray(); for (int i = 0; i < charList.Length; i++) { currentChar = charList[i]; if (currentChar < totalCharSet) { intObject = charArray[currentChar]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, currentChar); } if (intObject != null) { totalWidth += intObject.width; } } return(totalWidth); }
private static void fillBuffer(IntObject testMask, IntObject mask, IntObject buffer, sbyte[] @in, IntObject nextIn) { // if necessary, fill up in buffer and shift mask if (testMask.Value >= 0 && testMask.Value <= 0x00FFFFFF) { buffer.Value = (buffer.Value << 8) + u8(@in[nextIn.incr()]); mask.Value = testMask.Value << 8; } }
public void TestCopyIntProperty() { IntObject source = new IntObject { Property = 3 }; IntObject target = new IntObject(); target.SetFrom(source); Assert.AreEqual(3, target.Property); }
public void TestRead() { CborOptions options = new CborOptions(); options.Registry.ObjectMappingConventionRegistry.RegisterProvider(new LowerCaseObjectMappingConventionProvider()); const string hexBuffer = "A168696E7476616C75650C"; // {"intvalue": 12} IntObject intObject = Helper.Read <IntObject>(hexBuffer, options); Assert.NotNull(intObject); Assert.Equal(12, intObject.IntValue); }
public void TestIntObjectSerialization(int value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); IntObject intObject = new IntObject(12345); byte[] bytes = patternBuffer.Energize(intObject); Assert.AreEqual(6, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is IntObject); Assert.AreEqual(intObject.IntValue, ((IntObject)o).IntValue); Assert.IsFalse(intObject == o); }
public void SameValueTest(int v) { var var1 = new IntObject(v); Assert.IsTrue(var1 == new IntObject(v)); Assert.IsFalse(var1 == new IntObject(v + 1)); Assert.AreEqual(var1, new IntObject(v)); IntObject nullObj = null !; Assert.IsFalse(var1 == nullObj); Assert.IsTrue(var1 != nullObj); }
public SAWItemInfo GetFileInfo(string file, int ver) { SAWItemInfo ItemInfo = new SAWItemInfo(); LongObject version = new LongObject(); DateTime time = new DateTime(); LongObject size = new LongObject(); StringObject comment = new StringObject(); StringObject error = new StringObject(); file = SAWCommon.ConvertPath(file); if (0 != sdkObject.GetFileGeneralInfo(strRepositoryName, file, version, ref time, size, comment, error)) { string errorIfFolder = "File \"" + file + "\" not found."; if (errorIfFolder == error.GetValue()) { IntObject iobjSubFoldersNotDeletedCount = new IntObject(); IntObject iobjSubFoldersDeletedCount = new IntObject(); IntObject iobjFileNotDeletedCount = new IntObject(); IntObject iobjFilesDeletedCount = new IntObject(); List <SDKDeletedItemGeneralInfo> listDeletedItemGeneralInfo = new List <SDKDeletedItemGeneralInfo>(); IntObject iobjRight = new IntObject(); if (0 == sdkObject.GetFolderGeneralInfo(strRepositoryName, file, iobjSubFoldersNotDeletedCount, iobjSubFoldersDeletedCount, iobjFileNotDeletedCount, iobjFilesDeletedCount, version, ref time, comment, ref listDeletedItemGeneralInfo, iobjRight, error)) { ItemInfo.comment = comment.GetValue(); ItemInfo.name = file; ItemInfo.size = 0; ItemInfo.version = (int)version.GetValue(); ItemInfo.date = time; ItemInfo.isdir = true; ItemInfo.type = EnumActionType.Enum_ActionTypeNull; ItemInfo.user = ""; return(ItemInfo); } } return(null); } else { ItemInfo.comment = comment.GetValue(); ItemInfo.name = file; ItemInfo.size = (int)size.GetValue(); ItemInfo.version = (int)version.GetValue(); ItemInfo.date = time; ItemInfo.isdir = false; ItemInfo.type = EnumActionType.Enum_ActionTypeNull; ItemInfo.user = ""; return(ItemInfo); } }
public void ReadWithNamingPolicy() { JsonSerializerOptions options = new JsonSerializerOptions(); options.SetupExtensions(); options.GetObjectMappingRegistry().Register <IntObject>(objectMapping => objectMapping .AutoMap() .SetPropertyNamingPolicy(JsonNamingPolicy.CamelCase) ); const string json = @"{""intValue"":12}"; IntObject obj = Helper.Read <IntObject>(json, options); Assert.NotNull(obj); Assert.Equal(12, obj.IntValue); }
private static int getNumber(int nBits, sbyte[] buf, int bufPtr, int inc, BoolObject flag, IntObject mask, IntObject buffer, sbyte[] @in, IntObject nextIn) { // Extract and return a number (consisting of n_bits bits) from in stream IntObject number = new IntObject(1); if (nBits >= 3) { nextBit(buf, bufPtr + 3 * inc, number, mask, mask, buffer, @in, nextIn); if (nBits >= 4) { nextBit(buf, bufPtr + 3 * inc, number, mask, mask, buffer, @in, nextIn); if (nBits >= 5) { fillBuffer(mask, mask, buffer, @in, nextIn); for (; nBits >= 5; nBits--) { number.Value = number.Value << 1; mask.Value = (int)((uint)mask.Value >> 1); if (u32(buffer.Value) < u32(mask.Value)) { number.incr(); } else { buffer.sub(mask.Value); } } } } } flag.Value = nextBit(buf, bufPtr, number, mask, mask, buffer, @in, nextIn); if (nBits >= 1) { nextBit(buf, bufPtr + inc, number, mask, mask, buffer, @in, nextIn); if (nBits >= 2) { nextBit(buf, bufPtr + 2 * inc, number, mask, mask, buffer, @in, nextIn); } } return(number.Value); }
public void WriteWithNamingPolicy() { JsonSerializerOptions options = new JsonSerializerOptions(); options.SetupExtensions(); options.GetObjectMappingRegistry().Register <IntObject>(objectMapping => objectMapping .AutoMap() .SetPropertyNamingPolicy(JsonNamingPolicy.CamelCase) ); IntObject obj = new IntObject { IntValue = 12 }; const string json = @"{""intValue"":12}"; Helper.TestWrite(obj, json, options); }
void DrawIntExit() { //Exit GUILayout.BeginVertical("Box"); { GUILayout.BeginHorizontal(); { GUILayout.Label("Exit"); GUI.color = Color.green; if (GUILayout.Button("Add", GUILayout.Width(100))) { IntObject intObj = new IntObject(); ambBase.intObjectsExit.Add(intObj); } GUI.color = Color.white; } GUILayout.EndHorizontal(); GUILayout.BeginVertical("Box"); for (int i = 0; i < ambBase.intObjectsExit.Count; i++) { GUILayout.BeginHorizontal(); { GUILayout.Label("Name:"); ambBase.intObjectsExit[i].intName = GUILayout.TextField(ambBase.intObjectsExit[i].intName, 25); ambBase.intObjectsExit[i].value = EditorGUILayout.IntField(ambBase.intObjectsExit[i].value); GUI.color = Color.cyan; if (GUILayout.Button("Delete", GUILayout.Width(50))) { ambBase.intObjectsExit.RemoveAt(i); } GUI.color = Color.white; } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndVertical(); }
public bool Login(string strName, string Password, string rep) { this.strUserName = strName; this.strPassword = Password; this.strRepositoryName = rep; BoolObject bTrial = new BoolObject(); IntObject nTrial = new IntObject(); IntObject nPasswordLeft = new IntObject(); StringObject error = new StringObject(); if (0 != sdkObject.ConnectToServer(strServerIP, nServerPort, false, strName, Password, 0, "", 0, "", "", bTrial, nTrial, nPasswordLeft, error)) { this.bLogin = false; return(false); } else { this.bLogin = true; return(true); } }
public void AddChar(char c, float x, float y, LColor color) { this.charCurrent = c; if (charCurrent < totalCharSet) { intObject = charArray[charCurrent]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, (char)charCurrent); } if (intObject != null) { if (color != null) { SetImageColor(color); } if (antiAlias) { fontBatch.Draw(colors, x, y, intObject.width * fontScale, intObject.height * fontScale, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } else { fontBatch.Draw(colors, x, y, intObject.width, intObject.height, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } if (colors != null) { colors = null; } } }
private static bool nextBit(sbyte[] buf, int bufPtr1, IntObject number, IntObject testMask, IntObject mask, IntObject buffer, sbyte[] @in, IntObject nextIn) { fillBuffer(testMask, mask, buffer, @in, nextIn); int value = ((int)((uint)mask.Value >> 8)) * u8(buf[bufPtr1]); if (testMask != mask) { testMask.Value = value; } buf[bufPtr1] -= (sbyte)(u8(buf[bufPtr1]) >> 3); number.Value = number.Value << 1; if (u32(buffer.Value) < u32(value)) { mask.Value = value; buf[bufPtr1] += 31; number.incr(); return(true); } buffer.sub(value); mask.sub(value); return(false); }
protected bool Equals(IntObject other) { return(IntValue == other.IntValue); }
public static int decompress(sbyte[] @out, int outCapacity, sbyte[] @in) { int type = @in[0]; IntObject buffer = new IntObject((u8(@in[1]) << 24) | (u8(@in[2]) << 16) | (u8(@in[3]) << 8) | u8(@in[4])); IntObject nextIn = new IntObject(5); int nextOut = 0; int outEnd = outCapacity; if (type < 0) { // copy from stream without decompression int seqEnd = nextOut + buffer.Value; if (seqEnd > outEnd) { return(-1); } while (nextOut < seqEnd) { @out[nextOut++] = @in[nextIn.incr()]; } return(nextOut); } // Create and inti buffer sbyte[] buf = new sbyte[2800]; Arrays.Fill(buf, unchecked ((sbyte)0x80)); int bufOff = 0; IntObject mask = new IntObject(unchecked ((int)0xFFFFFFFF)); IntObject testMask = new IntObject(0); int lastChar = 0; while (true) { int bufPtr1 = bufOff + 2488; if (!nextBit(buf, bufPtr1, IntObject.Null, mask, mask, buffer, @in, nextIn)) { // Single new char if (bufOff > 0) { bufOff--; } if (nextOut == outEnd) { return(-1); } bufPtr1 = (((((nextOut & 0x07) << 8) + lastChar) >> type) & 0x07) * 0xFF - 0x01; IntObject j = new IntObject(1); while (j.Value <= 0xFF) { nextBit(buf, bufPtr1 + j.Value, j, mask, mask, buffer, @in, nextIn); } @out[nextOut++] = (sbyte)j.Value; } else { // Sequence of chars that exists in out stream // Find number of bits of sequence Length testMask.Value = mask.Value; int nBits = -1; BoolObject flag = new BoolObject(); do { bufPtr1 += 8; flag.Value = nextBit(buf, bufPtr1, IntObject.Null, testMask, mask, buffer, @in, nextIn); if (flag.Value) { nBits++; } } while (flag.Value && nBits < 6); // Find sequence Length int bufPtr2 = nBits + 2033; int j = 64; int seqLen; if (flag.Value || nBits >= 0) { bufPtr1 = (nBits << 5) + (((nextOut << nBits) & 0x03) << 3) + bufOff + 2552; seqLen = getNumber(nBits, buf, bufPtr1, 8, flag, mask, buffer, @in, nextIn); if (seqLen == 0xFF) { return(nextOut); // End of data stream } if (flag.Value || nBits > 0) { bufPtr2 += 56; j = 352; } } else { seqLen = 1; } // Find number of bits of sequence offset IntObject i = new IntObject(1); do { nBits = (i.Value << 4) - j; flag.Value = nextBit(buf, bufPtr2 + (i.Value << 3), i, mask, mask, buffer, @in, nextIn); } while (nBits < 0); // Find sequence offset int seqOff; if (flag.Value || nBits > 0) { if (!flag.Value) { nBits -= 8; } seqOff = getNumber(nBits / 8, buf, nBits + 2344, 1, flag, mask, buffer, @in, nextIn); } else { seqOff = 1; } // Copy sequence int nextSeq = nextOut - seqOff; if (nextSeq < 0) { return(-1); } int seqEnd = nextOut + seqLen + 1; if (seqEnd > outEnd) { return(-1); } bufOff = ((seqEnd + 1) & 0x01) + 0x06; do { @out[nextOut++] = @out[nextSeq++]; } while (nextOut < seqEnd); } lastChar = u8(@out[nextOut - 1]); } }
private void createSet( char[] customCharsArray ) { // If there are custom chars then I expand the font texture twice if (customCharsArray != null && customCharsArray.Length > 0) { textureWidth *= 2; } // In any case this should be done in other way. Texture with size 512x512 // can maintain only 256 characters with resolution of 32x32. The texture // size should be calculated dynamicaly by looking at character sizes. try { Bitmap imgTemp = new Bitmap(textureWidth, textureHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(imgTemp); //g.FillRectangle(new SolidBrush(Color.Yellow), 0, 0, textureWidth, textureHeight); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = ( customCharsArray != null ) ? customCharsArray.Length : 0; for (int i = 0; i < 256 + customCharsLength; i++) { // get 0-255 characters and then custom characters char ch = ( i < 256 ) ? (char) i : customCharsArray[i-256]; Bitmap fontImage = getFontImage(ch); IntObject newIntObject = new IntObject(); newIntObject.width = fontImage.Width; newIntObject.height = fontImage.Height; if (positionX + newIntObject.width >= textureWidth) { positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } // Draw it here g.DrawImage(fontImage, positionX, positionY); positionX += newIntObject.width; if( i < 256 ) { // standard characters charArray[i] = newIntObject; } else { // custom characters customChars[ch] = newIntObject; } fontImage = null; } fontTextureID = loadImage(imgTemp); } catch (Exception e) { Console.WriteLine("Failed to create font."); Console.WriteLine(e.StackTrace); } }
public void drawString(float x, float y, string whatchars, int startIndex, int endIndex, float scaleX, float scaleY, int format ) { IntObject intObject = null; int charCurrent; int totalwidth = 0; int i = startIndex, d = 1, c = correctL; float startY = 0; switch (format) { case ALIGN_RIGHT: d = -1; c = correctR; while (i < endIndex) { if (whatchars[i] == '\n') { startY += fontHeight; } i++; } break; case ALIGN_CENTER: for (int l = startIndex; l <= endIndex; l++) { charCurrent = whatchars[l]; if (charCurrent == '\n') { break; } if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars[(char)charCurrent]; } totalwidth += intObject.width - correctL; } totalwidth /= -2; break; case ALIGN_LEFT: default: d = 1; c = correctL; break; } GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, fontTextureID); GL.Translate(new Vector3(0, 5, 0)); GL.Rotate(180, new Vector3(0, 0, 1)); GL.Begin(BeginMode.Quads); while (i >= startIndex && i <= endIndex) { charCurrent = whatchars[i]; if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars[(char)charCurrent]; } if (intObject != null) { if (d < 0) { totalwidth += (intObject.width - c) * d; } if (charCurrent == '\n') { startY += fontHeight * d; totalwidth = 0; if (format == ALIGN_CENTER) { for (int l = i + 1; l <= endIndex; l++) { charCurrent = whatchars[l]; if (charCurrent == '\n') { break; } if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars[(char)charCurrent]; } totalwidth += intObject.width - correctL; } totalwidth /= -2; } //if center get next lines total width/2; } else { drawQuad((totalwidth + intObject.width) * scaleX + x, startY * scaleY + y, totalwidth * scaleX + x, (startY + intObject.height) * scaleY + y, intObject.storedX + intObject.width, intObject.storedY, intObject.storedX, intObject.storedY + intObject.height); if (d > 0) { totalwidth += (intObject.width - c) * d; } } i += d; } } GL.End(); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Blend); }
private void DrawString(float x, float y, float sx, float sy, float ax, float ay, float rotation, string chars, LColor c, int startIndex, int endIndex) { if (displays.Count > LSystem.DEFAULT_MAX_CACHE_SIZE) { lock (displays) { foreach (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache cache in displays.Values) { if (cache != null) { cache.Dispose(); } } } displays.Clear(); } this.intObject = null; this.charCurrent = 0; this.totalWidth = 0; if (rotation != 0 && (ax == 0 && ay == 0)) { ax = font.StringWidth(chars) / 2; ay = font.GetHeight(); } if (useCache) { display = (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache)CollectionUtils.Get(displays, chars); if (display == null) { fontBatch.GLBegin(); char[] charList = chars.ToCharArray(); for (int i = 0; i < charList.Length; i++) { charCurrent = charList[i]; if (charCurrent < totalCharSet) { intObject = charArray[charCurrent]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, (char)charCurrent); } if (intObject != null) { if ((i >= startIndex) || (i <= endIndex)) { if (antiAlias) { fontBatch.DrawQuad(totalWidth * fontScale, 0, (totalWidth + intObject.width) * fontScale, (intObject.height * fontScale), intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } else { fontBatch.DrawQuad(totalWidth, 0, (totalWidth + intObject.width), intObject.height, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } } totalWidth += intObject.width; } } fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation); CollectionUtils.Put(displays, chars, display = fontBatch.NewGLCache()); } else if (display != null && fontBatch != null && fontBatch.GetTexture() != null) { LTextureBatch.CommitQuad(fontBatch.GetTexture(), display, c, x, y, sx, sy, ax, ay, rotation); } } else { fontBatch.GLBegin(); char[] charList = chars.ToCharArray(); for (int i = 0; i < charList.Length; i++) { charCurrent = charList[i]; if (charCurrent < totalCharSet) { intObject = charArray[charCurrent]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, (char)charCurrent); } if (intObject != null) { if ((i >= startIndex) || (i <= endIndex)) { if (antiAlias) { fontBatch.DrawQuad(totalWidth * fontScale, 0, (totalWidth + intObject.width) * fontScale, (intObject.height * fontScale), intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } else { fontBatch.DrawQuad(totalWidth, 0, (totalWidth + intObject.width), intObject.height, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } } totalWidth += intObject.width; } } fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation); } }
private void Make(LFont font, char[] customCharsArray) { if (charArray == null) { charArray = new IntObject[totalCharSet]; } if (customCharsArray != null && customCharsArray.Length > totalCharSet) { textureWidth *= 2; } try { LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true); LGraphics g = imgTemp.GetLGraphics(); g.SetFont(font); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0; StringBuilder sbr = new StringBuilder(totalCharSet); for (int i = 0; i < totalCharSet + customCharsLength; i++) { char ch = (i < totalCharSet) ? (char)i : customCharsArray[i - totalCharSet]; int charwidth = font.CharWidth(ch); if (charwidth <= 0) { charwidth = 1; } int charheight = font.GetHeight(); if (charheight <= 0) { charheight = font.GetSize(); } IntObject newIntObject = new IntObject(); newIntObject.width = charwidth; newIntObject.height = charheight; if (positionX + newIntObject.width >= textureWidth) { g.DrawString(sbr.ToString(), 0, positionY); sbr.Clear(); positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } sbr.Append(ch); positionX += newIntObject.width; if (i < totalCharSet) { charArray[i] = newIntObject; } else { CollectionUtils.Put(customChars, ch, newIntObject); } } if (sbr.Length > 0) { g.DrawString(sbr.ToString(), 0, positionY); sbr = null; } g.Dispose(); g = null; fontBatch = new LTextureBatch(imgTemp.GetTexture()); } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } }
static void Main(string[] args) { Stopwatch watch = new Stopwatch(); int UPPER = 1000000; int[] int_arr = Enumerable.Range(1, UPPER).ToArray(); List <int> int_list = Enumerable.Range(1, UPPER).ToList(); Int32[] int32_arr = Enumerable.Range(1, UPPER).ToArray(); Int64[] int64_arr = new Int64[UPPER]; IntObject[] intobject_arr = new IntObject[UPPER]; List <IntObject> intobject_list = new List <IntObject>(); string[] string_arr = new string[UPPER]; List <string> string_list = new List <string>(); // Initializing some of the above for (int i = 0; i < UPPER; i++) { int64_arr[i] = (Int64)i; string_arr[i] = i.ToString(); string_list.Add(i.ToString()); intobject_arr[i] = new IntObject(i); intobject_list.Add(new IntObject(i)); } Console.WriteLine("Iterations: {0}{1}", UPPER, Environment.NewLine); Console.WriteLine("\n\rArrays:\t----------------------------------------------"); watch.Start(); int temp_int; for (int i = 0; i < UPPER; i++) { temp_int = int_arr[i]; } watch.Stop(); Console.WriteLine("Type: Int\tStructure: Array\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); Int32 temp_int32; for (int i = 0; i < UPPER; i++) { temp_int32 = int32_arr[i]; } watch.Stop(); Console.WriteLine("Type: Int32\tStructure: Array\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); Int64 temp_int64; for (int i = 0; i < UPPER; i++) { temp_int64 = int64_arr[i]; } watch.Stop(); Console.WriteLine("Type: Int64\tStructure: Array\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); string s; for (int i = 0; i < UPPER; i++) { s = string_arr[i]; } watch.Stop(); Console.WriteLine("Type: string\tStructure: Array\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); for (int i = 0; i < UPPER; i++) { temp_int = intobject_arr[i].IntValue; } watch.Stop(); Console.WriteLine("Type: IntObject\tStructure: Array\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); Console.WriteLine("\n\rLists:\t----------------------------------------------"); watch.Reset(); watch.Start(); foreach (var val in int_list) { temp_int = val; } watch.Stop(); Console.WriteLine("Type: Int\tStructure: List\t\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); foreach (var val in string_list) { s = val; } watch.Stop(); Console.WriteLine("Type: string\tStructure: List\t\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); foreach (var val in intobject_list) { temp_int = val.IntValue; } watch.Stop(); Console.WriteLine("Type: IntObject\tStructure: List\t\tticks: {0}\tMiliSeconds:{1}", watch.ElapsedTicks, watch.ElapsedMilliseconds); Console.WriteLine(); Console.WriteLine("Hit any key to exit."); Console.ReadKey(); }
protected override float CalculateSort(IntObject obj) { return(obj.Value); }
public int GetWidth(string s) { int totalWidth = 0; IntObject intObject = null; int currentChar = 0; char[] charList = s.ToCharArray(); for (int i = 0; i < charList.Length; i++) { currentChar = charList[i]; if (currentChar < totalCharSet) { intObject = charArray[currentChar]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, currentChar); } if (intObject != null) totalWidth += intObject.width; } return totalWidth; }
private void Make(LFont font, char[] customCharsArray) { if (charArray == null) { charArray = new IntObject[totalCharSet]; } if (customCharsArray != null && customCharsArray.Length > totalCharSet) { textureWidth *= 2; } try { LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true); LGraphics g = imgTemp.GetLGraphics(); g.SetFont(font); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0; StringBuilder sbr = new StringBuilder(totalCharSet); for (int i = 0; i < totalCharSet + customCharsLength; i++) { char ch = (i < totalCharSet) ? (char)i : customCharsArray[i - totalCharSet]; int charwidth = font.CharWidth(ch); if (charwidth <= 0) { charwidth = 1; } int charheight = font.GetHeight(); if (charheight <= 0) { charheight = font.GetSize(); } IntObject newIntObject = new IntObject(); newIntObject.width = charwidth; newIntObject.height = charheight; if (positionX + newIntObject.width >= textureWidth) { g.DrawString(sbr.ToString(), 0, positionY); sbr.Clear(); positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } sbr.Append(ch); positionX += newIntObject.width; if (i < totalCharSet) { charArray[i] = newIntObject; } else { CollectionUtils.Put(customChars, ch, newIntObject); } } if (sbr.Length > 0) { g.DrawString(sbr.ToString(), 0, positionY); sbr = null; } g.Dispose(); g = null; fontBatch = new LTextureBatch(imgTemp.GetTexture()); } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } }
private void createSet(char[] customCharsArray) { // If there are custom chars then I expand the font texture twice if (customCharsArray != null && customCharsArray.Length > 0) { textureWidth *= 2; } // In any case this should be done in other way. Texture with size 512x512 // can maintain only 256 characters with resolution of 32x32. The texture // size should be calculated dynamicaly by looking at character sizes. try { Bitmap imgTemp = new Bitmap(textureWidth, textureHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(imgTemp); //g.FillRectangle(new SolidBrush(Color.Yellow), 0, 0, textureWidth, textureHeight); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; for (int i = 0; i < 256 + customCharsLength; i++) { // get 0-255 characters and then custom characters char ch = (i < 256) ? (char)i : customCharsArray[i - 256]; Bitmap fontImage = getFontImage(ch); IntObject newIntObject = new IntObject(); newIntObject.width = fontImage.Width; newIntObject.height = fontImage.Height; if (positionX + newIntObject.width >= textureWidth) { positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } // Draw it here g.DrawImage(fontImage, positionX, positionY); positionX += newIntObject.width; if (i < 256) // standard characters { charArray[i] = newIntObject; } else // custom characters { customChars[ch] = newIntObject; } fontImage = null; } fontTextureID = loadImage(imgTemp); } catch (Exception e) { Console.WriteLine("Failed to create font."); Console.WriteLine(e.StackTrace); } }