layout: restructure into src/ tests/ android/ scripts/ tools/

- extension/src/{port,platform,codepage} -> src/; native_render -> src/host
  (+ dxt, shaders/); libgr2 -> src/gr2; extension/third_party -> third_party
- extension/tests -> tests/port, libgr2/tests -> tests/gr2
- android-native -> android (build.sh, push-client.sh moved in)
- script -> scripts; tools/40250 -> tools/server; oracle -> tools/granny-oracle;
  perf tools -> tools/perf
- all build trees under build/ (native, release, android, port-gate)
- xrender:: CMake aliases -> mt::; port-map ledger impl paths rewritten

No code changes. ctest 15/15, port_gate macos+android PASS, port_map check 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-29 19:08:19 +09:00
co-authored by Claude Opus 5.5
parent 70710477cf
commit a46093104c
2817 changed files with 13728 additions and 13744 deletions
@@ -0,0 +1,372 @@
// CPythonGraphic(40250 EterPythonLib/PythonGraphic.cpp)的平台骨架 —— 目前只有窗口树链接时真正需要
// 的那一个函数。
//
// CPythonGraphic 是 UI 的 2D 绘制层(D3D8 的正交投影、按钮的立体边框、冷却圈、截图),整份实现属于
// 2V0-f;platform_stub.py 不认 EterPythonLib(port_map 把它划成 python 层),所以这里按手写平台桩的
// 惯例来:先只放被引用到的符号,链接器会告诉我们下一个是谁。
//
// RenderCoolTimeBox:40250 的扇形顶点原样搬来,画法改成 UIRenderCommands(见函数注释)。
#include "EterPythonLib/StdAfx.h"
#include "EterPythonLib/PythonGraphic.h"
#include "EterLib/StateManager.h"
#include "../PlatformStub.h"
#include "../EterLib/UIRenderCommands.h"
#include <algorithm>
// 40250 PythonGraphic.cpp:611
CPythonGraphic::CPythonGraphic()
{
m_lightColor = GetColor(1.0f, 1.0f, 1.0f);
m_darkColor = GetColor(0.0f, 0.0f, 0.0f);
memset(&m_backupViewport, 0, sizeof(D3DVIEWPORT8));
m_fOrthoDepth = 1000.0f;
}
CPythonGraphic::~CPythonGraphic()
{
Tracef("Python Graphic Clear\n");
}
namespace
{
class CDummyDirect3D8 : public IDirect3D8
{
public:
HRESULT GetAdapterIdentifier(UINT, DWORD, D3DADAPTER_IDENTIFIER8* pIdentifier) override
{
if (!pIdentifier) return E_FAIL;
memset(pIdentifier, 0, sizeof(D3DADAPTER_IDENTIFIER8));
strncpy(pIdentifier->Driver, "dummy", sizeof(pIdentifier->Driver));
strncpy(pIdentifier->Description, "Dummy Direct3D8", sizeof(pIdentifier->Description));
return S_OK;
}
HRESULT GetAdapterDisplayMode(UINT, D3DDISPLAYMODE* pMode) override
{
if (!pMode) return E_FAIL;
pMode->Width = 1024;
pMode->Height = 768;
pMode->RefreshRate = 60;
pMode->Format = D3DFMT_X8R8G8B8;
return S_OK;
}
UINT GetAdapterModeCount(UINT) override
{
return 3;
}
HRESULT EnumAdapterModes(UINT, UINT Mode, D3DDISPLAYMODE* pMode) override
{
if (!pMode) return E_FAIL;
static const D3DDISPLAYMODE s_modes[] = {
{ 800, 600, 60, D3DFMT_X8R8G8B8 },
{ 1024, 768, 60, D3DFMT_X8R8G8B8 },
{ 1280, 1024, 60, D3DFMT_X8R8G8B8 },
};
if (Mode >= 3) return E_FAIL;
*pMode = s_modes[Mode];
return S_OK;
}
};
}
LPDIRECT3D8 CPythonGraphic::GetD3D()
{
static CDummyDirect3D8 s_dummyD3D;
return &s_dummyD3D;
}
void CPythonGraphic::SetViewport(float x, float y, float width, float height)
{
if (ms_lpd3dDevice)
{
ms_lpd3dDevice->GetViewport(&m_backupViewport);
D3DVIEWPORT8 vp = { (DWORD)x, (DWORD)y, (DWORD)width, (DWORD)height, 0.0f, 1.0f };
ms_lpd3dDevice->SetViewport(&vp);
}
UIRenderSetClip(x, y, width, height);
}
void CPythonGraphic::RestoreViewport()
{
if (ms_lpd3dDevice)
ms_lpd3dDevice->SetViewport(&m_backupViewport);
UIRenderRestoreClip();
}
void CPythonGraphic::SetOmniLight()
{
D3DMATERIAL8 Material;
Material.Ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
Material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
Material.Emissive = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1.0f);
STATEMANAGER.SetMaterial(&Material);
D3DLIGHT8 Light;
Light.Type = D3DLIGHT_SPOT;
Light.Position = D3DXVECTOR3(50.0f, 150.0f, 350.0f);
Light.Direction = D3DXVECTOR3(-0.15f, -0.3f, -0.9f);
Light.Theta = D3DXToRadian(30.0f);
Light.Phi = D3DXToRadian(45.0f);
Light.Falloff = 1.0f;
Light.Attenuation0 = 0.0f;
Light.Attenuation1 = 0.005f;
Light.Attenuation2 = 0.0f;
Light.Diffuse.r = 1.0f;
Light.Diffuse.g = 1.0f;
Light.Diffuse.b = 1.0f;
Light.Diffuse.a = 1.0f;
Light.Ambient.r = 1.0f;
Light.Ambient.g = 1.0f;
Light.Ambient.b = 1.0f;
Light.Ambient.a = 1.0f;
Light.Range = 500.0f;
if (ms_lpd3dDevice)
{
ms_lpd3dDevice->SetLight(0, &Light);
ms_lpd3dDevice->LightEnable(0, TRUE);
Light.Type = D3DLIGHT_POINT;
Light.Position = D3DXVECTOR3(0.0f, 200.0f, 200.0f);
Light.Attenuation0 = 0.1f;
Light.Attenuation1 = 0.01f;
Light.Attenuation2 = 0.0f;
ms_lpd3dDevice->SetLight(1, &Light);
ms_lpd3dDevice->LightEnable(1, TRUE);
}
}
long CPythonGraphic::GenerateColor(float r, float g, float b, float a) { return GetColor(r, g, b, a); }
// 40250 PythonGraphic.cpp:580
void CPythonGraphic::RenderDownButton(float sx, float sy, float ex, float ey)
{
RenderBox2d(sx, sy, ex, ey);
SetDiffuseColor(m_darkColor);
RenderLine2d(sx, sy, ex, sy);
RenderLine2d(sx, sy, sx, ey);
SetDiffuseColor(m_lightColor);
RenderLine2d(sx, ey, ex, ey);
RenderLine2d(ex, sy, ex, ey);
}
// 40250 PythonGraphic.cpp:593
void CPythonGraphic::RenderUpButton(float sx, float sy, float ex, float ey)
{
RenderBox2d(sx, sy, ex, ey);
SetDiffuseColor(m_lightColor);
RenderLine2d(sx, sy, ex, sy);
RenderLine2d(sx, sy, sx, ey);
SetDiffuseColor(m_darkColor);
RenderLine2d(sx, ey, ex, ey);
RenderLine2d(ex, sy, ex, ey);
}
bool CPythonGraphic::SaveScreenShot(const char*) { MT_PLATFORM_STUB(); return false; }
// 40250 PythonGraphic.cpp:52.
void CPythonGraphic::SetCursorPosition(int x, int y)
{
CScreen::SetCursorPosition(x, y, ms_iWidth, ms_iHeight);
}
// 40250 PythonGraphic.cpp:606
DWORD CPythonGraphic::GetAvailableMemory()
{
return ms_lpd3dDevice->GetAvailableTextureMem();
}
// 40250 PythonGraphic.cpp:124. The recording device reports no D3DCAPS2_FULLSCREENGAMMA (the frame
// goes to a window), so this returns at the caps check like 40250 does on such a device.
void CPythonGraphic::SetGamma(float fGammaFactor)
{
D3DCAPS8 d3dCaps;
D3DGAMMARAMP NewRamp;
int ui, val;
ms_lpd3dDevice->GetDeviceCaps(&d3dCaps);
if (D3DCAPS2_FULLSCREENGAMMA != (d3dCaps.Caps2 & D3DCAPS2_FULLSCREENGAMMA))
return;
for (int i = 0; i < 256; ++i)
{
val = (int) (i * fGammaFactor * 255.0f);
ui = 0;
if (val > 32767)
{
val = val - 32767;
ui = 1;
}
if (val > 32767)
val = 32767;
NewRamp.red[i] = (WORD) (val | (32768 * ui));
NewRamp.green[i] = (WORD) (val | (32768 * ui));
NewRamp.blue[i] = (WORD) (val | (32768 * ui));
}
ms_lpd3dDevice->SetGammaRamp(D3DSGR_NO_CALIBRATION, &NewRamp);
}
// 40250 PythonGraphic.cpp:491. The fan's vertices are built verbatim.
// PORT: 40250 draws them as a D3DPT_TRIANGLEFAN with untextured SELECTARG1(DIFFUSE) colour and alpha;
// the UI here is drawn from UIRenderCommands, so each fan triangle goes out as one untextured quad
// command (vertices centre, j, j+1, j+1) in the same half-transparent black.
void CPythonGraphic::RenderCoolTimeBox(float fxCenter, float fyCenter, float fRadius, float fTime)
{
if (fTime >= 1.0f)
return;
fTime = max(0.0f, fTime);
static D3DXCOLOR color = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.5f);
static D3DXVECTOR2 s_v2BoxPos[8] =
{
D3DXVECTOR2( -1.0f, -1.0f ),
D3DXVECTOR2( -1.0f, 0.0f ),
D3DXVECTOR2( -1.0f, +1.0f ),
D3DXVECTOR2( 0.0f, +1.0f ),
D3DXVECTOR2( +1.0f, +1.0f ),
D3DXVECTOR2( +1.0f, 0.0f ),
D3DXVECTOR2( +1.0f, -1.0f ),
D3DXVECTOR2( 0.0f, -1.0f ),
};
int iTriCount = int(8 - 8.0f * fTime);
float fLastPercentage = (8 - 8.0f * fTime) - iTriCount;
std::vector<TPDTVertex> vertices;
TPDTVertex vertex;
vertex.position.x = fxCenter;
vertex.position.y = fyCenter;
vertex.position.z = 0.0f;
vertex.diffuse = color;
vertex.texCoord.x = 0.0f;
vertex.texCoord.x = 0.0f;
vertices.push_back(vertex);
vertex.position.x = fxCenter;
vertex.position.y = fyCenter - fRadius;
vertex.position.z = 0.0f;
vertex.diffuse = color;
vertex.texCoord.x = 0.0f;
vertex.texCoord.x = 0.0f;
vertices.push_back(vertex);
for (int j = 0; j < iTriCount; ++j)
{
vertex.position.x = fxCenter + s_v2BoxPos[j].x * fRadius;
vertex.position.y = fyCenter + s_v2BoxPos[j].y * fRadius;
vertices.push_back(vertex);
}
if (fLastPercentage > 0.0f)
{
D3DXVECTOR2 * pv2Pos;
D3DXVECTOR2 * pv2LastPos;
assert((iTriCount-1+8)%8 >= 0 && (iTriCount-1+8)%8 < 8);
assert((iTriCount+8)%8 >= 0 && (iTriCount+8)%8 < 8);
pv2LastPos = &s_v2BoxPos[(iTriCount-1+8)%8];
pv2Pos = &s_v2BoxPos[(iTriCount+8)%8];
vertex.position.x = fxCenter + ((pv2Pos->x-pv2LastPos->x) * fLastPercentage + pv2LastPos->x) * fRadius;
vertex.position.y = fyCenter + ((pv2Pos->y-pv2LastPos->y) * fLastPercentage + pv2LastPos->y) * fRadius;
vertices.push_back(vertex);
++iTriCount;
}
if (vertices.empty())
return;
// PORT: the D3DPT_TRIANGLEFAN of iTriCount triangles, see the function comment.
const std::uint32_t argb = UIRenderColor(color);
for (int j = 0; j < iTriCount && j + 2 < int(vertices.size()); ++j)
{
const TPDTVertex* fan[4] = { &vertices[0], &vertices[j + 1], &vertices[j + 2], &vertices[j + 2] };
UIRenderCommand command{UIRenderCommand::Bar, 0, 0, 0, 0, argb};
for (int k = 0; k < 4; ++k)
{
command.qx[k] = fan[k]->position.x;
command.qy[k] = fan[k]->position.y;
}
command.x1 = std::min({command.qx[0], command.qx[1], command.qx[2]});
command.y1 = std::min({command.qy[0], command.qy[1], command.qy[2]});
command.x2 = std::max({command.qx[0], command.qx[1], command.qx[2]});
command.y2 = std::max({command.qy[0], command.qy[1], command.qy[2]});
command.quad = true;
UIRenderAdd(std::move(command));
}
}
// 40250 PythonGraphic.cpp:17
float CPythonGraphic::GetOrthoDepth()
{
return m_fOrthoDepth;
}
// 40250 PythonGraphic.cpp:22
void CPythonGraphic::SetInterfaceRenderState()
{
STATEMANAGER.SetTransform(D3DTS_PROJECTION, &ms_matIdentity);
STATEMANAGER.SetTransform(D3DTS_VIEW, &ms_matIdentity);
STATEMANAGER.SetTransform(D3DTS_WORLD, &ms_matIdentity);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_NONE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE);
STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
STATEMANAGER.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
STATEMANAGER.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
CPythonGraphic::Instance().SetBlendOperation();
CPythonGraphic::Instance().SetOrtho2D(ms_iWidth, ms_iHeight, GetOrthoDepth());
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
}
// 40250 PythonGraphic.cpp:42
void CPythonGraphic::SetGameRenderState()
{
STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE);
}
// 40250 PythonGraphic.cpp:387
void CPythonGraphic::PushState()
{
TState curState;
curState.matProj = ms_matProj;
curState.matView = ms_matView;
//STATEMANAGER.SaveTransform(D3DTS_WORLD, &m_SaveWorldMatrix);
m_stateStack.push(curState);
//CCamera::Instance().PushParams();
}
// 40250 PythonGraphic.cpp:399
void CPythonGraphic::PopState()
{
if (m_stateStack.empty())
{
assert(!"PythonGraphic::PopState StateStack is EMPTY");
return;
}
TState & rState = m_stateStack.top();
//STATEMANAGER.RestoreTransform(D3DTS_WORLD);
ms_matProj = rState.matProj;
ms_matView = rState.matView;
UpdatePipeLineMatrix();
m_stateStack.pop();
//CCamera::Instance().PopParams();
}