add some cleanup to lights example

This commit is contained in:
aap 2021-03-03 02:15:38 +01:00
parent 0921a2b003
commit d13bd898fe
5 changed files with 73 additions and 1 deletions

View File

@ -71,6 +71,25 @@ CameraCreate(int32 width, int32 height, bool32 z)
return cam;
}
void
CameraDestroy(rw::Camera *cam)
{
if(cam->frameBuffer){
cam->frameBuffer->destroy();
cam->frameBuffer = nil;
}
if(cam->zBuffer){
cam->zBuffer->destroy();
cam->zBuffer = nil;
}
rw::Frame *frame = cam->getFrame();
if(frame){
cam->setFrame(nil);
frame->destroy();
}
cam->destroy();
}
void
CameraSize(Camera *cam, Rect *r)
{

View File

@ -103,6 +103,7 @@ extern Args args;
bool InitRW(void);
void TerminateRW(void);
Camera *CameraCreate(int32 width, int32 height, bool32 z);
void CameraDestroy(rw::Camera *cam);
void CameraSize(Camera *cam, Rect *r);
void SetMousePosition(int x, int y);
EventStatus EventHandler(Event e, void *param);

View File

@ -100,10 +100,33 @@ CreateSpotSoftLight(void)
return light;
}
void
DestroyLight(rw::Light **light)
{
if(*light == nil)
return;
rw::World *world = (*light)->world;
if(world)
world->removeLight(*light);
rw::Frame *frame = (*light)->getFrame();
if(frame){
(*light)->setFrame(nil);
frame->destroy();
}
(*light)->destroy();
*light = nil;
}
void
LightsDestroy(void)
{
// TODO
DestroyLight(&SpotSoftLight);
DestroyLight(&SpotLight);
DestroyLight(&PointLight);
DestroyLight(&DirectLight);
DestroyLight(&AmbientLight);
DestroyLight(&BaseAmbientLight);
}
void

View File

@ -28,6 +28,7 @@ rw::Light *CreatePointLight(void);
rw::Light *CreateSpotLight(void);
rw::Light *CreateSpotSoftLight(void);
void LightsDestroy(void);
void LightsUpdate(void);
void DrawCurrentLight(void);

View File

@ -166,6 +166,31 @@ Initialize3D(void)
return true;
}
void
Terminate3D(void)
{
FORLIST(lnk, World->clumps){
rw::Clump *clump = rw::Clump::fromWorld(lnk);
World->removeClump(clump);
clump->destroy();
}
if(Camera){
World->removeCamera(Camera);
sk::CameraDestroy(Camera);
Camera = nil;
}
LightsDestroy();
if(World){
World->destroy();
World = nil;
}
sk::TerminateRW();
}
bool
attachPlugins(void)
{
@ -327,6 +352,9 @@ AppEventHandler(sk::Event e, void *param)
return EVENTPROCESSED;
case RWINITIALIZE:
return Initialize3D() ? EVENTPROCESSED : EVENTERROR;
case RWTERMINATE:
Terminate3D();
return EVENTPROCESSED;
case PLUGINATTACH:
return attachPlugins() ? EVENTPROCESSED : EVENTERROR;
case KEYDOWN: