Git Product home page Git Product logo

Comments (6)

bastienleonard avatar bastienleonard commented on September 3, 2024

I just started playing with your library, and I noticed that not binding to the root console causes the console to be destroyed. It makes sense, but coming from the C and Python versions it took some time to figure out what was wrong. (I expected to be able to pass () or something similar to the functions that take a console parameter.)

I'm not sure if anything needs to be changed beside adding a warning for new users, I just wanted to give my point of view after using your library for the first time.

from tcod-rs.

tomassedovic avatar tomassedovic commented on September 3, 2024

Thanks for the feedback!

What exactly do you mean by "not binding to the root console"? Are you calling Console::init_root(...), ignoring the return value and then trying to use something like put_char(0, 40, 25, '@', ...) where 0 is supposed to mean the root console?

Those parts were pretty much the first thing I wrote when I started with Rust so there's a very good chance they're either flat out wrong or not particularly idiomatic.

If you could post a code snippet of what you're trying to achieve and what your failed expectations are, that would be fantastic. I certainly don't want this to be confusing to the existing libtcod users coming from C or Python (other than Rust being a different language).

from tcod-rs.

bastienleonard avatar bastienleonard commented on September 3, 2024

I don't have the exact code I had written, but I believe I wasn't calling any method that requires a console instance, I was just trying to get the basic event loop working.
I was wondering why the window kept disappearing, until I realized I actually needed the console instance.

from tcod-rs.

tomassedovic avatar tomassedovic commented on September 3, 2024

Thanks, I see what you mean now.

You're right. This is confusing and it's reasonable to assume that people will start from the bare minimum and work their way up. The root console object shouldn't be necessary unless you're using console-specific commands such as clear, set_char, etc.

On the other hand, the non-root consoles have to have a destructor which calls TCOD_console_delete when they go out of scope (otherwise you get unsafe behaviour).

So how about something like this?

  • Console::init_root will return the root console, just like it does today, but you're free to ignore it and nothing will get destroyed.
  • Because you can ignore the root console but you may end up needing it later, it will also be available as a tcod::ROOT_CONSOLE const object.
  • Non-root consoles will get created by Console::new(...) and be dropped when they go out of scope just like today.
  • TCOD functions that can be used both on root and non-root consoles will be methods of Console
  • TCOD functions that can only be used on the root console will become static methods of Console (that's mostly how it is now but some may still be non-static, I'll need to check this)

I do want to add more documentation eventually, but I think this should not present any nasty surprises to existing libtcod users. Do you agree?

from tcod-rs.

tomassedovic avatar tomassedovic commented on September 3, 2024

@bastienleonard I've pushed something out, it should address the issue you were having.

I've added an examples that seems similar to what you described:

https://github.com/tomassedovic/tcod-rs/blob/master/examples/minimal.rs

Prior to this patch, the window closed immediately but the program kept running (not good), afterwards the window stays up.

Please let me know if this makes sense and if you have any other issues / confusion coming from C/Python.

from tcod-rs.

bastienleonard avatar bastienleonard commented on September 3, 2024

Thanks for the update Tomas, everything looks good to me.

from tcod-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.