Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: output-issues

File size: 2.1 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: Christian Meyer
13   co-programmer: Benjamin Grauer
14*/
15
16
17#include "factory.h"
18
19#include "shell_command.h"
20#include "game_loader.h"
21using namespace std;
22
23SHELL_COMMAND(create, Factory, fabricate);
24
25
26/*  --------------------------------------------------
27 *               Factory
28 *   --------------------------------------------------
29 */
30
31/**
32 *  constructor
33
34   set everything to zero and define factoryName
35*/
36Factory::Factory (const char* factoryName)
37{
38  this->setClassID(CL_FACTORY, "Factory");
39  this->setName(factoryName);
40
41  this->next = NULL;
42
43  Factory::registerFactory(this);
44}
45
46/** a reference to the First Factory */
47Factory* Factory::first = NULL;
48
49/**
50 *  destructor
51
52   clear the Q
53*/
54Factory::~Factory ()
55{
56  //  printf("%s\n", this->factoryName);
57  //  Factory* tmpDel = this->next;
58  //  this->next = NULL;
59  if (this->next)
60    delete this->next;
61}
62
63/**
64 *  add a Factory to the Factory Queue
65 * @param factory a Factory to be registered
66*/
67void Factory::registerFactory( Factory* factory)
68{
69  assert( factory != NULL);
70
71  PRINTF(5)("Registered factory for '%s'\n", factory->getName());
72
73  if( Factory::first == NULL)
74  {
75    Factory::first = factory;
76  }
77  else
78  {
79    Factory* tmpFac = Factory::first;
80    while( tmpFac->next != NULL)
81    {
82      tmpFac = tmpFac->next;
83    }
84    tmpFac->setNext(factory);
85  }
86}
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());
99      BaseObject* object = fac->fabricateDirect();
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.