MCPcopy Create free account
hub / github.com/defold/defold / NewScene

Function NewScene

engine/gui/src/gui.cpp:556–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554 }
555
556 HScene NewScene(HContext context, const NewSceneParams* params)
557 {
558 lua_State* L = context->m_LuaState;
559 int top = lua_gettop(L);
560 (void) top;
561
562 Scene* scene = (Scene*)lua_newuserdata(L, sizeof(Scene));
563 ResetScene(scene);
564
565 dmArray<HScene>& scenes = context->m_Scenes;
566 if (scenes.Full())
567 {
568 scenes.SetCapacity(scenes.Capacity() + INITIAL_SCENE_COUNT);
569 }
570 scenes.Push(scene);
571
572 lua_pushvalue(L, -1);
573 scene->m_InstanceReference = dmScript::Ref( L, LUA_REGISTRYINDEX );
574
575 // Here we create a custom table to hold the references created by this gui scene
576 // It is also the "Instance Context Table" used to by META_TABLE_SET_CONTEXT_VALUE
577 // and META_TABLE_GET_CONTEXT_VALUE implementaion
578 lua_newtable(L);
579 scene->m_ContextTableReference = dmScript::Ref(L, LUA_REGISTRYINDEX);
580
581 lua_newtable(L);
582 scene->m_DataReference = dmScript::Ref(L, LUA_REGISTRYINDEX);
583
584 scene->m_Context = context;
585 scene->m_Script = 0x0;
586 scene->m_ParticlefxContext = params->m_ParticlefxContext;
587 scene->m_Nodes.SetCapacity(params->m_MaxNodes);
588 scene->m_NodePool.SetCapacity(params->m_MaxNodes);
589 scene->m_Animations.SetCapacity(params->m_MaxAnimations);
590 scene->m_Textures.SetCapacity(params->m_MaxTextures*2, params->m_MaxTextures);
591 // hashtable has zero capacity by default
592 if (params->m_MaxDynamicTextures > 0)
593 {
594 scene->m_DynamicTextures.SetCapacity(params->m_MaxDynamicTextures*2, params->m_MaxDynamicTextures);
595 }
596 scene->m_MaterialResources.SetCapacity(params->m_MaxMaterials*2, params->m_MaxMaterials);
597 scene->m_Fonts.SetCapacity(params->m_MaxFonts*2, params->m_MaxFonts);
598 scene->m_Particlefxs.SetCapacity(params->m_MaxParticlefxs*2, params->m_MaxParticlefxs);
599 scene->m_AliveParticlefxs.SetCapacity(params->m_MaxParticlefx);
600 scene->m_Layers.SetCapacity(params->m_MaxLayers*2, params->m_MaxLayers);
601 scene->m_Layouts.SetCapacity(1);
602 scene->m_AdjustReference = params->m_AdjustReference;
603 scene->m_DefaultFont = 0;
604 scene->m_UserData = params->m_UserData;
605 scene->m_RenderHead = INVALID_INDEX;
606 scene->m_RenderTail = INVALID_INDEX;
607 scene->m_NextVersionNumber = 0;
608 scene->m_RenderOrder = 0;
609 scene->m_Width = context->m_DefaultProjectWidth;
610 scene->m_Height = context->m_DefaultProjectHeight;
611 scene->m_AdjustWidth = context->m_AdjustWidth;
612 scene->m_AdjustHeight = context->m_AdjustHeight;
613 scene->m_AdjustOffsetX = context->m_AdjustOffsetX;

Callers 6

SetUpMethod · 0.50
TEST_FFunction · 0.50
InitializeScriptSceneFunction · 0.50
SetUpMethod · 0.50
TEST_FFunction · 0.50
CompGuiCreateFunction · 0.50

Calls 15

lua_gettopFunction · 0.85
lua_newuserdataFunction · 0.85
ResetSceneFunction · 0.85
lua_pushvalueFunction · 0.85
RefFunction · 0.85
lua_setmetatableFunction · 0.85
SetInstanceFunction · 0.85
InitializeInstanceFunction · 0.85
lua_pushnilFunction · 0.85
ClearLayoutsFunction · 0.70
assertFunction · 0.50
FullMethod · 0.45

Tested by 5

SetUpMethod · 0.40
TEST_FFunction · 0.40
InitializeScriptSceneFunction · 0.40
SetUpMethod · 0.40
TEST_FFunction · 0.40