Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ArnoAtWork

Main application structure

This topic is 5537 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

I am developing an engine. For this, I try to design something really nice. So even for the main class(window, input, renderer,...) I am looking for something generic. Normally I use to design a main class like this
quote:
class CMainApplication { private: CRenderer* m_pRender; ... public: CMainApplication(); ~CMainApplication void CheckEvent(.......); };
but I''ve seen that sometimes, developpers use a keyboard class and a mouse class. Howether I do not understand the reason of these classes and more, I do not see how to use them effectively. Do you have an answer. Thanks a lot. Arno.

Share this post


Link to post
Share on other sites
Advertisement
Well, anytime you modularize data and/or functionality into classes you add to both the maintainability and reusability of that code. Also, in the case of the keyboard class this could be very useful in the case of different keyboard layouts for different localities -- you change the implementation of the keyboard class without affecting the rest of your code. For the mouse I'm not sure. I'm pretty sure that left, right, and middle are the same everywhere...

[edited by - Mage2k on April 21, 2003 4:35:01 PM]

Share this post


Link to post
Share on other sites
i myself created a keyboard class for my game. i love creating classes and have everything be modular. im starting a new game now and all i had to do was include direct.h (my own set of classes) and my graphics engine and input engine were complete, saved me lots of time.

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
I also created a keyboard class and a mouse class, keeping keyboard and mouse specific functionality contained in these classes (isKeyPressed, isMouseButtonPressed, containers for mouse cursor distance changes, etc). Even in these classes, OS/API specific functionality for accessing keyboard key containers, mouse access, etc is stored in an interface class, called by the mouse/keyboard classes, to make it even more modular.

This might be more modular than required, but I wanted to learn many API''s, and as such, my projects compile with Win32 and SDL. Great for comparisons between API''s (speed, etc).

Share this post


Link to post
Share on other sites
In fact, I decided to design a keyboard class, a mouse class and a rendering class. These three classes are managed by a fourth class called windows application. winappli manages event and updates keys states, button states and cursor position. All these four classes are derived of singleton class.

Just one think, a key is "up", "down" or "normal". So, at each update, I have to init each key at "normal" and I change several key state depending of update functions. But init 256 keys at each update could be quite long at each update, no?

thanks.

Share this post


Link to post
Share on other sites
You shouldn''t have to update every key status every time a single key is pressed. If you are using Windows, you can use the WM_KEYDOWN and WM_KEYUP messages with the WPARAM to identify which key has been pressed, and then set the appropriate key identifier you have as storage for key status. You should only need to reset all key status values at the start (during initialization).

For clarification on this, you can check out NeHe''s latest basecode - somewhere in the message processing loop I believe.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!