Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: updated debug.h: now possibility to log per module (compile-time)

  1. write in the cc-file at the beginnig !!BEFORE ANY INCLUDES!!

#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_[MODULENAME]
where [MODULNAME] is a name of a module that can be defined in debug.h

  1. define a new MODULE: easy just write a new one under the other ones in DEBUG.h
  1. if you do not wish special loggin everything stays as is, and you do not have to worry. (then de verbose will be set from orxonox.cc: int verbose)
File size: 3.0 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 Gives back the array !! MUST be executed AFTER finalize.
115   \returns The created array.
116*/
117GLfloat* Array::getArray ()
118{
119  return this->array;
120}
121
122/**
123   \returns The Count of entries in the Array
124*/
125int Array::getCount()
126{
127  return this->entryCount;
128}
129
130/**
131   \brief Simple debug info about the Array
132*/
133void Array::debug ()
134{
135  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
136}
Note: See TracBrowser for help on using the repository browser.