# Open Source iOS Library For Creating Customizable Stylish Notifications Atop Your App

by Johann at December 10, 2013 07:27 AM

I’ve mentioned a number of libraries for creating alerts that display atop of your app underneath the app bar with customizable styling such as TSMessages.

Here’s a library called MessageBarManager from Terry Worona for presenting alerts in a stylish manner with some great customization options and a manager with some handy features.

With MessageBarManager you can customize the coloring used by the alert, the icon displayed within the alert, duration, create callbacks to handle taps on the alert, queue up multiple alerts and more.

Here’s a set of images from the readme showing the MessageBarManager in action:

You can find MessageBarManager on Github here.

A nice library for presenting alerts.

Be the first to comment...

# Open Source iOS Component For Creating Interesting Customizable Circular Sliders

by Johann at December 09, 2013 11:11 PM

The slider is one of those common controls that you see customized all over the place, and previously I mentioned a tutorial on how to extend UIControl to create a custom slider.

Here’s a component from Eliot Fowler that allows you to make total unique circular sliders called EFCircularSlider.

This is an interesting component, and the sliders are highly customizable you can easily change the coloring, draw labels, have the slider snap on each label and more.

Here’s an image from the readme showing a custom dual slider from the included example app:

You can find EFCircularSlider on Github here.

A nice customized slider component.

Be the first to comment...

# LibGDX Tutorial 3B: Simple Animation

by Mike@gamefromscratch.com at December 09, 2013 10:59 PM

Back in Tutorial 3 I created a simple animation using a Timer and setting the frame manually from a TextureAtlas.  This is not the ideal way to perform animation using LibGDX and was done to illustrate how to use a TextureAtlas, not how to perform animation.  Instead the better way to perform animations is using the Animation class.  Here is an example using the same spritesheet from tutorial 3, remember you need to add it to the Android project assets folder.

package com.gamefromscratch;

public class AnimationDemo implements ApplicationListener {
private SpriteBatch batch;
private TextureAtlas textureAtlas;
private Animation animation;
private float elapsedTime = 0;

@Override
public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("data/spritesheet.atlas"));
animation = new Animation(1/15f, textureAtlas.getRegions());
}

@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}

@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

batch.begin();
//sprite.draw(batch);
elapsedTime += Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);
batch.end();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}
}

When you run it, you should see:

The key here is the Animation, created here:

animation = new Animation(1/15f, textureAtlas.getRegions());

When creating an animation you pass in the amount of time per frame ( 15 frames per second in this case ) and an array of TextureRegions.  These represent the individual frames of animation within the TextureAtlas.  In this particular example we are simply using all of the frames available within the Atlas as a single animation.  The next key change is:

elapsedTime += Gdx.graphics.getDeltaTime();

batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);

Here we are simply drawing the current frame from the animation to the screen.  We pass in the amount of time that has elapsed so the animation knows where it is in the sequence.  The true parameter is telling it to loop the animation.

Of course, you can have multiple animations from a single texture Atlas.  Consider the spritesheet we are currently working with.  If you take a look at the .atlas file, you will see each individual frame is named:

Looking at the spritesheet, you will see the animations are organized like such:

What we want to do is treat this as two sepeate animations.  Frames 1 through 10 represent an upward roll, while 11-20 are a downward roll.  Let’s take a look at how we do that:

public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("data/spritesheet.atlas"));

TextureRegion[] rotateUpFrames = new TextureRegion[10];

// Rotate Up Animation
// Create an array of TextureRegions
rotateUpFrames[0] = (textureAtlas.findRegion("0001"));
rotateUpFrames[1] = (textureAtlas.findRegion("0002"));
rotateUpFrames[2] = (textureAtlas.findRegion("0003"));
rotateUpFrames[3] = (textureAtlas.findRegion("0004"));
rotateUpFrames[4] = (textureAtlas.findRegion("0005"));
rotateUpFrames[5] = (textureAtlas.findRegion("0006"));
rotateUpFrames[6] = (textureAtlas.findRegion("0007"));
rotateUpFrames[7] = (textureAtlas.findRegion("0008"));
rotateUpFrames[8] = (textureAtlas.findRegion("0009"));
rotateUpFrames[9] = (textureAtlas.findRegion("0010"));

rotateUpAnimation = new Animation(0.1f,rotateUpFrames);

