Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [DF HACK] How to scan very fast the on-screen characters?  (Read 2868 times)

jeancallisti

  • Bay Watcher
    • View Profile
[DF HACK] How to scan very fast the on-screen characters?
« on: November 01, 2013, 01:12:48 pm »

Hello,

I have a personal project I'd like to kick off on DF and I don't know how to start.
My goal is to have a program written either in C++ or Lua, that would scan very quickly (let's say at least 30 times/second) all the characters displayed in the DF window.
I don't know what's the best approch to that :
1) something external to DF (with the proper charset/skin it shouldn't be too hard to code a fast character recognition thingie)
2) something internal to DF: does DF Hack allow to read memory in order to know what's displayed in DF, almost real-time?

Tell me what you think.
Logged

Godlysockpuppet

  • Bay Watcher
  • [Insert wit here]
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #1 on: November 01, 2013, 01:47:40 pm »

 (let's say at least 30 times/second)
Right there. That's going to be an ENORMOUS hit on your fps.
Also.... what is the point of this?
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #2 on: November 01, 2013, 05:07:47 pm »

Check out the source for DFTerm3

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #3 on: November 01, 2013, 05:47:44 pm »

OK I will. And it could be 10 or 5 times per second.
But still: does DFHack expose the characters currently displayed on-screen? I don't know to what extent it allows to manipulate DF's in-memory data.

@putman : I've quickly checked it out and this seems to be a great clue towards my goal. Thanks a lot!


« Last Edit: November 01, 2013, 05:49:19 pm by jeancallisti »
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #4 on: November 01, 2013, 07:28:23 pm »

does DFHack expose the characters currently displayed on-screen?
Yes, it does, provided you check it at the appropriate point in time. The DFTerm3 DFHack plugin seems to just grab the screen state whenever the remote client requests it, so it might be prone to errors (in the form of grabbing the screen contents in a half-updated state).

If you inject your own Renderer object (as the experimental "dfstream" plugin does), then you can capture every frame DF renders and do whatever you want with it (in the case of dfstream, it sends it through a TCP socket so others can look at it, plus it forwards the data back to the currently configured renderer so you can keep playing the game).
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #5 on: November 01, 2013, 08:11:01 pm »

The DFTerm3 DFHack plugin seems to just grab the screen state whenever the remote client requests it, so it might be prone to errors
Well that's a relief. It's all in Haskell. Ouch! Crisis averted.

If you inject your own Renderer object (as the experimental "dfstream" plugin does),...
That's exactly what I want!
Logged

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #6 on: November 02, 2013, 01:13:42 pm »

I'm new to Dwarf Fortress programming (i.e. DFhack plugin programming).
Where is "df/renderer.h"? Is it part of the DFHack project, or is there a DF SDK? I couldn't locate that file in the DFHack github.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #7 on: November 02, 2013, 02:22:41 pm »

It's generated from this.

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #8 on: November 02, 2013, 07:01:55 pm »

Thanks again for answering.
I'm an ok programer but i'm an awful compiler. What do you mean "generated from" ? Is it all taken care of by CMake and/or  XML::LibXML and XML::LibXSLT, or am I missing a step? I'll ask the question again if I fail to follow the instructions in the "Windows" section of the tutorial.

Back on-topic: i'm wondering what would be the smartest thing to do:
- implement my very own renderer class,
OR
- simply connect (locally) to dfstream
as a client, using the services it offers. Is it actually functional?
« Last Edit: November 03, 2013, 06:56:17 am by jeancallisti »
Logged

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #9 on: November 04, 2013, 07:00:45 am »

bumping my question about dfstream ^
Logged

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #10 on: November 04, 2013, 08:11:16 am »

Can't answer what would be the best for you (because i don't know WHY you would want to scan the screen) but imho it would be better to make your own renderer. Dfstream was made for a particular reason and you would have to work around your ideas to fit the dfstream. Also if you really need speed the custom renderer would be faster than renderer+tcp/ip to get the buffers

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #11 on: November 04, 2013, 09:52:25 am »

Can't answer what would be the best for you (because i don't know WHY you would want to scan the screen) but imho it would be better to make your own renderer. Dfstream was made for a particular reason and you would have to work around your ideas to fit the dfstream. Also if you really need speed the custom renderer would be faster than renderer+tcp/ip to get the buffers

Makes a lot of sense. Thanks!
Logged

jeancallisti

  • Bay Watcher
    • View Profile
Re: [DF HACK] How to scan very fast the on-screen characters?
« Reply #12 on: November 05, 2013, 06:24:17 am »

Basically, what I want to do is :
- capture the whole Dwarf Fortress screen (map AND gui on the side -- for now I'm not too worried about plugins additional windows, like Dwarf therapist and such) every once in a while (I've reduced my goals again: 5 times/sec ought to be enough)
- it needs to be a consistent state of the game (no half-rendered screen, with the upper part being the new frame, and the lower part the previous one!)
- then I run my own post-processing algorithm on the set of characters -- possibly in a separate thread.
- I have my own gui open alongside, where I ouput the results (by the way that will need to be graphical. I'll need to start looking at the way SDL can be initialized and used correctly in DFHack)

The reason why I'm reading only the final output (instead of trying to use fancy functions to get data directly from the game's core) is because I want my plugin to be as simple as possible, and to have a high maintainability. No matter what changes are made to data structure and stuff, it will still work as long as it can "read the screen", like a human. Maybe I'll reconsider that later. But for now I'm trying to whip together a quick prototype.

I'm bumping into sync problems: I don't know if the renderer class is meant to be used "as-is", and if there is concurrential access to its inner data -- or if I can just read it anytime.

I was told to get inspiration from DFTerm. But DFTerm is gigantic. DFTerm3 is in Haskell, and I'm totally unable to understand anything. DFTerm2 is in C++ -- I'll try to understand the design, but the synchronization methods are not usually what catches the eye when reading through. They're often partly implicit, if you get me.
« Last Edit: November 05, 2013, 06:34:45 am by jeancallisti »
Logged