Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
373 lines
9.3 KiB
C++
373 lines
9.3 KiB
C++
// X3DEditEffect.cpp: implementation of the CX3DEditEffect class.
|
||
//
|
||
//////////////////////////////////////////////////////////////////////
|
||
|
||
#include "stdafx.h"
|
||
#include "EffectEditor.h"
|
||
#include "X3DEditEffect.h"
|
||
#include "X3DEffectEditParticle.h"
|
||
#include "X3DEffectEditBillboard.h"
|
||
#include "X3DEffectEditCylinder.h"
|
||
#include "X3DEffectEditPlane.h"
|
||
#include "X3DEffectEditSphere.h"
|
||
#include "X3DEffectEditMesh.h"
|
||
|
||
#ifdef _DEBUG
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[]=__FILE__;
|
||
#define new DEBUG_NEW
|
||
#endif
|
||
|
||
//////////////////////////////////////////////////////////////////////
|
||
// Construction/Destruction
|
||
//////////////////////////////////////////////////////////////////////
|
||
|
||
CX3DEditEffect::CX3DEditEffect()
|
||
{
|
||
m_dwUIDCounter = 0;
|
||
}
|
||
|
||
CX3DEditEffect::~CX3DEditEffect()
|
||
{
|
||
m_lstEditEffectObject.clear();
|
||
m_dwUIDCounter = 0;
|
||
}
|
||
|
||
void CX3DEditEffect::RenderPicked(unsigned long dwEffectNumber, unsigned long dwFrame)
|
||
{
|
||
list<CX3DEditObject *>::iterator it;
|
||
CX3DEditObject *pEffect;
|
||
unsigned long dwEffectCount = 0;
|
||
|
||
m_lpD3DDevice->SetVertexShader(LVERTEXFVF);
|
||
|
||
for(it = m_lstEditEffectObject.begin(); it != m_lstEditEffectObject.end(); it++)
|
||
{
|
||
if(dwEffectCount == dwEffectNumber)
|
||
{
|
||
pEffect = (CX3DEditObject *)(*it);
|
||
pEffect->RenderNoTexture(dwFrame);
|
||
break;
|
||
}
|
||
dwEffectCount++;
|
||
}
|
||
}
|
||
|
||
unsigned long CX3DEditEffect::Pick(vector3 &vecStart, vector3 &vecEnd, unsigned long &dwEffectNumber)
|
||
{
|
||
list<CX3DEditObject *>::iterator it;
|
||
CX3DEditObject *pEffect;
|
||
unsigned long dwEffectKind, dwEffectKindTemp, dwCount = 0;
|
||
float fMinLength = 100000.0f, fLength;
|
||
|
||
dwEffectNumber = dwEffectKind = 0xFFFFFFFF;
|
||
for(it = m_lstEditEffectObject.begin(); it != m_lstEditEffectObject.end(); it++)
|
||
{
|
||
pEffect = (CX3DEditObject *)(*it);
|
||
dwEffectKindTemp = pEffect->GetPick(vecStart, vecEnd, fLength);
|
||
if(fLength && (fLength < fMinLength))
|
||
{
|
||
fMinLength = fLength;
|
||
dwEffectNumber = dwCount;
|
||
dwEffectKind = dwEffectKindTemp;
|
||
}
|
||
dwCount++;
|
||
}
|
||
|
||
return dwEffectKind;
|
||
}
|
||
|
||
unsigned long CX3DEditEffect::AddEditObject(CX3DEditObject *pNewEffect)
|
||
{
|
||
pNewEffect->SetUID(++m_dwUIDCounter);
|
||
m_lstEditEffectObject.push_back(pNewEffect);
|
||
|
||
return m_lstEffect.size() - 1;
|
||
}
|
||
|
||
CX3DEditObject *CX3DEditEffect::GetEditObject(unsigned long dwEffectNumber)
|
||
{
|
||
list<CX3DEditObject *>::iterator it;
|
||
unsigned long dwEffectCount = 0;
|
||
|
||
for(it = m_lstEditEffectObject.begin(); it != m_lstEditEffectObject.end(); it++)
|
||
{
|
||
if(dwEffectCount == dwEffectNumber) { return (CX3DEditObject *)(*it); }
|
||
dwEffectCount++;
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
CX3DEditObject *CX3DEditEffect::GetFindEditObject(unsigned long dwUID)
|
||
{
|
||
list<CX3DEditObject *>::iterator it;
|
||
CX3DEditObject *lpEffect;
|
||
|
||
for(it = m_lstEditEffectObject.begin(); it != m_lstEditEffectObject.end(); it++)
|
||
{
|
||
lpEffect = (CX3DEditObject *)(*it);
|
||
if(lpEffect->GetUID() == dwUID) { return lpEffect; }
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
CX3DEffectBase *CX3DEditEffect::GetEffect(unsigned long dwKind, unsigned long dwEffectNumber)
|
||
{
|
||
list<CX3DEffectBase *>::iterator it;
|
||
CX3DEffectBase *lpEffect;
|
||
unsigned long dwEffectCount = 0;
|
||
|
||
for(it = m_lstEffect.begin(); it != m_lstEffect.end(); it++)
|
||
{
|
||
if(dwEffectCount == dwEffectNumber)
|
||
{
|
||
lpEffect = (CX3DEffectBase *)(*it);
|
||
if(lpEffect->GetEffectKind() == dwKind)
|
||
return lpEffect;
|
||
else
|
||
return NULL;
|
||
}
|
||
dwEffectCount++;
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
BOOL CX3DEditEffect::DeleteEditObject(unsigned long dwEffectNumber)
|
||
{
|
||
list<CX3DEditObject *>::iterator it;
|
||
unsigned long dwEffectCount = 0;
|
||
CX3DEditObject *pEffect;
|
||
|
||
for(it = m_lstEditEffectObject.begin(); it != m_lstEditEffectObject.end(); it++)
|
||
{
|
||
if(dwEffectCount == dwEffectNumber)
|
||
{
|
||
pEffect = (CX3DEditObject *)(*it);
|
||
m_lstEditEffectObject.erase(it);
|
||
return TRUE;
|
||
}
|
||
dwEffectCount++;
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
void CX3DEditEffect::Load(const char *strFilePath, const char *strFileName)
|
||
{
|
||
FILE *fp;
|
||
char strFile[MAX_PATH];
|
||
strcpy(strFile, strFilePath);
|
||
strcat(strFile, strFileName);
|
||
fp = fopen(strFile, "rb");
|
||
if(!fp) return;
|
||
|
||
CX3DEffectEditParticle *lpParticle;
|
||
CX3DEffectEditBillboard *lpBillboard;
|
||
CX3DEffectEditCylinder *lpCylinder;
|
||
CX3DEffectEditPlane *lpPlane;
|
||
CX3DEffectEditSphere *lpSphere;
|
||
CX3DEffectEditMesh *lpMesh;
|
||
|
||
unsigned short Size, Kind;
|
||
unsigned long i, dwStartFrame, dwEndFrame;
|
||
unsigned char len;
|
||
char strTextureFile[MAX_PATH], strTemp[MAX_PATH];
|
||
|
||
fread(&m_dwMaxFrame, 4, 1, fp);
|
||
fread(&m_dwFrameTick, 4, 1, fp);
|
||
fread(&m_fIncFrame, 4, 1, fp);
|
||
fread(&Size, 2, 1, fp);
|
||
for(i = 0; i < Size; i++)
|
||
{
|
||
fread(&Kind, 2, 1, fp);
|
||
fread(&len, 1, 1, fp);
|
||
if(len)
|
||
{
|
||
fread(strTemp, len, 1, fp);
|
||
strcpy(strTextureFile, strFilePath);
|
||
strcat(strTextureFile, strTemp);
|
||
char *tm = strrchr(strTemp,'\\');
|
||
strcpy(strTextureFile, tm);
|
||
|
||
} else
|
||
{
|
||
strcpy(strTextureFile, "");
|
||
}
|
||
|
||
switch(Kind)
|
||
{
|
||
case EFFECT_PARTICLE:
|
||
lpParticle = new CX3DEffectEditParticle;
|
||
AddEffect(lpParticle);
|
||
AddEditObject(lpParticle);
|
||
if(strTextureFile) lpParticle->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpParticle->Create(dwStartFrame, dwEndFrame);
|
||
lpParticle->SetVisibility(true);
|
||
lpParticle->SetEffectKind(Kind);
|
||
lpParticle->Load(fp, strFilePath);
|
||
lpParticle->CreateBuffer();
|
||
break;
|
||
|
||
case EFFECT_BILLBOARD:
|
||
lpBillboard = new CX3DEffectEditBillboard;
|
||
AddEffect(lpBillboard);
|
||
AddEditObject(lpBillboard);
|
||
if(strTextureFile) lpBillboard->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpBillboard->Create(dwStartFrame, dwEndFrame);
|
||
lpBillboard->SetEffectKind(Kind);
|
||
lpBillboard->SetVisibility(true);
|
||
lpBillboard->Load(fp, strFilePath);
|
||
lpBillboard->CreateBuffer();
|
||
break;
|
||
|
||
case EFFECT_CYLINDER:
|
||
lpCylinder = new CX3DEffectEditCylinder;
|
||
AddEffect(lpCylinder);
|
||
AddEditObject(lpCylinder);
|
||
if(strTextureFile) lpCylinder->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpCylinder->Create(dwStartFrame, dwEndFrame);
|
||
lpCylinder->SetEffectKind(Kind);
|
||
lpCylinder->SetVisibility(true);
|
||
lpCylinder->Load(fp, strFilePath);
|
||
lpCylinder->CreateBuffer();
|
||
break;
|
||
|
||
case EFFECT_PLANE:
|
||
lpPlane = new CX3DEffectEditPlane;
|
||
AddEffect(lpPlane);
|
||
AddEditObject(lpPlane);
|
||
if(strTextureFile) lpPlane->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpPlane->Create(dwStartFrame, dwEndFrame);
|
||
lpPlane->SetEffectKind(Kind);
|
||
lpPlane->SetVisibility(true);
|
||
lpPlane->Load(fp, strFilePath);
|
||
lpPlane->CreateBuffer();
|
||
break;
|
||
|
||
case EFFECT_SPHERE:
|
||
lpSphere = new CX3DEffectEditSphere;
|
||
AddEffect(lpSphere);
|
||
AddEditObject(lpSphere);
|
||
if(strTextureFile) lpSphere->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpSphere->Create(dwStartFrame, dwEndFrame);
|
||
lpSphere->SetVisibility(true);
|
||
lpSphere->SetEffectKind(Kind);
|
||
lpSphere->Load(fp, strFilePath);
|
||
lpSphere->CreateBuffer();
|
||
break;
|
||
|
||
case EFFECT_MESH:
|
||
lpMesh = new CX3DEffectEditMesh;
|
||
AddEffect(lpMesh);
|
||
AddEditObject(lpMesh);
|
||
if(strTextureFile) lpMesh->LoadTexture(strTextureFile);
|
||
fread(&dwStartFrame, 4, 1, fp);
|
||
fread(&dwEndFrame, 4, 1, fp);
|
||
lpMesh->Create(dwStartFrame, dwEndFrame);
|
||
lpMesh->SetVisibility(true);
|
||
lpMesh->SetEffectKind(Kind);
|
||
lpMesh->Load(fp, strFilePath);
|
||
lpMesh->CreateBuffer();
|
||
break;
|
||
|
||
default:
|
||
MessageBox(NULL, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MB_OK);
|
||
fclose(fp);
|
||
return;
|
||
}
|
||
}
|
||
|
||
fclose(fp);
|
||
}
|
||
|
||
|
||
void CX3DEditEffect::Save(const char *strFilePath, const char *strFileName)
|
||
{
|
||
FILE *fp;
|
||
char strFile[MAX_PATH];
|
||
strcpy(strFile, strFilePath);
|
||
strcat(strFile, strFileName);
|
||
fp = fopen(strFile, "wb");
|
||
if(!fp) return;
|
||
|
||
list<CX3DEffectBase *>::iterator it;
|
||
CX3DEffectBase *pEffect;
|
||
|
||
unsigned short Size = m_lstEffect.size(), Kind;
|
||
unsigned char len;
|
||
unsigned long StartFrame, EndFrame;
|
||
char strTemp[MAX_PATH] , strTexture[MAX_PATH];
|
||
|
||
fwrite(&m_dwMaxFrame, 4, 1, fp);
|
||
fwrite(&m_dwFrameTick, 4, 1, fp);
|
||
fwrite(&m_fIncFrame, 4, 1, fp);
|
||
fwrite(&Size, 2, 1, fp);
|
||
for(it = m_lstEffect.begin(); it != m_lstEffect.end(); it++)
|
||
{
|
||
pEffect = (CX3DEffectBase *)(*it);
|
||
|
||
Kind = (unsigned short)pEffect->GetEffectKind();
|
||
StartFrame = pEffect->GetStartFrame();
|
||
EndFrame = pEffect->GetEndFrame();
|
||
|
||
fwrite(&Kind, 2, 1, fp);
|
||
|
||
if(strlen(pEffect->GetTextureFileName()))
|
||
{
|
||
strcpy(strTexture, pEffect->GetTextureFileName());
|
||
|
||
if(1)//strncmp(strTexture, strFilePath, strlen(strFilePath)))
|
||
{
|
||
//strcpy(strTemp, &strTexture[strlen(strFilePath)]);
|
||
sprintf(strTemp,"effectdds\\%s",strTexture);
|
||
|
||
} else {
|
||
MessageBox(NULL, "<EFBFBD>ؽ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߸<EFBFBD><DFB8><EFBFBD><EFBFBD><EFBFBD>", "Effect Editor", MB_OK);
|
||
return;
|
||
}
|
||
|
||
len = strlen(strTemp) + 1;
|
||
fwrite(&len, 1, 1, fp);
|
||
fwrite(strTemp, len, 1, fp);
|
||
} else
|
||
{
|
||
len = 0;
|
||
fwrite(&len, 1, 1, fp);
|
||
}
|
||
|
||
fwrite(&StartFrame, 4, 1, fp);
|
||
fwrite(&EndFrame, 4, 1, fp);
|
||
|
||
pEffect->Save(fp, strFilePath);
|
||
}
|
||
|
||
fclose(fp);
|
||
}
|
||
|
||
unsigned long CX3DEditEffect::GetEffectKind(unsigned long dwEffectNumber)
|
||
{
|
||
list<CX3DEffectBase *>::iterator it;
|
||
unsigned long dwEffectCount = 0;
|
||
|
||
for(it = m_lstEffect.begin(); it != m_lstEffect.end(); it++)
|
||
{
|
||
if(dwEffectCount == dwEffectNumber) { return ((CX3DEffectBase *)(*it))->GetEffectKind(); }
|
||
dwEffectCount++;
|
||
}
|
||
|
||
return 0xFFFFFFFF;
|
||
}
|