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 - Kain Nobel

Pages: 1 [2] 3
16
General / 99 Problems / (Not So) Fresh Start
« on: February 20, 2023, 10:36:07 am »
I'm doing a brand new SFML deployment for an existing project.

Everything SFML has been wiped clean. My existing project still has all the relevant includes and other configurations but I can't seem to compile anything useful.

Not sure where I've gone wrong but here are my steps...

  • I've downloaded the SFML-2.5.1-windows-gcc-5.1.0-tdm-32-bit eternal damnation package.
  • I've unzipped it to "C:/SFML/2.5.1/"
  • I've installed some whiz-bang TDM-GCC-32 compiler gadget.
  • I'm using an already existing install of Code::Blocks
  • Library had a problem finding the "al.h" header.
  • I've downloaded OpenAL, which one-click installed to "System32" directory.
  • Added "C:/Windows/System32/openal32.dll" to project (above all other libraries.)
  • I've copied the "GNU GCC" entry and pasted new entry for "TDM-GCC-32".
  • I've edited the "TDM-GCC-32" entry to point to directory "C:/TDM-GCC-32".

(click to show/hide)

I can't seem to find TDM-GCC 5.1.0 so I'm using TDM-GCC 10.3.0. Can I use the latest and greatest or do I have to hunt for the ancient TDM? I'm not really sure where to go from here.

Edit : I did find the link for TDM-GCC 5.1.0 but the last question still stands. Should I compile from source with 10.3.0 or should I just use 5.1.0?

17
General / Re: Fresh Build - Problems Galore
« on: February 04, 2022, 09:37:59 am »
Hahaha! That was a quick 2 second fix, thank you! SOLVED :)

I'm a little slow on the uptake (it's a lot of information to absorb at once.) I think the problem started when CLion was needing me to do something with CMake. I'm going to continue with this CLion trial but it is now compiling and linking to MY project which was the most important thing to me :D

Now I can get back to the Keyboard extension I was writing. This is pretty cool. If I finish it and it works I'll let you check it out, you'd be more than welcome to include it in the official SFML because it's pretty standard. :)

Off to test out the new Keyboard then I'll be giving the same treatment to Mouse and Joystick! :D

Slightly Off Topic : Untested Brand New Keyboard Preview!

Preview of the code is below if you want to give it a try. (I haven't even tested it yet, outside of when I was writing it @ onlinegdb.com. If anybody tests or modifies it, PM me with the new version. The only thing I haven't added was a 'isDoubleTap()' function and it'll probably be converted to a sf::Vector3 to replace m_SYNC, m_States and maybe m_DblTime to check for each and every key double tap. (Onlinegdb doesn't have sf::Vector3 obviously but it sounds like a good class to use for this. Maybe.))

Keyboard.hpp
(click to show/hide)

(click to show/hide)

Other than that, this topic is SOLVED, thank you for all your help!

18
General / Re: Fresh Build - Can't Find OpenAL Files
« on: February 04, 2022, 07:41:25 am »
After a long day's work, I'm back.

So I tried to do some things before I came here looking for more help. I tried another fresh build, this time using...

[GCC] 7.3.0 MinGW (DW2) - 32-bit

MinGW Builds 7.3.0 (32-bit)

The tutorial I followed EXACT (again).

Anyways, I get...



...I notice the 7.3.0 MinGW version of SFML 2.5.1 has no /src folder. OK. So I download fresh from Github (only the /src folder because I don't need more than that.) No prob. Right?

...Is there a reason there are .hpp files in /src? Some of the headers I need are from /src and this is from a fresh, brand new download. If the system isn't able to find these .hpp files then I'm taking the executive decision to move them to /include.

(click to show/hide)

...So now I'm moving those .hpp from /src to /include. I've moved ALL these files, it was a lot. I'm not sure if they're supposed to be in /src but my GUT tells me /include is the place to be.

So now I build again...



The Island example game wouldn't compile, so I downloaded stb_perlin.h and put it where it needs to be.

Now I'm back to...



Oh.

Is this something that is needed? I'm not familiar enough with the guts of SFML to know. I can only assume this is related to CSFML bindings, especially since that file extension is an .h and not a .hpp. For now I'm trying to build in purely C++, so I don't care for the CSFML portion (yet). Do I need to write something here to skip the check for these .h files? Are they needed for C++ SFML too? What would the preprocessor commands look like to skip this (if that's what I need to do)?

So, this^ comes full circle to the last time I tried to deploy and build fresh. Now that I've been through this process 3 times (yuck!), perhaps the tutorials ARE accurate but some things have changed in the library? I don't know...

EDIT: I've commented out the #include 'al.h' and #include 'alc.h' but that doesn't fix anything either.



So now I'm copying the extlibs into the SFML root directory.



^This pops up a whole bunch of times (in Code::Blocks).

It builds fresh regardless but I get (again)...



So... here are my settings.


EDIT: Updated picture due to bad cropping :X

Do I need to add extlibs too?

The only thing I haven't done (for which I've done last time) is build fresh with CMake. I'm not against building fresh with CMake but I want to make sure all my bases are covered before I touch it because I don't want it dumping on me a garbage truck full of files I don't need and can't use again. If I'm not using CSFML, then I probably don't need the extlibs right? (I might in the future but that's beyond the scope of this topic...) Is extlibs required to run OpenAL, OpenGL, etc or is that strictly for CSFML bindings?

I forget why I had to wipe SFML and start over, I just know one day I started getting a bunch of linker errors and... stuff. Which is strange because I wasn't messing with CMake, the Build options or anything, I was actually working on a Keyboard extension :( I'd like to see if that Keyboard extension works but I can't if the damn thing won't build! It WAS all building fine and it should've kept building fine because I hadn't changed any of the crucial pieces that make it work, nor have I touched the SFML source. :o

EDIT: So now I'm building with CMake. I've chose "Use default native compilers" and it gives...



OK. So I delete the files in /BUILD and I'm grabbing the CMakeLists.txt from Github.

Code: [Select]
The C compiler identification is GNU 5.1.0
The CXX compiler identification is GNU 5.1.0
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.22/Modules/CMakeRCInformation.cmake:27 (include):
  include could not find requested file:

    C:/SFML/2.5.1/cmake/CompilerOptionsOverride.cmake
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.22/Modules/Platform/Windows-GNU.cmake:130 (enable_language)
  C:/Program Files (x86)/CMake/share/cmake-3.22/Modules/Platform/Windows-GNU-C.cmake:2 (__windows_compiler_gnu)
  C:/Program Files (x86)/CMake/share/cmake-3.22/Modules/CMakeCInformation.cmake:48 (include)
  CMakeLists.txt:38 (project)


Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/TDM-GCC-32/bin/gcc.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/TDM-GCC-32/bin/g++.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:43 (include):
  include could not find requested file:

    C:/SFML/2.5.1/cmake/Config.cmake


CMake Error at CMakeLists.txt:79 (sfml_set_option):
  sfml_set_option Macro invoked with incorrect arguments for macro named:
  sfml_set_option


CMake Error at src/SFML/CMakeLists.txt:3 (include):
  include could not find requested file:

    C:/SFML/2.5.1/cmake/Macros.cmake


CMake Error at src/SFML/System/CMakeLists.txt:64 (sfml_add_library):
  Unknown CMake command "sfml_add_library".


Configuring incomplete, errors occurred!
See also "C:/SFML/2.5.1/BUILD/CMakeFiles/CMakeOutput.log".

And now I'm going to Github to chase all this down^... (topic pending update...) Actually, I'm not going any farther than that. Is there a better way to do this???? I'm pretty livid at this point. Do I need to download the entire source tree and not bother with the stuff >>here, in the Downloads section<<? :|

I started at 5PM. It's 11PM now. I've carefully documented EVERY step.

19
General / Fresh Build - Problems Galore [Hahaha SOLVED XD]
« on: February 02, 2022, 06:01:06 pm »
Hello and good day!

I was having CMake file problems so I decided to clear all my CMake files, then I decided to just clear the whole library and start over because another 8 hour night of heroic measures trying to build is uncalled for. (I'm experimenting with 3 different IDEs in the same project - it got ugly.)

I know, I know, I just set up a couple weeks ago, I'm setting up again already @_@

So...

The project can't find "AlCheck.hpp" and "AudioDevice.hpp" (and probably other libraries.)

I followed the SFML and Code::Blocks (MinGW). I followed Compiling SFML with CMake.

I've went to Build Options... > Search Directories > Compiler > and added "C:\SFML\2.5.1\extlibs\headers"
I've went to Build Options... > Search Directories > Linker > and added "C:\SFML\2.5.1\extlibs\headers"

Neither of these seem to be doing it.

I tried doing a lot of digging before I came here looking for help, I did pass by a mention of these problems on Apple (but the contributors were talking about Apple comes with OpenAL embedded so...) I'm not on Apple, or building from Apple, but I do wonder if the problem is semi-related? Hm. I'm trying to build on Windows.

Now I have to get to work, I'll try to get back to figuring this out in a day or so. Thank you to anybody who can help with some information on what I need to do, I'm not ready to quit yet :)

20
Wow that's pretty cool! Very sleek and professional :D

How long did it take you to develop Sequence Storm? I'm gonna have to go check that out :D

21
General / Re: General C++ Header Question [SOLVED] + Demo/Quiz
« on: February 01, 2022, 01:06:30 pm »
My problem is SOLVED, thank you for your help :) I suppose hindsight is 20/20, I was doing all kinds of funky things to try and get this to work - I didn't think that was the issue, haha!

