| [2823] | 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: Benjamin Grauer |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| [2754] | 16 | #include "array.h" |
|---|
| 17 | |
|---|
| [2842] | 18 | /** |
|---|
| 19 | \brief creates a new Array |
|---|
| 20 | */ |
|---|
| [2754] | 21 | Array::Array () |
|---|
| 22 | { |
|---|
| [2842] | 23 | initializeArray (); |
|---|
| [2754] | 24 | } |
|---|
| 25 | |
|---|
| [2842] | 26 | /** |
|---|
| 27 | \brief initializes an Array |
|---|
| 28 | the Function does this by setting up a fistEntry, and setting the entryCount. |
|---|
| 29 | */ |
|---|
| 30 | void Array::initializeArray () |
|---|
| [2754] | 31 | { |
|---|
| [2804] | 32 | if (verbose >= 2) |
|---|
| [2807] | 33 | printf ("crating new Array\n"); |
|---|
| 34 | firstEntry = new Entry; |
|---|
| 35 | firstEntry->next =NULL; |
|---|
| 36 | currentEntry=firstEntry; |
|---|
| [2809] | 37 | finalized = false; |
|---|
| [2808] | 38 | entryCount = 0; //0 means one entry |
|---|
| [2754] | 39 | return; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| [2842] | 42 | /** |
|---|
| 43 | \brief finalizes an array. |
|---|
| 44 | This Function creates the array, and makes it ready to be sent to the application. |
|---|
| 45 | */ |
|---|
| [2754] | 46 | void Array::finalizeArray (void) |
|---|
| 47 | { |
|---|
| [2804] | 48 | if (verbose >= 3) |
|---|
| 49 | printf ("Finalizing array.\n"); |
|---|
| [2807] | 50 | if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL) |
|---|
| 51 | printf ("could not allocate %i data Blocks\n", entryCount); |
|---|
| 52 | Entry* walker = firstEntry; |
|---|
| [2808] | 53 | for (int i=0; i<entryCount; i++) |
|---|
| [2807] | 54 | { |
|---|
| 55 | array[i] = walker->value; |
|---|
| 56 | walker = walker->next; |
|---|
| 57 | } |
|---|
| [2809] | 58 | finalized = true; |
|---|
| [2754] | 59 | return; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| [2842] | 62 | /** |
|---|
| 63 | \brief adds a new Entry to the Array |
|---|
| 64 | \param entry Entry to add. |
|---|
| 65 | */ |
|---|
| [2754] | 66 | void Array::addEntry (GLfloat entry) |
|---|
| 67 | { |
|---|
| [2809] | 68 | if (!finalized) |
|---|
| 69 | { |
|---|
| 70 | if (verbose >= 3) |
|---|
| 71 | printf ("adding new Entry to Array: %f\n", entry); |
|---|
| 72 | |
|---|
| 73 | entryCount++; |
|---|
| 74 | currentEntry->value = entry; |
|---|
| 75 | currentEntry->next = new Entry; |
|---|
| 76 | currentEntry = currentEntry->next; |
|---|
| 77 | currentEntry->next = NULL; |
|---|
| 78 | } |
|---|
| 79 | else |
|---|
| 80 | if (verbose >= 1) |
|---|
| 81 | printf ("adding failed, because list has been finalized\n"); |
|---|
| [2754] | 82 | } |
|---|
| 83 | |
|---|
| [2842] | 84 | /** |
|---|
| 85 | \brief Adds 3 entries at once (convenience) |
|---|
| 86 | */ |
|---|
| [2754] | 87 | void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2) |
|---|
| 88 | { |
|---|
| 89 | addEntry (entry0); |
|---|
| 90 | addEntry (entry1); |
|---|
| 91 | addEntry (entry2); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| [2842] | 94 | /** |
|---|
| 95 | \brief Gives back the array !! MUST be executed AFTER finalize. |
|---|
| 96 | \returns The created array. |
|---|
| 97 | */ |
|---|
| [2754] | 98 | GLfloat* Array::getArray () |
|---|
| 99 | { |
|---|
| 100 | return array; |
|---|
| 101 | } |
|---|
| [2758] | 102 | |
|---|
| [2842] | 103 | /** |
|---|
| 104 | \returns The Count of entries in the Array |
|---|
| 105 | */ |
|---|
| [2760] | 106 | int Array::getCount() |
|---|
| 107 | { |
|---|
| 108 | return entryCount; |
|---|
| 109 | } |
|---|
| [2758] | 110 | |
|---|
| [2842] | 111 | /** |
|---|
| 112 | \brief Simple debug info about the Array |
|---|
| 113 | */ |
|---|
| [2758] | 114 | void Array::debug () |
|---|
| 115 | { |
|---|
| [2807] | 116 | printf ("entryCount=%i, address=%p\n", entryCount, array); |
|---|
| [2758] | 117 | } |
|---|