Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / A header file for anyone that wants

Author
Message
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 22nd May 2008 23:41
I have just been interested in header files. To see how to make them and get practice making one, I decided to make one. I also decided it should be useful.
I have made a header file call KeyID's.h that will make it much easier to get a key's id numeber. All you have to do is type in the Key you want to use and add Key at the end.
Example:
if (dbKeyState (AKey) == 1){
MoveObject ( 1, 1.0f );
}

It sets it all for you.

I made this and I decided that other people might want to use it. So here it is, no legal restraints or anything. You can also change anything you want.

Give me Feed back at any time!
P.S.- It is a little messy, I am working on cleaning it up!

~~Its not about what you know, its about how you figure it out.~~

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 22nd May 2008 23:59
Very much appreciated. I only do this as I need the keys.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 00:00
ok, thanks! I mean I did this mostly for myself because it took me like and hour to find a key's ID, so I just made this! Glad you liked it!

~~Its not about what you know, its about how you figure it out.~~
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 00:13
Here is a more organized version.

~~Its not about what you know, its about how you figure it out.~~

Attachments

Login to view attachments
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 00:36
Hm.... My .h File actually is faulty, does anyone know why? To me it looks fine.....

This is my first time making a .h file, so any help would be appreciated!

I really want to make this header file foolproof so that I can use it on other game.

~~Its not about what you know, its about how you figure it out.~~
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 00:44
Are you getting some sort of error when using it?

If I were starting from scratch I'd avoid storing them as integers because of the space they takeup. Instead I'd use a #define which would make them look like literal numeric values to the compiler.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 00:47
that might work better... Thanks

~~Its not about what you know, its about how you figure it out.~~
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd May 2008 01:19
Alternatively, add the word 'const' at the start of every line:


programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 06:48
What will that do?

~~Its not about what you know, its about how you figure it out.~~
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 07:27
It would stop you from accidentally changing the value in your program.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 16:35
Ok, thanks.

Quote: "#define"

I would do that, but I am not really sure how, every line I see with #define is really confusing to me.
Would my file look like this?
#define EscKey 1;
I don't know, that is what it looks like when I see files with defines in them.

Thanks again for all the help!

~~Its not about what you know, its about how you figure it out.~~
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 16:39
Now when I add const it give me these errors-



All I can say is- ?????????????????? I have no idea what it means, or how to fix it. Like how does it know there is a bad suffix on number? What does that mean?

Thanks for any help, the header is attached to the thread.

~~Its not about what you know, its about how you figure it out.~~

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 16:48
Quote: "I would do that, but I am not really sure how, every line I see with #define is really confusing to me.
Would my file look like this?
#define EscKey 1;"


#define is a form of substitution, though not always a direct substitution. In your example you'd want to leave off the semi-colon at the end. Preprocessor directives aren't part of the c/c++ language. They're instructions used by the pre-processor to perform certain actions that, for the most part, change what's actually presented to the compiler.

#define EscKey 1

tells the pre-processor to substitute the text "1" wherever it finds the text sequence "EscKey". It doesn't change your file but it does change what the compiler sees. The first bit of text following the #define (surrounded by white space) is the item to be substituted for and whatever follows it is what replaces the original text. There are other things that allow for making a #define behave like a function but it's a bit much to talk about in the time I have available

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 16:53
Quote: "Now when I add const it give me these errors-"


Error list deleted:




You can't begin an identifier with a digit. It's seeing the digit that starts, say, 7Key and expects to find what follows it to either be a number or a legitimate qualifier for the type of number it represents, like 'f' to indicate a float, if applicable. Although you can use digits after the first character but you can only start an identifier with an alpha character, an underscore or the @ sign.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 17:02
Oh, that explains ALOT.
So it would now look like this if I use #define

#define EscKey 1

and using the cont with numbers-

const int N7Key = 8;

Thanks!

~~Its not about what you know, its about how you figure it out.~~
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 17:04
WooHooo!!!!!!
The final version works!!!!!!!
yay! My first header file!

Thanks for all the help!
Here it is, and it works!

~~Its not about what you know, its about how you figure it out.~~

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 17:15
Quote: "The final version works!!!!!!!"


Just remember, nothing is ever final... except..... uh, I don't want to think about it.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 23rd May 2008 17:15
Lol, good point...

~~Its not about what you know, its about how you figure it out.~~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd May 2008 17:36
Folks, I thought's I'd mention something. It might be common knowledge, but then again maybe not.

#defines are actually more overhead from a space perspective than using variables and constants... but from a assembly languange point of view (speed and space) using defines to represent integers is ideal.

My case and point is strings. If you use a #define for a string that can potentially be used more than one time, you will have that string embedded into your application needlessly multiple times.

For strings, #defines are great providing you use them in a manner where they are only included once. My preferred method for embedding strings (when not concerned with a string table for multi-lingual stuff) is a simple:



And only in places where I have code like this would I replace the literal string with a #define that equates to as much.

Just some ramblings.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd May 2008 18:51
That would hold true for strings, though I'm not inclined to use them for string purposes. But in the case of the header file that began this thread it makes sense to use #defines.... most of the time. Storing integers for, say, 90 some odd scan codes takes up 4 bytes per each code, regardless whether you use them or not. But if you you only reference three or four scan codes in your application then a #define makes more sense.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 23rd May 2008 19:12 Edited at: 23rd May 2008 19:30
Although string tables are used for internationalization, that is not their primary intent. Strings in string tables are managed by Windows, and they are marked for discard when the code using them either goes out of scope, or is otherwise discarded by Windows, or the application. (The segment attributes were called LOADONCALL and DISCARDABLE in 16-bit Windows versions. We are in a flat memory model, but LOADONCALL/DISCARDABLE still apply to resources.)

The only thing particularly wasteful about this is the fact that the alphanumeric keys are useable as literals ('A'/'a'), and the F1 keys, arrow keys and others are defined in an include file that you are using already. (In winuser.h)

Example:



Pretty much anything you are going to need that exists in Windows is already defined using #define, as it puts the onus on the compiler, and a variable is tantamount to a memory access, whereas a define is an immediate value.

Login to post a reply

Server time is: 2024-11-20 11:42:10
Your offset time is: 2024-11-20 11:42:10