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

Pages: [1] 2
1
Feature requests / Re: Option to disable OpenGL error checking
« on: November 14, 2015, 03:29:26 pm »
They are disabled in release builds.
Huh, I thought I tested in a release build... I tried again just now and they're indeed gone. I probably messed something up with my gDEBugger project. Well, thanks for pointing that out!

2
Feature requests / Option to disable OpenGL error checking
« on: November 14, 2015, 12:35:31 am »
Hi,

I've recently used SFML again in a long time, where I used OpenGL directly. While debugging the application with gDEBugger, I noticed that any texture related code (for which I used sf::Texture) was calling glGetError a lot. Since there is the general concept of anything glGet* being evil in OpenGL, I fear that this might impact performance. It'd be nice to be able to toggle these glGetError calls on and off, or maybe even have them enabled only when using a debug context (i.e. sf::ContextSettings::Attribute::Debug).

3
DotNet / Re: Loading textures from a zip archive
« on: January 29, 2015, 05:45:07 pm »
I think you'll find that PhysFs (http://icculus.org/physfs/) does what you want.

Ah, yes it does. Thanks, I'll take a look at that at some point.

I'm going to take a wild guess and say this will fix it http://stackoverflow.com/questions/8741474/returning-a-stream-from-file-openread

With your solution it outputted an error saying that 8-bit images weren't supported. I updated the concerned images and it works now! Thanks for your help.

4
DotNet / Loading textures from a zip archive
« on: January 29, 2015, 03:47:46 pm »
Hi!
Up until now I've been using OpenTK for rendering where I've been storing my textures in zip archives. This worked perfectly fine until I decided to switch to SFML.Net.

This is my code:
var tex = new Texture(loader.GetResourceAsStream(filename));
 
I'm using .NET 4.5's ZipArchive internally. loader is just a small interface I made for it.
With this I'm getting a NotSupportedException: "This stream from ZipArchiveEntry does not support seeking."

So I tried this:
byte[] data = loader.GetResourceAsByteArray(filename); // the array starts with "?PNG", so this is probably not the issue...
var tex = new Texture(new MemoryStream(data));
 
This one throws a LoadingFailedException: "Failed to load texture from memory."

Using zip files makes everything nice and simple so I'd hate to get rid of it. Is there any other way to do this?

Thanks in advance,
- Lignum

5
General / Re: 2D RPG
« on: January 25, 2014, 06:22:05 pm »
I've now set VSync(true) and removed the couts.
Now I have a constant framerate and it works without laggs.

I still have another question:
I want to build my RPG out of many rectangles and I will save them in a 2D Array.
How should I structure the data in the file? And which file format would you recommend me to use?

...

Good to hear that it works! :)

Assuming you're going to have pre-built maps you should have a look at the Tiled map editor. It uses XML as a format.

If you're going to have generated maps though and you want to save them to a file... you would probably still be best off using XML. Although it's not going to be much use to you for just tiles, you're going to love it later on when you're saving enemies, sprites etc.

Another problem is that I want to expand and update the Map sometimes.
So if I save the users last position, how can I place his character on the same position after the map update?

I don't quite understand what you mean. Do you mean that you're going to update the map at runtime? (e.g. secret passageway opens up by removing a tile). Or do you mean you're going to update the map via a map editor?

For both cases you shouldn't need to worry. However do keep in mind that moving objects shouldn't be tiles.
You're going to have some trouble with transparency and many other things otherwise.

The best solution would be to just use tilemaps of maybe 255x255 rectangles and a 4D Array.
The first two dimension would specify the position of the tilemap and the second two the content of the tilemap.

A 4D array? You should only need 2 dimensions. If you wanted to you could even make a 1D array.

Here's an example for a 1D array which uses numbers to represent different types of tiles:

const int map[16] =
{
     2, 2, 2, 2,
     2, 1, 1, 2,
     2, 2, 1, 2,
     2, 2, 2, 2
};

To get a tile you would do this:map[x * mapWidth + y];
An example for this case would be: map[3 * 4 + 2]; (coordinates start at 0)
which would return '2' because the tile at [3, 2] has the ID 2.

Also each rectangle should be filled with a sprite for the surface.
So should I just use an Array of Sprites and use a switch case to load the textures into each rectangle(sprite)?

