Ok... I'm stumped

Started by
16 comments, last by Zyroth 21 years, 7 months ago
my guess is that your Sound.h isn't just definitions but it is also code. you should be splitting everything into a .h AND a .cpp

example:

Sound.h:

  #ifndef SOUND_H#define SOUND_Hclass Sound {protected:    int whatChoooGot;public:    void doSomeStuff(int yourMom);};#endif  




Sound.cpp:

  #include "Sound.h"void Sound::doSomeStuff(int yourMom) {   for (int i = 0; i < yourMom; i++)        cout << "is hot\n";}  


make sense?

[edited by - Palidine on October 2, 2002 4:48:13 PM]
Advertisement
quote:Original post by Zyroth
yeah my code pretty much goes:

#ifndef WINDOWS_H
#include <windows.h>


#ifndef MMSYSTEM_H
#include <mmsystem.h>


#ifndef DSOUND_H
#include <dsound.h>


#ifndef SOUND_H
#define SOUND_H

#define DSVOLUME_TO_DB( volume ) ( ( DWORD )( -30*( 100 - volume ) ) )
#define MAX_SOUNDS 256

#define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLFREQUENCY

// digital sound object state defines
#define SOUND_NULL 0 // " "
#define SOUND_LOADED 1
#define SOUND_PLAYING 2
#define SOUND_STOPPED 3

struct pcm_sound_typ
{
LPDIRECTSOUNDBUFFER dsbuffer;
int state;
int rate;
int size;
int id;
};

pcm_sound_typ sound_fx[ MAX_SOUNDS ];

LPDIRECTSOUND lpds;
DSBUFFERDESC dsbd;
WAVEFORMATEX pcmwf;

bool InitDS( HWND hwnd );
bool PlayDS( bool loopSound, int id );
bool StopDS( int id );
bool SetVolumeDS( int vol, int id );
bool SetFrequencyDS( int freq, int id );
bool SetPanDS( int pan, int id );
bool DeInitDS();
int Load_WAV( char* filename, int CONTROL_FLAGS = DSBCAPS_CTRLDEFAULT );

#endif // for sound.h

#endif // for dsound.h

#endif // for mmsystem.h

#endif // for windows.h

[edited by - zyroth on October 2, 2002 4:45:21 PM]



try it this way and see if it works.
as you can see the "endif"s belong at the very bottom of the code, not right under the ifndef and define. this rule applies whether you have one or a million.

hope this helps

Beginner in Game Development?  Read here. And read here.

 

why.... *hmm* whyyy would you #ifndef/#endif around each #include? The header should (if I''m not mistaken) already
to that for you! I think that is the whole point... *~*

You may also want to make any variables in the .h file extern

#ifndef SOUND_H // is this used elsewhere?!
#define SOUND_H
#include <windows.h> // inside: #ifndef, ETC.

extern pcm_sound_typ sound_fx[ MAX_SOUNDS ];
extern LPDIRECTSOUND lpds;
extern DSBUFFERDESC dsbd;
extern WAVEFORMATEX pcmwf;
// ...
#endif


// in .cpp/.cc/.whatever

// other headers
#include "sound.h"

pcm_sound_typ sound_fx[ MAX_SOUNDS ]; // extern!!
LPDIRECTSOUND lpds;
DSBUFFERDESC dsbd;
WAVEFORMATEX pcmwf;


// continue w/ implementation..


Any questions?

No!
#ifndef Sound_h only applies to Sound.h not windows.h!

well if i''m wrong then tell me why. it''ll be a learning experience and that''s what we''re all here for.

Beginner in Game Development?  Read here. And read here.

 

What are you yelling about?


ok... #ifndef SOUND_H is (I believe) ''global like''... so if you
have another file using SOUND_H as it''s ''bounds'' then one of
the two files will NOT be included.

I was saying, don''t put #ifndef''s around the #include''s in
the .h, or .cpp... it should be done for you in the .h you are
including.

EX:

// sound.h
#ifndef SOUND_H
#define SOUND_H
// ... code stuffs
#endif


// some cpp file
#ifndef SOUND_H
#include "sound.h"
#endif


It is redundant... a waste time. Any more questions
(heh, if that was even directed at/toward me)

Hope this helps..

:D ~z~ :D
ahhh my newbieness shows again.
i apologize for the "yell".
but i see what you''re saying.

so is his problem fixed?

Beginner in Game Development?  Read here. And read here.

 

Yes. hehe. I think ''extern''ing all the variables and using
the #ifndef''s correctly, he will have no problem (I hope) (assuming ''he'')


:D ~z~ :D
quote:
my guess is that your Sound.h isn''t just definitions but it is also code. you should be splitting everything into a .h AND a .cpp


No he shouldn''t. Keeping smaller methods in the .h file will inline them, which is advantageous. Larger methods should always be implemented in the .cpp file however.
"I don''t know with what weapons the third world war will be fought, but I know the fourth will be fought with sticks and stones." Einstein

This topic is closed to new replies.

Advertisement