Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: C++ curses  (Read 13571 times)

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: C++ curses
« Reply #15 on: June 08, 2010, 06:53:20 am »

That works, but only if you never want scrolling maps, or different kinds of floor tiles, or a number of other things.  Now, the dirty thing could work, keeping a vector/list of the cells that have changed, but as Blacken pointed out, premature optimization is a really bad idea, so your best bet is just not to worry about it.  Like you said, it's curses, it's not like the drawing code is often the source of a slow program as far as rogue-likes are concerned....

[EDIT]: Yes, I realize you could probably fix it to work with those things, but it'd require that you go back and change it.  It's far easier just to write the drawing code how you want it to work, and optimize it only after you know that the basics aren't going to change any more.
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: C++ curses
« Reply #16 on: June 08, 2010, 05:22:45 pm »

[EDIT]: Yes, I realize you could probably fix it to work with those things, but it'd require that you go back and change it.  It's far easier just to write the drawing code how you want it to work, and optimize it only after you know that the basics aren't going to change any more.
Optimize it only when you actually need the performance improvement, you mean.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: C++ curses
« Reply #17 on: June 08, 2010, 06:17:20 pm »

Good point.  Which with a rogue-like really isn't too likely; at least, not from the drawing code.  AI, path-finding, or something similar can get rather slow if you're not careful, but the drawing shouldn't be an issue.
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: C++ curses
« Reply #18 on: June 09, 2010, 06:46:01 pm »

I can agree with this.
It becomes much more applicable in a 3D application to mess with the draw code,
 but it is not the first place to look for speed boosting.
I rewrote my water physics at least twice to get everything running faster.
At first it couldn't even support the moving water without the frame rate dying,
 but now it supports water, no-lag cave-ins, shadows, and all sorts of stuff.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Kazang

  • Bay Watcher
    • View Profile
Re: C++ curses
« Reply #19 on: June 12, 2010, 05:45:37 am »

While it is a very good idea to know how to implement things like this when programming, using a framework like Visual Studio (assuming you're on windows) can help cut out a lot of the time consuming legwork and makes the job a lot easier.

Learn the principle sure, it's important to do that.  But don't spend large amounts of time writing and using outdated drawing methods, it really is counter productive as you will likely want to replace it with a better system later on.  Example: the huge amount of time and effort it takes toady to merge a basic openGL sdl with his display code.  Unless you want to use curses for purely aesthetic purposes and are not planning to go beyond it in your program, I recommend "skipping" stuff like this in favour of better and more modern methods.

Just thought I would point that out.


Logged

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: C++ curses
« Reply #20 on: June 12, 2010, 01:25:35 pm »

Visual Studio isn't a framework. It's an IDE. That said, yes, it's pretty much the best one out there for C++ development.

And there are a lot of libraries out there that take care of the stupid gruntwork of writing a roguelike. libtcod is horribly designed, but probably the best thing out there right now if you are bound and determined to use C or C++.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Rotten

  • Bay Watcher
    • View Profile
Re: C++ curses
« Reply #21 on: June 13, 2010, 01:49:52 pm »

Well, I hate to bump an old thread with another of my stupid questions, but I spent a day staring at this but everything I do doesn't work.
Basically, I'm writing a loop to dump an array to the screen.
Code: [Select]
int maprows=24;
int mapcols=79;
Code: [Select]
   while (Quit == false)
    {
        int currow=0;
    int curcol=0;

        int MapArray[24][79] =
        {
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        };

        while (currow < maprows)
        {

            while (curcol < mapcols)
            {
                printw(MapArray[currow][curcol]);
                ++curcol;
            }
            ++currow;
        }
[after this is just input stuff which already works fine]
Now here's the error it gives:
line 59 (printw(MapArray[currow][curcol]);)- invalid conversion from int to 'const char*'
This is how the learncpp tutorial handled array loops (I checked to see if I had done anything wrong), minus that I'm using printw instead of cout. Changing the variables to char values gives the same error, even though they aren't integers. What.
 
Logged
True, but at a certain velocity the resulting explosion expels invader-bits at fatal speeds. You don't want to be dropping trogdolyte-shaped shrapnel bombs into your boneworks.
Only in Dwarf Fortress...

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: C++ curses
« Reply #22 on: June 13, 2010, 02:01:53 pm »

printw is designed to work with strings....
from help:
Quote
int printw(fmt [,arg...])
char *fmt;
so it's formated printing function. If you want to print one char with it (although this is strange and not recommended) but you can do it like this:
first change array to char. Then use printw("%c",MapArray[currow][curcol]); Although i'm not sure if it will print 0 char (because it's string termination sign).
Maybe it would be possible to print all the line in one go? something like:
Code: [Select]
while (currow < maprows)
        {
            printw("%s",MapArray[currow]);
            ++currow;
        }
Not sure if it would work, but still it will not accept 0 chars and up to 31 could work funny AFAIK.

Edit: also can't understand why learncpp teaches to use while's for loops. In my view for's are better because you don't need to define counts in the start:
Code: [Select]
for (int currow=0;currow < maprows;currow++)
            for(int curcol =0; curcol < mapcols;curcol++)
                printw("%c",MapArray[currow][curcol]);

Well now that i look at it maybe it's a bit more complex...
« Last Edit: June 13, 2010, 02:05:59 pm by darius »
Logged

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: C++ curses
« Reply #23 on: June 13, 2010, 02:16:53 pm »


Now here's the error it gives:
line 59 (printw(MapArray[currow][curcol]);)- invalid conversion from int to 'const char*'
This is how the learncpp tutorial handled array loops (I checked to see if I had done anything wrong), minus that I'm using printw instead of cout. Changing the variables to char values gives the same error, even though they aren't integers. What.

OK. So did you read the error message? You are attempting to convert an integral value into a const char*. That's not going to be a conversion that's going to get you any results (because a pointer of 0 is the null pointer, and you will segfault). Neither is a char a const char *.

I think you need to do a little more reading about your type system. I could give you the answer, but I'd rather see you figure out what the problem with your conversion is (and darius's method may work, but is decidedly suboptimal; I'd look at why you're having trouble instead of just trying to cargo-cult his code).
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Rotten

  • Bay Watcher
    • View Profile
