make initial default.zip creation a bit faster

This commit is contained in:
UnknownShadow200 2019-01-30 22:27:21 +11:00
parent 27cfcc715b
commit 6c9abbf0e5
8 changed files with 48 additions and 61 deletions

View File

@ -43,9 +43,9 @@ static void PerspectiveCamera_CentreMousePosition(void) {
int cenX = topLeft.X + Game.Width / 2; int cenX = topLeft.X + Game.Width / 2;
int cenY = topLeft.Y + Game.Height / 2; int cenY = topLeft.Y + Game.Height / 2;
Window_SetScreenCursorPos(cenX, cenY); Cursor_SetScreenPos(cenX, cenY);
/* Fixes issues with large DPI displays on Windows >= 8.0. */ /* Fixes issues with large DPI displays on Windows >= 8.0. */
cam_prev = Window_GetScreenCursorPos(); cam_prev = Cursor_GetScreenPos();
} }
static void PerspectiveCamera_RegrabMouse(void) { static void PerspectiveCamera_RegrabMouse(void) {
@ -109,7 +109,7 @@ static void PerspectiveCamera_UpdateMouse(void) {
if (screen->HandlesAllInput) { if (screen->HandlesAllInput) {
cam_delta.X = 0; cam_delta.Y = 0; cam_delta.X = 0; cam_delta.Y = 0;
} else if (Window_Focused) { } else if (Window_Focused) {
pos = Window_GetScreenCursorPos(); pos = Cursor_GetScreenPos();
cam_delta.X = pos.X - cam_prev.X; cam_delta.Y = pos.Y - cam_prev.Y; cam_delta.X = pos.X - cam_prev.X; cam_delta.Y = pos.Y - cam_prev.Y;
PerspectiveCamera_CentreMousePosition(); PerspectiveCamera_CentreMousePosition();
} }

View File

@ -1125,7 +1125,7 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
ReturnCode res; ReturnCode res;
if ((res = Stream_Read(stream, header, sizeof(header)))) return res; if ((res = Stream_Read(stream, header, sizeof(header)))) return res;
method = Stream_GetU16_LE(&header[4]); method = Stream_GetU16_LE(&header[4]);
compressedSize = Stream_GetU32_LE(&header[14]); compressedSize = Stream_GetU32_LE(&header[14]);
uncompressedSize = Stream_GetU32_LE(&header[18]); uncompressedSize = Stream_GetU32_LE(&header[18]);
@ -1139,6 +1139,7 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
path = String_Init(pathBuffer, pathLen, pathLen); path = String_Init(pathBuffer, pathLen, pathLen);
if ((res = Stream_Read(stream, pathBuffer, pathLen))) return res; if ((res = Stream_Read(stream, pathBuffer, pathLen))) return res;
state->_curEntry = entry;
if (!state->SelectEntry(&path)) return 0; if (!state->SelectEntry(&path)) return 0;
/* local file may have extra data before actual data (e.g. ZIP64) */ /* local file may have extra data before actual data (e.g. ZIP64) */
@ -1182,6 +1183,7 @@ static ReturnCode Zip_ReadCentralDirectory(struct ZipState* state) {
if (state->_usedEntries >= ZIP_MAX_ENTRIES) return ZIP_ERR_TOO_MANY_ENTRIES; if (state->_usedEntries >= ZIP_MAX_ENTRIES) return ZIP_ERR_TOO_MANY_ENTRIES;
entry = &state->Entries[state->_usedEntries++]; entry = &state->Entries[state->_usedEntries++];
entry->CRC32 = Stream_GetU32_LE(&header[12]);
entry->CompressedSize = Stream_GetU32_LE(&header[16]); entry->CompressedSize = Stream_GetU32_LE(&header[16]);
entry->UncompressedSize = Stream_GetU32_LE(&header[20]); entry->UncompressedSize = Stream_GetU32_LE(&header[20]);
entry->LocalHeaderOffset = Stream_GetU32_LE(&header[38]); entry->LocalHeaderOffset = Stream_GetU32_LE(&header[38]);

View File

@ -114,8 +114,8 @@ struct ZLibState { struct DeflateState Base; uint32_t Adler32; };
CC_API void ZLib_MakeStream(struct Stream* stream, struct ZLibState* state, struct Stream* underlying); CC_API void ZLib_MakeStream(struct Stream* stream, struct ZLibState* state, struct Stream* underlying);
/* Minimal data needed to describe an entry in a .zip archive. */ /* Minimal data needed to describe an entry in a .zip archive. */
struct ZipEntry { uint32_t CompressedSize, UncompressedSize, LocalHeaderOffset; }; struct ZipEntry { uint32_t CompressedSize, UncompressedSize, LocalHeaderOffset, CRC32; };
#define ZIP_MAX_ENTRIES 2048 #define ZIP_MAX_ENTRIES 1024
struct ZipState; struct ZipState;
/* Stores state for reading and processing entries in a .zip archive. */ /* Stores state for reading and processing entries in a .zip archive. */
@ -138,6 +138,8 @@ struct ZipState {
int _totalEntries; int _totalEntries;
/* (internal) Offset to central directory entries. */ /* (internal) Offset to central directory entries. */
uint32_t _centralDirBeg; uint32_t _centralDirBeg;
/* (internal) Current entry being processed. */
struct ZipEntry* _curEntry;
/* Data for each entry in the .zip archive. */ /* Data for each entry in the .zip archive. */
struct ZipEntry Entries[ZIP_MAX_ENTRIES]; struct ZipEntry Entries[ZIP_MAX_ENTRIES];
}; };

View File

@ -270,7 +270,7 @@ void Gui_CalcCursorVisible(void) {
if (vis == gui_cursorVisible) return; if (vis == gui_cursorVisible) return;
gui_cursorVisible = vis; gui_cursorVisible = vis;
Window_SetCursorVisible(vis); Cursor_SetVisible(vis);
if (Window_Focused) if (Window_Focused)
Camera.Active->RegrabMouse(); Camera.Active->RegrabMouse();
} }

View File

@ -279,52 +279,35 @@ static ReturnCode ZipPatcher_FixupLocalFile(struct Stream* s, struct ResourceTex
return s->Seek(s, dataEnd); return s->Seek(s, dataEnd);
} }
static ReturnCode ZipPatcher_WriteData(struct Stream* s, struct ResourceTexture* tex, const uint8_t* data, uint32_t len) { static ReturnCode ZipPatcher_WriteData(struct Stream* dst, struct ResourceTexture* tex, const uint8_t* data, uint32_t len) {
ReturnCode res; ReturnCode res;
tex->Size = len; tex->Size = len;
tex->Crc32 = Utils_CRC32(data, len); tex->Crc32 = Utils_CRC32(data, len);
res = ZipPatcher_LocalFile(s, tex); res = ZipPatcher_LocalFile(dst, tex);
if (res) return res; if (res) return res;
return Stream_Write(s, data, len); return Stream_Write(dst, data, len);
} }
/*static ReturnCode ZipPatcher_WriteStream(struct Stream* s, struct ResourceTexture* tex, struct Stream* src) { static ReturnCode ZipPatcher_WriteZipEntry(struct Stream* src, struct ResourceTexture* tex, struct ZipState* state) {
uint8_t tmp[2048]; uint8_t tmp[2048];
uint32_t read; uint32_t read;
struct Stream* dst = state->Obj;
ReturnCode res; ReturnCode res;
if ((res = ZipPatcher_LocalFile(s, tex))) return res;
tex->Size = state->_curEntry->UncompressedSize;
tex->Crc32 = state->_curEntry->CRC32;
res = ZipPatcher_LocalFile(dst, tex);
if (res) return res;
for (;;) { for (;;) {
res = src->Read(src, tmp, sizeof(tmp), &read); res = src->Read(src, tmp, sizeof(tmp), &read);
if (res) return res; if (res) return res;
if (!read) break; if (!read) break;
if ((res = Stream_Write(s, tmp, read))) return res; if ((res = Stream_Write(dst, tmp, read))) return res;
} }
return ZipPatcher_FixupLocalFile(s, tex); return 0;
}*/
static ReturnCode ZipPatcher_WriteStream(struct Stream* s, struct ResourceTexture* tex, struct Stream* src) {
uint8_t tmp[2048];
uint32_t read;
struct Stream crc32;
ReturnCode res;
res = ZipPatcher_LocalFile(s, tex);
if (res) return res;
Stream_WriteonlyCrc32(&crc32, s);
for (tex->Size = 0; ; tex->Size += read) {
res = src->Read(src, tmp, sizeof(tmp), &read);
if (res) return res;
if (!read) break;
res = Stream_Write(&crc32, tmp, read);
if (res) return res;
}
tex->Crc32 = crc32.Meta.CRC32.CRC32 ^ 0xFFFFFFFFUL;
return ZipPatcher_FixupLocalFile(s, tex);
} }
static ReturnCode ZipPatcher_WritePng(struct Stream* s, struct ResourceTexture* tex, Bitmap* src) { static ReturnCode ZipPatcher_WritePng(struct Stream* s, struct ResourceTexture* tex, Bitmap* src) {
@ -367,7 +350,6 @@ static bool ClassicPatcher_SelectEntry(const String* path ) {
static ReturnCode ClassicPatcher_ProcessEntry(const String* path, struct Stream* data, struct ZipState* state) { static ReturnCode ClassicPatcher_ProcessEntry(const String* path, struct Stream* data, struct ZipState* state) {
static const String guiClassicPng = String_FromConst("gui_classic.png"); static const String guiClassicPng = String_FromConst("gui_classic.png");
struct Stream* s = state->Obj;
struct ResourceTexture* entry; struct ResourceTexture* entry;
String name; String name;
@ -381,7 +363,7 @@ static ReturnCode ClassicPatcher_ProcessEntry(const String* path, struct Stream*
if (String_CaselessEqualsConst(&name, "gui.png")) name = guiClassicPng; if (String_CaselessEqualsConst(&name, "gui.png")) name = guiClassicPng;
entry = Resources_FindTex(&name); entry = Resources_FindTex(&name);
return ZipPatcher_WriteStream(s, entry, data); return ZipPatcher_WriteZipEntry(data, entry, state);
} }
static ReturnCode ClassicPatcher_ExtractFiles(struct Stream* s) { static ReturnCode ClassicPatcher_ExtractFiles(struct Stream* s) {
@ -467,7 +449,6 @@ static ReturnCode ModernPatcher_MakeAnimations(struct Stream* s, struct Stream*
} }
static ReturnCode ModernPatcher_ProcessEntry(const String* path, struct Stream* data, struct ZipState* state) { static ReturnCode ModernPatcher_ProcessEntry(const String* path, struct Stream* data, struct ZipState* state) {
struct Stream* s = state->Obj;
struct ResourceTexture* entry; struct ResourceTexture* entry;
struct TilePatch* tile; struct TilePatch* tile;
String name; String name;
@ -478,11 +459,12 @@ static ReturnCode ModernPatcher_ProcessEntry(const String* path, struct Stream*
Utils_UNSAFE_GetFilename(&name); Utils_UNSAFE_GetFilename(&name);
entry = Resources_FindTex(&name); entry = Resources_FindTex(&name);
return ZipPatcher_WriteStream(s, entry, data); return ZipPatcher_WriteZipEntry(data, entry, state);
} }
if (String_CaselessEqualsConst(path, "assets/minecraft/textures/blocks/fire_layer_1.png")) { if (String_CaselessEqualsConst(path, "assets/minecraft/textures/blocks/fire_layer_1.png")) {
return ModernPatcher_MakeAnimations(s, data); struct Stream* dst = state->Obj;
return ModernPatcher_MakeAnimations(dst, data);
} }
tile = ModernPatcher_GetTile(path); tile = ModernPatcher_GetTile(path);

View File

@ -546,7 +546,7 @@ static void TableWidget_MoveCursorToSelected(struct TableWidget* w) {
topLeft = Window_PointToScreen(0, 0); topLeft = Window_PointToScreen(0, 0);
x += topLeft.X; y += topLeft.Y; x += topLeft.X; y += topLeft.Y;
Window_SetScreenCursorPos(x, y); Cursor_SetScreenPos(x, y);
} }
static void TableWidget_MakeBlockDesc(String* desc, BlockID block) { static void TableWidget_MakeBlockDesc(String* desc, BlockID block) {

View File

@ -10,7 +10,7 @@ Rect2D Window_Bounds;
Size2D Window_ClientSize; Size2D Window_ClientSize;
static bool win_cursorVisible = true; static bool win_cursorVisible = true;
bool Window_GetCursorVisible(void) { return win_cursorVisible; } bool Cursor_GetVisible(void) { return win_cursorVisible; }
void Window_CreateSimple(int width, int height) { void Window_CreateSimple(int width, int height) {
struct DisplayDevice* device = &DisplayDevice_Default; struct DisplayDevice* device = &DisplayDevice_Default;
@ -567,14 +567,14 @@ void Window_ProcessEvents(void) {
} }
} }
Point2D Window_GetScreenCursorPos(void) { Point2D Cursor_GetScreenPos(void) {
POINT point; GetCursorPos(&point); POINT point; GetCursorPos(&point);
Point2D p = { point.x, point.y }; return p; Point2D p = { point.x, point.y }; return p;
} }
void Window_SetScreenCursorPos(int x, int y) { void Cursor_SetScreenPos(int x, int y) {
SetCursorPos(x, y); SetCursorPos(x, y);
} }
void Window_SetCursorVisible(bool visible) { void Cursor_SetVisible(bool visible) {
win_cursorVisible = visible; win_cursorVisible = visible;
ShowCursor(visible ? 1 : 0); ShowCursor(visible ? 1 : 0);
} }
@ -1335,7 +1335,7 @@ Point2D Window_PointToScreen(int x, int y) {
return p; return p;
} }
Point2D Window_GetScreenCursorPos(void) { Point2D Cursor_GetScreenPos(void) {
Window rootW, childW; Window rootW, childW;
Point2D root, child; Point2D root, child;
unsigned int mask; unsigned int mask;
@ -1344,25 +1344,26 @@ Point2D Window_GetScreenCursorPos(void) {
return root; return root;
} }
void Window_SetScreenCursorPos(int x, int y) { void Cursor_SetScreenPos(int x, int y) {
XWarpPointer(win_display, None, win_rootWin, 0, 0, 0, 0, x, y); XWarpPointer(win_display, None, win_rootWin, 0, 0, 0, 0, x, y);
XFlush(win_display); /* TODO: not sure if XFlush call is necessary */ XFlush(win_display); /* TODO: not sure if XFlush call is necessary */
} }
static Cursor win_blankCursor; void Cursor_SetVisible(bool visible) {
void Window_SetCursorVisible(bool visible) { static Cursor blankCursor;
win_cursorVisible = visible; win_cursorVisible = visible;
if (visible) { if (visible) {
XUndefineCursor(win_display, win_handle); XUndefineCursor(win_display, win_handle);
} else { } else {
if (!win_blankCursor) { if (!blankCursor) {
char data = 0; char data = 0;
XColor col = { 0 }; XColor col = { 0 };
Pixmap pixmap = XCreateBitmapFromData(win_display, win_handle, &data, 1, 1); Pixmap pixmap = XCreateBitmapFromData(win_display, win_handle, &data, 1, 1);
win_blankCursor = XCreatePixmapCursor(win_display, pixmap, pixmap, &col, &col, 0, 0); blankCursor = XCreatePixmapCursor(win_display, pixmap, pixmap, &col, &col, 0, 0);
XFreePixmap(win_display, pixmap); XFreePixmap(win_display, pixmap);
} }
XDefineCursor(win_display, win_handle, win_blankCursor); XDefineCursor(win_display, win_handle, blankCursor);
} }
} }
@ -2305,7 +2306,7 @@ Point2D Window_PointToScreen(int x, int y) {
return p; return p;
} }
Point2D Window_GetScreenCursorPos(void) { Point2D Cursor_GetScreenPos(void) {
HIPoint point; HIPoint point;
Point2D p; Point2D p;
/* NOTE: HIGetMousePosition is OSX 10.5 or later */ /* NOTE: HIGetMousePosition is OSX 10.5 or later */
@ -2316,7 +2317,7 @@ Point2D Window_GetScreenCursorPos(void) {
return p; return p;
} }
void Window_SetScreenCursorPos(int x, int y) { void Cursor_SetScreenPos(int x, int y) {
CGPoint point; CGPoint point;
point.x = x; point.y = y; point.x = x; point.y = y;
@ -2325,7 +2326,7 @@ void Window_SetScreenCursorPos(int x, int y) {
CGAssociateMouseAndMouseCursorPosition(1); CGAssociateMouseAndMouseCursorPosition(1);
} }
void Window_SetCursorVisible(bool visible) { void Cursor_SetVisible(bool visible) {
win_cursorVisible = visible; win_cursorVisible = visible;
if (visible) { if (visible) {
CGDisplayShowCursor(CGMainDisplayID()); CGDisplayShowCursor(CGMainDisplayID());

View File

@ -94,15 +94,15 @@ Point2D Window_PointToClient(int x, int y);
Point2D Window_PointToScreen(int x, int y); Point2D Window_PointToScreen(int x, int y);
/* Gets the position of the cursor in screen coordinates. */ /* Gets the position of the cursor in screen coordinates. */
Point2D Window_GetScreenCursorPos(void); Point2D Cursor_GetScreenPos(void);
/* Sets the position of the cursor in screen coordinates. */ /* Sets the position of the cursor in screen coordinates. */
void Window_SetScreenCursorPos(int x, int y); void Cursor_SetScreenPos(int x, int y);
/* Whether the cursor is visible when over this window. */ /* Whether the cursor is visible when over this window. */
bool Window_GetCursorVisible(void); bool Cursor_GetVisible(void);
/* Sets whether the cursor is visible when over this window. */ /* Sets whether the cursor is visible when over this window. */
/* NOTE: You MUST BE VERY CAREFUL with this! OS typically uses a counter for visibility, /* NOTE: You MUST BE VERY CAREFUL with this! OS typically uses a counter for visibility,
so setting invisible multiple times means you must then set visible multiple times. */ so setting invisible multiple times means you must then set visible multiple times. */
void Window_SetCursorVisible(bool visible); void Cursor_SetVisible(bool visible);
/* Shows a dialog box window. */ /* Shows a dialog box window. */
CC_API void Window_ShowDialog(const char* title, const char* msg); CC_API void Window_ShowDialog(const char* title, const char* msg);