Kind of. Use an std::vector<sf::Texture>.
Here's an example:
std::vector<sf::Texture> textureMap;
textureMap.push_back(...); // Texture for Tile ID 1
textureMap.push_back(...); // Texture for Tile ID 2
// and so on...

Here's an example for drawing with the above setup:
sf::Sprite tileSprite; // This should preferrably be a class member.

for (unsigned int x = 0; x < mapWidth; ++x)
{
     for (unsigned int y = 0, y < mapHeight; ++y)
     {
           int id = map[x * mapWidth + y]; // Get the ID at [x, y] from the map.
           tileSprite.setTexture(textureMap[id - 1]); // - 1 since id #1 is #0 in the vector.
           window.draw(tileSprite); // Draw it.
     }
}

There also must be a value for each rectangle whether clipping is enables for it or not.
I also need to save the height because I have at least 2 terrain levels.
The ground and objects that shoud be drawn over it, like houses, trees etc.

You could use a seperate array just for the collision map. But that's pretty inefficient, I advise against it.
So instead what you should do is make a vector like above that stores bools rather than textures.
For the layers, you would add another dimension to the array.

I've removed the pointer..
After these changes the programm still need constantly 33% of my CPU?!
And sometimes, instead of making big jumps like before, it still scrolls faster?!

Have you tried a release build? From my experience a debug build with a framelimit of 60fps will take up to 10-40% CPU. While a release build produces a mere 03-10%.

6
General / Re: 2D RPG
« on: January 25, 2014, 05:35:11 pm »
Id didn't programm for a long time and if don't use a pointer it throws errors..
That's very strange. Are you sure you're doing this?:

Game game;

because this won't work:

Game game = new Game;

I know. But if I don't use an absolute path in this case he is "unable to open file".
I don't know why but if I put the project in another folder it works.
But Visual Studio compiles to %Documents%\Visual Studio 2010\Projects\[Project name]
and I want my projects there.
It also works if I manually start the exe file with admin permissions.

You need to put your files in %Documents%\Visual Studio 2010\Projects\[Project name]\[Project name] to use relative paths in Visual Studio (you can also set the working directory in your project settings under Debugging->Working Directory, but this is the default one). While for the standalone .exe the files just need to be in the same place as the .exe.

--

Don't worry about that. Setting a View every frame is not the bottleneck here. In fact, that's how it should be done if the View changes on every loop iteration.

Ah okay, thanks for clearing that up!


7
General / Re: 2D RPG
« on: January 25, 2014, 04:23:05 pm »
Some things that might cause lag is that you're calling setView every frame, I'm not too familiar with views but I don't think you need to do that. After you've done that, try removing all std::couts by commenting them out and see if it still occurs.

As for the CPU usage, you're drawing as many frames as possible in a second. Limiting them should fix it.
Use setVerticalSyncEnabled(true), which limits the FPS to your monitor's max refresh rate (usually 60fps) or use setFramerateLimit(framerate). I suggest using 30 fps for regular games and 60 fps for fast-paced games.

Also some things I've noticed about your code are:
  • Why is your instance of Game a pointer? Just create it on the stack, it'll delete itself and it's much safer.
  • Don't use absolute paths for filenames unless you want the game for yourself only. Use a relative path.

8
General / Re: What are scenes as described by this article?
« on: January 25, 2014, 12:40:07 pm »
A scene is well... a scene. A game's main menu is a scene, the settings screen, even the gameplay itself is a scene.

It contains the objects shown on it and handles basic events like rendering and updating.

This allows for code like this to be written:
if (playGameClicked)
{
     changeScene(new GameScene); // In real code the passed parameter should be
                                       // wrapped into a smart pointer by the changeScene method.
}

SFML does not handle scenes, so you're going to have to implement them yourself.

9
General / Re: LNK1181: VS12
« on: January 24, 2014, 06:10:15 pm »
In "Additional Library Directories" you need to refer to the "Debug" and "Release" folders accordingly, since MSVC is looking for the .lib files in the folder you specified but in your case it only finds the folders "Debug" and "Release" rather than the SFML libraries.

I.e.: In your debug configuration you should refer to:
        D:\Programming\SFML\SFML-2.1\lib\Debug

        and in release:
        D:\Programming\SFML\SFML-2.1\lib\Release

10
Window / Re: Resizing the Window
« on: January 24, 2014, 12:22:14 am »
Looking at the documentation, setSize(sf::Vector2u size) is probably what you're looking for.

