« first day (3483 days earlier)      last day (104 days later) » 

6:00 AM
Hello everyone. Im looking for the right solution on how to remove objects properly
im having the next situation:
i have vector of 6 objects and then elements gets removed at the run time and i need to have an access to the right elements(at run time )
 
6:39 AM
and what happens instead of it?
 
I have element[0], elemnt[1], element[2], element[3].
At runtime what if some of these objects doesnt exist anymore? I need to access the right vectors(the ones that exist).
In very common order : 0, 1, 2 , 3.
Any simple idea how can i achieve that?
so my code in which iterator i equals 0 then 1 and so on no longer works if some of these elements gets destroyed at run time
 
7:12 AM
you can use a linked list carefully, or what I prefer is just marking objects as removed but actually remove them when you don't work with that vector
also you should check was the object removed or not
I have that logic only inside systems having vectors, so I don't worry about forgetting that check somewhere
 
marking them as removed? thanks i will try)
 
yes make a boolean flag indicating removal and skip that objects when iterating
and when iteration is done you should filter the entire vector
it's O(n)
 
i cant mark some element in vector just like that
need to use std::pair<std::vector, std::string> ? something like this?
 
definitely there is no need to use string
existence of the object is a part of the object
should be done like that:

class GameObject {
bool exists;
// other fields and methods
}
 
8:21 AM
@trollingchar i dont iterate through all elements at a time
 
Why not use a hash-map of game-object ID to game-object? And then just remove by key.
 
i would try it but what trollchar suggested already helped)
what i did was:
I added bool flag to object and then when i remove objects i just delete only objects and dont erase vector elements(so it still has all elements along with removed ones). And when i update my class of objects i just do the checking like if (object->getFlag()==true) object->update() . No need to set false flag since i remove objects anyway
 
So it's roughly like a pool
 
@trollingchar i actually do iterate through all objects when updating them but i dont when i access them at runtime after some event triggered. I guess i was just looking for an issue in wrong place)
 
8:37 AM
people often look in the wrong place
 
i guess i just could set removed objects to nullptr ?
is that possible?
 
how are you going to do that?
 
its not possible to set vector element to nullptr?
 
you need to know its index
v[i] = nullptr; // ok
o = nullptr; // sets local o to nullptr, vector is unaffected
i dont like the null pointer approach because boolean flag is named and explicit
if you forget why that null is here you're in trouble
 
8:54 AM
I don't like the idea of guarding everything that's relevant with a boolean, the ID handle approach suggested seems much nicer and is something I've used a lot
 
what is 'o'?
 
local variable
pointer to object
@Tyyppi_77 with a hash set?
 
a hash map yeah
 
The indirection explicitly reminds you that you need to look up the element and it's might not be there anymore. Some languages even remind you that the looked-up element might not exist in the map on a type-system level (Like in Rust, the lookup is an Option<Value>)
 
I don't see a way to iterate through it when there is a possibility of it being changed while iterating
 
9:03 AM
@trollingchar there s no way to get index from object pointer ?
 
You could also wrap the ID into something that looks like std::optional, i.e. with a has_entity() and entity() methods for testing existence and fetching the value
 
You probably need to have some remove-set that you empty at end of every frame. (Ofc. you can make it a vector, no reason to have the overhead of a set)
 
That's almost a must anyways with any kind of storage ^
 
I think we should know what you are trying to implement
I have a feeling that we solve the problem in the wrong direction
 
@trollingchar just some test. Some idea.
thanks you all for the help
 
9:08 AM
= )
 
 
4 hours later…
1:14 PM
Hi! I have a problem with webgl. I'm using vanilla webgl and I'm trying to port a Three.js code.

I want to replicate this example https://mattdesl.github.io/webgl-wireframes/app/
that does a wireframe render with barycentric coordinates.
What I want is this image:
I have a render that if the z axis is screen facing has a wrong result (some faces are white filled) while if the z axis is in the opposite direction I have the desired result
Here is a picture in the middle that clearly show a white filled face that superimposes to the wireframe
If I debug with Spector.js both drawing command (the original mattdesl.github.io/webgl-wireframes/app and my test)
has:

CULL_FACE: false
CULL_FACE_MODE: BACK
so, what can it be? anyone can give some hints?
 

« first day (3483 days earlier)      last day (104 days later) »