Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Okay, that's what I've got so far for my new game. It's all rendered in real time, but of course, I'll need to create a custom chat system to go with it.
Atm I'm thinking of creating an array of strings to hold each line, with a function to make sure the characters don't go over the maximum allowed per line.
But if I did that, I would need to re-dim the array each time a new line comes in and before that I'd need to store the existing strings into a temporary array.
Another pro to this method is people can easily scroll through the text one line at a time by simply clicking a button and changing a variable.
Code: For i = SelectedLine to SelectedLine + 10
Text_Rect.Left = 22
Text_Rect.top = 340 + (i * 15)
Text_Rect.Right = 22 + MaxChatLength
Text_Rect.bottom = Text_Rect.top + 15
Direct3DX.DrawText Main_Font, D3DColorRGBA(0, 0, 0, 200), StoredChatArray(i), Text_Rect, DT_TOP Or DT_LEFT Or DT_WORDBREAK Or DT_NOFULLWIDTHCHARBREAK
Anyone think of any better methods?
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Mhhh, Brandini just told me that there's a Preserve version of redim which will keep the old data intact. This'll make it a lot more easier.
Still, is storing the chat in an array the best idea?
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Not many players will press a button to re-read whats been said before. Cause it will take too much time for them to press and press and press. So I wouldn't save more than the last 25 messages or so.
Now all I would do is save the messages into Code: Dim lineChat(1 to 25) as String
And use a function to determine which one is free, and then to move the messages around. Like
Code: Public Sub(byval Message as String)
Dim i as Byte
For i=1 to 25
if lineChat(i) = vbNullstring then
lineChat(i) = Message
Exit sub
end if
Next i
lineChat(1) = Message
For i=1 to 24
lineChat(i+1) = Message
Next i
End Sub
So now, it first checks if 25 messages have been posted, if not the sub exists and the message is saved. If there are 25 messages in the chat, then it will replace lineChat(1) with the new message, and move them all up 1 slot and remove the old lineChat(25) message from memory.
Now you can just loop through the first 5 or so on the screen, and when you press up, it could jump up 5 slots at a time.
And for the idea of having a Len() to determine the length of the strings to keep them all in lines, so they are inside the chatbox. You could just use:
GOT BORED IGNORE THE BELOW PART. BY THE WAY, IM SICK.
Code: Public Sub BltText()
Dim i as long, ii as byte
For i = 1 to 25
if Len(lineChat(i)) > 0 Then
elseif Len(lineChat(i)) > 50 Then '50letters in a row
End if
Next i
End Sub
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Well, they'll be arrow buttons and you wont have to keep clicking, you can click, keep the mouse down, and after a few milliseconds it'll scroll up like a normal scroll bar would :]
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Dragoons Master
Unregistered
Hum... I don't think redim preserve is the best way to do this. I think a fixed size is better. Maybe Redim Preserve, but let the user specify how many msgs to be stored, I think that's better. And don't keep using redim preserve at every new msg, use it only when the player change the number of msgs to be stored.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Ah, thanks for that Dragoons. I'll probably use that.
Atm I've got the chat rendering. I'll add scrolling when my GFX artist sends me the new scrollable GUI.
Thanks a lot everyone
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Woot. Added colour to the text.
Needed to set the array to a custom RECT which has the Text as string, red as byte, blue as byte + green as byte.
Then I created a function which would take the QBColour and convert to RGB.
Also, noticed the grammar was off on items + npc names starting with vowels, so I added a grammar system which checks the first letter and uses 'an' or 'a' depending on the letter.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Wow, this is getting more and more impressive. Good work Robin.
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Stomach Pulser
Unregistered
William Wrote:It's looking sexy ^^ I second that!
ahahahah "Your target is now a little girl"
Thats Robin all over
Renegade Wrote:ahahahah "Your target is now a little girl"
Thats Robin all over  I lol'd very hard.
What happend to WW? 0_o
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Nothing. I'm actually very close to having WW coded to the point where I can hand it over to my developers to begin creating the actual in game content.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
A fixed-length array would probably be best. If people want a largest history of text you could easily have it in the settings. An array of the last 100-300 lines of text shouldn't be too much of a problem though. A circular buffer like Dave mentioned would be fastest for appending new messages but even just moving every message then adding the new one should perform just fine for this. The only thing that is going to be any noticeable performance hit is the text rendering itself, especially doing two renders per character like you're doing. Rendering system fonts has always been very slow for games. You could easily increase the speed quite a lot by using custom bitmap fonts along with that will give you more flexibility in the font displays, though of course comes with a price of complexity. It can be optimized even farther by creating a vertex buffer of the visible font so you can render the whole chatbox in just one batch call and only have to update it whenever the position or text changes.
Dave Wrote:If you had a circular buffer to store messages in, you would be quicker because you would never have to reallocate memory.
Just to nit-pick, this technically wouldn't be true unless you used a fixed memory allocation per element which variable-length strings. You're still allocating the memory for the new string, you're just not having to alter the rest of the buffer except for the one discarded element.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Yeah, I've heard that drawing text in any version of DX is slow, but I have FPS to spare and it's only a small time game. I am cutting corners and I am breaking coding standards more than I should, but hey
I'm just lazy ;D
Started working on the autotiles. Originally I was pissing around with extra polygons and crap, then I decided to pre-render all the possible tiles in Photshop. After 30 minutes of making them I realised that I could easily create the desired tiles by using 4 16x16 polygons rather than one 32x32.
I really need to find some sort of algorithm to scan the surrounding tiles to make this decision though, as I can't exactly use 8+ If statements every loop for every tile xD
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Looks very nice.
Just one semi-unrelated question. How do you determine the Length of the text? Not the Len() in letters, but in pixels?
Stomach Pulser
Unregistered
Renegade Wrote:ahahahah "Your target is now a little girl"
Thats Robin all over  And he also sees an axe...
Wow another fail atempt to be funny
|