// Rotate Down Animation
// Or you can just pass in all of the regions to the Animation constructor
rotateDownAnimation = new Animation(0.1f,
(textureAtlas.findRegion("0011")),
(textureAtlas.findRegion("0012")),
(textureAtlas.findRegion("0013")),
(textureAtlas.findRegion("0014")),
(textureAtlas.findRegion("0015")),
(textureAtlas.findRegion("0016")),
(textureAtlas.findRegion("0017")),
(textureAtlas.findRegion("0018")),
(textureAtlas.findRegion("0019")),
(textureAtlas.findRegion("0020")));

Gdx.input.setInputProcessor(this);
}

As you can see, it’s easy to create multiple animations from a single TextureAtlas.  Keep in mind, when creating a TextureAtlas using TexturePacker, it was the filename that you passed in that created the region names.  So what you would generally do is name your separate animations accordingly, such as WalkLeft, WalkRight, etc.

# (WebGL) Mozilla and Goo team up for a holiday competition

December 09, 2013 09:22 PM

Quote
Unleash The Game Creator in You By Entering Our Holiday Gaming Competition

Can you create an even more enticing inter...

# LibGDX Tutorial 9: Scene2D Part 2– Actions

by Mike@gamefromscratch.com at December 09, 2013 08:12 PM

In the second part of the LibGDX Scene2D tutorial we will now look at Actions.  Actions are a convenient ( and completely optional! ) way to get your game’s Actors to “do stuff”.

Let’s jump straight in to an example:

package com.gamefromscratch;

public class SceneDemo3 implements ApplicationListener {

public class MyActor extends Actor {
Texture texture = new Texture(Gdx.files.internal("data/jet.png"));
public boolean started = false;

public MyActor(){
setBounds(getX(),getY(),texture.getWidth(),texture.getHeight());
}

@Override
public void draw(Batch batch, float alpha){
batch.draw(texture,this.getX(),getY());
}
}
private Stage stage;

@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);

MyActor myActor = new MyActor();

MoveToAction moveAction = new MoveToAction();
moveAction.setPosition(300f, 0f);
moveAction.setDuration(10f);

}

@Override
public void dispose() {
}

@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}
}

When you run this example, it will slowly move the jet until it is at the position 300,0.

Much of this code is recycled from the previous Scene2D example, so we will only discuss the new portions, which reside in the create() function:

@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);

MyActor myActor = new MyActor();

MoveToAction moveAction = new MoveToAction();
moveAction.setPosition(300f, 0f);
moveAction.setDuration(10f);

}

Here we create a MoveToAction, which moves the attached Actor to a given position over time.  You set the position to move to with the method setPosition() and the total duration of the action using setDuration().  You assign the action to the Actor using addAction().  All actions are derived from the Action class, while MoveToAction is derived from TemporalAction, which is an action that has a duration.  In addition to MoveToAction, there are a number of others such as MoveByAction, ScaleToAction, ColorAction, DelayAction, RepeatAction, RotateByAction, etc.

There is one important thing to be aware of here.  Back in part one of the Scene2D tutorial our custom Actor MyActor overrode the act method.  It is the act() method of Actor that updates all of the Actions connected to an Actor.  Therefore if you create your own Actor class, be sure to call it’s parent’s act() or call each attached Action manually like so:

@Override
public void act(float delta){
for(Iterator<Action> iter = this.getActions().iterator(); iter.hasNext();){
iter.next().act(delta);
}
}

If you run more than one actions like so:

MoveToAction moveAction = new MoveToAction();
RotateToAction rotateAction = new RotateToAction();
ScaleToAction scaleAction = new ScaleToAction();

moveAction.setPosition(300f, 0f);
moveAction.setDuration(5f);
rotateAction.setRotation(90f);
rotateAction.setDuration(5f);
scaleAction.setScale(0.5f);
scaleAction.setDuration(5f);

You will see:

As you can see, all of your actions run concurrently by default.

There is one important thing to be aware of.  The draw() method in MyActor we’ve been using until this point is not capable of displaying rotation or scaling by default.  If you wish to enabled scaled/rotated drawing like above, you need to make a minor adjustment to draw(), like so:

@Override
public void draw(Batch batch, float alpha){
batch.draw(texture,this.getX(),getY(),this.getOriginX(),this.getOriginY(),this.getWidth(),
this.getHeight(),this.getScaleX(), this.getScaleY(),this.getRotation(),0,0,
texture.getWidth(),texture.getHeight(),false,false);
}

Obviously there are going to be many times when you want to delay an action, or run them in sequence.  Fortunately LibGdx supports exactly this.  Say you wanted to scale then rotate then move your Actor, you can accomplish this using a SequenceAction like so:

