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

Elronnd

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • NetHack and Slash'EM EU server
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #210 on: March 13, 2017, 09:47:06 PM »
Alright, I set the log level right after terminal_open() and got this:


14:16:50.451 [info] Trying to set "window.fullscreen = true"
14:16:50.451 [debug] Group "window":
14:16:50.451 [debug] * "fullscreen" = "true"


Interestingly enough, if I alt+enter while within the window, it fullscreens fine.  Even more interestingly, if I set window.fullscreen = true, while the window doesn't get fullscreened, I can then resize it even though I haven't set window.resizeable to true.  I'm on 64-bit arch linux, fvwm, I get the same output on both gcc and clang.  If it's relevant, my command line is gcc -std=c11 -LLinux64/ -lBearLibTerminal -o test test.c.
Wishes, wishes.  Wish in one hand and do something else in the other, and squeeze them both and see which comes true

 —Roger Zelazny, Nine Princes in Amber

Looks like a fish, moves like a fish, steers like a cow.

 —Douglas Adams, Hitchhiker's Guide to the Galaxy Fit the Fifth

The Saber Cat

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #211 on: April 10, 2017, 09:05:21 AM »
Hello!
I am experienced programmer, but complete newbie in C++. I'm trying to learn C++ by building a simple game using BearLibTerminal, but I'm completely lost with CMake.
My folder structure is:
Code: [Select]
learn
  bin
    libBearLibTerminal.so
  lib
    BearLibTerminal.h
  src
    main.cpp
  CMakeLists.txt
My CMakeLists file is:
Code: [Select]
cmake_minimum_required(VERSION 3.7)
project(learn)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

set(SOURCE_FILES src/main.cpp)
include_directories(${CMAKE_SOURCE_DIR}/lib)
add_executable(learn ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${CMAKE_BINARY_DIR}/libBearLibTerminal.so)

I'm trying to make my executable depend on libBearLibTerminal.so in the same directory, so I can zip them together, unzip on other Linux machine and run executable. But it sems that my executable depends on .../learn/bin/libBearLibTerminal.so, and not on the file in the current executable directory!

Being a complete newbie, I broke my head trying to make my executable be portable. So, I beg you to help - please, explain to me, how I can make libBearLibTerminal.so be shippable with main game file!..
« Last Edit: April 10, 2017, 09:08:06 AM by The Saber Cat »

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #212 on: April 11, 2017, 04:03:13 PM »
Quote from: The Saber Cat
I'm trying to make my executable depend on libBearLibTerminal.so in the same directory, so I can zip them together, unzip on other Linux machine and run executable. But it sems that my executable depends on .../learn/bin/libBearLibTerminal.so, and not on the file in the current executable directory!
In Linux application dependencies (shared .so libraries) are not searched for in the same directory with application executable. By default only a few select system directories (e. g. /usr/lib64) are considered. It is possible to add extra paths to this list while linking the executable, this is what 'rpath' is. CMake automatically adds paths to the libraries from nonstandard locations to the application's rpath, which is why your executable looks for the libBearLibTerminal in the ../learn/bin. It does not depends on that exact file, it depends simply on 'libBearLibTerminal.so', but that path is the only path from the search list where such file is present.

Therefore if you want to mimic Windows behavior of loading libraries from the same folder, you need to manually add the '.' path to rpath of your executable. In CMake it is something along the lines of
Code: [Select]
cmake_minimum_required(VERSION 3.7)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH ".")
project(learn)
...
Though I'm writing mostly from memory.

Another common approach on the Linux is to wrap the application binary in the script which sets LD_LIBRARY_PATH environment variable before launching executable. This environment variable also provides extra search paths for dependencies.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #213 on: April 11, 2017, 04:19:52 PM »
Quote from: Elronnd
First is that setting terminal_set("window.fullscreen = true"); doesn't do anything.  The second is that although if you set the window to be resizeable, you can resize it, if you try to get the terminal size you just get the original size. <...> Interestingly enough, if I alt+enter while within the window, it fullscreens fine.  Even more interestingly, if I set window.fullscreen = true, while the window doesn't get fullscreened, I can then resize it even though I haven't set window.resizeable to true.
I've tested a few combinations of distros, desktop managers and windowing libraries (SDL, GLFW, SFML and my own implementation) and can only conclude that it is a complete and utter mess =(. On the same OS but different DM and vice versa the same X11 app may or may not resize and fullscreen properly. Sometimes it is clear who is wrong, sometimes not. Out of the libraries, SDL is the winner though sometimes even it is powerless.

I've honestly thought I would be able to provide a window implementation which, while not being as feature-rich as others, would be more compact (e. g. SDL is many megabytes in size) and more tuned to the exact situation (e. g. resizing in steps to match cell size). Yep, nope.

I've taken a deeper look at the SDL code and I can downsize it to something reasonable. Believe me, it is not as simple as --disable-everything in ./configure, you can disable almost nothing this way in the current SDL codebase. I've even tried to discuss this on their mailing lists but couldn't get through moderation (wtf?). I probably should file a bug.

The Saber Cat

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #214 on: April 12, 2017, 02:01:40 AM »
Understood, thank you!

Another question.

learn.ini:
Code: [Select]
[Game]
speed = 1

main.cpp:
Code: [Select]
std::cout << terminal_get("ini.Game.speed", "10"); // prints 10
Other values, like terminal window name, are loading perfectly. How can I make it fetch custom values?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #215 on: April 12, 2017, 10:18:45 AM »
Quote from: The Saber Cat
Other values, like terminal window name, are loading perfectly. How can I make it fetch custom values?
Hmm, should have worked. Do you call terminal_get after terminal_open? Try to run the app from a console with BEARLIB_LOGLEVEL environment variable, e. g.
Code: [Select]
~/test$ BEARLIB_LOGLEVEL=trace ./SampleOmniThis will force the library to pring debug info about what configuration file it is using and what properties it has found.
« Last Edit: April 12, 2017, 10:50:54 AM by Cfyz »

