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 ... 12 13 [14] 15 16 ... 21
196
How are you handling passing input to Imgui?
In the ImGui SFML addon I use, I need to do:
ImGui::SFML::ProcessEvent(event);
in the SFML event loop.

197
I haven't tried running the code yet, but my off-the-top-of-my-head reaction would be:
The two lag timers are running at the same time. When the left arrow is pressed and the state switches to blowing, the blowing time lag is already at some point during the cycle, so the first frame will have a random length. Same for when leaving the blowing state, the other lag timer is already in progress.
Perhaps try these changes:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ blow = true; blowTimeLag = sf::Time::Zero; break; }
and
else if (blow and blowMotionCounter == 2){ blowMotionCounter = 0; blow = false; timeLag1 = sf::Time::Zero; sp.setTexture(p13); }

198
Graphics / Re: Can't release 64x builds.
« on: January 23, 2022, 11:18:40 am »
32 bit and 64 bit components (programs, libraries) are incompatible, they use different calling conventions. A 32 bit program requires all parts to be 32 bit. Same for 64 bit, all parts must be 64 bit.
If you want to support both, you need both versions of SFML and choose which to use based on the current platform in Visual Studio.

64 bit Windows can run 32 bit and 64 bit programs, but it runs 32 bit using a compatibility layer called WOW64 (Windows 32 On Windows 64). https://en.wikipedia.org/wiki/WoW64

199
General / Re: C++ Version / Power Usage Very High
« on: January 22, 2022, 04:32:17 pm »
For part 1, it really depends on if you need the newer features or something you are adding to your project needs them.
I mainly stayed on much older C++, but I've now jumped to C++17 due to the "if constexpr" command (lets me do compile time logic in my vector maths classes) and because the awesome Entt library needs C++17.

Part 2
I'm also setting it to 60Hz using the window's setFramerateLimit function. A simple app with ImGui rendering a giant texture (plus other engine stuff) gives me:

I'm running on a Threadripper and RTX2080TI though.
I don't have sound playing, that may be affecting things.

The slight disk usage you have will be due to the sf::Music. Unlike Sound, Music streams in from disk as it plays, rather than loading it all in advance. Better for memory, but needs to keep loading.

52% CPU does seem really high for what you are doing though.

200
Graphics / Re: Can't release 64x builds.
« on: January 22, 2022, 03:57:14 pm »
Compiling to 64 bit has a very big advantage: access to more memory.

On Windows, a standard 32bit program can only access 2GB of ram. If you enable the Large Address Aware flag (either when compiling, or manually setting it on the executable later) then you get around 3.5GB of ram of the potential 4GB address space.
But a 64bit program gets potential access to all free system ram.

64 bit programs can also potentially run faster, due to having more registers available and only a single calling convention using registers.

If Visual Studio is saying an include can't be found, that means the include search path isn't correct. Changing the Additional Include Directories setting for 64 bit platforms to the same as on 32 bit platforms should be enough to fix it.

But if you don't need the memory, 32bit would be wider supported (very slightly on Steam, where 99.73% of users are 64 bit according to the last hardware survey, but probably more elsewhere).

201
In your setup code, tell the main window to turn off key repeat.
window.setKeyRepeatEnabled(false);

Windows has a keyboard repeat delay and repeat rate, you can set them in the keyboard preferences. When a key is pressed, windows sends WM_KEYDOWN. If it is still down after the repeat delay, windows starts sending WM_KEYDOWN with the KF_REPEAT flag at the rate in the preferences. When finally released, WM_KEYUP is sent.
So by default SFML uses the way windows is sending it (held key makes lots of down events, only 1 up event), unless you turn that off with setKeyRepeatEnabled.

(I don't know if other operating systems do it that way too, I'm just a windows coder)

202
Graphics / Re: Can't release 64x builds.
« on: January 22, 2022, 03:10:37 am »
32 and 64 bit build types have separate settings.
In the project properties panel, you can use the Platform list at the top to choose which one you are looking at. Make sure the 64 bit version has the same settings (like include directory) as the 32 bit one.

203
Audio / Re: Problem With Vector / Audio Operations
« on: January 20, 2022, 02:40:15 pm »
The erase function requires an iterator to tell it which one to erase. In your code:
m_SoundV.erase(m_SoundV[i]);
m_BufferV.erase(m_BufferV[i]);
the value you are passing to erase is the actual sound or soundbuffer object, not an iterator to it.

An iterator is like a pointer, it's an object made to move through containers. STD likes them a lot.
Given an index number i, you can turn it into an iterator by adding it to another iterator, like begin(), which is the iterator of the first thing in the deque:
m_SoundV.erase(m_SoundV.begin()+i);
m_BufferV.erase(m_BufferV.begin()+i);

I find iterators to be annoying, but there are some containers (maps, lists) that can't be used with an index number lookup the iterator has extra logic for them to step 1 at a time.

Something that can go wrong with erasing is values move down to fill the gap. If you erase at position 5, whatever was at position 6 will now be position 5 and so on. Your code is ok, since it returns immediately after the erasing, it doesn't keep stepping through the deque. But it does mean you can only stop one sound each time. If several stopped, it takes one pass for each. The way around that is to make it take a step back if it erases. So if you erase at position 5, you need to check 5 again since a new item is there now. A bit like this:
  for(int i=0;i<m_soundV.size();++i)
{
    if (m_SoundV[i].getStatus() == sf::Sound::Stopped) {
        m_SoundV.erase(m_SoundV.begin()+i);
        m_BufferV.erase(m_BufferV.begin()+i);
        --i;
    }
}
This way the --i takes a step back, to counteract the ++i step forwards in the loop, so if anything is erased, you won't skip the next one, they all get checked.