Before I went on writing any kind of reply, I had to set up a mock "project" on onlinegdb.com. It's an extremely simplified and portable example of the problem I was having. I didn't want to throw this away, I figured it would be a useful demo of #include gone wrong. I'll save the raw code below for future explorers and code archeologists. By default, this works until you uncomment the lines pointed out within the code.

Problem (Demo)
https://onlinegdb.com/XZITnMQq6
Problem (Raw Code)
(click to show/hide)

Bonus points to anybody who figures out how to return the output below without having the problem of a circular #include issue. This isn't really something I'm going to force (I don't even think I need it nor do I think it would be good format for what I'm doing) but it does pique my curiosity. 8)

Code: [Select]
AAA says BA
BBB says AB

Other than that, my original problem is solved! Thanks for your help kojack! :D

Something tells me you're a teacher/professor? Feel free to use material from any of my questions in a classroom setting. I'm trying to learn/refresh on C++ so hopefully it helps more people than just me.

22
General / Re: General C++ Header Question
« on: January 31, 2022, 12:51:55 pm »
I just went through a major refactoring (the coding equivalent to being a chiropractor, yeouch!) trying to pop things back in place, so bare with me...

I've eliminated the stench @ Game::Application m_App; (within the RGL class header) but now it's popping up at rgl::Graphics m_Graphics; and rgl::Input m_Input; (within the RGL/Application class header). Same type of error, very similar scenario as the (now resolved but useful demonstration) code above. Circular dependencies? I'm trying to iron it out. I don't believe there should be but I'm still new to C++. Still, Ruby has a dependency model (require 'somelib') similar to C++ (#include <somelib.h>). (This project is planned to integrate into Ruby, but that's a non-factor and outside the scope of this topic...)

So here is the newly refactored include calls. It's been changed so class Common is class RGL now, namespace Game is namespace rgl now. I'm not messing with it anymore until tomorrow, so here it is as of right now...

(click to show/hide)

I've been careful to include only what I need, when I need it and where I need it. Each class takes the free floating SFML classes and gives it a well-defined structure for the project I'm setting up. RGL holds rgl::Application (think the application window), rgl::Application holds rgl::Audio, rgl::Graphics, rgl::Input (and maybe rgl::Video in the future) modules. Main calls RGL.main() => (RGL.mainStart, RGL.mainLoop, RGL.mainBreak, RGL.mainEnd) which manages the lifetime of the Application. Pretty much sums up the whole program at the moment.

