2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
7 #include "WorldMan.hpp"
8 #include "ConsoleCommands/ConVar.hpp"
11 const WorldT
* WorldManT::LoadWorld(const char* FileName
, ModelManagerT
& ModelMan
, cf::GuiSys::GuiResourcesT
& GuiRes
, bool InitForGraphics
, WorldT::ProgressFunctionT ProgressFunction
)
13 for (unsigned long WorldNr
=0; WorldNr
<Worlds
.Size(); WorldNr
++)
15 WorldInfoT
& WI
=Worlds
[WorldNr
];
17 if (WI
.FileName
==FileName
)
19 assert(WI
.RefCount
>0);
21 if (InitForGraphics
&& !WI
.Init4Gfx
) InitWorldForGfx(WI
);
27 // FileName not found in cache, create a new instance.
28 WorldT
* NewWorld
=new WorldT(FileName
, ModelMan
, GuiRes
, ProgressFunction
); // Must do this here in case WorldT::WorldT() throws.
30 Worlds
.PushBackEmpty();
31 WorldInfoT
& WI
=Worlds
[Worlds
.Size()-1];
38 if (InitForGraphics
) InitWorldForGfx(WI
);
44 void WorldManT::FreeWorld(const WorldT
* World
)
46 for (unsigned long WorldNr
=0; WorldNr
<Worlds
.Size(); WorldNr
++)
48 WorldInfoT
& WI
=Worlds
[WorldNr
];
50 if (WI
.WorldPtr
==World
)
52 assert(WI
.RefCount
>0);
58 Worlds
.RemoveAt(WorldNr
);
69 WorldManT::~WorldManT()
71 // Did we really pair each call to LoadWorld() with a call to FreeWorld()?
72 assert(Worlds
.Size()==0);
76 void WorldManT::InitWorldForGfx(WorldInfoT
& WI
)
78 // Assert that this is done only once for any world instance.
82 WI
.WorldPtr
->SHLMapMan
.InitTextures();
85 static ConVarT
r_gamma_lm("cl_gamma_lm", 1.0, ConVarT::FLAG_MAIN_EXE
, "The gamma correction value that is applied to lightmaps on the next map load.");
87 static ConVarT
r_lm_ambient_r("cl_lm_ambient_r", 0, ConVarT::FLAG_MAIN_EXE
, "The red component of the lightmaps ambient (==minimum) color.");
88 static ConVarT
r_lm_ambient_g("cl_lm_ambient_g", 0, ConVarT::FLAG_MAIN_EXE
, "The green component of the lightmaps ambient (==minimum) color.");
89 static ConVarT
r_lm_ambient_b("cl_lm_ambient_b", 0, ConVarT::FLAG_MAIN_EXE
, "The blue component of the lightmaps ambient (==minimum) color.");
91 assert(r_gamma_lm
.GetType()==ConVarT::Double
);
92 assert(r_lm_ambient_r
.GetType()==ConVarT::Integer
);
94 WI
.WorldPtr
->LightMapMan
.InitTextures(float(r_gamma_lm
.GetValueDouble()), r_lm_ambient_r
.GetValueInt(), r_lm_ambient_g
.GetValueInt(), r_lm_ambient_b
.GetValueInt());
96 // Note that this world has been inited for graphics already.