Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/array.cc @ 2838

Last change on this file since 2838 was 2835, checked in by bensch, 20 years ago

orxonox/trunk/src: added the files again.

File size: 1.8 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
18Array::Array ()
19{
[2807]20  createArray ();
[2754]21}
22
[2807]23void Array::createArray ()
[2754]24{
[2804]25  if (verbose >= 2)
[2807]26    printf ("crating new Array\n");
27  firstEntry = new Entry;
28  firstEntry->next =NULL;
29  currentEntry=firstEntry;
[2809]30  finalized = false;
[2808]31  entryCount = 0; //0 means one entry
[2754]32  return;
33}
34
35void Array::finalizeArray (void)
36{
[2804]37  if (verbose >= 3)
38    printf ("Finalizing array.\n"); 
[2807]39  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
40    printf ("could not allocate %i data Blocks\n", entryCount);
41  Entry* walker = firstEntry;
[2808]42  for (int i=0; i<entryCount; i++)
[2807]43    {
44      array[i] = walker->value;
45      walker = walker->next;
46    }
[2809]47  finalized = true;
[2754]48  return;
49}
50
51
52void Array::addEntry (GLfloat entry)
53{
[2809]54  if (!finalized)
55    {
56      if (verbose >= 3)
57        printf ("adding new Entry to Array: %f\n", entry);
58     
59      entryCount++;
60      currentEntry->value = entry;
61      currentEntry->next = new Entry;
62      currentEntry = currentEntry->next;
63      currentEntry->next = NULL;
64    }
65  else 
66    if (verbose >= 1)
67      printf ("adding failed, because list has been finalized\n");
[2754]68}
69
70void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
71{
72  addEntry (entry0);
73  addEntry (entry1);
74  addEntry (entry2);
75}
76 
77
78GLfloat* Array::getArray ()
79{
80  return array;
81}
[2758]82
[2760]83int Array::getCount()
84{
85  return entryCount;
86}
[2758]87
88
[2760]89
[2758]90void Array::debug ()
91{
[2807]92  printf ("entryCount=%i, address=%p\n", entryCount, array);
[2758]93}
Note: See TracBrowser for help on using the repository browser.