23
General / General C++ Header Question [SOLVED] + Demo/Quiz
« on: January 31, 2022, 08:24:21 am »
Hello and good day everyone!

This is a question I'd normally reserve for a place like StackOverflow considering it's a general programming question but I have to wait two days to post again o.o I'd like to solve this error sooner and get on with my life.

I'm having problems with something that has worked for a while, and I'm not sure why exactly it stopped working. I've swapped headers around and done other things to try to satisfy the compiler but it's not having it. This is a common problem I've randomly had with member variable classes and, as soon as I solve them, I forget what I've done to solve the last ones. I'll provide some sample code...

Code: [Select]
#ifndef COMMON_HPP
#define COMMON_HPP

/* Other #include calls omitted for brevity */

#include <Common/Application.hpp>

namespace Game { class TestCase {}; }

class Common {
    public:
        Common();
        virtual ~Common();
        Game::TestCase mTest; //<-- If this is OK...
        Game::Application m_App; //<-- ...then why is that NOT OK...?
};

#endif // COMMON_HPP

I keep getting...

Code: [Select]
error : 'Application' in namespace 'Game' does not name a type.
^Game::Application is defined much in the same way as Game::TestCase, so I'm not sure why I'd get a problem with one and not the other. Something something the chicken and the egg something something..... this shouldn't be that hard.

Moving #include calls doesn't seem to change it. Other member variable classes don't have these issues. I know the compiler needs to see what is what, and load things in a certain order, and profile classes so it knows to allocate enough memory for each class. I've provided the header for the class it needs so I'm not sure the issue. Application holds a bunch of classes, Common holds Application, Application apparently isn't a "type" so... what should I do?

Game::Application is a class in a namespace like Game::TestCase is a class in a namespace. I shouldn't have to do any funky typedef things, right? This seems like an easy to solve problem, I'm surprised I've been stuck on it for two days.

And I tend to sometimes get these errors too. It'd be like...

Code: [Select]
#include <Breakfast/Eggs>
#include <Breakfast/Bacon>
#include <Breakfast/Sausage>

class YoBreakfastPlate {
    Breakfast::Eggs mEggs;
    Breakfast::Bacon mBacon;
    Breakfast::Sausage mSausage;
}

...and the compiler tells me I'm out of Bacon?! That's just not good. The Bacon is sitting right here, I'm looking at it, how am I out of Bacon? Bacon ain't no type of Breakfast, not for you, you get no Bacon! We put no Bacon on YoBreakfastPlate! :o :'(

24
Hello and good day!

I've browsed/studied the SFML library for quite some time before jumping in and using it. On one hand, I feel intimately familiar with it and it all makes sense to me and all I have to do is learn the nuances of C++, on the other hand I haven't actually used it enough to know what I'm talking about. I'm a n00b, okay. We all were at one point.

So I'm reading an article from geeksforgeeks.org (link) and in the Pros and Cons, under Cons, they state SFML "cannot do 3D" and states something about OpenGL. This library *can* do 3D, and is ran on OpenGL, am I correct? I'm sure it's not *designed* for (or against) 3D, but there shouldn't be any issues making a 3D project with this library, right?

It's not a big concern of mine (my project is 2D) but I would like to hear about the experiences of designing a 3D game with this library. Tell me about your projects using 3D, tell me about the pros and cons, your challenges, your failures, your triumphs. Do you find that SFML suits your needs well or do you have to go through great lengths to design a project in the 3rd dimension? Does your project use full 3D or just some 3D elements to enhance an otherwise 2D experience? What kind of libraries would you need to further support the rendering of 3D assets?

Also, how is the iOS/Android support? I'm sure there is room for improvement but is it pretty robust thus far? The article was written in 2019 so maybe things have improved dramatically.

25
General / Re: C++ Version / Power Usage Very High [SOLVED]
« on: January 23, 2022, 10:46:29 am »
Alright cool, putting it to sleep for 10 milliseconds as suggested really dropped the values down to almost nothing, the difference is like night and day. (Its running as 0 to 2% CPU now with Power Usage at Very Low).

