🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Cripes! on indeterminate-length hold

Published October 21, 2008
Advertisement
I had to send my laptop in for repair recently, not to mention - if you haven't noticed - development has ground to a halt anyways. If and when I get back to Cripes!, I'll be doing an overhaul of the design, anyways.

My latest project is - of course - a MUD. How obvious... Well, I may as well post a bit of what's going on with that.


ExplorerMUD

((yes, that's what it's called >_>))

I'm going to try to work with a modular, object-oriented design. At the moment all I've got running is a basic listening server which creates a new thread for each client, sends "Hello World!" to the client, and disconnects. That's probably a good thing, because I left it on once when I went to school, and I had a connection from some person in Peru when I got back... what the?

Before I go on, I realized something about access specifiers and inheritance, which actually is very interesting and useful, although probably somewhat obvious if you think about it... a class with private and public members can be instantiated, and it works like you'd think, right? I don't really need (or want) to explain that. If you derive from that class, the public members remain usable within and outside the derived class, and the private members can't be used directly in either. But if the inherited public members access the private members, they still can! Like I said, it's obvious, but not really - in my case at least - something you'd think about most of the time.

This is one of those things where you have a - ha ha - paradigm shift. I've always thought (yes, I'm stupid), "what's the point of deriving from a class with private fields? If you can't use those it breaks the class." Well see, this is why it's useful to do that. It's another layer of encapsulation.

So, I've created a Thread class which can be used a bit like a Java thread: you just derive from it, and implement a Main() function. There's some encapsulated Thread info, like the thread ID, inside the base Thread class, but it's private so not even its derived classes can access it. But it defines protected and public members so they can be reached in some manner or other. There's a Start() function defined in Thread, for example, that starts a new thread as well as storing internal data about the thread. It starts the thread under a private member, Go(), which essentially encapsulates some ugly thread-specific calls and allows the virtual Main() to use the return keyword instead of, say, pthread_exit().

When you derive a Thread, you can create fields and functions within it, of course. Mutexes are a good example, as are functions that notify the thread in some manner that there's something to be done. The Thread class derivatives can allow for an inter-thread interface this way. You can also add fields to emulate arguments to Main() - pthread_create only accepts void functions accepting a void pointer, so for simplicity I do it this way - and create a constructor to fill those fields in before Create()ion.

That was long... >_>


I'll, um, save my speech on getting input from stdin via select() for later. Suffice to say, you can't use cin.

I'm doing all of this on Ubuntu, if you're wondering.
~Jonathan
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement