Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Game Development by Example - 4th SFML book  (Read 184127 times)

0 Members and 5 Guests are viewing this topic.

Bryan Pope

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #135 on: August 19, 2016, 03:29:09 am »
Good evening,

I am trying to compile the code from Chapter 11, but unfortunately I am getting a couple errors:
- std::unordered_map has no member rbegin or rend
- Utilities.h, char * is incompatible with Utils::LPWSTR

Do I need to do some other setup in VS2015?  (Other than VC++ Directories, C/C++ Preprocessor, Linker General and Input)

Thanks,

Bryan Pope

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #136 on: August 19, 2016, 04:02:05 am »
Hello Bryan,

First of all, thank you for buying the book. I really hope you are enjoying it so far, and sorry about the problems you're experiencing.

For the first issue, somehow the type definitions didn't get updated along with the rest of the code. You don't want to use unordered_map for the GUI_Interfaces container type. Instead, you could simply switch to std::map, or try something that looks like this:
using GUI_InterfaceType = std::pair<std::string, std::unique_ptr<GUI_Interface>>; // Smart pointer or raw, doesn't matter.
using GUI_Interfaces = std::vector<GUI_InterfaceType>; // Vector DOES support reverse iterators.
using GUI_Container = std::unordered_map<StateType, GUI_Interfaces>;
std::map would be an easier switch. Obviously some GUI code might have to change a little bit, because of the way information is accessed if it's a vector. I will try to contact Packt and get this fixed, as it should have been updated in the final product.

The second issue you're experiencing simply has to do with the encoding of your project. Your IDE is set to use wide characters, so instead of the char type you could simply use wchar_t, or you could re-work the function like this (use the 'A' suffix for two functions):
inline std::string GetWorkingDirectory() {
        HMODULE hModule = GetModuleHandle(0);
        if (hModule) {
                char path[256];
                GetModuleFileNameA(hModule, path, sizeof(path));
                PathRemoveFileSpecA(path);
                strcat_s(path, "\\");
                return std::string(path);
        }
        return "";
}
I would recommend the former, but it's your call. More information on that can be found here: http://www.cplusplus.com/forum/windows/185258/

« Last Edit: August 19, 2016, 04:05:06 am by OrderNexus »

Bryan Pope

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #137 on: August 20, 2016, 04:34:50 am »
I finally got the Chapter 11 code to work! :)  But I had to do a little bit more than your suggestions:

- I went with std::map to replace std::unordered_map for GUI_Interfaces
- I finally went and used the "A" versions of GetModuleFileName and PathRemoveFileSpec, as I would have needed to change path back to a char, plus I was getting linker errors on the W versions of those two functions..
- but that also had issues - there were linker errors here as well for both functions
- after some googling, I added shlwapi.lib to my dependencies and also included PathCch.h and Shlwapi.h to Utilities.h.  But I then received quite a few errors "No target architecture".  To fix this I also included Windows.h in Utilities.h.
- when I ran it I was getting a nullptr error
- to fix this I copied the *contents* of the Asset directory into the Debug directory, plus I also had to remove the .txt extension from each of the .cfg files.

Next step is to play around with the code a bit!

Cheers,

Bryan Pope

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #138 on: August 20, 2016, 05:03:48 am »
Hello again, Bryan,

I'm glad you got the code working! The shlwapi.lib inclusion is actually covered in the beginning of Chapter 6, as well as Shlwapi.h and Windows.h. I actually doubt that PathCch.h is required. You can give it a try and remove it, as the code runs just fine on my end without it. As far as the .txt extensions, someone else had the same issue. Were they like that in the code package you downloaded? If so, it might be something worthy of reporting to Packt, as it clearly wasn't intended to be like that.

Please feel free to let me know if you have any more issues. I will do my best to help you whenever possible. :)

Bryan Pope

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #139 on: August 20, 2016, 08:26:25 pm »
Good afternoon,

Yes you are correct about the Shlwapi.h, windows.h and shlwapi.lib being covered in Chapter 6, I had forgotten that.  Also, you are right, I do not need PathCch.h.

Yes, in the Code Download zip file chapters 4, 5, 7, 8, 9, 11, 12 and 14 have .cfg files that also have a .txt appended to them.  I have reported this to Packt using their submit errata.

Thanks so much!,

Bryan

CleverBoy

  • Newbie
  • *
  • Posts: 25
  • Game on!!
    • View Profile
    • Email
Re: SFML Game Development by Example - 4th SFML book
« Reply #140 on: August 23, 2016, 12:46:13 pm »
Thanks for making it available and sharing your knowledge. I  am your happy customer. :)

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #141 on: August 23, 2016, 02:12:20 pm »
Thanks for making it available and sharing your knowledge. I  am your happy customer. :)
Thank you for your kind words! I'm really glad to know you found it useful. :)

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #142 on: October 10, 2016, 11:42:49 am »
Hello there! Thank you so much for this book it has been invaluable because I am teaching myself to program with C++and learning how to do it through a project like this has been great.

