mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 02:56:09 -04:00
cleanup protocol.c a bit and make launcher widget vtables const
This commit is contained in:
parent
a8b230bebc
commit
746e8fdd87
@ -617,17 +617,17 @@ static cc_bool PushbackPlace(struct AABB* blockBB) {
|
||||
|
||||
static cc_bool IntersectsOthers(Vec3 pos, BlockID block) {
|
||||
struct AABB blockBB, entityBB;
|
||||
struct Entity* entity;
|
||||
struct Entity* e;
|
||||
int id;
|
||||
|
||||
Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]);
|
||||
Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]);
|
||||
|
||||
for (id = 0; id < ENTITIES_SELF_ID; id++) {
|
||||
entity = Entities.List[id];
|
||||
if (!entity) continue;
|
||||
e = Entities.List[id];
|
||||
if (!e) continue;
|
||||
|
||||
Entity_GetBounds(entity, &entityBB);
|
||||
Entity_GetBounds(e, &entityBB);
|
||||
entityBB.Min.Y += 1.0f / 32.0f; /* when player is exactly standing on top of ground */
|
||||
if (AABB_Intersects(&entityBB, &blockBB)) return true;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ static void LButton_Hover(void* w, int x, int y, cc_bool wasOver) {
|
||||
if (!wasOver) LWidget_Draw(w);
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE lbutton_VTABLE = {
|
||||
const static struct LWidgetVTABLE lbutton_VTABLE = {
|
||||
LButton_Draw, NULL,
|
||||
NULL, NULL, /* Key */
|
||||
LButton_Hover, LWidget_Draw, /* Hover */
|
||||
@ -433,7 +433,7 @@ static cc_bool LInput_DefaultInputFilter(char c) {
|
||||
return c >= ' ' && c <= '~' && c != '&';
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE linput_VTABLE = {
|
||||
const static struct LWidgetVTABLE linput_VTABLE = {
|
||||
LInput_Draw, LInput_TickCaret,
|
||||
LInput_KeyDown, LInput_KeyChar, /* Key */
|
||||
NULL, NULL, /* Hover */
|
||||
@ -548,7 +548,7 @@ static void LLabel_Draw(void* widget) {
|
||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args, w->x, w->y);
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE llabel_VTABLE = {
|
||||
const static struct LWidgetVTABLE llabel_VTABLE = {
|
||||
LLabel_Draw, NULL,
|
||||
NULL, NULL, /* Key */
|
||||
NULL, NULL, /* Hover */
|
||||
@ -588,7 +588,7 @@ static void LLine_Draw(void* widget) {
|
||||
Gradient_Blend(&Launcher_Framebuffer, w->col, 128, w->x, w->y, w->width, w->height);
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE lline_VTABLE = {
|
||||
const static struct LWidgetVTABLE lline_VTABLE = {
|
||||
LLine_Draw, NULL,
|
||||
NULL, NULL, /* Key */
|
||||
NULL, NULL, /* Hover */
|
||||
@ -651,7 +651,7 @@ static void LSlider_Draw(void* widget) {
|
||||
curWidth, w->height - BORDER2);
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE lslider_VTABLE = {
|
||||
const static struct LWidgetVTABLE lslider_VTABLE = {
|
||||
LSlider_Draw, NULL,
|
||||
NULL, NULL, /* Key */
|
||||
NULL, NULL, /* Hover */
|
||||
@ -1085,7 +1085,7 @@ static void LTable_Draw(void* widget) {
|
||||
Launcher_MarkAllDirty();
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE ltable_VTABLE = {
|
||||
const static struct LWidgetVTABLE ltable_VTABLE = {
|
||||
LTable_Draw, NULL,
|
||||
LTable_KeyDown, NULL, /* Key */
|
||||
LTable_MouseMove, NULL, /* Hover */
|
||||
|
@ -33,7 +33,7 @@ struct LWidgetVTABLE {
|
||||
};
|
||||
|
||||
#define LWidget_Layout \
|
||||
struct LWidgetVTABLE* VTABLE; /* General widget functions */ \
|
||||
const struct LWidgetVTABLE* VTABLE; /* General widget functions */ \
|
||||
int x, y, width, height; /* Top left corner, and dimensions, of this widget */ \
|
||||
cc_bool hovered; /* Whether this widget is currently being moused over */ \
|
||||
cc_bool selected; /* Whether this widget is last widget to be clicked on */ \
|
||||
|
@ -178,8 +178,8 @@ static void Protocol_AddEntity(cc_uint8* data, EntityID id, const String* displa
|
||||
}
|
||||
|
||||
void Protocol_RemoveEntity(EntityID id) {
|
||||
struct Entity* entity = Entities.List[id];
|
||||
if (!entity) return;
|
||||
struct Entity* e = Entities.List[id];
|
||||
if (!e) return;
|
||||
if (id != ENTITIES_SELF_ID) Entities_Remove(id);
|
||||
|
||||
/* See comment about some servers in Classic_AddEntity */
|
||||
@ -188,11 +188,9 @@ void Protocol_RemoveEntity(EntityID id) {
|
||||
Classic_TabList_Reset(id);
|
||||
}
|
||||
|
||||
static void Protocol_UpdateLocation(EntityID playerId, struct LocationUpdate* update, cc_bool interpolate) {
|
||||
struct Entity* entity = Entities.List[playerId];
|
||||
if (entity) {
|
||||
entity->VTABLE->SetLocation(entity, update, interpolate);
|
||||
}
|
||||
static void Protocol_UpdateLocation(EntityID id, struct LocationUpdate* update, cc_bool interpolate) {
|
||||
struct Entity* e = Entities.List[id];
|
||||
if (e) { e->VTABLE->SetLocation(e, update, interpolate); }
|
||||
}
|
||||
|
||||
|
||||
@ -1066,12 +1064,12 @@ static void CPE_SetBlockPermission(cc_uint8* data) {
|
||||
}
|
||||
|
||||
static void CPE_ChangeModel(cc_uint8* data) {
|
||||
struct Entity* entity;
|
||||
struct Entity* e;
|
||||
EntityID id = data[0];
|
||||
String model = Protocol_UNSAFE_GetString(data + 1);
|
||||
|
||||
entity = Entities.List[id];
|
||||
if (entity) Entity_SetModel(entity, &model);
|
||||
e = Entities.List[id];
|
||||
if (e) Entity_SetModel(e, &model);
|
||||
}
|
||||
|
||||
static void CPE_EnvSetMapAppearance(cc_uint8* data) {
|
||||
@ -1233,15 +1231,15 @@ static void CPE_SetMapEnvProperty(cc_uint8* data) {
|
||||
|
||||
static void CPE_SetEntityProperty(cc_uint8* data) {
|
||||
struct LocationUpdate update = { 0 };
|
||||
struct Entity* entity;
|
||||
struct Entity* e;
|
||||
float scale;
|
||||
|
||||
EntityID id = data[0];
|
||||
cc_uint8 type = data[1];
|
||||
int value = (int)Stream_GetU32_BE(data + 2);
|
||||
|
||||
entity = Entities.List[id];
|
||||
if (!entity) return;
|
||||
e = Entities.List[id];
|
||||
if (!e) return;
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
@ -1258,20 +1256,20 @@ static void CPE_SetEntityProperty(cc_uint8* data) {
|
||||
case 4:
|
||||
case 5:
|
||||
scale = value / 1000.0f;
|
||||
if (entity->ModelRestrictedScale) {
|
||||
Math_Clamp(scale, 0.01f, entity->Model->maxScale);
|
||||
if (e->ModelRestrictedScale) {
|
||||
Math_Clamp(scale, 0.01f, e->Model->maxScale);
|
||||
}
|
||||
|
||||
if (type == 3) entity->ModelScale.X = scale;
|
||||
if (type == 4) entity->ModelScale.Y = scale;
|
||||
if (type == 5) entity->ModelScale.Z = scale;
|
||||
if (type == 3) e->ModelScale.X = scale;
|
||||
if (type == 4) e->ModelScale.Y = scale;
|
||||
if (type == 5) e->ModelScale.Z = scale;
|
||||
|
||||
Entity_UpdateModelBounds(entity);
|
||||
Entity_UpdateModelBounds(e);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
entity->VTABLE->SetLocation(entity, &update, true);
|
||||
e->VTABLE->SetLocation(e, &update, true);
|
||||
}
|
||||
|
||||
static void CPE_TwoWayPing(cc_uint8* data) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user