Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/old.bezierTrack/importer/array.cc @ 3256

Last change on this file since 3256 was 2863, checked in by bensch, 20 years ago

orxonox/trunk/importer: now imports more than 3 different objects, but there is an error with the groupname, this will be resolved. also added toDo (do not inject into trunksvn add toDo )

File size: 2.8 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  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  if (verbose >= 2)
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)
53    printf ("crating new Array\n");
54  firstEntry = new Entry;
55  firstEntry->next =NULL;
56  currentEntry=firstEntry;
57  finalized = false;
58  entryCount = 0; //0 means one entry
59  return;
60}
61
62/**
63   \brief finalizes an array.
64   This Function creates the array, and makes it ready to be sent to the application.
65*/
66void Array::finalizeArray (void)
67{
68  if (verbose >= 3)
69    printf ("Finalizing array.\n"); 
70  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
71  //  if ((array = new GLfloat [entryCount]) == NULL)
72    printf ("could not allocate %i data Blocks\n", entryCount);
73  Entry* walker = firstEntry;
74  for (int i=0; i<entryCount; i++)
75    {
76      array[i] = walker->value;
77      walker = walker->next;
78    }
79  finalized = true;
80
81  return;
82}
83
84/**
85   \brief adds a new Entry to the Array
86   \param entry Entry to add.
87*/
88void Array::addEntry (GLfloat entry)
89{
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;
99      ++entryCount;
100    }
101  else 
102    if (verbose >= 1)
103      printf ("adding failed, because list has been finalized\n");
104}
105
106/**
107   \brief Adds 3 entries at once (convenience)
108*/
109void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
110{
111  addEntry (entry0);
112  addEntry (entry1);
113  addEntry (entry2);
114}
115 
116/**
117   \brief Gives back the array !! MUST be executed AFTER finalize.
118   \returns The created array.
119*/
120GLfloat* Array::getArray ()
121{
122  return array;
123}
124
125/**
126   \returns The Count of entries in the Array
127*/
128int Array::getCount()
129{
130  return entryCount;
131}
132
133/**
134   \brief Simple debug info about the Array
135*/
136void Array::debug ()
137{
138  printf ("entryCount=%i, address=%p\n", entryCount, array);
139}
Note: See TracBrowser for help on using the repository browser.