0
0

(A copy of my full source code is included below for your convenience)

Hi everyone! Today is the first day I’ve ever written any C++ code. I’ve got a specific question and I’ve tried to figure it out for a few hours now.

I’m using DEV C++, and I got my application to compile properly. I’m developing a sort-of game to learn with using the Irrlicht Engine and FMOD for sound support. I chose FMOD because the Irrlich Engine says that you guys suck, so I want to both prove them wrong and take the “hard” route just so I can learn faster.

However.. I’ve run into a problem. As I said my code compiles, but when I run the application the music restarts playing every.. eh… 100ms or so, WITHOUT stopping playing the song. In other words, itn about ten seconds I have five hundred copies of the song all playing at once at different points.

I know what the problem is, but I do not know how to fix it. I based my sound support on your /samples/simplest example. To make the music play I included a FMUSIC_PlaySong(mod); in my while(device->run()) section. This is the problem; every time my application reaches that line of code it restarts the song without stopping it. I do not know how to cause the song to start only one time; the FMUSIC_PlaySong(mod); MUST go in my while loop, else the application either only plays music or displays the graphics but not both. I’ve tried otherwise… but, as I said, I have written C++ for exactly 1 day now. If I am wrong, please forgive me.

Could ANYONE tell me what I can do to cause the music to be played only one time?

A copy of my full souce code (1 file) is included in the next post.

  • You must to post comments
0
0

include <irrlicht.h>

include <stdio.h>

include <stdlib.h>

if defined(WIN32) || defined(WATCOMC)

#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

else

#include "wincompat.h"

endif

include “fmod.h”

include “fmod_errors.h” /* optional */

using namespace irr;

pragma comment(lib, “Irrlicht.lib”)

scene::ICameraSceneNode* camera = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (camera)
return camera->OnEvent(event);

return false;
}
};

int main()
{

FMUSIC_MODULE *mod = NULL;

if (FSOUND_GetVersion() &lt; FMOD_VERSION)
{
    printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
    exit(1);
}

/*
    INITIALIZE
*/
if (!FSOUND_Init(32000, 64, 0))
{
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
}

MyEventReceiver receiver;

IrrlichtDevice *device =
createDevice(video::DT_OPENGL, core::dimension2d<s32>(800, 600), 32, true, true, &receiver);

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();

device->getFileSystem()->addZipFileArchive(“./maps/default/default.pk3”);

scene::IAnimatedMesh* q3levelmesh = smgr->getMesh(“./maps/default/pigskin.bsp”);
scene::ISceneNode* q3node = 0;

if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));

scene::ITriangleSelector* selector = 0;

if (q3node)
{
q3node->setPosition(core::vector3df(-300,-147,-325));

selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
q3node->setTriangleSelector(selector);
selector->drop();
}

camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
camera->setPosition(core::vector3df(0,100,0));

scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(1,1,1),
core::vector3df(0,-100,0), 100.0f,
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();

device->getCursorControl()->setVisible(false);

scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture(“./particles/fireball.bmp”));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));

video::SMaterial material1;
material1.Texture1 = driver->getTexture(“./models/woman1/alita4.bmp”);
material1.Lighting = true;

scene::IAnimatedMeshSceneNode* node1 = 0;
scene::IAnimatedMesh* wm1 = smgr->getMesh(“./models/woman1/tris.md2”);

if (wm1)
{
node1 = smgr->addAnimatedMeshSceneNode(wm1);
node1->setPosition(core::vector3df(-70,0,-90));
node1->setMD2Animation(scene::EMAT_STAND);
node1->getMaterial(0) = material1;
}

video::SMaterial material2;
material2.Texture1 = driver->getTexture(“./models/woman2/sydney.bmp”);
material2.Lighting = true;

scene::IAnimatedMeshSceneNode* node2 = 0;
scene::IAnimatedMesh* wm2 = smgr->getMesh(“./models/woman2/tris.md2”);

if (wm2)
{
node2 = smgr->addAnimatedMeshSceneNode(wm2);
node2->setPosition(core::vector3df(-90,0,-70));
node2->setMD2Animation(scene::EMAT_POINT);
node2->getMaterial(0) = material2;
}

video::SMaterial material3;
material3.Texture1 = driver->getTexture(“./models/woman3/2tone.bmp”);
material3.Lighting = true;

scene::IAnimatedMeshSceneNode* node3 = 0;
scene::IAnimatedMesh* wm3 = smgr->getMesh(“./models/woman3/tris.md2”);

if (wm3)
{
node3 = smgr->addAnimatedMeshSceneNode(wm3);
node3->setPosition(core::vector3df(-50,0,-110));
node3->setMD2Animation(scene::EMAT_WAVE);
node3->getMaterial(0) = material3;
}

video::SMaterial material4;
material4.Texture1 = driver->getTexture(“./models/woman4/Yohko.bmp”);
material4.Lighting = true;

scene::IAnimatedMeshSceneNode* node4 = 0;
scene::IAnimatedMesh* wm4 = smgr->getMesh(“./models/woman4/tris.md2”);

