Author Topic: BearLibTerminal: a pseudo-terminal window library for roguelike  (Read 282367 times)

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #30 on: February 28, 2015, 11:38:29 AM »
Quote from: Cfyz
I'll upload a fixed version later today.
Here it is, 0.11.4.

Quote from: notostraca
My source is here, in case there's something obviously wrong
Well, this gets weirder. I've downloaded the source, opened it in VS2013, switched startup project to 'Runner32' and hit 'Run': screenshot.

Try setting 'log.level' option before other configuration, i. e.
Code: [Select]
Terminal.Set("log: level=trace");
Terminal.Set("window: title='Dungeon Rising', size=110x45; font: Zodiac-Narrow-6x12.png, size=6x12;");
Post a screenshot and generated 'bearlibterminal.log', maybe that will give me some clue.

Quendus

  • Rogueliker
  • ***
  • Posts: 447
  • Karma: +0/-0
  • $@ \in \{1,W\} \times \{1,H\}$
    • View Profile
    • Klein Roguelikes
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #31 on: February 28, 2015, 12:49:14 PM »
I haven't tested noto's code so I don't have a clue what I'm talking about, but is it possible that the issue is with the working directory not being the same as the directory with the font image?
VS seems to have a habit of making the working directory different from the executable directory, and this has stung me before when using eg. libtcod.

notostraca

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #32 on: February 28, 2015, 05:25:50 PM »
Yeah, I posted a working version to Github, the line I highlighted didn't have a codepage set. If you still have the project, change the only line that calls Terminal.Set (it's in Entry.cs, method Run) to:
Code: [Select]
Terminal.Set("window: title='Dungeon Rising', size=110x45; font: ./Zodiac-Narrow-6x12.png, size=6x12, codepage=./custom.txt;");I've set it to copy custom.txt (in each of the Runner projects) to the output directory, same as the png. cfyz, I'll try 0.11.4 now, could you maybe fiddle with the codepage settings in that line?

notostraca

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #33 on: February 28, 2015, 05:51:54 PM »
I just posted an update to GitHub, using 0.11.4, and I have a screenshot, log, and debug build.
Log:
Code: [Select]
09:39:39.901 [Info] Trying to set "window: title='Dungeon Rising', size=110x45; font: ./Zodiac-Narrow-6x12.png, size=6x12, codepage=./custom.txt;"
09:39:39.904 [Debug] Group "window":
09:39:39.904 [Debug] * "size" = "110x45"
09:39:39.905 [Debug] * "title" = "Dungeon Rising"
09:39:39.905 [Debug] Group "font":
09:39:39.906 [Debug] * "codepage" = "./custom.txt"
09:39:39.906 [Debug] * "name" = "./Zodiac-Narrow-6x12.png"
09:39:39.907 [Debug] * "size" = "6x12"
09:39:39.907 [Debug] Tileset resource name "./Zodiac-Narrow-6x12.png" is recognized as a name of a bitmap resource
09:39:39.908 [Debug] Bitmap tileset: failed to parse guessed tile size, not an error
09:39:39.909 [Debug] Requested resource "./custom.txt" with possible prefix "codepage-"
09:39:39.909 [Debug] Requested resource "./Zodiac-Narrow-6x12.png" with possible prefix "tileset-"
09:39:39.911 [Trace] Loaded PNG image, 768x24
09:39:39.911 [Debug] Tileset has 128x2 tiles
09:39:39.912 [Debug] Successfully loaded a tileset for base code 0
09:39:39.912 [Debug] Reloaded the tileset with base code 0
09:39:39.913 [Trace] Scheduling texture #103078664 for removal
09:39:39.914 [Trace] Added tile texture #103078664
09:39:39.914 [Info] Added Unicode replacement character tile (6x12)
09:39:39.915 [Debug] SetOptions: new cell size is 6x12
09:39:39.915 [Debug] SetOptions: new window size is 110x45
Screenshot:

Debug Build: x86 https://dl.dropboxusercontent.com/u/11914692/DungeonRisingDebugBoxProblem_x86.zip
and x64 https://dl.dropboxusercontent.com/u/11914692/DungeonRisingDebugBoxProblem_x64.zip

Quendus, your answer seems likely, given the log; it mentions loading the png but not the codepage.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #34 on: February 28, 2015, 07:02:53 PM »
Figured this out, after a bit of meditation over two identical .txt files, one working as a codepage and one not. I do not see UTF-8 files with BOMs often, so my own tests did not catch that. And the ad-hoc parser used for codepages turned out to be too simple to handle it.

For now you should just remove the BOM (File -> Advanced Save Options -> UTF-8 without signature). I'll release another bugfix shortly =_=.

notostraca

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #35 on: March 01, 2015, 02:19:09 AM »
Yep, that was it. I committed the 2-character change and now it works. You're a master! Now I just need to make a game...

