|
|
This thread is locked; no one can reply to it.
|
1
2
|
| Quick question on newlines.. |
|
blargmob
Member #8,356
February 2007
|
Is there a newline sequence that is supported for allegro's text output methods? It seems that \n dudn't work. --- |
|
kazzmir
Member #1,786
December 2001
|
no |
|
blargmob
Member #8,356
February 2007
|
Dang, thanks anyways.. --- |
|
Neil Black
Member #7,867
October 2006
|
There isn't? That seems kinda not cool. Brings to mind the fact that Allegro makes cin unusable but offers no replacement...
|
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Write a wrapper function for multiline text output. Give it the starting string including newlines , parse it into lines , use function parameters for the starting position , justification , vertical line spacing and text color for foreground/background and use the allegro text functions to display each line in the proper placement. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Timorg
Member #2,028
March 2002
|
Well I don't see what std::cin has to do with text output. And std::cout still works, it outputs data to the console if one is available, otherwise the output is hidden. as with std::cin, it should read from the console, but if is a blocking function, so your game will pause while it gets input. I am off to check that... -Tim Edit: It definitely applies to linux, buggering off to windows to test mingw Under both it spawns a console when you call std::cin. ____________________________________________________________________________________________ |
|
Neil Black
Member #7,867
October 2006
|
It has nothing to do with text output, it's just something that's on my very short list of complaints about allegro. This thread lengthened that list to two things.
|
|
Timorg
Member #2,028
March 2002
|
A way to implement Edgar Reynaldo's idea could be. You could scan the string, when you find a newline, replace it with '\0', output the string, move your pointer to the character after the newline, move down 10 pixels (with the default font) and repeat til you reach the '\0'. Then run back along the string putting back all the newlines. If you complain enough, someone will implement it for you, as its quite trivial. If I get bored later, I might even bother. -Tim ____________________________________________________________________________________________ |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I think Timorg's improvement would be faster and pretty easy too. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Thomas Harte
Member #33
April 2000
|
Quote: I think Timorg's improvement would be faster and pretty easy too. There's absolutely no way you can justify not using the text_height function though. [My site] [Tetrominoes] |
|
OICW
Member #4,069
November 2003
|
So the multiline output is solved. Now as far as input goes you can use this. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Audric
Member #907
January 2001
|
Just a little warning on Timorg's version: It's extremely efficient but you had better document on your function that it modifies the string it received as input. |
|
OICW
Member #4,069
November 2003
|
That depends whether you are doing those operations on the input string or you're copying it to some teporary string. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Timorg
Member #2,028
March 2002
|
I got bored, and as with what Audric was saying, this code isn't thread safe, if you try to use the string elsewhere at the same time, you will get strange things happening. As for the other part of what Audric suggested, if your using STL strings, and call std::string.c_str() and pass it to the function, it depends on the implementation of STL to what will happen. Could be fine or yet again strange things might happen. Thomas Harte: I didn't mention text_height function, cause I was trying to keep the example simple. ------------- Edit: I got bored again, here is a c++ implementation that uses std::string
This is thread safe, and you can pass a null terminated string into it and it will work fine. ____________________________________________________________________________________________ |
|
Audric
Member #907
January 2001
|
I like the cleverness of the first solution anyway. My own hack would NOT have changed back the '\0' to '\n' I've been maintaining a codebase which had several..hmm..peculiarities like this, and as long as the prerequisites are listed at the function declaration, it's extremely reliable. |
|
Arthur Kalliokoski
Second in Command
February 2005
|
If you guys keep going, you'll come up with textprintf_ex() ! They all watch too much MSNBC... they get ideas. |
|
kazzmir
Member #1,786
December 2001
|
Except textprintf_ex doesn't handle newlines which is what prompted the whole debate. |
|
Kitty Cat
Member #2,815
October 2002
|
You don't need to scan the string manually for newlines. strchr is your friend:
-- |
|
Neil Black
Member #7,867
October 2006
|
Quote: Now as far as input goes you can use this. Yeah, but that seems a bit much just to let the player name his character...
|
|
Timorg
Member #2,028
March 2002
|
After fixing the errors in Kitty Cat's code. ie. removing the redundant 'i' variable, and changing the return value to void. I then made a version of my code where it duplicates the string, before messing with it, so that I wouldn't have to put all the '\n's in the right place. I then stripped out the allegro stuff, and made a program that calls each function 10000000 times.
I then profiled the program and got the following results. % cumulative self self total time seconds seconds calls ns/call ns/call name 58.79 9.67 9.67 10000000 967.05 967.05 textout_ml_ex0 32.83 15.07 5.40 10000000 540.03 540.03 textout_ml_ex1 3.83 15.70 0.63 10000000 63.00 63.00 my_textout0 2.61 16.13 0.43 10000000 43.00 43.00 my_textout1 1.95 16.45 0.32 main As you can see Kitty Cat's function is much more efficent than mine, its actual 15 times faster than my original code. Then if you optimize it (-O1) the difference is even more pronounced Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls ns/call ns/call name 62.63 4.44 4.44 10000000 444.02 444.02 textout_ml_ex0 31.31 6.66 2.22 10000000 222.01 222.01 textout_ml_ex1 2.19 6.82 0.16 10000000 15.50 15.50 my_textout0 2.05 6.96 0.15 10000000 14.50 14.50 my_textout1 1.83 7.09 0.13 main Which brings me to the final conclusion... If you want multi-line text output use Kitty Cat's code (after you modify it so that it will actually compile without errors. -Tim ____________________________________________________________________________________________ |
|
OICW
Member #4,069
November 2003
|
Quote: Yeah, but that seems a bit much just to let the player name his character... With that code you can do pretty much everything you want. I have a working console using that code for input. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Neil Black
Member #7,867
October 2006
|
I was saying that if the only reason you wanted text input was to get the player's name, that would be a lot of code to do it with. It's worth it if you're actually using a lot of text input, but it's just too much if you only use it once, which is about how much I would use it in a game.
|
|
OICW
Member #4,069
November 2003
|
As far as I know there's no other simple way of doing this in Allegro. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Neil Black
Member #7,867
October 2006
|
I know, that's the problem. Allegro include functions to replace (and vastly improve upon) cout, but completely ignores the need for input. I'm going to use the mind control routines in Allegro 5 to make someone put input routines in Allegro 6.
|
|
OICW
Member #4,069
November 2003
|
The problem is with how the keyboard is managed. You can write your scanf/cin function that will hide that code above from you. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
|
1
2
|