Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Jul 2012
Offline Last Active Today, 02:48 PM

Topics I've Started

Spatial partition 2d with 5 layers

08 July 2014 - 11:29 AM

I want to implement Spatial partition like http://gameprogrammingpatterns.com/spatial-partition.html

And all is good, but i have a question, i cannot decide on design cause i feel its going to be slow, so i need help.

I have objects that will represent anything in my game

class Object
    Object(sf::Vector2f & Position, sf::Vector2f & Size, glob::Layer Layer, CollisionBase & CollSett, EntityBase & EntitySetting, bool IsInUse = false);
    sf::Vector2f pos;
    sf::Vector2f size;
    glob::Layer layer;

    CollisionBase collSett;
    EntityBase entitySetting;

    bool isInUse;
    int myVecID;//For finding this object, comparing not actual ID

Each object has EntityBase and CollisionBase, entityBase is used for drawing, while collisionBase is used for collision and the class looks like this

class CollisionBase
    CollisionBase(bool IsColideWith = false, std::vector<Collision> & ListCollision = std::vector<Collision>{});

    bool isColideWith;
    std::vector<Collision> listCollision;

class Collision
    Collision(sf::Vector2f & PosOffset, sf::Vector2f & Size);
    sf::Vector2f posOffset;
    sf::Vector2f size;


So implementing spatial partition would mean i have references to objects in vectors that are small areas, or do i put the main data of objects in those small containers?

If i want to hold references i have a issue, each object is in vector that often resizes, meaning the reference will be invalid after resizing occurs

My question would be, how do i store references of the objects CollisionBase object, because that is all i need in the Spatial partition.


The objects are stored in this way

std::vector<Object> listObject;

Seperated world intro smaller chuncks, object occupies more the none chunk

02 July 2014 - 06:37 AM


I am doing 2d top down game, and i am storing objects as(chair, unit, tree, stone...) in a 1d vector, i used to loop all objects to seach for but, as the map grew in size and i require faster search for objects in it at this point.

For perspective, map size X = 3200pixels, map size Y = 3200pixels and has 5 layers, objects size vary from 5x5 pixels to 96x128 pixels in size, there can stacked one upon other.


What i require: I want to speed up the process when i search for a object that fits the search criteria. My solution would be to separate map intro smaller peaces and with that achieve easier search for objects.


For one scenario lets take this: A unit moves, it needs to check if position is valid, it needs to check each object if it collides with the new position unit wants to move to, it no collision found, position fine and it can reposition the unit, if collision was found no movement can be done.

I thought if i separate map intro smaller peaces i can check only the peace where unit wants to move and efficiently reducing amount of objects that it has to check collision with.


The question: What is the term called when i want to separate a big map intro smaller peaces, id like to read on the topic and educate, i have no experience in it, and i don't know the term.

Also if you want to do suggestions, fell free to do so biggrin.png.

How do multyple people write code for one project?

29 June 2014 - 02:22 PM


I am getting up with some of my friends and we want to code together, my question is, how do we actually share code?

How do i get to him what i wrote? and what he wrote to me? i never worked on a project with other person so i am wondering.

I am guessing when i change a file like Light.h i should it to him the file, he would have to replace his copy manually, but is there anything that does that automatically integrated intro ide, and how do you/companies do it?

Our choice of IDE is VS2013 express or Code::Blocks.


Function that takes unknown amount of strings, how do i vector?

02 June 2014 - 11:53 AM


I have a case as such

void func(std::vector<std::string>> VS);

And i need to call this function with vector that i initialize in the function call.

As such:

func(std::vector<std::string>{std::string("parameter1"), std::string("parameter2")});

Off course this example does not work, but it shows what i require.

The function can take from 1 to X strings passed intro it, and i do not want to pass each string separated, it needs to handle (1,2,3... 66,67...) strings.

What are workarounds? i didn't find one myself.