public void ReplaceScreenBuffer(ScreenBufferState newData) { var index = GameComponentsLookup.ScreenBuffer; var component = CreateComponent <ScreenBufferComponent>(index); component.data = newData; ReplaceComponent(index, component); }
void RandomNoise(ScreenBufferState data, int numNoisePixels) { for (int i = 0; i < numNoisePixels; i++) { int x = Random.Range(0, (int)data.size.x); int y = Random.Range(0, (int)data.size.y); data.SetColorCodeAt(x, y, (ColorCode)Random.Range(0, 15)); } }
/// Fills the buffer data with values generated by a function of pixel coordinates. public static void Fill(this ScreenBufferState data, Func <int, int, ColorCode> function) { for (int y = 0; y < data.size.y; ++y) { for (int x = 0; x < data.size.x; ++x) { data.SetColorCodeAt(x, y, function(x, y)); } } }
/// Fills the buffer data with a specified color. public static void Fill(this ScreenBufferState data, ColorCode colorCode) { for (int y = 0; y < data.size.y; ++y) { for (int x = 0; x < data.size.x; ++x) { data.SetColorCodeAt(x, y, colorCode); } } }
public override GameEntity CreateEntity(Contexts contexts) { var screenView = GetComponentInChildren <ScreenView>(); var screenResolution = screenView.resolution; var transformState = transform.GetState(); var screenState = new ScreenBufferState(screenResolution); var e = contexts.game.CreateMonitor(transformState, screenState); return(e); }
/// Creates a computer monitor with the specified transform and screen buffer contents. public static GameEntity CreateMonitor(this GameContext game, TransformState transformState, ScreenBufferState screenData ) { var e = game.CreateEntity(); e.AddTransform(transformState); e.AddScreenBuffer(screenData); e.AddPrefab(monitorPrefabPath); return(e); }
/// <summary> /// Displays a character on the display. Is tied to an aligned grid 4px wide by 8px tall, per original LEM1802 spec. /// </summary> /// <remarks> /// This utilizes the default font set of the LEM1802; manual pixel control is available from the SetPixel call. /// This code presumes that a display's resolution can be evenly divided into 4px w by 8 px h cells. /// Original font ripped from https://rdr4g0n.github.io/0x10c_SpriteStudio/. /// </remarks> /// <param name="data">The buffer that is being manipulated.</param> /// <param name="x">The X coordinate of where to render the character.</param> /// <param name="y">The Y coordinate of where to render the character.</param> /// <param name="c">The 32 bits that represent pixels of the character being on or off</param> /// <param name="foreground">The color to use for the positive space (pixels the character fills).</param> /// <param name="background">The color to use for the negative space (pixels the character doesn't fill.</param> public static void WriteChar(this ScreenBufferState data, int x, int y, uint character, ColorCode foreground, ColorCode background) { // Filter the cell indices, and multiply the amounts by the cell sizes. x = (x % (data.size.x / 4)) * 4; y = (y % (data.size.y / 8)) * 8; for (int i = 31; i >= 0; i--) { int pixelX = x + (i / 8), pixelY = y + 7 - (i % 8); bool filled = ((character >> (31 - i)) & 1) == 1; data.SetColorCodeAt(pixelX, pixelY, (filled ? foreground : background)); } }
/// <summary> /// Displays a string on the display. Is tied to an aligned grid 4px wide by 8px tall, per original LEM1802 spec. /// </summary> /// <param name="data">The buffer that is being manipulated.</param> /// <param name="x">The X coordinate of where to begin rendering the string.</param> /// <param name="y">The Y coordinate of where to begin rendering the string.</param> /// <param name="s">The string to render.</param> /// <param name="foreground">The color to use for the positive space (pixels the character fills).</param> /// <param name="background">The color to use for the negative space (pixels the character doesn't fill.</param> public static void WriteStr(this ScreenBufferState data, int x, int y, string s, ColorCode foreground, ColorCode background) { for (int i = 0; i < s.Length; i++) { if (x * 4 >= data.size.x) { y++; x = 0; } if (y * 8 >= data.size.y) { y = 0; } data.WriteChar(x, y, s[i], foreground, background); x++; } }
ScreenBufferState GetScreenBufferState() { var data = new ScreenBufferState(new Vector2Int(64, 48)); return(data); }
void TestAllCharacters(ScreenBufferState data) { data.WriteStr(0, 0, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", ColorCode.White, ColorCode.Black); }
/// <summary> /// Displays a character on the display. Is tied to an aligned grid 4px wide by 8px tall, per original LEM1802 spec. /// </summary> /// <remarks> /// This is just a helper method for the version of WriteChar that uses a byte. /// </remarks> /// <param name="data">The buffer that is being manipulated.</param> /// <param name="x">The X coordinate of where to render the character.</param> /// <param name="y">The Y coordinate of where to render the character.</param> /// <param name="c">Which character to render.</param> /// <param name="foreground">The color to use for the positive space (pixels the character fills).</param> /// <param name="background">The color to use for the negative space (pixels the character doesn't fill.</param> public static void WriteChar(this ScreenBufferState data, int x, int y, char c, ColorCode foreground, ColorCode background) { data.WriteChar(x, y, characterToByte[c], foreground, background); }
/// <summary> /// Displays a character on the display. Is tied to an aligned grid 4px wide by 8px tall, per original LEM1802 spec. /// </summary> /// <remarks> /// This utilizes the default font set of the LEM1802; manual pixel control is available from the SetPixel call. /// This code presumes that a display's resolution can be evenly divided into 4px w by 8 px h cells. /// Original font ripped from https://rdr4g0n.github.io/0x10c_SpriteStudio/. /// </remarks> /// <param name="data">The buffer that is being manipulated.</param> /// <param name="x">The X coordinate of where to render the character.</param> /// <param name="y">The Y coordinate of where to render the character.</param> /// <param name="c">The index of the character to render.</param> /// <param name="foreground">The color to use for the positive space (pixels the character fills).</param> /// <param name="background">The color to use for the negative space (pixels the character doesn't fill.</param> public static void WriteChar(this ScreenBufferState data, int x, int y, byte characterIndex, ColorCode foreground, ColorCode background) { // Fill character based on c // Just pulls a specific index from a constant array filled (by hand!) from linked source data.WriteChar(x, y, characterData[characterIndex], foreground, background); }