C client: shrink by 5kb

This commit is contained in:
UnknownShadow200 2018-09-06 05:13:30 +10:00
parent 63371827b6
commit 2520e649c0
5 changed files with 91 additions and 98 deletions

View File

@ -535,7 +535,6 @@ static void CuboidCommand_Make(struct ChatCommand* cmd) {
*------------------------------------------------------TeleportCommand----------------------------------------------------* *------------------------------------------------------TeleportCommand----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void TeleportCommand_Execute(STRING_PURE String* args, Int32 argsCount) { static void TeleportCommand_Execute(STRING_PURE String* args, Int32 argsCount) {
ErrorHandler_Fail("DED");
if (argsCount != 4) { if (argsCount != 4) {
Chat_AddRaw("&e/client teleport: &cYou didn't specify X, Y and Z coordinates."); Chat_AddRaw("&e/client teleport: &cYou didn't specify X, Y and Z coordinates.");
} else { } else {

View File

@ -107,7 +107,9 @@ static void ErrorHandler_Backtrace(STRING_TRANSIENT String* str, void* ctx) {
Int32 number = i + 1; Int32 number = i + 1;
UInt64 addr = (UInt64)pointers[i].Instruction; UInt64 addr = (UInt64)pointers[i].Instruction;
/* TODO: Log ESP and EBP here too */
/* TODO: SymGetLineFromAddr64 as well? */ /* TODO: SymGetLineFromAddr64 as well? */
/* TODO: Log module here too */
if (SymGetSymFromAddr64(process, addr, NULL, &sym.Symbol)) { if (SymGetSymFromAddr64(process, addr, NULL, &sym.Symbol)) {
String_Format3(str, "%i) 0x%x - %c\r\n", &number, &addr, sym.Symbol.Name); String_Format3(str, "%i) 0x%x - %c\r\n", &number, &addr, sym.Symbol.Name);
} else { } else {

View File

@ -6,12 +6,11 @@
#include "Game.h" #include "Game.h"
#include "Event.h" #include "Event.h"
#include "Picking.h" #include "Picking.h"
#include "Funcs.h"
GfxResourceID pickedPos_vb; GfxResourceID pickedPos_vb;
PackedCol pickedPos_col = PACKEDCOL_CONST(0, 0, 0, 102);
#define pickedPos_numVertices (16 * 6) #define pickedPos_numVertices (16 * 6)
VertexP3fC4b pickedPos_vertices[pickedPos_numVertices]; VertexP3fC4b pickedPos_vertices[pickedPos_numVertices];
VertexP3fC4b* pickedPos_ptr;
static void PickedPosRenderer_ContextLost(void* obj) { static void PickedPosRenderer_ContextLost(void* obj) {
Gfx_DeleteVb(&pickedPos_vb); Gfx_DeleteVb(&pickedPos_vb);
@ -45,32 +44,7 @@ void PickedPosRenderer_Render(Real64 delta) {
Gfx_SetAlphaBlending(false); Gfx_SetAlphaBlending(false);
} }
static void PickedPosRenderer_XQuad(Real32 x, Real32 z1, Real32 y1, Real32 z2, Real32 y2) {
VertexP3fC4b v; v.X = x; v.Col = pickedPos_col;
v.Y = y1; v.Z = z1; *pickedPos_ptr++ = v;
v.Y = y2; *pickedPos_ptr++ = v;
v.Z = z2; *pickedPos_ptr++ = v;
v.Y = y1; *pickedPos_ptr++ = v;
}
static void PickedPosRenderer_YQuad(Real32 y, Real32 x1, Real32 z1, Real32 x2, Real32 z2) {
VertexP3fC4b v; v.Y = y; v.Col = pickedPos_col;
v.X = x1; v.Z = z1; *pickedPos_ptr++ = v;
v.Z = z2; *pickedPos_ptr++ = v;
v.X = x2; *pickedPos_ptr++ = v;
v.Z = z1; *pickedPos_ptr++ = v;
}
static void PickedPosRenderer_ZQuad(Real32 z, Real32 x1, Real32 y1, Real32 x2, Real32 y2) {
VertexP3fC4b v; v.Z = z; v.Col = pickedPos_col;
v.X = x1; v.Y = y1; *pickedPos_ptr++ = v;
v.Y = y2; *pickedPos_ptr++ = v;
v.X = x2; *pickedPos_ptr++ = v;
v.Y = y1; *pickedPos_ptr++ = v;
}
void PickedPosRenderer_Update(struct PickedPos* selected) { void PickedPosRenderer_Update(struct PickedPos* selected) {
pickedPos_ptr = pickedPos_vertices;
Vector3 delta; Vector3 delta;
Vector3_Sub(&delta, &Game_CurrentCameraPos, &selected->Min); Vector3_Sub(&delta, &Game_CurrentCameraPos, &selected->Min);
Real32 dist = Vector3_LengthSquared(&delta); Real32 dist = Vector3_LengthSquared(&delta);
@ -79,52 +53,66 @@ void PickedPosRenderer_Update(struct PickedPos* selected) {
if (dist < 4.0f * 4.0f) offset = 0.00625f; if (dist < 4.0f * 4.0f) offset = 0.00625f;
if (dist < 2.0f * 2.0f) offset = 0.00500f; if (dist < 2.0f * 2.0f) offset = 0.00500f;
Vector3 p1, p2;
Vector3_Add1(&p1, &selected->Min, -offset);
Vector3_Add1(&p2, &selected->Max, offset);
Real32 size = 1.0f / 16.0f; Real32 size = 1.0f / 16.0f;
if (dist < 32.0f * 32.0f) size = 1.0f / 32.0f; if (dist < 32.0f * 32.0f) size = 1.0f / 32.0f;
if (dist < 16.0f * 16.0f) size = 1.0f / 64.0f; if (dist < 16.0f * 16.0f) size = 1.0f / 64.0f;
if (dist < 8.0f * 8.0f) size = 1.0f / 96.0f; if (dist < 8.0f * 8.0f) size = 1.0f / 96.0f;
if (dist < 4.0f * 4.0f) size = 1.0f / 128.0f; if (dist < 4.0f * 4.0f) size = 1.0f / 128.0f;
if (dist < 2.0f * 2.0f) size = 1.0f / 192.0f; if (dist < 2.0f * 2.0f) size = 1.0f / 192.0f;
/* How a face is laid out:
#--#-------#--#<== OUTER_MAX (3)
| | | |
| #-------#<===== INNER_MAX (2)
| | | |
| | | |
| | | |
(1) INNER_MIN =====>#-------# |
| | | |
(0) OUTER_MIN ==>#--#-------#--#
/* bottom face */ - these are used to fake thick lines, by making the lines appear slightly inset
PickedPosRenderer_YQuad(p1.Y, p1.X, p1.Z + size, p1.X + size, p2.Z - size); - note: actual difference between inner and outer is much smaller then the diagram
PickedPosRenderer_YQuad(p1.Y, p2.X, p1.Z + size, p2.X - size, p2.Z - size); */
PickedPosRenderer_YQuad(p1.Y, p1.X, p1.Z, p2.X, p1.Z + size); Vector3 coords[4];
PickedPosRenderer_YQuad(p1.Y, p1.X, p2.Z, p2.X, p2.Z - size); Vector3_Add1(&coords[0], &selected->Min, -offset);
Vector3_Add1(&coords[1], &coords[0], size);
Vector3_Add1(&coords[3], &selected->Max, offset);
Vector3_Add1(&coords[2], &coords[3], -size);
/* top face */ #define PickedPos_Y(y)\
PickedPosRenderer_YQuad(p2.Y, p1.X, p1.Z + size, p1.X + size, p2.Z - size); 0,y,1, 0,y,2, 1,y,2, 1,y,1,\
PickedPosRenderer_YQuad(p2.Y, p2.X, p1.Z + size, p2.X - size, p2.Z - size); 3,y,1, 3,y,2, 2,y,2, 2,y,1,\
PickedPosRenderer_YQuad(p2.Y, p1.X, p1.Z, p2.X, p1.Z + size); 0,y,0, 0,y,1, 3,y,1, 3,y,0,\
PickedPosRenderer_YQuad(p2.Y, p1.X, p2.Z, p2.X, p2.Z - size); 0,y,3, 0,y,2, 3,y,2, 3,y,3,
/* left face */ #define PickedPos_X(x)\
PickedPosRenderer_XQuad(p1.X, p1.Z, p1.Y + size, p1.Z + size, p2.Y - size); x,1,0, x,2,0, x,2,1, x,1,1,\
PickedPosRenderer_XQuad(p1.X, p2.Z, p1.Y + size, p2.Z - size, p2.Y - size); x,1,3, x,2,3, x,2,2, x,1,2,\
PickedPosRenderer_XQuad(p1.X, p1.Z, p1.Y, p2.Z, p1.Y + size); x,0,0, x,1,0, x,1,3, x,0,3,\
PickedPosRenderer_XQuad(p1.X, p1.Z, p2.Y, p2.Z, p2.Y - size); x,3,0, x,2,0, x,2,3, x,3,3,
/* right face */ #define PickedPos_Z(z)\
PickedPosRenderer_XQuad(p2.X, p1.Z, p1.Y + size, p1.Z + size, p2.Y - size); 0,1,z, 0,2,z, 1,2,z, 1,1,z,\
PickedPosRenderer_XQuad(p2.X, p2.Z, p1.Y + size, p2.Z - size, p2.Y - size); 3,1,z, 3,2,z, 2,2,z, 2,1,z,\
PickedPosRenderer_XQuad(p2.X, p1.Z, p1.Y, p2.Z, p1.Y + size); 0,0,z, 0,1,z, 3,1,z, 3,0,z,\
PickedPosRenderer_XQuad(p2.X, p1.Z, p2.Y, p2.Z, p2.Y - size); 0,3,z, 0,2,z, 3,2,z, 3,3,z,
/* front face */ static UInt8 faces[288] = {
PickedPosRenderer_ZQuad(p1.Z, p1.X, p1.Y + size, p1.X + size, p2.Y - size); PickedPos_Y(0) PickedPos_Y(3) /* YMin, YMax */
PickedPosRenderer_ZQuad(p1.Z, p2.X, p1.Y + size, p2.X - size, p2.Y - size); PickedPos_X(0) PickedPos_X(3) /* XMin, XMax */
PickedPosRenderer_ZQuad(p1.Z, p1.X, p1.Y, p2.X, p1.Y + size); PickedPos_Z(0) PickedPos_Z(3) /* ZMin, ZMax */
PickedPosRenderer_ZQuad(p1.Z, p1.X, p2.Y, p2.X, p2.Y - size); };
PackedCol col = PACKEDCOL_CONST(0, 0, 0, 102);
VertexP3fC4b* ptr = pickedPos_vertices;
Int32 i;
/* back face */ for (i = 0; i < Array_Elems(faces); i += 3, ptr++) {
PickedPosRenderer_ZQuad(p2.Z, p1.X, p1.Y + size, p1.X + size, p2.Y - size); ptr->X = coords[faces[i + 0]].X;
PickedPosRenderer_ZQuad(p2.Z, p2.X, p1.Y + size, p2.X - size, p2.Y - size); ptr->Y = coords[faces[i + 1]].Y;
PickedPosRenderer_ZQuad(p2.Z, p1.X, p1.Y, p2.X, p1.Y + size); ptr->Z = coords[faces[i + 2]].Z;
PickedPosRenderer_ZQuad(p2.Z, p1.X, p2.Y, p2.X, p2.Y - size); ptr->Col = col;
}
} }
void PickedPosRenderer_MakeComponent(struct IGameComponent* comp) { void PickedPosRenderer_MakeComponent(struct IGameComponent* comp) {

View File

@ -64,7 +64,7 @@ int main(void) {
String title = String_FromConst(PROGRAM_APP_NAME); String title = String_FromConst(PROGRAM_APP_NAME);
String rawArgs = Platform_GetCommandLineArgs(); String rawArgs = Platform_GetCommandLineArgs();
/* NOTE: Make sure to comment this out before pushing a commit */ /* NOTE: Make sure to comment this out before pushing a commit */
//rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566"); rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565");
String args[5]; Int32 argsCount = Array_Elems(args); String args[5]; Int32 argsCount = Array_Elems(args);
String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);

View File

@ -15,34 +15,48 @@ struct SelectionBox {
void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4b** lineVertices) { void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4b** lineVertices) {
Real32 offset = box->MinDist < 32.0f * 32.0f ? (1.0f / 32.0f) : (1.0f / 16.0f); Real32 offset = box->MinDist < 32.0f * 32.0f ? (1.0f / 32.0f) : (1.0f / 16.0f);
Vector3 p1 = box->Min, p2 = box->Max; Vector3 coords[2];
Vector3_Add1(&p1, &p1, -offset); Vector3_Add1(&coords[0], &box->Min, -offset);
Vector3_Add1(&p2, &p2, offset); Vector3_Add1(&coords[1], &box->Max, offset);
Int32 i;
VertexP3fC4b* ptr;
PackedCol col = box->Col; PackedCol col = box->Col;
SelectionBox_HorQuad(vertices, col, p1.X, p1.Z, p2.X, p2.Z, p1.Y); /* bottom */ #define SelectionBox_Y(y) 0,y,0, 0,y,1, 1,y,1, 1,y,0,
SelectionBox_HorQuad(vertices, col, p1.X, p1.Z, p2.X, p2.Z, p2.Y); /* top */ #define SelectionBox_Z(z) 0,0,z, 0,1,z, 1,1,z, 1,0,z,
SelectionBox_VerQuad(vertices, col, p1.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z); /* sides */ #define SelectionBox_X(x) x,0,0, x,1,0, x,1,1, x,0,1,
SelectionBox_VerQuad(vertices, col, p1.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z);
SelectionBox_VerQuad(vertices, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p2.Z); static UInt8 faceIndices[72] = {
SelectionBox_VerQuad(vertices, col, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z); SelectionBox_Y(0) SelectionBox_Y(1) /* YMin, YMax */
SelectionBox_Z(0) SelectionBox_Z(1) /* ZMin, ZMax */
SelectionBox_X(0) SelectionBox_X(1) /* XMin, XMax */
};
ptr = *vertices;
for (i = 0; i < Array_Elems(faceIndices); i += 3, ptr++) {
ptr->X = coords[faceIndices[i + 0]].X;
ptr->Y = coords[faceIndices[i + 1]].Y;
ptr->Z = coords[faceIndices[i + 2]].Z;
ptr->Col = col;
}
*vertices = ptr;
col.R = ~col.R; col.G = ~col.G; col.B = ~col.B; col.R = ~col.R; col.G = ~col.G; col.B = ~col.B;
/* bottom face */ static UInt8 edgeIndices[72] = {
SelectionBox_Line(lineVertices, col, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z); 0,0,0, 1,0,0, 1,0,0, 1,0,1, 1,0,1, 0,0,1, 0,0,1, 0,0,0, /* YMin */
SelectionBox_Line(lineVertices, col, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z); 0,1,0, 1,1,0, 1,1,0, 1,1,1, 1,1,1, 0,1,1, 0,1,1, 0,1,0, /* YMax */
SelectionBox_Line(lineVertices, col, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z); 0,0,0, 0,1,0, 1,0,0, 1,1,0, 1,0,1, 1,1,1, 0,0,1, 0,1,1, /* X/Z */
SelectionBox_Line(lineVertices, col, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z); };
/* top face */
SelectionBox_Line(lineVertices, col, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z); ptr = *lineVertices;
SelectionBox_Line(lineVertices, col, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z); for (i = 0; i < Array_Elems(edgeIndices); i += 3, ptr++) {
SelectionBox_Line(lineVertices, col, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z); ptr->X = coords[edgeIndices[i + 0]].X;
SelectionBox_Line(lineVertices, col, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z); ptr->Y = coords[edgeIndices[i + 1]].Y;
/* side faces */ ptr->Z = coords[edgeIndices[i + 2]].Z;
SelectionBox_Line(lineVertices, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z); ptr->Col = col;
SelectionBox_Line(lineVertices, col, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z); }
SelectionBox_Line(lineVertices, col, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z); *lineVertices = ptr;
SelectionBox_Line(lineVertices, col, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z);
} }
void SelectionBox_VerQuad(VertexP3fC4b** vertices, PackedCol col, void SelectionBox_VerQuad(VertexP3fC4b** vertices, PackedCol col,
@ -69,16 +83,6 @@ void SelectionBox_HorQuad(VertexP3fC4b** vertices, PackedCol col,
*vertices = ptr; *vertices = ptr;
} }
void SelectionBox_Line(VertexP3fC4b** vertices, PackedCol col,
Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2) {
VertexP3fC4b* ptr = *vertices;
VertexP3fC4b v; v.Col = col;
v.X = x1; v.Y = y1; v.Z = z1; *ptr++ = v;
v.X = x2; v.Y = y2; v.Z = z2; *ptr++ = v;
*vertices = ptr;
}
static Int32 SelectionBox_Compare(struct SelectionBox* a, struct SelectionBox* b) { static Int32 SelectionBox_Compare(struct SelectionBox* a, struct SelectionBox* b) {
Real32 aDist, bDist; Real32 aDist, bDist;
@ -205,7 +209,7 @@ void Selections_Render(Real64 delta) {
VertexP3fC4b vertices[SELECTIONS_MAX_VERTICES]; VertexP3fC4b* ptr = vertices; VertexP3fC4b vertices[SELECTIONS_MAX_VERTICES]; VertexP3fC4b* ptr = vertices;
VertexP3fC4b lineVertices[SELECTIONS_MAX_VERTICES]; VertexP3fC4b* linePtr = lineVertices; VertexP3fC4b lineVertices[SELECTIONS_MAX_VERTICES]; VertexP3fC4b* linePtr = lineVertices;
for (i = 0; i < selections_count; i++) { for (i = 0; i < selections_count; i++) {
SelectionBox_Render(&selections_list[i], &ptr, &linePtr); SelectionBox_Render(&selections_list[i], &ptr, &linePtr);
} }