2 Replies - 611 Views - Last Post: 22 January 2010 - 06:15 PM Rate Topic: -----

#1 SytheZN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-January 10

Newb + State Machines = Disaster

Posted 22 January 2010 - 04:05 PM

Hi there guys & gals.

To give you a bit of background before I launch into the questions, I'm fairly new to C#.
I'm working on a chat client for WM5/6 devices, using .Net CF3.5. So far things have gone well, up until I came to handling codes in the text.

Basically what needs to happen is when my client displays a message (incoming or outgoing) any codes in the text need to change the way the text is represented.

For example:

"The *quick* /brown/ _fox_ ..."

should display as:

"The quick brown fox ..."

Now this is where the questions start coming in...
From what I understand I need to impliment a state machine. The problem is I'm finding it very difficult to locate any decent information on how a state machine actually works, and how to impliment one.

My next concern is that I'm implimenting custom drawing code to handle all of the UI elements (my goals being finger-friendliness and good looks) and I'm worried that iterating through every character in a 200 message long string, given a maximum of 1000 chars per message, would seriously degrade performance.

So my questions are:
- Is there a better / faster way to parse and react to these codes than a state machine?
- If not, how does a state machine work?
- And, how would I impliment one to perform the task at hand?


Is This A Good Question/Topic? 0
  • +

Replies To: Newb + State Machines = Disaster

#2 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Newb + State Machines = Disaster

Posted 22 January 2010 - 05:04 PM

Here's information on the state pattern:
http://www.dofactory...tternState.aspx

Quote

- Is there a better / faster way to parse and react to these codes than a state machine?


You will only have to check the last typed character and identify if it has a closing character. You won't have to search through all the characters every time because previously typed stuff would already be altered to underline/bold/whatever.

In regards to using a state machine at all, I'm curious what your reasoning behind doing that is.

The link answers the other two questions you had.
Was This Post Helpful? 0
  • +
  • -

#3 SytheZN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-January 10

Re: Newb + State Machines = Disaster

Posted 22 January 2010 - 06:15 PM

Thanks for the info, I'll have to read it through carefully on the morrow.

View PostMentalFloss, on 22 Jan, 2010 - 04:04 PM, said:

In regards to using a state machine at all, I'm curious what your reasoning behind doing that is.


Well... I based the decision on the design used here.

One of the issues is that the tags can be nested in any order, and some of the tags defined in the protocol specification use more than one character(ie. ".+" to enlarge font and "#00ff00" to change font colour). Another thing is that I need to replace text codes with the appropriate emoticons.

I'm also not using a textbox control. I'm writing a custom control, inheriting from the Control base class, which doesn't support Auto Scrollbars. The reason for this is that everything needs to be skinned, including scrollbars etc.

In other words, I need to write code to handle the drawing of the text and emoticons to the control surface (which in this case is an in-memory bitmap for double buffering) and to handle redrawing from the correct positions when the control is scrolled.

To combat memory constraints, the control also needs to be reusable for multiple contacts. The way I've done things so far is to have a ContactInfo class containing all the information for a specific contact (Nickname, Real Name, Profile Photo, Contact Info, etc.) which I thought would be the logical place to store the chat history for the session. This way when a new contact is selected to chat, the history could be passed to the ChatWindow control for display, and the history could have new messages appended in the background.

If you can think of a better way to do all of this please feel free because I'm pretty overwhelmed by the complexity of it all at the moment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1