Optimisation setNewText
This commit is contained in:
parent
a2fb0a4719
commit
e59d6c22a5
@ -30,19 +30,32 @@ public class Text {
|
||||
|
||||
private void addCharListInEngine(){
|
||||
int i = 0;
|
||||
for (ObjectGl c : this.charList){
|
||||
c.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
|
||||
this.engine.add_objectGl(c);
|
||||
for (ObjectGl obj : this.charList){
|
||||
addCharInEngine(i, obj);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void addCharInEngine(int i, ObjectGl obj){
|
||||
obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
|
||||
this.engine.add_objectGl(obj);
|
||||
}
|
||||
|
||||
public void setNewText(String text){
|
||||
// TODO NE PAS REGENERER L'OBJECTGL DE ZERO A CHAQUE FOIS
|
||||
this.remove();
|
||||
this.charList = new ArrayList<>();
|
||||
textToArrayObjectGl(text);
|
||||
this.addCharListInEngine();
|
||||
int i = 0;
|
||||
for (ObjectGl obj : this.charList) {
|
||||
ObjectGlSetCharWrap(text.charAt(i), obj);
|
||||
i++;
|
||||
if (i >= text.length()) break;
|
||||
}
|
||||
while (i < text.length()){
|
||||
ObjectGl obj = this.charToObjectGl(text.charAt(i));
|
||||
this.charList.add(obj);
|
||||
addCharInEngine(i, obj);
|
||||
i++;
|
||||
}
|
||||
if (i < this.charList.size()) removeFromIndexToEnd(i);
|
||||
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
@ -51,19 +64,32 @@ public class Text {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromIndexToEnd(int i){
|
||||
int j = 0;
|
||||
for (ObjectGl objectGl : this.charList){
|
||||
if (j >= i) this.engine.remove_objectGl(objectGl);
|
||||
j++;
|
||||
}
|
||||
this.charList = this.charList.subList(0, i);
|
||||
}
|
||||
|
||||
private ObjectGl charToObjectGl(char a){
|
||||
ObjectGl objectGl = new ObjectGl(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null);
|
||||
objectGl.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/TextFrag.glsl");
|
||||
if (a < 132 && a > 96){
|
||||
objectGl.setTextureWrap(0.0f + (a - 97) * 10.0f,40.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
else if (a < 91 && a > 64){
|
||||
objectGl.setTextureWrap(0.0f + (a - 65) * 10.0f,30.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
else if (a < 64 && a > 31){
|
||||
objectGl.setTextureWrap(0.0f + (a - 32) * 10.0f,0.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
ObjectGlSetCharWrap(a, objectGl);
|
||||
return objectGl;
|
||||
}
|
||||
|
||||
private void ObjectGlSetCharWrap(char a, ObjectGl obj){
|
||||
if (a < 132 && a > 96){
|
||||
obj.setTextureWrap(0.0f + (a - 97) * 10.0f,40.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
else if (a < 91 && a > 64){
|
||||
obj.setTextureWrap(0.0f + (a - 65) * 10.0f,30.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
else if (a < 64 && a > 31){
|
||||
obj.setTextureWrap(0.0f + (a - 32) * 10.0f,0.0f,10.0f,10.0f, ObjectGl.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user