I must ask though how do you save a tiled map in the format that you do. Meaning this: http://imgur.com/YA9kw13

I can't seem to find any information on this at all. I am having some issues with trying to save a tile map in a certain way so that I can read it into my game.

Thank you!

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #143 on: October 10, 2016, 05:13:11 pm »
Hello, BonBons! Thank you for your kind words. I'm really glad you're enjoying the book so far. :)

By tiled, do you mean the Tiled Map Editor? (http://www.mapeditor.org/) If you do, I'm afraid I have no experience with it and wouldn't know if they even use the same type of elevation principles, not to mention other parameters necessary for their own format. I'm sure you could build a tool that somehow parses their format and writes it out however you want, but I can't say too much without looking at it.

If you simply mean how a map file like that can be saved, there's a big hint at the top of the file. As you can see, it's all saved as plain-text, making it easy to read and understand should you want to make revisions. All the lines that begin with the pipe symbol "|" are ignored by the code and treated as comments. Just above each new type of map file entry, there's a comment that explains exactly what parameters are stored in that line. For example, entities are stored by writing in the name of the entity type first, then the X and Y coordinates of the entity, and finally the elevation. Tiles store an additional value for their solidity, which can be either 0 or 1. That's pretty much all there is to it. If you can do basic file I/O, you know enough to save your entities and tiles in this format.

Hopefully this answers your question. I'm currently working on something that I can't say too much about, but let's just say that a portion of it deals with creating software that helps you build your own maps really easily. It should be out soon, so stay tuned. :)

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #144 on: October 13, 2016, 11:44:35 am »
Hey there would just like to say that your book has really taught me how to program in C++ and I've recently made a littel portfolio which I used to apply to Universities. And I actually got accepted from the basis from what I've learned from your books so thank you so much for that!


OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #145 on: October 13, 2016, 04:54:51 pm »
Hey there would just like to say that your book has really taught me how to program in C++ and I've recently made a littel portfolio which I used to apply to Universities. And I actually got accepted from the basis from what I've learned from your books so thank you so much for that!
Congratulations! I can't begin to explain to you how happy that makes me. Keep on doing great work, and good luck with your studies! :)

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #146 on: October 15, 2016, 04:33:17 pm »
Hey  :)

When I try to run the code in chapter 11 (in VS 2015), I get a "std::invalid_argument" error when it's trying to add the callback for "MainMenu_Play".

When debugging, it looks like the element contained in "eventInfo.gui.mElement" canno't be read in memory.

Is it possible that it comes from the fact that I compiled it in a x86 process ? (I read it somewhere on stackoverflow but I don't really think it's the problem here).

Tell me if you need me to post parts of the code or the debugger output !

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #147 on: October 15, 2016, 05:33:32 pm »
Hello. Yes, I'd like to see your GUI_Event struct, the EventInfo struct, and the code where the compiler notes the crash. At this point, it's hard to say what may have gone wrong, as it looks like you're modifying the code a little bit. :)

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #148 on: October 15, 2016, 06:49:21 pm »
(You can find attached a pic from the debugger)

GUI_Event
struct GUI_Event {
        GUI_EventType mType;
        const char *mElement;
        const char *mInterface;
        union {
                ClickCoordinates mClickCoords;
        };
};

EventInfo
struct EventInfo {
    EventInfo() { mCode = 0; }
    EventInfo(int event) { mCode = event; }
        EventInfo(GUI_Event &guiEvent) { gui = guiEvent; }
    union
    {
        int mCode;
                GUI_Event gui;
    };
};

and to me, it looks like it is crashing around here (from EventManager::loadBindings())

if (type == EventType::GUI_Click || type == EventType::GUI_Hover ||
                type == EventType::GUI_Release || type == EventType::GUI_Leave)
{
        start = end + delimiter.length();
        end = keyval.find(delimiter, start);
        std::string window = keyval.substr(start, end - start);
        std::string element;

    if (end != std::string::npos) {
                start = end + delimiter.length();
                end = keyval.length();
                element = keyval.substr(start, end);
        }
        char *w = new char[window.length() + 1]; // +1 for '\0'
        char *e = new char[element.length() + 1];

        strcpy_s(w, window.length() + 1, window.c_str());
        strcpy_s(e, element.length() + 1, element.c_str());

        eventInfo.gui.mInterface = w;
        eventInfo.gui.mElement = e;
}
« Last Edit: October 15, 2016, 06:51:24 pm by Nayk0_x »

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #149 on: October 15, 2016, 08:19:52 pm »
Everything above looks fine. Is there a way you could just archive all of your code and PM it to me so I can debug it?
« Last Edit: October 15, 2016, 08:23:56 pm by OrderNexus »