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

dividee

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #135 on: September 26, 2016, 08:44:43 PM »
If anyone is interested, I ported the Omni samples to Python. I just updated them for 0.14.8. Most of the time, the translation from C++ is quite literal. It runs in both Python 2.7 and 3.5 (and probably others). And also on pypy 5.3, although it's very slow on pypy because of ctypes...

Here is the link: https://github.com/ibatugow/blt_samples

You should be able to just download or clone the repository and run the samples in the Python directory. You can either run each sample individually or sample_omni.py for the whole thing.

gyscos

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #136 on: October 12, 2016, 10:11:19 PM »
For archlinux users, there is now an easy way to install the library.

infinity

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #137 on: October 15, 2016, 05:37:35 AM »
Great program, but I seem to have trouble printing unicode characters (ex. β) in Python. Could anyone give me an example of how I would get the terminal to print unicode characters as well as ASCII? I am using DejaVu fonts so they support unicode.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #138 on: October 15, 2016, 02:10:22 PM »
It should work as long as Python does not lose unicode along the way:
  • make sure the source code is saved in suitable encoding, e. g. utf-8
  • make sure that encoding is conveyed to Python with 'coding' comment
  • in Python2 use unicode strings
Code: [Select]
# -*- coding: utf-8 -*-
from bearlibterminal import terminal
terminal.open()
terminal.set('font: ./DejaVuSansMono.ttf, size=16')
terminal.printf(2, 1, 'β')  # would be u'β' if Python2
terminal.put(2, 2, 'β')
terminal.refresh()
terminal.read()
terminal.close()

NoahTheDuke

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #139 on: November 15, 2016, 05:03:56 AM »
Hey all, it's been a little while.

I'm trying to build a small roguelike using the Python wrapper, and I can't seem to get key releases to register. Any ideas how I've messed this up?

Code: [Select]
import PyBearLibTerminal as terminal

terminal.open()
terminal.printf(2, 1, 'β')
terminal.put(2, 2, 'β')
terminal.refresh()
while True:
    if terminal.has_input():
        key = terminal.read()
        print(key)
        if key == terminal.TK_Q | terminal.TK_KEY_RELEASED:
            print('released')
            break
        elif key == terminal.TK_Q:
            break
terminal.close()
produces
Code: [Select]
.../Programming/Python/roguelike python3 test.py
4
22
7
44
20
.../Programming/Python/roguelike
Has anyone experienced this before? Have I done something wrong or set something up wrong? I haven't tried this on my Windows machine, but I'll be sad if I can only access key releases on Windows.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #140 on: November 15, 2016, 04:06:24 PM »
Quote from: NoahTheDuke
I can't seem to get key releases to register.
This is intended. To mimic the most basic terminal input, by default the library reports key presses only. If you need some extra (key releases, mouse), you have to enable that via 'input.filter' option, e. g.
Code: [Select]
terminal.set('input.filter=[keyboard+]')It is documented at reference/input/input.filter.

The "[keyboard+, mouse]" notation feels a bit clunky, but I just can't think up a better one.

NoahTheDuke

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #141 on: November 16, 2016, 01:59:36 AM »
A-ha! Finally, an answer. Thanks for pointing that out; shoulda read the spec closer!

Tilded

  • Newcomer
  • Posts: 49
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #142 on: November 21, 2016, 04:23:38 AM »
Hi, I'm starting a new project using bearlibterminal and python, and its going awesome so far! Thanks for this wonderful library

tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #143 on: November 28, 2016, 08:09:36 PM »
I'm converting a project from libtcod to bearlibterminal because of various features I liked. Everything seems to be going well except for keyboard inputs. It appears as though an extremely large buffer of input commands are being kept when a user holds down a key. Is there a way to avoid this behavior? or to delete the queue on demand?

Ive tried using the non-blocking terminal.has_input() prior to calling terminal.return. But i get the same input lag no matter how I do it.

Code: [Select]
def read_key_int():
    while terminal.has_input():
        return terminal.read()
    return None

Any help would be greatly appreciated.

