Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/importer/array.cc @ 3178

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

orxonox/trunk: merged branches/images back into the trunk.
merged with command: svn merge bensches/images/ trunk/ -r 3084:HEAD

Conflicts in configure/.ac

resolved in favor of branches/images (newer)

Mayor differences:

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