C3DTask.cpp
Go to the documentation of this file.00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "stdpch.h"
00031
00032 #ifdef NL_OS_WINDOWS
00033 # include <windows.h>
00034 # include "../resource.h"
00035 # undef min
00036 # undef max
00037 extern HINSTANCE ghInstance;
00038 #endif
00039
00040
00041
00042
00043 #include <nel/misc/path.h>
00044
00045 #include <nel/3d/mesh.h>
00046 #include <nel/3d/shape.h>
00047 #include <nel/3d/material.h>
00048 #include <nel/3d/register_3d.h>
00049 #include <nel/3d/u_driver.h>
00050 #include <nel/3d/u_camera.h>
00051 #include <nel/3d/scene_user.h>
00052
00053
00054
00055
00056 #include "wwcommon/CTaskManager.h"
00057 #include "CConfigTask.h"
00058 #include "CTimeTask.h"
00059 #include "C3DTask.h"
00060 #include "CSimulationImpl.h"
00061
00062
00063
00064
00065 using namespace std;
00066 using namespace NL3D;
00067 using namespace NLMISC;
00068
00069 #ifdef NL_OS_WINDOWS
00070 #include "resource.h"
00071 extern HINSTANCE ghInstance;
00072 #endif // NL_OS_WINDOWS
00073
00074 namespace WWCLIENT {
00075
00076 void C3DTask::init() {
00077 m_ScreenWidth = CConfigTask::instance().configFile().getVar("ScreenWidth").asInt();
00078 m_ScreenHeight = CConfigTask::instance().configFile().getVar("ScreenHeight").asInt();
00079
00080 CConfigFile::CVar v;
00081 v = CConfigTask::instance().configFile().getVar("AmbientColor");
00082 nlassert(v.size()==4);
00083
00084 m_AmbientColor.set(v.asInt(0),v.asInt(1),v.asInt(2),v.asInt(3));
00085 v = CConfigTask::instance().configFile().getVar("ClearColor");
00086 nlassert(v.size()==4);
00087 m_ClearColor.set(v.asInt(0),v.asInt(1),v.asInt(2),v.asInt(3));
00088
00089
00090
00091 uint icon = 0;
00092 #ifdef NL_OS_WINDOWS
00093 icon = (uint)LoadIcon(ghInstance,MAKEINTRESOURCE(IDI_ICON1));
00094 #endif
00095 bool useD3D = CConfigTask::instance().configFile().getVar("OpenGL").asInt()==0;
00096 #ifdef NL_INDEX_BUFFER_H //new 3d
00097 m_Driver = UDriver::createDriver(icon,useD3D);
00098 #else
00099 m_Driver = UDriver::createDriver(icon);
00100 #endif
00101 nlassert(m_Driver);
00102 m_Driver->setSwapVBLInterval(0);
00103
00104
00105 if (!m_Driver->setDisplay (UDriver::CMode(m_ScreenWidth, m_ScreenHeight,
00106 CConfigTask::instance().configFile().getVar("ScreenDepth").asInt(),
00107 CConfigTask::instance().configFile().getVar("Fullscreen").asInt()==0,
00108 CConfigTask::instance().configFile().getVar("ScreenFrequency").asInt(),
00109 CConfigTask::instance().configFile().getVar("AntiAlias").asInt()))) {
00110 nlwarning ("Can't set display mode %d %d %d %d %d", m_ScreenWidth, m_ScreenHeight,
00111 CConfigTask::instance().configFile().getVar("ScreenDepth").asInt(),
00112 CConfigTask::instance().configFile().getVar("Fullscreen").asInt(),
00113 CConfigTask::instance().configFile().getVar("ScreenFrequency").asInt());
00114 return;
00115 }
00116
00117
00118 m_Driver->setFontManagerMaxMemory (2000000);
00119
00120
00121 m_TextContext = m_Driver->createTextContext (CPath::lookup("n019003l.pfb"));
00122
00123 if (m_TextContext == 0) {
00124 nlwarning ("Can't create text context");
00125 return;
00126 }
00127
00128 m_TextContext->setKeep800x600Ratio(false);
00129
00130 m_Driver->setAmbientColor(m_AmbientColor);
00131
00132 m_Driver->enableFog(false);
00133 m_Driver->setupFog(CConfigTask::instance().configFile().getVar("FogDistMin").asFloat(),CConfigTask::instance().configFile().getVar("FogDistMax").asFloat(),m_ClearColor);
00134
00135
00136 m_Scene = m_Driver->createScene(false);
00137
00138 if (m_Scene == 0) {
00139 nlwarning ("Can't create a NeL UScene");
00140 return;
00141 }
00142
00143 m_Scene->getCam().setPerspective(degToRad(CConfigTask::instance().configFile().getVar("Fov").asFloat()), 1.33f, 1.0f*GScale, 30000.0f*GScale);
00144 m_Scene->getCam().setTransformMode(UTransformable::DirectMatrix);
00145
00146 m_Scene->enableLightingSystem(true);
00147 m_Scene->setShadowMapBlurSize(1);
00148
00149 m_Scene->setPolygonBalancingMode(UScene::PolygonBalancingOn);
00150 m_Scene->setGroupLoadMaxPolygon("Fx", CConfigTask::instance().configFile().getVar("FxNbMaxPoly").asInt());
00151
00152
00153
00154 NL3D::CSceneUser* sceneUser = dynamic_cast<NL3D::CSceneUser*>(m_Scene);
00155 sceneUser->getScene().getShapeBank()->setShapeCacheSize("default", 500);
00156
00157
00158
00159 #ifdef NL_OS_WINDOWS
00160 HWND hWnd = (HWND )m_Driver->getDisplay();
00161 SetWindowText(hWnd,"Werewolf");
00162 #endif
00163 }
00164
00165 void C3DTask::update() {
00166 if(!m_Driver->isActive())
00167 WWCOMMON::CTaskManager::instance().exit();
00168
00169 m_Scene->animate(CTimeTask::instance().time());
00170 m_Driver->EventServer.pump();
00171
00175
00176
00177
00178
00179 }
00180
00181 void C3DTask::render() {
00182
00183 C3DTask::instance().driver().enableFog(true);
00184 if(getClientSimulation()->getSelfSob() != NULL) {
00185 getClientSimulation()->getSelfSob()->render();
00186 }
00187 m_Scene->render();
00188 C3DTask::instance().driver().enableFog(false);
00189
00190
00191 }
00192
00193 void C3DTask::release() {
00194 ;
00195 }
00196
00197 std::string C3DTask::name() {
00198 return "C3DTask";
00199 }
00200
00201 NL3D::UDriver &C3DTask::driver() const {
00202 nlassert(m_Driver);
00203 return *m_Driver;
00204 }
00205
00206 NL3D::UScene &C3DTask::scene() const {
00207 nlassert(m_Scene);
00208 return *m_Scene;
00209 }
00210
00211 NL3D::UTextContext &C3DTask::textContext() const {
00212 nlassert(m_TextContext);
00213 return *m_TextContext;
00214 }
00215
00216 void C3DTask::clear() {
00217 m_Driver->clearBuffers (m_ClearColor);
00218 }
00219
00220 void C3DTask::clearColor(CRGBA color) {
00221 m_ClearColor = color;
00222 }
00223
00224 void C3DTask::captureCursor(bool b) {
00225 ;
00226 }
00227
00228 uint16 C3DTask::getScreenWidth() {
00229 return m_ScreenWidth;
00230 }
00231
00232 uint16 C3DTask::getScreenHeight() {
00233 return m_ScreenHeight;
00234 }
00235
00236 };