Thank you both :D SOLVED!

26
General / C++ Version / Power Usage Very High [SOLVED]
« on: January 22, 2022, 02:11:07 pm »
Hello and good day!

I have two questions that may or may not be related. They may or may not even be easy to answer, and that's OK too. The first one should be easy enough...

Question 1

I'd have to really dig through tutorials and documentation (and I did for a little bit) but...

What version of C++ should I be using? C++14? C++17? ISO or GNU matter? Any other "rule of thumb"? I'm using (paraphrasing) C++14 GNU (ISO with GNU extension). I've experimented with changing these selections around a tiny bit only because of my next question...

Question 2

What could be making Power Usage rate as Very High and what would be a good way to drop this rating? Does SFML generally use a lot of power always or would it be because I might have something set up incorrectly as far as C++ standard, ISO/GNU, etc? I honestly don't believe it is anything having to do with what I've made thus far but here is details of what I have done...

(click to show/hide)



Other than 2 "Musics" playing, and a image being drawn (once) I could have nothing going on, not touching any buttons, and the power usage is the only one that fluctuates and it hits "Very high" a lot for no apparent reason. CPU is "fairly stable" (although it would be cool if it was lower) and Memory is right where I'd want and expect it to be thus far.

Any ideas what could possibly be making my Power Usage high? With my frame rate set at steady 60 via SFML, should I be calling a sleep function in main loop or would that just slow down the application each frame and mess up the FPS? Any other suggestions to drop the power usage? I don't think anything can be done about CPU, I recall it always being about that high from the start, so I think its more in the scope of SFML than anything I've written.

27
Audio / Re: Problem With Vector / Audio Operations [Un-SOLVED]
« on: January 22, 2022, 04:36:57 am »
Update: I've marked this as Un-SOLVED but I'm putting it back as SOLVED because I've implemented a satisfactory buffer cleanup! I'll leave this lingering question just in case anybody has a good answer. However, I'm not stuck on it so we're good now :D

(click to show/hide)

This is basically what I did, just for reference to anybody new who might need to do it. I basically time the longest sound, double that time, and do a full clear of the buffers if the time maxes out. I'm sure an even BETTER implementation COULD be made, sure, but this works for me.

Code: [Select]
bool SoundMix::play(const sf::String& l_name, float volume, float pitch) {
    // End function doing nothing if no name given
    if (l_name.isEmpty()) { return true; }
    // Create sound and sound buffer
    sf::Sound sound;
    sf::SoundBuffer buffer;
    // If unable to open from file
    if (!buffer.loadFromFile(l_name)) {
        // Print to console
        cout << "Unable to load Sound Effect" << endl;
        // Error opening file
        return false;
    }
    // Set volume, pitch and loop
    sound.setVolume(volume);
    sound.setPitch(pitch);
    sound.setLoop(false);
    // If sound duration is more than current max time
    if (buffer.getDuration() > m_timeSEMax) {
        // Restart timer and set time max duration
        m_timeSE.restart();
        m_timeSEMax = (buffer.getDuration());
        // Give the buffers some extra time by doubling it
        m_timeSEMax += (buffer.getDuration());
    }
    // Add to vectors
    m_SoundV.push_back(sound);
    m_BufferV.push_back(buffer);
    // Set the last buffer on the stack
    m_SoundV[m_SoundV.size() - 1].setBuffer(m_BufferV[m_BufferV.size() - 1]);
    // Play the sound
    m_SoundV[m_SoundV.size() - 1].play();
    cout << "Playing SE : " << m_SoundV.size() << endl;
    // Opened file successfully
    return true;
}
void Audio::updateBuffers() {
    // End function if no buffers
    if (m_BufferV.empty()) { return; }
    // Clear buffers if enough time has passed by
    if (m_timeSE.getElapsedTime() >= m_timeSEMax) {
        cout << "Erasing Buffers : " << m_BufferV.size();
        // Clear buffers and restart timer
        m_BufferV.clear();
        m_timeSE.restart();
        cout << " ; Buffer Size " << m_BufferV.size() << endl;
    }
}[code]

