1. Post #1241
    kill yourself
    Protocol7's Avatar
    June 2006
    25,724 Posts
    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
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 2 (list)

  2. Post #1242
    Team Hamster
    Mordi's Avatar
    January 2012
    312 Posts
    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 -> http://tinythread.sourceforge.net/?page=functionality

    It doesn't seem too complicated, but I'm not sure how to use it. Could anyone help?
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  3. Post #1243
    Gold Member
    Cheezy's Avatar
    October 2005
    1,497 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  4. Post #1244
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    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?
    declare it outside a method
    Reply With Quote Edit / Delete Mac Australia Show Events

  5. Post #1245
    Gold Member
    Cheezy's Avatar
    October 2005
    1,497 Posts
    declare it outside a method
    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.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  6. Post #1246
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    no it won't
    Reply With Quote Edit / Delete Mac Australia Show Events

  7. Post #1247
    Gold Member
    Chryseus's Avatar
    February 2009
    2,350 Posts
    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 -> http://tinythread.sourceforge.net/?page=functionality

    It doesn't seem too complicated, but I'm not sure how to use it. Could anyone help?
    The given examples should be pretty self explanatory, maybe you should read up on how multithreading works.

    http://www.codeproject.com/Articles/...ading-Tutorial
    http://en.wikipedia.org/wiki/Thread_safety
    http://en.wikipedia.org/wiki/Mutual_exclusion

    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?
    My Java is a bit rusty but it should be something like this:
    public class Example
    {
    	private controller.Controller newController;
    	public Example()
    	{
    		// Constructor
    		newController = new controller.Controller();
    	}
    	public method1()
    	{
    		// do stuff
    	}
    	public method2()
    	{
    		// do stuff
    	}
    }

    You should also probably use the this keyword to access member variables and objects.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Programming King Programming King x 1Disagree Disagree x 1 (list)

  8. Post #1248
    Gold Member
    Cheezy's Avatar
    October 2005
    1,497 Posts
    My Java is a bit rusty but it should be something like this:
    public class Example
    {
    	private controller.Controller newController;
    	public Example()
    	{
    		// Constructor
    		newController = new controller.Controller();
    	}
    	public method1()
    	{
    		// do stuff
    	}
    	public method2()
    	{
    		// do stuff
    	}
    }

    You should also probably use the this keyword to access member variables and objects.
    Thanks a lot, that did the trick!
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Friendly Friendly x 1 (list)

  9. Post #1249
    Gold Member
    Number-41's Avatar
    August 2005
    4,246 Posts
    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.
    God fuck I hate that mistake. It doesn't generate a normal "Error: expected a ;" or something but everything just stops working...
    Reply With Quote Edit / Delete Windows 7 Belgium Show Events

  10. Post #1250
    I gave enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,389 Posts
    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;
    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.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  11. Post #1251
    Gibo990's Avatar
    January 2008
    281 Posts
    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
    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
    
    Game *myGame;
    
    //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..."];
        
        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
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  12. Post #1252
    Richy19's Avatar
    May 2010
    5,368 Posts
    Does anyone have by any chance a sample premake4 script file for creating dynamic libraries?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  13. Post #1253
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    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.
    "Again"? But it doesn't play the first time!

    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.

    Edited:

    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
    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.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  14. Post #1254
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    SoundManager_Object (.h, then .cpp):
    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
    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().
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Winner Winner x 1 (list)

  15. Post #1255
    rivershark's Avatar
    February 2010
    1,243 Posts
    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.

    Edited:

    Nevermind, I answered myself after it fucked up my whole program by reading in the last value twice
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  16. Post #1256
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    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().
    Hmm.

    I took your advice, and changed it accordingly:

    SoundManager_Object (.h, then .cpp):
    Code:
    class ManagerObject_Sound {
    public:
    	string filepath;
    	sf::SoundBuffer buffer;
    
    	ManagerObject_Sound(string);
    	sf::SoundBuffer &GetBuffer();
    	bool IsCorrectBuffer(string);
    };
    Code:
    sf::SoundBuffer &ManagerObject_Sound::GetBuffer()
    {
    	return buffer;
    };
    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.

    :(

    Edited:

    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:

    manobj_sound.cpp:
    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();
    };
    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.

    Edited:

    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. :|
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  17. Post #1257
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    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. :|
    Oh...right.. the sf::Sound falls out of scope at the end of the function. You have to store it somewhere..
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  18. Post #1258
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    Oh...right.. the sf::Sound falls out of scope at the end of the function. You have to store it somewhere..
    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?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #1259
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    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?
    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.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  20. Post #1260
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    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.
    Well, I decided to take your suggestion and do that. I modified the SoundManager_Object 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:
    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;
    };
    And it compiles fine, but as soon as it starts to play a sound, well...



    And this is after an error window comes up saying something about an access violation reading location

    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.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #1261
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    Well, I decided to take your suggestion and do that. I modified the SoundManager_Object 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:
    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;
    };
    And it compiles fine, but as soon as it starts to play a sound, well...



    And this is after an error window comes up saying something about an access violation reading location

    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.
    I'm not sure why it crashes, but you forgot to remove the "sf::Sound SoundInstance(buffer);" line from the constructor, so you're still not using the one that is stored in the class. Remove that line and it should work.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  22. Post #1262
    Gold Member
    dvondrake's Avatar
    August 2006
    2,329 Posts
    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;
    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.
    Not sure if you've already figured this out yet, but the general idea is to move the player forwards, test if the bounding boxes are intersecting, and if so move him back. That's how I do it at least. So long as it's all done before the frame is rendered, so you don't visually see the player moving inside the wall and bouncing back.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  23. Post #1263
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    I'm not sure why it crashes, but you forgot to remove the "sf::Sound SoundInstance(buffer);" line from the constructor, so you're still not using the one that is stored in the class. Remove that line and it should work.
    Fair enough.

    Commented out that line from the constructor.

    It doesn't crash any more, but now it's right back to where we had begun.

    Also fun fact, when it was crashing, if I pressed "continue" fast enough through the horde of error popups that came up, I could actually hear my sound play - it only played a fraction of a second at a time, in the time it took for one message box to close and another to open, but it was playing.

    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  24. Post #1264
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    Fair enough.

    Commented out that line from the constructor.

    It doesn't crash any more, but now it's right back to where we had begun.

    Also fun fact, when it was crashing, if I pressed "continue" fast enough through the horde of error popups that came up, I could actually hear my sound play - it only played a fraction of a second at a time, in the time it took for one message box to close and another to open, but it was playing.

    Can you show the code where you're creating your ManagerObject_Sound instance?
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  25. Post #1265
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    Yeah, no problem.

    It's being made in the Manager_Sound, shown below. As always, .h then .cpp.

    Code:
    class Manager_Sound {
    public:
    	int CachedBufferIndex;
    
    	std::vector<ManagerObject_Sound> ObjectVector;
    
    	Manager_Sound();
    	void ResetCachedBuffer();
    	void CacheBufferIndex(string);
    	bool HasBuffer(string);
    	bool PlaySoundInternal(string,bool,float,float,float,float,float,bool,float,float);
    
    	// Holy overload (will have lots of overloads when everything is wroking)
    	bool PlaySound(string);
    };
    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());
    		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);
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #1266
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    Yeah, no problem.

    It's being made in the Manager_Sound, shown below. As always, .h then .cpp.

    Code:
    -snip-
    Okay, I think I've figured it out.

    Look at these two lines:
    Code:
    ManagerObject_Sound bufferObj(fpath);
    ObjectVector.push_back(bufferObj);
    In the first line you are creating an instance of ManagerObject_Sound and the constructor is called.

    In the second line you are calling push_back(), which is creating a copy of bufferObj (calling the copy constructor, which doesn't play the sound). Then after the function ends, the original bufferObj is destroyed, thus destroying the sf::Sound that is playing.

    What you should do is moving the code in the constructor to a separate method (let's say Init()) and call that like this:
    Code:
    ObjectVector.push_back(ManagerObject_Sound());
    ManagerObject_Sound &bufferObj = ObjectVector.back();
    
    bufferObj.Init();
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Programming King Programming King x 1 (list)

  27. Post #1267
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    Okay, I understood most of that.

    I'm not quite sure what you mean by "the code in the constructor," though.

    Here's what I did, though. Firstly, I removed the debug code from ManagerObject_Sound, so it looks like this now (.h and .cpp):

    Code:
    class ManagerObject_Sound {
    public:
    	string filepath;
    	sf::SoundBuffer buffer;
    
    	ManagerObject_Sound(string);
    	sf::SoundBuffer &GetBuffer();
    	bool IsCorrectBuffer(string);
    };
    Code:
    ManagerObject_Sound::ManagerObject_Sound(string fpath)
    {
    	filepath = fpath;
    
    	buffer.LoadFromFile(fpath);
    };
    So, now it's back to what it was originally and what I want to look like (roughly; I'll change it as needed to get it working ).

    Then, in my Manager_Sound, I changed it from this:

    Code:
    		// First create the object and push it
    		ManagerObject_Sound bufferObj(fpath);
    
    		ObjectVector.push_back(bufferObj);
    To this:

    Code:
    // First create the object and push it
    		ObjectVector.push_back(ManagerObject_Sound(fpath));
    		ManagerObject_Sound &bufferObj = ObjectVector.back();
    Which looks more or less like what you suggested.

    I'm just not exactly sure what all code you want me to scoop out of the constructor and put into its own method.

    Just for clarification, Sound_Manager.cpp's relevant code is now as thus:

    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);
    
    		ObjectVector.push_back(ManagerObject_Sound(fpath));
    		ManagerObject_Sound &bufferObj = ObjectVector.back();
    
    		// Then use it to play a sound
    		sf::Sound SoundInstance(bufferObj.GetBuffer());
    		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;
    }
    However, there still is no sound.

    Thanks a lot for all the help, by the way. You guys have no idea how much this means to me. Now I just wish we can get it working soon.

    Edited:

    HOT

    I also made it so the "SoundInstance" is created and stored in the class declaration (to "keep it alive"), and now the sound plays when the buffer is made. Yay.

    Also set up the "buffer already exists" to work similarly, but unfortunately, it's not yet working.

    Progress, though!

    Edited:

    Now that I got that working, and I am onto getting the cached buffer method to work, here's what I got.

    Manager_Sound (.h then .cpp) (There's new, relevant code now! Honest!)
    Code:
    class Manager_Sound {
    public:
    	int CachedBufferIndex;
    
    	std::vector<ManagerObject_Sound> ObjectVector;
    	sf::Sound SoundInstance;
    
    	Manager_Sound();
    	void ResetCachedBuffer();
    	void CacheBufferIndex(string);
    	bool HasBuffer(string);
    	bool PlaySoundInternal(string,bool,float,float,float,float,float,bool,float,float);
    
    	// Holy overload
    	bool PlaySound(string);
    };
    Code:
    void Manager_Sound::CacheBufferIndex(string fpath)
    {
    	int i;
    
    	for (i=0; ObjectVector.size(); i++)
    	{
    		if (ObjectVector[i].IsCorrectBuffer(fpath))
    		{
    			CachedBufferIndex = i;
    			break;
    		}
    	}
    }
    
    bool Manager_Sound::HasBuffer(string fpath)
    {
    	return !(CachedBufferIndex==MANAGER_NULL_INDEX);
    }
    
    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!
    	{
               // You know what's here... This part is working. I won't post it AGAIN and clutter this page even more than I already have.
    	}
    	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.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 = false;
    	}
    	// At the end of the day, return whether or not we had to make a new buffer.
    
    	return NewBuffer;
    }
    ManagerObject_Sound.cpp
    Code:
    bool ManagerObject_Sound::IsCorrectBuffer(string fpath)
    {
    	return (filepath==fpath);
    };
    As far as I know, the ObjectVector.back(); method and this method should be returning the same thing.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  28. Post #1268
    Gold Member
    Z_guy's Avatar
    July 2005
    561 Posts
    Now that I got that working, and I am onto getting the cached buffer method to work, here's what I got.

    -snip-

    As far as I know, the ObjectVector.back(); method and this method should be returning the same thing.
    This line:
    Code:
    ManagerObject_Sound bufferObj = ObjectVector[CachedBufferIndex];
    You are creating a copy of the ManagerObject_Sound (which gets destroyed when the function ends).

    Create a reference instead:
    Code:
    ManagerObject_Sound &bufferObj = ObjectVector[CachedBufferIndex];
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Programming King Programming King x 1 (list)

  29. Post #1269
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,671 Posts
    Oh wow I feel stupid.

    Could have sworn I made sure I did that...

    Thanks again, guys. It works beautifully. Now I'm off to continue my endeavors, since this challenge has finally been overcome.

    The lesson of the day is pointers are my friend, and I should use them.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Winner Winner x 2Agree Agree x 1 (list)

  30. Post #1270
    I gave enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,389 Posts
    Not sure if you've already figured this out yet, but the general idea is to move the player forwards, test if the bounding boxes are intersecting, and if so move him back. That's how I do it at least. So long as it's all done before the frame is rendered, so you don't visually see the player moving inside the wall and bouncing back.
    Do you mean to move the player back to the point where he was before collision or just move it backwards one time?
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  31. Post #1271
    Absolute tosser, manchild, and belligerent douche-nozzle.
    download's Avatar
    July 2006
    6,466 Posts
    I'm trying (and failing) to create a 2D array of Java.awt rectangles, no clue what's going on...

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package lab4_2;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     *
     * @author Kyle
     */
    public class Lab4_2 {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            GameBoard game = new GameBoard();
            
            final int XSIZE = 195, YSIZE = 215; //frame size
            
            JFrame win = new JFrame("Tic Tac Toe");
            win.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            win.setBounds(0, 0, XSIZE, YSIZE);
            
            Rectangle panels[][] = new Rectangle[2][2]; //Array
            
            int count1 = 0, count2, colourCount = 0; //colourCount is to determine which rectangle will be red or black
            
            while(count1 <= 2)
            {
                count2 = 0;
                while(count2 <= 2)
                {
                    
                    //Colour choice 
                    if(colourCount % 2 == 0)
                    {
                        panels[count1][count2].setColor(Color.BLACK);
                    }
                    else
                    {
                        panels[count1][count2].setColor(Color.RED);
                    }
                    
                    //Create rectangle
                    panels[count1][count2].fillRect(count1*(XSIZE/3), count2*(YSIZE/3), XSIZE/3, YSIZE/3);
                    
                    colourCount++;     
                    count2++;
                }
                
            }
            
            //Add to window
            count1 = 0;
            while (count1 <=2)
            {
                count2 = 0;
                while (count2 <= 2)
                {
                    win.getContentPane().add(panels[count1][count2]);
                    count2++;
                }
                count1++;
            }
            
            win.pack();
            win.setVisible(true);
        }
    }
    
    

    Any clue what's wrong?
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  32. Post #1272
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,137 Posts
    In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.
    Reply With Quote Edit / Delete Windows 8 United States Show Events

  33. Post #1273
    Absolute tosser, manchild, and belligerent douche-nozzle.
    download's Avatar
    July 2006
    6,466 Posts
    In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.
    I don't think so, I've used arrays in the past and have always done it like this, only difference is that they were String arrays rather than Rectangle Arrays
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  34. Post #1274
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,137 Posts
    I don't think so, I've used arrays in the past and have always done it like this, only difference is that they were String arrays rather than Rectangle Arrays
    Check the documentation. Just looked at it, it should be rectangle[][]
    Reply With Quote Edit / Delete United States Show Events

  35. Post #1275
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    Does anyone have by any chance a sample premake4 script file for creating dynamic libraries?
    Code:
    solution "SOLUTION"
      project "PROJ"
      kind "SharedLib" -- Dynamic Library
      --kind "StaticLib" -- Static Library
      --kind "WindowedApp" -- No console window
      --kind "ConsoleApp" -- Console Window
    I assume you know the rest?
    Reply With Quote Edit / Delete Linux Denmark Show Events Agree Agree x 1 (list)

  36. Post #1276
    Absolute tosser, manchild, and belligerent douche-nozzle.
    download's Avatar
    July 2006
    6,466 Posts
    Check the documentation. Just looked at it, it should be rectangle[][]
    If that was the problem I'll be so fucked off

    Edited:

    Nope, not working

    Edited:

    Netbeans won't recognise "rectangle", but it will "Rectangle"
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  37. Post #1277
    Gold Member
    uitham's Avatar
    March 2010
    1,889 Posts
    Code:
    		for(int i = 0; i <= window.getSize().x; i++)
    		{
    			int a = window.getSize().y;
    			int b = window.getSize().x;
    			sf::Vertex vertices[] =
    			{
    
    				sf::Vertex(sf::Vector2f(  i,   0), sf::Color::Green, sf::Vector2f( 0,  0)),
    				sf::Vertex(sf::Vector2f(  i,  a - ((a>b)?b:a / (a<b)?b:a) * i), sf::Color(255 / a * ((a>b)?b:a / (a<b)?b:a), 128, 128), sf::Vector2f( 1,  1))
    			};
    			window.draw(vertices, 4, sf::Lines);
    		}
            window.display();
    For some reason, this only draws 1 line at x=0.

    When I didn't make it safe for resized windows yet, so 600 instead of a and 800 instead of b it worked for some reason.

    The point is to make a sort of triangle filling half the screen

    Don't tell me I can just use 1 triangle, I am planning to be able to control the individual sizes of each line

    Using SFML if it wasn't obvious enough already
    Reply With Quote Edit / Delete Windows 8 Netherlands Show Events

  38. Post #1278
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    In Java for arrays I believe its typename[][] variablename rather than typename variablename[][] when initializing an array.
    Both work in Java. The Java tutorials on the Oracle website only briefly mention this at the beginning, then they use "Type[] variable" for the rest of the tutorials. I've never seen another tutorial even mention it.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  39. Post #1279
    Gold Member
    Number-41's Avatar
    August 2005
    4,246 Posts
    If I have an abstract class and another one publicly inheriting from it, what will the derived class inherit? Public and protected datamembers?

    Also do I have to implement a constructor for the abstract class?
    Reply With Quote Edit / Delete Windows 7 Belgium Show Events

  40. Post #1280
    Gold Member
    esalaka's Avatar
    July 2007
    10,064 Posts
    If I have an abstract class and another one publicly inheriting from it, what will the derived class inherit? Public and protected datamembers?
    I think public inheriting just means the child class inherits everything as-is. Other sorts of inheritance are fucking complex.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events