Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Flash619

Pages: 1 2 3 [4] 5 6 ... 10
46
General / Re: References returning null values?
« on: November 02, 2012, 07:46:16 pm »
Shared pointers maybe. But there are simpler ways to deal with that. Manager classes put in well thought locations. See : http://en.sfml-dev.org/forums/index.php?topic=9437.msg64068#msg64068
Quote
the "getSprite" function seems completely useless and a waste of code
Yes!

Thanks for the link! It does seem a good idea to just include it in the main game state manager class, then I can just use that to sort of bounce off of to access it. Once I get a few new functions wrote for my window, I may try to take a look at that. :)

47
General / Re: References returning null values?
« on: November 02, 2012, 06:54:19 pm »
I don't understand the question, it's too simple. c++ is all about RAII, pointers and classes, how can you miss that is.. ???
Honestly, what do Java developers do if none of the problems you had so far appear in Java? :o

>.> I've only touched Java in my spare time to make modifications/plugins for Minecraft. ^^;;

What I'm saying is I don't understand how to make "return s;" not make variables go out of scope when it leaves the class. I understand the concept of "out of scope", and that its removing the memory allocation the moment I use "=" but I don't know how to do it any other way than that. As I said earlier, I tried it with pointers, it threw more errors than the references did.

And yes, I even understand why they throw an error. They throw a memory access violation. Meaning that its pointing to data that is "out of scope" and no longer there.

I do understand the concepts, but I don't actually know any of the hands on how to fix it stuff and because of that, a simple class like this, could quite literally, take me an entire day. That's why I come here for help hoping someone knows what it is I'm looking to do and can explain how. xD I know how to break things in code but how to fix things or rather "make things work" can be a mystery.

This code right here:

sf::Sprite GenesisLogo_S;
                GenesisLogo_S.setTexture(texture.getTexture("Resource/SplashScreen/PredawnStudios/Genesis_Logo_XL.png"));
 

Works just fine, so that kinda makes me realize that the "getSprite" function seems completely useless and a waste of code. After all either way I need to declare the sprite in my splash screen file, so if I use get sprite then what happens, it makes another sprite, so I have a sprite and another sprite, which seems wasteful to me and like it would *very very minutely* slow it down some.

48
General / Re: References returning null values?
« on: November 02, 2012, 06:46:33 pm »
sf::Sprite Sprite::getSprite(std::string path)
{
    Texture texture;
    sf::Sprite s;
    s.setTexture(texture.getTexture(path));

    return s;
}//HERE!!!
HERE!!! - Your texture object gets out of scope = it destroys all texture objects it allocated.

Well that's what I knew the problem was originally, but how do I return it to another class/file without it going out of scope?  ??? I mean, not using a "=" seems nearly impossible, but then again, I don't know everything about everything.

I figured that when you said to make a new copy of the sprite... that that's what you meant.

49
General / Re: References returning null values?
« on: November 02, 2012, 06:22:14 pm »
find() return iterator to element with that key or iterator equal to iterator returned by end() if element doesn't exist.

So I have it setup like.....

#include "stdafx.h"
#include "SpriteUtilities.h"
sf::Sprite Sprite::getSprite(std::string path)
{
        Texture texture;
        sf::Sprite s;
        s.setTexture(texture.getTexture(path));

        return s;
}
sf::Texture& Texture::getTexture(std::string& path)
{
        std::map<std::string,sf::Texture>::iterator it = mTextures.find(path);
        if(it==mTextures.end())
        {
                log.info("Attempting to load texture at: " + path);
                if(!mTextures[path].loadFromFile(path))
                {
                        log.error("Unable to load texture from path: " + path);
                        log.error("Texture errors detected, graphic failure may occur!");
                        return it->second;
                }
                it = mTextures.find(path);
                return it->second;
        }

}
 

But When I do

                sf::Sprite GenesisLogo_S;
                GenesisLogo_S = sprite.getSprite("Resource/SplashScreen/PredawnStudios/Genesis_Logo_XL.png");
 

