Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/nico/src/importer/array.cc @ 4053

Last change on this file since 4053 was 3238, checked in by bensch, 20 years ago

orxonox/branches: updated branches: buerli, nico, sound. And moved bezierTrack to old.bezierTrack. Conflicts resolved in a usefull order.
Conflics mostly resolved in favor of trunk
merge.

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