1. Post #1201
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Its alright man, we all have something that makes us stumble. For you its installing the compiler. For me its getting shit to render right.

    I don't know why but for some reason my program only draws around maybe half of the triangles it should be. Stops around the 32,000th one or so.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  2. Post #1202
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Its alright man, we all have something that makes us stumble. For you its installing the compiler. For me its getting shit to render right.

    I don't know why but for some reason my program only draws around maybe half of the triangles it should be. Stops around the 32,000th one or so.
    Integer limit?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  3. Post #1203
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Integer limit?
    Figured it out, I was passing the number of faces not the number of integers.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1Useful Useful x 1 (list)

  4. Post #1204
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    Hey guys.

    So I'll admit I'm fairly fresh with the C++ game, but I'm not sure where the problem is here.

    Firstly, some background: I am using SFML, and decided that, because the SoundBuffer object in SFML is expensive to instantiate, I want to create a manager to optimize its usage. How this manager will work is I call a "PlaySound" method, with a filepath as an argument, on the manager - the manager will then go through an array of objects it has stored on itself. If there is a SoundBuffer in that array that is tied to that filepath, then it will simply use that buffer, rather than make a new one. If there is no buffer tied to that filepath, then it'll make a buffer for it, store it, and use that buffer.

    To tie SoundBuffers and filepaths together, I decided to make what I call a ManagerObject_Sound, which, when provided with a filepath, will store that filepath, and then create and store a SoundBuffer for that filepath. Real simple.

    However, I am having some issues.

    Firstly, I'm not exactly sure how to handle the sf::SoundBuffer, because the class is such that you can simply do
    Code:
    sf::SoundBuffer buffer;
    and it'll create the SoundBuffer into the variable "buffer." I have no idea how to create the class in such a way that it can store an object of the type sf::SoundBuffer, because I imagine if I just do something like
    Code:
    class ManagerObject_Sound {
    public:
    
    // Define the variables to be used in the constructor
    sf::SoundBuffer buffer;
    
    // Define the constructor
    ManagerObject_Sound();
    then it'll just create a buffer right then and there.

    Secondly, using the code below, I get compile errors:

    Code:
    #include <SFML/Audio.hpp>
    using namespace std;
    
    class ManagerObject_Sound {
    	public:
    
    	string filepath;
    	sf::SoundBuffer* buffer;
    
    	ManagerObject_Sound(string);
    	bool IsForFile(string);
    	sf::SoundBuffer* GetSoundBuffer();
    }
    
    ManagerObject_Sound::ManagerObject_Sound(string fpath)
    {
    	filepath = fpath;
    
    	buffer = new sf::SoundBuffer();
    
    	if (!buffer.LoadFromFile(fpath))
    	{
    		// Error loading
    	}
    }
    
    bool ManagerObject_Sound::IsForFile(string fpath)
    {
    	return (filepath==fpath);
    }
    
    sf::SoundBuffer* ManagerObject_Sound::GetSoundBuffer()
    {
    	return buffer;
    }
    Code:
    1>c:\users\jason\documents\visual studio 2008\projects\ragnarok_client\ragnarok_client\manobj_sound.cpp(16) :
    error C2533: 'ManagerObject_Sound::{ctor}' : constructors not allowed a return type
    I don't know why it is thinking I am trying to return something in my constructor, because I am obviously not.

    Please forgive me if the class is a horrible abomination: I am going off a somewhat-confusing tutorial's example, and I have absolutely no idea what to do with the SoundBuffer, as explained early. A friend of mine suggested to use a pointer (*), but he admitted he's rusty on C++ and isn't sure.

    Any help for either of these issues would be greatly appreciated.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  5. Post #1205
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Rather than creating a new managerobject_sound for each buffer, you may want to create a vector.

    So rather than sf::buffer* you would have
    Code:
    std::vector<sf::buffer> buffer;
    Then setup a function like.
    Code:
    void addToBuffer(sf::buffer addBuffer)
    {
         buffer.push_back(addBuffer);
    }
    What this does is rather than creating an array of thirty objects, it creates a vector that can be expanded as needed rather than initializing every buffer before its even needed. You can also check if an existing buffer of that type is already in the vector as well.

    You may want to check with someone smarter than me though.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Informative Informative x 1 (list)

  6. Post #1206
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    Interesting idea. I'll be sure to look into vectors, and what exactly they are and how they work. Thanks for the suggestion.

    Any other ideas are welcome, of course.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #1207
    Dennab
    July 2009
    2,787 Posts
    So, I am trying to solve a sprite layering issue in XNA 4.0

    I decided the best method of approaching my issue is putting all the instances of the "Window" class in a list called "WindowList" this is to make the layering work properly so that clicking a window will bring it forth. I use an insertion sort loop to put them all in order in the list to draw the deepest one first, and then drawing the second deepest and so on. The problem is that the draw order seems completly fucked in this case. It's pretty much random with both layering and detection of where I click

    Code:
     public void SortWindows()
            {
                for (int i = 1; i < WindowList.Count; i++)
                {
                    for (int j = i; j > 0; j--)
                    {
                        if (WindowList[j].WindowLayerDepth > WindowList[j - 1].WindowLayerDepth)
                        {
                            AttractionWindow tmp = WindowList[j - 1];
                            WindowList[j - 1] = WindowList[j];
                            WindowList[j] = tmp;
                        }
    
                        else
                            break;
                    }
                }
            }
    Is in the Game1 class, calls every loop, will change to only call when needed.

    Code:
    protected override void Draw(GameTime gameTime)
            {
                GraphicsDevice.Clear(Color.Black);
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                for (int i = 0; i < WindowList.Count; i++)
                {
                    WindowList[i].Draw(spriteBatch);
                }
                spriteBatch.End();
    
                base.Draw(gameTime);
            }
    and here's the click detection code

    Code:
    if (CurrentmouseState.LeftButton == ButtonState.Pressed && OldMouseState.LeftButton == ButtonState.Released)
                {
                    bool Invalid = false;
                    int ExcludeWindow = 0;
                    for (int i = 0; i < main.WindowList.Count; i++)
                    {
                        if (main.WindowList[i].rectangle.Intersects(rectanglePoint) && main.WindowList[i].TopWindow == true)
                        {
                            Invalid = true;
                            break;
                        }
                    }
    
                    if (!Invalid)
                    {
                        for (int i = 0; i < main.WindowList.Count; i++)
                        {
                            if (main.WindowList[i].rectangle.Intersects(rectanglePoint))
                            {
                                main.WindowList[i].surfaceWindow();
                                main.WindowList[i].TopWindow = true;
                                ExcludeWindow = i;
                                break;
                                
                            }
                        }
    
                        {
                            for (int i = 0; i < main.WindowList.Count; i++)
                            {
                                if (i != ExcludeWindow)
                                {
                                    main.WindowList[i].TopWindow = false;
                                }
                            }
                        }
                    }
                    
                }
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  8. Post #1208
    Jaykin' Bacon: Episode Three
    Jimbomcb's Avatar
    February 2005
    23,742 Posts
    so... I have a file I need to decompress

    http://dl.dropbox.com/u/1032139/token

    I know it's compressed using some method, I was assuming zlib but nothing seemed to work. am I missing something, is there some tell-tale way to work out what way it's compressed or am I out of luck.
    Reply With Quote Edit / Delete Windows 7 Show Events

  9. Post #1209
    krassell's Avatar
    January 2009
    351 Posts
    I need real quick way to write symbol-by-symbol to the console.
    putchar() takes shameful amount of time to fill 80*50.
    I don't really care how hacky it will be, speed is what matters.
    Oh also, that is, in C++.
    Reply With Quote Edit / Delete Windows 7 Russian Federation Show Events

  10. Post #1210
    Gold Member
    esalaka's Avatar
    July 2007
    10,249 Posts
    Curses?
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  11. Post #1211
    kill yourself
    Protocol7's Avatar
    June 2006
    26,086 Posts
    Interesting idea. I'll be sure to look into vectors, and what exactly they are and how they work. Thanks for the suggestion.

    Any other ideas are welcome, of course.
    Vectors are fantastic. They're STL containers (standard template library).

    Templates basically mean that you can define one class or function, use templates and every time you invoke it, you can set the data type it will handle. That's why when darkrei9n did

    std::vector<sf::SoundBuffer> buffer;

    You see the SoundBuffer in the angle brackets; that's instantiating a vector container that stores objects of type SoundBuffer. Which is, from what I gather, what you want to do.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  12. Post #1212
    Gold Member
    Chryseus's Avatar
    February 2009
    2,470 Posts
    import pyglet
    from pyglet.gl import *
    import math
    
    class Camera(object):
    	def __init__(self):
    		self.x = 0
    		self.y = 0
    		self.z = 0
    		self.rotx = 0
    		self.roty = 0
    		self.rotz = 0
    		
    class Game(pyglet.window.Window):
    	def __init__(self):
    		super(Game, self).__init__()
    		self.setupViewport(60, 0.1, 1000)
    		glEnable(GL_POINT_SMOOTH)
    		glPointSize(2.0)
    	def on_draw(self):
    		glLoadIdentity()
    		gluLookAt(0,0,-10,0,0,0,0,1,0)
    		glBegin(GL_POINTS)
    		glColor3f(1.0,0,0)
    		glVertex3f(0,0,0)
    		glEnd()
    		glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
    		self.clear()
    	def drawCube(self, x, y, width, height, style):
    		glBegin(GL_QUADS)
    		glColor3f(1.0,0,0)
    		glVertex3f(-1.0,-1.0,0) # TL
    		glVertex3f(-1.0,-1.0,-1.0) # TLB
    		glVertex3f(1.0,-1.0,0) # TR
    		glVertex3f(1.0,-1.0,-1.0) # TRB
    		
    		glColor3f(0,1.0,0)
    		glVertex3f(-1.0,-1.0,-1.0) # BTL
    		glVertex3f(1.0,-1.0,-1.0) # BTR
    		glVertex3f(1.0,1.0,-1.0) # BBR
    		glVertex3f(-1.0,1.0,-1.0) # BBL
    		glEnd()
    	def setupViewport(self, fov, nearclip, farclip):
    		aspect = self.width / self.height
    		glViewport(0,0,self.width,self.height)
    		glMatrixMode(GL_PROJECTION)
    		glLoadIdentity()
    		gluPerspective(80,aspect,nearclip,farclip)
    		glMatrixMode(GL_MODELVIEW)
    
    g = Game()
    pyglet.app.run()

    It worked fine with a plain old orthographic projection matrix but now that I've switched it to perspective I can't see anything, it's driving me mad.

    Never mind I fixed it, had to override the on_resize event
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  13. Post #1213
    Team Hamster
    Mordi's Avatar
    January 2012
    312 Posts
    I need some help determining 2D texture-coordinates.

    I've got a big spritefont-texture, and I want to get the coordinates of a single character. I have saved the x/y-offsets of each character in pixels, and I also have the width. What I have tried is diving these by the width and height of the spritefont and using this as the coordinates, but this did not seem to work. Am I doing something else wrong, or is my math off here?

    Edit: Nevermind, I figured it out. I was casting wrongly.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  14. Post #1214
    HeatPipe's Avatar
    October 2007
    1,574 Posts
    Hello. How can I make one additional reference of one class datatype pointing to existing object?

    Like, I have two references in stack pointing into one single object in the heap?
    Reply With Quote Edit / Delete Windows 7 Slovenia Show Events

  15. Post #1215
    kill yourself
    Protocol7's Avatar
    June 2006
    26,086 Posts
    Hello. How can I make one additional reference of one class datatype pointing to existing object?

    Like, I have two references in stack pointing into one single object in the heap?
    Wouldn't that just be two pointers?

    Just declare two stack pointers with the address of the heap object. I think.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  16. Post #1216
    Gold Member
    ShaunOfTheLive's Avatar
    November 2007
    9,907 Posts
    so... I have a file I need to decompress

    http://dl.dropbox.com/u/1032139/token

    I know it's compressed using some method, I was assuming zlib but nothing seemed to work. am I missing something, is there some tell-tale way to work out what way it's compressed or am I out of luck.
    I'll try to figure it out, but it better not be a virus (I got ass fucked before by a virus from here and almost lost my FP account)

    EDIT: it doesn't have any recognizable header or anything distinguishing it from random data... sorry bro can't help
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  17. Post #1217
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Trying to generate indices for a cube, anyone know any equations?
    Reply With Quote Edit / Delete Windows 8 United States Show Events

  18. Post #1218
    Gold Member
    raccoon12's Avatar
    November 2008
    3,175 Posts
    Help
    1>------ Build started: Project: TerrainGeneration, Configuration: Debug Win32 ------
    1> main.cpp
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ terrainwindow.hpp(33): warning C4018: '<=' : signed/unsigned mismatch
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(3): error C2011: 'Entity' : 'class' type redefinition
    1> r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(3) : see declaration of 'Entity'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(11): error C2027: use of undefined type 'Entity'
    1> r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(3) : see declaration of 'Entity'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(13): error C2065: 'texture' : undeclared identifier
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(13): error C2228: left of '.loadFromFile' must have class/struct/union
    1> type is ''unknown-type''
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(19): error C2355: 'this' : can only be referenced inside non-static member functions
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(19): error C2227: left of '->setTexture' must point to class/struct/union/generic type
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ entity.hpp(19): error C2065: 'texture' : undeclared identifier
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(8): error C2079: 'ent' uses undefined class 'Entity'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(8): error C2079: 'ent2' uses undefined class 'Entity'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(9): error C2228: left of '.textureInit' must have class/struct/union
    1> type is 'int'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(10): error C2228: left of '.setPosition' must have class/struct/union
    1> type is 'int'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(12): error C2228: left of '.textureInit' must have class/struct/union
    1> type is 'int'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(13): error C2228: left of '.setPosition' must have class/struct/union
    1> type is 'int'
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(15): error C2664: 'TerrainWindow::AddDrawableToVector' : cannot convert parameter 1 from 'int' to 'Entity'
    1> Source or target has incomplete type
    1>r:\users\bryton\documents\visual studio 2010\projects\terraingeneration\terraingeneration\ main.cpp(16): error C2664: 'TerrainWindow::AddDrawableToVector' : cannot convert parameter 1 from 'int' to 'Entity'
    1> Source or target has incomplete type
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    main.cpp
    Code:
    #include "TerrainWindow.hpp"
    #include "Entity.hpp"
    int main()
    {
    	TerrainWindow wnd;
    	wnd.CreateTerrainWindow(800, 600, 32, "Test of SFML Engine");
    
    	Entity ent, ent2;
    	ent.textureInit("dot.png");
    	ent.setPosition(10.0f, 10.0f);
    
    	ent2.textureInit("dot.png");
    	ent2.setPosition(100.0f, 100.0f);
    
    	wnd.AddDrawableToVector(ent);
    	wnd.AddDrawableToVector(ent2);
    
    	wnd.TerrainWindowLoop();
    }
    //
    TerrainWIndow.hpp
    Code:
    #include "BasicInclude.h"
    #include "Entity.hpp"
    class TerrainWindow 
    {
    	// terrain window
    public:
    	void CreateTerrainWindow(int width, int height, int bits, std::string title);
    //	sf::RenderWindow GetTerrainWindow();
    	void TerrainWindowLoop();
    //	bool GetState();
    //	void SetState(bool running);
    	void CreateSinWave();
    	void AddDrawableToVector(Entity newDrawable);
    	void Draw();
    protected:
    	sf::RenderWindow Wnd;
    //	bool isRunning;
    //	sf::Sprite sinWave;
    	std::vector<Entity> sprites;
    };
    
    void TerrainWindow::CreateTerrainWindow(int width, int height, int bits, std::string title)
    {
    	Wnd.create(sf::VideoMode(width, height, bits), title);
    }
    
    void TerrainWindow::AddDrawableToVector(Entity newDrawable)
    {
    	sprites.push_back(newDrawable);
    }
    void TerrainWindow::Draw()
    {
    	for(int i = 0; i <= sprites.size(); i++)
    	{
    		Wnd.draw(sprites.at(i));
    		std::cout << i << "\n";
    		std::cout << sprites.size();
    	}
    }
    void TerrainWindow::TerrainWindowLoop()
    {	
    	while(Wnd.isOpen())
    	{
    		sf::Event events;
    		while (Wnd.pollEvent(events))
    		{
    			
    			if (events.type == sf::Event::Closed)
    				Wnd.close();
    		}
    		Wnd.clear();
    		TerrainWindow::Draw();
    		Wnd.display();
    	}
    }
    Entity.hpp
    Code:
    #include "BasicInclude.h"
    
    class Entity : public sf::Sprite
    {
    public:
    	void textureInit(std::string file);
    private:
    	sf::Texture texture;
    };
    
    void Entity::textureInit(std::string file)
    {
    	if(!texture.loadFromFile(file))
    	{
    		std::cout << "Error opening " << file << "\n";
    	}
    	else
    	{
    		this->setTexture(texture);
    	}
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #1219
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Trying to generate indices for a cube, anyone know any equations?
    Do it by hand in your head?
    DebugVertex_t cubeVerts[] = 
    		{
    			//POSITION - TOP
    			{glm::vec3(vecMin.x,  vecMax.y,  vecMin.y), color}, //LEFT BACK
    			{glm::vec3(vecMax.x,  vecMax.y,  vecMin.y), color}, //RIGHT BACK
    			{glm::vec3(vecMin.x,  vecMax.y,  vecMax.y), color}, //LEFT FRONT
    			{glm::vec3(vecMax.x,  vecMax.y,  vecMax.y), color}, //RIGHT FRONT
    
    			//POSITION - BOTTOM
    			{glm::vec3(vecMin.x,  vecMin.y,  vecMin.y), color}, //LEFT BACK
    			{glm::vec3(vecMax.x,  vecMin.y,  vecMin.y), color}, //RIGHT BACK
    			{glm::vec3(vecMin.x,  vecMin.y,  vecMax.y), color}, //LEFT FRONT
    			{glm::vec3(vecMax.x,  vecMin.y,  vecMax.y), color}, //RIGHT FRONT
    		};
    
    		//Create some Indexes
    		unsigned int crossIndexes[] =
    		{
    			//TOP
    			0, 1,
    			2, 3,
    			0, 2,
    			1, 3,
    
    			//BOTTOM
    			4, 5,
    			6, 7,
    			4, 6,
    			5, 7,
    
    			//SIDES
    			0, 4,
    			1, 5,
    			2, 6,
    			3, 7,
    		};
    
    		m_iIndexCount = 24;
    
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  20. Post #1220
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Do it by hand in your head?
    DebugVertex_t cubeVerts[] = 
    		{
    			//POSITION - TOP
    			{glm::vec3(vecMin.x,  vecMax.y,  vecMin.y), color}, //LEFT BACK
    			{glm::vec3(vecMax.x,  vecMax.y,  vecMin.y), color}, //RIGHT BACK
    			{glm::vec3(vecMin.x,  vecMax.y,  vecMax.y), color}, //LEFT FRONT
    			{glm::vec3(vecMax.x,  vecMax.y,  vecMax.y), color}, //RIGHT FRONT
    
    			//POSITION - BOTTOM
    			{glm::vec3(vecMin.x,  vecMin.y,  vecMin.y), color}, //LEFT BACK
    			{glm::vec3(vecMax.x,  vecMin.y,  vecMin.y), color}, //RIGHT BACK
    			{glm::vec3(vecMin.x,  vecMin.y,  vecMax.y), color}, //LEFT FRONT
    			{glm::vec3(vecMax.x,  vecMin.y,  vecMax.y), color}, //RIGHT FRONT
    		};
    
    		//Create some Indexes
    		unsigned int crossIndexes[] =
    		{
    			//TOP
    			0, 1,
    			2, 3,
    			0, 2,
    			1, 3,
    
    			//BOTTOM
    			4, 5,
    			6, 7,
    			4, 6,
    			5, 7,
    
    			//SIDES
    			0, 4,
    			1, 5,
    			2, 6,
    			3, 7,
    		};
    
    		m_iIndexCount = 24;
    
    Need to be able to do it for any size cube. Essentially setting up a function to create a cube that can be any size depending on arguments.
    Reply With Quote Edit / Delete Windows 8 United States Show Events

  21. Post #1221
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Need to be able to do it for any size cube. Essentially setting up a function to create a cube that can be any size depending on arguments.
    Indexes don't change. Either way the code above should get you a cube that's the size of the mins/maxs.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #1222
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Indexes don't change. Either way the code above should get you a cube that's the size of the mins/maxs.
    As in a 4x4x4 vertex cube or a 2x2x2 vertex cube. So the indices do change in this case.
    Reply With Quote Edit / Delete Windows 8 United States Show Events

  23. Post #1223
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    I need real quick way to write symbol-by-symbol to the console.
    putchar() takes shameful amount of time to fill 80*50.
    I don't really care how hacky it will be, speed is what matters.
    Oh also, that is, in C++.
    char buff[80*50];
    memset(buff, 'X', sizeof(buff));
    write(1, buff, sizeof(buff));
    
    Reply With Quote Edit / Delete Mac Australia Show Events

  24. Post #1224
    Gold Member
    Jookia's Avatar
    July 2007
    6,768 Posts
    I need real quick way to write symbol-by-symbol to the console.
    putchar() takes shameful amount of time to fill 80*50.
    I don't really care how hacky it will be, speed is what matters.
    Oh also, that is, in C++.
    Curses.
    Reply With Quote Edit / Delete Linux Australia Show Events Disagree Disagree x 2 (list)

  25. Post #1225
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 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.

    However, I now have a new issue.

    The object class I made is, as before, called ManagerObject_Sound.

    In my manager class, which is Manager_Sound, I decided to use a vector, since darkrei9n brought them to my attention and they sound awesome. Using the generic form of "std::vector<DATA TYPE> VARNAME;", I do such:

    Code:
    class Manager_Sound {
    public:
    	std::vector<ManagerObject_Sound> ObjectVector;
    
    	Manager_Sound();
    };
    However, doing so, I get this error:
    Code:
    1>c:\users\jason\documents\visual studio 2008\projects\ragnarok_client\ragnarok_client\manager_sound.cpp(8) : error C2065: 'ManagerObject_Sound' : undeclared identifier
    I've replaced the "ManagerObject_Sound" in that vector declaration with "int," and it works fine, so it's not the vector.

    Any ideas? Google didn't bring up much for me.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #1226

    January 2012
    422 Posts
    Seems to me that the compiler cannot find your datatype for ManagerObject_Sound. Did you include it?
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  27. Post #1227
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    Seems to me that the compiler cannot find your datatype for ManagerObject_Sound. Did you include it?
    Do I need to?

    The file's name is "manobj_sound.cpp". I just tried simply doing "include <manobj_sound>", but it says it can't include manobj_sound.

    Forgive the newbiness / stupidity, but the tutorials I've seen about classes all seem to be pretty hazy about this stuff, so I really don't know about this, and I don't really have any friends that can help me out much here, so you guys are my only hope when Google turns up nothing that I find very useful.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  28. Post #1228
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Do I need to?

    The file's name is "manobj_sound.cpp". I just tried simply doing "include <manobj_sound>", but it says it can't include manobj_sound.

    Forgive the newbiness / stupidity, but the tutorials I've seen about classes all seem to be pretty hazy about this stuff, so I really don't know about this, and I don't really have any friends that can help me out much here, so you guys are my only hope when Google turns up nothing that I find very useful.
    #include only includes the file for that file that calls it along with any files called by the file you just included.

    Let me show you the hierarchy for my project, might help you understand #include better.

    Okay nevermind, VS11 doesn't want to generate the graph of my include files.

    Think about it like a hirearchy. Main could include <iostream> and you could have two headers include main, but as far as those two files are concerned unless you include the other they don't exist. Anything that main included they acknowledge but nothing else.
    Reply With Quote Edit / Delete Windows 8 United States Show Events

  29. Post #1229

    January 2012
    422 Posts
    #include <ashdasd>
    is different from
    #include "askjdfasd"
    See here: http://stackoverflow.com/questions/2...clude-filename

    You would need to do #include "manobj_sound.cpp", and typically you would want to do the header file instead.

    As a side note, http://cplusplus.com is great for language and function reference.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  30. Post #1230
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    #include <ashdasd>
    is different from
    #include "askjdfasd"
    See here: http://stackoverflow.com/questions/2...clude-filename

    You would need to do #include "manobj_sound.cpp", and typically you would want to do the header file instead.

    As a side note, http://cplusplus.com is great for language and function reference.
    Fair enough. My object doesn't have a header, though. Should I make it one, and if so, what all should be in it?

    Also, doing #include "manobj_sound.cpp" in the file for for my manager alleviated that issue, but now I have a new issue:

    Code:
    1>manobj_sound.obj : error LNK2005: "public: __thiscall ManagerObject_Sound::ManagerObject_Sound(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0ManagerObject_Sound@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in manager_sound.obj
    1>manobj_sound.obj : error LNK2005: "public: class sf::SoundBuffer __thiscall ManagerObject_Sound::GetBuffer(void)" (?GetBuffer@ManagerObject_Sound@@QAE?AVSoundBuffer@sf@@XZ) already defined in manager_sound.obj
    1>manobj_sound.obj : error LNK2005: "public: bool __thiscall ManagerObject_Sound::IsCorrectBuffer(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?IsCorrectBuffer@ManagerObject_Sound@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in manager_sound.obj
    And I have no idea what that means. I see it's referring to the functions in my ManagerObject_Sound, though, whose code is as thus:

    Code:
    #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);
    };
    
    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);
    };


    Nevermind, I figured it out. I'm glad I downloaded the source code for the open-source Roguelike "Cataclysm" (had to recompile it myself, with a provided hotfix), because I just looked at how they handle .cpp's and .h's. That stackoverflow thread you linked me to helped as well, with the examples posted in it.

    Thanks a lot guys.

    Edited:

    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);
    };
    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);
    };
    I suggest you read through the language tutorial on http://cplusplus.com. 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::
    Yeah, I went through the entirety of the tutorial on that site (that's where I started), and it doesn't really explain any of this stuff that well at all. Trust me, I've looked at it enough times.

    I already established that, as you can see in my post edit - having actual source code to reference helps me a lot in these things.

    And I know about needing to use the std namespace, and how it's generally better to prefix things with std:: - the only reason that's there is legacy code when I was trying to figure out what was going wrong with the vector thing.

    Like I said, though, I've got it all figured out. Thanks a lot.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  31. Post #1231

    January 2012
    422 Posts
    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);
    };
    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);
    };
    I suggest you read through the language tutorial on http://cplusplus.com. 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::
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  32. Post #1232
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    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.

    :(.

    Just for clarification: the two sounds I am using are "explode1.wav," from the HL2 "Source Sounds.gcf", and the "creeper1.ogg" from Minecraft.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  33. Post #1233
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    Is it set to automatically loop and are you using pause() or stop() to stop playing?
    Reply With Quote Edit / Delete United States Show Events

  34. Post #1234
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    Is it set to automatically loop and are you using pause() or stop() to stop playing?
    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.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  35. Post #1235
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    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.
    Are you sure the volume variable is set to 100, By default it should be but you may want to double check.
    Reply With Quote Edit / Delete United States Show Events

  36. Post #1236

    January 2012
    422 Posts
    Post Code.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  37. Post #1237
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    Relevant code is as follows:

    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
    Code:
    ManagerObject_Sound::ManagerObject_Sound(string fpath)
    {
    	filepath = fpath;
    
    	buffer.LoadFromFile(fpath);
    };
    
    sf::SoundBuffer ManagerObject_Sound::GetBuffer()
    {
    	return buffer;
    };
    SoundManager:
    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);
    }
    MasterManager (.h, then .cpp):
    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:
    #include "master_manager.h"
    
    MasterManager::MasterManager()
    {
    };
    main
    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;
    		}
    	}
    }
    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).
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  38. Post #1238
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    try returning the offset on the sound rather than false. If you notice that its not moving call stop when its done.
    Reply With Quote Edit / Delete United States Show Events

  39. Post #1239
    Please waste more of your money changing this title again.
    Gmod4ever's Avatar
    August 2005
    6,840 Posts
    try returning the offset on the sound rather than false. If you notice that its not moving call stop when its done.
    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. :).
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  40. Post #1240
    Gold Member
    darkrei9n's Avatar
    November 2007
    5,367 Posts
    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. :).
    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.
    Reply With Quote Edit / Delete United States Show Events