and I print it to the screen, its the right size, but it is still white.  :-\

Is it because of how I'm returning?

50
General / Re: References returning null values?
« on: November 02, 2012, 06:07:31 pm »
Actually, map<sf::Texture> should be map<std::string,sf::Texture> instead. And 'return it->second;' instead of *it.
http://www.cplusplus.com/reference/stl/map/find/
There is no use in holding sprites in a map. Just return them as copy. That's what tutorials say.

The only thing I still find confusing is the if statement. ^^;;; I solved the rest.

I just cant figure out what the "end()" is for.


OOOOH I think I get it, its because you told it to search for it, so then if its at the end it didn't find anything and then you add it?

51
General / Re: References returning null values?
« on: November 02, 2012, 05:55:44 pm »
This is not a hash map, this will be sorted, and if you use begin() and end() to iterate over that, it'll iterate in alphabetical order. Hash maps are(I think) under name unordered_map in boost, tr1 and c++11.

Yea that makes sense. I think I would just stick with the std::map tho and learn how to properly use that instead of going with a unordered map.

So would I have to have two maps then like?:

std::map<sf::Texture> mTextures; //Holds the textures.
std::map<sf::Sprite> mSprites; //Holds the sprites that get the textures from the texture map.
 

It seems like the easiest way but I'm not sure if there is a better one.

Also in your code at:

if(it==mTexture.end()) //Why did you check to see if the iterator was at the end of the map? Was that to check
{                                  //to see if there was already a instance of it in the map?
mTextures[gName].loadFromFile(gName);
it = mTextures.find(gName);
}
 

52
General / Re: References returning null values?
« on: November 02, 2012, 05:46:59 pm »
This stores textures by paths(might contain errors, wrote it in like 30 seconds..):
class sss
{
private:
std::map<sf::Texture> mTextures;
public:
sf::Texture& get(const std::string& gName);
};

sf::Texture& sss::get(const std::string& gName)
{
std::map<sf::Texture>::iterator it = mTextures.find(gName);
if(it==mTexture.end())
{
mTextures[gName].loadFromFile(gName);
it = mTextures.find(gName);
}
return *it;
}
 

Seems kinda similar to a Java hash map.  ;D

53
General / Re: References returning null values?
« on: November 02, 2012, 05:40:22 pm »
I've never used std::map before. Would I just store the variable in there, and then transfer that?

Between the two options you mentioned which would you recommend? Either way I would like to learn more about dynamically allocating memory.

54
General / References returning null values?
« on: November 02, 2012, 05:20:58 pm »
Ok I'll admit, this is my mess up.  I even know whats wrong, I just don't know how to fix it. ^^;

So I have a little class *actually two classes* that I made to handle sprite/texture stuff to lower down the amount of re used code in other classes. What they do is very easy to figure out. If you want a sprite, you use get sprite, send it the path, it uses texture to retrieve the texture and such. But I'm trying to 1, figure out why its not working, and 2, trying to make a decision as to how to return the variables.

Option a, would be to use references *what I'm trying currently* but then that makes me wonder if it would conflict with other instances of the same class. *if two things tried to get a sprite at once*

Option b, Or if it would be better to just make a new copy of the variable every time. *would use more memory and such*.

As for the code here it is:
#include "stdafx.h"
#include "SpriteUtilities.h"
sf::Sprite& Sprite::getSprite(std::string path)
{
        Texture texture;
        sf::Sprite s;
        s.setTexture(texture.getTexture(path));

        return s;
}
sf::Texture& Texture::getTexture(std::string path)
{
        sf::Texture t;
        log.info("Attempting to load texture at: " + path);
        if(!t.loadFromFile(path))
        {
                log.error("Unable to load texture from path: " + path);
                log.error("Texture errors detected, graphic failure may occur!");
                return t;
        }
        return t;
}
 

The problem is that since the variable is declared in a outside class/function, the moment it returns the reference the memory allocation is cleared and it returns a blank sprite. I just don't really remember how to fix it. >.>'

