dynamic list

Started by
3 comments, last by Khatharr 7 years, 9 months ago

Hi

I want to create a dynamical moving list like in an aircraft for failures. So anything critical in red should go on top, other moving down one. Non critical, yellow go in the middle and warnings in white below. I want to create a texture for each failure and set it active or not. When active inserting depending the color.

First thoughts are alike:

typedef struct {
int active;

int type; // 1=integer 2=float 3=int array 4=float array 5=two ints 6=two floats
// 7=two array ints 8=two array floats
int index; // index into array
char label[100]; //dataref
int color; // 1=white 2=green 3=yellow 4=blue 5=red 6=cyan
char text[100]; //texturefilename
} FAILURES;

int mListe ()
{
std::list<int> mylist (2,100); // two ints with a value of 100
mylist.push_front (200);
mylist.push_front (300);

std::cout << "mylist contains:";
for (std::list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)

//need to display textures here
std::cout << ' ' << *it;

std::cout << '\n';
return 0;
}

So basically how to write the mListe function.

- push/pop textures from Failures

- display, move up/down

Image display is something alike:

glPushMatrix();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
XPLMBindTexture2d(textures[MAUS2_TEXTURE].texIMGID, 0);
glColor3f(1, 1, 1);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2f(x-25, y+25); //top left corner
glTexCoord2i(0, 1);
glVertex2i(x+25, y+25); //top right corner
glTexCoord2i(1, 1);
glVertex2i(x+25, y-25); //bottom right corner
glTexCoord2i(1, 0);
glVertex2i(x-25, y-25); //bottom left corner
glEnd();
glPopMatrix();

so y height should change dynamically.

Many thanks for any feedback.

Advertisement

Sounds like you just need to sort that list (based on warning severity). Are the elements in the list likely to change over time? For example, can a yellow warning eventually become a red warning? If not then it should be sufficient to simply insert new warnings in the correct location, keeping the list sorted at all times.

If warnings can change over time then you will have to resort the list whenever anything changes but no more than once per frame (you can use a dirty flag to do that). It's so rare that I have to sort anything now that I don't feel confident giving you the best method of doing it but there are some options in <algorithm>, std::sort that will work with a list.

Once your list is sorted it should be simple to display, just display each element in turn, incrementing the y value as you go.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

I would think you want to keep your data in a priority_queue and just traverse the queue in order on each render pass?

Stephen M. Webb
Professional Free Software Developer

Apart from changing from on to off I see for now no need they would change. Critical is always critical etc. Maybe later in a checklist this might change. So first critical, then advisory later warning etc. probably sorting with the class color.

For now I wonder how to push the class into list:

typedef struct {
int active; // 0=not 1=load once 2=refresh often
int type; // 1=integer 2=float 3=int array 4=float array 5=two ints 6=two floats
int index; // index into array
char label[100];
int color; // 1=white 2=green 3=yellow 4=blue 5=red 6=cyan
char text[100];
char next[100];
float min;
float empty;
float nom;
float full;
float max;
float scale;
XPLMDataRef dataref; // load ref pointer at first update; set NULL until then
char data[200];
XPLMCommandRef functionref; // load ref pointer at first update; set NULL until then
char function[200];
float nom2;
XPLMDataRef dataref2; // load ref pointer at first update; set NULL until then
char data2[200];
float scale2;
} Ausfaelle;


Ausfaelle Ausfaelle_Line[]={
{ 1, 2, 0, "OUTSID", 1, " EXTERNAL CHECKS PAGE 3", "" ,0, 0, 1, 2, 2, 1,NULL, "sim/cockpit2/annunciators/passenger_oxy_on", NULL, "", 0, NULL, "", 1 },
{ 1, 22, 0, "", 2, "..SERVICE.ACCESS.DOORS.......OPEN", "" , 0, 0.5, 1, 1, 2, 1,NULL, "sim/cockpit2/ice/ice_surface_boot_on", NULL, "", 1, NULL, "", 1 },
{ 1, 2, 0, "", 3, "..HYDRAULIC.OIL..................", "" , 0, 0, 1, 2, 2, 1,NULL, "sim/cockpit2/annunciators/autopilot_disconnect", NULL, "", 0, NULL, "", 1 },
};


int mListe ()
{
std::vector<int> bar;
std::list<int>::iterator it;
// int foo[] = {10,20,30,40,50};
Ausfaelle_Line *it = new Ausfaelle;

// iterate foo: inserting into bar
for (auto it = std::begin(Ausfaelle_Line); it!=std::end(Ausfaelle_Line); ++it)
bar.push_back(*it);

return 0;
}

Many thanks

You don't need to keep the objects themselves sorted; you only need to sort their order in the display. I also thought of a priority_queue, but that doesn't support iteration. Maybe if you used it on a set of pairs with pointers and priority levels and just rebuilt it and emptied it on each frame. It uses vector for internal storage by default, so if you re-use the container it should cut down on the allocation cost.

Than again, maybe a 'bucket' approach would be better here. Instead of storing each item's priority (color) as a member of the object, just have a vector for each priority level. Place the objects in the vector that matches their priority and then just iterate the vectors in the order you want.

Would that work?

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement