move Atlas/Atlas1D vars to exported api

This commit is contained in:
UnknownShadow200 2019-03-13 23:30:26 +11:00
parent 97a3d1bd65
commit c706fc161e
17 changed files with 141 additions and 140 deletions

View File

@ -355,7 +355,7 @@ void Block_RecalculateAllSpriteBB(void) {
}
}
static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, Bitmap* bmp) {
static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, const Bitmap* bmp) {
BitmapCol* row;
int x, y;
@ -368,7 +368,7 @@ static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, Bitmap* bmp)
return 1.0f;
}
static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, Bitmap* bmp) {
static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, const Bitmap* bmp) {
BitmapCol* row;
int x, y;
@ -381,7 +381,7 @@ static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, Bitmap* bmp)
return 1.0f;
}
static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, Bitmap* bmp) {
static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, const Bitmap* bmp) {
BitmapCol* row;
int x, y;
@ -394,7 +394,7 @@ static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, Bitmap* bmp)
return 0.0f;
}
static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, Bitmap* bmp) {
static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, const Bitmap* bmp) {
BitmapCol* row;
int x, y;
@ -408,8 +408,8 @@ static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, Bitmap* bmp)
}
void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas_Bitmap;
int tileSize = Atlas_TileSize;
Bitmap* bmp = &Atlas2D.Bitmap;
int tileSize = Atlas2D.TileSize;
TextureLoc texLoc = Block_Tex(block, FACE_XMAX);
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
@ -417,7 +417,7 @@ void Block_RecalculateBB(BlockID block) {
float minX = 0, minY = 0, maxX = 1, maxY = 1;
Vector3 minRaw, maxRaw;
if (y < Atlas_RowsCount) {
if (y < Atlas2D.RowsCount) {
minX = Block_GetSpriteBB_MinX(tileSize, x, y, bmp);
minY = Block_GetSpriteBB_MinY(tileSize, x, y, bmp);
maxX = Block_GetSpriteBB_MaxX(tileSize, x, y, bmp);

View File

@ -478,8 +478,8 @@ static void Builder_DrawSprite(int count) {
#define s_u1 0.0f
#define s_u2 UV2_Scale
loc = Block_Tex(Builder_Block, FACE_XMAX);
v1 = Atlas1D_RowId(loc) * Atlas1D_InvTileSize;
v2 = v1 + Atlas1D_InvTileSize * UV2_Scale;
v1 = Atlas1D_RowId(loc) * Atlas1D.InvTileSize;
v2 = v1 + Atlas1D.InvTileSize * UV2_Scale;
offsetType = Blocks.SpriteOffset[Builder_Block];
if (offsetType >= 6 && offsetType <= 7) {
@ -926,11 +926,11 @@ static int Adv_StretchZ(int countIndex, int x, int y, int z, int chunkIndex, Blo
static void Adv_DrawXMin(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_XMIN);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = adv_minBB.Z, u2 = (count - 1) + adv_maxBB.Z * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];
@ -967,11 +967,11 @@ static void Adv_DrawXMin(int count) {
static void Adv_DrawXMax(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_XMAX);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = (count - adv_minBB.Z), u2 = (1 - adv_maxBB.Z) * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];
@ -1008,11 +1008,11 @@ static void Adv_DrawXMax(int count) {
static void Adv_DrawZMin(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_ZMIN);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = (count - adv_minBB.X), u2 = (1 - adv_maxBB.X) * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];
@ -1049,11 +1049,11 @@ static void Adv_DrawZMin(int count) {
static void Adv_DrawZMax(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_ZMAX);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = adv_minBB.X, u2 = (count - 1) + adv_maxBB.X * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_maxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_minBB.Y * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];
@ -1090,11 +1090,11 @@ static void Adv_DrawZMax(int count) {
static void Adv_DrawYMin(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_YMIN);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = adv_minBB.X, u2 = (count - 1) + adv_maxBB.X * UV2_Scale;
float v1 = vOrigin + adv_minBB.Z * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_maxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_minBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_maxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];
@ -1131,11 +1131,11 @@ static void Adv_DrawYMin(int count) {
static void Adv_DrawYMax(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_YMAX);
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = adv_minBB.X, u2 = (count - 1) + adv_maxBB.X * UV2_Scale;
float v1 = vOrigin + adv_minBB.Z * Atlas1D_InvTileSize;
float v2 = vOrigin + adv_maxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + adv_minBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + adv_maxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
struct Builder1DPart* part = &Builder_Parts[adv_baseOffset + Atlas1D_Index(texLoc)];
int F = adv_bitFlags[Builder_ChunkIndex];

View File

@ -15,12 +15,12 @@ col.B = (uint8_t)(col.B * Drawer.TintCol.B / 255);\
void Drawer_XMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = Drawer.MinBB.Z;
float u2 = (count - 1) + Drawer.MaxBB.Z * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.X = Drawer.X1; v.Col = col;
@ -34,12 +34,12 @@ void Drawer_XMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
void Drawer_XMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = (count - Drawer.MinBB.Z);
float u2 = (1 - Drawer.MaxBB.Z) * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.X = Drawer.X2; v.Col = col;
@ -53,12 +53,12 @@ void Drawer_XMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
void Drawer_ZMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = (count - Drawer.MinBB.X);
float u2 = (1 - Drawer.MaxBB.X) * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.Z = Drawer.Z1; v.Col = col;
@ -72,12 +72,12 @@ void Drawer_ZMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
void Drawer_ZMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = Drawer.MinBB.X;
float u2 = (count - 1) + Drawer.MaxBB.X * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.Z = Drawer.Z2; v.Col = col;
@ -92,11 +92,11 @@ void Drawer_ZMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
void Drawer_YMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = Drawer.MinBB.X;
float u2 = (count - 1) + Drawer.MaxBB.X * UV2_Scale;
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.Y = Drawer.Y1; v.Col = col;
@ -110,12 +110,12 @@ void Drawer_YMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
void Drawer_YMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
float u1 = Drawer.MinBB.X;
float u2 = (count - 1) + Drawer.MaxBB.X * UV2_Scale;
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D_InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
v.Y = Drawer.Y2; v.Col = col;

View File

@ -579,7 +579,7 @@ static void EnvRenderer_MakeBorderTex(GfxResourceID* texId, BlockID block) {
if (Gfx.LostContext) return;
Gfx_DeleteTexture(texId);
*texId = Atlas_LoadTile(loc);
*texId = Atlas2D_LoadTile(loc);
}
static Rect2D EnvRenderer_Rect(int x, int y, int width, int height) {

View File

@ -396,7 +396,7 @@ static void Http_MakeHeaders(String* headers, struct HttpRequest* req) {
if (req->LastModified) {
String_AppendConst(headers, "If-Modified-Since: ");
DateTime_HttpDate(req->LastModified, headers);
Http_FormatDate(req->LastModified, headers);
String_AppendConst(headers, "\r\n");
}
@ -854,6 +854,20 @@ void Http_UrlEncodeUtf8(String* dst, const String* src) {
}
}
void Http_FormatDate(TimeMS ms, String* str) {
static const char* days_of_week[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
static const char* month_names[13] = { NULL, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
struct DateTime t;
int days;
DateTime_FromTotalMs(&t, ms);
days = DateTime_TotalDays(&t);
String_Format2(str, "%c, %p2 ", days_of_week[days % 7], &t.Day);
String_Format2(str, "%c %p4 ", month_names[t.Month], &t.Year);
String_Format3(str, "%p2:%p2:%p2 GMT", &t.Hour, &t.Minute, &t.Second);
}
/*########################################################################################################################*
*-----------------------------------------------------Http component------------------------------------------------------*

View File

@ -59,6 +59,9 @@ void Http_AsyncGetDataEx(const String* url, bool priority, const String* id, Tim
void Http_UrlEncode(String* dst, const uint8_t* data, int len);
/* Converts characters to UTF8, then calls Http_URlEncode on them. */
void Http_UrlEncodeUtf8(String* dst, const String* src);
/* Formats a date for inclusion in HTTP headers. */
/* NOTE: Time is always assumed as being UTC. */
void Http_FormatDate(TimeMS ms, String* str);
/* Attempts to retrieve a fully completed request. */
/* NOTE: You MUST also check Result/StatusCode, and check Size is > 0. */

View File

@ -52,7 +52,7 @@ static void IsometricDrawer_InitCache(void) {
static void IsometricDrawer_Flush(void) {
int count;
if (iso_lastTexIndex != -1) {
Gfx_BindTexture(Atlas1D_TexIds[iso_lastTexIndex]);
Gfx_BindTexture(Atlas1D.TexIds[iso_lastTexIndex]);
count = (int)(iso_vertices - iso_vertices_base);
Gfx_UpdateDynamicVb_IndexedTris(iso_vb, iso_vertices_base, count);
}

View File

@ -185,7 +185,7 @@ void MapRenderer_RenderNormal(double delta) {
for (batch = 0; batch < MapRenderer_1DUsedCount; batch++) {
if (normPartsCount[batch] <= 0) continue;
if (hasNormParts[batch] || checkNormParts[batch]) {
Gfx_BindTexture(Atlas1D_TexIds[batch]);
Gfx_BindTexture(Atlas1D.TexIds[batch]);
MapRenderer_RenderNormalBatch(batch);
checkNormParts[batch] = false;
}
@ -280,7 +280,7 @@ void MapRenderer_RenderTranslucent(double delta) {
for (batch = 0; batch < MapRenderer_1DUsedCount; batch++) {
if (tranPartsCount[batch] <= 0) continue;
if (!hasTranParts[batch]) continue;
Gfx_BindTexture(Atlas1D_TexIds[batch]);
Gfx_BindTexture(Atlas1D.TexIds[batch]);
MapRenderer_RenderTranslucentBatch(batch);
}
Gfx_DisableMipmaps();
@ -700,12 +700,12 @@ static void MapRenderer_EnvVariableChanged(void* obj, int envVar) {
static void MapRenderer_TerrainAtlasChanged(void* obj) {
if (MapRenderer_1DUsedCount) {
bool refreshRequired = elementsPerBitmap != Atlas1D_TilesPerAtlas;
bool refreshRequired = elementsPerBitmap != Atlas1D.TilesPerAtlas;
if (refreshRequired) MapRenderer_Refresh();
}
MapRenderer_1DUsedCount = MapRenderer_UsedAtlases();
elementsPerBitmap = Atlas1D_TilesPerAtlas;
elementsPerBitmap = Atlas1D.TilesPerAtlas;
MapRenderer_ResetPartFlags();
}

View File

@ -2955,7 +2955,7 @@ static void TexIdsOverlay_ContextRecreated(void* screen) {
s->DynamicVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, TEXID_OVERLAY_VERTICES_COUNT);
TextAtlas_Make(&s->IdAtlas, &chars, &s->TextFont, &prefix);
s->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas_RowsCount, Game.Width);
s->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, Game.Width);
s->YOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Game.Height);
s->TileSize = size;
@ -2978,19 +2978,19 @@ static void TexIdsOverlay_RenderTerrain(struct TexIdsOverlay* s) {
for (i = 0; i < ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW;) {
ptr = vertices;
idx = Atlas1D_Index(i + s->BaseTexLoc);
end = i + Atlas1D_TilesPerAtlas;
end = i + Atlas1D.TilesPerAtlas;
for (; i < end; i++) {
tex.X = s->XOffset + Atlas2D_TileX(i) * size;
tex.Y = s->YOffset + Atlas2D_TileY(i) * size;
tex.uv.V1 = Atlas1D_RowId(i + s->BaseTexLoc) * Atlas1D_InvTileSize;
tex.uv.V2 = tex.uv.V1 + UV2_Scale * Atlas1D_InvTileSize;
tex.uv.V1 = Atlas1D_RowId(i + s->BaseTexLoc) * Atlas1D.InvTileSize;
tex.uv.V2 = tex.uv.V1 + UV2_Scale * Atlas1D.InvTileSize;
Gfx_Make2DQuad(&tex, col, &ptr);
}
Gfx_BindTexture(Atlas1D_TexIds[idx]);
Gfx_BindTexture(Atlas1D.TexIds[idx]);
count = (int)(ptr - vertices);
Gfx_UpdateDynamicVb_IndexedTris(s->DynamicVb, vertices, count);
}
@ -3042,7 +3042,7 @@ static void TexIdsOverlay_Render(void* screen, double delta) {
origXOffset = s->XOffset;
s->BaseTexLoc = 0;
for (rows = Atlas_RowsCount; rows > 0; rows -= ATLAS2D_TILES_PER_ROW) {
for (rows = Atlas2D.RowsCount; rows > 0; rows -= ATLAS2D_TILES_PER_ROW) {
TexIdsOverlay_RenderTerrain(s);
TexIdsOverlay_RenderTextOverlay(s);

View File

@ -1494,7 +1494,7 @@ static void BlockModel_GetBounds(struct Entity* e) {
static void BlockModel_Flush(void) {
if (bModel_lastTexIndex != -1) {
Gfx_BindTexture(Atlas1D_TexIds[bModel_lastTexIndex]);
Gfx_BindTexture(Atlas1D.TexIds[bModel_lastTexIndex]);
Models.Active->index = bModel_index;
Model_UpdateVB();
}

View File

@ -259,7 +259,7 @@ static void Terrain_Update1DCounts(void) {
index = Atlas1D_Index(terrain_particles[i].TexLoc);
terrain_1DCount[index] += 4;
}
for (i = 1; i < Atlas1D_Count; i++) {
for (i = 1; i < Atlas1D.Count; i++) {
terrain_1DIndices[i] = terrain_1DIndices[i - 1] + terrain_1DCount[i - 1];
}
}
@ -281,11 +281,11 @@ static void Terrain_Render(float t) {
}
Gfx_SetDynamicVbData(Particles_VB, vertices, terrain_count * 4);
for (i = 0; i < Atlas1D_Count; i++) {
for (i = 0; i < Atlas1D.Count; i++) {
int partCount = terrain_1DCount[i];
if (!partCount) continue;
Gfx_BindTexture(Atlas1D_TexIds[i]);
Gfx_BindTexture(Atlas1D.TexIds[i]);
Gfx_DrawVb_IndexedTris_Range(partCount, offset);
offset += partCount;
}
@ -368,7 +368,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID old, BlockID now) {
loc = Block_Tex(old, FACE_XMIN);
baseRec = Atlas1D_TexRec(loc, 1, &texIndex);
uScale = (1.0f/16.0f); vScale = (1.0f/16.0f) * Atlas1D_InvTileSize;
uScale = (1.0f/16.0f); vScale = (1.0f/16.0f) * Atlas1D.InvTileSize;
minBB = Blocks.MinBB[old]; maxBB = Blocks.MaxBB[old];
minX = (int)(minBB.X * 16); maxX = (int)(maxBB.X * 16);

View File

@ -521,7 +521,7 @@ static bool LoadingScreen_MouseScroll(void* screen, float delta) { return true;
static void LoadingScreen_UpdateBackgroundVB(VertexP3fT2fC4b* vertices, int count, int atlasIndex, bool* bound) {
if (!(*bound)) {
*bound = true;
Gfx_BindTexture(Atlas1D_TexIds[atlasIndex]);
Gfx_BindTexture(Atlas1D.TexIds[atlasIndex]);
}
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);

View File

@ -223,7 +223,7 @@ static void Animations_ReadDescription(struct Stream* stream, const String* path
#define ANIMS_FAST_SIZE 64
static void Animations_Draw(struct AnimationData* data, TextureLoc texLoc, int size) {
int dstX = Atlas1D_Index(texLoc), srcX;
int dstY = Atlas1D_RowId(texLoc) * Atlas_TileSize;
int dstY = Atlas1D_RowId(texLoc) * Atlas2D.TileSize;
GfxResourceID tex;
uint8_t buffer[Bitmap_DataSize(ANIMS_FAST_SIZE, ANIMS_FAST_SIZE)];
@ -247,7 +247,7 @@ static void Animations_Draw(struct AnimationData* data, TextureLoc texLoc, int s
Bitmap_CopyBlock(srcX, data->FrameY, 0, 0, &anims_bmp, &frame, size);
}
tex = Atlas1D_TexIds[dstX];
tex = Atlas1D.TexIds[dstX];
if (tex) { Gfx_UpdateTexturePart(tex, 0, dstY, &frame, Gfx.Mipmaps); }
if (size > ANIMS_FAST_SIZE) Mem_Free(ptr);
}
@ -297,7 +297,7 @@ static void Animations_Validate(void) {
tileX = Atlas2D_TileX(data.TexLoc);
tileY = Atlas2D_TileY(data.TexLoc);
if (data.FrameSize > Atlas_TileSize || tileY >= Atlas_RowsCount) {
if (data.FrameSize > Atlas2D.TileSize || tileY >= Atlas2D.RowsCount) {
Chat_Add2("&cAnimation frames for tile (%i, %i) are bigger than the size of a tile in terrain.png", &tileX, &tileY);
} else if (maxX > anims_bmp.Width || maxY > anims_bmp.Height) {
Chat_Add2("&cSome of the animation frames for tile (%i, %i) are at coordinates outside animations.png", &tileX, &tileY);
@ -317,11 +317,11 @@ static void Animations_Tick(struct ScheduledTask* task) {
int i, size;
if (anims_useLavaAnim) {
size = min(Atlas_TileSize, 64);
size = min(Atlas2D.TileSize, 64);
Animations_Draw(NULL, 30, size);
}
if (anims_useWaterAnim) {
size = min(Atlas_TileSize, 64);
size = min(Atlas2D.TileSize, 64);
Animations_Draw(NULL, 14, size);
}
@ -388,12 +388,8 @@ struct IGameComponent Animations_Component = {
/*########################################################################################################################*
*------------------------------------------------------TerrainAtlas-------------------------------------------------------*
*#########################################################################################################################*/
Bitmap Atlas_Bitmap;
int Atlas_TileSize, Atlas_RowsCount;
int Atlas1D_Count, Atlas1D_TilesPerAtlas;
int Atlas1D_Mask, Atlas1D_Shift;
float Atlas1D_InvTileSize;
GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES];
struct _Atlas2DData Atlas2D;
struct _Atlas1DData Atlas1D;
TextureRec Atlas1D_TexRec(TextureLoc texLoc, int uCount, int* index) {
TextureRec rec;
@ -402,16 +398,16 @@ TextureRec Atlas1D_TexRec(TextureLoc texLoc, int uCount, int* index) {
/* Adjust coords to be slightly inside - fixes issues with AMD/ATI cards */
rec.U1 = 0.0f;
rec.V1 = y * Atlas1D_InvTileSize;
rec.V1 = y * Atlas1D.InvTileSize;
rec.U2 = (uCount - 1) + UV2_Scale;
rec.V2 = rec.V1 + UV2_Scale * Atlas1D_InvTileSize;
rec.V2 = rec.V1 + UV2_Scale * Atlas1D.InvTileSize;
return rec;
}
static void Atlas_Convert2DTo1D(void) {
int tileSize = Atlas_TileSize;
int tilesPerAtlas = Atlas1D_TilesPerAtlas;
int atlasesCount = Atlas1D_Count;
int tileSize = Atlas2D.TileSize;
int tilesPerAtlas = Atlas1D.TilesPerAtlas;
int atlasesCount = Atlas1D.Count;
Bitmap atlas1D;
int atlasX, atlasY;
int tile = 0, i, y;
@ -425,9 +421,9 @@ static void Atlas_Convert2DTo1D(void) {
atlasY = Atlas2D_TileY(tile) * tileSize;
Bitmap_CopyBlock(atlasX, atlasY, 0, y * tileSize,
&Atlas_Bitmap, &atlas1D, tileSize);
&Atlas2D.Bitmap, &atlas1D, tileSize);
}
Atlas1D_TexIds[i] = Gfx_CreateTexture(&atlas1D, true, Gfx.Mipmaps);
Atlas1D.TexIds[i] = Gfx_CreateTexture(&atlas1D, true, Gfx.Mipmaps);
}
Mem_Free(atlas1D.Scan0);
}
@ -436,38 +432,38 @@ static void Atlas_Update1D(void) {
int maxAtlasHeight, maxTilesPerAtlas, maxTiles;
maxAtlasHeight = min(4096, Gfx.MaxTexHeight);
maxTilesPerAtlas = maxAtlasHeight / Atlas_TileSize;
maxTiles = Atlas_RowsCount * ATLAS2D_TILES_PER_ROW;
maxTilesPerAtlas = maxAtlasHeight / Atlas2D.TileSize;
maxTiles = Atlas2D.RowsCount * ATLAS2D_TILES_PER_ROW;
Atlas1D_TilesPerAtlas = min(maxTilesPerAtlas, maxTiles);
Atlas1D_Count = Math_CeilDiv(maxTiles, Atlas1D_TilesPerAtlas);
Atlas1D.TilesPerAtlas = min(maxTilesPerAtlas, maxTiles);
Atlas1D.Count = Math_CeilDiv(maxTiles, Atlas1D.TilesPerAtlas);
Atlas1D_InvTileSize = 1.0f / Atlas1D_TilesPerAtlas;
Atlas1D_Mask = Atlas1D_TilesPerAtlas - 1;
Atlas1D_Shift = Math_Log2(Atlas1D_TilesPerAtlas);
Atlas1D.InvTileSize = 1.0f / Atlas1D.TilesPerAtlas;
Atlas1D.Mask = Atlas1D.TilesPerAtlas - 1;
Atlas1D.Shift = Math_Log2(Atlas1D.TilesPerAtlas);
}
void Atlas_Update(Bitmap* bmp) {
Atlas_Bitmap = *bmp;
Atlas_TileSize = bmp->Width / ATLAS2D_TILES_PER_ROW;
Atlas_RowsCount = bmp->Height / Atlas_TileSize;
Atlas_RowsCount = min(Atlas_RowsCount, ATLAS2D_MAX_ROWS_COUNT);
Atlas2D.Bitmap = *bmp;
Atlas2D.TileSize = bmp->Width / ATLAS2D_TILES_PER_ROW;
Atlas2D.RowsCount = bmp->Height / Atlas2D.TileSize;
Atlas2D.RowsCount = min(Atlas2D.RowsCount, ATLAS2D_MAX_ROWS_COUNT);
Atlas_Update1D();
Atlas_Convert2DTo1D();
}
static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, Bitmap* element) {
int size = Atlas_TileSize;
int size = Atlas2D.TileSize;
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
if (y >= Atlas_RowsCount) return GFX_NULL;
if (y >= Atlas2D.RowsCount) return GFX_NULL;
Bitmap_CopyBlock(x * size, y * size, 0, 0, &Atlas_Bitmap, element, size);
Bitmap_CopyBlock(x * size, y * size, 0, 0, &Atlas2D.Bitmap, element, size);
return Gfx_CreateTexture(element, false, Gfx.Mipmaps);
}
GfxResourceID Atlas_LoadTile(TextureLoc texLoc) {
int tileSize = Atlas_TileSize;
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) {
int tileSize = Atlas2D.TileSize;
Bitmap tile;
GfxResourceID texId;
uint8_t scan0[Bitmap_DataSize(64, 64)];
@ -486,11 +482,11 @@ GfxResourceID Atlas_LoadTile(TextureLoc texLoc) {
void Atlas_Free(void) {
int i;
Mem_Free(Atlas_Bitmap.Scan0);
Atlas_Bitmap.Scan0 = NULL;
Mem_Free(Atlas2D.Bitmap.Scan0);
Atlas2D.Bitmap.Scan0 = NULL;
for (i = 0; i < Atlas1D_Count; i++) {
Gfx_DeleteTexture(&Atlas1D_TexIds[i]);
for (i = 0; i < Atlas1D.Count; i++) {
Gfx_DeleteTexture(&Atlas1D.TexIds[i]);
}
}

View File

@ -27,37 +27,42 @@ extern struct IGameComponent Animations_Component;
/* Maximum possible number of 1D terrain atlases. (worst case, each 1D atlas only has 1 tile) */
#define ATLAS1D_MAX_ATLASES (ATLAS2D_TILES_PER_ROW * ATLAS2D_MAX_ROWS_COUNT)
/* Bitmap that contains the textures of all tiles. */
/* Tiles are indexed left to right, top to bottom. */
extern Bitmap Atlas_Bitmap;
/* Size of each tile in pixels. (default 16x16) */
extern int Atlas_TileSize;
/* Number of rows in the atlas. (default 16, can be 32) */
extern int Atlas_RowsCount;
/* Number of 1D atlases the atlas was split into. */
extern int Atlas1D_Count;
/* Number of tiles in each 1D atlas. */
extern int Atlas1D_TilesPerAtlas;
/* Converts a tile id into 1D atlas index, and index within that atlas. */
extern int Atlas1D_Mask, Atlas1D_Shift;
/* Texture V coord that equals the size of one tile. (i.e. 1/Atlas1D_TilesPerAtlas) */
/* NOTE: The texture U coord that equals the size of one tile is 1. */
extern float Atlas1D_InvTileSize;
/* Textures for each 1D atlas. Only Atlas1D_Count of these are valid. */
extern GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES];
CC_VAR extern struct _Atlas2DData {
/* Bitmap that contains the textures of all tiles. */
/* Tiles are indexed left to right, top to bottom. */
Bitmap Bitmap;
/* Size of each tile in pixels. (default 16x16) */
int TileSize;
/* Number of rows in the atlas. (default 16, can be 32) */
int RowsCount;
} Atlas2D;
CC_VAR extern struct _Atlas1DData {
/* Number of 1D atlases the atlas was split into. */
int Count;
/* Number of tiles in each 1D atlas. */
int TilesPerAtlas;
/* Converts a tile id into 1D atlas index, and index within that atlas. */
int Mask, Shift;
/* Texture V coord that equals the size of one tile. (i.e. 1/Atlas1D.TilesPerAtlas) */
/* NOTE: The texture U coord that equals the size of one tile is 1. */
float InvTileSize;
/* Textures for each 1D atlas. Only Atlas1D_Count of these are valid. */
GfxResourceID TexIds[ATLAS1D_MAX_ATLASES];
} Atlas1D;
#define Atlas2D_TileX(texLoc) ((texLoc) & ATLAS2D_MASK) /* texLoc % ATLAS2D_TILES_PER_ROW */
#define Atlas2D_TileY(texLoc) ((texLoc) >> ATLAS2D_SHIFT) /* texLoc / ATLAS2D_TILES_PER_ROW */
/* Returns the index of the given tile id within a 1D atlas */
#define Atlas1D_RowId(texLoc) ((texLoc) & Atlas1D_Mask) /* texLoc % Atlas1D_TilesPerAtlas */
#define Atlas1D_RowId(texLoc) ((texLoc) & Atlas1D.Mask) /* texLoc % Atlas1D_TilesPerAtlas */
/* Returns the index of the 1D atlas within the array of 1D atlases that contains the given tile id */
#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */
#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D.Shift) /* texLoc / Atlas1D_TilesPerAtlas */
/* Loads the given atlas and converts it into an array of 1D atlases. */
/* NOTE: Use Game_ChangeTerrainAtlas to change atlas, because that raises TextureEvents.AtlasChanged */
void Atlas_Update(Bitmap* bmp);
/* Loads the given tile into a new separate texture. */
GfxResourceID Atlas_LoadTile(TextureLoc texLoc);
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc);
/* Frees the atlas and 1D atlas textures. */
void Atlas_Free(void);
/* Returns the UV rectangle of the given tile id in the 1D atlases. */

View File

@ -88,20 +88,6 @@ void DateTime_FromTotalMs(struct DateTime* time, TimeMS ms) {
}
}
void DateTime_HttpDate(TimeMS ms, String* str) {
static const char* days_of_week[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
static const char* month_names[13] = { NULL, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
struct DateTime t;
int days;
DateTime_FromTotalMs(&t, ms);
days = DateTime_TotalDays(&t);
String_Format2(str, "%c, %p2 ", days_of_week[days % 7], &t.Day);
String_Format2(str, "%c %p4 ", month_names[t.Month], &t.Year);
String_Format3(str, "%p2:%p2:%p2 GMT", &t.Hour, &t.Minute, &t.Second);
}
/*########################################################################################################################*
*----------------------------------------------------------Misc-----------------------------------------------------------*

View File

@ -29,7 +29,6 @@ struct DateTime {
int DateTime_TotalDays(const struct DateTime* time);
TimeMS DateTime_TotalMs(const struct DateTime* time);
void DateTime_FromTotalMs(struct DateTime* time, TimeMS ms);
void DateTime_HttpDate(TimeMS ms, String* str);
CC_NOINLINE int Utils_ParseEnum(const String* text, int defValue, const char** names, int namesCount);
bool Utils_IsUrlPrefix(const String* value, int index);

View File

@ -13,7 +13,6 @@ struct AABB;
/* Packs an x,y,z into a single index */
#define World_Pack(x, y, z) (((y) * World.Length + (z)) * World.Width + (x))
/* Contains general data about the world, primarily the blocks. */
CC_VAR extern struct _WorldData {
/* The blocks in the world. */
BlockRaw* Blocks;
@ -92,7 +91,6 @@ enum EnvVar {
ENV_VAR_SKYBOX_COL
};
/* Contains data about the current environment of the world. */
CC_VAR extern struct _EnvData {
BlockID EdgeBlock, SidesBlock;
int EdgeHeight, SidesOffset;