28
Audio / Re: Problem With Vector / Audio Operations
« on: January 21, 2022, 04:53:25 am »
Cool, I'm starting to understand a little bit better as I go. It seems the entire module from top to bottom is now complete, all I have to do is schedule "chores" for buffer cleanup every once in a while ;)

Thank you both for your help! I am a quick learner so I should be needing less and less help as time goes on; I'll try to do what I can around here to help as well :D Of course, at this point in time, my help would be the blind leading the blind, haha, but I'm catching on and studying more and more every day.

SOLVED!

29
Audio / Re: Problem With Vector / Audio Operations
« on: January 20, 2022, 12:16:33 pm »
Here is a (stupid) piece from my SoundMix update() function. I know it would require more logic than that, of course, but the erase function throws an error and I need to address this next. I think I know what I need to do I just don't know how to write it, I guess.

A piece of the function for erasing...
Code: [Select]
    // End method if no sound is playing
    if (m_SoundV[i].getStatus() == sf::Sound::Stopped) {
        m_SoundV.erase(m_SoundV[i]); // I also tried .erase(i);
        m_BufferV.erase(m_BufferV[i]); // I also tried .erase(i);
        return;
    }

The errors I get on erasing
Code: [Select]
||=== Build: Debug in Game (compiler: GNU GCC Compiler) ===|
C:\Game\src\game\soundmix.cpp||In member function 'void Game::Sound::update(int)':|
C:\Game\src\game\soundmix.cpp|605|error: no matching function for call to 'std::deque<sf::Sound>::erase(__gnu_cxx::__alloc_traits<std::allocator<sf::Sound> >::value_type&)'|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1742|note: candidate: std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::const_iterator) [with _Tp = sf::Sound; _Alloc = std::allocator<sf::Sound>; std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<sf::Sound, sf::Sound&, sf::Sound*>; std::deque<_Tp, _Alloc>::const_iterator = std::_Deque_iterator<sf::Sound, const sf::Sound&, const sf::Sound*>]|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1742|note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<sf::Sound> >::value_type {aka sf::Sound}' to 'std::deque<sf::Sound>::const_iterator {aka std::_Deque_iterator<sf::Sound, const sf::Sound&, const sf::Sound*>}'|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1766|note: candidate: std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::const_iterator, std::deque<_Tp, _Alloc>::const_iterator) [with _Tp = sf::Sound; _Alloc = std::allocator<sf::Sound>; std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<sf::Sound, sf::Sound&, sf::Sound*>; std::deque<_Tp, _Alloc>::const_iterator = std::_Deque_iterator<sf::Sound, const sf::Sound&, const sf::Sound*>]|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1766|note:   candidate expects 2 arguments, 1 provided|
C:\Game\src\game\soundmix.cpp|606|error: no matching function for call to 'std::deque<sf::SoundBuffer>::erase(__gnu_cxx::__alloc_traits<std::allocator<sf::SoundBuffer> >::value_type&)'|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1742|note: candidate: std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::const_iterator) [with _Tp = sf::SoundBuffer; _Alloc = std::allocator<sf::SoundBuffer>; std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<sf::SoundBuffer, sf::SoundBuffer&, sf::SoundBuffer*>; std::deque<_Tp, _Alloc>::const_iterator = std::_Deque_iterator<sf::SoundBuffer, const sf::SoundBuffer&, const sf::SoundBuffer*>]|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1742|note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<sf::SoundBuffer> >::value_type {aka sf::SoundBuffer}' to 'std::deque<sf::SoundBuffer>::const_iterator {aka std::_Deque_iterator<sf::SoundBuffer, const sf::SoundBuffer&, const sf::SoundBuffer*>}'|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1766|note: candidate: std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::erase(std::deque<_Tp, _Alloc>::const_iterator, std::deque<_Tp, _Alloc>::const_iterator) [with _Tp = sf::SoundBuffer; _Alloc = std::allocator<sf::SoundBuffer>; std::deque<_Tp, _Alloc>::iterator = std::_Deque_iterator<sf::SoundBuffer, sf::SoundBuffer&, sf::SoundBuffer*>; std::deque<_Tp, _Alloc>::const_iterator = std::_Deque_iterator<sf::SoundBuffer, const sf::SoundBuffer&, const sf::SoundBuffer*>]|
C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\include\c++\bits\stl_deque.h|1766|note:   candidate expects 2 arguments, 1 provided|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

