Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound/src/array.cc @ 3288

Last change on this file since 3288 was 2964, checked in by bensch, 20 years ago

orxonox/branches/sound: merged Trunk back into sound. and included all headers for real into the configure.ac-script.

File size: 2.8 KB
RevLine 
[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
[2853]18/**
19   \brief creates a new Array
20*/
[2754]21Array::Array ()
22{
[2853]23  initializeArray ();
[2754]24}
25
[2853]26/**
27   \brief deletes an Array.
28   It does this by first deleting all the array-entries, and then delete the array[] itself
29*/
30Array::~Array()
[2754]31{
[2804]32  if (verbose >= 2)
[2853]33    printf("deleting array\n");
34  Entry* walker = firstEntry;
35  Entry* last;
36  while (walker != NULL)
37    {
38      last = walker;
39      walker = walker->next;
40      delete last;
41    }
42  if (finalized)
43    delete [] array;
44}
45
46/**
47   \brief initializes an Array
48   the Function does this by setting up a fistEntry, and setting the entryCount.
49*/
50void Array::initializeArray ()
51{
52  if (verbose >= 2)
[2807]53    printf ("crating new Array\n");
54  firstEntry = new Entry;
55  firstEntry->next =NULL;
56  currentEntry=firstEntry;
[2809]57  finalized = false;
[2808]58  entryCount = 0; //0 means one entry
[2754]59  return;
60}
61
[2853]62/**
63   \brief finalizes an array.
64   This Function creates the array, and makes it ready to be sent to the application.
65*/
[2754]66void Array::finalizeArray (void)
67{
[2804]68  if (verbose >= 3)
69    printf ("Finalizing array.\n"); 
[2807]70  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
[2866]71  //  if ((array = new GLfloat [entryCount]) == NULL)
[2807]72    printf ("could not allocate %i data Blocks\n", entryCount);
73  Entry* walker = firstEntry;
[2808]74  for (int i=0; i<entryCount; i++)
[2807]75    {
76      array[i] = walker->value;
77      walker = walker->next;
78    }
[2809]79  finalized = true;
[2866]80
[2754]81  return;
82}
83
[2853]84/**
85   \brief adds a new Entry to the Array
86   \param entry Entry to add.
87*/
[2754]88void Array::addEntry (GLfloat entry)
89{
[2809]90  if (!finalized)
91    {
92      if (verbose >= 3)
93        printf ("adding new Entry to Array: %f\n", entry);
94     
95      currentEntry->value = entry;
96      currentEntry->next = new Entry;
97      currentEntry = currentEntry->next;
98      currentEntry->next = NULL;
[2866]99      ++entryCount;
[2809]100    }
101  else 
102    if (verbose >= 1)
103      printf ("adding failed, because list has been finalized\n");
[2754]104}
105
[2853]106/**
107   \brief Adds 3 entries at once (convenience)
108*/
[2754]109void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
110{
111  addEntry (entry0);
112  addEntry (entry1);
113  addEntry (entry2);
114}
115 
[2853]116/**
117   \brief Gives back the array !! MUST be executed AFTER finalize.
118   \returns The created array.
119*/
[2754]120GLfloat* Array::getArray ()
121{
122  return array;
123}
[2758]124
[2853]125/**
126   \returns The Count of entries in the Array
127*/
[2760]128int Array::getCount()
129{
130  return entryCount;
131}
[2758]132
[2853]133/**
134   \brief Simple debug info about the Array
135*/
[2758]136void Array::debug ()
137{
[2807]138  printf ("entryCount=%i, address=%p\n", entryCount, array);
[2758]139}
Note: See TracBrowser for help on using the repository browser.