Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 1999
Offline Last Active Today, 03:44 AM

Posts I've Made

In Topic: [C++] Changing Fore And Back Color Of Text

20 July 2016 - 12:53 AM

Thanks for the replies, in the meantime I've also been searching some more on the internet and it seems that newer version of dwarf fortress which can be run on linux seem to use SDL, so I'll look into SDL, which also would give me a system to handle input more easily, because I was planning to use getch, but it is a bit annoying when it comes to arrow keys and things like that.


Even if you were to use OpenGL directly, you would still want SDL (or something similar, like GLFW) to handle window creation and input in a cross-platform manner. I still recommend libtcod. It uses SDL for input and such. More importantly, it has several features that, if you start from scratch, you would need to implement yourself when you need them, such as a 'console' to draw your ASCII characters to, loading of ASCII fonts and tile sheets, pathfinding & line of sight, and more. You can choose between renderers based on SDL and OpenGL, and can implement any custom rendering you need on top.

Of course, if you want to do it all from scratch, that's fine, but libtcod will save you a good bit of time. I'm not a fan of its API myself, but it's the most complete solution I know that's usable in multiple languages.

In Topic: [C++] Changing Fore And Back Color Of Text

19 July 2016 - 01:08 AM

The OpenGL renderer in DF was implemented quite some time ago. You can see several old bug reports for it in their issue tracker.

And for clarity, I wasn't recommending the OP to use OpenGL, but rather libtcod. My intent was to express that most such games take that approach these days and libtcod is an easy way to get going with it. It can use either SDL or OpenGL under the hood.

In Topic: [C++] Changing Fore And Back Color Of Text

18 July 2016 - 11:56 PM

@OP: Dwarf Fortress is not using the system terminal/console for graphics. It has its own rendering system. Two actually, one using SDL and one using OpenGL. While some 'old skool' ASCII games do have support for the system terminal, most of them still have custom renderers. libtcod is pretty widely used for this sort of thing. See CogMind for a relatively popular recent example using it.



If you aim in the direction of Dwarf Fortress you might be better served by something like pdcurses. There is also libtcod but there are some design decisions in there that never sat well with me and it's not in active development. Different libraries may have sprung up since the last time I investigated the DF-related ecosystem though.

FYI, libtcod is still active under a different maintainer over at bitbucket.

In Topic: Whats the difference between static, inferred and dynamic types

19 June 2016 - 12:09 PM

Static types are fixed. Variables are declared as specific types and their types don't change. 

// x is forever an int
int x;

Dynamic types need not be declared and the type can change. Variables can be initialized with one type and later assigned a different one.

// x is an integer type of some kind
var x = 10;

// Now it's a string type
x = 'ten'

Type inference occurs when no type is specified and the compiler determines what the type should be based on the type of the initializer. The dynamic type example I show above uses type inference for both the initialization and the assignment. C++ and D also support it.

// In this D code, x is inferred to be an int and y a float,
// but they are still statically typed (i.e. the types can't be changed)
auto x = 10;
const y = 20.0f;

In Topic: Trying to remove bullets and get 'java.util.ConcurrentModificationExcepti...

18 June 2016 - 10:49 AM

An alternative to GlassKnife's solution is to add the bullets you don't want to delete to the second ArrayList and just zap the rest from the original, then swap them out.

ArrayList<Bullet> bullets= new ArrayList<>();
ArrayList<Bullet> backBuffer = new ArrayList<>();
for( Bullet bullet : bullets ) {
   if( !outOfBounds(bullet) )
ArrayList<Bullet> tmp = bullets;
bullets = backBuffer;
backBuffer = tmp;

This avoids all the shuffling of items that goes on under the hood when removing elements from an ArrayList.