Omnivore

  • Rogueliker
  • ***
  • Posts: 154
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #36 on: March 01, 2015, 02:41:08 AM »
Here's a fairly simple and complete BOM detector I wrote awhile back in D, should be easy to port or at least give an idea.  https://gist.github.com/Brian61/298fba834f851bf95be2.

Switched to C# in my latest project and spent yesterday creating the interface between my new project and BearLibTerminal :)

Quick questions:
In the string passed to set, is whitespace necessary between the separators (':',',',';')?   Also is extra whitespace permissible at end of string, and lastly are embedded line endings allowed?

And another :)
If you attempt to get a char value via: Terminal.State(Terminal.TK_CHAR) during a non printable char event (mouse for ex), do you just get 0?  (Update: went source diving and it looks to be the case.)

Finally, a suggestion: For some uses in C#, the list of const int TK_XXX symbols in BearLibTerminal.cs would be much better represented as a public enum outside the Terminal class, say as public enum TerminalKeys {...}.  Its not a huge deal since you can do as I've done and just cut-n-paste the list of symbol = value, pairs.
« Last Edit: March 01, 2015, 08:25:40 AM by Omnivore »

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #37 on: March 02, 2015, 01:31:59 PM »
Quote from: Omnivore
Here's a fairly simple and complete BOM detector I wrote awhile back in D, should be easy to port or at least give an idea.
That's a nice snippet, gonna save it. I'm not sure about such variety of encodings in this case though, I thought ANSI/UTF-8 would be enough for external text files. Do you think UTF-16/32 encoded files should also be supported? (since it will be a bit of a hassle).

Quote from: Omnivore
In the string passed to set, is whitespace necessary between the separators (':',',',';')?   Also is extra whitespace permissible at end of string, and lastly are embedded line endings allowed?
No, whitespaces are cosmetic there, extra ',' and ';' are also ignored and trailing ';' is optional. As for newlines, it is an oversight and it may or may not work depending on where you place that newline. I'll fix and document this in the next update.

Quote from: Omnivore
If you attempt to get a char value via: Terminal.State(Terminal.TK_CHAR) during a non printable char event (mouse for ex), do you just get 0?  (Update: went source diving and it looks to be the case.)
Yes, you figured it out correctly. The idea is that value of TK_CHAR may be used to determine whether last stroke was textual or not.

Quote from: Omnivore
For some uses in C#, the list of const int TK_XXX symbols in BearLibTerminal.cs would be much better represented as a public enum outside the Terminal class, say as public enum TerminalKeys {...}.
A lot of constants represent both an input event and a state, e. g. TK_A which may be returned by Read and also may be tested by State/Check. It's either using one single enum or duplicate a lot of constants in separate enums. And one huge list just does not look like enum since its values not equally meaningful within same context. C# is not my area of expertise, so I may miss some fundamental feature or strict community preferences here, but this list of constants does not seem that bad =_=.
« Last Edit: March 02, 2015, 02:05:50 PM by Cfyz »

Omnivore

  • Rogueliker
  • ***
  • Posts: 154
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #38 on: March 02, 2015, 02:38:40 PM »
Do you think UTF-16/32 encoded files should also be supported? (since it will be a bit of a hassle).
No, but it may be worth detecting them and throwing/returning an error to the user.

As for newlines, it is an oversight and it may or may not work depending on where you place that newline. I'll fix and document this in the next update.
Cool :)  I'm loading the initial settings from an external file, while I can strip the line endings, it'd be nice I think for future users if it wasn't necessary.

The idea is that value of TK_CHAR may be used to determine whether last stroke was textual or not.
Good.  I'm processing the input and sometimes grabbing the value when I don't really need it just to simplify the code, was more worried about causing an internal error accidentally.

Quote from: Omnivore
For some uses in C#, the list of const int TK_XXX symbols in BearLibTerminal.cs would be much better represented as a public enum outside the Terminal class, say as public enum TerminalKeys {...}.
A lot of constants represent both an input event and a state, e. g. TK_A which may be returned by Read and also may be tested by State/Check. It's either using one single enum or duplicate a lot of constants in separate enums. And one huge list just does not look like enum since its values not equally meaningful within same context. C# is not my area of expertise, so I may miss some fundamental feature or strict community preferences here, but this list of constants does not seem that bad =_=.
While I wouldn't call it bad in this case, I believe it is considered 'C# best practice' to use enums instead of lists of constants.  In my particular use case, I'm making use of the ability to get a string name from the enum by its value.  I turn the input events into string descriptors (plus extra data for char value, mouse position, etc) which then is used in a user configurable command table.  It allows an easy to implement key map file with lines of the form: "T.CONTROL = JUMP_SIDEWAYS".

