Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/array.cc @ 3454

Last change on this file since 3454 was 3206, checked in by bensch, 19 years ago

orxonox/trunk: new PRINTF() implemented in Material and Array

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