mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
use more compat tablist representation in memory, 1kb less usage
This commit is contained in:
parent
e105b53648
commit
aabfab54cf
49
src/Entity.c
49
src/Entity.c
@ -686,32 +686,20 @@ void Entities_DrawShadows(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct _TabListData TabList;
|
struct _TabListData TabList;
|
||||||
|
|
||||||
bool TabList_Valid(EntityID id) {
|
static void TabList_Delete(EntityID id) {
|
||||||
return TabList.PlayerNames[id] || TabList.ListNames[id] || TabList.GroupNames[id];
|
int i, index;
|
||||||
}
|
index = TabList.NameOffsets[id];
|
||||||
|
if (!index) return;
|
||||||
|
|
||||||
static void TabList_RemoveAt(int index) {
|
StringsBuffer_Remove(&TabList._buffer, index - 1);
|
||||||
int i;
|
StringsBuffer_Remove(&TabList._buffer, index - 2);
|
||||||
StringsBuffer_Remove(&TabList.Buffer, index);
|
StringsBuffer_Remove(&TabList._buffer, index - 3);
|
||||||
|
|
||||||
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
||||||
if (TabList.PlayerNames[i] == index) { TabList.PlayerNames[i] = 0; }
|
if (TabList.NameOffsets[i] > index) TabList.NameOffsets[i] -= 3;
|
||||||
if (TabList.PlayerNames[i] > index) { TabList.PlayerNames[i]--; }
|
|
||||||
|
|
||||||
if (TabList.ListNames[i] == index) { TabList.ListNames[i] = 0; }
|
|
||||||
if (TabList.ListNames[i] > index) { TabList.ListNames[i]--; }
|
|
||||||
|
|
||||||
if (TabList.GroupNames[i] == index) { TabList.GroupNames[i] = 0; }
|
|
||||||
if (TabList.GroupNames[i] > index) { TabList.GroupNames[i]--; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TabList_Delete(EntityID id) {
|
TabList.NameOffsets[id] = 0;
|
||||||
if (!TabList_Valid(id)) return;
|
|
||||||
|
|
||||||
TabList_RemoveAt(TabList.PlayerNames[id]);
|
|
||||||
TabList_RemoveAt(TabList.ListNames[id]);
|
|
||||||
TabList_RemoveAt(TabList.GroupNames[id]);
|
|
||||||
TabList.GroupRanks[id] = 0;
|
TabList.GroupRanks[id] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,7 +713,7 @@ void TabList_Set(EntityID id, const String* player, const String* list, const St
|
|||||||
uint8_t oldRank;
|
uint8_t oldRank;
|
||||||
struct Event_Int* events;
|
struct Event_Int* events;
|
||||||
|
|
||||||
if (TabList_Valid(id)) {
|
if (TabList.NameOffsets[id]) {
|
||||||
oldPlayer = TabList_UNSAFE_GetPlayer(id);
|
oldPlayer = TabList_UNSAFE_GetPlayer(id);
|
||||||
oldList = TabList_UNSAFE_GetList(id);
|
oldList = TabList_UNSAFE_GetList(id);
|
||||||
oldGroup = TabList_UNSAFE_GetGroup(id);
|
oldGroup = TabList_UNSAFE_GetGroup(id);
|
||||||
@ -741,21 +729,20 @@ void TabList_Set(EntityID id, const String* player, const String* list, const St
|
|||||||
}
|
}
|
||||||
TabList_Delete(id);
|
TabList_Delete(id);
|
||||||
|
|
||||||
TabList.PlayerNames[id] = TabList.Buffer.count; StringsBuffer_Add(&TabList.Buffer, player);
|
StringsBuffer_Add(&TabList._buffer, player);
|
||||||
TabList.ListNames[id] = TabList.Buffer.count; StringsBuffer_Add(&TabList.Buffer, list);
|
StringsBuffer_Add(&TabList._buffer, list);
|
||||||
TabList.GroupNames[id] = TabList.Buffer.count; StringsBuffer_Add(&TabList.Buffer, group);
|
StringsBuffer_Add(&TabList._buffer, group);
|
||||||
TabList.GroupRanks[id] = rank;
|
|
||||||
|
|
||||||
|
TabList.NameOffsets[id] = TabList._buffer.count;
|
||||||
|
TabList.GroupRanks[id] = rank;
|
||||||
Event_RaiseInt(events, id);
|
Event_RaiseInt(events, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TabList_Free(void) { StringsBuffer_Clear(&TabList.Buffer); }
|
static void TabList_Free(void) { StringsBuffer_Clear(&TabList._buffer); }
|
||||||
static void TabList_Reset(void) {
|
static void TabList_Reset(void) {
|
||||||
Mem_Set(TabList.PlayerNames, 0, sizeof(TabList.PlayerNames));
|
Mem_Set(TabList.NameOffsets, 0, sizeof(TabList.NameOffsets));
|
||||||
Mem_Set(TabList.ListNames, 0, sizeof(TabList.ListNames));
|
|
||||||
Mem_Set(TabList.GroupNames, 0, sizeof(TabList.GroupNames));
|
|
||||||
Mem_Set(TabList.GroupRanks, 0, sizeof(TabList.GroupRanks));
|
Mem_Set(TabList.GroupRanks, 0, sizeof(TabList.GroupRanks));
|
||||||
StringsBuffer_Clear(&TabList.Buffer);
|
StringsBuffer_Clear(&TabList._buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IGameComponent TabList_Component = {
|
struct IGameComponent TabList_Component = {
|
||||||
|
23
src/Entity.h
23
src/Entity.h
@ -151,28 +151,27 @@ void Entities_DrawShadows(void);
|
|||||||
#define TABLIST_MAX_NAMES 256
|
#define TABLIST_MAX_NAMES 256
|
||||||
/* Data for all entries in tab list */
|
/* Data for all entries in tab list */
|
||||||
CC_VAR extern struct _TabListData {
|
CC_VAR extern struct _TabListData {
|
||||||
/* Raw unformatted name (for Tab name auto complete) */
|
/* Buffer indices for player/list/group names. */
|
||||||
uint16_t PlayerNames[TABLIST_MAX_NAMES];
|
/* Use TabList_UNSAFE_GetPlayer/List/Group to get these names. */
|
||||||
/* Formatted name for display in tab list. */
|
/* NOTE: An Offset of 0 means the entry is unused. */
|
||||||
uint16_t ListNames[TABLIST_MAX_NAMES];
|
uint16_t NameOffsets[TABLIST_MAX_NAMES];
|
||||||
/* Name of the group this entry is in (e.g. rank name, map name) */
|
|
||||||
uint16_t GroupNames[TABLIST_MAX_NAMES];
|
|
||||||
/* Position/Order of this entry within the group. */
|
/* Position/Order of this entry within the group. */
|
||||||
uint8_t GroupRanks[TABLIST_MAX_NAMES];
|
uint8_t GroupRanks[TABLIST_MAX_NAMES];
|
||||||
StringsBuffer Buffer;
|
StringsBuffer _buffer;
|
||||||
} TabList;
|
} TabList;
|
||||||
|
|
||||||
/* Returns whether the tab list entry with the given ID is used at all. */
|
|
||||||
CC_API bool TabList_Valid(EntityID id);
|
|
||||||
/* Removes the tab list entry with the given ID, raising TabListEvents.Removed event. */
|
/* Removes the tab list entry with the given ID, raising TabListEvents.Removed event. */
|
||||||
CC_API void TabList_Remove(EntityID id);
|
CC_API void TabList_Remove(EntityID id);
|
||||||
/* Sets the data for the tab list entry with the given id. */
|
/* Sets the data for the tab list entry with the given id. */
|
||||||
/* Raises TabListEvents.Changed if replacing, TabListEvents.Added if a new entry. */
|
/* Raises TabListEvents.Changed if replacing, TabListEvents.Added if a new entry. */
|
||||||
CC_API void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank);
|
CC_API void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank);
|
||||||
|
|
||||||
#define TabList_UNSAFE_GetPlayer(id) StringsBuffer_UNSAFE_Get(&TabList.Buffer, TabList.PlayerNames[id]);
|
/* Raw unformatted name (for Tab name auto complete) */
|
||||||
#define TabList_UNSAFE_GetList(id) StringsBuffer_UNSAFE_Get(&TabList.Buffer, TabList.ListNames[id]);
|
#define TabList_UNSAFE_GetPlayer(id) StringsBuffer_UNSAFE_Get(&TabList._buffer, TabList.NameOffsets[id] - 3);
|
||||||
#define TabList_UNSAFE_GetGroup(id) StringsBuffer_UNSAFE_Get(&TabList.Buffer, TabList.GroupNames[id]);
|
/* Formatted name for display in tab list. */
|
||||||
|
#define TabList_UNSAFE_GetList(id) StringsBuffer_UNSAFE_Get(&TabList._buffer, TabList.NameOffsets[id] - 2);
|
||||||
|
/* Name of the group this entry is in (e.g. rank name, map name) */
|
||||||
|
#define TabList_UNSAFE_GetGroup(id) StringsBuffer_UNSAFE_Get(&TabList._buffer, TabList.NameOffsets[id] - 1);
|
||||||
|
|
||||||
/* Represents another entity in multiplayer */
|
/* Represents another entity in multiplayer */
|
||||||
struct NetPlayer {
|
struct NetPlayer {
|
||||||
|
@ -1688,12 +1688,11 @@ static void ChatInputWidget_TabKey(struct InputWidget* w) {
|
|||||||
numMatches = 0;
|
numMatches = 0;
|
||||||
|
|
||||||
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
||||||
EntityID id = (EntityID)i;
|
if (!TabList.NameOffsets[i]) continue;
|
||||||
if (!TabList_Valid(id)) continue;
|
|
||||||
|
|
||||||
name = TabList_UNSAFE_GetPlayer(i);
|
name = TabList_UNSAFE_GetPlayer(i);
|
||||||
if (!String_CaselessContains(&name, &part)) continue;
|
if (!String_CaselessContains(&name, &part)) continue;
|
||||||
matches[numMatches++] = id;
|
matches[numMatches++] = (EntityID)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numMatches == 1) {
|
if (numMatches == 1) {
|
||||||
@ -2079,7 +2078,7 @@ static void PlayerListWidget_Init(void* widget) {
|
|||||||
int id;
|
int id;
|
||||||
|
|
||||||
for (id = 0; id < TABLIST_MAX_NAMES; id++) {
|
for (id = 0; id < TABLIST_MAX_NAMES; id++) {
|
||||||
if (!TabList_Valid((EntityID)id)) continue;
|
if (!TabList.NameOffsets[id]) continue;
|
||||||
PlayerListWidget_AddName(w, (EntityID)id, -1);
|
PlayerListWidget_AddName(w, (EntityID)id, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user