Here is the main code (would be too long to show you everything):
// Check if state changed
if(Periph->state_changed){
Periph->state_changed = false;
geometry::initialization(Periph->state);
}
// First Drawing Call
geometry::drawContext(App);
// Depending on View Type
switch(Periph->state){
case VIEW_EMPTY:
geometry::drawTitle(App);
break;
case VIEW_FULLSCREEN_LIGHT:
case VIEW_LIGHT:
for(uint8_t i=0;i<NbEm;i++) // For each diode of the Bezel
for(uint8_t j=0;j<NbPd;j++) // For each group of 8 OPD ( 8 OPD per Bezel Module )
if( (Device->USBData.projection[diodeX3::whichCycle[i]][j/8]&obstacle::NumberToPd[j%8]) != 0 && pdRange::areLinked(i,j) ) geometry::addLine(i,j);
geometry::drawLine(App);
break;
case VIEW_FULLSCREEN_OBSTACLE:
case VIEW_OBSTACLE:
for(uint8_t i=0;i<NbEm;i++) // For each diode of the Bezel
for(uint8_t j=0;j<NbPd;j++) // For each OPD ( 8 OPD per Bezel Module )
if( (Device->USBData.projection[diodeX3::whichCycle[i]][j/8]&obstacle::NumberToPd[j%8]) == 0 && pdRange::areLinked(i,j) ) geometry::addLine(i,j);
geometry::drawLine(App);
break;
case VIEW_FULLSCREEN_PROCESS:
case VIEW_PROCESS:
geometry::clearPixels();
processPixels(PROCESS_MODE_AVERAGE);
geometry::drawPixels(App);
break;
default:
break;
}
// Refresh Screen
App->display();
As you can see, every thing about drawing is in a class used in static called geometry.
Here is the code for add and draw:
void geometry::addBezel(){
// Filling Screen first (order in which it's filled is really important, else it does not work properly)
ArrayQuad[4].position = sf::Vector2f(ScreenRef.x, ScreenRef.y);
ArrayQuad[5].position = sf::Vector2f(ScreenRef.x+ScreenSize.x, ScreenRef.y);
ArrayQuad[6].position = sf::Vector2f(ScreenRef.x+ScreenSize.x, ScreenRef.y+ScreenSize.y);
ArrayQuad[7].position = sf::Vector2f(ScreenRef.x, ScreenRef.y+ScreenSize.y);
for(uint8_t i=0;i<4;i++) ArrayQuad[i].color = sf::Color::White;
// Filling Bezel second
ArrayQuad[0].position = BezelRef;
ArrayQuad[1].position = sf::Vector2f(BezelRef.x+BezelSize.x,BezelRef.y);
ArrayQuad[2].position = sf::Vector2f(BezelRef.x+BezelSize.x,BezelRef.y+BezelSize.y);
ArrayQuad[3].position = sf::Vector2f(BezelRef.x,BezelRef.y+BezelSize.y);
for(uint8_t i=0;i<4;i++) ArrayQuad[i].color = sf::Color(230,216,174);
}
void geometry::addEm(){
// Processing Positions
initEm();
// Filling each emitters
for(uint8_t i=0;i<66;i++){
ArrayQuad[(2+i)*4].position = sf::Vector2f(TabEm[i].x-SIZE_EmX/2,TabEm[i].y-SIZE_EmY/2);
ArrayQuad[(2+i)*4+1].position = sf::Vector2f(TabEm[i].x+SIZE_EmX/2,TabEm[i].y-SIZE_EmY/2);
ArrayQuad[(2+i)*4+2].position = sf::Vector2f(TabEm[i].x+SIZE_EmX/2,TabEm[i].y+SIZE_EmY/2);
ArrayQuad[(2+i)*4+3].position = sf::Vector2f(TabEm[i].x-SIZE_EmX/2,TabEm[i].y+SIZE_EmY/2);
for(uint8_t j=0;j<4;j++) ArrayQuad[(2+i)*4+j].color = sf::Color::Red;
}
}
void geometry::addRcv(){
// Processing Positions
initRcv();
// Filling each recivers
for(uint8_t i=0;i<176;i++){
ArrayQuad[(2+66+i)*4].position = sf::Vector2f(TabPd[i].x-SIZE_PdX/2,TabPd[i].y-SIZE_PdY/2);
ArrayQuad[(2+66+i)*4+1].position = sf::Vector2f(TabPd[i].x+SIZE_PdX/2,TabPd[i].y-SIZE_PdY/2);
ArrayQuad[(2+66+i)*4+2].position = sf::Vector2f(TabPd[i].x+SIZE_PdX/2,TabPd[i].y+SIZE_PdY/2);
ArrayQuad[(2+66+i)*4+3].position = sf::Vector2f(TabPd[i].x-SIZE_PdX/2,TabPd[i].y+SIZE_PdY/2);
for(uint8_t j=0;j<4;j++) ArrayQuad[(2+66+i)*4+j].color = sf::Color::Blue;
}
}
void geometry::initialization(uint8_t state){
initConstants(state);
addBezel();
addEm();
addRcv();
}
// Draw Bezel, Screen, Emitters and Receivers
void geometry::drawContext(sf::RenderWindow *App){ App->draw(ArrayQuad); }
// Draw a "Welcome" Text on default view
void geometry::drawTitle(sf::RenderWindow *App){ App->draw(Title); }
// Add a line to draw in the array of Line
void geometry::addLine(uint8_t Em, uint8_t Pd){
ArrayLine.push_back(sf::Vertex(TabEm[Em],sf::Color::Blue));
ArrayLine.push_back(sf::Vertex(TabPd[Pd],sf::Color::Blue));
}
// Draw every line in the array
void geometry::drawLine(sf::RenderWindow *App){ App->draw(&ArrayLine[0], ArrayLine.size(), sf::Lines); ArrayLine.clear(); }
All above "initialization" is used only when initialization is called (so not at each loop cycle)
Let's say my view is the one i showed you last: then it's VIEW_OBSTACLE.
Meaning only things called are drawContext(App); addLine(i,j); and drawLines(App);
I insist on the fact that only geometry has been modified since I posted here; so my loss in performance can only be there.
Is the bottleneck the fact I clear & fill std::vector each loop? Should I use another structure?