Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4579 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Jun 10, 2005, 2:59:14 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: array is now also a template

Location:
orxonox/trunk/src/lib/graphics/importer
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/importer/Makefile.am

    r4564 r4579  
    99                           md2Model.cc \
    1010                           material.cc \
    11                            texture.cc \
    12                            array.cc
     11                           texture.cc
    1312
    1413
  • orxonox/trunk/src/lib/graphics/importer/Makefile.in

    r4564 r4579  
    5656am_libORXimporter_a_OBJECTS = model.$(OBJEXT) objModel.$(OBJEXT) \
    5757        primitive_model.$(OBJEXT) md2Model.$(OBJEXT) \
    58         material.$(OBJEXT) texture.$(OBJEXT) array.$(OBJEXT)
     58        material.$(OBJEXT) texture.$(OBJEXT)
    5959libORXimporter_a_OBJECTS = $(am_libORXimporter_a_OBJECTS)
    6060DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
    6161depcomp = $(SHELL) $(top_srcdir)/depcomp
    6262am__depfiles_maybe = depfiles
    63 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/material.Po \
     63@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/material.Po \
    6464@AMDEP_TRUE@    ./$(DEPDIR)/md2Model.Po ./$(DEPDIR)/model.Po \
    6565@AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po \
     
    192192                           md2Model.cc \
    193193                           material.cc \
    194                            texture.cc \
    195                            array.cc
     194                           texture.cc
    196195
    197196noinst_HEADERS = abstract_model.h \
     
    253252        -rm -f *.tab.c
    254253
    255 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/array.Po@am__quote@
    256254@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
    257255@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md2Model.Po@am__quote@
  • orxonox/trunk/src/lib/graphics/importer/array.h

    r4577 r4579  
     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
    116/*!
    217  \file array.h
     
    823#ifndef _ARRAY_H
    924#define _ARRAY_H
    10 #include "glincl.h"
     25#include "debug.h"
    1126
    1227//! Array Class that handles dynamic-float arrays.
    13 class Array
     28template<class T> class Array
    1429{
    15  public:
    16   Array ();
    17   ~Array();
     30  public:
     31    Array ();
     32    ~Array();
    1833
    19   void initializeArray ();
    20   void finalizeArray (void);
    21   void addEntry (GLfloat entry);
    22   void addEntry(GLfloat entry0, GLfloat entry1, GLfloat entry2);
     34    void finalizeArray (void);
     35    void addEntry (T entry);
     36    void addEntry(T entry0, T entry1, T entry2);
    2337
    24   /** \returns The array */
    25   inline const GLfloat* getArray () const { return this->array; };
    26   /**   \returns The Count of entries in the Array*/
    27   inline int getCount(void)const { return this->entryCount; };
    28   void debug(void) const ;
    29  private:
    30   //! One entry of the Array
    31   struct Entry
    32   {
    33     GLfloat value;  //!< The value of this Entry.
    34     Entry* next;    //!< Pointer to the Next entry.
    35   };
     38    /** \returns The array */
     39    inline const T* getArray () const { return this->array; };
     40    /**   \returns The Count of entries in the Array*/
     41    inline unsigned int getCount(void)const { return this->entryCount; };
     42    void debug(void) const ;
    3643
    37   GLfloat* array;      //!< The array that will be produced when finalizing the Array.
    38   int entryCount;      //!< The count of Entries in this Array.
    39   bool finalized;      //!< If this variable is set to true, the Array can not be changed anymore. true if finalized, false else (initially).
    40   Entry* firstEntry;   //!< Pointer to the first Entry of this Array
    41   Entry* currentEntry; //!< Pointer to the current Entry of this Array. The one Entry we are working with.
     44  private:
     45    //! One entry of the Array
     46    struct Entry
     47    {
     48      T            value;          //!< The value of this Entry.
     49      Entry*       next;           //!< Pointer to the Next entry.
     50    };
     51
     52    T*            array;           //!< The array that will be produced when finalizing the Array.
     53    unsigned int  entryCount;      //!< The count of Entries in this Array.
     54    bool          finalized;       //!< If this variable is set to true, the Array can not be changed anymore. true if finalized, false else (initially).
     55    Entry*        firstEntry;      //!< Pointer to the first Entry of this Array
     56    Entry*        currentEntry;    //!< Pointer to the current Entry of this Array. The one Entry we are working with.
     57};
    4258
    4359
    44 };
     60/**
     61   \brief creates a new Array
     62*/
     63template<class T>
     64Array<T>::Array ()
     65{
     66  PRINTF(4)("crating new Array\n");
     67  this->firstEntry = new Entry;
     68  this->firstEntry->next =NULL;
     69  this->currentEntry=firstEntry;
     70  this->finalized = false;
     71  this->entryCount = 0; //0 means one entry
     72}
    4573
     74/**
     75   \brief deletes an Array.
     76   It does this by first deleting all the array-entries, and then delete the array[] itself
     77*/
     78template<class T>
     79Array<T>::~Array()
     80{
     81  PRINTF(4)("deleting array\n");
     82  Entry* walker = this->firstEntry;
     83  Entry* previous;
     84  while (walker)
     85  {
     86    previous = walker;
     87    walker = walker->next;
     88    delete previous;
     89  }
     90  if (finalized)
     91    delete []this->array;
     92}
     93
     94/**
     95   \brief finalizes an array.
     96   This Function creates the array, and makes it ready to be sent to the application.
     97*/
     98template<class T>
     99void Array<T>::finalizeArray (void)
     100{
     101  PRINTF(4)("Finalizing array. Length: %i\n", entryCount);
     102  //  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
     103  if (!(this->array = new GLfloat [this->entryCount]))
     104    PRINTF(1)("could not allocate %i data Blocks\n", this->entryCount);
     105  Entry* walker = this->firstEntry;
     106  for (int i=0; i<this->entryCount; i++)
     107  {
     108    this->array[i] = walker->value;
     109    walker = walker->next;
     110  }
     111  this->finalized = true;
     112}
     113
     114/**
     115   \brief adds a new Entry to the Array
     116   \param entry Entry to add.
     117*/
     118template<class T>
     119void Array<T>::addEntry (T entry)
     120{
     121  if (!this->finalized)
     122  {
     123    PRINTF(5)("adding new Entry to Array: %f\n", entry);
     124
     125    this->currentEntry->value = entry;
     126    this->currentEntry->next = new Entry;
     127    this->currentEntry = currentEntry->next;
     128    this->currentEntry->next = NULL;
     129    ++this->entryCount;
     130  }
     131  else
     132    PRINTF(2)("adding failed, because list has been finalized\n");
     133}
     134
     135/**
     136   \brief Adds 3 entries at once (convenience)
     137*/
     138template<class T>
     139void Array<T>::addEntry (T entry0, T entry1, T entry2)
     140{
     141  this->addEntry(entry0);
     142  this->addEntry(entry1);
     143  this->addEntry(entry2);
     144}
     145
     146/**
     147   \brief Simple debug info about the Array
     148*/
     149template<class T>
     150void Array<T>::debug (void) const
     151{
     152  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
     153}
    46154#endif
  • orxonox/trunk/src/lib/graphics/importer/model.cc

    r4577 r4579  
    148148  this->scaleFactor = 1;
    149149
    150   this->vertices = new Array();
    151   this->vTexture = new Array();
    152   this->normals = new Array();
     150  this->vertices = new Array<GLfloat>();
     151  this->vTexture = new Array<GLfloat>();
     152  this->normals = new Array<GLfloat>();
    153153
    154154  this->materialList = new tList<Material>;
     
    201201  // this creates the display List.
    202202  this->importToDisplayList();
    203 
    204203
    205204  // deletes everything we allocated.
  • orxonox/trunk/src/lib/graphics/importer/model.h

    r4577 r4579  
    1414
    1515// FORWARD DEFINITION //
    16 class Array;
    1716class Vector;
     17template<class T> class Array;
    1818template<class T> class tList;
    1919
     
    174174  unsigned int     normalCount;     //!< A modelwide Counter for the normals.
    175175  unsigned int     texCoordCount;   //!< A modelwide Counter for the texCoord.
    176   Array*           vertices;        //!< The Array that handles the Vertices.
    177   Array*           normals;         //!< The Array that handles the Normals.
    178   Array*           vTexture;        //!< The Array that handles the VertexTextureCoordinates.
     176  Array<GLfloat>*  vertices;        //!< The Array that handles the Vertices.
     177  Array<GLfloat>*  normals;         //!< The Array that handles the Normals.
     178  Array<GLfloat>*  vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    179179
    180180  ModelGroup*      firstGroup;      //!< The first of all groups.
Note: See TracChangeset for help on using the changeset viewer.