if (wm4)
{
node4 = smgr->addAnimatedMeshSceneNode(wm4);
node4->setPosition(core::vector3df(-110,0,-50));
node4->setMD2Animation(scene::EMAT_SALUTE);
node4->getMaterial(0) = material4;
}

video::SMaterial material5;
material5.Texture1 = driver->getTexture(“./models/swat/skin.bmp”);
material5.Lighting = true;

scene::IAnimatedMeshSceneNode* node5 = 0;
scene::IAnimatedMesh* sw1 = smgr->getMesh(“./models/swat/tris.md2”);

if (sw1)
{
node5 = smgr->addAnimatedMeshSceneNode(sw1);
node5->setPosition(core::vector3df(-210,0,-10));
node5->setMD2Animation(scene::EMAT_STAND);
node5->getMaterial(0) = material5;
}

video::SMaterial material6;
material6.Texture1 = driver->getTexture(“./models/swat/skin2.bmp”);
material6.Lighting = true;

scene::IAnimatedMeshSceneNode* node6 = 0;
scene::IAnimatedMesh* sw2 = smgr->getMesh(“./models/swat/tris.md2”);

if (sw2)
{
node6 = smgr->addAnimatedMeshSceneNode(sw2);
node6->setPosition(core::vector3df(-210,0,-70));
node6->setMD2Animation(scene::EMAT_STAND);
node6->getMaterial(0) = material6;
}

video::SMaterial material7;
material7.Texture1 = driver->getTexture(“./models/mrciaronni/mrciaronni.bmp”);
material7.Lighting = true;

scene::IAnimatedMeshSceneNode* node7 = 0;
scene::IAnimatedMesh* mr1 = smgr->getMesh(“./models/mrciaronni/mrciaronni.md2”);

if (mr1)
{
node7 = smgr->addAnimatedMeshSceneNode(mr1);
node7->setPosition(core::vector3df(-210,0,-50));
node7->setMD2Animation(scene::EMAT_STAND);
node7->getMaterial(0) = material7;
}

material1.Texture1 = 0;
material1.Lighting = false;
material2.Texture1 = 0;
material2.Lighting = false;
material3.Texture1 = 0;
material3.Lighting = false;
material4.Texture1 = 0;
material4.Lighting = false;
material5.Texture1 = 0;
material5.Lighting = false;
material6.Texture1 = 0;
material6.Lighting = false;
material7.Texture1 = 0;
material7.Lighting = false;

smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
video::SColorf(1.0f,1.0f,1.0f,1.0f),
600.0f);

scene::ISceneNode* selectedSceneNode = 0;
scene::ISceneNode* lastSelectedSceneNode = 0;

int lastFPS = -1;

while(device->run())
{
driver->beginScene(true, true, 0);

smgr->drawAll();

core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() – line.start).normalize() * 1000.0f;

core::vector3df intersection;
core::triangle3df tri;

if (smgr->getSceneCollisionManager()->getCollisionPoint(
line, selector, intersection, tri))
{
bill->setPosition(intersection);

driver->setTransform(video::TS_WORLD, core::matrix4());
driver->setMaterial(material1);
driver->setMaterial(material2);
driver->setMaterial(material3);
driver->setMaterial(material4);
driver->setMaterial(material5);
driver->setMaterial(material6);
driver->setMaterial(material7);
driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
}
selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

if (lastSelectedSceneNode)
lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);

if (selectedSceneNode == q3node || selectedSceneNode == bill)
selectedSceneNode = 0;

if (selectedSceneNode)
selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

lastSelectedSceneNode = selectedSceneNode;

driver->endScene();

int fps = driver->getFPS();

if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024,
L”Sire’s Revenge”,
fps, driver->getPrimitiveCountDrawn());

device->setWindowCaption(tmp);
lastFPS = fps;

mod = FMUSIC_LoadSong("./invtro94.s3m");
if (!mod)
{
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
}
FMUSIC_PlaySong(mod); 

   }

}
FMUSIC_FreeSong(mod);
FSOUND_Close();
device->drop();

return 0;

}

  • You must to post comments
0
0

Put FMUSIC_LoadSong outside your while loop.

edit: And MUSIC_PlaySong.

  • You must to post comments
0
0

Thanks Andrew! I put:

mod = FMUSIC_LoadSong(“./invtro94.s3m”);
if (!mod)
{
printf(“%s\n”, FMOD_ErrorString(FSOUND_GetError()));
exit(1);
}
FMUSIC_PlaySong(mod);

just BEFORE the while loop and now it’s fine, it loads the map and models, plays the song, and allows for movement. I don’t remember what I was trying before but wherever I had it outside of the while loop, it either didn’t play the sound at all, or just played sound but made no graphics. Once I had it playing sound (in the previous problem) but the map and models were all jumbled on top of each other.

Thanks again. I’m reading my butt off on C++, Irrlicht Engine, and FMOD, not to mention DEV C++. I hope to learn fast. 😀

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.