Skip to content
Permalink
Browse files

more comments

  • Loading branch information...
UnknownShadow200 committed Jun 8, 2019
1 parent 8603b7f commit b0794ef8268994e72424dfc81fe40bbe3d43f018
Showing with 68 additions and 44 deletions.
  1. +1 −1 src/Drawer2D.h
  2. +2 −2 src/Gui.h
  3. +6 −6 src/PacketHandlers.c
  4. +1 −1 src/Screens.c
  5. +22 −22 src/Server.c
  6. +6 −3 src/Server.h
  7. +6 −6 src/Widgets.c
  8. +24 −3 src/Widgets.h
@@ -3,7 +3,7 @@
#include "PackedCol.h"
#include "Constants.h"
#include "Bitmap.h"
/* Responsible for performing drawing operations on bitmaps, and for converting bitmaps into textures.
/* Performs a variety of drawing operations on bitmaps, and converts bitmaps into textures.
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/

@@ -79,9 +79,9 @@ struct WidgetVTABLE {
};
#define Widget_Layout struct WidgetVTABLE* VTABLE; \
int x, y, width, height; /* Top left corner, and dimensions, of this widget */ \
bool active; /* Whether this widget is currently being moused over*/ \
bool active; /* Whether this widget is currently being moused over */ \
bool disabled; /* Whether widget is prevented from being interacted with */ \
uint8_t horAnchor, verAnchor; /* Specifies the reference point for when this widget is resized */ \
uint8_t horAnchor, verAnchor; /* The reference point for when this widget is resized */ \
int xOffset, yOffset; /* Offset from the reference point */ \
Widget_LeftClick MenuClick;

@@ -773,12 +773,12 @@ static void CPE_SendExtEntry(const String* extName, int extVersion) {
Server.SendData(data, 69);
}

