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
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
Klassen template <class T> struct STListEntry { T* Object; char* pcObjectPath; char* pcAddInf1; char* pcAddInf2; inline STListEntry() {Object = NULL; pcObjectPath = NULL, pcAddInf1 = NULL, pcAddInf2 = NULL;} inline ~STListEntry() {delete Object; delete[] pcObjectPath; delete[] pcAddInf1; delete[] pcAddInf2;} }; template <class T> class TMemoryManager { private: static STListEntry<T>** pObjectList; static int iObjectCount; protected: static T* GetListMember(char* pcObjectPath = NULL, char* pcAddInf1 = NULL, char* pcAddInf2 = NULL) { //Sind die ZusatzInfos identisch, bzw egal (== NULL) //Die Liste durchgehen for (int i = 0; i < iObjectCount; i++) //Angabe ist egal if ((pcObjectPath == NULL || //oder nicht egal, Information existiert und ist identisch (pObjectList[i]->pcObjectPath != NULL && strcmp(pObjectList[i]->pcObjectPath, pcObjectPath) == 0)) && //Angabe ist egal (pcAddInf1 == NULL || //oder nicht egal, Information existiert und ist identisch (pObjectList[i]->pcAddInf1 != NULL && strcmp(pObjectList[i]->pcAddInf1, pcAddInf1) == 0)) && //Angabe ist egal (pcAddInf2 == NULL || //oder nicht egal, Information existiert und ist identisch (pObjectList[i]->pcAddInf2 != NULL && strcmp(pObjectList[i]->pcAddInf2, pcAddInf2) == 0))) //dann gefundenes Objekt zurückgeben return pObjectList[i]->Object; //ansonsten kein Objekt übereinstimmend: return NULL; } public: static void InsertEntry(T* Object, char* pcObjectPath = NULL, char* pcAddInf1 = NULL, char* pcAddInf2 = NULL) { iObjectCount++; pObjectList = (STListEntry<T>**)tbMemReAlloc(pObjectList, iObjectCount*sizeof(STListEntry<T>*)); pObjectList[iObjectCount-1] = new STListEntry<T>; pObjectList[iObjectCount-1]->Object = Object; //Zuweisen der Strings: if (pcObjectPath != NULL) { pObjectList[iObjectCount-1]->pcObjectPath = new char[255]; strcpy(pObjectList[iObjectCount-1]->pcObjectPath, pcObjectPath); } if (pcAddInf1 != NULL) { pObjectList[iObjectCount-1]->pcAddInf1 = new char[255]; strcpy(pObjectList[iObjectCount-1]->pcAddInf1, pcAddInf1); } if (pcAddInf2 != NULL) { pObjectList[iObjectCount-1]->pcAddInf2 = new char[255]; strcpy(pObjectList[iObjectCount-1]->pcAddInf2, pcAddInf2); } } //Setzt vorraus, dass die chars zugewiesenen Speicher haben, im Normalfall char* = new char[255] static void GetChars(T* Object, char* pcObjectPath = NULL, char* pcAddInf1 = NULL, char* pcAddInf2 = NULL) { for (int i = 0; i < iObjectCount; i++) if (Object == pObjectList[i]->Object) { if (pcObjectPath != NULL && pObjectList[i]->pcObjectPath != NULL) strcpy(pcObjectPath, pObjectList[i]->pcObjectPath); if (pcAddInf1 != NULL && pObjectList[i]->pcAddInf1 != NULL) strcpy(pcAddInf1, pObjectList[i]->pcAddInf1); if (pcAddInf2 != NULL && pObjectList[i]->pcAddInf2 != NULL) strcpy(pcAddInf2, pObjectList[i]->pcAddInf2); break; } } static void Release() { tbMemFree(pObjectList); } }; template <class T> int TMemoryManager<T>::iObjectCount = 0; template <class T> STListEntry<T>** TMemoryManager<T>::pObjectList = NULL; //******************************************************* class CEffectManager : public TMemoryManager<tbEffect> { public: static tbEffect* GetEntry(char* pcEffectPath = NULL, char* pcAddInf1 = NULL, char* pcAddInf2 = NULL) { tbEffect* Effect = GetListMember(pcEffectPath, pcAddInf1, pcAddInf2); if (Effect == NULL) { Effect = new tbEffect; Effect->Init(pcEffectPath); InsertEntry(Effect, pcEffectPath, pcAddInf1, pcAddInf2); } return Effect; } }; class CModelManager : public TMemoryManager<tbModel> { public: static tbModel* GetEntry(char* pcModelPath = NULL, char* pcTexPrefix = NULL, char* pcTexPostfix = NULL) { tbModel* Model = GetListMember(pcModelPath, pcTexPrefix, pcTexPostfix); if (Model == NULL) { Model = new tbModel; Model->Init(pcModelPath, pcTexPrefix, pcTexPostfix); InsertEntry(Model, pcModelPath, pcTexPrefix, pcTexPostfix); } return Model; } }; class CFontManager : public TMemoryManager<tbFont> { public: static tbFont* GetEntry(char* pcTGAPath = NULL, char* pcTBFPath = NULL, char* pcAddInf2 = NULL, bool bAlwaysCreateNew = false) { tbFont* Font = NULL; if (!bAlwaysCreateNew) Font = GetListMember(pcTGAPath, pcTBFPath, pcAddInf2); if (Font == NULL) { Font = new tbFont; Font->Init(pcTGAPath, pcTBFPath); InsertEntry(Font, pcTGAPath, pcTBFPath, pcAddInf2); } return Font; } }; |
Anonymous
unregistriert
Zitat von »"www.germangamedev.de"«
C-/C++-Quelltext
1 if (surfaces_.find (fileName) == surfaces_.end())
C-/C++-Quelltext |
|
1 |
if(surfaces_.end()->first == fileName) |
ich danke trotzdem für die müheZitat von »"Spik)evil("«
Also im Klartext: Ich kann dir nicht helfen, aber ich biete ne Alternative an
Zitat von »"Lemming"«
@nix da
Zitat von »"www.germangamedev.de"«
C-/C++-Quelltext
1 if (surfaces_.find (fileName) == surfaces_.end())
auf die idee hätt ich auch kommen können. Das einzige, was man dabei noch beachten muss is, dass der eintrag den man sucht ja tatsächlich der letzte sein könnte... aber damit sollts gehenoder?
C-/C++-Quelltext
1 if(surfaces_.end()->first == fileName)
Zitat von »"helium"«
end() verweist aber nicht auf das letzte Element!!!!!!!! (nein, meine Tastatur klemmt nicht)
Anonymous
unregistriert
Is der Grund dafür dein persönlicher Geschmack, oder zieht das ganze ernste Nachteile mit sich?Zitat von »"nix da"«
Lemming
Typedefs? niemals Lieber lang und eindeutig als ein ugly typedef oder using namespace!
Anonymous
unregistriert
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 |
namespace math { namespace std { template<typename T> vector { public: vector (void) {} ~vector (void) {} T value; }; } } #include <vector> using namespace math; using namespace std; int main (void) { vector<unsigned long> test; // Welcher vector wird benutzt? return 0; } |
Werbeanzeige