internal DiscordEmoji(DiscordClient parent, DiscordEmojiJSON e) { ID = e.id; name = e.name; client = parent; emojiState = TextureState.Unloaded; }
public void SetData() { if (m_texture_state == TextureState.SetDataPending) { m_texture.SetData<uint>(m_buffer_front, 0, BUFFER_SIZE); m_texture_state = TextureState.SetDataComplete; } }
public void SetState(TextureState state) { State = state; if (State == TextureState.Compile) { _amount = .2f; } if (state == TextureState.Decomplie) { _amount = 0f; } }
public void OnBufferComplete() { Debug.Assert(m_monitor_state == MonitorState.DrawingToBackBuffer); m_monitor_state = MonitorState.VSync; // Swap buffers uint[] temp = m_buffer_front; m_buffer_front = m_buffer_back; m_buffer_back = temp; m_texture_state = TextureState.SetDataPending; }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { state = new TextureState() { currentTexture = host.AltTextureIndex, remainingTime = _cooldown.Next(Random) }; if (host.AltTextureIndex != _indexMin) { host.AltTextureIndex = _indexMin; (state as TextureState).currentTexture = _indexMin; } }
private void SetTextures(TextureState state) { if (state == TextureState.Normal) { MeshRenderer.material.mainTexture = normalAlbedo; MeshRenderer.material.SetTexture("_BumpMap", mormalNormalMap); } else { MeshRenderer.material.mainTexture = crackedAlbedo; MeshRenderer.material.SetTexture("_BumpMap", crackedNormalMap); } }
/** * Load (or reuse) a texture from a file to perform an action. */ public void withTexture(string textureFile, int textureType, TextureCallback action) { if (textureCache.ContainsKey(textureFile)) { textureCache[textureFile].withTexture(action); } else { // Create the texture state object TextureState newState = new TextureState(); newState.withTexture(action); textureCache[textureFile] = newState; bool createMipMaps = true; bool linear = false; bool isNormal = false; bool compress = true; switch (textureType) { case TYPE_SPECULAR: case TYPE_GLOSS: linear = true; break; case TYPE_NORMAL: linear = true; isNormal = true; compress = false; break; default: break; } // Begin loading the texture var img = new ImageLoaderThreaded.QueuedImage(); img.imgPath = textureFile; img.callback = qimg => newState.applyTexture(qimg); img.createMipMaps = createMipMaps; img.isNormalMap = isNormal; img.linear = linear; img.compress = compress; ImageLoaderThreaded.singleton.QueueImage(img); } }
public bool CheckCondition(TextureState TState) { switch (TState.Comp) { case EComparator.LESS: return(m_CurrentValue < TState.Value); case EComparator.LEQUAL: return(m_CurrentValue <= TState.Value); case EComparator.EQUAL: return(m_CurrentValue == TState.Value); case EComparator.NOTEQUAL: return(m_CurrentValue != TState.Value); case EComparator.GEQUAL: return(m_CurrentValue >= TState.Value); case EComparator.GREATER: return(m_CurrentValue > TState.Value); default: return(false); } }
/** * Load (or reuse) a texture from a file to perform an action. */ public void withTexture(string textureFile, TextureCallback action) { if (textureCache.ContainsKey(textureFile)) { textureCache[textureFile].withTexture(action); } else { // Create the texture state object TextureState newState = new TextureState(); newState.withTexture(action); textureCache[textureFile] = newState; // Begin loading the texture var img = new ImageLoaderThreaded.QueuedImage(); img.imgPath = textureFile; img.createMipMaps = true; img.callback = qimg => newState.applyTexture(qimg); ImageLoaderThreaded.singleton.QueueImage(img); } }
public IEnumerator GetEmoji(DiscordTextureCallback callback) { if (emojiState == TextureState.Unloaded) { emojiState = TextureState.Loading; Debug.Log("https://cdn.discordapp.com/emojis/" + ID + ".png"); WWW www = new WWW("https://cdn.discordapp.com/emojis/" + ID + ".png"); yield return(www); Texture2D result = www.texture; if (result == null) { emojiState = TextureState.NoTexture; yield break; } emoji = www.texture; emojiState = TextureState.Loaded; client.unityInvoker.Enqueue(() => callback(client, emoji, new DiscordError())); } }
public void Draw(SpriteBatch sb, Vector2 pos, Color colour) { switch (State) { case TextureState.Decomplie: _amount += Speed * .1f; break; case TextureState.Compile: _amount -= Speed * .1f; break; } int hPixels = (int)((Sprite.Height * Sprite.Width) / pixelSize); int pixel = 0; if (State == TextureState.Compile) { pixel = (int)((Sprite.Height * Sprite.Width * _amount) / pixelSize); } else { pixel = (int)((Sprite.Height * Sprite.Width * _amount) / pixelSize); } int y = (int)(pixel / (Sprite.Width / pixelSize)); int x = (int)(pixel - y * (Sprite.Width / pixelSize)); x *= (int)pixelSize; y *= (int)pixelSize; if (_amount <= 0 && State == TextureState.Compile) { _amount = 0; State = TextureState.None; } if (y >= Sprite.Height) { State = TextureState.None; return; } if (new Point(x, y) != lastpixels) { if (State == TextureState.Decomplie || State == TextureState.Compile && _amount > .05f) { Vector2 p = new Vector2(x, y); if (State == TextureState.Compile) { p.Y -= 80; } _particals.Add(new Partical() { Position = p, Part = new Rectangle(x, y, (int)pixelSize, (int)pixelSize), LifeTime = .6f, }); } } lastpixels = new Point(x, y); sb.Draw(Sprite, pos + new Vector2(x, y), new Rectangle(x, y, Sprite.Width - x, (int)pixelSize), Color.White); y += (int)pixelSize; sb.Draw(Sprite, pos + new Vector2(0, y), new Rectangle(0, y, Sprite.Width, Sprite.Height - y), Color.White); if (State == TextureState.Compile) { dir = 2; } else if (State == TextureState.Decomplie) { dir = -2; } for (int i = _particals.Count - 1; i >= 0; i--) { _particals[i].Position.Y += dir; _particals[i].LifeTime -= Speed; sb.Draw(Sprite, _particals[i].Position + pos, _particals[i].Part, Color.White * (_particals[i].LifeTime * 2)); if (_particals[i].LifeTime <= 0) { _particals.RemoveAt(i); } } }
/// <summary> /// Initialize the device objects /// </summary> /// <param name="dev">The grpahics device used to initialize</param> public void InitializeDeviceObjects(Device dev) { if (dev != null) { // Set up our events dev.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); } // Keep a local copy of the device device = dev; textureState0 = device.TextureState[0]; textureState1 = device.TextureState[1]; samplerState0 = device.SamplerState[0]; renderState = device.RenderState; // Create a bitmap on which to measure the alphabet Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.TextContrast = 0; // Establish the font and texture size textureScale = 1.0f; // Draw fonts into texture without scaling // Calculate the dimensions for the smallest power-of-two texture which // can hold all the printable characters textureWidth = textureHeight = 128; for (;;) { try { // Measure the alphabet PaintAlphabet(g, true); } catch (System.InvalidOperationException) { // Scale up the texture size and try again textureWidth *= 2; textureHeight *= 2; continue; } break; } // If requested texture is too big, use a smaller texture and smaller font, // and scale up when rendering. Direct3D.Caps d3dCaps = device.DeviceCaps; // If the needed texture is too large for the video card... if (textureWidth > d3dCaps.MaxTextureWidth) { // Scale the font size down to fit on the largest possible texture textureScale = (float)d3dCaps.MaxTextureWidth / (float)textureWidth; textureWidth = textureHeight = d3dCaps.MaxTextureWidth; for (;;) { // Create a new, smaller font ourFontHeight = (int)Math.Floor(ourFontHeight * textureScale); systemFont = new System.Drawing.Font(systemFont.Name, ourFontHeight, systemFont.Style); try { // Measure the alphabet PaintAlphabet(g, true); } catch (System.InvalidOperationException) { // If that still doesn't fit, scale down again and continue textureScale *= 0.9F; continue; } break; } } // Release the bitmap used for measuring and create one for drawing bmp.Dispose(); bmp = new Bitmap(textureWidth, textureHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.TextContrast = 0; // Draw the alphabet PaintAlphabet(g, false); // Create a new texture for the font from the bitmap we just created fontTexture = Texture.FromBitmap(device, bmp, 0, Pool.Managed); RestoreDeviceObjects(null, null); }
/// <summary> /// Initialize the device objects /// </summary> /// <param name="dev">The grpahics device used to initialize</param> public void InitializeDeviceObjects(Device dev) { if (dev != null) { // Set up our events dev.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); } // Keep a local copy of the device device = dev; textureState0 = device.TextureState[0]; textureState1 = device.TextureState[1]; samplerState0 = device.SamplerState[0]; renderState = device.RenderState; // Establish the font and texture size textureScale = 1.0f; // Draw fonts into texture without scaling // Large fonts need larger textures if (ourFontHeight > 60) { textureWidth = textureHeight = 2048; } else if (ourFontHeight > 30) { textureWidth = textureHeight = 1024; } else if (ourFontHeight > 15) { textureWidth = textureHeight = 512; } else { textureWidth = textureHeight = 256; } // If requested texture is too big, use a smaller texture and smaller font, // and scale up when rendering. Direct3D.Caps d3dCaps = device.DeviceCaps; if (textureWidth > d3dCaps.MaxTextureWidth) { textureScale = (float)d3dCaps.MaxTextureWidth / (float)textureWidth; textureWidth = textureHeight = d3dCaps.MaxTextureWidth; } Bitmap bmp = new Bitmap(textureWidth, textureHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.TextContrast = 0; string str; float x = 0; float y = 0; Point p = new Point(0, 0); Size size = new Size(0, 0); // Calculate the spacing between characters based on line height size = g.MeasureString(" ", systemFont).ToSize(); x = spacingPerChar = (int)Math.Ceiling(size.Height * 0.3); for (char c = (char)32; c < (char)127; c++) { str = c.ToString(); // We need to do some things here to get the right sizes. The default implemententation of MeasureString // will return a resolution independant size. For our height, this is what we want. However, for our width, we // want a resolution dependant size. Size resSize = g.MeasureString(str, systemFont).ToSize(); size.Height = resSize.Height + 1; // Now the Resolution independent width if (c != ' ') // We need the special case here because a space has a 0 width in GenericTypoGraphic stringformats { resSize = g.MeasureString(str, systemFont, p, StringFormat.GenericTypographic).ToSize(); size.Width = resSize.Width; } else { size.Width = resSize.Width; } if ((x + size.Width + spacingPerChar) > textureWidth) { x = spacingPerChar; y += size.Height; } if (c != ' ') // We need the special case here because a space has a 0 width in GenericTypoGraphic stringformats { g.DrawString(str, systemFont, Brushes.White, new Point((int)x, (int)y), StringFormat.GenericTypographic); } else { g.DrawString(str, systemFont, Brushes.White, new Point((int)x, (int)y)); } textureCoords[c - 32, 0] = ((float)(x + 0 - spacingPerChar)) / textureWidth; textureCoords[c - 32, 1] = ((float)(y + 0 + 0)) / textureHeight; textureCoords[c - 32, 2] = ((float)(x + size.Width + spacingPerChar)) / textureWidth; textureCoords[c - 32, 3] = ((float)(y + size.Height + 0)) / textureHeight; x += size.Width + (2 * spacingPerChar); } // Create a new texture for the font from the bitmap we just created fontTexture = Texture.FromBitmap(device, bmp, 0, Pool.Managed); RestoreDeviceObjects(null, null); }
public void InitializeDeviceObjects(Device dev) { if (dev != null) { // Set up our events dev.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); } // Keep a local copy of the device device = dev; textureState0 = device.TextureState[0]; textureState1 = device.TextureState[1]; samplerState0 = device.SamplerState[0]; renderState = device.RenderState; // Create a bitmap on which to measure the alphabet Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; g.TextContrast = 0; // Establish the font and texture size textureScale = 1.0f; // Draw fonts into texture without scaling // Calculate the dimensions for the smallest power-of-two texture which // can hold all the printable characters textureWidth = textureHeight = 128; for (;;) { try { // Measure the alphabet PaintAlphabet(g, true); } catch (System.InvalidOperationException) { // Scale up the texture size and try again textureWidth *= 2; textureHeight *= 2; continue; } break; } // If requested texture is too big, use a smaller texture and smaller font, // and scale up when rendering. Caps d3dCaps = device.DeviceCaps; // If the needed texture is too large for the video card... if (textureWidth > d3dCaps.MaxTextureWidth) { // Scale the font size down to fit on the largest possible texture textureScale = (float)d3dCaps.MaxTextureWidth / (float)textureWidth; textureWidth = textureHeight = d3dCaps.MaxTextureWidth; for(;;) { // Create a new, smaller font fontSize = (int) Math.Floor(fontSize * textureScale); font = new System.Drawing.Font(font.Name, fontSize, font.Style); try { // Measure the alphabet PaintAlphabet(g, true); } catch (System.InvalidOperationException) { // If that still doesn't fit, scale down again and continue textureScale *= 0.9F; continue; } break; } } // Release the bitmap used for measuring and create one for drawing bmp.Dispose(); bmp = new Bitmap(textureWidth, textureHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.TextContrast = 0; // Draw the alphabet PaintAlphabet(g, false); // Create a new texture for the font from the bitmap we just created fontTexture = Texture.FromBitmap(device, bmp, 0, Pool.Managed); RestoreDeviceObjects(null, null); }
public void Reset() { m_monitor_state = MonitorState.Idle; m_texture_state = TextureState.Idle; }