Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/src: added the files again.

File size: 1.8 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#include "array.h"
17
18Array::Array ()
19{
20  createArray ();
21}
22
23void Array::createArray ()
24{
25  if (verbose >= 2)
26    printf ("crating new Array\n");
27  firstEntry = new Entry;
28  firstEntry->next =NULL;
29  currentEntry=firstEntry;
30  finalized = false;
31  entryCount = 0; //0 means one entry
32  return;
33}
34
35void Array::finalizeArray (void)
36{
37  if (verbose >= 3)
38    printf ("Finalizing array.\n"); 
39  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
40    printf ("could not allocate %i data Blocks\n", entryCount);
41  Entry* walker = firstEntry;
42  for (int i=0; i<entryCount; i++)
43    {
44      array[i] = walker->value;
45      walker = walker->next;
46    }
47  finalized = true;
48  return;
49}
50
51
52void Array::addEntry (GLfloat entry)
53{
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");
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}
82
83int Array::getCount()
84{
85  return entryCount;
86}
87
88
89
90void Array::debug ()
91{
92  printf ("entryCount=%i, address=%p\n", entryCount, array);
93}
Note: See TracBrowser for help on using the repository browser.