I did not assign a template (well, I attempted to) for the std::deque but it was somehow working GREAT until I decided I wanted to start deleting things that aren't playing anymore. I *think* I need to assign templates instead of std::deque<sf::Sound> and std::deque<sf::SoundBuffer>. I don't understand WHY C++ tutorials confuse the hell out of me but the whole template thing does confuse me and I can't get it to behave. I know almost exactly what I want to do but I'm all hung up on syntax.

If the tutorials I've read online weren't confusing me so much I wouldn't ask but how would you define the template I need to write in? What I had (but commented out) was something along the lines of...

Code: [Select]
// In HEADER...

template<typename S> sf::Sound;
template<typename B> sf::SoundBuffer;

namespace Game {
class SoundMix {
    public:
        std::deque<S> m_SoundV;
        std::deque<B> m_BufferV;
};
}

I only removed the template stuff because it wouldn't compile but I think it is needed - is it? The program that I'm compiling right now can play tons of sounds concurrently but I don't have a way to erase them and they're NOT templated, I passed the actual sf::Sound and sf::SoundBuffer into the std::deque<obj> as I defined them in the header. I would imagine these things would build up quick and I need to purge them like they were yesterday's brunch.

I'm a Ruby programmer so I'll post how I'm trying to do it in a mock Ruby style (it should be easy enough to read, even if you've never programmed Ruby - Ruby is EXTREMELY SIMPLE to program, its almost like speaking life into a machine with plain language.)

Code: [Select]
@sounds.each_index {|i| @sounds.delete_at(i) if @sounds[i].stopped?}
@buffers.each_index {|i| @buffers.delete_at(i) if @buffers[i].no_connections?}

What do I need to do to perform a function like that with the C++? And how should the template be? I'm almost to where I need to be thanks to both of you :)

30
Audio / Problem With Vector / Audio Operations [SOLVED]
« on: January 18, 2022, 11:22:22 am »
Hello and good day!

So I'm still new with C++ and it fights me every chance it gets. If you hear me yelling I'm probably yelling at the compiler and not my kids ;)

The problem I'm having today is more C++ related than Audio module related but I happen to be working with audio so I'm posting it here. I'd post it in the discord or ask around in IRC but I can't seem to get either working. It could be my horrible internet connection, or my Brave browser, but I put shields down so I don't know...

So I'm trying to do a Game::Sounds mixer class but for the life of me I can't get the std::vector to behave. I've made a std::vector for both the sf::Sound and the sf::SoundBuffer variables. Do I need a separate vector for both or is there a better way?

I would like to put the Sounds in a vector as they're played. I'll push them to the vector when played and pop them out when they're finished. It doesn't have to be a std::vector, I could use an array or whatever an std::list is but I figured it would be best for the job at hand.

Anywho, I wrote this micro example with a dummied sf::Sound and sf::SoundBuffer for testing purposes; it closely resembles what I actually have, minus a bunch of code irrelevant to the topic. Same problems. It can be easily tested @ ...

https://www.onlinegdb.com/online_c++_compiler

Code: [Select]
//-- Game/Sounds.hpp --//

#ifndef GAME_SOUNDS
#define GAME_SOUNDS

#include <vector>
#include <iostream>
#include <string>


// Dummy SFML sf:: namespace ;)
namespace sf {
    class Sound {};
    class SoundBuffer {};
}

namespace Game {
static const int SOUND_MAX = 16;
class Sounds {
public:
// Public Member Declarations
        std::vector<sf::Sound> m_SoundV[16];
        std::vector<sf::SoundBuffer> m_BufferV[16];
        // Constructor and Destructor
        Sounds();
        ~Sounds();
// Public Function Declarations
bool play(const std::string& l_name, float volume, float pitch);
int size();
};
} // End of Game::Sounds

