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; 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 void
CameraSize(Camera *cam, Rect *r) CameraSize(Camera *cam, Rect *r)
{ {

View File

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

View File

@ -100,10 +100,33 @@ CreateSpotSoftLight(void)
return light; 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 void
LightsDestroy(void) LightsDestroy(void)
{ {
// TODO DestroyLight(&SpotSoftLight);
DestroyLight(&SpotLight);
DestroyLight(&PointLight);
DestroyLight(&DirectLight);
DestroyLight(&AmbientLight);
DestroyLight(&BaseAmbientLight);
} }
void void

View File

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

View File

@ -166,6 +166,31 @@ Initialize3D(void)
return true; 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 bool
attachPlugins(void) attachPlugins(void)
{ {
@ -327,6 +352,9 @@ AppEventHandler(sk::Event e, void *param)
return EVENTPROCESSED; return EVENTPROCESSED;
case RWINITIALIZE: case RWINITIALIZE:
return Initialize3D() ? EVENTPROCESSED : EVENTERROR; return Initialize3D() ? EVENTPROCESSED : EVENTERROR;
case RWTERMINATE:
Terminate3D();
return EVENTPROCESSED;
case PLUGINATTACH: case PLUGINATTACH:
return attachPlugins() ? EVENTPROCESSED : EVENTERROR; return attachPlugins() ? EVENTPROCESSED : EVENTERROR;
case KEYDOWN: case KEYDOWN: