•      Sign In
• Create Account

## Chat/Combat Log (Game)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Nexian  Members

118
Like
0Likes
Like

Posted 18 August 2012 - 02:54 PM

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

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:

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
};


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 every 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, 18 August 2012 - 03:07 PM.

### #2Narf the Mouse  Members

318
Like
0Likes
Like

Posted 18 August 2012 - 05:55 PM

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.

### #3NightCreature83  Members

4785
Like
0Likes
Like

Posted 19 August 2012 - 06:17 AM

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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

### #4Nexian  Members

118
Like
1Likes
Like

Posted 19 August 2012 - 11:00 AM

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.

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

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.

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. ^^

### #5NightCreature83  Members

4785
Like
1Likes
Like

Posted 23 August 2012 - 04:34 PM

Yeah that would then allow you to write functors to do the filtering for you.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

### #66677  Members

1054
Like
0Likes
Like

Posted 25 August 2012 - 03:32 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.