Re: C++ curses
« Reply #24 on: June 13, 2010, 04:26:14 pm »

Actually, I ended up finding a solution a little while after posting this. I just used Word to mass-replace all the 0's with 46's, changed the array to char and replaced printw with mvaddch. Working fine (well, sort of. There is a bug where it only prints 10 .'s, but at least it starts now...). Thanks for helping, though.

Quote
Neither is a char a const char *.
Yeah, you're right. I don't really see the point of a const char though? The page I read (after googling) made it sound like a variable that cant be changed.
Quote from: bytes.com/topic/c
Code: [Select]
# const char cc = 'A';
# char c = 'B';

# c = 'C';    /* Legal */

# cc = 'Z';   /* will cause a compiler error because it is constant */
What's the point?
Logged
True, but at a certain velocity the resulting explosion expels invader-bits at fatal speeds. You don't want to be dropping trogdolyte-shaped shrapnel bombs into your boneworks.
Only in Dwarf Fortress...

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: C++ curses
« Reply #25 on: June 13, 2010, 05:26:37 pm »

You will probably never instantiate a const char*. Look at what the semantics of const mean in a function declaration.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: C++ curses
« Reply #26 on: June 14, 2010, 07:26:17 am »

Actually, I ended up finding a solution a little while after posting this. I just used Word to mass-replace all the 0's with 46's, changed the array to char and replaced printw with mvaddch. Working fine (well, sort of. There is a bug where it only prints 10 .'s, but at least it starts now...). Thanks for helping, though.

Quote
Neither is a char a const char *.
Yeah, you're right. I don't really see the point of a const char though? The page I read (after googling) made it sound like a variable that cant be changed.
Quote from: bytes.com/topic/c
Code: [Select]
# const char cc = 'A';
# char c = 'B';

# c = 'C';    /* Legal */

# cc = 'Z';   /* will cause a compiler error because it is constant */
What's the point?
Thats only for declarations. If function has const in its arguments it means that "I swear not to change stuff there" e.g
Code: [Select]
f(int *x); can change the value of x;
f(int const  *x); will not change x;
Spoiler (click to show/hide)

as for changing all values, i suggest using loops (way faster IMHO) :)
Logged
Pages: 1 [2]