Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Hm .. welchen Teil vom Code?Poste doch bitte den Code, sonst kann dir keiner helfen.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
void GI::update() { for (int i = 0; i < objectCount; i++) { if (objectBuffer[i]->animationCount > 0) { static short result; objectBuffer[i]->animationList[0]->preUpdate(&objectBuffer[i]->positionX, &objectBuffer[i]->positionY, &objectBuffer[i]->positionZ, &objectBuffer[i]->rotationX, &objectBuffer[i]->rotationY, &objectBuffer[i]->rotationZ); if ((result = objectBuffer[i]->animationList[0]->play()) == -1) continue; objectBuffer[i]->animationList[0]->postUpdate(&objectBuffer[i]->positionX, &objectBuffer[i]->positionY, &objectBuffer[i]->positionZ, &objectBuffer[i]->rotationX, &objectBuffer[i]->rotationY, &objectBuffer[i]->rotationZ); if (result == 1) { objectBuffer[i]->animationList[0]->deinitialize(); removeAnimationFromQueue(i); } } } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
bool Animation::translateRotate() { static int tick = 0;; static bool first = true; static float rotationSpeedX = 0.0F, rotationSpeedY = 0.0F, rotationSpeedZ = 0.0F; static float speedX = 0.0F, speedY = 0.0F, speedZ = 0.0F; static bool negativeX = false, negativeY = false, negativeZ = false; if (first) { first = false; tick = 0; rotationSpeedX = 0.0F; rotationSpeedY = 0.0F; rotationSpeedZ = 0.0F; speedX = 0.0F; speedY = 0.0F; speedZ = 0.0F; negativeX = false; negativeY = false; negativeZ = false; float distance = 0.0F, hypo1 = 0.0F; double hypo2 = 0.0F; float distanceX = 0.0F, distanceY = 0.0F, distanceZ = 0.0F, ticks = 0.0F; originCoordX > destCoordX ? distanceX = originCoordX - destCoordX : distanceX = destCoordX - originCoordX; originCoordY > destCoordY ? distanceY = originCoordY - destCoordY : distanceY = destCoordY - originCoordY; originCoordZ > destCoordZ ? distanceZ = originCoordZ - destCoordZ : distanceZ = destCoordZ - originCoordZ; hypo1 = (distanceX * distanceX) + (distanceY * distanceY); hypo2 = ((double)(hypo1 + (distanceZ * distanceZ))); hypo2 = sqrt(hypo2); distance = (float)hypo2; ticks = distance / speed; speedX = distanceX / ticks; speedY = distanceY / ticks; speedZ = distanceZ / ticks; if (destRotX < 0) { negativeX = true; destRotX = -destRotX; } if (destRotY < 0) { negativeY = true; destRotY = -destRotY; } if (destRotZ < 0) { negativeZ = true; destRotZ = -destRotZ; } if (destRotX != 0) rotationSpeedX = destRotX / ticks; else rotationSpeedX = 0; if (destRotY != 0) rotationSpeedY = destRotY / ticks; else rotationSpeedY = 0; if (destRotZ != 0) rotationSpeedZ = destRotZ / ticks; else rotationSpeedZ = 0; tick = (int)ticks; } if (tick > 0) { ...mathematik (variablen werden neu berechnet) tick--; return 0; } else { ...unrelevantes zeug... first = true; return 1; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#ifndef ANIMATION_H_ #define ANIMATION_H_ #include <string.h> #include <math.h> #define ANIMATION_TRANSLATESMOOTH 1 #define ANIMATION_ROTATESMOOTH 2 #define ANIMATION_TRANSLATEROTATE 3 class Animation { public: Animation(); Animation(const Animation& other); ~Animation(); float originCoordX, originCoordY, originCoordZ; float destCoordX, destCoordY, destCoordZ; float finalCoordX, finalCoordY, finalCoordZ; float originRotX, originRotY, originRotZ; float destRotX, destRotY, destRotZ; float finalRotX, finalRotY, finalRotZ; float angle, radius; float speed; int type; //FUNCTIONS int play(); void setUnused(); void preUpdate(float *originPositionX, float *originPositionY, float *originPositionZ, float *originRotationX, float *originRotationY, float *originRotationZ); void postUpdate(float *newPositionX, float *newPositionY, float *newPositionZ, float *newRotationX, float *newRotationY, float *newRotationZ); void deinitialize(); bool translateSmooth(); bool rotateSmooth(); bool translateRotate(); private: }; #endif |
Danke für deine schnelle Antwort.Du hast es selbst schon gesagt. Die Variable darf nicht static sein. Normalerweise sind Variablen in einer Klasse einer bestimmten Instanz zugeordnet. Das bedeutet wenn du eine Klasse mit einer nicht statischen Variable hast und zwei verschiedene Instanzen der Klasse anlegst, dann hat jede Instanz ihre eigene Version der Variable. Innerhalb der verschiedenen Instanz können die Variablen unterschiedliche Werte speichern.
Eine statische Variable ist nicht einer Instanz einer Klasse zugeordnet sondern der Klasse selbst. Legst du zwei Instanzen deiner Klasse an und änderst in der einen den Wert der Variable so wird der Wert in allen Instanzen der Klasse geändert. Die Instanzen teilen sich quasi die selbe Variable.
Für dein Problem bedeutet das also dass du die Variable nicht statisch machen darfst. Mit Performance hat das auch wenig zu tun. Bei einer nicht statischen Variable besitzt eben jede Instanz ihre eigene Version der Variable. Dadurch verbraucht dein Programm dann etwas mehr Speicher. static ist allgemein ein Schlüsselwort was du vermutlich relativ selten benötigen wirst. Als ich angefangen habe kannte ich static gar nicht und habe es auch lange nicht vermisst. Aber static hat natürlich seine Berechtigung und wird auch immer mal wieder benötigt, bzw kann dir Code vereinfachen. In deinem Fall ist es aber falsch.
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Wo auch immer Du das gelernt hast, es ist falsch.Ich habe zu Zeiten gelernt, dass eine static Variable nicht im RAM sondern auf der Festplatte angelegt wird.
Autovariablen haben local scope und werden nach verlassen ihres scopes gelöscht.Wo auch immer Du das gelernt hast, es ist falsch.Ich habe zu Zeiten gelernt, dass eine static Variable nicht im RAM sondern auf der Festplatte angelegt wird.
Static heißt lediglich, dass alle Instanzen einer Klasse sich diese Variable teilen, weil es eine Klassen-Variable und keine Instanz-Variable ist. Mit der Festplatte hat das nichts zu tun und das wäre auch ganz übel, weil Zugriffe auf die Festplatte um etwa den Faktor 10.000 langsamer sind als Zugriffe auf den RAM. Neu zugeordnet wird da übrigens auch nichts "pro Tick".
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige