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

Pages: [1] 2
1
General / Re: Simple hex arithmetic not yielding expected results.
« on: December 17, 2016, 05:37:06 pm »
Thank you and sorry.

2
General / Simple hex arithmetic not yielding expected results.
« on: December 17, 2016, 08:59:15 am »
I am trying to understand the "contiguous" nature of vectors and where they assign their values in memory.
Can someone please explain why the 2nd cout yields a 1 instead of a 4?

std::vector<int> test = { 2,13,4 };
std::cout << &test[2] << " " << &test[1] << std::endl;
std::cout << &test[2] - &test[1] << std::endl;

An int on my machine is 4 bytes large.
So that means test[2] is 4 bytes away from test[1] in memory.

if I write:
std::cout << (int)&test[2] << " " << (int)&test[1] << std::endl;
std::cout << (int)&test[2] - (int)&test[1] << std::endl;

Then I get 4...
Can someone explain why the first example yields 1?

Thank you.

3
General / *SOLVED* STL inludes error after SFGUI include?
« on: September 09, 2016, 05:16:41 pm »
I'm using VS2015 and I wanted to start playing around with SFGUI. So I added its include files to my SFML Project.
After adding the include folder and lib folder to the VC++ directories I get errors in my code.
Like "cannot open source file "vector"" and also an error with sf::RenderWindow not having matching params.

So i removed SGUI from the VC++ directories and I still can't compile.
Has anyone encountered this issue before?

EDIT: I found the problem, i had to check the "Inherent from parent or project defaults" check box.

4
General / Re: Textures going out of scope?
« on: September 05, 2016, 07:43:51 pm »
Passing the unique_ptr to a function was where I was getting errors. something about a deleted function.

I didn't know you had to use std::move.

Very good, thank you!

5
General / Re: Textures going out of scope?
« on: September 05, 2016, 05:20:18 am »
Solved the problem, thank you for your help! I would still like to know more about a memory management system, it would be a good way for me to push my knowledge.

Here's the revised version:
MapGrid.h
class MapGrid
{
public:
        MapGrid();

        void createTile();
        void adjustTilePosition();
        void populateGrid(MapTile* mapTile);
       
        int tileCount;

        float x_offset;
        float y_offset;

        std::vector<MapTile*> mapTiles;
}

MapGrid.cpp
MapGrid::MapGrid()
{
        x_offset = 0.0f;
        y_offset = 0.0f;
        tileCount = 0;
}

void MapGrid::createTile()
{
        MapTile* newMapTile = new MapTile(x_offset, y_offset);
        tileCount++;
        adjustTilePosition();
        populateGrid(newMapTile);
}

void MapGrid::adjustTilePosition()
{
        if (tileCount % 10 == 0)
        {
                x_offset = 0;
                y_offset += 50;
        }
        else
        {
                x_offset += 50;
        }
}

void MapGrid::populateGrid(MapTile* mapTile)
{
        mapTiles.push_back(mapTile);
}

I know raw pointers are frowned upon, so I'll use a unique_ptr.
Thanks again.

Edit: unique_ptr was giving me some problems, so I switched to shared_ptr.

6
General / Re: Textures going out of scope?
« on: September 05, 2016, 12:23:34 am »
So I learned something new while writing some test code and googling a few things.
From what I read, you can't have a vector of references, but you can have a vector of pointers.

So i'll just create the MapTile Object and push_back it's address onto the vector.
I'm at work now, so I can't test it, but I can only hope that it will work.

Here's the test code:
int main()
{
   std::vector<int*> vect;
   int x = 1;
   
   vect.push_back(&x);
   
   std::cout << vect[0] << std::endl;
   std::cout << &x << std::endl;
   
   return 0;
}

Also, would a map container's insert be different than a vector's push_back?
I suppose not because you can use an iterator on it...
Thanks!

7
General / Re: Textures going out of scope?
« on: September 04, 2016, 08:19:53 pm »
Here's some code.

MapGrid.h
class MapGrid
{
public:
        MapGrid();

        void createTile();
        void adjustTilePosition();
        void populateGrid(MapTile &mapTile);
       
        int tileCount;

        float x_offset;
        float y_offset;

        std::vector<MapTile> mapTiles;
};

MapGrid.cpp
MapGrid::MapGrid()
{
        x_offset = 0.0f;
        y_offset = 0.0f;
        tileCount = 0;
}

void MapGrid::createTile()
{
        MapTile newMapTile(x_offset, y_offset);
        tileCount++;
        adjustTilePosition();
        populateGrid(newMapTile);
}