The parts about templates you've written look like you meant typedefs. There's no need to make any templates for an std::deque, it already is one.

A typedef lets you give an alternative name to a type, usually to make it easier to use.
typedef sf::Sound S;
std::deque<S> m_SoundV;
In that code, S is another name for sf::Sound. Or you could shorten it even further:
typedef std::deque<sf::Sound> S;
S m_soundV;
Now S is the entire deque type.
But none of these are actually needed, they just reduce your typing if you use std::deque<sf::Sound> a lot.
I think that's what you meant there.


Anyway, one little SFML optimisation tip. SoundBuffers are large, they could take megabytes each (they are raw uncompressed audio, like a WAV file). Sounds are tiny. You can have many Sounds all sharing a single SoundBuffer. If 100 gunshots are playing at once, you can have 100 Sounds and 1 SoundBuffer. So usually you don't remove a SoundBuffer, you keep it around, since making a new one uses a lot of memory and slows down to read the file from disk again.
The same with sprites and textures, you can have hundreds of Sprites all using 1 Texture.

204
SFML projects / Re: Simple SFML/Box2D example
« on: January 20, 2022, 02:39:18 am »
Nice.
My students made a Breakout game with SFML and Box2D as their first assignment in one of my subjects. :)
(Well, they did, until the subject was sadly discontinued half way through last year)

205
Audio / Re: Problem With Vector / Audio Operations
« on: January 18, 2022, 01:21:23 pm »
You also need to be a little careful with sounds and sound buffers, due to the way they are linked to each other internally (sounds know which buffer they are using, buffers know every sound using them).
For example, if you had this code:
        std::vector<sf::SoundBuffer> sbv;
        std::vector<sf::Sound> sv;

        {
                sf::SoundBuffer sb;
                sb.loadFromFile("data/NFF-soft-confirm.wav");
                sf::Sound s(sb);

                sbv.push_back(sb);
                sv.push_back(s);
                sv.back().play();
        }
 
This will start trying to play the sound, then immediately stop (usually too fast to tell, if you aren't debug stepping through the code).
The reason is there are 2 sounds and 2 buffers alive at once, the local ones (s and sb) and the copies in the vectors. When a sound is pushed into a vector, it is duplicated. The duplicate connects itself to the buffer sb, since that's what sound s is connected to.
When buffer sb goes out of scope at the end of the braces, it's destructor tells every sound using that buffer to remove their buffer connection. Both sounds (s and the one in the vector) lose their buffer.

So the connection (and any play operations) needs to happen after pushing the sound and sound buffer, otherwise it will be lost.
And as eXpl0it3r says, vectors themselves can shuffle around (as they fill up, they will move everything to larger blocks of memory) which will break the connection, so something like a deque will help.

Using any complex class (like sounds, sprites, textures, etc) as a value in an std::vector or other container is always something to be careful of, since the duplication while inserting/pushing might mess things up on cleanup. If I'm not familiar with the internals of a class, I'd always heap allocate it and push the address instead.

206
One big benefit to the event style is for order dependent processing of keys, such as typing a name. You don't want to have to manually do an isKeyPressed for every possible key, instead the event will tell you which key was pressed so you can add it to a string.

Although the direct style is what I prefer for game related controls, since for those you need to track the state of a key. An event is fine to start a player jump, but to run to the right when you hold a key, that needs to track the presses and releases to know the current state if you used events.

I use my own wrapper on top of sfml's events that lets me query if a key (or mouse button or xbox controller button) was pressed since last update, released since last update or current held down.

207
Window / Re: nothing is moving on screen
« on: January 17, 2022, 08:46:59 pm »
Your game::isClosing() contains a while loop that won't let game::isClosing() return until the window is closed. If the window is open, the outer while loop will be an infinite loop and the rest of the game will never get to run.

208
Window / Re: Mouse cursor reverting to default when leaving the window
« on: January 16, 2022, 03:24:33 am »
I haven't played around with custom cursors myself, but looking at the sfml source the sf::Cursor class destroys the allocated system specific cursor when it goes out of scope.
To me, the code looks like sf::Cursor should exist for the lifetime of the program, not be a temporary in PrepareMouseCursor(). So perhaps it's holding a residual image while in the window, when it leaves the window then returns the cursor you set no longer exists.

Try moving the sf::Cursor out of the function and maybe put it where the renderWindow is, so it has a similar lifetime.

(Technically: Win32 DestroyCursor() is called when sf::Cursor destructs)

209
Audio / Re: Audio is recording, but not playing, im no idea why this is.
« on: January 13, 2022, 09:34:43 pm »
Looks like your while loop is a busy loop that won't finish until the sound source has completed. This means all rendering has stopped, the colour change a few lines above did happen but it's never getting a chance to appear on screen.
Once the while loop ends, rendering resumes but the button has now returned to it's not playing colour.

210
I haven't read that book, but I'm guessing how they've probably structured it.
The scene node class must have a draw method, so the myRenderWindow.draw(mySceneNode); works.
If you make new kinds of scene nodes (like a sprite node), they need their own draw method that overrides (replaces) the scene node draw method.

So in your sprite node class you'd need something like:
void SpriteNode::draw(RenderTarget& target, RenderStates states) const
{
   target.draw(m_sprite);
}
So when you tell the sprite node to draw, it in turn tells the sprite member to draw.

Is that function there? Make sure it's name and parameters are identical to the one in scene node (if you called it Draw instead of draw it will call the wrong one).

Pages: 1 ... 12 13 [14] 15 16 ... 21