Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/util/loading/factory.cc @ 5864

Last change on this file since 5864 was 5750, checked in by bensch, 19 years ago

orxonox/trunk: merged the WorldEntities into the Trunk.
Merged with command:
svn merge branches/world_entities/ trunk/ -r5516:HEAD

conflics from world_entities changed in favor of branches/world_entity
all other conflict in favor of the trunk

File size: 2.2 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, ClassID classID)
37{
38  this->setClassID(CL_FACTORY, "Factory");
39  this->setName(factoryName);
40
41  this->next = NULL;
42  this->classID = classID;
43
44  Factory::registerFactory(this);
45}
46
47/** a reference to the First Factory */
48Factory* Factory::first = NULL;
49
50/**
51 *  destructor
52
53   clear the Q
54*/
55Factory::~Factory ()
56{
57  //  printf("%s\n", this->factoryName);
58  //  Factory* tmpDel = this->next;
59  //  this->next = NULL;
60  if (this->next)
61    delete this->next;
62}
63
64/**
65 *  add a Factory to the Factory Queue
66 * @param factory a Factory to be registered
67*/
68void Factory::registerFactory( Factory* factory)
69{
70  assert( factory != NULL);
71
72  PRINTF(5)("Registered factory for '%s'\n", factory->getName());
73
74  if( Factory::first == NULL)
75  {
76    Factory::first = factory;
77  }
78  else
79  {
80    Factory* tmpFac = Factory::first;
81    while( tmpFac->next != NULL)
82    {
83      tmpFac = tmpFac->next;
84    }
85    tmpFac->setNext(factory);
86  }
87}
88
89void Factory::fabricate(const char* className, const char* entityName)
90{
91  if (className == NULL)
92    return;
93  Factory* fac = Factory::first;
94
95  while (fac != NULL)
96  {
97    if (!strcmp(className, fac->getName()))
98    {
99      PRINTF(3)("Create a new Object of type %s\n", fac->getName());
100      BaseObject* object = fac->fabricateDirect();
101      if (object != NULL)
102      {
103        object->setName(entityName);
104      }
105      break;
106    }
107    fac = fac->next;
108  }
109}
Note: See TracBrowser for help on using the repository browser.