void MapGrid::adjustTilePosition()
{
        if (tileCount % 10 == 0)
        {
                x_offset = 0;
                y_offset += 50;
        }
        else
        {
                x_offset += 50;
        }
}

void MapGrid::populateGrid(MapTile &mapTile)
{
        mapTiles.push_back(mapTile);
}
 

MapTile.h
class MapTile
{
public:
        MapTile() = default;
        MapTile(float x, float y);

        int id;
        float x;
        float y;

        sf::FloatRect rectangle;
        sf::Texture texture;
        sf::Sprite sprite;
 

MapTile.cpp
MapTile::MapTile(float _x, float _y)
{
        texture.loadFromFile("Zelda Sprites/Blank.png");
        sprite.setTexture(texture);
        sprite.setPosition(_x, _y);
}
 

Perhaps it's going out of scope when createTile() ends?

8
General / Textures going out of scope?
« on: September 04, 2016, 03:35:57 am »
So I have 2 classes. One is called MapGrid and the other is called MapTile. My MapGrid class' job is to create and store MapTiles in a vector that is part of the MapGrid class. MapGrid class also control the Position of the MapTile sprite. In the MapTile class I have an sf::sprite and an sf::texture. Everytime MapGrid constructs a MapTile, it assigns a .png file to a texture and then that texture is assigned to a sprite and is pushed back onto the vector in MapGrid.

I then try to render the MapGrid with code that looks something like this. (going off memory)
for(auto iter : mapGrid.mapTiles)
window.draw(iter.sprite);

Can someone tell me if this is a scope issue and the texture reference is being destroyed before it can be rendered? Is there any way to work around this other than not storing each sf::texture in the MapTile object?

Thanks!

9
General / To inherit or not?
« on: August 25, 2016, 05:20:12 am »
So I'm not sure if my MapTile and BrushTile classes should inherit from the sf::Sprite class.
From what I've read it depends on the relationship. With a HAS_A relationship you would simply add the sprite as member. But if it's a IS_A relationship, you would tell your class to inherit from the other.

I hope I'm making sense, could some one please clarify the rules.

10
Feature requests / Re: OutputFileSteam
« on: August 24, 2016, 12:21:02 am »
Propably offtop (a bit), sorry.  :-[

Do not write monoplatform code if you don't have to do so.
"C:/binary.txt"
 
This will work only on Windows, use relative paths or typedefs to specify root directory.

std::ios::binary
 
Linux (and propably any Unix-like system) doesn't really support binary mode. Of course code will work, but files will contain normal, readable data.

Although writing code that would be compatible for other OS' is a little too advanced for me right now, I'll keep that in mind and learn it in the future.

Here's a pastebin of my saving and loading code:
http://pastebin.com/gedzPuJS

Thanks for all the help and suggestions everyone!

11
Feature requests / Re: OutputFileSteam
« on: August 22, 2016, 01:16:07 am »
Well thanks to your help, I figured it out. Thank you so much. I have something to work with now.
Here is what I came up with.

#include <fstream>
#include <iostream>


int main()
{
        int testVariable = 72;
        int testVariable2 = 0;

        std::cout << testVariable << std::endl;

        std::ofstream outputFile;
        outputFile.open("C:/binary.txt", std::ios::out | std::ios::binary);
        outputFile << testVariable;
        outputFile.close();

        std::ifstream inputFile;
        inputFile.open("C:/binary.txt", std::ios::in | std::ios::binary);
        inputFile >> testVariable2;
        inputFile.close();

        std::cout << testVariable2 << std::endl;
       
        system("pause");
    return 0;
}

12
Feature requests / Re: OutputFileSteam
« on: August 21, 2016, 04:00:21 pm »
Oh great! I can use the insertion/extractor operators. This is way more help than what I got on stackoverflow when that wasn't the reason for my post.

Thank you!
<3 this community.

13
Feature requests / OutputFileSteam
« on: August 21, 2016, 07:11:20 am »
I'm currently reading about <fstream> and how to use it. I'm finding it difficult to write an output file in binary using the fstream::write() function. This is due to the fact that it only accepts a char* type instead of void* as it's first param. I know that SFML has an InputFileStream class, but I would like to see a OutputFileStream class as well.

14
SFML projects / Re: My first SFML Program
« on: August 15, 2016, 12:44:25 am »
Thanks I'll review my book and re-read those portions.

15
SFML projects / Re: My first SFML Program
« on: August 14, 2016, 09:17:16 pm »
I read about this loop type in C++ primer 5th edition(C++11).
Is it called a for each loop?

Pages: [1] 2
anything