Skip to main content
gamedev.net
🔒 Locked

Main application structure

Started by ArnoAtWork 4 replies 1.2k views
Original Post
ArnoAtWork
ArnoAtWork
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.
Mage2k
Mage2k
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]
---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
Neen10do
Neen10do
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!
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!
mr_dejao
mr_dejao
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).
The guy who invented the first wheel was an idiot. The guy who invented the other three, he was the genius.
ArnoAtWork
ArnoAtWork
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.
mr_dejao
mr_dejao
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.
The guy who invented the first wheel was an idiot. The guy who invented the other three, he was the genius.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.