Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/importer/array.cc @ 2847

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

orxonox/trunk/importer: implemented destructors of Class Array and Class Material… working

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