static void CPE_WriteTwoWayPing(bool serverToClient, int payload) {
static void CPE_WriteTwoWayPing(bool serverToClient, int id) {
uint8_t* data = Server.WriteBuffer;
*data++ = OPCODE_TWO_WAY_PING;
{
*data++ = serverToClient;
Stream_SetU16_BE(data, payload); data += 2;
Stream_SetU16_BE(data, id); data += 2;
}
Server.WriteBuffer = data;
}
@@ -1296,12 +1296,12 @@ static void CPE_SetEntityProperty(uint8_t* data) {

static void CPE_TwoWayPing(uint8_t* data) {
uint8_t serverToClient = *data++;
int payload = Stream_GetU16_BE(data);
int id = Stream_GetU16_BE(data);

if (serverToClient) {
CPE_WriteTwoWayPing(true, payload); /* server to client reply */
CPE_WriteTwoWayPing(true, id); /* server to client reply */
Net_SendPacket();
} else { PingList_Update(payload); }
} else { Ping_Update(id); }
}

static void CPE_SetInventoryOrder(uint8_t* data) {
@@ -1355,7 +1355,7 @@ static void CPE_Reset(void) {
static void CPE_Tick(void) {
cpe_pingTicks++;
if (cpe_pingTicks >= 20 && cpe_twoWayPing) {
CPE_WriteTwoWayPing(false, PingList_NextPingData());
CPE_WriteTwoWayPing(false, Ping_NextPingId());
cpe_pingTicks = 0;
}
}
@@ -274,7 +274,7 @@ static void StatusScreen_MakeText(struct StatusScreen* s, String* status) {
indices = ICOUNT(Game_Vertices);
String_Format1(status, "%i vertices", &indices);

ping = PingList_AveragePingMs();
ping = Ping_AveragePingMS();
if (ping) String_Format1(status, ", ping %i ms", &ping);
}
}
@@ -86,43 +86,43 @@ static void Server_CheckAsyncResources(void) {
/*########################################################################################################################*
*--------------------------------------------------------PingList---------------------------------------------------------*
*#########################################################################################################################*/
struct PingEntry { int64_t Sent, Recv; uint16_t Data; };
static struct PingEntry pingList_entries[10];
static int pingList_head;

int PingList_NextPingData(void) {
int head = pingList_head;
int next = pingList_entries[head].Data + 1;

head = (head + 1) % Array_Elems(pingList_entries);
pingList_entries[head].Data = next;
pingList_entries[head].Sent = DateTime_CurrentUTC_MS();
pingList_entries[head].Recv = 0;
struct PingEntry { int64_t sent, recv; uint16_t id; };
static struct PingEntry ping_entries[10];
static int ping_head;

int Ping_NextPingId(void) {
int head = ping_head;
int next = ping_entries[head].id + 1;

head = (head + 1) % Array_Elems(ping_entries);
ping_entries[head].id = next;
ping_entries[head].sent = DateTime_CurrentUTC_MS();
ping_entries[head].recv = 0;

pingList_head = head;
ping_head = head;
return next;
}

void PingList_Update(int data) {
void Ping_Update(int id) {
int i;
for (i = 0; i < Array_Elems(pingList_entries); i++) {
if (pingList_entries[i].Data != data) continue;
for (i = 0; i < Array_Elems(ping_entries); i++) {
if (ping_entries[i].id != id) continue;

pingList_entries[i].Recv = DateTime_CurrentUTC_MS();
ping_entries[i].recv = DateTime_CurrentUTC_MS();
return;
}
}

int PingList_AveragePingMs(void) {
int Ping_AveragePingMS(void) {
double totalMs = 0.0;
int i, measures = 0;

for (i = 0; i < Array_Elems(pingList_entries); i++) {
struct PingEntry entry = pingList_entries[i];
if (!entry.Sent || !entry.Recv) continue;
for (i = 0; i < Array_Elems(ping_entries); i++) {
struct PingEntry entry = ping_entries[i];
if (!entry.sent || !entry.recv) continue;

/* Half, because received->reply time is actually twice time it takes to send data */
totalMs += (entry.Recv - entry.Sent) * 0.5;
totalMs += (entry.recv - entry.sent) * 0.5;
measures++;
}
return measures == 0 ? 0 : (int)(totalMs / measures);
@@ -42,9 +42,12 @@ struct IGameComponent;
struct ScheduledTask;
extern struct IGameComponent Server_Component;

int PingList_NextPingData(void);
void PingList_Update(int data);
int PingList_AveragePingMs(void);
/* Prepares a ping entry for sending to the server, then returns its ID. */
int Ping_NextPingId(void);
/* Updates received time for ping entry with matching ID. */
void Ping_Update(int id);
/* Calculates average ping time based on most recent ping entries. */
int Ping_AveragePingMS(void);

/* Data for currently active connection to a server. */
CC_VAR extern struct _ServerConnectionData {
@@ -64,11 +64,6 @@ void TextWidget_Make(struct TextWidget* w) {
w->col = col;
}

void TextWidget_Create(struct TextWidget* w, const String* text, const FontDesc* font) {
TextWidget_Make(w);
TextWidget_Set(w, text, font);
}

void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* font) {
struct DrawTextArgs args;
Gfx_DeleteTexture(&w->texture.ID);
@@ -90,6 +85,11 @@ void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* fo
w->texture.X = w->x; w->texture.Y = w->y;
}

void TextWidget_Create(struct TextWidget* w, const String* text, const FontDesc* font) {
TextWidget_Make(w);
TextWidget_Set(w, text, font);
}


/*########################################################################################################################*
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
@@ -2196,7 +2196,7 @@ static void TextGroupWidget_UpdateY(struct TextGroupWidget* w) {
}
} else {
y = Window_Height - w->yOffset;
for (i = w->lines- 1; i >= 0; i--) {
for (i = w->lines - 1; i >= 0; i--) {
y -= textures[i].Height;
textures[i].Y = y;
}
@@ -8,20 +8,25 @@
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/

/* A text label. */
struct TextWidget {
Widget_Layout
struct Texture texture;

bool reducePadding;
PackedCol col;
};
/* Resets state of the given text widget to default. */
CC_NOINLINE void TextWidget_Make(struct TextWidget* w);
CC_NOINLINE void TextWidget_Create(struct TextWidget* w, const String* text, const FontDesc* font);
/* Draws the given text into a texture, then updates the position and size of this widget. */
CC_NOINLINE void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* font);
/* Shorthand for TextWidget_Make then TextWidget_Set */
CC_NOINLINE void TextWidget_Create(struct TextWidget* w, const String* text, const FontDesc* font);


typedef void (*Button_Get)(String* raw);
typedef void (*Button_Set)(const String* raw);
/* A labelled button that can be clicked on. */
struct ButtonWidget {
Widget_Layout
struct Texture texture;
@@ -31,20 +36,23 @@ struct ButtonWidget {
Button_Get GetValue;
Button_Set SetValue;
};
/* Resets state of the given button widget, then calls ButtonWidget_Set */
CC_NOINLINE void ButtonWidget_Create(struct ButtonWidget* w, int minWidth, const String* text, const FontDesc* font, Widget_LeftClick onClick);
/* Draws the given text into a texture, then updates the position and size of this widget. */
CC_NOINLINE void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const FontDesc* font);


/* Clickable and draggable scrollbar. */
struct ScrollbarWidget {
Widget_Layout
int totalRows, topRow;
float scrollingAcc;
int mouseOffset;
bool draggingMouse;
};
/* Resets state of the given scrollbar widget to default. */
CC_NOINLINE void ScrollbarWidget_Create(struct ScrollbarWidget* w);


/* A row of blocks with a background. */
struct HotbarWidget {
Widget_Layout
struct Texture selTex, backTex;
@@ -53,9 +61,11 @@ struct HotbarWidget {
float scrollAcc;
bool altHandled;
};
/* Resets state of the given hotbar widget to default. */
CC_NOINLINE void HotbarWidget_Create(struct HotbarWidget* w);


/* A table of blocks. */
struct TableWidget {
Widget_Layout
int elementsCount, elementsPerRow, rowsCount;
@@ -108,8 +118,11 @@ struct InputWidget {
double caretAccumulator;
};

/* Removes all characters and then deletes the input texture. */
CC_NOINLINE void InputWidget_Clear(struct InputWidget* w);
/* Tries appending all characters from the given string, then update the input texture. */
CC_NOINLINE void InputWidget_AppendString(struct InputWidget* w, const String* text);
/* Tries appending the given character, then updates the input texture. */
CC_NOINLINE void InputWidget_Append(struct InputWidget* w, char c);


@@ -175,6 +188,7 @@ typedef String (*TextGroupWidget_Get)(void* obj, int i);
#define TEXTGROUPWIDGET_MAX_LINES 30
#define TEXTGROUPWIDGET_LEN (STRING_SIZE + (STRING_SIZE / 2))

/* A group of text labels. */
struct TextGroupWidget {
Widget_Layout
int lines, defaultHeight;
@@ -187,17 +201,24 @@ struct TextGroupWidget {
};

CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, const FontDesc* font, STRING_REF struct Texture* textures, TextGroupWidget_Get getLine);
/* Sets whether the given line has non-zero height when that line has no text in it. */
/* By default, all lines are placeholder lines. */
CC_NOINLINE void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder);
/* Deletes first line, then moves all other lines upwards, then redraws last line. */
/* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */
CC_NOINLINE void TextGroupWidget_ShiftUp(struct TextGroupWidget* w);
/* Deletes last line, then moves all other lines downwards, then redraws first line. */
/* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */
CC_NOINLINE void TextGroupWidget_ShiftDown(struct TextGroupWidget* w);
/* Returns height of lines, except for the first 0 or more empty lines. */
CC_NOINLINE int TextGroupWidget_UsedHeight(struct TextGroupWidget* w);
/* Returns either the URL or the line underneath the given coordinates. */
CC_NOINLINE void TextGroupWidget_GetSelected(struct TextGroupWidget* w, String* text, int mouseX, int mouseY);
/* Redraws the given line, updating the texture and Y position of other lines. */
CC_NOINLINE void TextGroupWidget_Redraw(struct TextGroupWidget* w, int index);
/* Calls TextGroupWidget_Redraw for all lines */
CC_NOINLINE void TextGroupWidget_RedrawAll(struct TextGroupWidget* w);
/* Gets the text for the i'th line. */
static String TextGroupWidget_UNSAFE_Get(struct TextGroupWidget* w, int i) { return w->GetLine(w->getLineObj, i); }


0 comments on commit b0794ef

Please sign in to comment.
You can’t perform that action at this time.