final MyActor myActor = new MyActor();

SequenceAction sequenceAction = new SequenceAction();

MoveToAction moveAction = new MoveToAction();
RotateToAction rotateAction = new RotateToAction();
ScaleToAction scaleAction = new ScaleToAction();

moveAction.setPosition(300f, 0f);
moveAction.setDuration(5f);
rotateAction.setRotation(90f);
rotateAction.setDuration(5f);
scaleAction.setScale(0.5f);
scaleAction.setDuration(5f);

Simply add all the actors to the SequenceAction, then one will run, followed by the next then the next.

By statically importing Actions, like so:

You can also chain actions, so it’s possible to express the above action like:

Or run in parallel, like so:

There are several other actions, such as Int or FloatAction, that allow you to modify a value over time, DelayAction for running an action, um, after a delay, RepeatAction, for performing an Action over and over.  However, they all follow the same basic layout, so you should be able to figure them out easily at this point.  One last thing to point out, all Actions are poolable.  This means you can keep a pool of actions instead of allocating them over and over.  Here is one such example of a Pool of MoveToActions:

final MyActor myActor = new MyActor();
Pool<MoveToAction> actionPool = new Pool<MoveToAction>(){
protected MoveToAction newObject(){
return new MoveToAction();
}
};

MoveToAction moveAction = actionPool.obtain();
moveAction.setDuration(5f);
moveAction.setPosition(300f, 0);

You can also have an action simply be code.  Consider the above example, let’s say you wanted to log when the MoveToAction was complete.  You could accomplish this by doing the following:

run(new Runnable(){
@Override
public void run() {
Gdx.app.log("STATUS", "Action complete");
}

})));

A Runnable action simply runs the code specified in the run method when, um, run. That’s about it for Actions.  On their own they are pretty simply, but can easily be chained to create very complex interactions.

# Intel Graphics Performance Analyzers news

December 09, 2013 05:30 PM

# Intel SDK for OpenCL Applications XE 2013 R2 adds Windows support

December 09, 2013 05:23 PM

Quote
The Intel® SDK for OpenCL* Applications XE 2013 R2 includes certified OpenCL 1.2 support for Intel® Xeon® processors and Intel® Xeon Phi™ coprocessors for Linux* operating s...

# Next-gen Snowdrop Engine showcased in new Tom Clancy's The Division trailer

December 09, 2013 04:58 PM

Quote
Massive Entertainment's new engine brings realistic lighting and more to Xbox One and PS4 open world shooter

Ubiso...

# No Man's Sky Trailer

by Timothy Lottes (noreply@blogger.com) at December 09, 2013 10:28 AM

# Efficient Vectors of Vectors

by Thomas Young at December 09, 2013 07:29 AM

(Also posted to upcoder.com.)

STL style vectors are convenient because they hide the details of internal buffer management, and present a simplified interface, but sometimes convenience can be a trap!

In my previous post I touched briefly on STL vectors with non-simple element types, and mentioned the ‘vector of vectors’ construct in particular as a specific source of memory woes.

In this post I’ll talk about this construct in more detail, explain a bit about why there is an issue, and go on to suggest a fairly straightforward alternative for many situations.

## Interview question

One of my standard interview questions for c++ programmers has been:

What can be done to optimize the following class?

#include <vector>

class cLookup
{
std::vector<std::vector<long> > _v;
public:

{
_v.push_back(entries);
return _v.size() - 1;
}

long getNumberOfEntriesInLine(long lineIndex) const
{
return _v[lineIndex].size();
}
long getEntryInLine(long lineIndex, long indexInLine) const
{
return _v[lineIndex][indexInLine];
}
};

(Index type issues ignored for simplicity.)

Note that the question intentionally doesn’t tell you what needs to be optimised. I guess I ideally want applicants to then either:

1. ask what should be optimised, or
2. immediately spot what is ‘wrong’ with the code (and go on to make some suggestions for improvement)

It’s generally a good first reflex in any optimisation situation to try to find out some more about exactly what’s going on (whether by profiling, or measuring statistics, or even just looking at how a piece of code is used), and (perhaps more fundamentally), what needs to be optimised, and so asking for more information is probably a good initial response to pretty much any optimisation question.

But the vector of vectors in the above code such an expensive and inefficient construct that if you’ve ever done something like this in the wild, or come across similar constructs during optimisations, then it should really stand out as a red flag, and I don’t think it’s unreasonable to just assume that this is what the question is asking about.

