Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: little error in model, and also a speed-fix in Array

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/**
21   \brief creates a new Array
22*/
23Array::Array ()
24{
25  this->initializeArray ();
26}
27
28/**
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{
34  PRINTF(4)("deleting array\n");
35  Entry* walker = this->firstEntry;
36  Entry* previous;
37  while (walker)
38    {
39      previous = walker;
40      walker = walker->next;
41      delete previous;
42    }
43  if (finalized)
44    delete []this->array;
45}
46
47/**
48   \brief initializes an Array
49   the Function does this by setting up a fistEntry, and setting the entryCount.
50*/
51void Array::initializeArray ()
52{
53  PRINTF(4)("crating new Array\n");
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
59  return;
60}
61
62/**
63   \brief finalizes an array.
64   This Function creates the array, and makes it ready to be sent to the application.
65*/
66void Array::finalizeArray (void)
67{
68  PRINTF(4)("Finalizing array. Length: %i\n", entryCount); 
69  //  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
70  if (!(this->array = new GLfloat [this->entryCount]))
71    PRINTF(1)("could not allocate %i data Blocks\n", this->entryCount);
72  Entry* walker = this->firstEntry;
73  for (int i=0; i<this->entryCount; i++)
74    {
75      this->array[i] = walker->value;
76      walker = walker->next;
77    }
78  this->finalized = true;
79
80  return;
81}
82
83/**
84   \brief adds a new Entry to the Array
85   \param entry Entry to add.
86*/
87void Array::addEntry (GLfloat entry)
88{
89  if (!this->finalized)
90    {
91      PRINTF(5)("adding new Entry to Array: %f\n", entry);
92     
93      this->currentEntry->value = entry;
94      this->currentEntry->next = new Entry;
95      this->currentEntry = currentEntry->next;
96      this->currentEntry->next = NULL;
97      ++this->entryCount;
98    }
99  else 
100    PRINTF(2)("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  this->addEntry (entry0);
109  this->addEntry (entry1);
110  this->addEntry (entry2);
111}
112 
113/**
114   \brief Simple debug info about the Array
115*/
116void Array::debug (void) const
117{
118  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
119}
Note: See TracBrowser for help on using the repository browser.