Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5877 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
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*/
[5750]36Factory::Factory (const char* factoryName, ClassID classID)
[3940]37{
[4597]38  this->setClassID(CL_FACTORY, "Factory");
39  this->setName(factoryName);
40
[4739]41  this->next = NULL;
[5750]42  this->classID = classID;
[4597]43
[4739]44  Factory::registerFactory(this);
[3940]45}
46
[4739]47/** a reference to the First Factory */
[4730]48Factory* Factory::first = NULL;
49
[3940]50/**
[4836]51 *  destructor
[4597]52
[3940]53   clear the Q
54*/
55Factory::~Factory ()
56{
[4020]57  //  printf("%s\n", this->factoryName);
[4004]58  //  Factory* tmpDel = this->next;
59  //  this->next = NULL;
60  if (this->next)
61    delete this->next;
[3940]62}
63
[4487]64/**
[4836]65 *  add a Factory to the Factory Queue
66 * @param factory a Factory to be registered
[3940]67*/
[4739]68void Factory::registerFactory( Factory* factory)
[3940]69{
[4739]70  assert( factory != NULL);
[3940]71
[5298]72  PRINTF(5)("Registered factory for '%s'\n", factory->getName());
[4739]73
74  if( Factory::first == NULL)
[5155]75  {
[4739]76    Factory::first = factory;
[5155]77  }
[4739]78  else
79  {
80    Factory* tmpFac = Factory::first;
81    while( tmpFac->next != NULL)
82    {
83      tmpFac = tmpFac->next;
84    }
85    tmpFac->setNext(factory);
86  }
[3940]87}
[5155]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());
[5156]100      BaseObject* object = fac->fabricateDirect();
[5155]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.