mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 02:56:09 -04:00
more c90 rewrite
This commit is contained in:
parent
59e444ed72
commit
ad78ab8d0d
24
src/Entity.c
24
src/Entity.c
@ -473,39 +473,43 @@ void TabList_MakeComponent(struct IGameComponent* comp) {
|
||||
*---------------------------------------------------------Player----------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define PLAYER_NAME_EMPTY_TEX -30000
|
||||
#define NAME_OFFSET 3 /* offset of back layer of name above an entity */
|
||||
|
||||
static void Player_MakeNameTexture(struct Player* player) {
|
||||
String colorlessName; char colorlessBuffer[STRING_SIZE];
|
||||
struct DrawTextArgs args;
|
||||
bool bitmapped;
|
||||
String name;
|
||||
Size2D size;
|
||||
Bitmap bmp;
|
||||
|
||||
/* we want names to always be drawn not using the system font */
|
||||
bool bitmapped = Drawer2D_BitmappedText;
|
||||
bitmapped = Drawer2D_BitmappedText;
|
||||
Drawer2D_BitmappedText = true;
|
||||
String displayName = String_FromRawArray(player->DisplayNameRaw);
|
||||
name = String_FromRawArray(player->DisplayNameRaw);
|
||||
|
||||
Drawer2D_MakeFont(&args.Font, 24, FONT_STYLE_NORMAL);
|
||||
DrawTextArgs_Make(&args, &displayName, &args.Font, false);
|
||||
DrawTextArgs_Make(&args, &name, &args.Font, false);
|
||||
size = Drawer2D_MeasureText(&args);
|
||||
|
||||
if (size.Width == 0) {
|
||||
player->NameTex.ID = GFX_NULL;
|
||||
player->NameTex.X = PLAYER_NAME_EMPTY_TEX;
|
||||
} else {
|
||||
char buffer[STRING_SIZE];
|
||||
String shadowName = String_FromArray(buffer);
|
||||
String_InitArray(colorlessName, colorlessBuffer);
|
||||
size.Width += NAME_OFFSET; size.Height += NAME_OFFSET;
|
||||
|
||||
size.Width += 3; size.Height += 3;
|
||||
Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
|
||||
{
|
||||
PackedCol origWhiteCol = Drawer2D_Cols['f'];
|
||||
|
||||
Drawer2D_Cols['f'] = PackedCol_Create3(80, 80, 80);
|
||||
String_AppendColorless(&shadowName, &displayName);
|
||||
args.Text = shadowName;
|
||||
Drawer2D_DrawText(&bmp, &args, 3, 3);
|
||||
String_AppendColorless(&colorlessName, &name);
|
||||
args.Text = colorlessName;
|
||||
Drawer2D_DrawText(&bmp, &args, NAME_OFFSET, NAME_OFFSET);
|
||||
|
||||
Drawer2D_Cols['f'] = origWhiteCol;
|
||||
args.Text = displayName;
|
||||
args.Text = name;
|
||||
Drawer2D_DrawText(&bmp, &args, 0, 0);
|
||||
}
|
||||
Drawer2D_Make2DTexture(&player->NameTex, &bmp, size, 0, 0);
|
||||
|
14
src/Game.c
14
src/Game.c
@ -673,8 +673,10 @@ void Game_TakeScreenshot(void) {
|
||||
}
|
||||
|
||||
static void Game_RenderFrame(double delta) {
|
||||
struct ScheduledTask entTask;
|
||||
uint64_t frameStart;
|
||||
bool allowZoom, visible;
|
||||
float t;
|
||||
|
||||
frameStart = Stopwatch_Measure();
|
||||
Gfx_BeginFrame();
|
||||
@ -694,8 +696,8 @@ static void Game_RenderFrame(double delta) {
|
||||
}
|
||||
|
||||
Game_DoScheduledTasks(delta);
|
||||
struct ScheduledTask entTask = Game_Tasks[entTaskI];
|
||||
float t = (float)(entTask.Accumulator / entTask.Interval);
|
||||
entTask = Game_Tasks[entTaskI];
|
||||
t = (float)(entTask.Accumulator / entTask.Interval);
|
||||
LocalPlayer_SetInterpPosition(t);
|
||||
|
||||
Gfx_Clear();
|
||||
@ -746,13 +748,15 @@ void Game_Free(void* obj) {
|
||||
}
|
||||
|
||||
void Game_Run(int width, int height, const String* title, struct DisplayDevice* device) {
|
||||
int x = device->Bounds.X + (device->Bounds.Width - width) / 2;
|
||||
int y = device->Bounds.Y + (device->Bounds.Height - height) / 2;
|
||||
uint64_t lastRender, render;
|
||||
struct GraphicsMode mode;
|
||||
uint64_t lastRender, render;
|
||||
double time;
|
||||
int x, y;
|
||||
|
||||
x = device->Bounds.X + (device->Bounds.Width - width) / 2;
|
||||
y = device->Bounds.Y + (device->Bounds.Height - height) / 2;
|
||||
GraphicsMode_MakeDefault(&mode);
|
||||
|
||||
Window_Create(x, y, width, height, &mode);
|
||||
Window_SetTitle(title);
|
||||
Window_SetVisible(true);
|
||||
|
@ -14,8 +14,15 @@ struct Texture {
|
||||
int16_t X, Y; uint16_t Width, Height;
|
||||
TextureRec uv;
|
||||
};
|
||||
/* Statically initialises the position and dimensions of this texture */
|
||||
#define Tex_Rect(x,y, width,height) x,y,width,height
|
||||
/* Statically initialises the texture coordinate corners of this texture */
|
||||
#define Tex_UV(u1,v1, u2,v2) u1,v1,u2,v2
|
||||
/* Sets the position and dimensions of this texture */
|
||||
#define Tex_SetRect(tex, x,y, width, height) tex.X = x; tex.Y = y; tex.Width = width; tex.Height = height;
|
||||
/* Sets texture coordinate corners of this texture */
|
||||
/* Useful to only draw a sub-region of the texture's pixels */
|
||||
#define Tex_SetUV(tex, u1,v1, u2,v2) tex.uv.U1 = u1; tex.uv.V1 = v1; tex.uv.U2 = u2; tex.uv.V2 = v2;
|
||||
|
||||
void GfxCommon_Init(void);
|
||||
void GfxCommon_Free(void);
|
||||
|
@ -1172,21 +1172,21 @@ ReturnCode Socket_Close(SocketPtr socket) {
|
||||
|
||||
ReturnCode Socket_Select(SocketPtr socket, int selectMode, bool* success) {
|
||||
fd_set set;
|
||||
struct timeval time = { 0 };
|
||||
int selectCount, nfds;
|
||||
|
||||
FD_ZERO(&set);
|
||||
FD_SET(socket, &set);
|
||||
|
||||
struct timeval time = { 0 };
|
||||
int selectCount = -1;
|
||||
|
||||
#ifdef CC_BUILD_WIN
|
||||
int nfds = 1;
|
||||
nfds = 1;
|
||||
#else
|
||||
int nfds = socket + 1;
|
||||
nfds = socket + 1;
|
||||
#endif
|
||||
|
||||
if (selectMode == SOCKET_SELECT_READ) {
|
||||
selectCount = select(nfds, &set, NULL, NULL, &time);
|
||||
} else if (selectMode == SOCKET_SELECT_WRITE) {
|
||||
} else {
|
||||
selectCount = select(nfds, NULL, &set, NULL, &time);
|
||||
}
|
||||
|
||||
|
@ -287,12 +287,14 @@ static void StatusScreen_MakeText(struct StatusScreen* s, String* status) {
|
||||
}
|
||||
|
||||
static void StatusScreen_DrawPosition(struct StatusScreen* s) {
|
||||
struct TextAtlas* atlas = &s->PosAtlas;
|
||||
struct Texture tex;
|
||||
PackedCol col = PACKEDCOL_WHITE;
|
||||
Vector3I pos;
|
||||
VertexP3fT2fC4b vertices[4 * 64];
|
||||
VertexP3fT2fC4b* ptr = vertices;
|
||||
PackedCol col = PACKEDCOL_WHITE;
|
||||
|
||||
struct TextAtlas* atlas = &s->PosAtlas;
|
||||
struct Texture tex;
|
||||
Vector3I pos;
|
||||
int count;
|
||||
|
||||
/* Make "Position: " prefix */
|
||||
tex = atlas->Tex;
|
||||
@ -313,7 +315,7 @@ static void StatusScreen_DrawPosition(struct StatusScreen* s) {
|
||||
|
||||
Gfx_BindTexture(atlas->Tex.ID);
|
||||
/* TODO: Do we need to use a separate VB here? */
|
||||
int count = (int)(ptr - vertices);
|
||||
count = (int)(ptr - vertices);
|
||||
GfxCommon_UpdateDynamicVb_IndexedTris(ModelCache_Vb, vertices, count);
|
||||
}
|
||||
|
||||
@ -531,19 +533,21 @@ static void LoadingScreen_UpdateBackgroundVB(VertexP3fT2fC4b* vertices, int coun
|
||||
static void LoadingScreen_DrawBackground(void) {
|
||||
VertexP3fT2fC4b vertices[144];
|
||||
VertexP3fT2fC4b* ptr = vertices;
|
||||
int count = 0, atlasIndex = 0, y = 0;
|
||||
PackedCol col = PACKEDCOL_CONST(64, 64, 64, 255);
|
||||
|
||||
TextureLoc texLoc = Block_GetTex(BLOCK_DIRT, FACE_YMAX);
|
||||
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex);
|
||||
|
||||
float u2 = (float)Game_Width / (float)LOADING_TILE_SIZE;
|
||||
struct Texture tex = { GFX_NULL, Tex_Rect(0,0, Game_Width,LOADING_TILE_SIZE), Tex_UV(0,rec.V1, u2,rec.V2) };
|
||||
|
||||
struct Texture tex;
|
||||
TextureLoc loc;
|
||||
int count = 0, atlasIndex, y;
|
||||
bool bound = false;
|
||||
while (y < Game_Height) {
|
||||
|
||||
loc = Block_GetTex(BLOCK_DIRT, FACE_YMAX);
|
||||
tex.ID = GFX_NULL;
|
||||
Tex_SetRect(tex, 0,0, Game_Width,LOADING_TILE_SIZE);
|
||||
tex.uv = Atlas1D_TexRec(loc, 1, &atlasIndex);
|
||||
tex.uv.U2 = (float)Game_Width / LOADING_TILE_SIZE;
|
||||
|
||||
for (y = 0; y < Game_Height; y += LOADING_TILE_SIZE) {
|
||||
tex.Y = y;
|
||||
y += LOADING_TILE_SIZE;
|
||||
GfxCommon_Make2DQuad(&tex, col, &ptr);
|
||||
count += 4;
|
||||
|
||||
|
@ -297,13 +297,13 @@ static void MPConnection_FailConnect(ReturnCode result) {
|
||||
|
||||
static void MPConnection_TickConnect(void) {
|
||||
ReturnCode res = 0;
|
||||
bool poll_write;
|
||||
TimeMS now;
|
||||
|
||||
Socket_GetError(net_socket, &res);
|
||||
if (res) { MPConnection_FailConnect(res); return; }
|
||||
|
||||
now = DateTime_CurrentUTC_MS();
|
||||
bool poll_write = false;
|
||||
Socket_Select(net_socket, SOCKET_SELECT_WRITE, &poll_write);
|
||||
|
||||
if (poll_write) {
|
||||
@ -363,15 +363,18 @@ static void MPConnection_CheckDisconnection(double delta) {
|
||||
static String title = String_FromConst("Disconnected!");
|
||||
static String reason = String_FromConst("You've lost connection to the server");
|
||||
|
||||
ReturnCode availRes, selectRes;
|
||||
uint32_t pending = 0;
|
||||
bool poll_success;
|
||||
|
||||
net_discAccumulator += delta;
|
||||
if (net_discAccumulator < 1.0) return;
|
||||
net_discAccumulator = 0.0;
|
||||
|
||||
uint32_t available = 0; bool poll_success = false;
|
||||
ReturnCode availResult = Socket_Available(net_socket, &available);
|
||||
ReturnCode selectResult = Socket_Select(net_socket, SOCKET_SELECT_READ, &poll_success);
|
||||
availRes = Socket_Available(net_socket, &pending);
|
||||
selectRes = Socket_Select(net_socket, SOCKET_SELECT_READ, &poll_success);
|
||||
|
||||
if (net_writeFailed || availResult || selectResult || (available == 0 && poll_success)) {
|
||||
if (net_writeFailed || availRes || selectRes || (pending == 0 && poll_success)) {
|
||||
Game_Disconnect(&title, &reason);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Block.h"
|
||||
|
||||
#define Widget_UV(u1,v1, u2,v2) u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f
|
||||
#define Widget_UV(u1,v1, u2,v2) Tex_UV(u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f)
|
||||
static void Widget_NullFunc(void* widget) { }
|
||||
static Size2D Size2D_Empty;
|
||||
|
||||
@ -116,6 +116,9 @@ static void ButtonWidget_Reposition(void* widget) {
|
||||
}
|
||||
|
||||
static void ButtonWidget_Render(void* widget, double delta) {
|
||||
PackedCol normCol = PACKEDCOL_CONST(224, 224, 224, 255);
|
||||
PackedCol activeCol = PACKEDCOL_CONST(255, 255, 160, 255);
|
||||
PackedCol disabledCol = PACKEDCOL_CONST(160, 160, 160, 255);
|
||||
struct ButtonWidget* w = widget;
|
||||
struct Texture back;
|
||||
PackedCol col;
|
||||
@ -145,10 +148,6 @@ static void ButtonWidget_Render(void* widget, double delta) {
|
||||
GfxCommon_Draw2DTexture(&back, white);
|
||||
}
|
||||
|
||||
PackedCol normCol = PACKEDCOL_CONST(224, 224, 224, 255);
|
||||
PackedCol activeCol = PACKEDCOL_CONST(255, 255, 160, 255);
|
||||
PackedCol disabledCol = PACKEDCOL_CONST(160, 160, 160, 255);
|
||||
|
||||
if (!w->Texture.ID) return;
|
||||
col = w->Disabled ? disabledCol : (w->Active ? activeCol : normCol);
|
||||
Texture_RenderShaded(&w->Texture, col);
|
||||
@ -350,8 +349,9 @@ static void HotbarWidget_RenderHotbarBlocks(struct HotbarWidget* w) {
|
||||
}
|
||||
|
||||
static void HotbarWidget_RepositonBackgroundTexture(struct HotbarWidget* w) {
|
||||
struct Texture tex = { GFX_NULL, Tex_Rect(w->X,w->Y, w->Width,w->Height), Widget_UV(0,0, 182,22) };
|
||||
w->BackTex = tex;
|
||||
w->BackTex.ID = GFX_NULL;
|
||||
Tex_SetRect(w->BackTex, w->X,w->Y, w->Width,w->Height);
|
||||
Tex_SetUV(w->BackTex, 0,0, 182/256.0f,22/256.0f);
|
||||
}
|
||||
|
||||
static void HotbarWidget_RepositionSelectionTexture(struct HotbarWidget* w) {
|
||||
@ -360,8 +360,9 @@ static void HotbarWidget_RepositionSelectionTexture(struct HotbarWidget* w) {
|
||||
int vSize = (int)(22.0f * scale);
|
||||
int y = w->Y + (w->Height - (int)(23.0f * scale));
|
||||
|
||||
struct Texture tex = { GFX_NULL, Tex_Rect(0,y, hSize,vSize), Widget_UV(0,22, 24,44) };
|
||||
w->SelTex = tex;
|
||||
w->SelTex.ID = GFX_NULL;
|
||||
Tex_SetRect(w->SelTex, 0,y, hSize,vSize);
|
||||
Tex_SetUV(w->SelTex, 0,22/256.0f, 24/256.0f,44/256.0f);
|
||||
}
|
||||
|
||||
static int HotbarWidget_ScrolledIndex(struct HotbarWidget* w, float delta, int index, int dir) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user