2016-06-23 16:50:55 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "rwbase.h"
|
|
|
|
#include "rwerror.h"
|
|
|
|
#include "rwplg.h"
|
|
|
|
#include "rwpipeline.h"
|
|
|
|
#include "rwobjects.h"
|
|
|
|
#include "rwengine.h"
|
|
|
|
|
2017-08-24 15:10:34 +02:00
|
|
|
#define PLUGIN_ID ID_WORLD
|
2016-06-23 16:50:55 +02:00
|
|
|
|
|
|
|
namespace rw {
|
|
|
|
|
2020-04-17 14:34:37 +02:00
|
|
|
int32 World::numAllocated = 0;
|
|
|
|
|
2017-08-10 14:43:52 +02:00
|
|
|
PluginList World::s_plglist = { sizeof(World), sizeof(World), nil, nil };
|
|
|
|
|
2016-06-23 16:50:55 +02:00
|
|
|
World*
|
|
|
|
World::create(void)
|
|
|
|
{
|
2017-08-24 15:10:34 +02:00
|
|
|
World *world = (World*)rwMalloc(s_plglist.size, MEMDUR_EVENT | ID_WORLD);
|
2016-06-23 16:50:55 +02:00
|
|
|
if(world == nil){
|
2017-07-12 10:10:57 +02:00
|
|
|
RWERROR((ERR_ALLOC, s_plglist.size));
|
2016-06-23 16:50:55 +02:00
|
|
|
return nil;
|
|
|
|
}
|
2020-04-17 14:34:37 +02:00
|
|
|
numAllocated++;
|
2016-06-23 16:50:55 +02:00
|
|
|
world->object.init(World::ID, 0);
|
|
|
|
world->lights.init();
|
|
|
|
world->directionalLights.init();
|
2020-04-15 09:47:43 +02:00
|
|
|
s_plglist.construct(world);
|
2016-06-23 16:50:55 +02:00
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:47:43 +02:00
|
|
|
void
|
|
|
|
World::destroy(void)
|
|
|
|
{
|
|
|
|
s_plglist.destruct(this);
|
|
|
|
rwFree(this);
|
2020-04-17 14:34:37 +02:00
|
|
|
numAllocated--;
|
2020-04-15 09:47:43 +02:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:50:55 +02:00
|
|
|
void
|
|
|
|
World::addLight(Light *light)
|
|
|
|
{
|
|
|
|
light->world = this;
|
|
|
|
if(light->getType() < Light::POINT){
|
|
|
|
this->directionalLights.append(&light->inWorld);
|
2017-08-12 10:25:25 +02:00
|
|
|
}else{
|
2016-06-23 16:50:55 +02:00
|
|
|
this->lights.append(&light->inWorld);
|
2017-08-12 10:25:25 +02:00
|
|
|
if(light->getFrame())
|
|
|
|
light->getFrame()->updateObjects();
|
|
|
|
}
|
2016-06-23 16:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 09:47:43 +02:00
|
|
|
void
|
|
|
|
World::removeLight(Light *light)
|
|
|
|
{
|
|
|
|
if(light->world == this)
|
|
|
|
light->inWorld.remove();
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:50:55 +02:00
|
|
|
void
|
|
|
|
World::addCamera(Camera *cam)
|
|
|
|
{
|
|
|
|
cam->world = this;
|
2017-08-12 10:25:25 +02:00
|
|
|
if(cam->getFrame())
|
|
|
|
cam->getFrame()->updateObjects();
|
2016-06-23 16:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 09:47:43 +02:00
|
|
|
void
|
|
|
|
World::removeCamera(Camera *cam)
|
|
|
|
{
|
|
|
|
if(cam->world == this)
|
|
|
|
cam->world = nil;
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:50:55 +02:00
|
|
|
}
|