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

Pages: [1]
1
(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;
}

2
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 !

3
OK thank you ! I will send it to you in 2 days (not at home for now)

4
It still crashes after it tried to load keys.cfg, textures.cfg and EnemyList.list.

Something has to be wrong about how I named some of my paths or the location (I placed them just like you did, in a "Resources" folder).

I also have a LOT of warning messages but it's mostly "X will be initialized after", I don't know if it can be the root of my problem.

Thank you for your patience tho, I feel like a total noob with these loading problems  :P

5
I already tried that and it failed to load any files (so no more build errors but it just crash when trying to load the files).
I tried to build and run your code and same thing, crashed when trying to load any files.
I even tried to change the location of the media and config files with no success.

The old loading method (without using methods from Utilities.h) works well but I don't want to use that since it's not optimized.

The worst thing is that I'm pretty sure the solution is so obvious that I can't see it  ;D

6
Hello again,

It seems like
strcat_s(path, "\\")
can't be used in CodeBlocks (or am I wrong ?)
It's supposed to be a Visual C++ or Visual Studio function, is there an alternative ? Like using std::string
instead of a char* ?

The code:

#pragma once
#define RUNNING_WINDOWS
#include <iostream>
#include <cstring>
#include <algorithm>

namespace Utils
{
    #ifdef RUNNING_WINDOWS
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <Shlwapi.h>
    inline std::string getWorkingDirectory()
    {
        HMODULE hModule = GetModuleHandle(nullptr);
        if(hModule)
        {
            char path[256];
            GetModuleFileName(hModule, path, sizeof(path));
            PathRemoveFileSpecA(path);
            strcat_s(path, "\\");
            return std::string(path);
        }
        return "";
    }

and the error:

Utilities.hpp|21|error: 'strcat_s' was not declared in this scope|

7
EDIT: I didn't link to libshlwapi.a correclty, now it works  :)
Thank you, I didn't implement the getContext() method, no more errors about that.

There is now a problem with the method
PathRemoveFileSpec(path);
from
#include <Shlwapi.h>

Utilities.hpp|22|undefined reference to `_imp__PathRemoveFileSpecA@4'|

I assumed it's a linker error and tried to add the
Shlwapi.dll
in the bin folder but with no success (I'm using CodeBlocks, if that matters)

8
Quote
I was just about to reply to you about including the shared context header. Please make sure you consult the code files that came with the book. You will find complete source code there, with all of the necessary includes in place.

Yes, I'm going through your code line by line at the moment and found some answers to my problem.

There is however one last error that I didn't manage to resolve:
[...]\Character.cpp|7|undefined reference to `EntityManager::getContext()'|

and the code snippet:
Character::Character(EntityManager *entityMgr)
: EntityBase(entityMgr)
, mSpriteSheet(mEntityManager->getContext()->mTextureManager)

I probably missed something in your code (I should be sleeping but this error bugs me so hard !)

9
EDIT: Looks like I missed some includes, no more error for the SharedContext. But now I have another bunch of errors  8) I will try to correct them first before posting them

Hello  :)

I have an issue in Chapter 7 regarding the header of the class "Map".

When I try to build the code, there is an error here:

struct TileInfo {
    /// C-tor & D-tor ///
    TileInfo(SharedContext* context, const std::string &texture = "", TileId id = 0)

[...]Map.hpp|17|error: expected ')' before '*' token|

So it seems there is a problem with the "SharedContext *" parameter. The SharedContext header should be good:

class Map;
struct SharedContext
{
    SharedContext():
    mWindow(nullptr)
    , mEventManager(nullptr)
    , mTextureManager(nullptr)
    , mEntityManager(nullptr)
    , mGameMap(nullptr)
    {}

    Window          *mWindow;
    EventManager    *mEventManager;
    TextureManager  *mTextureManager;
    EntityManager   *mEntityManager;
    Map             *mGameMap;
};
 

I read somewhere in previous answers that
SharedContext *
member in StateManager.hpp should be
SharedContext
but it doesn't seem to resolve the problem  :(

10
General discussions / Re: SFML Game Development by Example - 4th SFML book
« on: February 08, 2016, 07:42:21 pm »
I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Thank you for the nice customer support  ;D I tried to add your piece of code but there is a problem with the loadBindings() function:
Code: [Select]
CustomHash.hpp|9|error: invalid static_cast from type 'std::basic_string<char>' to type 'std::size_t {aka unsigned int}'|
Do I have to use "std::make_tuple" for both "find" and "emplace" methods in order to add the "CustomHash" argument or I don't have to touch them ? The question is more related to C++ than SFML/Your book tho
std::string should be hashable by default, if I'm not mistaken, so you don't need to provide the third argument for the binding container. You only need to do that with non-fundamental data types, such as "enum class" or anything else you might use as the key. It's also fair to point out that the CustomHash posted above works only with types that can be statically cast to std::size_t (unsigned integer). The binding container's key is a string, so that would require a different approach. Hope this helps :)

Thanks, it worked ! I just added CustomHash to unordered_maps that used "StateType" (well, that was exactly what you said earlier, but I thought I had to add it to every unordered_map container for some reason..) and everything runs perfectly  :)

11
General discussions / Re: SFML Game Development by Example - 4th SFML book
« on: February 08, 2016, 06:48:51 pm »
I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Thank you for the nice customer support  ;D I tried to add your piece of code but there is a problem with the loadBindings() function:
Code: [Select]
CustomHash.hpp|9|error: invalid static_cast from type 'std::basic_string<char>' to type 'std::size_t {aka unsigned int}'|
Do I have to use "std::make_tuple" for both "find" and "emplace" methods in order to add the "CustomHash" argument or I don't have to touch them ? The question is more related to C++ than SFML/Your book tho

12
General discussions / Re: SFML Game Development by Example - 4th SFML book
« on: February 07, 2016, 11:38:16 pm »
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks
Hello! First of all, thank you so much for showing support and purchasing the book! I hope you enjoy it the rest of the way :)

The shift key problem you're experiencing is a result of tiny changes between SFML versions. The sf::Keyboard::Key enum values are different after version 2.1, so you have to edit the "keys.cfg" file, specifically the "Move 9:0 24:38" line, and change the number 38 to whatever numerical index the LShift key happens to fall under in 2.1.

Please let me know if you have any more problems on the way!

I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)

13
General discussions / Re: SFML Game Development by Example - 4th SFML book
« on: February 03, 2016, 10:34:18 pm »
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks

Pages: [1]