## The problem

The class methods can be divided into a ‘lookup building’ part, which might only be used at preprocess or loading time, and a non-mutating ‘query’ part.

In real life we should usually be motivated and directed by some kind of performance measure, and there are then two issues potentially resulting from that vector of vectors, with our performance measures ideally telling us which (or both) of these issues we actually need to focus on:

• inefficiencies during construction, or
• run-time memory footprint

### Lookup construction

The construction part has the potential to be horribly inefficient, depending on the compilation environment.

It’s all about what the top level vector does with the contained objects when increasing buffer capacity, and, more specifically, whether or not C++11 ‘move semantics’ are being applied.

To increase buffer capacity, vectors allocate a new block of memory and then move the contents of the existing buffer across. Before C++11 move semantics the move part actually requires copy construction of elements in the new buffer from elements in the old buffer and then destruction of the old elements, but with C++11 move semantics this copy and destroy can be avoided.

We can see this in action with the following test code:

#include <vector>
#include <iostream>

int i = 0;

class cSideEffector
{
int _i;
public:
cSideEffector()
{
_i = i++;
std::cout << "element " << _i << " constructed\n";
}
cSideEffector(const cSideEffector& rhs)
{
_i = i++;
std::cout << "element " << _i << " copy constructed (from element " << rhs._i << ")\n";
}
~cSideEffector()
{
std::cout << "element " << _i << " destroyed\n";
}
};

int
main(int argc, char* argv[])
{
std::vector<std::vector<cSideEffector> > v;
v.resize(4);
v[0].resize(1);
v[1].resize(1);
v[2].resize(1);
v[3].resize(1);
std::cout << "before resize(5), v.capacity() = " << v.capacity() << '\n';
v.resize(5);
return 0;
}

Building this with Clang 3.0, without the -std=c++0x option, I get:

element 0 constructed
element 1 copy constructed (from element 0)
element 0 destroyed
element 2 constructed
element 3 copy constructed (from element 2)
element 2 destroyed
element 4 constructed
element 5 copy constructed (from element 4)
element 4 destroyed
element 6 constructed
element 7 copy constructed (from element 6)
element 6 destroyed
before resize(5), v.capacity() = 4
element 8 copy constructed (from element 1)
element 9 copy constructed (from element 3)
element 10 copy constructed (from element 5)
element 11 copy constructed (from element 7)
element 1 destroyed
element 3 destroyed
element 5 destroyed
element 7 destroyed
element 8 destroyed
element 9 destroyed
element 10 destroyed
element 11 destroyed

But if I add the -std=c++0x option (enabling C++11 move semantics), I get:

element 0 constructed
element 1 constructed
element 2 constructed
element 3 constructed
before resize(5), v.capacity() = 4
element 0 destroyed
element 1 destroyed
element 2 destroyed
element 3 destroyed

So we can see first of all that without move semantics enabled each buffer reallocation triggers copy and delete for all the existing elements. And then we can see that this is something that this is something that can potentially be resolved by turning on support for move semantics.

Note that this copy and delete usually won’t be an issue for basic types (where copy can be just a memory copy, and delete a null operation), but if the vector elements have their own internal buffer management (as is the case with vectors of vectors) then this results in a whole lot of essentially unnecessary memory heap operations, which be both a significant performance hit and bad news for memory fragmentation.

Move semantics can be pretty cool if you can depend on the necessary compiler support, and you can then find a load of stuff on the web discussing this in more detail (e.g. here or here).

At PathEngine, however, we need to support clients building the SDK on a bunch older compilers, and if there is some way to implement stuff like this lookup class without all this overhead regardless of whether C++11 move semantics are actually available then we definitely want to do this, and the lookup construction stage remains an optimisation target!

### It’s all about the runtime

Actually, in practice we would never want to do something like cLookup::addLine() during loading. Something like this would normally only be called at preprocess generation time, with the possibility to store the resulting preprocess data to persistent files and load back in at runtime with much more direct data paths.

(In reality there would be some other stuff to support this in that cLookup class, this is a simplified example and doesn’t give the whole picture.)

And then, while we obviously want to avoid all those memory ops during preprocess generation, the real issue here is probably the implications of the vector of vector construct on the SDK run-time, and particular on run-time memory footprint.

It turns out that vectors of vectors are also very bad news for your system memory heap.
For something like PathEngine this is *worse* than the potential construction inefficiencies from unnecessary copying,
and this is an issue *whether or not* C++11 move semantics are being applied.

