tapio / rlutil

C and C++ utilities for cross-platform console roguelike game creation.
http://tapio.github.com/rlutil/
229 stars 42 forks source link

[WIN32] Weird behavior lowest-rightmost CMD character #14

Closed Zorgatone closed 8 years ago

Zorgatone commented 8 years ago

I have this sourcecode: Crook - Roguelike (bug-wincmd branch on file src/crook.c, commit 3e2e1ac)

I'm having a very weird issue on the windows' CMD prompt. I am saving the coordinates correctly (AFAICT), and I'm debugging the player position and the arrow pressed.

If you can test this, go to the lower-rightmost position in the terminal. Everytime x == maxx && y == maxy both the debug info and the player are printed one line above

Zorgatone commented 8 years ago

@tapio after further investigation I noticed that when in that position the CMD scrolls down its buffer.

Any way to fix this? Is it a problem with the engine, or shold I just move again to (1, 1) after writing to that position?

EDIT: when I do that and move to (1, 1) again, I can see the CMD quickly scrolling up and down

Zorgatone commented 8 years ago

Maybe we can use a function that can add a character without advancing the cursor? We could add a function like ncurses addch?

nabijaczleweli commented 8 years ago

Can confirm (bug(?))

Zorgatone commented 8 years ago

@nabijaczleweli if you're on windows you can clone the repo and test. I don't know if OS X or Linux have the same issue or not

nabijaczleweli commented 8 years ago

Hrmmm, apparently my message wasn't clear enough. I meant, that I can confirm it (the issue), but am not sure, whether it is a bug.

Zorgatone commented 8 years ago

Oh, ok thanks

Zorgatone commented 8 years ago

Is it possible to modify/print a character on a given position(x, y) without moving the cursor? That will help a lot to solve this.

Something similar to ncurses' addch().

nabijaczleweli commented 8 years ago

Try the one wevuse in cls() to fill the screen with ' ', maybe?

Zorgatone commented 8 years ago

@nabijaczleweli commented on 17 nov 2015, 14:44 CET:

Try the one wevuse in cls() to fill the screen with ' ', maybe?

I don't get what you're trying to say. I don't want to clear the screen :stuck_out_tongue_winking_eye:

nabijaczleweli commented 8 years ago

I meant the FillConsoleOutputCharacter() WinAPI function (or the like)

Zorgatone commented 8 years ago

That won't be of any use if I don't want to fill the entire screen with the same character.

That's not what is causing the problem with the player being in the low-right corner

nabijaczleweli commented 8 years ago

WriteConsoleOutputCharacter() sounds like something we could use

nabijaczleweli commented 8 years ago

How should the function (in rlutil) be called?

Zorgatone commented 8 years ago

I'm used to use ncurses' "addch(char)" and "mvaddch(row,col,char)". I don't know if those names would fit for rlutil though.

Maybe a simpler name would be cool

nabijaczleweli commented 8 years ago

I'm gonna hold off starting work on this, because my other PRs (#17 and #19) explode the codebase quite a lot already (i.e. merging it will be a PITA).

Zorgatone commented 8 years ago

Ok, cool

nabijaczleweli commented 8 years ago

@Zorgatone I was aiming for a different name, because the arguments are in a different order and it will be quite confusing

Zorgatone commented 8 years ago

Yeah ok. What about this?

/* return_type */ setChar(int ch);
/* return_type */ setCharAt(int ch, int row, int col);

//  (returning void for nothing, or int for cursor's current position)
nabijaczleweli commented 8 years ago

int can't be used for cursor position, but, other than that, it looks alright

nabijaczleweli commented 8 years ago

Also works on Linux now

nabijaczleweli commented 8 years ago

