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 - Grimshaw

Pages: 1 ... 38 39 [40]
General / [Solved] Resource Manager
« on: January 03, 2011, 04:27:11 am »
SearchFileName is just a parameter that you would pass through the search function! Check now!

Notice this:

vector< pair<string, sf::Image*> > ImageList;

So, ImageList is a vector, a dynamic array which contains in each position a pair<string, sf::Image*>.

ImageList with 2 images loaded:
ImageList[0] is a pair<string, sf::Image*>
ImageList[1] is also a pair<string, sf::Image*>

When you reference the ImageList, being i a valid position, it counts as the pair, and you can check the pair values, using first and second, that will return objects you stored. Check STL and C++ documentation for a better information : )


General / [Solved] Resource Manager
« on: January 03, 2011, 04:14:01 am »
Overwrite, a pointer holds one address, no matter what!

Commonly, a pointer to any structure has 4 bytes size in a 32 bits system, if i'm remembering well.

General / [Solved] Resource Manager
« on: January 03, 2011, 04:02:57 am »
I will try to explain the use of pointers generally:
(If you have doubts, feel free to add me on msn)

So, when you declare a sf::Image:

Code: [Select]
sf::Image img;

... you are allocating some memory, you can check how much using the function sizeof, like this:

Code: [Select]
sizeof(img); //sizeof(sf::Image) is also valid! Function returns size in bytes

When you do this:

Code: [Select]
sf::Image *img = new sf::Image;

...you are also allocating memory, pretty much the same way as for how much you care!

After either declaration, there is a sf::Image in your RAM, now you only need to be careful about how you use it!

With the first way, the object is bound to the created sf::Image memory address automaticly, and you may call its methods without further trouble!

Now on what comes to pointers:

A pointer is a variable too! But because a pointer holds as its value an address, its value can be anything in the RAM.
Because the pointer has this capacity to point at different adresses, you can play at will, as long as your data have integrity of course!

Code: [Select]
sf::Image img1,img2; //just two images
sf::Image *pImg = 0; //Points at nothing, the NULL
pImg = &img1; //& meaning address-of, now our pointer knows about img1;
pImg = &img2;//and now, it knows where the img2 is!

img1.LoadFromFile(""); // Calling a method normally
pImg->LoadFromFile("") //Calling a method from a pointer! This would call the LoadFromFile of img2!

(*pImg); //the symbol on the left makes the pointer behave like a normal object, so you could do:
(*pImg).LoadFromFile(""); //and still be calling img2 method!

&pImg; // The address of a pointer even lets you acess the raw bytes!

//You don't need to point at sf::Image created staticly!
pImg = new sf::Image(); //This just throws a sf::Image into memory, and keep its address for future reference!
delete pImg; //This will destroy permanently the sf::Image pImg is pointing to!

Now applying to the resource manager example:

In the vector, you keep a pointer instead of the actual sf::Image because you can later reference to it, instead of copying , which is faster!

and the resources will all be centralized, everything used it there, and thats good for your organization, specially when a lot of resources are used!

Imagine your search function like this:
Code: [Select]

sf::Image* ResourceManager::SearchImage(string SearchFileName){
       for(unsigned int i = 0; i < ImageList.size(); i++){
              if(ImageList[i].first == SearchFileName){ // first is the string , in the pair
                      return ImageList[i].second; //you return the pointer to the sf::Image you are holding

Where you called the function, you just got a fresh pointer:
use it normally as a sf::Image
Code: [Select]

I hope this clarifies it a bit for you!

General / White Window
« on: January 03, 2011, 03:36:31 am »
Quote from: "Terrydil"
Or perhaps your drawing code is actually inside your event handling code, so nothing would get drawn until an event gets handled.

I'd place a bet on that : )

General / [Solved] Resource Manager
« on: January 03, 2011, 03:34:53 am »
Good thinking !

You don't seem to require a very advanced resource manager for that!
And it is definetly good to keep it simple, stupid!

You could just implement a ResourceManager class, which holds in a few containers with the data your game uses.

Because you're game will be running on the PC, and will most likely be lightweight(assuming that :) ), you could load everything you need into memory at once, (really)preferably at inititialization, to avoid desnecessary memory allocations during gameplay.

My tip for the containers:

(example for sf::Image objects)
Code: [Select]
vector< pair<string, sf::Image*> > ImageList;

then you would have a list of images, associated with a name, so you could query it later.

(Inserting a new image)
Code: [Select]
sf::Image img;
ImageList.insert(ImageList.end(), make_pair(FileName, &img));

You could then make a search function, to get a pointer to the image you need, by using its name!

Hope it helps!

Feature requests / Proposal to change identifiers
« on: January 03, 2011, 03:22:44 am »
Or just add the function in the previous post instead of replacing, could be useful : )

About the other changes, i think the API is really understandable as it is, but still, change is always good, means evolution : )

General / [Solved] Resource Manager
« on: January 03, 2011, 03:17:18 am »
Could you elaborate? What do you mean with resource manager?

What are your concrete goals for the RTS? First try to have a better idea of what you want to manage, then find the optimal algorithm to do it : )

Graphics / Draw sprite using vector
« on: December 30, 2010, 01:51:21 pm »
Code: [Select]
void Bullet::move(int x, int y)
    for(unsigned int i = 0; i < bullets.size();  i++){
        bullets[i]->Move(x, y);

That should do, to move ALL the bullets : )

Graphics / Problems with Sprite derived class
« on: December 30, 2010, 04:40:03 am »
Hello, try passing the sf::Image by reference:

SDerived(sf::Image &img) : sf::Sprite(img)

Window / Can GetEvent or sf::Input be called from another thread?
« on: December 30, 2010, 01:15:16 am »

Wouldn't we get a more stable application if the main thread was the graphics thread? (Fetch events and render everything)

Have a renderer drawing all game structures in the main loop and those structures would be updated in some other thread : )

Graphics / Draw sprite using vector
« on: December 29, 2010, 11:37:33 pm »
If the vector is declared as vector<Sprite*>, it will expect Sprite* objects to be added.

If your Bullet class is not inherited from Sprite, it has no relation to Sprite class, therefore, it can't be inserted.

Possible fix:

When declaring Bullet class: class Bullet : public Sprite{..};

Another possible fix:

Instead of declaring the vector as vector<Sprite*>, declare it as vector<Bullet*>

To render everything, you can do something like this:

Code: [Select]
for(unsigned int i = 0; i < bullets.size(); i++){

Note: it will only work if the object "bullets" is a Sprite, or inherits from Sprite.

Hope it helps ;D

SFML projects / Puzzle Game Prototype
« on: December 12, 2010, 02:08:38 pm »
Oh yeah man, i plan to add way more puzzles : )
Do you think it has potential to go commercial with some work on top of it? =)

SFML projects / Puzzle Game Prototype
« on: December 12, 2010, 04:41:19 am »
Hello community, this is my first post! yay!

Thanks Laurent for the great library, it looks great from every way i look at it! Lifesaver! : )

I am writing a "puzzle" game in my free times and it is build on top of SFML, so i guess it deserves to be posted here! :shy:

The game is about moving blocks, horizontal blocks only move horizontally and vertical blocks only move vertically! Use the mouse to play, instructions in-game : )

You can download the game from here:

Enjoy and follow me in my blog (signature) if you find time : )

Pages: 1 ... 38 39 [40]