### Memory footprint

From the point of view of memory footprint there are two main problems here:

1. The fact that separate buffer allocations are made per entry in _table, and
2. Operating system and vector class memory overhead for each of those allocations

The situation will look something like this:

One buffer gets allocated at the top level, by _v, and filled in with the sub vector class data, and a bunch of other buffers then also get allocated by these sub vectors.

Note that each vector has four data members, a buffer pointer, a current size value (or end pointer), a current capactity (or end pointer), and a pointer to an allocator object. It’s most common to see STL containers without allocation customisation, and so it can be a surprise to see the allocator pointer. When allocator customisation is not being used the allocator pointers all be set to zero, but nevertheless get stored once per lookup line, and help to bulk out the memory overhead.

If each of the four vector data members is a 32 bit value then this gives us a starting cost of 16 bytes per line in the lookup, most of which is not really necessary in this case.

And allocating an individual buffer for each line is also a bad thing because allocating a lot of buffers will lead to memory fragmentation, and because there is a non-negligeable amount of built in hidden overhead per system memory allocation. Each individual buffer allocated from the system will require additional data related to tracking the buffer in the system memory allocation heap, and will also most likely be aligned to some fixed value by the system (so with memory buffer lengths actually being extended to a multiple of that fixed value).

As a result, for a lookup object created with short lines, the memory overhead for each line can easily exceed the amount of actual data being stored.

And we should also be aware of the possibility of vector overallocation.

In the code shown, the subvectors probably shouldn’t be overallocated because they are copy constructed from existing vectors (although I haven’t researched the ‘official’ situation for this in the standard!), but the top level vector will be overallocated (by a factor of 1.5, on average, as discussed in my previous post), and in the general case of vector of vector construction overallocation may not just mean buffers being larger than necessary, but also potentially that more buffers are allocated than actually needed.

In practice, in loading code, we set things up so that vectors get loaded without any overallocation, but it can be worth checking that this is definitely working as expected.

With or without overallocation it’s clear that there are some significant memory footprint and fragmentation issues, and these kinds of memory issues are then also usually performance issues, because of the need to keep memory caches working effectively, and because of heap management costs!

## Collapsed vector vector

The key point, for this use case, is that we actually only ever need to add data to the end of the lookup, and so we just don’t need all that separate dynamic state tracking for each individual line.

And the solution is then to ‘collapse’ all those individual line buffers into a single buffer, giving us just one single buffer containing all the lookup entries concatenated together in order.

Since the lookup lines are not all the same length we also need some way to find the lookup entries for each line, and so we use a second buffer which indexes into the concatenated entries for this purpose.

The index buffer tells us exactly where each line starts in the concatenated entries buffer.

Note that we give the index buffer one entry per lookup line, plus one additional entry which points to the end of the concatenated entries. (This extra index entry enables us to treat all the lookup lines in the same way, and avoids an explicit test for first or last line.)

We could add code for this directly into the cLookup class fairly easily, but this is something we’re bound to come across with regards other data structures, and we should set things up to make it as easy as possible for us to avoid the vector of vectors construct, so why not create a new container class for this purpose, which can be used to replace vectors of vectors more generally?

### Data members

We need to maintain a couple of dynamically resized buffers (with increasing size), and std::vector is actually just the thing for that (!), so we can start out with something like:

#include <vector>

template <class T>
class cCollapsedVectorVector
{
typedef typename std::vector<T>::size_type size_type;
std::vector<T> _v;
std::vector<std::size_type> _index;
public:

//... implementation here
};

These vector members save us re-implementing a bunch of low-level buffer management stuff, whilst still resolving all the major issues we had with the vector of vectors construct.

We want to make it easy to replace vector of vectors with this new class, so lets copy the std::vector interface as far as reasonably possible.

We’ll add things like a size_type typedef and basic STL style vector methods like size() and empty(), and try to make common element access code for vectors work with the new class.

We could also provide the same interface for the actual push_back operation (i.e. taking a subvector to be concatenated), but I’ve chosen to diverge from that interface to make it clear in the calling code that something a bit different is going on at construction time.

I’ve also avoided trying to do anything that might require proxy objects or iterator classes in order to keep things simple. The final class can then look something like this:

#include <vector>
#include <cassert>