Elronnd

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • NetHack and Slash'EM EU server
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #216 on: April 22, 2017, 11:15:25 PM »
Is there a way to underline text or make it blink?  I can sort of make stuff underline by switching to another layer and printing ___, but there's a small gap in between them, and sometimes they overlap with the text in a way that's less than pleasing.  Also, is there a way to get bold or italic text other than loading an alternate font?
Wishes, wishes.  Wish in one hand and do something else in the other, and squeeze them both and see which comes true

 —Roger Zelazny, Nine Princes in Amber

Looks like a fish, moves like a fish, steers like a cow.

 —Douglas Adams, Hitchhiker's Guide to the Galaxy Fit the Fifth

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #217 on: April 24, 2017, 11:39:15 AM »
Quote from: Elronnd
Is there a way to underline text or make it blink?  I can sort of make stuff underline by switching to another layer and printing ___, but there's a small gap in between them, and sometimes they overlap with the text in a way that's less than pleasing.
No, currently there is no such functionality. Underlining is theoretically possible (truetype fonts have some information and for bitmap fonts the library might try to do an educated guess).

Quote from: Elronnd
Also, is there a way to get bold or italic text other than loading an alternate font?
Again, currently no. If you are talking about automatically producing bold/italic variations from a single font, it is technically possible to implement (thickening or shearing the tile) but I think it would look pretty ugly. Ultimately the library would need to operate on relatively small bitmap tiles and geometric transformations of small bitmap images had never produced anything pretty.

Elronnd

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • NetHack and Slash'EM EU server
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #218 on: April 25, 2017, 02:25:06 AM »
Quote from: Elronnd
Is there a way to underline text or make it blink?  I can sort of make stuff underline by switching to another layer and printing ___, but there's a small gap in between them, and sometimes they overlap with the text in a way that's less than pleasing.
No, currently there is no such functionality. Underlining is theoretically possible (truetype fonts have some information and for bitmap fonts the library might try to do an educated guess).

Awww.  In that case, how does the cursor blink work?
Wishes, wishes.  Wish in one hand and do something else in the other, and squeeze them both and see which comes true

 —Roger Zelazny, Nine Princes in Amber

Looks like a fish, moves like a fish, steers like a cow.

 —Douglas Adams, Hitchhiker's Guide to the Galaxy Fit the Fifth

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #219 on: April 25, 2017, 04:04:13 PM »
Quote from: Elronnd
In that case, how does the cursor blink work?
The library cheats by using an internal read with timeout, flipping the cursor visibility every time it, ugh, times out. I've been thinking about blinking and it feels like blinking is just a case of simple animation. It would be nice to solve both at once.

Btw, just a bit better pseudo-underline might be produced by overlaying 0x2581 (Lower One Eighth Block) instead of underscores.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #220 on: May 14, 2017, 01:38:31 PM »
Update 0.15.3 with various fixes: Windows / Linux / OS X / PyPi
  • Add font() function (select the current font by name, closes issue #33).
  • Fix adding sprite tiles to an atlas (closes issue #30).
  • Fix excess generation of 'character replacement' tiles.
  • Fix dynamic tile generation (individual to a font, closes issue #32).
  • Fix configuring several fonts in one set() call (closes issue #34).
  • Retrieve clipboard contents via terminal_get("clipboard").
  • Fix bitmap tileset reverse codepage (sparse tileset) handling.
  • input.cursor-blink-rate=0 disables cursor blinking in terminal_read_str().
  • Fix printing tab characters (configured by output.tab-width option).
  • Fix app hanging on reopening terminal in macOS (see issue #23).
And TODO list is like a few miles long >_<.

quejebo

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #221 on: May 23, 2017, 05:44:18 AM »
Hey, I've been enjoying the library but I have a quick question:

I have a square grid, say 12x12, and I'd like to overlay a thinner font for text on it, say 8x12.  I've found that I can do this with put_ext, incrementing my dx by 8 for every character:
Code: [Select]
for (i,char) in enumerate(text):
    terminal.put_ext(x,y,i*8, 0, ord(char))
But this is rather less than ideal: it means lots of slow looping in python, and prevents me from using the nice annotation syntax (e.g., for color) that exists for print.  Is there a way to accomplish this same purpose with the print function?


Serin Delaunay

  • Newcomer
  • Posts: 13
  • Karma: +0/-0
  • they/them/their
    • View Profile
    • itch.io
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #222 on: May 23, 2017, 09:14:32 PM »
You could use a grid with 4x12 cells, and configure the font with "size=16x16, spacing=2x1". Then square symbols would need 3x1 spacing.

quejebo

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #223 on: May 24, 2017, 06:46:46 AM »
Thanks for the response.  That approach works in this example because they have a nice common denominator, but this isn't always the case for how I'm scaling things.  I suppose the more precise use case here is to easily use separate font scales for the UI from the game's grid -- without the requirement for nice integer ratios between them.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #224 on: May 24, 2017, 06:52:17 PM »
Quote from: quejebo
I suppose the more precise use case here is to easily use separate font scales for the UI from the game's grid -- without the requirement for nice integer ratios between them.
Well, this comes up from time to time... The main obstacle is that text in pseudo-terminal output is not a separate entity, it is the same as other tiles (and vice-versa) and must abide the same rules. When you try to detach text from the grid, different nuances arise. How to remove that text from screen when you can't address it by x, y cell anymore? What z-order does it take, always above the grid? And between each other text piece?