C# passionate who loves making bugs and removing features... Wait a second...
morasiu / termgine Goto Github PK
View Code? Open in Web Editor NEWGame engine for making terminal based games.
License: MIT License
Game engine for making terminal based games.
License: MIT License
When rendering an 80x30 scene on a terminal emulator of a different size (e.g. 120x30) the scene is improperly rendered, as the renderer does not return the carriage after the expected 80th column.
This is what happens when trying to rendering an 80x30 scene on a 120x30 terminal
And here's the appropriate rendering on a properly sized terminal
The issue comes from the rendering portion of the Display class, more specifically in this function
private void DrawCurrentScene() {
if (CurrentScene == null)throw new NullReferenceException("CurrentScene is null");
Console.SetCursorPosition(0, 0);
var currentContent = CurrentScene.Content.Split('\n');
var currentColors = CurrentScene.ColorMask.Split('\n');
for (var y = 0; y < CurrentScene.Height; y++) {
for (var x = 0; x < CurrentScene.Width; x++) {
var color = GetColorFromNumber(currentColors[y][x]);
WriteInColor(currentContent[y][x], color);
}
}
}
because currentContent is generated by splitting the scene per newlines, but the actual newline character is never rendered, the scene will ever only be rendered correctly on a properly sized terminal.
Since defining a terminal buffer size or resizing the console windows is not supported outside of Windows, I'd suggest to simply add an empty WriteLine() after the inner cicle, so that after each row has been completely rendered, a new line is always drawn.
If that's an ok solution I can write up a pull request
Few possible reasons to do that:
Edit: As I tried to experiment with this using System.Numerics.Vector2, few errors occurred due to x,y of Vector2 being floats. Inside of function's AddObjectToGlobalContent
and AddObjectColorToGlobalColorMask
, globalPositionY
and globalPositionX
need to be int's but result of addition on right side is float and this need to be converted to int. Of course this can lead to rounding errors i.e. rendering console char's/content at wrong place. To avoid that, generic Vector of int type need to be used, but that would lead to use of Span and as a result C# 7.3 requirement. Sample code:
Span<int> span = stackalloc int[] {1,1};
Vector<int> vector = new Vector<int>(span);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.