EDIT: Seeing zsbzsb's post, you're most likely better off with setView.

11
General / Re: Help with Tile Map tutorial
« on: January 23, 2014, 11:21:11 pm »
Make the 3rd parameter of the load function a std::vector<int> instead of a const int*. Then use my code to load the map from a .txt file. You need to modify it a little bit to return a std::vector<int> rather than a std::vector< std::vector<int> > but other than that, that's it.

12
General / Re: Help with Tile Map tutorial
« on: January 23, 2014, 10:51:33 pm »
The Vector equivalent of your array would be this:
std::vector< std::vector<int> > level;
(Space on the right is mandatory because the compiler likes to confuse it with the right shift bitwise operator: ">>")

You then would use the fstream header to read a .txt file and load it into the vector.

This is pseudocode for loading the map from the .txt file (written in browser, haven't tested):
std::vector< std::vector<int> > LoadLevel(const std::string& filename)
{
      std::vector< std::vector<int> > level;
      std::ifstream in(filename); // Open an input stream for the file 'filename'.

      if (!in || in.fail())
      {
           std::cerr << "Couldn't load level " << filename << "!\n";
      } else
      {
           std::string height;
           getline(in, height);

           int mapHeight = atoi(height.c_str());
     
           for (int y = 0; y < mapHeight; ++y)
           {
               std::vector<int> row;
               std::string line;
               getline(in, line); // Get the next line in the stream.

               // Iterate over every character in the read line and put its numeric
               // value in our row.
               for (int x = 0; x < line.length(); ++x)
               {
                  row.push_back(atoi(line[x].c_str())); // Unless you know nobody's going to fool around,
                                                                 // you should check whether the character is actually
                                                                 // a number you should do some error checking.
               }

               level.push_back(row); // Put the parsed row into our level.
          }

          in.close(); // Free resources. This is important! We don't want any memory leaks.
      }

      return level;
}

Usage:
std::vector< std::vector<int> > level = LoadLevel("level.txt");
if (level.is_empty())
{
    // Level didn't load.
}

// Getting a tile at the coordinates (3, 2).
// Note that the coordinates are swapped.
int tileAt3_2 = level[2][3];

Example .txt file (6x6 level):
6    <-- This is the level's height.
333333
303003
303003
333003
300003
333333

13
General / Re: [Solved] Resource Manager Stack Corruption
« on: January 22, 2014, 01:02:00 pm »
Ah, that makes sense.
It doesn't really make sense. I'd still say you're linked something wrong. ;)

Also you should really abandon the use of manual memory management (new/delete). With modern C++ where we have RAII and smart pointers the new/delete pairs shouldn't be used anymore. Here's just an example why.

And I really don't advise to down grade to VS 2012, since VS 2013 comes with a lot of nice C++11 features and has a few bug fixes that might hunt you a long time when using VS 2012, since it's not fixed there. ;)

Well perhaps I did link something wrong, but maybe it has something to do with the fact that I built it myself? Since for VS 2012 I used the pre-built binaries and that works.

I normally use smart pointers when it's too much of a pain to use new/delete because I care too much about performance/memory when I really shouldn't. But thanks for your advice, I'll consider (or rather force myself) to use smart pointers from now on.

14
General / Re: [Solved] Resource Manager Stack Corruption
« on: January 21, 2014, 09:48:30 pm »
VS2012
Ah, that makes sense. Well I'm glad it works now. Thanks for the help.

15
General / Re: Resource Manager Stack Corruption
« on: January 21, 2014, 09:39:58 pm »
I do believe that this is a problem on SFML's side, because this code reproduces the error:
sf::Font* font = new sf::Font;
font->loadFromFile("Fonts/arial.ttf");
delete font;

EDIT: http://en.sfml-dev.org/forums/index.php?topic=10191.5 this guy is in the exact same situation.

I'm unable to reproduce this behaviour. It's hard to imagine how this could cause a problem if you're linking to the correct runtime libraries in all of your application's modules. Perhaps you could upload the project files of a minimal repro for someone to take a look at. I don't know about everyone else, by my crystal ball is currently in for cleaning ;P

Which compiler are you using? I literally downgraded to VS2012 as you posted this, and everything's working fine. I was using a self-built version of SFML for VS2013 before.

Pages: [1] 2
anything