template <class T>
class cCollapsedVectorVector
{
public:
typedef typename std::vector<T>::size_type size_type;
private:
std::vector<T> _v;
std::vector<size_type> _index;

public:

cCollapsedVectorVector() :
_index(1)
{
_index[0] = 0;
}
cCollapsedVectorVector(const std::vector<std::vector<T> >& buildFrom) :
_index(buildFrom.size() + 1)
{
_index.clear();
_index.push_back(0);
for(size_type i = 0; i != buildFrom.size(); ++i)
{
_index.push_back(_index.back() + buildFrom[i].size());
}
_v.resize(_index.back());
size_type vIndex = 0;
for(size_type i = 0; i != buildFrom.size(); ++i)
{
for(size_type j = 0; j != subVectorSize(i); ++j)
{
_v[vIndex++] = buildFrom[i][j];
}
}
assertD(vIndex == SizeL(_v));
}

void
shrinkToFit()
{
if(_v.capacity() != _v.size())
{
std::vector<T>(_v).swap(_v);
}
if(_index.capacity() != _index.size())
{
std::vector<size_type>(_index).swap(_index);
}
}

bool operator==(const cCollapsedVectorVector& rhs) const
{
return _index == rhs._index && _v == rhs._v;
}

void swap(cCollapsedVectorVector& rhs)
{
_v.swap(rhs._v);
_index.swap(rhs._index);
}

bool empty() const
{
return _index.size() == 1;
}
void clear()
{
_index.resize(1);
_v.clear();
}

void pushBackSubVector()
{
_index.push_back(_index.back());
}
void pushBackSubVector(size_type size)
{
_index.push_back(_index.back() + size);
_v.resize(_v.size() + size);
}
void pushBackInLastSubVector(const T& value)
{
assert(!empty());
_index.back()++;
_v.push_back(value);
}
void popBackInLastSubVector()
{
assert(!empty());
assert(subVectorSize(size() - 1) > 0);
_index.back()--;
_v.pop_back();
}

size_type size() const
{
return _index.size() - 1;
}
const T* operator[](size_type i) const
{
return &_v[_index[i]];
}
T* operator[](size_type i)
{
return &_v[_index[i]];
}

const T* back() const
{
assert(!empty());
return &_v[_index[_index.size() - 2]];
}
T* back()
{
assert(!empty());
return &_v[_index[_index.size() - 2]];
}

size_type subVectorSize(size_type i) const
{
return _index[i + 1] - _index[i];
}
};

## Application

In cases where we only need to add to the end of the data structure (as in the case of cLookup), we can build to this new class directly, but in cases where this is not possible we could also fall back to using a vector of vectors at build or preprocess time, with this then baked into a cCollapsedVectorVector using the relevant constructor.

Anyway, now we can rewrite the lookup class as follows:

class cLookup
{
cCollapsedVectorVector<long> _v;

public:

{
_v.pushBackSubVector(entries.size());
for(std::vector<long>::size_type i = 0; i != entries.size(); ++i)
{
_v.back()[i] = entries[i];
}
return _v.size() - 1;
}
void shrinkToFit()
{
_v.shrinkToFit();
}

long getNumberOfEntriesInLine(long lineIndex) const
{
return _v.subVectorSize(lineIndex);
}
long getEntryInLine(long lineIndex, long indexInLine) const
{
return _v[lineIndex][indexInLine];
}
};

Note the addition of a shrinkToFit() method, which can be called when the calling code has finished adding lines, to avoid overallocation.

## Conclusion

Vectors of vectors should be avoided if possible, and if data is only ever added at the end if the top level vector this is easy to achieve.

This is an example of an optimisation which should be applied pre-emptively, I think, because of the performance and memory footprint implications.

If you have vectors of vectors in your code, take a look at this right now and see if they can be replaced with something like cCollapsedVectorVector!

# Top iOS Development Resources For Week Ended December 8th, 2013

by Johann at December 09, 2013 07:00 AM

Welcome back to our feature of the most popular new and updated resources mentioned on the site in the last week.

This weeks top resource is a library enabling you to create animated progress bars with full color and size customization and more.

Here are the resources:

1.  LDProgressView – An open source component providing great looking customizable progress bars.  (share on twitter) (featured here)

2. Canvas – A library providing animations that can be implemented without code in Xcode’s Storyboard tool. (share on twitter) (featured here)

3.  PulsingHalo – An open source component allowing you to create a customizable effect for illustrating  map annotations and beacons. (share on twitter) (featured here)

4. MDRadialProgress – An open source component allowing you to creating highly customizable circular progress views. (share on twitter) (featured here)

Be the first to comment...

