On Saturday, May 7, 2016 at 2:59:08 AM UTC-4, Ford Ox wrote:
>
> I want to do small simulation (similiar to games) where I have multiple 
> objects that can move and spawn at map. What is the most efficient way to 
> do that?
>

It depends on how many objects you have and the size of your grid. If you 
don't have much experience with this type of problem, I would strongly 
recommend taking whichever approach is easiest, then profiling to find the 
bottlenecks.
 

>
> I was thinking about something like this:
>
> @doc "I wont to be able to check for collision in constant time"
> map = Array{Union{all objects...}(1000000, 100000)
>
>
>
This creates a 100GB array! If your map is that big, then you need another 
approach (storing your objects in a vector for example)
 

> Is this the most efficient way?
> Also, why do I have to specify the type of map array (Union..), when I 
> will technically store there only pointers, which are all of the same size.
>

Yes, but arrays of chars (for examples) can be much more efficiently 
packed, that's why you need to specify a type.
 

> If I use Array{Any}, will it be as fast as using Union{..} ?
>

My guess is "essentially, yes", but profiling is the only source of truth. 
See the Julia performance tips. 
 

>
> Should I make map, moveable_objects_1-5 global variable, so I dont have to 
> send it as parameter every time? 
>

Globals have very poor performance in Julia at the moment, unless you can 
make them const.
 

> (That will make my code unusable when imported by somebody else right?)
>

It depends. But yes, in general, it's better practice to pass the world 
state as an argument than having it as a global.
 

> Or should I pack them inside one type (f.e. type Data)? I am used to 
> [this.](..) so this is kinda new to me.
>

Yes, that's reasonable. 

Reply via email to