Thanks!

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #144 on: November 28, 2016, 10:57:37 PM »
Hmm. BearLibTerminal does not do anything out of ordinary here. It accepts input at the same rate it comes from the OS and keeps it until it is read, pretty much just like any other app would. You shouldn't be able to enqueue a significant amount of keystrokes unless the application is particularily lazy with input. Even if you redraw a whole screen every read, it should not be noticeable until you are consistently generate more that 60-80 keypresses per second =).

Do you have a minimal working example illustrating your problem?

The non-blocking read code you posted will not help clearing the queue: it won't read more or faster than a regular read would (but it will exit faster and more frequently). If you want to flush the input, you need a proper cycle:
Code: [Select]
def clear_input():
    while terminal.has_input():
        terminal.read()
Obviously this will lose all those buffered keystrokes.

Most of the time you should not have to clear anything, though. Losing input is not good and it's more robust to shape the control flow so that a sudden bunch of keypresses do not surprise the program that much.


tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #145 on: November 29, 2016, 02:21:38 PM »
That clear function solved my issue. Its not the prettiest solution, but it works for now as there appears to be no noticeable input loss from the user.

It might have something to do with how time/turns are handled in my scheduler func.

Thanks for the quick reply!

Also:
Is there a way to write to the states?

For example if I want to move the mouse cursor to a cell with a line of code.
in libtcod there is:
Code: [Select]
libtcod.mouse_move(x, y)

that moves it to certain pixel coords.
« Last Edit: November 29, 2016, 03:55:23 PM by tapeworm711 »

Tzan

  • Rogueliker
  • ***
  • Posts: 193
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #146 on: November 29, 2016, 06:18:40 PM »
When I was doing a tile game in Java, I would get the input and put it in a que.
So multiple clicks might be in the que after a unit is done moving.
But then the next unit would use them, we dont want that.
So I always clear the que at the end of a units turn.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #147 on: November 30, 2016, 11:58:40 AM »
Quote from: Tzan
But then the next unit would use them, we dont want that. So I always clear the que at the end of a units turn.
Yep, discarding input is okay when you're doing it deliberately. But by that time you already know what is what.
Nuance is, clearing input just to make the whole thing work may indicate a flaw in control flow. Or may not, but my experience says chances are high.
A simple (maybe too simple, but obvious) example would be accidentally doing things in draw-read-refresh order. It displays the scene one frame late and does introduce a visible lag.

Quote from: tapeworm711
Is there a way to write to the states?
No, those states are intended to be, well, just the current state of things. Modifying is done through terminal_set -- or a separate function if the action is frequent and important enough (e. g. terminal_layer).

Setting mouse position is a questionable action. For once, I'd never do that in my own program because as a user I'd really hate for mouse to jump on screen out of my control. I might add the functionality just for completeness sake but it has quite a low priority. Unless you provide a compelling use case =).

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #148 on: November 30, 2016, 01:17:19 PM »
I've been fiddling with bitmap fonts in C# and there's a fairly interesting effect when using bitmap font without specifying size. It opens a white full screen sized window and nothing else.

Also, are http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/console_set_custom_font.html?c=false&cpp=true&cs=false&py=false&lua=false TCOD layouted fonts supported?
« Last Edit: November 30, 2016, 01:19:40 PM by Aukustus »

tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #149 on: November 30, 2016, 09:10:01 PM »
The use case was for ranged combat:


User pressed "f" to enter Fire-Mode.
Program figures out closest targetable monster.
Reticle is placed over that monster.
If user presses "f" mode, targets will cycle between those available.
But use can "free-aim" by using the mouse, when user moves mouse reticle and firing line follows mouse in circle.
(NOTE: it felt more natural to move the cursor to the reticle than to have it just follow relatively. This was a minor thing, so I took it out)


NOTE: in the python bindings i'm using: TK_MOUSE_MOVE state is ALWAYS 0. (using check, its always False. Found that odd. all other mouse states appear to be working correctly.

Additionally i'm not sure how to get bearlib to read the "box drawing acsii" from my PNG file instead of the default. Even using your yoshi_island font the boxes draw standard when addressing them via unicode (ex: 0x2502 prints a |, regardless of the glyph in the .PNG)

Enjoy my barrage of ?'s!!