So any help, and recommendations as to which way would be best to go, is greatly appreciated! :) I did indeed try pointers but they didn't just say error, they screamed it, all over my build log.  ::) So I decided to try references. ^^;;

Huge thanks in advance and as always, if you wish to know more just ask! :)

55
General / Re: Accepting User Input, and Gui/library recommendations?
« on: November 01, 2012, 05:27:53 pm »
I can try to create my own mini window and take a crash course on the win32 library functions to try to figure out how to implement and read from a basic text box. Or I can try to find some sort of Library such as Qt or WxWidgets, and use some of their build in functions for it.
Like I said if possible I would like to have the box within the window itself, and not another separate popup window.
Using an GUI library like MFC, Qt or WxWidget won't give you the possibility to have GUI elements on top of the OpenGL/SFML rendering (afaik), thus you can't really use those.
The 'easiest' thing would be to use the OS specific 'message boxes' (or Qt's equivalent), but this would then be a 'pop-up' window, which you don't want.
So this leaves you with the SFML/OpenGL GUIs, like SFGUI (gets my recommendation), TGUI or basically anything that can implement an OpenGL renderer (e.g. GWEN or CEGUI).
Good luck! :)

This definitively looks interesting! I had never heard of it before, and it looks, amazing. o.o; Thanks a bunch! :D I'll update this later to tell how it went. ^_^

56
General / Accepting User Input, and Gui/library recommendations?
« on: November 01, 2012, 03:46:42 pm »
       So I have come to the point in my engine, where I will need the user to input a string into a little box in the window. It seems I have two choices for this, either 1, I can try to create my own mini window and take a crash course on the win32 library functions to try to figure out how to implement and read from a basic text box. Or I can try to find some sort of Library such as Qt or WxWidgets, and use some of their build in functions for it.

         Now having never done any three of the above options, I really was hoping to get some personal input on the subject, as to what you would recommend and possibly why. I do think making my own system for message box's and input would give much more custom control, but at the same time, it seems like a big chance for me to create a lot of inefficient/possibly unstable code because I have never used text box's before, ever. ^^;; The only popup experience I have is a win32 message box that accepts yes or no. >.>

        So yes I would love to hear your input. Like I said if possible I would like to have the box within the window itself, and not another separate popup window. It would basically have two buttons and a text box. Let me know what you think, and huge thanks in advance! :)

57
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: October 30, 2012, 10:47:57 pm »
What does "including a DLL" means?

Including as in, the .dll's come with the .exe right next to it so that the program runs with dynamically linked libraries.

58
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: October 30, 2012, 10:46:06 pm »
Yes. This will prevent different versions of SFML from being loaded (although I admit this is an issue only because I explicitly link against SFML 2.0 RC), and as sfeMovie is dynamically linked to SFML, in any case you'll need to provide the SFML dlls.

Well if I'm including the .dll's, I may as well just set it to dynamic then.  ;D

59
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: October 30, 2012, 10:34:07 pm »
Hmm, make sure you're linking everything dynamically AND in release mode. sfeMovie is not provided as debug library for now.

So all of SFML has to be linked dynamically as well then?

60
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: October 30, 2012, 09:53:28 pm »

So I got it working for the most part on 2010 without issue. But I have a problem now.

I get:
Quote
First-chance exception at 0x773d4b32 in Genesis.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0107f0e4..
First-chance exception at 0x773d4b32 in Genesis.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0107e8a0..
First-chance exception at 0x773d4b32 in Genesis.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
Unhandled exception at 0x773d4b32 in Genesis.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0107e8a0..

Every time it reaches:

        if(!CS.openFromFile("Resource/SplashScreen/PredawnStudios/predawn_splash.theora.ogv"))
        {
                ConsoleLog.info("Unable to open splash video file! Returning...");
                return;
        }
 

Any ideas?

Pages: 1 2 3 [4] 5 6 ... 10
anything