Jump to content

Roland

Members
  • Posts

    2,953
  • Joined

  • Last visited

Posts posted by Roland

  1. Just some free thoughts on this

     

     

    If you are after most efficiency use either std::vector or simple arrays. Using std::list or std::map is not at all suited for games as iterating over them is quite slow compared to vector

     

    If possible store the objects and not pointers to them in your array in order to get contiguous memory. Iterating over any data in non-contiguous memory imposes a lot of cache misses in general and removes the ability for the compiler and CPU to do effective cache prefetching. This alone can kill performance

     

    When removing from your vector use the 'swap/pop' method. This way you keep your array contiguous

    std::swap(entitys[index], entitys());

    entitys.pop_back();

     

    This of course assumes you know the index of your object. This can be known this way

    myArray.push_back(object);

    object.index = myArray.size()-1

     

    then you removes it with

    std::swap(myArray[object.index],myArray.back());

    myArray.pop_back();

  2. I don't understand. Isn't that just telling the function to iterate through from the beginning to the end and remove all elements with the specified value?

     

    Imagine if you had a list with 1000 elements and you used remove() to remove 10 of them. (This is a pretty realistic example for a game engine.) It would be ridiculously inefficient.

    Unfortunately I have no idea how the remove work behind the scene.

  3. Yes, I do that all the time. That is the only way to quickly remove an object from a list. For example, in the Entity constructor I do this:

    world->entities.push_front(this);

    it = world.begin();

     

    And in the destructor I do this:

    world.erase(it);
    

     

    If you use list.remove(this) it has to iterate through the entire list looking for that value, which is very slow. It's amazing how many people don't know this. Look at all these people who think they are experts but don't understand the most basic concepts of data management in C++:

    http://www.blitzbasic.com/Community/posts.php?topic=93291

    Node need to have iterators dangling around

     

    world->entities.push_front(this); // or world->entities.push_back(this);
    //...
    //..
    std::remove(world->entities.begin(), world->entities.end(), this);
    
    

  4. I'm nearly through the lessons. It's actually pretty hard to separate out what the user needs to know and give it to them in a digestable format.

     

    The containers tutorial really makes the problems of C++ iterators glaringly obvious. That's the only way to do fast removal of objects from a list and they are so incredibly error-prone.

     

    Hi there Josh.

     

    First of all the interator sample has an error

     

    std::vector myvector = {"Bob", "Jane", "Fred"};
    for (auto it = myvector.begin(); it != myvector.end(); it++)
    {
    std::string element = (*it);
    Print(element);
    }
    

     

     

    should be

     

    
    std::vector<std::string> myvector = {"Bob", "Jane", "Fred"};
    for (auto it = myvector.begin(); it != myvector.end(); it++)
    {
    std::string element = (*it);
    Print(element);
    }
    

     

     

    secondly you can create the vector and iterate in a less mysterious way

    if you don't care what myvector actually is.

     

    auto myvector = { "Bob", "Jane", "Fred" };
    
    for each( auto element in myvector )
    {
     Print(element);
    }
    

     

    if you do care its

    std::vector<std::string> myvector = { "Bob", "Jane", "Fred" };
    
    for each( auto element in myvector )
    {
     Print(element);
    }
    

    • Upvote 1
  5. Shame.

     

    From memory you covered most of the topics Josh is after.

    Yep. Started with "No knowledge of C++" then covered most things. Classes, Inheritance, Polymorfism, Standard Templates and so on ending up in some Leadwerks scene samples. To bad they are lost and I have no own backup either as I bough a new pc since then and AGAIN!!! was to lazy to make a DVD backup as I had it on YouTube...

  6. Hey Roland didn't you do a youtube series on C++ in Leadwerks?

     

    I can't find it. Did you remove it?

    Yes I did. But then I switch to a new account, deleted the old one. Of course I forgot to backup them. Yes! Totally idiotic but that's what happened. About 20 videos about C++ lost sad.png Sorry about that

    • Upvote 1
  7. snapback.pngaiaf, on 17 May 2017 - 08:35 PM, said:

     

    Im interested to do this.

    I'm sure you'd do a great job of this, but since English isn't your first language it would require a lot of proof-reading on my part.

     

    Was interested but I guess there will be the same problem for me

  8. I keep on getting the error "Asset map value is different" in the Errors tab, although everything seems to work. A bit irritating as that removes focus from the Output tab when running. No errors on the Output tab when loading.

     

    Okay then I though. Lets delete the map and make a new one. Same result and its really not a complicated map. A Terrain and some boxes and spheres.

     

    I have the latest Beta.

     

    Any idea on how to get rid of this annoying thing?

  9. If have an entity in my scene with a script attached that holds some parameter, something like this

     

    Script.param = 10--int
    

     

    and then in my LUA program at some point picks that entity.

     

    Is is possible to access the script.param then (at this stage I have only the entity)

     

    I made a temporary solution for this that works by using the Get/SetKeyValue like this

     

    Script.param = 10--int
    
    function Script:Start()
    self.entity:SetKeyValue("param", self.param)
    end
    

     

    which allows me to get that param event though I only have the entity

     

    local value = entity:GetKeyValue("param")
    

     

    However this feels a bit odd. Maybe there is some better way ?

     

    Note: In C++ I could do this using my LuaBridge class, but this project is pure LUA

  10. Solved now.

    I created the camera in C++ instead of loading a camera created in the editor and then it works.

     

    auto cam = Camera::Create();
    cam->AddPostEffect("Shaders/PostEffects/02_pp_fog_by_klepto.lua");
    cam->SetKeyValue("fog_fogrange", "0,20");
    cam->SetKeyValue("fog_fogcolor", "0.57,0.53,0.55,1.0");
    cam->SetKeyValue("fog_fogangle", "5,21");
    cam->SetKeyValue("fog_fogislocal", "0");
    

    • Upvote 3
×
×
  • Create New...