How does one even print to an arbitrary position/save the cursor position on Linux (without <ESC>[6n, which doesn't work)? Google just gives me shitposts and repeated data on moving the cursor and querying terminal size.

Zorgatone commented 8 years ago

I have absolutely no idea

nabijaczleweli commented 8 years ago

teethgrind

nabijaczleweli commented 8 years ago

Okay, this looks literally impossible, even using [n]curses (like in https://github.com/nabijaczleweli/rlutil/commit/72f640699cb9108262590916812622cf26757a71) leaves off H1 on the end of each line and requires moving the cursor.

Zorgatone commented 8 years ago

Still somehow world be good to prevent that CMD issue.

Maybe just moving the cursor home every time it goes beyond the maximum lines and maximum columns. Or just using some Windows API to set the buffer's number of rows just to the visible ones.

nabijaczleweli commented 8 years ago

You can locate() to the last position and then setChar() there. Or, alternatively, use the setCharAt() implementation on my fork (on mobile rn, so no link).

Actually, we could just have setCharAt() with a working body on Windooze and an assert() (with an "if you know how to do it, plz show us" message, mebbe)/return an error code.

Zorgatone commented 8 years ago

Oh you already have done those two functions? Nice

nabijaczleweli commented 8 years ago

Well, setCharAt() is a terrible failure on Linux, but it's trivial on Windows: https://github.com/tapio/rlutil/blob/72f640699cb9108262590916812622cf26757a71/rlutil.h

Zorgatone commented 8 years ago

You could have that on windows, and on other platforms just save the old position, move to new position, print character normally, restore previous position.

That's a bit of an hack, but it should work at least for now :laughing:

Zorgatone commented 8 years ago

setCharAt and Test 12: Non-advancing character setting worked on Mac OS X

nabijaczleweli commented 8 years ago

Hrmmm, interesting. It leaves H1 after each line on an sshd-into Ubuntu 13.04 LTS Headless x86 on Windows 10 x86_64

nabijaczleweli commented 8 years ago

@Zorgatone How about Test 13: Positioned character setting?

Zorgatone commented 8 years ago

No wait, nevermind.... On non-blocking input there are some random characters appearing:

Test 8: Non-blocking keyboard input
You should be able to move the '@' character with WASD keys.
Hit Space to continue to the next test.
Turn count: 71149d

                 w              

                                @
Zorgatone commented 8 years ago

Also this on arrow keys:

Test 9: Arrow keys
You should be able to move the '@' character with arrow keys.
Hit Escape to continue to the next test.

        [C                
       ^[[D              @    
                            [[C
      ^[[B                    

                      ^[[A

           ^[[D      
Zorgatone commented 8 years ago

But the 12th test works, haven't seen a 13th though

nabijaczleweli commented 8 years ago

Pull the positioned-character branch on my fork

nabijaczleweli commented 8 years ago

@Zorgatone Those weird results happen when invoked normally or when piping?

Zorgatone commented 8 years ago

Same tests 8 and 9 (printing wasd and arrow characters from input), and this is test 13:

Press any key to continue...r setting
Next ASCII characters should appear rapidly after each other in a 15-width pattern.
!"#$%&'()*+,-./ remain blinking in the same position.
0123456789:;<=>
?@ABCDEFGHIJKLM
NOPQRSTUVWXYZ[\
]^_`abcdefghijk
lmnopqrstuvwxyz
{|}~
nabijaczleweli commented 8 years ago

teethgrind Still OSX? ... Fuck OSX

Zorgatone commented 8 years ago

lolol, it's not the non-standard iTerm here... I don't really care about iTerm at all.

It's the system default Terminal.app I'm talking about, yes still OS X.

Zorgatone commented 8 years ago

What are this two files?

Could we add those and the binaries to the .gitignore and make clean?

TR:rlutil tommaso$ cat Makefile 
CC=gcc
CXX=g++
CFLAGS=-I. -g -O2 -Wall -Wextra

all: test example-c

test: rlutil.h test.cpp
    $(CXX) $(CFLAGS) -lncurses -o test test.cpp

example-c: rlutil.h example.c
    $(CC) $(CFLAGS) -o example-c example.c

.PHONY: clean

clean:
    rm -f test example-c

TR:rlutil tommaso$ make clean
rm -f test example-c
TR:rlutil tommaso$ git status
On branch positioned-character
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    example-c.dSYM/
    test.dSYM/

nothing added to commit but untracked files present (use "git add" to track)
nabijaczleweli commented 8 years ago

These files aren't.

No; they exist only in your head.

Zorgatone commented 8 years ago

They appeared when I runned make.

I've cloned the new repo removing all the old files first

nabijaczleweli commented 8 years ago

s/runned/ran/

Remove them, rerun make. What toolchain?

Zorgatone commented 8 years ago
TR:rlutil tommaso$ ls
Makefile        docs            rlutil.h
README.markdown     example.c       test.cpp
cross-compile.sh    index.html
TR:rlutil tommaso$ make
g++ -I. -g -O2 -Wall -Wextra -lncurses -o test test.cpp
gcc -I. -g -O2 -Wall -Wextra -o example-c example.c
TR:rlutil tommaso$ which gcc; gcc -v; which g++; g++ -v
/usr/bin/gcc
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
/usr/bin/g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
TR:rlutil tommaso$ ls
Makefile        example-c       rlutil.h
README.markdown     example-c.dSYM      test
cross-compile.sh    example.c       test.cpp
docs            index.html      test.dSYM
TR:rlutil tommaso$ 
Zorgatone commented 8 years ago

See the updated log, I forgot to paste it

nabijaczleweli commented 8 years ago

W_h_ell, that's surprising. Works On My Machines:tm:, though

nabijaczleweli commented 8 years ago

Also, Google it

Zorgatone commented 8 years ago

We can just add an entry on .gitignore and make clean for any files with the dSYM extension though.

Just to clean the crap out before pulling other changes.

Yeah I googled that XD

Zorgatone commented 8 years ago

That's probably because my toolchain is logged in with my Apple Developer ID (OS X, iOS), and is generating those.

The issue wasn't what exactly are those files, but if we could just get rid of those doing make clean, and ignoring them from the repo in .gitignore.

If those aren't just when building your fork, I'll open a PR separately.