Being able to use the enum to turn the integer value into a string ("TK_T" in this case) and then strip the "TK_", add the ".CONTROL" if the control key state is true, etc.  Having the values of a long list in a C# enum saves a lot of typing which could potentially introduce errors.   Its not a major issue since you can do as I've done and simply cut and paste the list of integer constants into an enum, but that is a potential maintenance problem if the constants are expanded or changed - probably not much of a chance of that in this case.

Anyhow, thanks for doing this library :)  It fits in quite well with the data structures I'm using and since I had a 'layers' variable for the imaging already, its nice to be able to use it for something other than a sort order key!  Also the guy that's been doing artwork for me will be glad to hear that he can stack tiles and layers since that seems to be the common practice in the portion of the graphics industry he works in.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #39 on: March 02, 2015, 04:05:18 PM »
Quote from: Omnivore
In my particular use case, I'm making use of the ability to get a string name from the enum by its value.
http://ideone.com/Ah494k
I did it mostly for lulz but if your main concern is type conversion, it might actually help to get rid of some copy-paste.
« Last Edit: March 02, 2015, 04:09:27 PM by Cfyz »

notostraca

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #40 on: March 23, 2015, 05:07:38 AM »
OK, Terminal.PutExt is just awesome.  I have creatures vibrating wildly within their cell for a moment when damaged, and it was extremely easy to add with BearLibTerminal. Brief video preview: http://a.pomf.se/kmyrvl.webm.  I'm going to try to port BearLibTerminal to Mac OSX soon (a friend who looked into the code told me that the same X11 window API used on Linux should mostly work on OSX), but first I am having trouble building the lib on Windows -- I posted an issue on BitBucket.  I'm really hoping that the Mac port is feasible and can be incorporated into the main code, at least, if I ever get it to work. Cfyz, are you opposed to using a cross-platform library that handles windowing on the (perfectly reasonable) grounds of not wanting a sizable extra dependency, or is there some technical aspect of BearLibTerminal that makes SFML, GLFW, or similar libraries unusable with it?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #41 on: March 23, 2015, 11:56:43 AM »
Quote from: notostraca
Cfyz, are you opposed to using a cross-platform library that handles windowing on the (perfectly reasonable) grounds of not wanting a sizable extra dependency, or is there some technical aspect of BearLibTerminal that makes SFML, GLFW, or similar libraries unusable with it?
No, I do not oppose this. Whatever the reasons for using homebrew window implementations once were, they do not stand now. Not only OS X, there are also Wayland and various EGL flavours and reimplementing the wheel becomes clearly counterproductive. Ability to change icon in runtime or to resize window in discrete steps just not worth it.

I do plan to delegate windowing to GLFW. In the very near future. This, however, will require some work: current BearLibTerminal uses two threads with rendering in background, which is ok under Windows (which gave me a false impression) and somehow works under most of Linux, but as it turns out it is not guaranteed to work reliably or work at all. Making BearLibTerminal single-threaded will not require any changes in its API (probably, no one will even notice) but this will be a big overhaul in the code. I really appreciate your willingness to contribute but it looks like I'll have to clean up this mess myself.

Quote from: notostraca
OK, Terminal.PutExt is just awesome.
I wonder if anyone using corner-coloring in put_ext. I hope no one is. It does not work uniformly (with final result depending strongly on particular hardware, ugh) and restricts some possible optimizations, so I plan to remove it.
« Last Edit: March 23, 2015, 11:58:28 AM by Cfyz »

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #42 on: March 24, 2015, 04:01:08 PM »
Here comes a new update of questionable nature. It fixes a few things like UTF-8 BOM handling in external text files and X11 window title modification, but the main addition is the configuration file.

The idea to add some alternate configuration mechanism came from inability to configure logging options before the library is initialized, which effectively prohibits useful verbose output during the initialization step. The most obvious way would be to allow library configuration before initialization. Using the same terminal_set mechanism, but before terminal_open, is hacky and still requires application modification to switch log verbosity. Meh. Therefore, I decided to add a configuration file in a simplest INI format, which somehow went out of control.

Not only logging, but all library options might be specified in the configuration file, even fonts/tilesets. Furthermore, only the "BearLibTerminal" section is used for initial library configuration and all other sections in the file are left for the application. By utilizing omnipotent terminal_set and newly added terminal_get it is possible to read, add, modify and remove properties in the file:
Code: [Select]
terminal_set("ini.settings.window-size=80x25"); // Save preferred interface size.
int tile_size = terminal_get<int>("ini.settings.tile-size", 16); // Read requested tileset size.

See API / configuration page for more detailed information.

Downloads are here.
« Last Edit: March 24, 2015, 04:26:02 PM by Cfyz »

Omnivore

  • Rogueliker
  • ***
  • Posts: 154
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #43 on: March 24, 2015, 04:15:50 PM »
You sir, are awesome :)

Zanetski

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #44 on: June 23, 2015, 01:26:28 AM »
Just tried it out... this library is amazing! I really like how the API is less verbose than libtcod. Definitely my preferred choice now.