• What do you need help with? Version 5
    5,752 replies, posted
  • in your header you should have [code]class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; ManagerObject_Sound(string); sf::SoundBuffer GetBuffer(); bool IsCorrectBuffer(string); };[/code] and in your class file [code]ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); }; sf::SoundBuffer ManagerObject_Sound::GetBuffer() { return buffer; }; bool ManagerObject_Sound::IsCorrectBuffer(string fpath) { return (filepath==fpath); };[/code] I suggest you read through the language tutorial on [url]http://cplusplus.com[/url]. It will help with these problems, and give you the knowledge to fix some problems you may come up with soon. Don't forget to include the header file in your class definition. And include your header instead of the class file in your other files. And also you don't need the using namespace std; if you aren't going to use code from the standard library. Typically its just a good idea to access the namespace with the modifier std::
  • Well, I got the manager working beautifully. It only creates a buffer for a sound if said sound hasn't been played yet, and then it stores that buffer so if the sound is played again, it will simply point to the stored buffer instead, which is exactly what I wanted. I couldn't have asked for the manager to work more beautifully. Now I have an issue of the sound simply not playing. I have it set up so, every 3 seconds, it will play a sound, and that works just fine - it creates the buffer the first time it tries to play, then just points to the cached buffer every subsequent time, and it does indeed print my debug when it attempts to play, but it just doesn't make a noise. I know that the buffer is valid, the buffer is loading the file, and the sound is loading the buffer, because if I give a bad filepath, then it will yell at me that the buffer wasn't able to load the file. I am using SFML for this, using a standard sf::SoundBuffer and sf::Sound, using Sound.Play() after it's loaded the buffer, which is done after the buffer loads from file. I looked it up, and it seems like no one really has this problem, and if they do, it's because of a simple mistake or missing .dll - neither of which applies to me. :(. [b]Just for clarification:[/b] the two sounds I am using are "explode1.wav," from the HL2 "Source Sounds.gcf", and the "creeper1.ogg" from Minecraft.
  • Is it set to automatically loop and are you using pause() or stop() to stop playing?
  • [QUOTE=darkrei9n;35831828]Is it set to automatically loop and are you using pause() or stop() to stop playing?[/QUOTE] As far as I know, it's not set to automatically loop, and I'm not stopping it at all. The issue is it's not playing at all.
  • [QUOTE=Gmod4ever;35831852]As far as I know, it's not set to automatically loop, and I'm not stopping it at all. The issue is it's not playing at all.[/QUOTE] Are you sure the volume variable is set to 100, By default it should be but you may want to double check.
  • Relevant code is as follows: [b]SoundManager_Object (.h, then .cpp):[/b] [code]#ifndef _MANOBJ_SOUND_H_ #define _MANOBJ_SOUND_H_ #include <SFML/Audio.hpp> using namespace std; class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; ManagerObject_Sound(string); sf::SoundBuffer GetBuffer(); bool IsCorrectBuffer(string); }; #endif[/code] [code]ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); }; sf::SoundBuffer ManagerObject_Sound::GetBuffer() { return buffer; };[/code] [b]SoundManager:[/b] [code]bool Manager_Sound::PlaySoundInternal(string fpath,bool loop,float pitch, float volume,float x, float y, float z,bool disable_spatialization, float mindist, float atten) { bool NewBuffer = false; CacheBufferIndex(fpath); if (!HasBuffer(fpath)) // We don't have a buffer for this? We better make one! { // First create the object and push it ManagerObject_Sound bufferObj(fpath); ObjectVector.push_back(bufferObj); // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); // This instance of the constructor should do SetBuffer, but I included SetBuffer to see if it made a difference. It didn't. SoundInstance.SetBuffer(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = true; } else { // We already have a buffer for this; just use that buffer ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex]; // Then use it to play a sound sf::Sound SoundInstance(bufferObj.GetBuffer()); SoundInstance.SetVolume(volume); SoundInstance.SetPitch(pitch); SoundInstance.SetLoop(loop); SoundInstance.SetPosition(x,y,z); SoundInstance.SetRelativeToListener(disable_spatialization); SoundInstance.SetMinDistance(mindist); SoundInstance.SetAttenuation(atten); SoundInstance.Play(); NewBuffer = false; } // At the end of the day, return whether or not we had to make a new buffer. return NewBuffer; } bool Manager_Sound::PlaySound(string fpath) { return PlaySoundInternal(fpath,false,1.f,100.f,0.f,0.f,0.f,true,1,1); }[/code] [b]MasterManager (.h, then .cpp):[/b] [code]#ifndef _MASTER_MANAGER_H_ #define _MASTER_MANAGER_H_ #include <SFML/System.hpp> #include "manager_sound.h" class MasterManager { public: Manager_Sound SoundManager; MasterManager(); }; #endif[/code] [code]#include "master_manager.h" MasterManager::MasterManager() { };[/code] [b]main[/b] [code]int main() { float nextSoundTest = 3.f; // Initialize ALL the things! // Initialize the master manager, which will, in turn, initialize all the submanagers. MasterManager ManagerMaster; // Open up the window sf::Window App(sf::VideoMode(800, 600, 32), "Hi there"); sf::Clock Clock; while (App.IsOpened()) { // Test if (Clock.GetElapsedTime() > nextSoundTest) { nextSoundTest = Clock.GetElapsedTime() + 3.f; bool nBuffer = ManagerMaster.SoundManager.PlaySound("resources/stinger_fire1.wav"); cout << "Played sound. New buffer? " << nBuffer << std::endl; } } }[/code] Note that the first time the sound plays, it does indeed say that it created a new buffer (returns 1), and all subsequent times, it returns 0 (new buffer not made).
  • try returning the offset on the sound rather than false. If you notice that its not moving call stop when its done.
  • [QUOTE=darkrei9n;35832104]try returning the offset on the sound rather than false. If you notice that its not moving call stop when its done.[/QUOTE] I'm not sure what that's supposed to accomplish. It prints zero on return, as it should, since I'm printing in the very same frame I'm trying to play, and since it makes a new sound instance every time, it doesn't give me progress on existing sound objects. Sorry, maybe it's because I'm tired (I'm actually heading off to bed right after this post), but I just don't really see the goal of that right now. Thanks for trying, though. :).
  • [QUOTE=Gmod4ever;35832152]I'm not sure what that's supposed to accomplish. It prints zero on return, as it should, since I'm printing in the very same frame I'm trying to play, and since it makes a new sound instance every time, it doesn't give me progress on existing sound objects. Sorry, maybe it's because I'm tired (I'm actually heading off to bed right after this post), but I just don't really see the goal of that right now. Thanks for trying, though. :).[/QUOTE] Goal is to see if the sound is resetting to 0 seconds properly. Try calling stop before playing it again to ensure its reset to the start of the sound.
  • Just saying, in your class implementation files (.cpp) you are terminating the function curly brackets with semicolons. Not sure it effects a whole lot but that should be reserved for class declaration, not function implementation
  • I'm trying to use TinyThread for a loading-routine. I've already got the loading-function up, and I've made it so that when it returns true, the program assumes it's done loading, and moves on. However, there doesn't seem to be any proper tutorials on how to use it. There is only this -> [url]http://tinythread.sourceforge.net/?page=functionality[/url] It doesn't seem too complicated, but I'm not sure how to use it. Could anyone help?
  • JAVA: [IMG]http://s13.postimage.org/x1mbwm513/d8b7cdced523d1ec02370c8e59d3fba2.png[/IMG] How would I go about making an instance of an object in a way so that it can be used by other methods in the same class?
  • [QUOTE=Cheezy;35833729]JAVA: [IMG]http://gyazo.com/d8b7cdced523d1ec02370c8e59d3fba2[/IMG] How would I go about making an instance of an object in a way so that it can be used by other methods in the same class?[/QUOTE] declare it outside a method
  • [QUOTE=swift and shift;35833745]declare it outside a method[/QUOTE] That'd be the best solution, but for some reason that just gives me a huge list of stack overflows when I run the program.
  • [QUOTE=Mordi;35833499]I'm trying to use TinyThread for a loading-routine. I've already got the loading-function up, and I've made it so that when it returns true, the program assumes it's done loading, and moves on. However, there doesn't seem to be any proper tutorials on how to use it. There is only this -> [url]http://tinythread.sourceforge.net/?page=functionality[/url] It doesn't seem too complicated, but I'm not sure how to use it. Could anyone help?[/QUOTE] The given examples should be pretty self explanatory, maybe you should read up on how multithreading works. [url]http://www.codeproject.com/Articles/14746/Multithreading-Tutorial[/url] [url]http://en.wikipedia.org/wiki/Thread_safety[/url] [url]http://en.wikipedia.org/wiki/Mutual_exclusion[/url] [QUOTE=Cheezy;35833729]JAVA: How would I go about making an instance of an object in a way so that it can be used by other methods in the same class?[/QUOTE] My Java is a bit rusty but it should be something like this: [cpp]public class Example { private controller.Controller newController; public Example() { // Constructor newController = new controller.Controller(); } public method1() { // do stuff } public method2() { // do stuff } }[/cpp] You should also probably use the [b]this[/b] keyword to access member variables and objects.
  • [QUOTE=Chryseus;35833768] My Java is a bit rusty but it should be something like this: [cpp]public class Example { private controller.Controller newController; public Example() { // Constructor newController = new controller.Controller(); } public method1() { // do stuff } public method2() { // do stuff } }[/cpp] You should also probably use the [b]this[/b] keyword to access member variables and objects.[/QUOTE] Thanks a lot, that did the trick!
  • [QUOTE=Gmod4ever;35830191]Hey guys. I solved my compile issues (turns out you need a ";" after the "}" when declaring a class...), and I think I've managed to figure out how I want to make my manager object. [/QUOTE] God fuck I hate that mistake. It doesn't generate a normal "Error: expected a ;" or something but everything just stops working...
  • I have a 3D "dungeon" in XNA. The walls have individual BoundingBoxes around them. I also have a player, that is moved with velocityX and velocityZ. How can i make realistic collisions with having only one BoundingBox/Sphere around the player? This is how i move the player: [code]int velocityX = 0; int velocityZ = 0; if (ks.IsKeyDown(Keys.W)) { velocityZ = 1; } if (ks.IsKeyDown(Keys.S)) { velocityZ = -1; } if (ks.IsKeyDown(Keys.A)) { velocityX = 1; } if (ks.IsKeyDown(Keys.D)) { velocityX = -1; } cameraPos += (cameraRotation.Forward * currentSpeed * elapsedTime) * velocityZ; cameraPos += (cameraRotation.Left * currentSpeed * elapsedTime) * velocityX; velocityZ = 0; velocityX = 0;[/code] I am already generating the BoundingBoxes around the walls and i can access them very easily. I also have a function to test if a BoundingBox is colliding with another.
  • With Objective-C. Say I have two methods, setupGame and playGame. The user clicks a button that will call setupGame. Then they click another button to play the game, which will call playGame. I have setup an instance of Game in the setupGame method, however I'm not sure how you would pass it to playGame. Here's the code: [CODE] #import "AppController.h" #import "Game.h" @implementation AppController //awakeFromNib - Called when the program is run to setup the .xibs - (void) awakeFromNib { [gameStatus setStringValue: @"No Game Being Played"]; } //When setup button is pressed - (IBAction)setupGame:(id)sender { [gameStatus setStringValue: @"Setting up game..."]; Game *myGame = [[Game alloc]init]; [myGame setupPlayers]; [myGame setupDeck]; [myGame dealCards]; [myGame selectBriscolaSuit]; [myGame selectPlayerStart]; } - (IBAction)playGame:(id)sender { [myGame playGame]; [myGame gameWinner]; [myGame newGame]; } @end [/CODE] The error I'm getting is in the playGame method 'Unknown receiver myGame'. Would doing this work? [CODE] #import "AppController.h" #import "Game.h" @implementation AppController [B]Game *myGame;[/B] //awakeFromNib - Called when the program is run to setup the .xibs - (void) awakeFromNib { [gameStatus setStringValue: @"No Game Being Played"]; } //When setup button is pressed - (IBAction)setupGame:(id)sender { [gameStatus setStringValue: @"Setting up game..."]; [B]myGame = [[Game alloc]init];[/B] [myGame setupPlayers]; [myGame setupDeck]; [myGame dealCards]; [myGame selectBriscolaSuit]; [myGame selectPlayerStart]; } - (IBAction)playGame:(id)sender { [myGame playGame]; [myGame gameWinner]; [myGame newGame]; } @end [/CODE]
  • Does anyone have by any chance a sample premake4 script file for creating dynamic libraries?
  • [QUOTE=darkrei9n;35832215]Goal is to see if the sound is resetting to 0 seconds properly. Try calling stop before playing it again to ensure its reset to the start of the sound.[/QUOTE] "Again"? But it doesn't play the first time! :v: I'll try do Stop(), maybe even SetPlayingOffset(), before I attempt to play the sound at all. I'll also try printing the sound's status after I tell it to play. This is very frustrating. [editline]5th May 2012[/editline] [QUOTE=Protocol7;35832743]Just saying, in your class implementation files (.cpp) you are terminating the function curly brackets with semicolons. Not sure it effects a whole lot but that should be reserved for class declaration, not function implementation[/QUOTE] That's no issue, I can change that easily enough. Just decided to cover my bases and do that for everything, since the ";" after "}" for class implementation gave me over a day of stress. :v:
  • [QUOTE=Gmod4ever;35832023][b]SoundManager_Object (.h, then .cpp):[/b] [code]#ifndef _MANOBJ_SOUND_H_ #define _MANOBJ_SOUND_H_ #include <SFML/Audio.hpp> using namespace std; class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; ManagerObject_Sound(string); sf::SoundBuffer GetBuffer(); bool IsCorrectBuffer(string); }; #endif[/code][/QUOTE] You're returning a sf::SoundBuffer by value in GetBuffer(), which gets destroyed after the call, which is why the sound isn't playing. Return a reference instead: sf::SoundBuffer &GetBuffer().
  • Hey I've got a quick question. A couple more of these may pop up because I am doing my final project for my Introduction to Programming in C++ class today. Here it is: Is there anything particularly "wrong" or "bad" about using a do-while loop structure for an end-of-file loop? I'm supposed to read float values from a text file but for each value I've got to run it through several functions and I wrote much of the code before I realized that our instructor ALWAYS had us use while loops whenever we were reading values from a file. I just want to be sure that there's nothing bad about doing it the way I'm doing it, because my instructor is kind of a stingy fellow, and I don't want to get a giant penalty for doing it this way. [editline]blahblahblah[/editline] Nevermind, I answered myself after it fucked up my whole program by reading in the last value twice
  • [QUOTE=Z_guy;35836864]You're returning a sf::SoundBuffer by value in GetBuffer(), which gets destroyed after the call, which is why the sound isn't playing. Return a reference instead: sf::SoundBuffer &GetBuffer().[/QUOTE] Hmm. I took your advice, and changed it accordingly: [b]SoundManager_Object (.h, then .cpp):[/b] [code]class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; ManagerObject_Sound(string); sf::SoundBuffer &GetBuffer(); bool IsCorrectBuffer(string); };[/code] [code]sf::SoundBuffer &ManagerObject_Sound::GetBuffer() { return buffer; };[/code] It compiles fine, and doesn't error or anything in runtime, but it still plays no sound. It behaves exactly like before - buffer creates first time, is simply pointed to the other times, but no sound plays ever. :( [editline]5th May 2012[/editline] For shits and giggles, I attempted to play the sound as soon as the buffer is made and loaded, and print what filepath it loads, and the status of the sound. This is the code I use for it: [b]manobj_sound.cpp:[/b] [code]#include <SFML/Audio.hpp> #include "manobj_sound.h" #include <iostream> ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); sf::Sound SoundInstance(buffer); SoundInstance.SetBuffer(buffer); SoundInstance.SetVolume(100); SoundInstance.SetPitch(1); SoundInstance.SetLoop(true); SoundInstance.SetPosition(0,0,0); SoundInstance.SetRelativeToListener(false); SoundInstance.SetMinDistance(1); SoundInstance.SetAttenuation(1); SoundInstance.Play(); cout << "MO_Sound created and sound played from buffer loaded from path (" << fpath << "). Status: " << SoundInstance.GetStatus(); };[/code] It prints, and it prints the correct filepath and it prints the status being 2, which is is "Playing." So I don't know what's going on. [editline]5th May 2012[/editline] I've looked around it, and I've seen a few people say (to others with similar problems) "you have to keep the sf::Sound alive." I can't find anyone anywhere explaining what the hell that means, though, or how to do it. :|
  • [QUOTE=Gmod4ever;35837572]I've looked around it, and I've seen a few people say (to others with similar problems) "you have to keep the sf::Sound alive." I can't find anyone anywhere explaining what the hell that means, though, or how to do it. :|[/QUOTE] Oh...right.. the sf::Sound falls out of scope at the end of the function. You have to store it somewhere..
  • [QUOTE=Z_guy;35840134]Oh...right.. the sf::Sound falls out of scope at the end of the function. You have to store it somewhere..[/QUOTE] Do you mean I should like, make a vector or something to store it until its duration is over, where I kill it? How exactly should I handle this? :v:
  • [QUOTE=Gmod4ever;35841217]Do you mean I should like, make a vector or something to store it until its duration is over, where I kill it? How exactly should I handle this? :v:[/QUOTE] As a test to see if it solves the problem, you could try to store it in the manager. But otherwise you'd want to handle it in a similar way as your sf::Sprites.
  • [QUOTE=Z_guy;35844111]As a test to see if it solves the problem, you could try to store it in the manager. But otherwise you'd want to handle it in a similar way as your sf::Sprites.[/QUOTE] Well, I decided to take your suggestion and do that. I modified the [b]SoundManager_Object[/b] to look as such (.h, then .cpp): [code]class ManagerObject_Sound { public: string filepath; sf::SoundBuffer buffer; sf::Sound SoundInstance; ManagerObject_Sound(string); sf::SoundBuffer &GetBuffer(); bool IsCorrectBuffer(string); };[/code] [code]ManagerObject_Sound::ManagerObject_Sound(string fpath) { filepath = fpath; buffer.LoadFromFile(fpath); sf::Sound SoundInstance(buffer); SoundInstance.SetBuffer(buffer); SoundInstance.SetVolume(100); SoundInstance.SetPitch(1); SoundInstance.SetLoop(true); SoundInstance.SetPosition(0,0,0); SoundInstance.SetRelativeToListener(false); SoundInstance.SetMinDistance(1); SoundInstance.SetAttenuation(1); SoundInstance.Play(); cout << "MO_Sound created and sound played from buffer loaded from path (" << fpath << "). Status: " << SoundInstance.GetStatus() << ", Duration: " << buffer.GetDuration() << std::endl; };[/code] And it compiles fine, but as soon as it starts to play a sound, well... [t]http://dl.dropbox.com/u/8416055/WellThen.png[/t] And this is after an error window comes up saying something about an access violation reading location :v: And about the way I manage sprites... Yeah... I haven't gotten to making a sprite manager yet. I wanted to do sounds first, because there's less involved in testing those. :v: