Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/importer/array.cc @ 4577

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

orxonox/trunk: model is now able to return the values of its vertices

File size: 2.7 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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
17
18#include "array.h"
19
20#include "debug.h"
21
22/**
23   \brief creates a new Array
24*/
25Array::Array ()
26{
27  this->initializeArray ();
28}
29
30/**
31   \brief deletes an Array.
32   It does this by first deleting all the array-entries, and then delete the array[] itself
33*/
34Array::~Array()
35{
36  PRINTF(4)("deleting array\n");
37  Entry* walker = this->firstEntry;
38  Entry* previous;
39  while (walker)
40    {
41      previous = walker;
42      walker = walker->next;
43      delete previous;
44    }
45  if (finalized)
46    delete []this->array;
47}
48
49/**
50   \brief initializes an Array
51   the Function does this by setting up a fistEntry, and setting the entryCount.
52*/
53void Array::initializeArray ()
54{
55  PRINTF(4)("crating new Array\n");
56  this->firstEntry = new Entry;
57  this->firstEntry->next =NULL;
58  this->currentEntry=firstEntry;
59  this->finalized = false;
60  this->entryCount = 0; //0 means one entry
61  return;
62}
63
64/**
65   \brief finalizes an array.
66   This Function creates the array, and makes it ready to be sent to the application.
67*/
68void Array::finalizeArray (void)
69{
70  PRINTF(4)("Finalizing array. Length: %i\n", entryCount);
71  //  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
72  if (!(this->array = new GLfloat [this->entryCount]))
73    PRINTF(1)("could not allocate %i data Blocks\n", this->entryCount);
74  Entry* walker = this->firstEntry;
75  for (int i=0; i<this->entryCount; i++)
76    {
77      this->array[i] = walker->value;
78      walker = walker->next;
79    }
80  this->finalized = true;
81
82  return;
83}
84
85/**
86   \brief adds a new Entry to the Array
87   \param entry Entry to add.
88*/
89void Array::addEntry (GLfloat entry)
90{
91  if (!this->finalized)
92    {
93      PRINTF(5)("adding new Entry to Array: %f\n", entry);
94
95      this->currentEntry->value = entry;
96      this->currentEntry->next = new Entry;
97      this->currentEntry = currentEntry->next;
98      this->currentEntry->next = NULL;
99      ++this->entryCount;
100    }
101  else
102    PRINTF(2)("adding failed, because list has been finalized\n");
103}
104
105/**
106   \brief Adds 3 entries at once (convenience)
107*/
108void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
109{
110  this->addEntry (entry0);
111  this->addEntry (entry1);
112  this->addEntry (entry2);
113}
114
115/**
116   \brief Simple debug info about the Array
117*/
118void Array::debug (void) const
119{
120  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
121}
Note: See TracBrowser for help on using the repository browser.