AVA2 cross-platform client parity baseline

This commit is contained in:
shen
2026-10-06 00:53:42 -07:00
commit 9f748eb05a
3271 changed files with 1275528 additions and 0 deletions
+315
View File
@@ -0,0 +1,315 @@
#include "python_grp.h"
#include "eter_image/GrpDevice.h"
#include <SDL3/SDL.h>
#include <Python.h>
#include <string>
#include <vector>
#include <algorithm>
namespace ava2 {
namespace {
PyObject* dummy_none(PyObject*, PyObject*) { Py_RETURN_NONE; }
PyObject* dummy_zero(PyObject*, PyObject*) { return PyInt_FromLong(0); }
PyObject* dummy_one(PyObject*, PyObject*) { return PyInt_FromLong(1); }
PyObject* dummy_float_zero(PyObject*, PyObject*) { return PyFloat_FromDouble(0.0); }
PyObject* dummy_str(PyObject*, PyObject*) { return PyString_FromString(""); }
PyObject* dummy_tuple2(PyObject*, PyObject*) { return Py_BuildValue("ii", 0, 0); }
PyObject* dummy_tuple3(PyObject*, PyObject*) { return Py_BuildValue("iii", 0, 0, 0); }
PyObject* dummy_tuple4(PyObject*, PyObject*) { return Py_BuildValue("iiii", 0, 0, 0, 0); }
static uint32_t s_currentColor = 0xFFFFFFFF;
static uint32_t s_diffuseColor = 0xFFFFFFFF;
static uint32_t s_clearColor = 0xFF000000;
static float s_alpha = 1.0f;
static PyObject* grp_GenerateColor(PyObject*, PyObject* args) {
float r = 0.0f, g = 0.0f, b = 0.0f, a = 1.0f;
if (!PyArg_ParseTuple(args, "ffff", &r, &g, &b, &a)) {
PyErr_Clear();
int ir = 0, ig = 0, ib = 0, ia = 255;
if (PyArg_ParseTuple(args, "iiii", &ir, &ig, &ib, &ia)) {
uint32_t color = ((uint32_t)(ia & 0xFF) << 24) |
((uint32_t)(ir & 0xFF) << 16) |
((uint32_t)(ig & 0xFF) << 8) |
(uint32_t)(ib & 0xFF);
return PyLong_FromUnsignedLong(color);
}
return PyLong_FromUnsignedLong(0xFFFFFFFF);
}
uint8_t ur = (uint8_t)std::clamp((int)(r * 255.0f), 0, 255);
uint8_t ug = (uint8_t)std::clamp((int)(g * 255.0f), 0, 255);
uint8_t ub = (uint8_t)std::clamp((int)(b * 255.0f), 0, 255);
uint8_t ua = (uint8_t)std::clamp((int)(a * 255.0f), 0, 255);
uint32_t color = ((uint32_t)ua << 24) | ((uint32_t)ur << 16) | ((uint32_t)ug << 8) | (uint32_t)ub;
return PyLong_FromUnsignedLong(color);
}
static PyObject* grp_SetColor(PyObject*, PyObject* args) {
unsigned long color = 0;
if (PyArg_ParseTuple(args, "k", &color)) {
s_currentColor = (uint32_t)color;
} else {
PyErr_Clear();
int icolor = 0;
if (PyArg_ParseTuple(args, "i", &icolor)) {
s_currentColor = (uint32_t)icolor;
}
}
Py_RETURN_NONE;
}
static PyObject* grp_SetAlpha(PyObject*, PyObject* args) {
float a = 1.0f;
if (PyArg_ParseTuple(args, "f", &a)) {
s_alpha = std::clamp(a, 0.0f, 1.0f);
uint8_t ua = (uint8_t)(s_alpha * 255.0f);
s_currentColor = (s_currentColor & 0x00FFFFFF) | ((uint32_t)ua << 24);
}
Py_RETURN_NONE;
}
static PyObject* grp_SetDiffuseColor(PyObject*, PyObject* args) {
float r = 1.0f, g = 1.0f, b = 1.0f, a = 1.0f;
if (PyArg_ParseTuple(args, "ffff", &r, &g, &b, &a)) {
uint8_t ur = (uint8_t)std::clamp((int)(r * 255.0f), 0, 255);
uint8_t ug = (uint8_t)std::clamp((int)(g * 255.0f), 0, 255);
uint8_t ub = (uint8_t)std::clamp((int)(b * 255.0f), 0, 255);
uint8_t ua = (uint8_t)std::clamp((int)(a * 255.0f), 0, 255);
s_diffuseColor = ((uint32_t)ua << 24) | ((uint32_t)ur << 16) | ((uint32_t)ug << 8) | (uint32_t)ub;
}
Py_RETURN_NONE;
}
static PyObject* grp_SetClearColor(PyObject*, PyObject* args) {
float r = 0.0f, g = 0.0f, b = 0.0f;
if (PyArg_ParseTuple(args, "fff", &r, &g, &b)) {
uint8_t ur = (uint8_t)std::clamp((int)(r * 255.0f), 0, 255);
uint8_t ug = (uint8_t)std::clamp((int)(g * 255.0f), 0, 255);
uint8_t ub = (uint8_t)std::clamp((int)(b * 255.0f), 0, 255);
s_clearColor = 0xFF000000 | ((uint32_t)ur << 16) | ((uint32_t)ug << 8) | (uint32_t)ub;
}
Py_RETURN_NONE;
}
static PyObject* grp_RenderBar(PyObject*, PyObject* args) {
int x = 0, y = 0, w = 0, h = 0;
if (PyArg_ParseTuple(args, "iiii", &x, &y, &w, &h)) {
auto* renderer = CGraphicDevice::Instance().GetRenderer();
if (renderer && w > 0 && h > 0) {
uint8_t a = (s_currentColor >> 24) & 0xFF;
uint8_t r = (s_currentColor >> 16) & 0xFF;
uint8_t g = (s_currentColor >> 8) & 0xFF;
uint8_t b = s_currentColor & 0xFF;
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, r, g, b, a);
SDL_FRect rect{ (float)x, (float)y, (float)w, (float)h };
SDL_RenderFillRect(renderer, &rect);
}
}
Py_RETURN_NONE;
}
static PyObject* grp_RenderLine(PyObject*, PyObject* args) {
int x = 0, y = 0, dx = 0, dy = 0;
if (PyArg_ParseTuple(args, "iiii", &x, &y, &dx, &dy)) {
auto* renderer = CGraphicDevice::Instance().GetRenderer();
if (renderer) {
uint8_t a = (s_currentColor >> 24) & 0xFF;
uint8_t r = (s_currentColor >> 16) & 0xFF;
uint8_t g = (s_currentColor >> 8) & 0xFF;
uint8_t b = s_currentColor & 0xFF;
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, r, g, b, a);
SDL_RenderLine(renderer, (float)x, (float)y, (float)(x + dx), (float)(y + dy));
}
}
Py_RETURN_NONE;
}
static PyObject* grp_RenderBox(PyObject*, PyObject* args) {
int x = 0, y = 0, w = 0, h = 0;
if (PyArg_ParseTuple(args, "iiii", &x, &y, &w, &h)) {
auto* renderer = CGraphicDevice::Instance().GetRenderer();
if (renderer && w > 0 && h > 0) {
uint8_t a = (s_currentColor >> 24) & 0xFF;
uint8_t r = (s_currentColor >> 16) & 0xFF;
uint8_t g = (s_currentColor >> 8) & 0xFF;
uint8_t b = s_currentColor & 0xFF;
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, r, g, b, a);
SDL_FRect rect{ (float)x, (float)y, (float)w, (float)h };
SDL_RenderRect(renderer, &rect);
}
}
Py_RETURN_NONE;
}
static PyObject* grp_RenderRoundBox(PyObject*, PyObject* args) {
int x = 0, y = 0, w = 0, h = 0;
if (PyArg_ParseTuple(args, "iiii", &x, &y, &w, &h)) {
auto* renderer = CGraphicDevice::Instance().GetRenderer();
if (renderer && w > 0 && h > 0) {
uint8_t a = (s_currentColor >> 24) & 0xFF;
uint8_t r = (s_currentColor >> 16) & 0xFF;
uint8_t g = (s_currentColor >> 8) & 0xFF;
uint8_t b = s_currentColor & 0xFF;
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, r, g, b, a);
SDL_FRect rect{ (float)x, (float)y, (float)w, (float)h };
SDL_RenderRect(renderer, &rect);
}
}
Py_RETURN_NONE;
}
static PyObject* grp_RenderGradationBar(PyObject*, PyObject* args) {
int x = 0, y = 0, w = 0, h = 0;
unsigned long startCol = 0, endCol = 0;
if (PyArg_ParseTuple(args, "iiiikk", &x, &y, &w, &h, &startCol, &endCol)) {
auto* renderer = CGraphicDevice::Instance().GetRenderer();
if (renderer && w > 0 && h > 0) {
uint8_t sa = (startCol >> 24) & 0xFF, sr = (startCol >> 16) & 0xFF, sg = (startCol >> 8) & 0xFF, sb = startCol & 0xFF;
uint8_t ea = (endCol >> 24) & 0xFF, er = (endCol >> 16) & 0xFF, eg = (endCol >> 8) & 0xFF, eb = endCol & 0xFF;
SDL_FColor c1{ sr/255.0f, sg/255.0f, sb/255.0f, sa/255.0f };
SDL_FColor c2{ er/255.0f, eg/255.0f, eb/255.0f, ea/255.0f };
SDL_Vertex verts[4];
verts[0] = { { (float)x, (float)y }, c1, {0, 0} };
verts[1] = { { (float)(x+w), (float)y }, c1, {0, 0} };
verts[2] = { { (float)(x+w), (float)(y+h) }, c2, {0, 0} };
verts[3] = { { (float)x, (float)(y+h) }, c2, {0, 0} };
int indices[6] = { 0, 1, 2, 0, 2, 3 };
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderGeometry(renderer, nullptr, verts, 4, indices, 6);
}
}
Py_RETURN_NONE;
}
} // namespace
void initgrp() {
static PyMethodDef methods[] = {
{"InitScreenEffect", dummy_none, METH_VARARGS, nullptr},
{"Culling", dummy_none, METH_VARARGS, nullptr},
{"ClearDepthBuffer", dummy_none, METH_VARARGS, nullptr},
{"Identity", dummy_none, METH_VARARGS, nullptr},
{"GenerateColor", grp_GenerateColor, METH_VARARGS, nullptr},
{"PopState", dummy_none, METH_VARARGS, nullptr},
{"PushState", dummy_none, METH_VARARGS, nullptr},
{"PushMatrix", dummy_none, METH_VARARGS, nullptr},
{"PopMatrix", dummy_none, METH_VARARGS, nullptr},
{"Translate", dummy_none, METH_VARARGS, nullptr},
{"Rotate", dummy_none, METH_VARARGS, nullptr},
{"SetColorRenderState", dummy_none, METH_VARARGS, nullptr},
{"SetAroundCamera", dummy_none, METH_VARARGS, nullptr},
{"SetPositionCamera", dummy_none, METH_VARARGS, nullptr},
{"SetEyeCamera", dummy_none, METH_VARARGS, nullptr},
{"SetPerspective", dummy_none, METH_VARARGS, nullptr},
{"SetOrtho2d", dummy_none, METH_VARARGS, nullptr},
{"SetOrtho3d", dummy_none, METH_VARARGS, nullptr},
{"SetColor", grp_SetColor, METH_VARARGS, nullptr},
{"SetAlpha", grp_SetAlpha, METH_VARARGS, nullptr},
{"SetDiffuseColor", grp_SetDiffuseColor, METH_VARARGS, nullptr},
{"SetClearColor", grp_SetClearColor, METH_VARARGS, nullptr},
{"GetCursorPosition3d", dummy_tuple2, METH_VARARGS, nullptr},
{"SetCursorPosition", dummy_none, METH_VARARGS, nullptr},
{"RenderLine", grp_RenderLine, METH_VARARGS, nullptr},
{"RenderBox", grp_RenderBox, METH_VARARGS, nullptr},
{"RenderRoundBox", grp_RenderRoundBox, METH_VARARGS, nullptr},
{"RenderBox3d", dummy_none, METH_VARARGS, nullptr},
{"RenderBar", grp_RenderBar, METH_VARARGS, nullptr},
{"RenderBar3d", dummy_none, METH_VARARGS, nullptr},
{"RenderGradationBar", grp_RenderGradationBar, METH_VARARGS, nullptr},
{"RenderCube", dummy_none, METH_VARARGS, nullptr},
{"RenderDownButton", dummy_none, METH_VARARGS, nullptr},
{"RenderUpButton", dummy_none, METH_VARARGS, nullptr},
{"GetAvailableMemory", dummy_zero, METH_VARARGS, nullptr},
{"SaveScreenShot", dummy_none, METH_VARARGS, nullptr},
{"SaveScreenShotToPath", dummy_none, METH_VARARGS, nullptr},
{"SetGamma", dummy_none, METH_VARARGS, nullptr},
{"SetInterfaceRenderState", dummy_none, METH_VARARGS, nullptr},
{"SetGameRenderState", dummy_none, METH_VARARGS, nullptr},
{"SetViewport", dummy_none, METH_VARARGS, nullptr},
{"RestoreViewport", dummy_none, METH_VARARGS, nullptr},
{"SetOmniLight", dummy_none, METH_VARARGS, nullptr},
{"GetCameraPosition", dummy_tuple2, METH_VARARGS, nullptr},
{"GetTargetPosition", dummy_tuple2, METH_VARARGS, nullptr},
{"CreateTextBar", dummy_none, METH_VARARGS, nullptr},
{"CreateBigTextBar", dummy_none, METH_VARARGS, nullptr},
{"DestroyTextBar", dummy_none, METH_VARARGS, nullptr},
{"RenderTextBar", dummy_none, METH_VARARGS, nullptr},
{"TextBarTextOut", dummy_none, METH_VARARGS, nullptr},
{"TextBarSetTextColor", dummy_none, METH_VARARGS, nullptr},
{"TextBarGetTextExtent", dummy_none, METH_VARARGS, nullptr},
{"ClearTextBar", dummy_none, METH_VARARGS, nullptr},
{"SetTextBarClipRect", dummy_none, METH_VARARGS, nullptr},
{nullptr, nullptr, 0, nullptr}
};
auto* module = Py_InitModule("grp", methods);
}
void initgrpImage() {
static PyMethodDef methods[] = {
{"Render", dummy_none, METH_VARARGS, nullptr},
{"SetPosition", dummy_none, METH_VARARGS, nullptr},
{"Generate", dummy_none, METH_VARARGS, nullptr},
{"GenerateExpanded", dummy_none, METH_VARARGS, nullptr},
{"GenerateFromHandle", dummy_none, METH_VARARGS, nullptr},
{"Delete", dummy_none, METH_VARARGS, nullptr},
{"DeleteExpanded", dummy_none, METH_VARARGS, nullptr},
{"SetFileName", dummy_none, METH_VARARGS, nullptr},
{"SetOrigin", dummy_none, METH_VARARGS, nullptr},
{"SetRotation", dummy_none, METH_VARARGS, nullptr},
{"SetScale", dummy_none, METH_VARARGS, nullptr},
{"SetRenderingRect", dummy_none, METH_VARARGS, nullptr},
{"SetDiffuseColor", dummy_none, METH_VARARGS, nullptr},
{"GetWidth", dummy_zero, METH_VARARGS, nullptr},
{"GetHeight", dummy_zero, METH_VARARGS, nullptr},
{nullptr, nullptr, 0, nullptr}
};
auto* module = Py_InitModule("grpImage", methods);
}
void initgrpText() {
static PyMethodDef methods[] = {
{"Update", dummy_none, METH_VARARGS, nullptr},
{"Render", dummy_none, METH_VARARGS, nullptr},
{"Generate", dummy_none, METH_VARARGS, nullptr},
{"Destroy", dummy_none, METH_VARARGS, nullptr},
{"SetFontName", dummy_none, METH_VARARGS, nullptr},
{"SetFontColor", dummy_none, METH_VARARGS, nullptr},
{"SetOutLineColor", dummy_none, METH_VARARGS, nullptr},
{"SetSecret", dummy_none, METH_VARARGS, nullptr},
{"SetOutline", dummy_none, METH_VARARGS, nullptr},
{"SetText", dummy_none, METH_VARARGS, nullptr},
{"GetText", dummy_str, METH_VARARGS, nullptr},
{"GetSize", dummy_tuple2, METH_VARARGS, nullptr},
{"SetPosition", dummy_none, METH_VARARGS, nullptr},
{"ShowCursor", dummy_none, METH_VARARGS, nullptr},
{"HideCursor", dummy_none, METH_VARARGS, nullptr},
{"SetHorizontalAlign", dummy_none, METH_VARARGS, nullptr},
{"SetVerticalAlign", dummy_none, METH_VARARGS, nullptr},
{"SetMax", dummy_none, METH_VARARGS, nullptr},
{"GetSplitingTextLineCount", dummy_str, METH_VARARGS, nullptr},
{"GetSplitingTextLine", dummy_str, METH_VARARGS, nullptr},
{"PixelPositionToCharacterPosition", dummy_none, METH_VARARGS, nullptr},
{nullptr, nullptr, 0, nullptr}
};
auto* module = Py_InitModule("grpText", methods);
}
void initgrpThing() {
static PyMethodDef methods[] = {
{"Update", dummy_none, METH_VARARGS, nullptr},
{"Render", dummy_none, METH_VARARGS, nullptr},
{"SetPosition", dummy_none, METH_VARARGS, nullptr},
{"Generate", dummy_none, METH_VARARGS, nullptr},
{"Delete", dummy_none, METH_VARARGS, nullptr},
{"SetFileName", dummy_none, METH_VARARGS, nullptr},
{"SetRotation", dummy_none, METH_VARARGS, nullptr},
{"SetScale", dummy_none, METH_VARARGS, nullptr},
{nullptr, nullptr, 0, nullptr}
};
auto* module = Py_InitModule("grpThing", methods);
}
} // namespace ava2