Jump to content

Delete all entities from the frameworks world


ParaToxic
 Share

Recommended Posts

In gamelib I wrote a function which clears the framework worlds. It's a bit tricky because not all entities are part of a world, like sources, so you have to keep pointers for those yourself.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Actually the code was not in gamelib, but in cubix. There I have this code to switch to the next level, clearing and recreating framework (it still uses gamelib functions though):

 

 

#if devel

Keyboard::I****(KEY_F2) ||

#endif

nextlevel )

{ // TODO: This will go to GameLib

nextlevel=false;

//game.scene.framewerk.Free();

game.scene.skyworld.Set();

game.scene.skyworld.Clear();

game.scene.skyworld.Free();

game.scene.world.Set();

game.scene.world.Clear();

game.scene.world.Free();

game.scene.foregroundworld.Set();

game.scene.foregroundworld.Clear();

game.scene.foregroundworld.Free();

FreeEntity(game.scene.outofworldentity["sound_1"].entity); //TODO: free all entities loop

game.scene.outofworldentity.clear(); // clear the whole map and resize it to 0

//FreeEntity(game.scene.scene);

#if devel

printf("LEVEL2: CLEAR\n");

CountEntities();

#endif

game.scene.ReInitialize();

game.luat.Create(); // create the LuaTools object

game.luat.SetScriptObject("fw",game.scene.framewerk); // set the Lua variable fw

game.scene.LoadMap("maps/level2.sbx");

ReInitialize();

SetStats(0); // TODO: Somehow Application should do this

BeginRender();

EndRender();

Flip(1,-2);

}

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

ReInitialize() is just a Cubix game specific reinitialization to create default values for enemies and player:

 

 

void Cubix::ReInitialize()

{

pla=game.scene.SetCurrentPlayer("player1");

if(NULL==pla->body)Notify("player1 not found");

pla->SetWeapon("rifle");

CreateEnemies();

cubes.at(0).SetGravityMode(false); // prepare first attacking cube

snd2.Load("Models/Cube1/Cube1.ogg");

src2.Create(snd2,LOOP);

src2.SetRange(100);

src2.SetVolume(0.6);

src2.Play();

//SetEntityKey(snd2,"name","snd2");

//SetEntityName(src2,"src2");

sounds["exp"].Load("models/cube1/cubedeath.ogg");

sources["exp"].Create(sounds["exp"],EAX);

sources["exp"].SetRange(100);

sources["exp"].SetVolume(0.6);

sounds["die"].Load("models/player1/playerdeath.ogg");

sources["die"].Create(sounds["die"],EAX);

sources["die"].SetRange(100);

game.scene.framewerk.listener.SetPosition(game.scene.cam.GetPosition(GLOBAL));

game.scene.framewerk.listener.SetRotation(game.scene.cam.GetRotation(GLOBAL));

game.scene.framewerk.listener.SetParent(game.scene.cam);

//Sound::SetEAXEffect(MOUNTAINS); // engine bug: this disables 3D sounds

game.scene.foregroundworld.Set();

emitter1=GetFirstEntityByKey("name","emitter_1",ENTITY_EMITTER);

//TEmitter emitter2=GetFirstEntityByKey("name","emitter_1",ENTITY_EMITTER);

game.scene.world.Set();

//if(!emitter2)MessageBoxA(0,"NO EMITTER",0,0);

//EntityColor(emitter1,Vec4(1,0,0,1));

//emitter1.SetArea(Vec3(1,1,1));

//SetEmitterArea(emitter2,Vec3(1,1,1));

}

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...