Last change
on this file since 2810 was
2810,
checked in by bensch, 20 years ago
|
orxonox/branches/importer: merged the new importer into the source
|
File size:
1.4 KB
|
Rev | Line | |
---|
[2754] | 1 | #include "array.h" |
---|
| 2 | |
---|
| 3 | Array::Array () |
---|
| 4 | { |
---|
[2810] | 5 | createArray (); |
---|
[2754] | 6 | } |
---|
| 7 | |
---|
[2810] | 8 | void Array::createArray () |
---|
[2754] | 9 | { |
---|
[2810] | 10 | if (verbose >= 2) |
---|
| 11 | printf ("crating new Array\n"); |
---|
| 12 | firstEntry = new Entry; |
---|
| 13 | firstEntry->next =NULL; |
---|
| 14 | currentEntry=firstEntry; |
---|
| 15 | finalized = false; |
---|
| 16 | entryCount = 0; //0 means one entry |
---|
[2754] | 17 | return; |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | void Array::finalizeArray (void) |
---|
| 21 | { |
---|
[2810] | 22 | if (verbose >= 3) |
---|
| 23 | printf ("Finalizing array.\n"); |
---|
| 24 | if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL) |
---|
| 25 | printf ("could not allocate %i data Blocks\n", entryCount); |
---|
| 26 | Entry* walker = firstEntry; |
---|
| 27 | for (int i=0; i<entryCount; i++) |
---|
| 28 | { |
---|
| 29 | array[i] = walker->value; |
---|
| 30 | walker = walker->next; |
---|
| 31 | } |
---|
| 32 | finalized = true; |
---|
[2754] | 33 | return; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | void Array::addEntry (GLfloat entry) |
---|
| 38 | { |
---|
[2810] | 39 | if (!finalized) |
---|
| 40 | { |
---|
| 41 | if (verbose >= 3) |
---|
| 42 | printf ("adding new Entry to Array: %f\n", entry); |
---|
| 43 | |
---|
| 44 | entryCount++; |
---|
| 45 | currentEntry->value = entry; |
---|
| 46 | currentEntry->next = new Entry; |
---|
| 47 | currentEntry = currentEntry->next; |
---|
| 48 | currentEntry->next = NULL; |
---|
| 49 | } |
---|
| 50 | else |
---|
| 51 | if (verbose >= 1) |
---|
| 52 | printf ("adding failed, because list has been finalized\n"); |
---|
[2754] | 53 | } |
---|
| 54 | |
---|
| 55 | void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2) |
---|
| 56 | { |
---|
| 57 | addEntry (entry0); |
---|
| 58 | addEntry (entry1); |
---|
| 59 | addEntry (entry2); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | GLfloat* Array::getArray () |
---|
| 64 | { |
---|
| 65 | return array; |
---|
| 66 | } |
---|
[2758] | 67 | |
---|
[2760] | 68 | int Array::getCount() |
---|
| 69 | { |
---|
| 70 | return entryCount; |
---|
| 71 | } |
---|
[2758] | 72 | |
---|
| 73 | |
---|
[2760] | 74 | |
---|
[2758] | 75 | void Array::debug () |
---|
| 76 | { |
---|
[2810] | 77 | printf ("entryCount=%i, address=%p\n", entryCount, array); |
---|
[2758] | 78 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.