#endif




//-- Game/Sounds.cpp --//

namespace Game {

bool Sounds::play(const std::string& l_name, float volume, float pitch) {
// Create new sound and buffer
sf::Sound sound;
sf::SoundBuffer buffer;


// Omitted: Load sound / return error on fail
// Omitted: Set volume and pitch


// Add sound and buffer to vector
m_SoundV.push_back(sound);
m_BufferV.push_back(buffer);
// For example simplicity, we just return true (no error)
return true;
}

int Sounds::size() {
    // Get size of sound vector
    return m_SoundV.size();
}
} // End of Game::Sounds




//-- Main.cpp --//

int main() {
    Game::Sounds soundmixer;
    soundmixer.play("Sample", 100.0f, 1.0f);
    std::cout << soundmixer.size() << std::endl;
    return 0;
}

Here is a snapshot of the errors I'm currently having...

Code: [Select]
main.cpp:53:11: error: request for member ‘push_back’ in ‘((Game::Sounds*)this)->Game::Sounds::m_SoundV’, which is of non-class type ‘std::vector [16]’
   53 |  m_SoundV.push_back(sound);
      |           ^~~~~~~~~
main.cpp:54:12: error: request for member ‘push_back’ in ‘((Game::Sounds*)this)->Game::Sounds::m_BufferV’, which is of non-class type ‘std::vector [16]’
   54 |  m_BufferV.push_back(buffer);
      |            ^~~~~~~~~
main.cpp: In member function ‘int Game::Sounds::size()’:
main.cpp:61:21: error: request for member ‘size’ in ‘((Game::Sounds*)this)->Game::Sounds::m_SoundV’, which is of non-class type ‘std::vector [16]’
   61 |     return m_SoundV.size();

Why is the vector being so naughty? When I originally tried it, I was trying to construct the vectors in many such a ways; using const, using static, attempting a std::vector<T*> template stuff (which I don't understand yet), passing references& and pointers*. No matter what I do I can't seem to catch a break with it. I've been crunching on reading material and tutorials, even finished a 1300+ page book on C++ but somehow I haven't been able to figure out vectors.

At one point I was doing something like vector->push_back(obj); not that I thought that was the correct way to do it, but it seemed to shut the compiler up for a second.

Once I get better at C++ and have suffered my metaphorical beatings, I shouldn't be blowing these threads up too much. ;)

EDIT: Follow-up question. This is an old function, utilizing an sf::Sound and an sf::SoundBuffer.

Code: [Select]
bool Audio::playSE(const sf::String& l_name, float volume, float pitch) {
    if (l_name.isEmpty()) {
        // Stop the SE
        m_SE.stop();
        // Nothing wrong with stopping the SE
        return true;
    }
    // Get sound buffer
    //sf::SoundBuffer buffer;
    // If unable to open from file
    if (!m_SE.openFromFile(l_name)) {
        // Error opening file
        return false;
    }
    // Set volume, pitch and loop
    m_SE.setVolume(volume);
    m_SE.setPitch(pitch);
    m_SE.setLoop(false);
    // Play the SE
    //m_SE.setBuffer(buffer);
    m_SE.play();
    // Opened file successfully (just kidding...)
    return true;
}

^Does the buffer go out of scope here as soon as the function is finished? I've never heard a single sound doing this. Do I have to carry buffer on to some outside update() function within my game loop and manage it until the entire sound is finished playing? In the example before this one, I had a vector for sounds AND buffers; do I need them both or would there be a better way?

I did read the tutorial a few times. When I swapped out the sf::Sound for an sf::Music I didn't have to use a sf::SoundBuffer but I'm trying to do things proper as I'm a very by the book kind of guy. I can only guess how many sounds would be played at once and I don't want to bog it down with a bunch of sf::Music objects (which does work for me but I know its wrong and I don't want to initiate a bunch of heavy Musics when I need to play a bunch of consecutive lightweight Sounds.)

Pages: 1 [2] 3
anything