Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How does DF handle it's UI?  (Read 1483 times)

Arkenstone

  • Bay Watcher
  • Perfect Clear Diamond
    • View Profile
How does DF handle it's UI?
« on: June 14, 2011, 08:24:56 am »

Hello, I've been trying to make a DF-style TUI (Terminal User Interface) for some time now, but I've been having some problems.  I can do the graphics easily enough with a normal graphical output, (although I've been having trouble finding one that will take individual pixel color assignments without linearizing) but what I haven't been able to find is a way to read the keyboard in real-time.

Nobody at my college seems to know this, so I must resort to asking if anyone on the forum knows.  I'd prefer the answer in C++ (or better yet, an assembly language) but I'll take any form I can get.  Oh, and if you can tell me how to read the CPU's timer, that'd be nice too.


Oh, and to clarify before someone makes the mistake: I do not want a program that will do this for me.  I actually want to do as much as possible myself, the more control I have the better.  I only want a way to read what keys are being (or have been) pressed; I can do all the looping for a real-time reading of said keys easily enough.  I also have an idea for having keystrokes being stored on a queque should some actions take a while, so please don't go into multithreading or anything like that.
Logged

Quote from: Retro
Dwarven economics are still in the experimental stages. The humans have told them that they need to throw a lot of money around to get things going, but every time the dwarves try all they just end up with a bunch of coins lying all over the place.

The EPIC Dwarven Drinking Song of Many Names

Feel free to ask me any questions you have about logic/computing; I'm majoring in the topic.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: How does DF handle it's UI?
« Reply #1 on: June 14, 2011, 08:32:17 am »

It's platform-specific. What platform are you coding for?
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Arkenstone

  • Bay Watcher
  • Perfect Clear Diamond
    • View Profile
Re: How does DF handle it's UI?
« Reply #2 on: June 14, 2011, 08:59:03 pm »

Well, Windows/PC I suppose; but I wouldn't mind knowing methods for all the platforms...  :P
Logged

Quote from: Retro
Dwarven economics are still in the experimental stages. The humans have told them that they need to throw a lot of money around to get things going, but every time the dwarves try all they just end up with a bunch of coins lying all over the place.

The EPIC Dwarven Drinking Song of Many Names

Feel free to ask me any questions you have about logic/computing; I'm majoring in the topic.

Urist McDepravity

  • Bay Watcher
    • View Profile
Re: How does DF handle it's UI?
« Reply #3 on: June 14, 2011, 11:00:43 pm »

Hello, I've been trying to make a DF-style TUI (Terminal User Interface) for some time now, but I've been having some problems.  I can do the graphics easily enough with a normal graphical output, (although I've been having trouble finding one that will take individual pixel color assignments without linearizing) but what I haven't been able to find is a way to read the keyboard in real-time.
DF uses OpenGL for rendering and SDL for input (mouse and keyb) processing.
This part is open-sourced, so you can look at the code at Baughn's repository at github: https://github.com/Baughn/Dwarf-Fortress--libgraphics-
Logged

Ethicalfive

  • Bay Watcher
    • View Profile
Re: How does DF handle it's UI?
« Reply #4 on: June 15, 2011, 01:32:20 am »

Not really sure if I quite understand, but Autohotkeys (C-C++ scripting language) is built for input-output handling, has COM and DLL support.. Reads key inputs and sends a range of key outputs, decent GUI support, tcp/ip capabilities.

Maybe DFhack can read DF's action buffer or whatever it uses to store keypresses(not sure it does buffer them directly though).

Anyhow, take a look at DFhack and Autohotkeys, either of those may be useful to you.
Logged
Urist McMiner Unearths a strange pad. He trembles as he inspects it's time saving features. Knowing no 1 dwarf must posess this power, he quietly drops it into the nearest chasm and never speaks of it again.DwarfPad

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: How does DF handle it's UI?
« Reply #5 on: June 15, 2011, 04:07:54 am »

Well, Windows/PC I suppose; but I wouldn't mind knowing methods for all the platforms...  :P
In a Windows app, the best method (unless using a layer like DirectX or SDL) is to handle the WM_CHAR, or WM_KEYDOWN and WM_KEYUP window messages. You'll always get the keydown and keyup messages even for short presses, it's a billion miles better than polling the key states.
For a console app use _kbhit() and _getch() (I think)
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Urist McDepravity

  • Bay Watcher
    • View Profile
Re: How does DF handle it's UI?
« Reply #6 on: June 15, 2011, 05:34:58 am »

unless using a layer like DirectX or SDL
I'd strongly advice against using any win-specific stuff directly for any big project. Why lock yourself into windows-only, and rely on low-level API while there are many good cross-platform libraries for that?
SDL is good for starters, altho its graphics subsystem isn't too great.

Oh, and make sure you handle unicode correctly. World is not limited to ASCII, and different locales are constant source of all kinds of problems.
Logged