port 2A step 4: platform skeleton + rest of the 2V3 header closure

- Mirror the remaining non-Python 2V3 closure headers (98 more, 173 total): EffectLib,
  EterGrnLib, SpeedTreeLib, SphereLib, PRTerrainLib, EterImageLib, EterBase/Poly, cipher/tea,
  EterLib Grp*/IME/Input/MSWindow/StateManager, GameLib actor/map/race headers, EterPack.
- SDK shims: granny.h, SpeedTreeRT.h, imm.h, Dimm.h (the SDK MIDL header, not mirrored),
  dinput/d3dx8 additions; D3D8 render-state enums, FVF macros and the COM resource hierarchy;
  more Win32 GDI/handle types with layout static_asserts.
- PORT edits for MSVC-permissive code (typename, friend visibility, <algorithm>, pointer→uintptr_t)
  and PRTerrainLib/StdAfx.h dropping the ScriptLib/Python include.
- port_logic links the vendored cryptopp/minilzo.
- extension/src/platform: port_platform target with 103 generated stub files (1917 function
  stubs, 146 static members) from the new platform_stub.py (clang -ast-dump-filter);
  MT_PLATFORM_STUB() marks every unimplemented body. libmtgodot links port_platform and
  port_gate.sh builds it.

Gate: macOS, Android, iOS, Windows (mingw) PASS; Linux BLOCKED (no toolchain).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-22 21:46:24 +09:00
co-authored by Claude Opus 5
parent fc47582017
commit 9a8e11f3dd
220 changed files with 24287 additions and 25 deletions
+149
View File
@@ -0,0 +1,149 @@
#pragma once
#include "GrpScreen.h"
#include "../EterBase/Singleton.h"
#include "../SphereLib/spherepack.h"
class CGraphicObjectInstance;
template <class T>
struct RangeTester : public SpherePackCallback
{
T * f;
float dist;
RangeTester(T * fn, float distance=-1)
: f(fn), dist(distance)
{}
virtual ~RangeTester()
{}
virtual void RayTraceCallback(const Vector3d &p1, // source pos of ray
const Vector3d &dir, // dest pos of ray
float distance,
const Vector3d &sect,
SpherePack *sphere)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::RayTraceCallback");
#endif
if (dist<=0.0f || dist>=distance)
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
};
virtual void VisibilityCallback(const Frustum &f,SpherePack *sphere,ViewState state){};
virtual void RangeTestCallback(const Vector3d &p,float distance,SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::RangeTestCallback");
#endif
if (state!=VS_OUTSIDE)
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
}
virtual void PointTest2dCallback(const Vector3d &p, SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::PointTest2dCallback");
#endif
if (state!=VS_OUTSIDE)
{
#ifdef SPHERELIB_STRICT
puts("FIND!!");
#endif
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
}
}
};
class CCullingManager : public CSingleton<CCullingManager>, public SpherePackCallback, private CScreen
{
public:
typedef SpherePack * CullingHandle;
typedef std::vector<CGraphicObjectInstance *> TRangeList;
CCullingManager();
virtual ~CCullingManager();
virtual void RayTraceCallback(const Vector3d &p1, // source pos of ray
const Vector3d &dir, // dest pos of ray
float distance,
const Vector3d &sect,
SpherePack *sphere);
virtual void VisibilityCallback(const Frustum &f,SpherePack *sphere,ViewState state);
void RangeTestCallback(const Vector3d &p,float distance,SpherePack *sphere,ViewState state);
void Reset();
void Update();
void Process();
void FindRange(const Vector3d &p, float radius);
void FindRay(const Vector3d &p1, const Vector3d &dir);
void FindRayDistance(const Vector3d &p1, const Vector3d &dir, float distance);
void RangeTest(const Vector3d& p, float radius, SpherePackCallback* callback)
{
m_Factory->RangeTest(p, radius, callback);
}
void PointTest2d(const Vector3d& p, SpherePackCallback* callback)
{
m_Factory->PointTest2d(p, callback);
}
template <class T>
void ForInRange2d(const Vector3d& p, T* pFunc)
{
RangeTester<T> r(pFunc);
m_Factory->PointTest2d(p, &r);
}
template <class T>
void ForInRange(const Vector3d &p, float radius, T* pFunc)
{
RangeTester<T> r(pFunc);
m_Factory->RangeTest(p, radius, &r/*this*/);
}
template <class T>
void ForInRay(const Vector3d &p1, const Vector3d &dir, T* pFunc)
{
RangeTester<T> r(pFunc);
/*Vector3d p2;
//p2.Set(p.x+(dir.x*50000.0f),p.y+(dir.y*50000.0f),p.z+(dir.z*50000.0f));
p2.x = p.x+50000.0f*dir.x;
p2.y = p.y+50000.0f*dir.y;
p2.z = p.z+50000.0f*dir.z;
// p + (50000.0f*dir);//(p.x+(dir.x*50000.0f),p.y+(dir.y*50000.0f),p.z+(dir.z*50000.0f));*/
m_Factory->RayTrace(p1, dir, &r/*this*/);
}
template <class T>
void ForInRayDistance(const Vector3d &p, const Vector3d &dir, float distance, T* pFunc)
{
RangeTester<T> r(pFunc, distance);
m_Factory->RayTrace(p, dir, &r/*this*/);
}
CullingHandle Register(CGraphicObjectInstance * ob);
void Unregister(CullingHandle h);
TRangeList::iterator begin() { return m_list.begin(); }
TRangeList::iterator end() { return m_list.end(); }
protected:
TRangeList m_list;
float m_RayFarDistance;
SpherePackFactory * m_Factory;
};
+103
View File
@@ -0,0 +1,103 @@
// Decal.h: interface for the CDecal class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_)
#define AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "GrpBase.h"
class CDecal
{
public:
enum
{
MAX_DECAL_VERTICES = 256,
};
CDecal();
virtual ~CDecal();
void Clear();
virtual void Make(D3DXVECTOR3 v3Center, D3DXVECTOR3 v3Normal, D3DXVECTOR3 v3Tangent, float fWidth, float fHeight, float fDepth) = 0;
// virtual void Update();
virtual void Render();
protected:
//
D3DXVECTOR3 m_v3Center;
D3DXVECTOR3 m_v3Normal;
// Clip Plane
D3DXPLANE m_v4LeftPlane;
D3DXPLANE m_v4RightPlane;
D3DXPLANE m_v4BottomPlane;
D3DXPLANE m_v4TopPlane;
D3DXPLANE m_v4FrontPlane;
D3DXPLANE m_v4BackPlane;
// 개수
DWORD m_dwVertexCount;
DWORD m_dwPrimitiveCount;
// 버택스 버퍼와 인댁스 버퍼
// CGraphicVertexBuffer m_GraphicVertexBuffer;
// CGraphicIndexBuffer m_GraphicIndexBuffer;
// 버택스 버퍼와 인댁스 버퍼 대신에 배열 만들고 DrawIndexedPrimitiveUP로 그리자.
typedef struct
{
WORD m_wMinIndex;
DWORD m_dwVertexCount;
DWORD m_dwPrimitiveCount;
DWORD m_dwVBOffset;
} TTRIANGLEFANSTRUCT;
std::vector<TTRIANGLEFANSTRUCT> m_TriangleFanStructVector;
TPDTVertex m_Vertices[MAX_DECAL_VERTICES];
WORD m_Indices[MAX_DECAL_VERTICES];
const float m_cfDecalEpsilon;
protected:
bool AddPolygon(DWORD dwAddCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 *c_pv3Normal);
void ClipMesh(DWORD dwPrimitiveCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 *c_pv3Normal);
DWORD ClipPolygon(DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal) const;
static DWORD ClipPolygonAgainstPlane(const D3DXPLANE& v4Plane,
DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal);
};
/*
class CDecalManager : public CSingleton<CDecalManager>
{
public:
CDecalManager();
~CDecalManager();
void Add(CDecal * pDecal);
void Remove(CDecal * pDecal);
void Update();
void Render();
private:
std::vector<CDecal *> m_DecalPtrVector;
};
*/
#endif // !defined(AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_)
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include "GrpDIB.h"
class CBlockTexture;
class CDibBar
{
public:
CDibBar();
virtual ~CDibBar();
bool Create(HDC hdc, DWORD dwWidth, DWORD dwHeight);
void Invalidate();
void SetClipRect(const RECT & c_rRect);
void ClearBar();
void Render(int ix, int iy);
protected:
DWORD __NearTextureSize(DWORD dwSize);
void __DivideTextureSize(DWORD dwSize, DWORD dwMax, DWORD * pdwxStep, DWORD * pdwxCount, DWORD * pdwxRest);
CBlockTexture * __BuildTextureBlock(DWORD dwxPos, DWORD dwyPos, DWORD dwImageWidth, DWORD dwImageHeight, DWORD dwTextureWidth, DWORD dwTextureHeight);
void __BuildTextureBlockList(DWORD dwWidth, DWORD dwHeight, DWORD dwMax=256);
virtual void OnCreate(){}
protected:
CGraphicDib m_dib;
std::vector<CBlockTexture *> m_kVec_pkBlockTexture;
DWORD m_dwWidth;
DWORD m_dwHeight;
};
@@ -0,0 +1,63 @@
#ifndef __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__
#define __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__
#include <deque>
#include "Thread.h"
#include "Mutex.h"
#include "../EterBase/MappedFile.h"
class CFileLoaderThread
{
public:
typedef struct SData
{
std::string stFileName;
CMappedFile File;
LPVOID pvBuf;
DWORD dwSize;
} TData;
public:
CFileLoaderThread();
~CFileLoaderThread();
int Create(void * arg);
public:
void Request(std::string & c_rstFileName);
bool Fetch(TData ** ppData);
void Shutdown();
protected:
static UINT CALLBACK EntryPoint(void * pThis);
UINT Run(void * arg);
void * Arg() const { return m_pArg; }
void Arg(void * arg) { m_pArg = arg; }
HANDLE m_hThread;
private:
void * m_pArg;
unsigned m_uThreadID;
protected:
UINT Setup();
UINT Execute(void * pvArg);
void Destroy();
void Process();
private:
std::deque<TData *> m_pRequestDeque;
Mutex m_RequestMutex;
std::deque<TData *> m_pCompleteDeque;
Mutex m_CompleteMutex;
HANDLE m_hSemaphore;
int m_iRestSemCount;
bool m_bShutdowned;
};
#endif
+28
View File
@@ -0,0 +1,28 @@
#pragma once
class CGraphicColor
{
public:
CGraphicColor(const CGraphicColor& c_rSrcColor);
CGraphicColor(float r, float g, float b, float a);
CGraphicColor(DWORD color);
CGraphicColor();
~CGraphicColor();
void Clear();
void Set(float r, float g, float b, float a);
void Set(const CGraphicColor& c_rSrcColor);
void Set(DWORD color);
void Blend(float p, const CGraphicColor& c_rSrcColor, const CGraphicColor& c_rDstColor);
DWORD GetPackValue() const;
protected:
float m_r;
float m_g;
float m_b;
float m_a;
};
@@ -0,0 +1,33 @@
#pragma once
#include "GrpColor.h"
#include "Pool.h"
class CGraphicColorInstance
{
public:
CGraphicColorInstance();
virtual ~CGraphicColorInstance();
void Clear();
void SetColorReference(const CGraphicColor& c_rSrcColor);
void BlendColorReference(DWORD blendTime, const CGraphicColor& c_rDstColor);
void Update();
const CGraphicColor& GetCurrentColorReference() const;
protected:
DWORD GetCurrentTime();
protected:
CGraphicColor m_srcColor;
CGraphicColor m_dstColor;
CGraphicColor m_curColor;
DWORD m_baseTime;
DWORD m_blendTime;
};
typedef CDynamicPool<CGraphicColorInstance> TGraphicColorInstancePool;
+35
View File
@@ -0,0 +1,35 @@
#pragma once
class CGraphicDib
{
public:
CGraphicDib();
virtual ~CGraphicDib();
void Destroy();
bool Create(HDC hDC, int width, int height);
void SetBkMode(int iBkMode);
void TextOut(int ix, int iy, const char * c_szText);
void Put(HDC hDC, int x, int y);
int GetWidth();
int GetHeight();
void* GetPointer();
HDC GetDCHandle();
protected:
void Initialize();
protected:
HDC m_hDC;
HBITMAP m_hBmp;
BITMAPINFO m_bmi;
int m_width;
int m_height;
void * m_pvBuf;
};
+74
View File
@@ -0,0 +1,74 @@
#pragma once
#include "GrpBase.h"
#include "GrpDetector.h"
#include "StateManager.h"
class CGraphicDevice : public CGraphicBase
{
public:
enum EDeviceState
{
DEVICESTATE_OK,
DEVICESTATE_BROKEN,
DEVICESTATE_NEEDS_RESET,
DEVICESTATE_NULL
};
enum ECreateReturnValues
{
CREATE_OK = (1 << 0),
CREATE_NO_DIRECTX = (1 << 1),
CREATE_GET_DEVICE_CAPS = (1 << 2),
CREATE_GET_DEVICE_CAPS2 = (1 << 3),
CREATE_DEVICE = (1 << 4),
CREATE_REFRESHRATE = (1 << 5),
CREATE_ENUM = (1 << 6), // 2003. 01. 09. myevan 모드 리스트 얻기 실패
CREATE_DETECT = (1 << 7), // 2003. 01. 09. myevan 모드 선택 실패
CREATE_NO_TNL = (1 << 8),
CREATE_BAD_DRIVER = (1 << 9),
CREATE_FORMAT = (1 << 10),
};
CGraphicDevice();
virtual ~CGraphicDevice();
void InitBackBufferCount(UINT uBackBufferCount);
void Destroy();
int Create(HWND hWnd, int hres, int vres, bool Windowed = true, int bit = 32, int ReflashRate = 0);
EDeviceState GetDeviceState();
bool Reset();
void EnableWebBrowserMode(const RECT& c_rcWebPage);
void DisableWebBrowserMode();
void MoveWebBrowserRect(const RECT& c_rcWebPage);
bool ResizeBackBuffer(UINT uWidth, UINT uHeight);
void RegisterWarningString(UINT uiMsg, const char * c_szString);
protected:
void __Initialize();
bool __IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo);
void __WarningMessage(HWND hWnd, UINT uiMsg);
void __InitializeDefaultIndexBufferList();
void __DestroyDefaultIndexBufferList();
bool __CreateDefaultIndexBufferList();
bool __CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices);
void __InitializePDTVertexBufferList();
void __DestroyPDTVertexBufferList();
bool __CreatePDTVertexBufferList();
DWORD CreatePTStreamVertexShader();
DWORD CreatePNTStreamVertexShader();
DWORD CreatePNT2StreamVertexShader();
DWORD CreateDoublePNTStreamVertexShader();
protected:
DWORD m_uBackBufferCount;
std::map<UINT, std::string> m_kMap_strWarningMessage;
CStateManager* m_pStateManager;
};
@@ -0,0 +1,61 @@
#pragma once
#include "GrpImageInstance.h"
class CGraphicExpandedImageInstance : public CGraphicImageInstance
{
public:
static DWORD Type();
static void DeleteExpandedImageInstance(CGraphicExpandedImageInstance * pkInstance)
{
pkInstance->Destroy();
ms_kPool.Free(pkInstance);
}
enum ERenderingMode
{
RENDERING_MODE_NORMAL,
RENDERING_MODE_SCREEN,
RENDERING_MODE_COLOR_DODGE,
RENDERING_MODE_MODULATE,
};
public:
CGraphicExpandedImageInstance();
virtual ~CGraphicExpandedImageInstance();
void Destroy();
void SetDepth(float fDepth);
void SetOrigin();
void SetOrigin(float fx, float fy);
void SetRotation(float fRotation);
void SetScale(float fx, float fy);
void SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom);
void SetRenderingMode(int iMode);
protected:
void Initialize();
void OnRender();
void OnSetImagePointer();
BOOL OnIsType(DWORD dwType);
protected:
float m_fDepth;
D3DXVECTOR2 m_v2Origin;
D3DXVECTOR2 m_v2Scale;
float m_fRotation;
RECT m_RenderingRect;
int m_iRenderingMode;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicExpandedImageInstance* New();
static void Delete(CGraphicExpandedImageInstance* pkImgInst);
static CDynamicPool<CGraphicExpandedImageInstance> ms_kPool;
};
@@ -0,0 +1,81 @@
#pragma once
#include "GrpTexture.h"
#include "GrpImageTexture.h"
#include "GrpDIB.h"
#include <vector>
#include <map>
class CGraphicFontTexture : public CGraphicTexture
{
public:
typedef std::pair<WORD,wchar_t> TCharacterKey;
typedef struct SCharacterInfomation
{
short index;
short width;
short height;
float left;
float top;
float right;
float bottom;
float advance;
} TCharacterInfomation;
typedef std::vector<TCharacterInfomation*> TPCharacterInfomationVector;
public:
CGraphicFontTexture();
virtual ~CGraphicFontTexture();
void Destroy();
bool Create(const char* c_szFontName, int fontSize, bool bItalic);
bool CreateDeviceObjects();
void DestroyDeviceObjects();
bool CheckTextureIndex(DWORD dwTexture);
void SelectTexture(DWORD dwTexture);
bool UpdateTexture();
TCharacterInfomation* GetCharacterInfomation(WORD codePage, wchar_t keyValue);
TCharacterInfomation* UpdateCharacterInfomation(TCharacterKey code);
bool IsEmpty() const;
protected:
void Initialize();
bool AppendTexture();
HFONT GetFont(WORD codePage);
protected:
typedef std::vector<CGraphicImageTexture*> TGraphicImageTexturePointerVector;
typedef std::map<TCharacterKey, TCharacterInfomation> TCharacterInfomationMap;
typedef std::map<WORD, HFONT> TFontMap;
protected:
CGraphicDib m_dib;
HFONT m_hFontOld;
HFONT m_hFont;
TGraphicImageTexturePointerVector m_pFontTextureVector;
TCharacterInfomationMap m_charInfoMap;
TFontMap m_fontMap;
int m_x;
int m_y;
int m_step;
bool m_isDirty;
TCHAR m_fontName[LF_FACESIZE];
LONG m_fontSize;
bool m_bItalic;
};
@@ -0,0 +1,127 @@
#pragma once
#include "../EterBase/Singleton.h"
#include "GrpBase.h"
#include "Util.h"
#include "Pool.h"
#include <deque>
typedef DWORD TLightID;
enum ELightType
{
LIGHT_TYPE_STATIC, // Continuously turning on light
LIGHT_TYPE_DYNAMIC, // Immediately turning off light
};
class CLightBase
{
public:
CLightBase() {};
virtual ~CLightBase() {};
void SetCurrentTime();
protected:
static float ms_fCurTime;
};
class CLight : public CGraphicBase, public CLightBase
{
public:
CLight();
virtual ~CLight();
void Initialize();
void Clear();
void Update();
void SetParameter(TLightID id, const D3DLIGHT8 & c_rLight);
void SetDistance(float fDistance);
float GetDistance() const { return m_fDistance; }
TLightID GetLightID() { return m_LightID; }
BOOL isEdited() { return m_isEdited; }
void SetDeviceLight(BOOL bActive);
void SetDiffuseColor(float fr, float fg, float fb, float fa = 1.0f);
void SetAmbientColor(float fr, float fg, float fb, float fa = 1.0f);
void SetRange(float fRange);
void SetPosition(float fx, float fy, float fz);
const D3DVECTOR & GetPosition() const;
void BlendDiffuseColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime = 0.0f);
void BlendAmbientColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime = 0.0f);
void BlendRange(float fRange, float fBlendTime, float fDelayTime = 0.0f);
private:
TLightID m_LightID; // Light ID. equal to D3D light index
D3DLIGHT8 m_d3dLight;
BOOL m_isEdited;
float m_fDistance;
TTransitorColor m_DiffuseColorTransitor;
TTransitorColor m_AmbientColorTransitor;
TTransitorFloat m_RangeTransitor;
};
class CLightManager : public CGraphicBase, public CLightBase, public CSingleton<CLightManager>
{
public:
enum
{
LIGHT_LIMIT_DEFAULT = 3,
// LIGHT_MAX_NUM = 32,
};
typedef std::deque<TLightID> TLightIDDeque;
typedef std::map<TLightID, CLight *> TLightMap;
typedef std::vector<CLight *> TLightSortVector;
public:
CLightManager();
virtual ~CLightManager();
void Destroy();
void Initialize();
// NOTE : FlushLight후 렌더링
// 그 후 반드시 RestoreLight를 해줘야만 한다.
void Update();
void FlushLight();
void RestoreLight();
/////
void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT8 & LightData);
CLight * GetLight(TLightID LightID);
void DeleteLight(TLightID LightID);
/////
void SetCenterPosition(const D3DXVECTOR3 & c_rv3Position);
void SetLimitLightCount(DWORD dwLightCount);
void SetSkipIndex(DWORD dwSkipIndex);
protected:
TLightIDDeque m_NonUsingLightIDDeque;
TLightMap m_LightMap;
TLightSortVector m_LightSortVector;
D3DXVECTOR3 m_v3CenterPosition;
DWORD m_dwLimitLightCount;
DWORD m_dwSkipIndex;
protected:
TLightID NewLightID();
void ReleaseLightID(TLightID LightID);
CDynamicPool<CLight> m_LightPool;
};
@@ -0,0 +1,77 @@
#pragma once
#include "GrpImage.h"
#include "Pool.h"
class CGraphicMarkInstance
{
public:
static DWORD Type();
BOOL IsType(DWORD dwType);
void SetImageFileName(const char* c_szFileName);
const std::string& GetImageFileName();
public:
CGraphicMarkInstance();
virtual ~CGraphicMarkInstance();
void Destroy();
void Render();
void SetDepth(float fDepth);
void SetDiffuseColor(float fr, float fg, float fb, float fa);
void SetPosition(float fx, float fy);
void SetIndex(UINT uIndex);
void SetScale(float fScale);
void Load();
bool IsEmpty() const;
int GetWidth();
int GetHeight();
CGraphicTexture * GetTexturePointer();
const CGraphicTexture & GetTextureReference() const;
CGraphicImage * GetGraphicImagePointer();
bool operator == (const CGraphicMarkInstance & rhs) const;
protected:
enum
{
MARK_WIDTH = 16,
MARK_HEIGHT = 12,
};
void Initialize();
virtual void OnRender();
virtual void OnSetImagePointer();
virtual BOOL OnIsType(DWORD dwType);
void SetImagePointer(CGraphicImage * pImage);
protected:
D3DXCOLOR m_DiffuseColor;
D3DXVECTOR2 m_v2Position;
UINT m_uIndex;
FLOAT m_fScale;
FLOAT m_fDepth;
CGraphicImage::TRef m_roImage;
std::string m_stImageFileName;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicMarkInstance* New();
static void Delete(CGraphicMarkInstance* pkImgInst);
static CDynamicPool<CGraphicMarkInstance> ms_kPool;
};
+122
View File
@@ -0,0 +1,122 @@
#pragma once
float CrossProduct2D(float x1, float y1, float x2, float y2);
bool IsInTriangle2D(float ax, float ay, float bx, float by, float cx, float cy, float tx, float ty);
D3DXVECTOR3* D3DXVec3Rotation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXQUATERNION* c_pqtRot);
D3DXVECTOR3* D3DXVec3Translation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXVECTOR3* c_pvtTrans);
void GetRotationFromMatrix(D3DXVECTOR3 * pRotation, const D3DXMATRIX * c_pMatrix);
void GetPivotAndRotationFromMatrix(D3DXMATRIX * pMatrix, D3DXVECTOR3 * pPivot, D3DXVECTOR3 * pRotation);
void ExtractMovement(D3DXMATRIX * pTargetMatrix, D3DXMATRIX * pSourceMatrix);
inline D3DXVECTOR3* D3DXVec3Blend(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc1, const D3DXVECTOR3* c_pvtSrc2, float d)
{
pvtOut->x=c_pvtSrc1->x+d*(c_pvtSrc2->x-c_pvtSrc1->x);
pvtOut->y=c_pvtSrc1->y+d*(c_pvtSrc2->y-c_pvtSrc1->y);
pvtOut->z=c_pvtSrc1->z+d*(c_pvtSrc2->z-c_pvtSrc1->z);
return pvtOut;
}
inline D3DXQUATERNION* D3DXQuaternionBlend(D3DXQUATERNION* pqtOut, const D3DXQUATERNION* c_pqtSrc1, const D3DXQUATERNION* c_pqtSrc2, float d)
{
pqtOut->x=c_pqtSrc1->x+d*(c_pqtSrc2->x-c_pqtSrc1->x);
pqtOut->y=c_pqtSrc1->y+d*(c_pqtSrc2->y-c_pqtSrc1->y);
pqtOut->z=c_pqtSrc1->z+d*(c_pqtSrc2->z-c_pqtSrc1->z);
pqtOut->w=c_pqtSrc1->w+d*(c_pqtSrc2->w-c_pqtSrc1->w);
return pqtOut;
}
inline float ClampDegree(float fDegree)
{
if (fDegree >= 360.0f)
fDegree -= 360.0f;
if (fDegree < 0.0f)
fDegree += 360.0f;
return fDegree;
}
inline float GetVector3Distance(const D3DXVECTOR3 & c_rv3Source, const D3DXVECTOR3 & c_rv3Target)
{
return (c_rv3Source.x-c_rv3Target.x)*(c_rv3Source.x-c_rv3Target.x) + (c_rv3Source.y-c_rv3Target.y)*(c_rv3Source.y-c_rv3Target.y);
}
inline D3DXQUATERNION SafeRotationNormalizedArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
if (vFrom == vTo)
return D3DXQUATERNION(0.0f,0.0f,0.0f,1.0f);
if (vFrom == -vTo)
return D3DXQUATERNION(0.0f,0.0f,1.0f,0.0f);
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &vFrom, &vTo);
float d = D3DXVec3Dot(&vFrom, &vTo);
float s = sqrtf((1+d)*2);
return D3DXQUATERNION(c.x/s,c.y/s,c.z/s,s*0.5f);
}
inline D3DXQUATERNION RotationNormalizedArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &vFrom, &vTo);
float d = D3DXVec3Dot(&vFrom, &vTo);
float s = sqrtf((1+d)*2);
return D3DXQUATERNION(c.x/s,c.y/s,c.z/s,s*0.5f);
}
inline D3DXQUATERNION RotationArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
D3DXVECTOR3 vnFrom, vnTo;
D3DXVec3Normalize(&vnFrom, &vFrom);
D3DXVec3Normalize(&vnTo, &vTo);
return RotationNormalizedArc(vnFrom, vnTo);
}
inline float square_distance_between_linesegment_and_point(const D3DXVECTOR3& p1,const D3DXVECTOR3& p2,const D3DXVECTOR3& x)
{
const auto v1 = p2 - p1;
float l = D3DXVec3LengthSq(&v1);
const auto v2 = x - p1;
const auto v3 = p2 - p1;
float d = D3DXVec3Dot(&(v2),&(v3));
if (d<=0.0f)
{
return D3DXVec3LengthSq(&(v2));
}
else if (d>=l)
{
const auto v4 = x - p2;
return D3DXVec3LengthSq(&(v4));
}
else
{
D3DXVECTOR3 c;
return D3DXVec3LengthSq(D3DXVec3Cross(&c,&(v2),&(v3)))/l;
}
}
inline D3DXVECTOR3 * Vec3TransformQuaternionSafe(D3DXVECTOR3* pvout, const D3DXVECTOR3* pv, const D3DXQUATERNION* pq)
{
D3DXVECTOR3 v;
D3DXVec3Cross(&v,pv,(D3DXVECTOR3*)pq);
v *= -2*pq->w;
v += (pq->w*pq->w - D3DXVec3LengthSq((D3DXVECTOR3*)pq))*(*pv);
v += 2*D3DXVec3Dot((D3DXVECTOR3*)pq,pv)*(*(D3DXVECTOR3*)pq);
*pvout = v;
return pvout;
}
inline D3DXVECTOR3 * Vec3TransformQuaternion(D3DXVECTOR3* pvout, const D3DXVECTOR3* pv, const D3DXQUATERNION* pq)
{
D3DXVec3Cross(pvout,pv,(D3DXVECTOR3*)pq);
*pvout *= -2*pq->w;
*pvout += (pq->w*pq->w - D3DXVec3LengthSq((D3DXVECTOR3*)pq))*(*pv);
*pvout += 2*D3DXVec3Dot((D3DXVECTOR3*)pq,pv)*(*(D3DXVECTOR3*)pq);
return pvout;
}
@@ -0,0 +1,161 @@
#pragma once
#include "GrpColorInstance.h"
#include "GrpScreen.h"
#include "CullingManager.h"
#include "CollisionData.h"
#include "AttributeInstance.h"
enum
{
THING_OBJECT = 0xadf21f13,
TREE_OBJECT = 0x8ac9f7a6,
ACTOR_OBJECT = 0x29a76c24,
EFFECT_OBJECT = 0x1cfa97c6,
DUNGEON_OBJECT = 0x18326035,
};
enum
{
PORTAL_ID_MAX_NUM = 8,
};
class CGraphicObjectInstance : public CGraphicCollisionObject
{
public:
CGraphicObjectInstance();
virtual ~CGraphicObjectInstance();
virtual int GetType() const = 0;
public:
const D3DXVECTOR3 & GetPosition() const;
const D3DXVECTOR3 & GetScale() const;
float GetRotation();
float GetYaw();
float GetPitch();
float GetRoll();
void SetPosition(float x, float y, float z);
void SetPosition(const D3DXVECTOR3 & newposition);
void SetScale(float x, float y, float z);
void SetRotation(float fRotation);
void SetRotation(float fYaw, float fPitch, float fRoll);
void SetRotationQuaternion(const D3DXQUATERNION &q);
void SetRotationMatrix(const D3DXMATRIX & m);
void Clear();
void Update();
bool Render();
void BlendRender();
void RenderToShadowMap();
void RenderShadow();
void RenderPCBlocker();
void Deform();
void Transform();
void Show();
void Hide();
bool isShow();
// Camera Block
void BlockCamera(bool bBlock) {m_BlockCamera = bBlock;}
bool BlockCamera() { return m_BlockCamera; }
// Ray Test
bool isIntersect(const CRay & c_rRay, float * pu, float * pv, float * pt);
// Bounding Box
D3DXVECTOR4 & GetWTBBoxVertex(const unsigned char & c_rucNumTBBoxVertex);
D3DXVECTOR3 & GetTBBoxMin() { return m_v3TBBoxMin; }
D3DXVECTOR3 & GetTBBoxMax() { return m_v3TBBoxMax; }
D3DXVECTOR3 & GetBBoxMin() { return m_v3BBoxMin; }
D3DXVECTOR3 & GetBBoxMax() { return m_v3BBoxMax; }
// Matrix
D3DXMATRIX & GetTransform();
const D3DXMATRIX& GetWorldMatrix() { return m_worldMatrix; }
// Portal
void SetPortal(DWORD dwIndex, int iID);
int GetPortal(DWORD dwIndex);
// Initialize
void Initialize();
virtual void OnInitialize();
// Bounding Sphere
public:
void UpdateBoundingSphere();
void RegisterBoundingSphere();
virtual bool GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius) = 0;
virtual void OnRender() = 0;
virtual void OnBlendRender() = 0;
virtual void OnRenderToShadowMap() = 0;
virtual void OnRenderShadow() = 0;
virtual void OnRenderPCBlocker() = 0;
virtual void OnClear(){}
virtual void OnUpdate(){}
virtual void OnDeform(){}
protected:
D3DXVECTOR3 m_v3Position;
D3DXVECTOR3 m_v3Scale;
float m_fYaw;
float m_fPitch;
float m_fRoll;
D3DXMATRIX m_mRotation;
bool m_isVisible;
D3DXMATRIX m_worldMatrix;
// Camera Block
bool m_BlockCamera;
// Bounding Box
D3DXVECTOR4 m_v4TBBox[8];
D3DXVECTOR3 m_v3TBBoxMin, m_v3TBBoxMax;
D3DXVECTOR3 m_v3BBoxMin, m_v3BBoxMax;
// Portal
BYTE m_abyPortalID[PORTAL_ID_MAX_NUM];
// Culling
CCullingManager::CullingHandle m_CullingHandle;
// Static Collision Data
public:
void AddCollision(const CStaticCollisionData * pscd, const D3DXMATRIX * pMat);
void ClearCollision();
bool CollisionDynamicSphere(const CDynamicSphereInstance & s) const;
bool MovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
D3DXVECTOR3 GetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
void UpdateCollisionData(const CStaticCollisionDataVector * pscdVector = 0);
protected:
CCollisionInstanceVector m_StaticCollisionInstanceVector;
virtual void OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector) = 0;
// using in WorldEditor
public:
DWORD GetCollisionInstanceCount();
CBaseCollisionInstance * GetCollisionInstanceData(DWORD dwIndex);
// Height Data
public:
void SetHeightInstance(CAttributeInstance * pAttributeInstance);
void ClearHeightInstance();
void UpdateHeightInstance(CAttributeInstance * pAttributeInstance = 0);
bool IsObjectHeight();
bool GetObjectHeight(float fX, float fY, float * pfHeight);
protected:
CAttributeInstance * m_pHeightAttributeInstance;
virtual void OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance) = 0;
virtual bool OnGetObjectHeight(float fX, float fY, float * pfHeight) = 0;
};
@@ -0,0 +1,35 @@
#pragma once
#include "GrpTexture.h"
class CGraphicShadowTexture : public CGraphicTexture
{
public:
CGraphicShadowTexture();
virtual ~CGraphicShadowTexture();
void Destroy();
bool Create(int width, int height);
void Begin();
void End();
void Set(int stage = 0) const;
const D3DXMATRIX& GetLightVPMatrixReference() const;
LPDIRECT3DTEXTURE8 GetD3DTexture() const;
protected:
void Initialize();
protected:
D3DXMATRIX m_d3dLightVPMatrix;
D3DVIEWPORT8 m_d3dOldViewport;
LPDIRECT3DTEXTURE8 m_lpd3dShadowTexture;
LPDIRECT3DSURFACE8 m_lpd3dShadowSurface;
LPDIRECT3DSURFACE8 m_lpd3dDepthSurface;
LPDIRECT3DSURFACE8 m_lpd3dOldBackBufferSurface;
LPDIRECT3DSURFACE8 m_lpd3dOldDepthBufferSurface;
};
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include "GrpImage.h"
class CGraphicSubImage : public CGraphicImage
{
public:
typedef CRef<CGraphicImage> TRef;
public:
static TType Type();
static char m_SearchPath[256];
public:
CGraphicSubImage(const char* c_szFileName);
virtual ~CGraphicSubImage();
bool CreateDeviceObjects();
bool SetImageFileName(const char* c_szFileName);
void SetRectPosition(int left, int top, int right, int bottom);
void SetRectReference(const RECT& c_rRect);
static void SetSearchPath(const char * c_szFileName);
protected:
void SetImagePointer(CGraphicImage* pImage);
bool OnLoad(int iSize, const void* c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
protected:
CGraphicImage::TRef m_roImage;
};
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "Resource.h"
#include "Ref.h"
#include "GrpFontTexture.h"
class CGraphicText : public CResource
{
public:
typedef CRef<CGraphicText> TRef;
public:
static TType Type();
public:
CGraphicText(const char* c_szFileName);
virtual ~CGraphicText();
virtual bool CreateDeviceObjects();
virtual void DestroyDeviceObjects();
CGraphicFontTexture * GetFontTexturePointer();
protected:
bool OnLoad(int iSize, const void * c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
protected:
CGraphicFontTexture m_fontTexture;
};
@@ -0,0 +1,134 @@
#ifndef __INC_ETERLIB_GRPTEXTINSTANCE_H__
#define __INC_ETERLIB_GRPTEXTINSTANCE_H__
#include "Pool.h"
#include "GrpText.h"
class CGraphicTextInstance
{
public:
typedef CDynamicPool<CGraphicTextInstance> TPool;
public:
enum EHorizontalAlign
{
HORIZONTAL_ALIGN_LEFT = 0x01,
HORIZONTAL_ALIGN_CENTER = 0x02,
HORIZONTAL_ALIGN_RIGHT = 0x03,
};
enum EVerticalAlign
{
VERTICAL_ALIGN_TOP = 0x10,
VERTICAL_ALIGN_CENTER = 0x20,
VERTICAL_ALIGN_BOTTOM = 0x30
};
public:
static void Hyperlink_UpdateMousePos(int x, int y);
static int Hyperlink_GetText(char* buf, int len);
public:
CGraphicTextInstance();
virtual ~CGraphicTextInstance();
void Destroy();
void Update();
void Render(RECT * pClipRect = NULL);
void ShowCursor();
void HideCursor();
void ShowOutLine();
void HideOutLine();
void SetColor(DWORD color);
void SetColor(float r, float g, float b, float a = 1.0f);
void SetOutLineColor(DWORD color);
void SetOutLineColor(float r, float g, float b, float a = 1.0f);
void SetHorizonalAlign(int hAlign);
void SetVerticalAlign(int vAlign);
void SetMax(int iMax);
void SetTextPointer(CGraphicText* pText);
void SetValueString(const std::string& c_stValue);
void SetValue(const char* c_szValue, size_t len = -1);
void SetPosition(float fx, float fy, float fz = 0.0f);
void SetSecret(bool Value);
void SetOutline(bool Value);
void SetFeather(bool Value);
void SetMultiLine(bool Value);
void SetLimitWidth(float fWidth);
void GetTextSize(int* pRetWidth, int* pRetHeight);
const std::string& GetValueStringReference();
WORD GetTextLineCount();
int PixelPositionToCharacterPosition(int iPixelPosition);
int GetHorizontalAlign();
protected:
void __Initialize();
int __DrawCharacter(CGraphicFontTexture * pFontTexture, WORD codePage, wchar_t text, DWORD dwColor);
void __GetTextPos(DWORD index, float* x, float* y);
int __GetTextTag(const wchar_t * src, int maxLen, int & tagLen, std::wstring & extraInfo);
protected:
struct SHyperlink
{
short sx;
short ex;
std::wstring text;
SHyperlink() : sx(0), ex(0) { }
};
protected:
DWORD m_dwTextColor;
DWORD m_dwOutLineColor;
WORD m_textWidth;
WORD m_textHeight;
BYTE m_hAlign;
BYTE m_vAlign;
WORD m_iMax;
float m_fLimitWidth;
bool m_isCursor;
bool m_isSecret;
bool m_isMultiLine;
bool m_isOutline;
float m_fFontFeather;
/////
std::string m_stText;
D3DXVECTOR3 m_v3Position;
private:
bool m_isUpdate;
bool m_isUpdateFontTexture;
CGraphicText::TRef m_roText;
CGraphicFontTexture::TPCharacterInfomationVector m_pCharInfoVector;
std::vector<DWORD> m_dwColorInfoVector;
std::vector<SHyperlink> m_hyperlinkVector;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicTextInstance* New();
static void Delete(CGraphicTextInstance* pkInst);
static CDynamicPool<CGraphicTextInstance> ms_kPool;
};
extern const char* FindToken(const char* begin, const char* end);
extern int ReadToken(const char* token);
#endif
+208
View File
@@ -0,0 +1,208 @@
#pragma once
#include <imm.h>
#pragma comment(lib, "imm32.lib")
#include "Dimm.h"
class IIMEEventSink
{
public:
virtual bool OnWM_CHAR( WPARAM wParam, LPARAM lParam ) = 0;
virtual void OnUpdate() = 0;
virtual void OnChangeCodePage() = 0;
virtual void OnOpenCandidateList() = 0;
virtual void OnCloseCandidateList() = 0;
virtual void OnOpenReadingWnd() = 0;
virtual void OnCloseReadingWnd() = 0;
};
class CIME
{
public:
enum
{
IMEREADING_MAXLEN = 128,
IMESTR_MAXLEN = 1024,
IMECANDIDATE_MAXLEN = 32768,
MAX_CANDLIST = 10,
MAX_CANDIDATE_LENGTH = 256
};
public:
CIME();
virtual ~CIME();
bool Initialize(HWND hWnd);
void Uninitialize(void);
static void Clear();
void SetMax(int iMax);
void SetUserMax(int iMax);
void SetText(const char* c_szText, int len);
int GetText(std::string & rstrText, bool addCodePage=false);
const char* GetCodePageText();
int GetCodePage();
// Candidate List
int GetCandidateCount();
int GetCandidatePageCount();
int GetCandidate(DWORD index, std::string & rstrText);
int GetCandidateSelection();
// Reading Information
int GetReading(std::string & rstrText);
int GetReadingError();
void SetInputMode(DWORD dwMode);
DWORD GetInputMode();
bool IsIMEEnabled();
void EnableIME(bool bEnable=true);
void DisableIME();
void EnableCaptureInput();
void DisableCaptureInput();
bool IsCaptureEnabled();
void SetNumberMode();
void SetStringMode();
bool __IsWritable(wchar_t key);
void AddExceptKey(wchar_t key);
void ClearExceptKey();
void PasteTextFromClipBoard();
void EnablePaste(bool bFlag);
void PasteString(const char * str);
static void FinalizeString(bool bSend = false);
void UseDefaultIME();
static int GetCurPos();
static int GetCompLen();
static int GetULBegin();
static int GetULEnd();
static void CloseCandidateList();
static void CloseReadingInformation();
static void ChangeInputLanguage();
static void ChangeInputLanguageWorker();
LRESULT WMInputLanguage(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMStartComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMEndComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMNotify(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMChar(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
protected:
void IncCurPos();
void DecCurPos();
void SetCurPos(int offset);
void DelCurPos();
protected:
static void CheckInputLocale();
static void CheckToggleState();
static void SetSupportLevel( DWORD dwImeLevel );
void InsertString(wchar_t* szString, int iSize);
void OnChar(wchar_t c);
UINT GetCodePageFromLang( LANGID langid );
void ResultProcess(HIMC hImc);
void CompositionProcessBuilding(HIMC hImc);
void CompositionProcess(HIMC hImc);
void AttributeProcess(HIMC hImc);
void CandidateProcess(HIMC hImc);
void ReadingProcess(HIMC hImc);
bool IsMax(const wchar_t* wInput, int len);
DWORD GetImeId(UINT uIndex = 0);
bool GetReadingWindowOrientation();
static void SetupImeApi();
static INPUTCONTEXT* (WINAPI * _ImmLockIMC)( HIMC );
static BOOL (WINAPI * _ImmUnlockIMC)( HIMC );
static LPVOID (WINAPI * _ImmLockIMCC)( HIMCC );
static BOOL (WINAPI * _ImmUnlockIMCC)( HIMCC );
static UINT (WINAPI * _GetReadingString)( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT );
static BOOL (WINAPI * _ShowReadingWindow)( HIMC, BOOL );
protected:
HIMC m_hOrgIMC;
int m_max;
int m_userMax;
BOOL m_bOnlyNumberMode;
std::vector<wchar_t> m_exceptKey;
bool m_bEnablePaste;
bool m_bUseDefaultIME;
public:
static bool ms_bInitialized;
static bool ms_bDisableIMECompletely;
static bool ms_bUILessMode;
static bool ms_bImeEnabled;
static bool ms_bCaptureInput;
static bool ms_bChineseIME;
static bool ms_bUseIMMCandidate;
static HWND ms_hWnd;
static HKL ms_hklCurrent;
static char ms_szKeyboardLayout[KL_NAMELENGTH+1];
static OSVERSIONINFOA ms_stOSVI;
static HINSTANCE ms_hImm32Dll;
static HINSTANCE ms_hCurrentImeDll;
static DWORD ms_dwImeState;
static DWORD ms_adwId[2];
// IME Level
static DWORD ms_dwIMELevel;
static DWORD ms_dwIMELevelSaved;
// Candidate List
static bool ms_bCandidateList;
static DWORD ms_dwCandidateCount;
static bool ms_bVerticalCandidate;
static int ms_iCandListIndexBase;
static WCHAR ms_wszCandidate[CIME::MAX_CANDLIST][MAX_CANDIDATE_LENGTH];
static DWORD ms_dwCandidateSelection;
static DWORD ms_dwCandidatePageSize;
// Reading Information
static bool ms_bReadingInformation;
static int ms_iReadingError;
static bool ms_bHorizontalReading;
static std::vector<wchar_t> ms_wstrReading;
// Indicator
static wchar_t* ms_wszCurrentIndicator;
static IIMEEventSink* ms_pEvent;
wchar_t m_wszComposition[IMESTR_MAXLEN];
static wchar_t m_wText[IMESTR_MAXLEN];
static int ms_compLen;
static int ms_curpos;
static int ms_lastpos;
static int ms_ulbegin;
static int ms_ulend;
static UINT ms_uOutputCodePage;
static UINT ms_uInputCodePage;
};
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
#endif
class CInputDevice
{
public:
CInputDevice();
virtual ~CInputDevice();
HRESULT CreateDevice(HWND hWnd);
protected:
static LPDIRECTINPUT8 ms_lpDI;
};
class CInputKeyboard : public CInputDevice
{
public:
CInputKeyboard();
virtual ~CInputKeyboard();
bool InitializeKeyboard(HWND hWnd);
void UpdateKeyboard();
void ResetKeyboard();
bool IsPressed(int iIndex);
void KeyDown(int iIndex);
void KeyUp(int iIndex);
protected:
virtual void OnKeyDown(int iIndex) = 0;
virtual void OnKeyUp(int iIndex) = 0;
protected:
static LPDIRECTINPUTDEVICE8 ms_lpKeyboard;
static bool ms_bPressedKey[256];
static char ms_diks[256];
};
+125
View File
@@ -0,0 +1,125 @@
///////////////////////////////////////////////////////////////////////
// CLensFlare Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
///////////////////////////////////////////////////////////////////////
// Preprocessor
#pragma once
#include "GrpImageInstance.h"
#include "GrpScreen.h"
#include <float.h>
#include <string>
#include <vector>
///////////////////////////////////////////////////////////////////////
// Constants
const float c_fHalfMaxBright = 0.45f;
const float c_fDistanceScale = 1.0f;
const int c_nDepthTestDimension = 15;
///////////////////////////////////////////////////////////////////////
// CFlare
class CFlare
{
public:
void Draw(float fBrightScale, int nWidth, int nHeight, int nX, int nY);
void Init(std::string strPath);
CFlare();
virtual ~CFlare();
private:
struct SFlarePiece
{
SFlarePiece() :
m_fPosition(0.0f),
m_fWidth(0.0f),
m_pColor(NULL)
{
}
CGraphicImageInstance m_imageInstance;
float m_fPosition; // -1.0 = light location, 0.0 = center, 1.0 = far end of flare
float m_fWidth; // height = width
float * m_pColor;
};
std::vector<SFlarePiece *> m_vFlares;
};
///////////////////////////////////////////////////////////////////////
// CLensFlare
class CLensFlare : public CScreen
{
public:
CLensFlare();
virtual ~CLensFlare();
void Compute(const D3DXVECTOR3 & c_rv3LightDirection); // D3DTS_VIEW로 부터 카메라 방향을 얻어오므로, 카메라 설정 뒤에 해야 함.
void DrawBeforeFlare();
void DrawAfterFlare();
void DrawFlare();
void SetMainFlare(std::string strSunFile, float fSunSize);
void Initialize(std::string strPath);
void SetFlareLocation(double dX, double dY);
void SetVisible(bool bState) { m_bFlareVisible = bState; }
bool IsVisible() { return m_bFlareVisible; }
void SetBrightnesses(float fBeforeBright, float fAfterBright);
void ReadControlPixels();
void AdjustBrightness();
void CharacterizeFlare(bool bEnabled, bool bShowMainFlare, float fMaxBrightness, const D3DXCOLOR & c_rColor);
protected:
float Interpolate(float fStart, float fEnd, float fPercent);
private:
float m_afFlarePos[2], m_afFlareWinPos[2];
float m_fBeforeBright, m_fAfterBright;
bool m_bFlareVisible, m_bDrawFlare, m_bDrawBrightScreen;
float m_fSunSize;
CFlare m_cFlare;
float * m_pControlPixels;
float * m_pTestPixels;
bool m_bEnabled;
bool m_bShowMainFlare;
float m_fMaxBrightness;
float m_afColor[4];
CGraphicImageInstance m_SunFlareImageInstance;
void ReadDepthPixels(float * pPixels);
void ClampBrightness();
};
@@ -0,0 +1,22 @@
#pragma once
#include "MSWindow.h"
class CMSApplication : public CMSWindow
{
public:
CMSApplication();
virtual ~CMSApplication();
void Initialize(HINSTANCE hInstance);
void MessageLoop();
bool IsMessage();
bool MessageProcess();
protected:
void ClearWindowClass();
LRESULT WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
};
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include "../EterBase/Stl.h"
class CMSWindow
{
public:
CMSWindow();
virtual ~CMSWindow();
void Destroy();
bool Create(const char* c_szName, int brush=BLACK_BRUSH, DWORD cs=0, DWORD ws=WS_OVERLAPPEDWINDOW, HICON hIcon=NULL, int iCursorResource=32512);
void Show();
void Hide();
void SetVisibleMode(bool isVisible);
void SetPosition(int x, int y);
void SetCenterPosition();
void SetText(const char* c_szText);
void AdjustSize(int width, int height);
void SetSize(int width, int height);
bool IsVisible();
bool IsActive();
void GetMousePosition(POINT* ppt);
void GetClientRect(RECT* prc);
void GetWindowRect(RECT* prc);
int GetScreenWidth();
int GetScreenHeight();
HWND GetWindowHandle();
HINSTANCE GetInstance();
virtual LRESULT WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
virtual void OnSize(WPARAM wParam, LPARAM lParam);
protected:
const char* RegisterWindowClass(DWORD style, int brush, WNDPROC pfnWndProc, HICON hIcon=NULL, int iCursorResource=32512);
protected:
typedef std::set<char*, stl_sz_less> TWindowClassSet;
protected:
HWND m_hWnd;
RECT m_rect;
bool m_isActive;
bool m_isVisible;
protected:
static TWindowClassSet ms_stWCSet;
static HINSTANCE ms_hInstance;
};
+113
View File
@@ -0,0 +1,113 @@
#pragma once
#ifdef _IMPROVED_PACKET_ENCRYPTION_
#include "../EterBase/cipher.h"
#endif
#include "../EterBase/tea.h"
#include "NetAddress.h"
class CNetworkStream
{
public:
CNetworkStream();
virtual ~CNetworkStream();
void SetRecvBufferSize(int recvBufSize);
void SetSendBufferSize(int sendBufSize);
#ifndef _IMPROVED_PACKET_ENCRYPTION_
void SetSecurityMode(bool isSecurityMode, const char* c_szTeaKey);
void SetSecurityMode(bool isSecurityMode, const char* c_szTeaEncryptKey, const char* c_szTeaDecryptKey);
#endif
bool IsSecurityMode();
int GetRecvBufferSize();
void Clear();
void ClearRecvBuffer();
void Process();
bool Connect(const CNetworkAddress& c_rkNetAddr, int limitSec = 3);
bool Connect(const char* c_szAddr, int port, int limitSec = 3);
bool Connect(DWORD dwAddr, int port, int limitSec = 3);
void Disconnect();
bool Peek(int len);
bool Peek(int len, char* pDestBuf);
bool Recv(int len);
bool Recv(int len, char* pDestBuf);
bool Send(int len, const char* pSrcBuf);
bool Peek(int len, void* pDestBuf);
bool Recv(int len, void* pDestBuf);
bool Send(int len, const void* pSrcBuf);
bool SendFlush(int len, const void* pSrcBuf);
bool IsOnline();
void SetPacketSequenceMode(bool isOn);
bool SendSequence();
protected:
virtual void OnConnectSuccess();
virtual void OnConnectFailure();
virtual void OnRemoteDisconnect();
virtual void OnDisconnect();
virtual bool OnProcess();
bool __SendInternalBuffer();
bool __RecvInternalBuffer();
void __PopSendBuffer();
int __GetSendBufferSize();
#ifdef _IMPROVED_PACKET_ENCRYPTION_
size_t Prepare(void* buffer, size_t* length);
bool Activate(size_t agreed_length, const void* buffer, size_t length);
void ActivateCipher();
#endif
private:
time_t m_connectLimitTime;
char* m_recvTEABuf;
int m_recvTEABufInputPos;
int m_recvTEABufSize;
char* m_recvBuf;
int m_recvBufSize;
int m_recvBufInputPos;
int m_recvBufOutputPos;
char* m_sendBuf;
int m_sendBufSize;
int m_sendBufInputPos;
int m_sendBufOutputPos;
char* m_sendTEABuf;
int m_sendTEABufSize;
int m_sendTEABufInputPos;
bool m_isOnline;
#ifdef _IMPROVED_PACKET_ENCRYPTION_
Cipher m_cipher;
#else
// Obsolete encryption stuff here
bool m_isSecurityMode;
char m_szEncryptKey[TEA_KEY_LENGTH]; // Client 에서 보낼 패킷을 Encrypt 할때 사용하는 Key
char m_szDecryptKey[TEA_KEY_LENGTH]; // Server 에서 전송된 패킷을 Decrypt 할때 사용하는 Key
#endif
SOCKET m_sock;
CNetworkAddress m_addr;
// Sequence
DWORD m_iSequence;
bool m_bUseSequence;
std::vector<BYTE> m_kVec_bSequenceTable;
};
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "../EterBase/Debug.h"
#include <algorithm> // PORT: std::find below; MSVC's headers pulled it in transitively
//#define DYNAMIC_POOL_STRICT
+264
View File
@@ -0,0 +1,264 @@
#pragma once
#include "../EterBase/Timer.h"
#include "../EterBase/Debug.h"
/*
class CProfiler : public CSingleton<CProfiler>
{
public:
enum
{
STACK_DATA_MAX_NUM = 64,
};
public:
typedef struct SProfileStackData
{
int iCallStep;
long iStartTime;
long iEndTime;
std::string strName;
} TProfileStackData;
typedef struct SProfileAccumulationData
{
int iStartTime;
int iCallingCount;
int iCollapsedTime;
std::string strName;
} TProfileAccumulationData;
typedef std::map<std::string, CGraphicTextInstance*> TGraphicTextInstanceMap;
typedef std::map<std::string, TProfileAccumulationData> TProfileAccumulationDataMap;
public:
CProfiler()
{
Clear();
m_ProfileAccumulationDataMap.clear();
}
virtual ~CProfiler()
{
}
void Clear()
{
m_ProfileStackDataCount = 0;
m_iCallStep = 0;
TProfileAccumulationDataMap::iterator itor = m_ProfileAccumulationDataMap.begin();
for (; itor != m_ProfileAccumulationDataMap.end(); ++itor)
{
TProfileAccumulationData & rData = itor->second;
rData.iCallingCount = 0;
rData.iCollapsedTime = 0;
}
}
void Push(const char * c_szName)
{
assert(m_ProfileStackDataCount < STACK_DATA_MAX_NUM);
TProfileStackData & rProfileStackData = m_ProfileStackDatas[m_ProfileStackDataCount++];
rProfileStackData.iCallStep = m_iCallStep;
rProfileStackData.iStartTime = ELTimer_GetMSec();
rProfileStackData.strName = c_szName;
++m_iCallStep;
TGraphicTextInstanceMap::iterator itor = m_GraphicTextInstanceMap.find(c_szName);
if (m_GraphicTextInstanceMap.end() == itor)
{
CGraphicTextInstance * pGraphicTextInstance = CGraphicTextInstance::New();
CResource * pResource = CResourceManager::Instance().GetResourcePointer("굴림체.fnt");
pGraphicTextInstance->Clear();
pGraphicTextInstance->SetTextPointer(static_cast<CGraphicText*>(pResource));
m_GraphicTextInstanceMap.insert(TGraphicTextInstanceMap::value_type(c_szName, pGraphicTextInstance));
}
}
void Pop(const char * c_szName)
{
TProfileStackData * pProfileStackData;
if (!GetProfileStackDataPointer(c_szName, &pProfileStackData))
{
assert(!"The name doesn't exist");
return;
}
pProfileStackData->iEndTime = ELTimer_GetMSec();
--m_iCallStep;
}
void PushAccumulation(const char * c_szName)
{
TProfileAccumulationDataMap::iterator itor = m_ProfileAccumulationDataMap.find(c_szName);
if (itor == m_ProfileAccumulationDataMap.end())
{
TProfileAccumulationData ProfileAccumulationData;
ProfileAccumulationData.iCollapsedTime = 0;
ProfileAccumulationData.iCallingCount = 0;
ProfileAccumulationData.strName = c_szName;
m_ProfileAccumulationDataMap.insert(TProfileAccumulationDataMap::value_type(c_szName, ProfileAccumulationData));
itor = m_ProfileAccumulationDataMap.find(c_szName);
/////
CGraphicTextInstance * pGraphicTextInstance = m_GraphicTextInstancePool.Alloc();
CResource * pResource = CResourceManager::Instance().GetResourcePointer("굴림체.fnt");
pGraphicTextInstance->Clear();
pGraphicTextInstance->SetTextPointer(static_cast<CGraphicText*>(pResource));
m_GraphicTextInstanceMap.insert(TGraphicTextInstanceMap::value_type(c_szName, pGraphicTextInstance));
}
TProfileAccumulationData & rData = itor->second;
rData.iStartTime = ELTimer_GetMSec();
}
void PopAccumulation(const char * c_szName)
{
TProfileAccumulationDataMap::iterator itor = m_ProfileAccumulationDataMap.find(c_szName);
if (itor == m_ProfileAccumulationDataMap.end())
return;
TProfileAccumulationData & rData = itor->second;
rData.iCollapsedTime += ELTimer_GetMSec() - rData.iStartTime;
++rData.iCallingCount;
}
void ProfileByConsole()
{
for (int i = 0; i < m_ProfileStackDataCount; ++i)
{
TProfileStackData & rProfileStackData = m_ProfileStackDatas[i];
// for (int i = 0; i < rProfileStackData.iCallStep; ++i)
// Tracef("\t");
Tracef("%-10s: %2d\t", rProfileStackData.strName.c_str(), rProfileStackData.iEndTime - rProfileStackData.iStartTime);
}
Tracef("\n");
}
void ProfileOneStackDataByConsole(const char * c_szName)
{
TProfileStackData * pProfileStackData;
if (!GetProfileStackDataPointer(c_szName, &pProfileStackData))
{
return;
}
Tracef("%-10s: %3d\n", pProfileStackData->strName.c_str(), pProfileStackData->iEndTime - pProfileStackData->iStartTime);
}
void ProfileOneAccumulationDataByConsole(const char * c_szName)
{
TProfileAccumulationDataMap::iterator itor = m_ProfileAccumulationDataMap.find(c_szName);
if (itor == m_ProfileAccumulationDataMap.end())
return;
TProfileAccumulationData & rData = itor->second;
Tracef("%-10s : [CollapsedTime : %3d] / [CallingCount : %3d]\n", rData.strName.c_str(),
rData.iCollapsedTime,
rData.iCallingCount);
}
void ProfileByScreen()
{
float fxPosition = 0;
float fyPosition = 10;
char szText[128];
for (int i = 0; i < m_ProfileStackDataCount; ++i)
{
TProfileStackData & rProfileStackData = m_ProfileStackDatas[i];
TGraphicTextInstanceMap::iterator itor = m_GraphicTextInstanceMap.find(rProfileStackData.strName);
if (m_GraphicTextInstanceMap.end() != itor)
{
CGraphicTextInstance * pGraphicTextInstance = itor->second;
fxPosition = 10 + (float) rProfileStackData.iCallStep * 10 * 4;
sprintf(szText, "%-10s : %3d", rProfileStackData.strName.c_str(), rProfileStackData.iEndTime - rProfileStackData.iStartTime);
pGraphicTextInstance->SetColor(0.7f, 0.7f, 0.7f);
pGraphicTextInstance->SetValue(szText, strlen(szText));
pGraphicTextInstance->SetPosition(fxPosition, fyPosition);
pGraphicTextInstance->Update();
pGraphicTextInstance->Render();
fyPosition += 17;
}
}
fxPosition = 10;
fyPosition += 10;
TProfileAccumulationDataMap::iterator itor = m_ProfileAccumulationDataMap.begin();
for (; itor != m_ProfileAccumulationDataMap.end(); ++itor)
{
TProfileAccumulationData & rData = itor->second;
TGraphicTextInstanceMap::iterator itor = m_GraphicTextInstanceMap.find(rData.strName);
if (m_GraphicTextInstanceMap.end() != itor)
{
CGraphicTextInstance * pGraphicTextInstance = itor->second;
sprintf(szText, "%-10s : [CollapsedTime : %3d] / [CallingCount : %3d]", rData.strName.c_str(),
rData.iCollapsedTime,
rData.iCallingCount);
pGraphicTextInstance->SetColor(0.7f, 0.7f, 0.7f);
pGraphicTextInstance->SetValue(szText, strlen(szText));
pGraphicTextInstance->SetPosition(fxPosition, fyPosition);
pGraphicTextInstance->Update();
pGraphicTextInstance->Render();
fyPosition += 17;
}
}
}
protected:
bool GetProfileStackDataPointer(const char * c_szName, TProfileStackData ** ppProfileStackData)
{
for (int i = 0; i < m_ProfileStackDataCount; ++i)
{
if (0 == m_ProfileStackDatas[i].strName.compare(c_szName))
{
*ppProfileStackData = &m_ProfileStackDatas[i];
return true;
}
}
return false;
}
protected:
// Profile Stack Data
int m_ProfileStackDataCount;
TProfileStackData m_ProfileStackDatas[STACK_DATA_MAX_NUM];
// Profile Increase Data
TProfileAccumulationDataMap m_ProfileAccumulationDataMap;
int m_iCallStep;
TGraphicTextInstanceMap m_GraphicTextInstanceMap;
};
*/
@@ -0,0 +1,73 @@
#pragma once
#include "Resource.h"
#include "FileLoaderThread.h"
#include <set>
#include <map>
#include <string>
class CResourceManager : public CSingleton<CResourceManager>
{
public:
CResourceManager();
virtual ~CResourceManager();
void LoadStaticCache(const char* c_szFileName);
void DestroyDeletingList();
void Destroy();
void BeginThreadLoading();
void EndThreadLoading();
CResource * InsertResourcePointer(DWORD dwFileCRC, CResource* pResource);
CResource * FindResourcePointer(DWORD dwFileCRC);
CResource * GetResourcePointer(const char * c_szFileName);
CResource * GetTypeResourcePointer(const char * c_szFileName, int iType=-1);
// 추가
bool isResourcePointerData(DWORD dwFileCRC);
void RegisterResourceNewFunctionPointer(const char* c_szFileExt, CResource* (*pResNewFunc)(const char* c_szFileName));
void RegisterResourceNewFunctionByTypePointer(int iType, CResource* (*pNewFunc) (const char* c_szFileName));
void DumpFileListToTextFile(const char* c_szFileName);
bool IsFileExist(const char * c_szFileName);
void Update();
void ReserveDeletingResource(CResource * pResource);
public:
void ProcessBackgroundLoading();
void PushBackgroundLoadingSet(std::set<std::string> & LoadingSet);
protected:
void __DestroyDeletingResourceMap();
void __DestroyResourceMap();
void __DestroyCacheMap();
DWORD __GetFileCRC(const char * c_szFileName, const char ** c_pszLowerFile = NULL);
protected:
typedef std::map<DWORD, CResource *> TResourcePointerMap;
typedef std::map<std::string, CResource* (*)(const char*)> TResourceNewFunctionPointerMap;
typedef std::map<int, CResource* (*)(const char*)> TResourceNewFunctionByTypePointerMap;
typedef std::map<CResource *, DWORD> TResourceDeletingMap;
typedef std::map<DWORD, std::string> TResourceRequestMap;
typedef std::map<long, CResource*> TResourceRefDecreaseWaitingMap;
protected:
TResourcePointerMap m_pCacheMap;
TResourcePointerMap m_pResMap;
TResourceNewFunctionPointerMap m_pResNewFuncMap;
TResourceNewFunctionByTypePointerMap m_pResNewFuncByTypeMap;
TResourceDeletingMap m_ResourceDeletingMap;
TResourceRequestMap m_RequestMap; // 쓰레드로 로딩 요청한 리스트
TResourceRequestMap m_WaitingMap;
TResourceRefDecreaseWaitingMap m_pResRefDecreaseWaitingMap;
static CFileLoaderThread ms_loadingThread;
};
extern int g_iLoadingDelayTime;
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include "GrpScreen.h"
class CScreenFilter : public CScreen
{
public:
CScreenFilter();
virtual ~CScreenFilter();
void SetEnable(BOOL bFlag);
void SetBlendType(BYTE bySrcType, BYTE byDestType);
void SetColor(const D3DXCOLOR & c_rColor);
void Render();
protected:
BOOL m_bEnable;
BYTE m_bySrcType;
BYTE m_byDestType;
D3DXCOLOR m_Color;
};
+341
View File
@@ -0,0 +1,341 @@
/******************************************************************************
Copyright (C) 1999, 2000 NVIDIA Corporation
This file is provided without support, instruction, or implied warranty of any
kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.
Comments:
A simple class to manage rendering state. Created as a singleton.
Create it as a static global, or with new. It doesn't matter as long as it is created
before you use the CStateManager::GetSingleton() API to get a reference to it.
Call it with STATEMANAGER.SetRenderState(...)
Call it with STATEMANAGER.SetTextureStageState(...), etc.
Call the 'Save' versions of the function if you want to deviate from the current state.
Call the 'Restore' version to retrieve the last Save.
There are two levels of caching:
- All Sets/Saves/Restores are tracked for redundancy. This reduces the size of the batch to
be flushed
- The flush function is called before rendering, and only copies state that is
different from the current chip state.
If you get an assert it is probably because an API call failed.
See NVLink for a good example of how this class is used.
Don't be afraid of the vector being used to track the flush batch. It will grow as big as
it needs to be and then stop, so it shouldn't be reallocated.
The state manager holds a reference to the d3d device.
- cmaughan@nvidia.com
******************************************************************************/
#ifndef __CSTATEMANAGER_H
#define __CSTATEMANAGER_H
#include <d3d8.h>
#include <d3dx8.h>
#include <vector>
#include "../EterBase/Singleton.h"
#define CHECK_D3DAPI(a) \
{ \
HRESULT hr = (a); \
\
if (hr != S_OK) \
assert(!#a); \
}
static const DWORD STATEMANAGER_MAX_RENDERSTATES = 256;
static const DWORD STATEMANAGER_MAX_TEXTURESTATES = 128;
static const DWORD STATEMANAGER_MAX_STAGES = 8;
static const DWORD STATEMANAGER_MAX_VCONSTANTS = 96;
static const DWORD STATEMANAGER_MAX_PCONSTANTS = 8;
static const DWORD STATEMANAGER_MAX_TRANSFORMSTATES = 300; // World1 lives way up there...
static const DWORD STATEMANAGER_MAX_STREAMS = 16;
class CStreamData
{
public:
CStreamData(LPDIRECT3DVERTEXBUFFER8 pStreamData = NULL, UINT Stride = 0) : m_lpStreamData(pStreamData), m_Stride(Stride)
{
}
bool operator == (const CStreamData& rhs) const
{
return ((m_lpStreamData == rhs.m_lpStreamData) && (m_Stride == rhs.m_Stride));
}
LPDIRECT3DVERTEXBUFFER8 m_lpStreamData;
UINT m_Stride;
};
class CIndexData
{
public:
CIndexData(LPDIRECT3DINDEXBUFFER8 pIndexData = NULL, UINT BaseVertexIndex = 0)
: m_lpIndexData(pIndexData),
m_BaseVertexIndex(BaseVertexIndex)
{
}
bool operator == (const CIndexData& rhs) const
{
return ((m_lpIndexData == rhs.m_lpIndexData) && (m_BaseVertexIndex == rhs.m_BaseVertexIndex));
}
LPDIRECT3DINDEXBUFFER8 m_lpIndexData;
UINT m_BaseVertexIndex;
};
// State types managed by the class
typedef enum eStateType
{
STATE_MATERIAL = 0,
STATE_RENDER,
STATE_TEXTURE,
STATE_TEXTURESTAGE,
STATE_VSHADER,
STATE_PSHADER,
STATE_TRANSFORM,
STATE_VCONSTANT,
STATE_PCONSTANT,
STATE_STREAM,
STATE_INDEX
} eStateType;
class CStateID
{
public:
CStateID(eStateType Type, DWORD dwValue0 = 0, DWORD dwValue1 = 0)
: m_Type(Type),
m_dwValue0(dwValue0),
m_dwValue1(dwValue1)
{
}
CStateID(eStateType Type, DWORD dwStage, D3DTEXTURESTAGESTATETYPE StageType)
: m_Type(Type),
m_dwStage(dwStage),
m_TextureStageStateType(StageType)
{
}
CStateID(eStateType Type, D3DRENDERSTATETYPE RenderType)
: m_Type(Type),
m_RenderStateType(RenderType)
{
}
eStateType m_Type;
union
{
DWORD m_dwValue0;
DWORD m_dwStage;
D3DRENDERSTATETYPE m_RenderStateType;
D3DTRANSFORMSTATETYPE m_TransformStateType;
};
union
{
DWORD m_dwValue1;
D3DTEXTURESTAGESTATETYPE m_TextureStageStateType;
};
};
typedef std::vector<CStateID> TStateID;
class CStateManagerState
{
public:
CStateManagerState()
{
}
void ResetState()
{
DWORD i, y;
for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++)
m_RenderStates[i] = 0x7FFFFFFF;
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
for (y = 0; y < STATEMANAGER_MAX_TEXTURESTATES; y++)
m_TextureStates[i][y] = 0x7FFFFFFF;
for (i = 0; i < STATEMANAGER_MAX_STREAMS; i++)
m_StreamData[i] = CStreamData();
m_IndexData = CIndexData();
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
m_Textures[i] = NULL;
// Matrices and constants are not cached, just restored. It's silly to check all the
// data elements (by which time the driver could have been sent them).
for (i = 0; i < STATEMANAGER_MAX_TRANSFORMSTATES; i++)
D3DXMatrixIdentity(&m_Matrices[i]);
for (i = 0; i < STATEMANAGER_MAX_VCONSTANTS; i++)
m_VertexShaderConstants[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f);
for (i = 0; i < STATEMANAGER_MAX_PCONSTANTS; i++)
m_PixelShaderConstants[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f);
m_dwPixelShader = 0;
m_dwVertexShader = D3DFVF_XYZ;
ZeroMemory(&m_Matrices, sizeof(D3DXMATRIX) * STATEMANAGER_MAX_TRANSFORMSTATES);
}
// Renderstates
DWORD m_RenderStates[STATEMANAGER_MAX_RENDERSTATES];
// Texture stage states
DWORD m_TextureStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
// Vertex shader constants
D3DXVECTOR4 m_VertexShaderConstants[STATEMANAGER_MAX_VCONSTANTS];
// Pixel shader constants
D3DXVECTOR4 m_PixelShaderConstants[STATEMANAGER_MAX_PCONSTANTS];
// Textures
LPDIRECT3DBASETEXTURE8 m_Textures[STATEMANAGER_MAX_STAGES];
// Shaders
DWORD m_dwPixelShader;
DWORD m_dwVertexShader;
D3DXMATRIX m_Matrices[STATEMANAGER_MAX_TRANSFORMSTATES];
D3DMATERIAL8 m_D3DMaterial;
CStreamData m_StreamData[STATEMANAGER_MAX_STREAMS];
CIndexData m_IndexData;
};
class CStateManager : public CSingleton<CStateManager>
{
public:
CStateManager(LPDIRECT3DDEVICE8 lpDevice);
virtual ~CStateManager();
void SetDefaultState();
void Restore();
bool BeginScene();
void EndScene();
// Material
void SaveMaterial();
void SaveMaterial(const D3DMATERIAL8 * pMaterial);
void RestoreMaterial();
void SetMaterial(const D3DMATERIAL8 * pMaterial);
void GetMaterial(D3DMATERIAL8 * pMaterial);
void SetLight(DWORD index, CONST D3DLIGHT8* pLight);
void GetLight(DWORD index, D3DLIGHT8* pLight);
// Renderstates
void SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue);
void RestoreRenderState(D3DRENDERSTATETYPE Type);
void SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value);
void GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue);
// Textures
void SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture);
void RestoreTexture(DWORD dwStage);
void SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture);
void GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture);
// Texture stage states
void SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
void RestoreTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type);
void SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
void GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pdwValue);
void SetBestFiltering(DWORD dwStage); // if possible set anisotropy filtering, or use trilinear
// Vertex Shader
void SaveVertexShader(DWORD dwShader);
void RestoreVertexShader();
void SetVertexShader(DWORD dwShader);
void GetVertexShader(DWORD * pdwShader);
// Pixel Shader
void SavePixelShader(DWORD dwShader);
void RestorePixelShader();
void SetPixelShader(DWORD dwShader);
void GetPixelShader(DWORD * pdwShader);
// *** These states are cached, but not protected from multiple sends of the same value.
// Transform
void SaveTransform(D3DTRANSFORMSTATETYPE Transform, const D3DMATRIX* pMatrix);
void RestoreTransform(D3DTRANSFORMSTATETYPE Transform);
// Don't cache-check the transform. To much to do
void SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix);
void GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix);
// SetVertexShaderConstant
void SaveVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
void RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
void SetVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
// SetPixelShaderConstant
void SavePixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
void RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
void SetPixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
void SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride);
void RestoreStreamSource(UINT StreamNumber);
void SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride);
void SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex);
void RestoreIndices();
void SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData,UINT BaseVertexIndex);
HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount);
HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData, UINT VertexStreamZeroStride);
// Codes For Debug
DWORD GetRenderState(D3DRENDERSTATETYPE Type);
private:
void SetDevice(LPDIRECT3DDEVICE8 lpDevice);
private:
CStateManagerState m_ChipState;
CStateManagerState m_CurrentState;
CStateManagerState m_CopyState;
TStateID m_DirtyStates;
bool m_bForce;
bool m_bScene;
DWORD m_dwBestMinFilter;
DWORD m_dwBestMagFilter;
LPDIRECT3DDEVICE8 m_lpD3DDev;
#ifdef _DEBUG
// Saving Flag
BOOL m_bRenderStateSavingFlag[STATEMANAGER_MAX_RENDERSTATES];
BOOL m_bTextureStageStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
BOOL m_bTransformSavingFlag[STATEMANAGER_MAX_TRANSFORMSTATES];
#endif _DEBUG
};
#define STATEMANAGER (CStateManager::Instance())
#endif __CSTATEMANAGER_H
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include "DibBar.h"
class CTextBar : public CDibBar
{
public:
CTextBar(int fontSize, bool isBold);
virtual ~CTextBar();
void TextOut(int ix, int iy, const char * c_szText);
void SetTextColor(int r, int g, int b);
void GetTextExtent(const char * c_szText, SIZE* p_size);
protected:
void __SetFont(int fontSize, bool isBold);
void OnCreate();
protected:
HFONT m_hFont;
HFONT m_hOldFont;
int m_fontSize;
bool m_isBold;
};
+28
View File
@@ -0,0 +1,28 @@
#ifndef __INC_ETERLIB_THREAD_H__
#define __INC_ETERLIB_THREAD_H__
class CThread
{
public:
CThread();
int Create(void * arg);
protected:
static UINT CALLBACK EntryPoint(void * pThis);
virtual UINT Setup() = 0; // Execute이 불려지기 전에 불려진다.
virtual UINT Execute(void * arg) = 0; // 실제 쓰레드가 하는 일이 들어가는 곳
UINT Run(void * arg);
void * Arg() const { return m_pArg; }
void Arg(void * arg) { m_pArg = arg; }
HANDLE m_hThread;
private:
void * m_pArg;
unsigned m_uThreadID;
};
#endif