Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/openAL/src/lib/graphics/importer/array.cc @ 4194

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

orxonox/branches/openAL: merged trunk back to openAL
merged with command:

svn merge ../trunk/ openAL/ -r 3920:HEAD

no conflicts at all

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