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

Pages: 1 ... 11 12 [13] 14 15 ... 22
181
The values I get:
big_tex loading time: 395 ms
small_tex[0] loading time: 25 ms
small_tex[1] loading time: 25 ms
small_tex[2] loading time: 25 ms
small_tex[3] loading time: 25 ms
small_tex[4] loading time: 25 ms
small_tex[5] loading time: 25 ms
small_tex[6] loading time: 26 ms
small_tex[7] loading time: 25 ms
small_tex[8] loading time: 25 ms
small_tex[9] loading time: 25 ms
small_tex[10] loading time: 25 ms
small_tex[11] loading time: 25 ms
small_tex[12] loading time: 25 ms
small_tex[13] loading time: 25 ms
small_tex[14] loading time: 25 ms
small_tex[15] loading time: 25 ms

182
General / Re: Error when building my project in visual studio
« on: April 02, 2022, 12:13:06 pm »
While windows itself can run either (Windows 64 bit can run 32 bit apps), within a single program the libraries and executable must all be the same platform. 64 with 64 or 32 with 32.

Glad it worked. :)

183
General / Re: Error when building my project in visual studio
« on: April 02, 2022, 10:53:33 am »
This can be caused by mixing 32 bit and 64 bit libraries (which isn't allowed).
Based on the directory it appears to be building to, it looks like your project is 64 bit (ignore the Win32 bit on each line, my 64bit apps say that too). But did you get the 64 bit version of sfml too?
Or if your project is 32 bit, is sfml also 32 bit?

184
Graphics / Re: sf::RenderTexture not working properly
« on: March 31, 2022, 11:11:36 pm »
Your window is 800x800 pixels, but your render texture is 6x6 pixels (due to the texture.create(L,H); call).

185
General / Re: Linking static SFML with Premake & MingW drives me nuts
« on: March 12, 2022, 11:55:14 pm »
From what I've read here: https://github.com/premake/premake-core/issues/627
the issue is Premake doesn't carry over dependencies for static libraries.
FarfocelEngine is linking with sfml, but since both are static it isn't actually merging them there. When Sandbox is linked with FarfocelEngine, the sfml parts are missing.

This works in Visual Studio because it explicitly fixes this, but MingW is just doing what it's told.

So you'd need to link Sandbox with all of FarfocelEngine's dependencies too.

At least that's how it looks, been a while since I used premake, static sfml or anything other than visual studio.

186
General / Re: How to use correctly the trigger
« on: March 08, 2022, 07:17:49 am »
Joystick axes are in the range -100 to 100. However you might not reach exactly that. For example, my Xbox one controller gets about 99.609 max. So it's safer to test against a threshold (like axisvalue > 90) to make sure it covers most controllers.

Another fun thing to consider: The left trigger is positive, the right trigger is negative. So for the right trigger you'd want axisvalue < -90 and for left trigger you'd have axisvalue > 90.
This was intentional by microsoft. They merged both triggers into one, it's impossible to tell if both triggers are fully pulled in at the same time. But if you use the XInput library (only supports Xbox stuff) then it gives you both triggers separately.

187
General / Re: Memory usage problem
« on: February 25, 2022, 08:42:37 am »
Good point, I'm on VS2022 with self built SFML from the repo, so things might have changed since VS2017.

In one of the older visual studios (maybe 2008 or 2010) the Ogre3D community discovered a memory leak in Microsoft's STL, every stream (string stream, file stream, etc) leaked 4 bytes. They were using temp string streams to format debug info (fps, tri count, etc) every frame for a gui panel, so that added up fast when the engine is running at 1000+fps. :)

188
General / Re: All sprites showing as white boxes.
« on: February 21, 2022, 11:05:52 am »
It depends on how you are using the Bullet objects.
This is just a guess about how you are handling it, but if you are pushing them into a vector, like std::vector<Bullet>, then that's the problem.
Sprites store a pointer to the texture you attach to them. This means the Texture object can't move in memory, the pointer to the texture in the sprite will break.
When an object is added to a vector, it makes a duplicate at a different location, so the texture pointer is not valid in the duplicate (points to the original Bullet, not the one in the vector). Also adding things to a vector will make the vector occasionally resize, which requires moving everything around (breaking the texture pointers again).
Although as I said, that's just a guess. :)

I find the easiest way to deal with Texture objects is to allocate them on the heap (using new) and handle them with pointers. This stops duplication and moving around in memory, so the binding from the sprite won't break.
I'd change the header to have:
sf::Texture *bulletTexture;

and the constructor to have:
bulletTexture = new sf::Texture;
bulletTexture->loadFromFile("Resources/Syringe.png");
bulletSprite.setTexture(*bulletTexture);

Even better would be to load the texture once somewhere (like a resource manager) and reuse it. Unlimited sprites can share a single texture. Right now every Bullet is reloading the png file and storing a copy of it's data.
(on a side note, I'd remove all the this-> bits, they aren't hurting but they also aren't doing anything)

189
General / Re: Memory usage problem
« on: February 19, 2022, 10:32:39 pm »
What OS are you running this on and how are you measuring memory use?

Running it on my system (as a 64bit build on Win 10), Visual Studio's diagnostic tool (debug build) shows it sits on about 55MB.


Task Manager shows similar (around 49MB for release, 51+ for debug)

190
General / Re: Spawning random enemies
« on: February 18, 2022, 05:52:02 am »
Ah, yes, I wasn't looking at that part.
There's two minor things to fix that should get it spawning.
In your entidadmanager::actualizar() function, you make a clock called reloj. But this is remade every time you call the actualizar function, so the elapsed time keeps resetting to 0 before it reaches the 1 second time.
Move the Clock reloj; line into the entidadmanager.h file, in the same spot as the m_v is declared.

Second, this bit is unreliable:
if(reloj.getElapsedTime().asMilliseconds() == 1000)
The problem is == means exact match. The milliseconds is an integer (so no floating point error), but if you are running at 60fps, the elapsed time will jump 16ms each update. So it can jump over 1000, it might never hit exactly on it.
Change the == to >=
Now if it hits 1000 or goes over 1000 (by any amount), it will trigger the spawn.

191
General / Re: Spawning random enemies
« on: February 17, 2022, 06:58:57 am »
A resource manager of some kind would let you do that.
I think there's one in one of the sfml books.
I wrote my own. :)

Basically you ask it for a texture (such as by filename) and it will either load the texture, or reuse one already loaded.

But we can do a simple cheat method:
entidad::entidad() {
        static Texture *tex = 0;
        if(tex==0)
        {
            tex = new Texture();
            tex->loadFromFile("meteorito.png");
        }
        Sprite sp;
        sp.setTexture(*tex);
        m_sprite = sp;
        m_sprite.setScale(0.70f,0.70f);
        m_pos.x = rand () % 800 + 30;;
        m_pos.y = 0;
        m_sprite.setPosition(m_pos.x,m_pos.y);
}
The way this works is the static tex starts at 0 (null pointer). Statics keep their value on every run of the function (so the =0 part only happens once, not every time). Then if checks if tex has been set. If not, it creates a texture, puts it in tex and loads the file.
This way tex will only load the texture if it is the first asteroid. If it's not the first, it will use the texture that was created by the first asteroid.

Hopefully that makes sense, I just finished running a 6 hour class a few mnutes ago and my head isn't feeling good. :)

This is pretty hacky though, a good resource manager that handles this for you would be better, but it's more complicated to write.

192
General / Re: Spawning random enemies
« on: February 16, 2022, 06:54:28 pm »
In this code:
entidad::entidad() {
        Texture tex;
        Sprite sp;
        tex.loadFromFile("meteorito.png");
        sp.setTexture(tex);
        m_sprite = sp;
        m_sprite.setScale(0.70f,0.70f);
        m_pos.x = rand () % 800 + 30;;
        m_pos.y = 0;
        m_sprite.setPosition(m_pos.x,m_pos.y);
}
you make a temporary texture called tex and set the sprite's texture to it.
But sprites need the texture to have the same lifetime, they don't copy the texture, they just keep a pointer to it. So when tex leaves scope at the end of the function, the sprite is now trying to use an invalid texture.

Putting the texture in the asteroid won't work though, because every time you copy the asteroid (like pushing it into m_v) it will break the connection again.
The easiest way to have a texture that doesn't move around in memory and lasts longer than the sprite is to make it as a pointer.
entidad::entidad() {
        Texture *tex;
        Sprite sp;
        tex->loadFromFile("meteorito.png");
        sp.setTexture(*tex);
        m_sprite = sp;
        m_sprite.setScale(0.70f,0.70f);
        m_pos.x = rand () % 800 + 30;;
        m_pos.y = 0;
        m_sprite.setPosition(m_pos.x,m_pos.y);
}
That should work.
Although it has a downside which your version also had: every asteroid loads its own copy of the texture. Many sprites can share a single texture, which is more efficient. It works, it just won't handle massive numbers of sprites as well.

193
General / Re: Trying to sync rocket with rocket launcher
« on: February 04, 2022, 12:08:56 am »
That looks like getRot() is returning angles in degrees.
But cos and sin take angles in radians.
Try making it:
this->rocket->updatePos(sf::Vector2f(this->player->getPos().x + (25 * cos(this->rocket->getRot() * 3.141592654f / 180.f)), this->player->getPos().y + (25 * -sin(this->rocket->getRot() * 3.141592654f / 180.f))));

It also looks like the rocket is rotating in the wrong direction, if so, try removing the - from the sin part, that will reverse rotation.

194
SFML objects like sounds and textures are iffy to copy around, due to their attachments to other objects.

In your code:
Player player;
player = Player(3);
 
There are two Player objects. I'll refer to them as 1 and 2 to simplify it.
We have player, then we have a temporary made by Player(3). The temp is copied over the top of player.

Sounds are attached to SoundBuffers. The SoundBuffer keeps a list of every Sound that is using it (sharing soundbuffers is good for memory, many sounds to one sound buffer, like many sprites to one texture).

The temp Player is created. It's constructor loads an audio file into buf and attaches sound to buf.
Then when the temp Player is copied over player, the temp buf and sound are copied to the blank player's buf and sound.
So here's where things get tricky.
When a SoundBuffer is copied, it doesn't copy attachments.
When a Sound is copied, it attaches to the same buffer as the original was attached to.
At this point player.buf is set up, but the setBuffer's effect wasn't copied over, just the sample data. The player.sound is attached to the temporary buf, not player.buf!

After the copy, the temporary player is destructed. When a SoundBuffer is destructed, it detaches all Sounds. So player.sound is detached from the temporary buffer.
In the end player.buf is there, but has no sounds, and player.sound is there, but isn't attached to anything.

If you add this to your player class:
Player& operator=(const Player& p)
{
    buf = p.buf;
    sound = p.sound;
    sound.setBuffer(buf);
    return *this;
}
 
That should make it reattach the sound and the buffer when you do player = Player(3);

Although a better way would be to have buffers stored in a sound manager so they can be easily reused. Copying sounds around should be safe, but SoundBuffer is a resource that should only exist once for each audio file, so it's a bit trickier to deal with.

195
General / Re: General C++ Header Question
« on: January 31, 2022, 01:50:42 pm »
Ah, yep, there's circular includes in there. For example:
rgl includes application
application includes audio
audio includes rgl
rgl includes application ... and so on.

Here's a simplified example:
// aaa.h
#ifndef AAA_H
#define AAA_H

#include "bbb.h"

class AAA
{
        BBB *b;
};

#endif
 
// bbb.h
#ifndef BBB_H
#define BBB_H

#include "aaa.h"

class BBB
{
        AAA *a;
};

#endif
 
// main.cpp
#include "aaa.h"

int main()
{
   return 0;
}
 

Here's what the preprocessor will do. First, it replaces the #include in main.cpp with the contents of aaa.h:
// main.cpp
#ifndef AAA_H
#define AAA_H

#include "bbb.h"

class AAA
{
        BBB *b;
};

#endif

int main()
{
   return 0;
}

Then it will replace the #include "bbb.h" with the contents of bbb.h:
// main.cpp
#ifndef AAA_H
#define AAA_H

#ifndef BBB_H
#define BBB_H

#include "aaa.h"

class BBB
{
        AAA *a;
};

#endif

class AAA
{
        BBB *b;
};

#endif

int main()
{
   return 0;
}

That added another #include "aaa.h", so it has to replace that too:
// main.cpp
#ifndef AAA_H
#define AAA_H

#ifndef BBB_H
#define BBB_H

#ifndef AAA_H
#define AAA_H

#include "bbb.h"

class AAA
{
        BBB *b;
};

#endif

class BBB
{
        AAA *a;
};

#endif

class AAA
{
        BBB *b;
};

#endif

int main()
{
   return 0;
}

Now this is where it gets stuck. It can't replace the new #include "bbb.h" because that code is disabled by the include guards.
From the top, it checks if AAA_H isn't defined. It isn't, so it defines it.
Then it checks if BBB_H isn't defined. It isn't, so it defines it.
Then it checks if AAA_H isn't defined. But at this point it is (from above), so the entire contents of the third #ifdef block are removed.
// main.cpp
#ifndef AAA_H
#define AAA_H

#ifndef BBB_H
#define BBB_H

#ifndef AAA_H
//#define AAA_H
//
//#include "bbb.h"
//
//class AAA
//{
//      BBB *b;
//};
//
#endif

class BBB
{
        AAA *a;
};

#endif

class AAA
{
        BBB *b;
};

#endif

int main()
{
   return 0;
}

Now that the preprocessor has completed, the compiler works its way down the code. The first thing it sees (that isn't a # command) is class BBB, which contains an AAA. But AAA hasn't been declared yet, so the compiler gives an error and stops.

Generally, the headers shouldn't have dependencies on things that include them. So if rgl.hpp includes application.hpp, then it's risky for anything in application.hpp to rely on rgl.hpp. Same for audio.hpp, it shouldn't rely on application.hpp, and so on.

One fix for some of these things is to predeclare the types. So aaa.h doesn't really need to include bbb.h if instead it added the line:
class BBB;
That's enough to warn the compiler "hey, don't panic at this BBB thing, I'll fill in the details later". But that only works for pointers or references. You can't have a BBB object without all the details already specified. So this is fine:
class BBB;
BBB *b;
but this is invalid:
class BBB;
BBB b;
because it can't make a BBB without knowing the class contents, but pointers don't care.

Mostly it comes down to reorganising the headers to make sure dependencies don't loop back on themselves. It's rather tricky at times, this is one side of C++ I don't like compared to other languages.

Hmm, that got a bit long. My holidays ended today, so my brain has kicked back into teaching mode. :)

Pages: 1 ... 11 12 [13] 14 15 ... 22
anything