Original article: Top iOS Development Resources For Week Ended December 8th, 2013

# Waiting For Horus Beta 14

by Timothy Lottes (noreply@blogger.com) at December 08, 2013 08:47 PM

# Hunting Anubis

by Timothy Lottes (noreply@blogger.com) at December 08, 2013 08:39 PM

# Enhance this!

Don't you hate when people have strong critiques towards a thing, but it happens that it's just that they don't know enough about it? Well, I don't, because then I think of how many times in my youth (and let's say only then) I did the same...

Regardless, today I happen to have a bit of time and I saw yet another post laughing at how stupid the "image enhance" trick used in movies and TV series is, and so you get this nerdrage against nerdrage...

Now think a second about this. Who do you think it's right? C.S.I., which is a huge TV series using arguably some of the best writers and consultants, or the random dude on the net? Do you think they don't know how realistic any of the techniques they use is? Do you think they don't actually and very carefully thread between real science and fiction to deliver a mix that is comprehensible and entertains their audience, telling a story while keeping it grounded in actual techniques used in the field? Don't you think -they- know better, and the result was very consciously constructed?

The same goes of course for anything, really, especially when something is successful, makes a lot of money, has a lot of money behind, you should always bias yourself towards being humble and assuming the professionals making said thing -know better-.

Now, back to the "image enhance" trick. It turns out it is real science. It's called "super-resolution" and it's a deep field with a lot (really, a lot!) of research and techniques behind it.
It's actually common nowadays as well, chances are that if your TV has some sort of SD2HD conversion, well that is super-resolution in action (and even more surprising are all the techniques that can reconstruct depth from a single image, which also ship in many TVs, the kind of models they came up with for that are crazy!).

The scenarios presented in movies are actually -quite- realistic even if the details are fictionalized. True, the interface to these programs won't look like that, maybe they won't be real-time and surely they won't be able to "zoom" in "hundreds" of times, but they surely can help and surely are used.

That is to me a reasonable compromise between fiction and reality, as certainly you can and will use computers to get a legible nameplate for a video that is too low-resolution for the naked eye, or match an otherwise unreadable face against a database of suspects and so on, probably not in quite as glamorous and simple way as the movies show, but fundamentally the idea is sound (and I'm quite sure, used in the real world).
It is a non-realistic representation of a very realistic scenario, which is the best that good fiction should try to achieve, going further is silly. Or are you going to argue that a movie is crap because at night for example you can't really see as clearly as they show, or because they don't let a DNA test take weeks and an investigation several years?

When it comes to videos we can use techniques known as "multiple image" super-resolution, registering (aligning) multiple images (frames in this case, i.e. optical flow), and merging the results, which do work quite well. Also, most fictionalized super-resolution enhances focus on faces or nameplates, which are both much easier to super-resolve because we can "hint" the algorithm with a statistical model (a-priori) which helps tremendously to guide the "hallucination".
And even if hallucinating detail might not hold in a court (the stronger the a-priori model, the more it will generate plausible results but by no means always reliable), it might be very well be used as a hint to direct the investigations (I've never seen a case where it was used in courts, always to try to identify a potential suspect or a nameplate, both cases where having a strong probability, even if it's far from certainty, are realistic).

So, bottom line is, if you think these guys are "stuuuuupid", well then you might want to think twice. Here are some random-ish links (starting points... google scholar for references and so on if you're interested... I couldn't even find many of my favorite ones right now) to the science of super-resolution:
It would take many pages only to survey the general ideas in the field. Don't limit your imagination... Computer science is more amazing than you might think... We can capture light in flight, we can read somebody's heartbeat from video, fucking use lasers to see around corners and yes, even take some hints about an environment from corneas...

And by the way, don't bitch about Gravity, try enjoy the narrative instead. You might live a happier life :)

# Arauna 2 path tracer demo

December 08, 2013 02:18 PM

Quote
Arauna2 demo released (ompf2.com)

Hi all,

I posted a demo of the new Arauna2 renderer on ompf2.com: http://ompf2.com/viewtopic.php?f=5&t=1887

A youtube of the demo can be found he...

# fgiesen

by fgiesen at December 08, 2013 12:48 AM

As a general rule, when trying to understand or prove something, symmetry is a big help. If something has obvious symmetries, or can be brought into a symmetric form, doing so is usually worth trying. One example of this is my old post on index determination for DXT5/BC3 alpha blocks. But a while ago I ran into something that makes for a really nice example: consider the expression

$|a + b| + |a - b|$

If these were regular parentheses, this would simply evaluate to $2a$, but we’re taking absolute values here, so it’s a bit more complicated than that. However, the expression does look pretty symmetric, so let’s see if we can do something with that. Name and conquer, so let’s define:

$f(a,b) := |a + b| + |a - b|$

This expression looks fairly symmetric in a and b, so what happens if we switch the two?

$f(b,a) = |b + a| + |b - a| = |a + b| + |-(a - b)| = \\ |a + b| + |a - b| = f(a,b)$

So it’s indeed symmetric in the two arguments. Another candidate to check is sign flips – we’re taking absolute values here, so we might find something interesting there as well:

$f(a,-b) = |a + (-b)| + |a - (-b)| = |a - b| + |a + b| = f(a,b)$

And because we already know that f is symmetric in its arguments, this gives us $f(-a,b) = f(a,b)$ for free – bonus! Putting all these together, we now know that

$f(a,b) = f(b,a) = f(|a|,|b|) = | |a| + |b| | + | |a| - |b| |$

which isn’t earth-shattering but not obvious either. You could prove this directly from the original expression, but I like doing it this way (defining a function f and poking at it) because it’s much easier to see what’s going on.

But we’re not quite done yet: One final thing you can do with absolute values is figure out what needs to happen for the expression to be non-negative and see if you can simplify it further. Now, both $|a|$ and $|b|$ are always non-negative, so in fact we have

$f(a,b) = |a| + |b| + | |a| - |b| |$.

Now suppose that $|a| \ge |b|$. In that case, we know the sign of the expression on the right and can simplify further:

$f(a,b) = |a| + |b| + (|a| - |b|) = 2 |a|$

and similarly, when $|b| \ge |a|$, we get $f(a,b) = 2 |b|$. Putting the two together, we arrive at the conclusion

$|a + b| + |a - b| = f(a,b) = 2 \max(|a|,|b|)$

which I think is fairly cute. (This expression comes up in SATD computations and can be used to save some work in the final step.)

# Destiny Gameplay Trailer

by Timothy Lottes (noreply@blogger.com) at December 07, 2013 07:55 PM

# The Division : Snowdrop Engine Showcase

by Timothy Lottes (noreply@blogger.com) at December 07, 2013 07:50 PM

# Open Source iOS Component For Creating Customizable Circular Progress Views

by Johann at December 07, 2013 07:21 AM

I’ve mentioned a number of controls for making circular progress views such as DACircularProgress.

Here’s another library for creating radial progress views called MDRadialProgress from Marco Dinacci that adds a number of nice features.

With MDRadialProgress you can draw clockwise or anti-clockwise, add a label indicating progress, customize the look of the progress view, draw progress in separated slices, and more.

Here’s an image from the readme showing some of the things you can do with MDRadialProgress:

You can find MDRadialProgress on Github here.

A nice circular progress view component.

Be the first to comment...

# Xcode Plugin Allowing You To Markup Links And Images Within Code And Console Output

by Johann at December 07, 2013 01:10 AM

I’ve mentioned a number of Xcode Plugins such as the Xcode Colors plugin that allows you to colorize text shown in the console for easier debugging.

Here’s a plugin from Michael Krause that builds upon the Xcode Colors plugin adding a custom markup for images and hyperlinks that works both within source code, and within the console. You can also adjust the size of the zoom level of your image within the markup.

Here’s an image from the readme showing both images and links displayed within the Xcode console by XCAddedMarkup:

You can find XCAddedMarkup on Github here.

A nice plugin for making your code explanations, and console output more useful.

Be the first to comment...

# NVIDIA GeForce driver 334.35 XP32 with PhysX System Software 9.13.0927

December 06, 2013 04:22 PM

PhysX System Software 9.13.0927 can be used by anyone though

[img]http://farm8.staticflickr...

# iOS Component For Creating A Pulsing Animation Great For Map Annotations And Beacons

by Johann at December 06, 2013 03:31 PM

A few months ago I mentioned a handy library that makes it easy to create custom colored map annotation pins.  Using this library you might want to add in some custom colored pulses to match the look of your pins.

Here’s a component from shu223 that allows you to create a nice animation pulse that is great for indication an iBeacon or annotation in MapKit called Pulsing Halo.

You can customize the size of the effect, and the color.

Here’s an image from the readme showing PulsingHalo’s animation in action:

You can find PulsingHalo on Github here.

A nice  animation effect.

Be the first to comment...