Sign in to follow this  

Chat/Combat Log (Game)

This topic is 1971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

I am currently looking into making a combat log for a game in C++ using Directx9.

I know there is a game forum, but my question is more general. Also, every chat/combat log post I look for tends to be about client/server winsock stuff [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Basically I am wondering how the chat/combat log data is best stored, with the following in mind:

- The data will not be stored to a file
- The data will be stored on a line-by-line basis
- The data can be of any total length (A game can technically go on indefinitely)
- A single line will probably have a maximum length
- The data will need to have the ability to store graphics as well as text. i.e. I would like the text to be able to say "Player 1 has gained 3 [image of a yellow star]". This would also need to allow me to hover of the yellow star image to display a tooltip.
- The data will need to have filter options. i.e. filtering it so you only see Player 1's actions, or you only see environment effects.

So far I see a basic outline of something like:

[CODE]
vector<CombatLogLine> lines;

struct CombatLogLine
{
wchar_t text[256]; //the line of text
vector<ChatIcon> icons; //the icons in the text

};


struct ChatIcon
{
IDirect3DTexture9* texture; //the image displayed
short position; //this will be the numerical position in the actual line of text
D3DXVECTOR3 screenPosition; //the actual screen coordinates of the image
wchar_t tooltip[256]; //the tooltip shown
};
[/CODE]

Ideally I would like to be able to use ID3DXFont's DrawTextW method for actually printing the text as I already have this functioning and scaling for resolution. My main issues are whether the above outlined code is suitable for the job and how I would determine and place a ChatIcon within the line of text.

Right now my best guess is I that I would need to read through the CombatLogLine and get each position of a ChatIcon and split the text for each icon, making a rectangle of the text up to that point using DrawTextW and placing the icon image at the end of the rectangle's position (setting it's screenPosition) and repeat this process with the remaining text until the line is drawn.

From there I can loop through my ChatIcons for the visible text lines and see if my cursor is hovering over any of them and display the correct tooltip.

What worries me here is the drawing of the lines, as it would seem I need to perform this action [i]every [/i]frame with a specialised method to split the text up and intersperse it with icons. I am not sure how much of an impact such an operation would have, but I generally see the program displaying a maximum of 20 lines at once.

Any advice or confirmation/suggestions of methods here is much appreciated. Edited by Nexian

Share this post


Link to post
Share on other sites
Buy the book Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. It sounds like you're at the point where it'd be rather useful.

Share this post


Link to post
Share on other sites
For filtering reasons I would add a type field to your CombatLogLine struct.

Have you profiled this case for being slow already, if not don´t worry about it untill it becomes a problem, but an idea to reduce the drawcalls is to combine all of the CombatLogLines into one string seperated with carrage return feed symbol if they don't contain an image. This will then only use one call to D3DXFont::DrawText for that portion of text.

Share this post


Link to post
Share on other sites
[quote name='Narf the Mouse' timestamp='1345334114' post='4970958']
Buy the book Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. It sounds like you're at the point where it'd be rather useful.
[/quote]

Thank you for the book suggestion. Added a link to the book for when I am not horrifically poor :)

[quote name='NightCreature83' timestamp='1345378625' post='4971088']
For filtering reasons I would add a type field to your CombatLogLine struct.

Have you profiled this case for being slow already, if not don´t worry about it untill it becomes a problem, but an idea to reduce the drawcalls is to combine all of the CombatLogLines into one string seperated with carrage return feed symbol if they don't contain an image. This will then only use one call to D3DXFont::DrawText for that portion of text.
[/quote]

Yeah, a type field would probably be a good idea, maybe with a source and flags for the type. Like Source = Player 1 and Type = LTYPE_COMBAT | LTYPE_GETHIT

You're right, I probably should worry about performance when it actually becomes an issue. ^^

Share this post


Link to post
Share on other sites
For images in the chat log take a look at half life and team fortress. They actually use custom fonts to render images in the chat window. Lets say your game doesn't use the £ symbol anywhere then you could replace that with a star in your font. There are a few font creators online that you can use.

Share this post


Link to post
Share on other sites
Sign in to follow this