00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "LampBasic.h"
00026 #include "Framework/System/BasicFramework.h"
00027 #include "Core/Utility/FPSMeasurement.h"
00028 #include "Graphics/System/LampGraphics.h"
00029 #include "Graphics/Enumeration/GraphicsDeviceEnumeration.h"
00030 #include "Graphics/System/GraphicsDevice.h"
00031 #include "Graphics/Renderer/RenderingDevice.h"
00032 #include "Input/System/LampInput.h"
00033
00034 #include "Core/System/StringMethod.h"
00035
00036 namespace Lamp{
00037
00038
00039
00040
00041
00042 BasicFramework::BasicFramework(const String& name) : SimpleFramework(name){
00043
00044 font_ = NULL;
00045 ::memset(&fontDescription_, 0, sizeof(D3DXFONT_DESC));
00046 fontDescription_.Height = 14;
00047 fontDescription_.Weight = FW_NORMAL;
00048 fontDescription_.Weight = FW_BOLD;
00049 fontDescription_.CharSet = SHIFTJIS_CHARSET;
00050 StdStrcpy(fontDescription_.FaceName, "MS ゴシック");
00051
00052 drawFPSMeasurement_ = new FPSMeasurement();
00053 gameFPSMeasurement_ = new FPSMeasurement();
00054 drawFPS_ = gameFPS_ = 0.f;
00055
00056 GraphicsDeviceEnumeration::getInstance()->setConfirmGraphicsDevice(this);
00057
00058 LampGraphics::addDeviceObjectHolder(this);
00059 }
00060
00061
00062 BasicFramework::~BasicFramework(){
00063
00064 LampGraphics::removeDeviceObjectHolder(this);
00065
00066 delete gameFPSMeasurement_;
00067 delete drawFPSMeasurement_;
00068 }
00069
00070
00071
00072
00073 void BasicFramework::mainLoop(){
00074
00075
00076
00077 int inputCount = 0;
00078 LampInput::waitForInput();
00079 while(LampInput::hasMoreInput()){
00080 LampInput::nextInput();
00081 frameworkRun();
00082
00083 gameFPS_ = gameFPSMeasurement_->measurement();
00084 inputCount++;
00085 if(inputCount == 60){
00086 LampInput::bufferClear();
00087 break;
00088 }
00089 }
00090
00091 frameworkRenderSetup();
00092
00093 frameworkPresentation();
00094
00095 frameworkRender();
00096 frameworkDrawInformation();
00097
00098 drawFPS_ = drawFPSMeasurement_->measurement();
00099 }
00100
00101
00102 void BasicFramework::frameworkRun(){
00103 SimpleFramework::frameworkRun();
00104
00105 if(keyboard_->down(Keyboard::keyEnter) &&
00106 (keyboard_->pressed(Keyboard::keyLeftAlt) ||
00107 keyboard_->pressed(Keyboard::keyRightAlt))){
00108 GraphicsDevice::getInstance()->toggleFullscreen();
00109 }
00110
00111 if(keyboard_->down(Keyboard::keyF9)){
00112 GraphicsDevice::getInstance()->rebuild();
00113 }
00114 }
00115
00116
00117 void BasicFramework::frameworkDrawInformation(){
00118 if(font_ == NULL){ return; }
00119 RenderingDevice* device = RenderingDevice::getInstance();
00120 if(!device->beginScene()){ return; }
00121
00122 ::GetClientRect(windowHandle_, &informationDrawRect_);
00123 int gap = 5;
00124 informationDrawRect_.top += gap;
00125 informationDrawRect_.bottom -= gap;
00126 informationDrawRect_.left += gap * 2;
00127 informationDrawRect_.right -= gap * 2;
00128
00129 drawInformation();
00130 device->endScene();
00131 }
00132
00133
00134
00135
00136 void BasicFramework::drawInformation(){
00137 drawInformationString(getFPSString(), Color4c::white, true, true);
00138 }
00139
00140
00141 void BasicFramework::drawInformationString(
00142 const String& message, Color4c color, bool alignRight, bool alignBottom){
00143 if(font_ == NULL){ return; }
00144
00145 u_int alignFlag = 0;
00146 if(alignRight){
00147 alignFlag |= (DT_RIGHT | DT_SINGLELINE);
00148 }else{
00149 alignFlag |= DT_LEFT;
00150 }
00151 if(alignBottom){
00152 alignFlag |= (DT_BOTTOM | DT_SINGLELINE);
00153 }else{
00154 alignFlag |= DT_TOP;
00155 }
00156
00157 font_->DrawText(NULL, message.getBytes(), -1, &informationDrawRect_,
00158 alignFlag, color.getARGB());
00159 }
00160
00161
00162 String BasicFramework::getFPSString() const{
00163 String fpsString;
00164 fpsString.format("Game %4.1f Draw %4.1f", gameFPS_, drawFPS_);
00165 return fpsString;
00166 }
00167
00168
00169
00170
00171 bool BasicFramework::initializeGraphicsDeviceObjects(){
00172
00173 if(DirectXFailed(D3DXCreateFontIndirect(
00174 LampGraphics::getDirect3DDevice(), &fontDescription_, &font_))){
00175 ErrorOut("BasicFramework::initializeGraphicsDeviceObjects() "
00176 "フォントの作成に失敗しました");
00177 SafeRelease(font_);
00178 return false;
00179 }
00180 return true;
00181 }
00182
00183
00184 void BasicFramework::deleteGraphicsDeviceObjects(){
00185
00186 SafeRelease(font_);
00187 }
00188
00189
00190 bool BasicFramework::restoreGraphicsDeviceObjects(){
00191
00192 if(font_ != NULL){
00193 if(DirectXFailed(font_->OnResetDevice())){
00194 ErrorOut("BasicFramework::restoreGraphicsDeviceObjects() "
00195 "フォントの作成に失敗しました");
00196 SafeRelease(font_);
00197 return false;
00198 }
00199 }
00200 return true;
00201 }
00202
00203
00204 void BasicFramework::invalidateGraphicsDeviceObjects(){
00205
00206 if(font_ != NULL){ font_->OnLostDevice(); }
00207 }
00208
00209 }
00210