public override void Execute() { bool copyBitmaps = false; for (int i = 0; i < Owner.MaxObjects; i++) { if (Owner.WorldObjects.Host[i].life > 0) { Owner.WorldObjects.Host[i].position += Owner.WorldObjects.Host[i].velocity; float2 pos = Owner.WorldObjects.Host[i].position; float size = Owner.WorldObjects.Host[i].size; if (pos.x < -1 - size || pos.x > 1 + size || pos.y < -1 - size || pos.y > 1 + size) { Owner.WorldObjects.Host[i].life = 0; } else { Owner.WorldObjects.Host[i].life--; } } if (Owner.WorldObjects.Host[i].life <= 0 && m_random.NextDouble() < CreateObjectChance) { MyWorldObject newObject = new MyWorldObject(); newObject.life = (int)(m_random.NextDouble() * MaxLife); newObject.size = (float)m_random.NextDouble() * (MaxSize - MinSize) + MinSize; newObject.position = new float2((float)m_random.NextDouble() * 2 - 1, (float)m_random.NextDouble() * 2 - 1); if (m_random.NextDouble() > StaticObjectChance) { newObject.velocity = new float2((float)m_random.NextDouble() * 2 - 1, (float)m_random.NextDouble() * 2 - 1); float velocitySize = (float)( (m_random.NextDouble() * (MaxVelocity - MinVelocity) + MinVelocity) / Math.Sqrt(newObject.velocity.x * newObject.velocity.x + newObject.velocity.y * newObject.velocity.y) ); newObject.velocity *= velocitySize; } IExample example = m_dataset.GetNext(); Array.Copy(example.Input, 0, Owner.Bitmaps.Host, i * IMG_WIDTH * IMG_WIDTH, IMG_WIDTH * IMG_WIDTH); copyBitmaps = true; CudaDeviceVariable <float> devBitmaps = Owner.Bitmaps.GetDevice(Owner); newObject.bitmap = devBitmaps.DevicePointer + (devBitmaps.TypeSize * i * IMG_WIDTH * IMG_WIDTH); Owner.WorldObjects.Host[i] = newObject; } } Owner.WorldObjects.SafeCopyToDevice(); if (copyBitmaps) { Owner.Bitmaps.SafeCopyToDevice(); } }