| 1 |
#include "stdafx.h" |
| 2 |
#include "CCamera.h" |
| 3 |
#include "CStructPlugin.h" |
| 4 |
#include "CStruct.h" |
| 5 |
#include "CStructSelectMode.h" |
| 6 |
#include "CSimulationMode.h" |
| 7 |
#include "CConfigMode.h" |
| 8 |
#include "CSaveFile.h" |
| 9 |
|
| 10 |
// 外部グローバル |
| 11 |
extern bool g_MoverEnabled; |
| 12 |
|
| 13 |
// 内部グローバル |
| 14 |
CStructPlugin *g_Struct = NULL; |
| 15 |
|
| 16 |
/* |
| 17 |
* [static] |
| 18 |
* プレビュー |
| 19 |
*/ |
| 20 |
void CStructPlugin::RenderPreview( |
| 21 |
VEC3 pos, // 位置 |
| 22 |
VEC3 dir, // dir |
| 23 |
VEC3 up // up |
| 24 |
){ |
| 25 |
CNamedObjectAfterRenderer::SetCurrentInst(NULL); |
| 26 |
g_SaveFile->ResetSwitch(); |
| 27 |
if(ms_PreviewState && g_Struct){ |
| 28 |
g_SystemObject[SYS_OBJ_LOCAL].SetPreviewPosture(pos, dir, up); |
| 29 |
SetCamDistSwitch(pos); |
| 30 |
g_Struct->Preview(); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
/* |
| 35 |
* デストラクタ |
| 36 |
*/ |
| 37 |
CStructPlugin::~CStructPlugin(){ |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* ロード |
| 42 |
*/ |
| 43 |
bool CStructPlugin::Load(){ |
| 44 |
char *str = m_Script, *tmp, *eee; |
| 45 |
if(!ChDir() || !m_Script) return false; |
| 46 |
g_NamedObjectMipMap = g_StructMipMap; |
| 47 |
CNamedObject::SetCastShadowDefault(true); |
| 48 |
try{ |
| 49 |
if(!(str = LoadStructBefore(eee = str))) throw CSynErr(eee); |
| 50 |
|
| 51 |
if(!(str = ReadModelSwitch(eee = str))) throw CSynErr(eee); |
| 52 |
|
| 53 |
if(!(str = BeginBlock(eee = str, "PrimaryAssembly"))) throw CSynErr(eee); |
| 54 |
CFreeObjectContainer freeobj; |
| 55 |
while(tmp = freeobj.Read(str, this)){ |
| 56 |
str = tmp; |
| 57 |
m_FreeObject.push_back(freeobj); |
| 58 |
} |
| 59 |
|
| 60 |
if(!(str = LoadStructAfter(eee = str))) throw CSynErr(eee); |
| 61 |
|
| 62 |
if(!(str = ReadEffect(eee = str))) throw CSynErr(eee); |
| 63 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 64 |
|
| 65 |
if(*(eee = str)) throw CSynErr(eee); |
| 66 |
} |
| 67 |
catch(CSynErr err){ |
| 68 |
HandleError(&err); |
| 69 |
return false; |
| 70 |
} |
| 71 |
IFreeObjectContainer ifo = m_FreeObject.begin(); |
| 72 |
for(; ifo!=m_FreeObject.end(); ifo++) ifo->LoadModel(this); |
| 73 |
LoadData(); |
| 74 |
DELETE_A(m_Buffer); |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
/* |
| 79 |
* ロード |
| 80 |
*/ |
| 81 |
char *CStructPlugin::LoadStructBefore( |
| 82 |
char *str // 対象文字列 |
| 83 |
){ |
| 84 |
char *eee; |
| 85 |
if(!(str = BeginBlock(eee = str, "StructInfo"))) throw CSynErr(eee); |
| 86 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 87 |
return str; |
| 88 |
} |
| 89 |
|
| 90 |
/* |
| 91 |
* ロード |
| 92 |
*/ |
| 93 |
bool CStructPlugin::LoadOldForm(){ |
| 94 |
if(!ChDir()) return false; |
| 95 |
g_NamedObjectMipMap = g_StructMipMap; |
| 96 |
CNamedObject::SetCastShadowDefault(true); |
| 97 |
FILE *file = fopen(TextName(), "rt"); |
| 98 |
char *dummy = FlashOut(); |
| 99 |
float sc; |
| 100 |
fscanf(file, "%s %s %f", dummy, dummy, &sc); |
| 101 |
fclose(file); |
| 102 |
float oldscale = 2.0f/sc; |
| 103 |
m_FreeObject.push_back(CFreeObjectContainer(new CFreeObject3D("MainObject", "Model.x", oldscale))); |
| 104 |
m_FreeObject.begin()->LoadModel(this); |
| 105 |
m_PartsNum = 1; |
| 106 |
return true; |
| 107 |
} |
| 108 |
|
| 109 |
/* |
| 110 |
* プレビュー設定 |
| 111 |
*/ |
| 112 |
void CStructPlugin::SetPreview(){ |
| 113 |
ms_PreviewState = true; |
| 114 |
g_Struct = this; |
| 115 |
string desc = g_Struct->GetBasicInfo(); |
| 116 |
desc += "\n"+g_Struct->GetDescription(); |
| 117 |
g_StructSelectMode->SetProperty((char *)desc.c_str()); |
| 118 |
} |
| 119 |
|
| 120 |
/* |
| 121 |
* プレビュー |
| 122 |
*/ |
| 123 |
void CStructPlugin::Preview(){ |
| 124 |
SetPartsInst(NULL); |
| 125 |
SetMoverState(NULL); |
| 126 |
SetPosture(); |
| 127 |
Render(NULL); |
| 128 |
PreviewStruct(); |
| 129 |
} |
| 130 |
|
| 131 |
/* |
| 132 |
* オブジェクト検索 |
| 133 |
*/ |
| 134 |
CNamedObject *CStructPlugin::FindObject( |
| 135 |
const string &name // オブジェクト名 |
| 136 |
){ |
| 137 |
CNamedObject *ret; |
| 138 |
IFreeObjectContainer ifo = m_FreeObject.begin(); |
| 139 |
for(; ifo!=m_FreeObject.end(); ifo++) if(ret = ifo->Check(name)) return ret; |
| 140 |
return NULL; |
| 141 |
} |
| 142 |
|
| 143 |
/* |
| 144 |
* サウンド有効かどうか |
| 145 |
*/ |
| 146 |
bool CStructPlugin::IsSoundEnabled(){ |
| 147 |
return !!g_ConfigMode->GetStructSound(); |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
* 姿勢設定 |
| 152 |
*/ |
| 153 |
void CStructPlugin::SetPosture(){ |
| 154 |
IFreeObjectContainer ifo = m_FreeObject.begin(); |
| 155 |
for(; ifo!=m_FreeObject.end(); ifo++) ifo->SetPosture(); |
| 156 |
} |
| 157 |
|
| 158 |
/* |
| 159 |
* 入力チェック |
| 160 |
*/ |
| 161 |
void CStructPlugin::ScanInput( |
| 162 |
CStruct *strct // 施設インスタンス |
| 163 |
){ |
| 164 |
strct->SetLocalAxis(); |
| 165 |
SetCamDistSwitch(strct->GetPos()); |
| 166 |
g_PreSimulationFlag = false; |
| 167 |
IFreeObjectContainer ifo = m_FreeObject.begin(); |
| 168 |
for(; ifo!=m_FreeObject.end(); ifo++) ifo->ScanInput(); |
| 169 |
} |
| 170 |
|
| 171 |
/* |
| 172 |
* レンダリング |
| 173 |
*/ |
| 174 |
void CStructPlugin::Render( |
| 175 |
CStruct *strct // 施設インスタンス |
| 176 |
){ |
| 177 |
SetAnimation(strct); |
| 178 |
if(strct){ |
| 179 |
strct->SetLocalAxis(); |
| 180 |
SetCamDistSwitch(strct->GetPos()); |
| 181 |
} |
| 182 |
g_PreSimulationFlag = false; |
| 183 |
CNamedObject::SetSetMaterial(m_Version>=2.00f); |
| 184 |
if(strct && !g_SimulationMode->GetSimSpeed()){ |
| 185 |
g_MoverEnabled = false; |
| 186 |
SetMoverState(strct); |
| 187 |
SetPosture(); |
| 188 |
SetPartsInst(strct); |
| 189 |
g_MoverEnabled = true; |
| 190 |
} |
| 191 |
IFreeObjectContainer ifo = m_FreeObject.begin(); |
| 192 |
for(; ifo!=m_FreeObject.end(); ifo++) ifo->Render(); |
| 193 |
SimulateEffect(strct); |
| 194 |
} |
| 195 |
|
| 196 |
/* |
| 197 |
* シミュレーション進行 |
| 198 |
*/ |
| 199 |
void CStructPlugin::Simulate( |
| 200 |
CStruct *strct // 施設インスタンス |
| 201 |
){ |
| 202 |
SetMoverState(strct); |
| 203 |
strct->SetLocalAxis(); |
| 204 |
SetCamDistSwitch(strct->GetPos()); |
| 205 |
g_PreSimulationFlag = true; |
| 206 |
SetPosture(); |
| 207 |
SimulateEffect(strct); |
| 208 |
} |