Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/loading/factory.cc @ 5695

Last change on this file since 5695 was 5298, checked in by bensch, 19 years ago

orxonox/trunk: output-issues

File size: 2.1 KB
RevLine 
[4597]1/*
[3940]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: Christian Meyer
[4250]13   co-programmer: Benjamin Grauer
[3940]14*/
15
16
17#include "factory.h"
[5155]18
19#include "shell_command.h"
[3940]20#include "game_loader.h"
21using namespace std;
22
[5162]23SHELL_COMMAND(create, Factory, fabricate);
24
25
[3940]26/*  --------------------------------------------------
[4597]27 *               Factory
[4003]28 *   --------------------------------------------------
29 */
[3940]30
31/**
[4836]32 *  constructor
[4597]33
[4020]34   set everything to zero and define factoryName
[3940]35*/
[4487]36Factory::Factory (const char* factoryName)
[3940]37{
[4597]38  this->setClassID(CL_FACTORY, "Factory");
39  this->setName(factoryName);
40
[4739]41  this->next = NULL;
[4597]42
[4739]43  Factory::registerFactory(this);
[3940]44}
45
[4739]46/** a reference to the First Factory */
[4730]47Factory* Factory::first = NULL;
48
[3940]49/**
[4836]50 *  destructor
[4597]51
[3940]52   clear the Q
53*/
54Factory::~Factory ()
55{
[4020]56  //  printf("%s\n", this->factoryName);
[4004]57  //  Factory* tmpDel = this->next;
58  //  this->next = NULL;
59  if (this->next)
60    delete this->next;
[3940]61}
62
[4487]63/**
[4836]64 *  add a Factory to the Factory Queue
65 * @param factory a Factory to be registered
[3940]66*/
[4739]67void Factory::registerFactory( Factory* factory)
[3940]68{
[4739]69  assert( factory != NULL);
[3940]70
[5298]71  PRINTF(5)("Registered factory for '%s'\n", factory->getName());
[4739]72
73  if( Factory::first == NULL)
[5155]74  {
[4739]75    Factory::first = factory;
[5155]76  }
[4739]77  else
78  {
79    Factory* tmpFac = Factory::first;
80    while( tmpFac->next != NULL)
81    {
82      tmpFac = tmpFac->next;
83    }
84    tmpFac->setNext(factory);
85  }
[3940]86}
[5155]87
88void Factory::fabricate(const char* className, const char* entityName)
89{
90  if (className == NULL)
91    return;
92  Factory* fac = Factory::first;
93
94  while (fac != NULL)
95  {
96    if (!strcmp(className, fac->getName()))
97    {
98      PRINTF(3)("Create a new Object of type %s\n", fac->getName());
[5156]99      BaseObject* object = fac->fabricateDirect();
[5155]100      if (object != NULL)
101      {
102        object->setName(entityName);
103      }
104      break;
105    }
106    fac = fac->next;
107  }
108}
Note: See TracBrowser for help on using the repository browser.