Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/importer/array.cc @ 3094

Last change on this file since 3094 was 2860, checked in by dave, 20 years ago

orxonox/branches/dave: das level hat jetzt form angenommen, stand:nach der Convention vom Samstag….

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
[2842]18/**
19   \brief creates a new Array
20*/
[2754]21Array::Array ()
22{
[2842]23  initializeArray ();
[2754]24}
25
[2842]26/**
[2847]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    }
[2848]42  if (finalized)
43    delete [] array;
[2847]44}
45
46/**
[2842]47   \brief initializes an Array
48   the Function does this by setting up a fistEntry, and setting the entryCount.
49*/
50void Array::initializeArray ()
[2754]51{
[2804]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
[2842]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)
71    printf ("could not allocate %i data Blocks\n", entryCount);
72  Entry* walker = firstEntry;
[2808]73  for (int i=0; i<entryCount; i++)
[2807]74    {
75      array[i] = walker->value;
76      walker = walker->next;
77    }
[2809]78  finalized = true;
[2754]79  return;
80}
81
[2842]82/**
83   \brief adds a new Entry to the Array
84   \param entry Entry to add.
85*/
[2754]86void Array::addEntry (GLfloat entry)
87{
[2809]88  if (!finalized)
89    {
90      if (verbose >= 3)
91        printf ("adding new Entry to Array: %f\n", entry);
92     
93      entryCount++;
94      currentEntry->value = entry;
95      currentEntry->next = new Entry;
96      currentEntry = currentEntry->next;
97      currentEntry->next = NULL;
98    }
99  else 
100    if (verbose >= 1)
101      printf ("adding failed, because list has been finalized\n");
[2754]102}
103
[2842]104/**
105   \brief Adds 3 entries at once (convenience)
106*/
[2754]107void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
108{
109  addEntry (entry0);
110  addEntry (entry1);
111  addEntry (entry2);
112}
113 
[2842]114/**
115   \brief Gives back the array !! MUST be executed AFTER finalize.
116   \returns The created array.
117*/
[2754]118GLfloat* Array::getArray ()
119{
120  return array;
121}
[2758]122
[2842]123/**
124   \returns The Count of entries in the Array
125*/
[2760]126int Array::getCount()
127{
128  return entryCount;
129}
[2758]130
[2842]131/**
132   \brief Simple debug info about the Array
133*/
[2758]134void Array::debug ()
135{
[2807]136  printf ("entryCount=%i, address=%p\n", entryCount, array);
[2758]137}
Note: See TracBrowser for help on using the repository browser.