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 | |
---|
16 | #include "array.h" |
---|
17 | |
---|
18 | /** |
---|
19 | \brief creates a new Array |
---|
20 | */ |
---|
21 | Array::Array () |
---|
22 | { |
---|
23 | initializeArray (); |
---|
24 | } |
---|
25 | |
---|
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 () |
---|
31 | { |
---|
32 | if (verbose >= 2) |
---|
33 | printf ("crating new Array\n"); |
---|
34 | firstEntry = new Entry; |
---|
35 | firstEntry->next =NULL; |
---|
36 | currentEntry=firstEntry; |
---|
37 | finalized = false; |
---|
38 | entryCount = 0; //0 means one entry |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | \brief finalizes an array. |
---|
44 | This Function creates the array, and makes it ready to be sent to the application. |
---|
45 | */ |
---|
46 | void Array::finalizeArray (void) |
---|
47 | { |
---|
48 | if (verbose >= 3) |
---|
49 | printf ("Finalizing array.\n"); |
---|
50 | if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL) |
---|
51 | printf ("could not allocate %i data Blocks\n", entryCount); |
---|
52 | Entry* walker = firstEntry; |
---|
53 | for (int i=0; i<entryCount; i++) |
---|
54 | { |
---|
55 | array[i] = walker->value; |
---|
56 | walker = walker->next; |
---|
57 | } |
---|
58 | finalized = true; |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | \brief adds a new Entry to the Array |
---|
64 | \param entry Entry to add. |
---|
65 | */ |
---|
66 | void Array::addEntry (GLfloat entry) |
---|
67 | { |
---|
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"); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | \brief Adds 3 entries at once (convenience) |
---|
86 | */ |
---|
87 | void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2) |
---|
88 | { |
---|
89 | addEntry (entry0); |
---|
90 | addEntry (entry1); |
---|
91 | addEntry (entry2); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | \brief Gives back the array !! MUST be executed AFTER finalize. |
---|
96 | \returns The created array. |
---|
97 | */ |
---|
98 | GLfloat* Array::getArray () |
---|
99 | { |
---|
100 | return array; |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | \returns The Count of entries in the Array |
---|
105 | */ |
---|
106 | int Array::getCount() |
---|
107 | { |
---|
108 | return entryCount; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | \brief Simple debug info about the Array |
---|
113 | */ |
---|
114 | void Array::debug () |
---|
115 | { |
---|
116 | printf ("entryCount=%i, address=%p\n", entryCount, array); |
---|
117 | } |
---|