Making a map in c++

Discussion in 'Tech Discussion' started by Zaart, Sep 26, 2019.

Tags:
  1. Zaart

    Zaart Deer Master Race

    Joined:
    Oct 15, 2016
    Messages:
    1,320
    Likes Received:
    2,011
    Reading List:
    Link
    Hey guys,
    so well i was trying to make a game (yay) but everyone said that in c it was not going to work well (sob)

    so fast forward to today where i learnt a bit of c++, and to make a game i have to make a map!

    so should i use linked list and some rpg maker tileset (one member of the linked list = one of the tileset, and then i draw those on the screen depending on a file with number to know where to put what)

    or should i plan all my maps in advance and do it like "oh player is in map 3, i should load this set!"

    with linked list it might be easier to know where a wall is....

    as you can probably see i am a bit lost about where to start -.-
     
  2. The Hamster Overlord

    The Hamster Overlord Mad scientist/Revered wizard/Alleged antichrist

    Joined:
    Aug 12, 2018
    Messages:
    4,282
    Likes Received:
    4,529
    Reading List:
    Link
    I'm not a professional but the second option seems more efficient
     
  3. Art Of Throwing

    Art Of Throwing Spare me

    Joined:
    Jun 19, 2016
    Messages:
    232
    Likes Received:
    236
    Reading List:
    Link
    It might be easier to use rpg maker. if u do all the maps in advance then u need to do it all hardcoded right?
     
  4. SublimeWay

    SublimeWay Well-Known Member

    Joined:
    Mar 24, 2016
    Messages:
    322
    Likes Received:
    151
    Reading List:
    Link
    I’m curious why you went with C++ for your first try at game dev. You might want to consider something a little more user friendly in your first attempt. Personally I prefer Unity and C# as there’s a huge amount of tutorials and knowledge base out there, and it’s free to use for your purposes.

    Also wondering why you chose a linked list instead of an array.
     
  5. sgrey

    sgrey Well-Known Member

    Joined:
    Jul 12, 2017
    Messages:
    1,206
    Likes Received:
    1,492
    Reading List:
    Link
    Since you will traverse it a lot of times all the time, a linked list might not be a good idea as it will cause some performance loss due to a large number of RAM access requests. I suggest an indexable structure. Perhaps, the hashmap or a map data structure would be best? Or make your own class with an array as storage and implement navigation methods for it.

    If this is your first game, I suggest also do not go for the fancy stuff like dynamic loading of procedurally generated maps. Try to use static maps first, try stuff out, see how it works and get some experience. You can modify them later to be more fancy.
     
  6. methael

    methael Well-Known Member

    Joined:
    Aug 12, 2016
    Messages:
    79
    Likes Received:
    57
    Reading List:
    Link
    Try pre allocating nodes of the linked lists together. So the memory is next to each other, and it doesn't have to jump from one address to another that's far away...?
     
    Deleted member 155674 likes this.
  7. GuldTasken

    GuldTasken Well-Known Member

    Joined:
    May 1, 2016
    Messages:
    672
    Likes Received:
    584
    Reading List:
    Link
    Who ever that said, C isn't going to work well for a game, is pretty much an amateur within coding. The C language is in the forefront regarding optimization and coding of games, especially the core of a game. Then, sure... you can make games using Java and other languages. But you have to realise, that these languages are generally Slower to be read etcetera. For example, Most JAVA games have the bottleneck in the RAM... Minecraft as a good example.

    So just keep at it. If anything, learning C makes learning anything other than that, easier.
     
    Deleted member 155674 likes this.
  8. sgrey

    sgrey Well-Known Member

    Joined:
    Jul 12, 2017
    Messages:
    1,206
    Likes Received:
    1,492
    Reading List:
    Link
    you have no control over it, especially since each node has to be allocated separately, you can't really just reserve the block. And your program might be put to sleep and run later in the middle of the allocation by the scheduler. There is no way to guarantee you will get consecutive memory unless maybe you use some special custom allocator. Even if that happens, you still get a bunch of garbage in the cache to go together with the actual data you want
     
  9. Shtirliz

    Shtirliz Well-Known Member

    Joined:
    Feb 20, 2018
    Messages:
    179
    Likes Received:
    170
    Reading List:
    Link
    And here I am here, thinking that you need advice how to do a container...

    About question - first you need to understand your tools and only after that you can plan what you can do.
     
  10. Jojo775

    Jojo775 Honorary Algae Knight

    Joined:
    Feb 13, 2018
    Messages:
    4,301
    Likes Received:
    2,569
    Reading List:
    Link
    You can make games in any language but unless you it's just a demonstration for university or something, you should stick to java or C#.
     
  11. Ddraig

    Ddraig Frostfire Dragon|Retired lurker|FFF|Loved by RNG

    Joined:
    Apr 6, 2016
    Messages:
    7,853
    Likes Received:
    22,455
    Reading List:
    Link
    Tbh an array sounds way better here. You will need to access each tile a lot (to check if tile is traversable or not) and going through ll every time is not a great idea.
    Nope array is better coz O(1) access to every tile and you can always define each tile to have an isWall variable or use simple math to determine the map limits.

    As for maps, I would suggest loading data from a file. Generate a map object out of it and use that object for display. The object would take I guess tileset(as in the look of the tile) and the filename.

    I believe there are tutorials on yt too about creating games in c++
     
  12. Zaart

    Zaart Deer Master Race

    Joined:
    Oct 15, 2016
    Messages:
    1,320
    Likes Received:
    2,011
    Reading List:
    Link
    well i also want to use this as an opportunity to learn ^^
    but yeah hardcoded is one of the option i thought of
    well i used CSFML in c to make an rpg last year so i thought SFML and c++ was the obvious next step
    and yeah an array might have been better -.- for whatever reason when i think of a structure the first thing that pop into my mind is "LINKED LIST!" it is weird
    oh thanks, it is quite the detailed answer
    i am not bad in c, and it indeed speed up the process of learning c++ quite a lot!
    but in a previous thread i made everyone told me that making a game in c was the step just above making a game in ASM (Rollercoaster tycoon i am looking at you)
    to have control over it you need to re-code malloc and make some sort of temporary memory keeper -.- not something to be enjoyed
    thats exacty why i am asking ^^
    discussing it help me understand it better
    Nah it's for fun ^^ well mostly because i have a lot of free time recently
    oh thanks, indeed array look better for this,
    but i am unsure about what you mean by 'generating a map object'
     
    Last edited: Sep 26, 2019
  13. TamaSaga

    TamaSaga Well-Known Member

    Joined:
    Oct 11, 2016
    Messages:
    1,726
    Likes Received:
    2,173
    Reading List:
    Link
    Honestly, traversing the array is going to take no time relative to loading the map itself. As long as you don't load every map as a precache step, it shouldn't matter which route is most efficient. Try not to prematurely optimize or you'll spend too much time thinking and no time doing.
     
  14. sgrey

    sgrey Well-Known Member

    Joined:
    Jul 12, 2017
    Messages:
    1,206
    Likes Received:
    1,492
    Reading List:
    Link
    it has been done before, but not for the purpose of allocating consecutive ram chunks

    sounds like he talking about reading map information and put in in some C++ object that you will use after reading the information from a file
     
  15. Ddraig

    Ddraig Frostfire Dragon|Retired lurker|FFF|Loved by RNG

    Joined:
    Apr 6, 2016
    Messages:
    7,853
    Likes Received:
    22,455
    Reading List:
    Link
    Make a map (defined by you) object. In the init method/constructor, make the tile array and the tile objects for it. Taking height and width as parameters or passing it as first values in the file would also be a good idea.
    Remember to destroy the tile objects inside it in the destructor/finalize methods too btw
     
    AMissingLinguist likes this.
  16. Zaart

    Zaart Deer Master Race

    Joined:
    Oct 15, 2016
    Messages:
    1,320
    Likes Received:
    2,011
    Reading List:
    Link
    oh thanks i think i see ^^
    Oh? why would someone do something so masochistic =P
    well maybe but i still remember the time i had to redo my whole code to optimise it T-T
    but yeah i just wanted different point of view in order to not go at it blindly like a dog an a mine field
    edit: also you can now have a title ya know?
     
  17. lighterxx

    lighterxx Hoshi stan before a human °^°)

    Joined:
    Jan 31, 2019
    Messages:
    1,269
    Likes Received:
    2,143
    Reading List:
    Link
    you definitely need rpg maker, you would have alot easier time in longterm, ALSO IF ITS AN INTERESTING GAME CAN I JOIN TOO
     
  18. sleepingloli

    sleepingloli Well-Known Member

    Joined:
    Feb 13, 2019
    Messages:
    60
    Likes Received:
    65
    Reading List:
    Link
    Hint: The context for that affirmation is not the performance side. It's what they should put their focus on when they don't know neither programming nor game development; and that depends on their goals.
     
    AMissingLinguist and Zaart like this.
  19. Zaart

    Zaart Deer Master Race

    Joined:
    Oct 15, 2016
    Messages:
    1,320
    Likes Received:
    2,011
    Reading List:
    Link
    SURE, I WOULD LOVE TO!
    well i also wanna learn a new language so rpg maker is not what i really want to do
    it is true i am a bit of a noob =P
     
    lighterxx likes this.
  20. Molen

    Molen Well-Known Member

    Joined:
    Oct 6, 2016
    Messages:
    255
    Likes Received:
    268
    Reading List:
    Link