Closed ghost closed 8 years ago
I'm a bit confused by "The pause menu is a screen, not a terminal, ..."
You can use any layer (terminal, screen, gui2), but you should probably stick to that layer throughout the program. Having some threads write directly to a Screen, and others directly to a terminal pretty surely will lead to chaos.
Anyway, it seems not at all surprising to me, that if you don't somehow notify the enemy-threads of pause-mode that they will just continue. You could let all enemy-threads take a lock on some "pause"-Object and then quickly release the lock. When in pause-mode you let the main-thread lock the pause-object, and all enemies will block until you release it in main thread.
I think you need to apply one of architectural pattern which will help you with designing interactions between components. Please consider something like MVC https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller It is battle tested pattern to deliver and connect components in projects like yours. Your model - dungeons, enemies and of course your player can be implemented as a domain model without any dependencies to view. This will facilitate your tests of domain objects and interactions between them. I don't think you should implement enemies as separate threads (this is too much overhead with this approach). I think you should put multithreading in view layer to render model to users.
Lanterna works in three layers, Terminal -> Screen -> TextGUI, each building on top of the previous one. As @avl42 is noting, you probably want to choose one of these (depending on how low-level access you need) and stick to it. Don't think of Screen as a GUI element, it works like a buffered image of the terminal content and lets you manipulate individual "cells" just like you would do with pixels when programming normal graphics. You would have one Screen object that is using for the whole application and build your logic (possibly containing multiple different kind of 'screens' (in the traditional sense)) on top of it.
In general, lanterna is thread-safe, or at least I aim for it to be. If you find issues, like race conditions or concurrency errors, while working with multiple threads to a single Terminal/Screen/TextGUI, please let us know, preferably with some information on how to reproduce.
I'm going to pre-emptively close this, please re-open if you have additional input on this issue
Hi everybody,
currently I try to programm a dungeon crawler with lanterna. In doing so, I want to have my enemies as seperate threads. According to what they print out in the IDE, they work and change their positions, but that isn't printet on the terminal.
If I enter the pause menu it get's even weirder. The pause menu is a screen, not a terminal, and if I don't stop the enemy-threads, they are displayed in the screen.
Can someone help me? What do I have to pay attention on if several threads want to access the terminal?
thanks in advance Tschokolov