mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Command line args work now
This commit is contained in:
parent
cbeaba1bdb
commit
0ed684a7e7
@ -11,6 +11,7 @@ void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
|
||||
bmp->Stride = width * BITMAP_SIZEOF_PIXEL;
|
||||
bmp->Scan0 = scan0;
|
||||
}
|
||||
|
||||
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size) {
|
||||
Int32 x, y;
|
||||
for (y = 0; y < size; y++) {
|
||||
@ -40,7 +41,7 @@ void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height) {
|
||||
}
|
||||
|
||||
|
||||
#define PNG_HEADER 8
|
||||
#define PNG_SIG_SIZE 8
|
||||
#define PNG_RGB_MASK 0xFFFFFFUL
|
||||
#define PNG_PALETTE 256
|
||||
#define PNG_FourCC(a, b, c, d) ((UInt32)a << 24) | ((UInt32)b << 16) | ((UInt32)c << 8) | (UInt32)d
|
||||
@ -58,15 +59,14 @@ void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height) {
|
||||
#define PNG_FILTER_PAETH 4
|
||||
|
||||
typedef void(*Png_RowExpander)(UInt8 bpp, Int32 width, UInt32* palette, UInt8* src, UInt32* dst);
|
||||
UInt8 png_sig[PNG_SIG_SIZE] = { 137, 80, 78, 71, 13, 10, 26, 10 };
|
||||
|
||||
void Png_CheckHeader(Stream* stream) {
|
||||
UInt8 header[PNG_HEADER];
|
||||
static UInt8 sig[PNG_HEADER] = { 137, 80, 78, 71, 13, 10, 26, 10 };
|
||||
Stream_Read(stream, header, PNG_HEADER);
|
||||
|
||||
UInt8 header[PNG_SIG_SIZE];
|
||||
Stream_Read(stream, header, PNG_SIG_SIZE);
|
||||
Int32 i;
|
||||
for (i = 0; i < PNG_HEADER; i++) {
|
||||
if (header[i] != sig[i]) ErrorHandler_Fail("Invalid PNG header");
|
||||
for (i = 0; i < PNG_SIG_SIZE; i++) {
|
||||
if (header[i] != png_sig[i]) ErrorHandler_Fail("Invalid PNG header");
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,3 +462,25 @@ void Bitmap_DecodePng(Bitmap* bmp, Stream* stream) {
|
||||
}
|
||||
if (bmp->Scan0 == NULL) ErrorHandler_Fail("Invalid PNG image");
|
||||
}
|
||||
|
||||
void Bitmap_EncodePng(Bitmap* bmp, Stream* stream) {
|
||||
Stream_Write(stream, png_sig, PNG_SIG_SIZE);
|
||||
|
||||
/* Write header chunk */
|
||||
Stream_WriteU32_BE(stream, 13);
|
||||
Stream_WriteU32_BE(stream, PNG_FourCC('I', 'H', 'D', 'R'));
|
||||
Stream_WriteU32_BE(stream, bmp->Width);
|
||||
Stream_WriteU32_BE(stream, bmp->Height);
|
||||
Stream_WriteU8(stream, 8); /* bits per sample */
|
||||
Stream_WriteU8(stream, PNG_COL_RGB); /* TODO: RGBA but mask all alpha to 255? */
|
||||
Stream_WriteU8(stream, 0); /* DEFLATE compression method */
|
||||
Stream_WriteU8(stream, 0); /* ADAPTIVE filter method */
|
||||
Stream_WriteU8(stream, 0); /* Not using interlacing */
|
||||
|
||||
/* Write PNG body */
|
||||
// do stuff here ????
|
||||
|
||||
/* Write end chunk */
|
||||
Stream_WriteU32_BE(stream, 0);
|
||||
Stream_WriteU32_BE(stream, PNG_FourCC('I', 'E', 'N', 'D'));
|
||||
}
|
@ -784,8 +784,6 @@ bool AsyncDownloader_GetCurrent(AsyncRequest* request, Int32* progress) { return
|
||||
void AsyncDownloader_PurgeOldEntriesTask(ScheduledTask* task) { }
|
||||
DateTime DateTime_FromTotalMs(Int64 ms) { DateTime time; return time; }
|
||||
|
||||
void Bitmap_EncodePng(Bitmap* bmp, Stream* stream) { }
|
||||
|
||||
void Gfx_MakeApiInfo(void) { }
|
||||
void AdvLightingBuilder_SetActive(void) { }
|
||||
|
||||
|
@ -17,6 +17,7 @@ extern ReturnCode ReturnCode_FileNotFound;
|
||||
void Platform_Init(void);
|
||||
void Platform_Free(void);
|
||||
void Platform_Exit(ReturnCode code);
|
||||
STRING_PURE String Platform_GetCommandLineArgs(void);
|
||||
|
||||
void* Platform_MemAlloc(UInt32 numElems, UInt32 elemsSize);
|
||||
void* Platform_MemRealloc(void* mem, UInt32 numElems, UInt32 elemsSize);
|
||||
|
@ -9,8 +9,9 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Constants.h"
|
||||
#include "Game.h"
|
||||
#include "Funcs.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int main(void) {
|
||||
ErrorHandler_Init("client.log");
|
||||
Platform_Init();
|
||||
|
||||
@ -47,27 +48,28 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
String title = String_FromConst(PROGRAM_APP_NAME);
|
||||
//argc = 5;
|
||||
//char* default_argv[5] = { "path", "UnknownShadow200", "fff", "127.0.0.1", "25566" };
|
||||
argc = 2;
|
||||
char* default_argv[2] = { "path", "UnknownShadow200" };
|
||||
argv = default_argv;
|
||||
String rawArgs = Platform_GetCommandLineArgs();
|
||||
//rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
|
||||
//rawArgs = String_FromReadonly("UnknownShadow200");
|
||||
|
||||
if (argc == 1 || argc == 2) {
|
||||
String_AppendConst(&Game_Username, argc > 1 ? argv[1] : "Singleplayer");
|
||||
//String_AppendConst(&Game_Username, "Singleplayer");
|
||||
} else if (argc < 5) {
|
||||
String args[5]; UInt32 argsCount = Array_Elems(args);
|
||||
String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
|
||||
|
||||
if (argsCount == 1) {
|
||||
String name = args[0];
|
||||
if (name.length == 0) name = String_FromReadonly("Singleplayer");
|
||||
String_Set(&Game_Username, &name);
|
||||
} else if (argsCount < 4) {
|
||||
Platform_LogConst("ClassicalSharp.exe is only the raw client. You must either use the launcher or provide command line arguments to start the client.");
|
||||
return;
|
||||
} else {
|
||||
String_AppendConst(&Game_Username, argv[1]);
|
||||
String_AppendConst(&Game_Mppass, argv[2]);
|
||||
String ipRaw = String_FromReadonly(argv[3]);
|
||||
String portRaw = String_FromReadonly(argv[4]);
|
||||
String_Set(&Game_Username, &args[0]);
|
||||
String_Set(&Game_Mppass, &args[1]);
|
||||
String_Set(&Game_IPAddress, &args[2]);
|
||||
|
||||
String bits[4]; UInt32 bitsCount = 4;
|
||||
String_UNSAFE_Split(&ipRaw, '.', bits, &bitsCount);
|
||||
if (bitsCount != 4) {
|
||||
String bits[4]; UInt32 bitsCount = Array_Elems(bits);
|
||||
String_UNSAFE_Split(&args[2], '.', bits, &bitsCount);
|
||||
if (bitsCount != Array_Elems(bits)) {
|
||||
Platform_LogConst("Invalid IP"); return;
|
||||
}
|
||||
|
||||
@ -78,11 +80,9 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
UInt16 portTmp;
|
||||
if (!Convert_TryParseUInt16(&portRaw, &portTmp)) {
|
||||
if (!Convert_TryParseUInt16(&args[3], &portTmp)) {
|
||||
Platform_LogConst("Invalid port"); return;
|
||||
}
|
||||
|
||||
String_Set(&Game_IPAddress, &ipRaw);
|
||||
Game_Port = portTmp;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,27 @@ void Platform_Exit(ReturnCode code) {
|
||||
ExitProcess(code);
|
||||
}
|
||||
|
||||
STRING_PURE String Platform_GetCommandLineArgs(void) {
|
||||
String args = String_FromReadonly(GetCommandLineA());
|
||||
|
||||
Int32 argsStart;
|
||||
if (args.buffer[0] == '"') {
|
||||
/* Handle path argument in full "path" form, which can include spaces */
|
||||
argsStart = String_IndexOf(&args, '"', 1) + 1;
|
||||
} else {
|
||||
argsStart = String_IndexOf(&args, ' ', 0) + 1;
|
||||
}
|
||||
|
||||
if (argsStart == 0) argsStart = args.length;
|
||||
args = String_UNSAFE_SubstringAt(&args, argsStart);
|
||||
|
||||
/* get rid of duplicate leading spaces before first arg */
|
||||
while (args.length > 0 && args.buffer[0] == ' ') {
|
||||
args = String_UNSAFE_SubstringAt(&args, 1);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
void* Platform_MemAlloc(UInt32 numElems, UInt32 elemsSize) {
|
||||
UInt32 numBytes = numElems * elemsSize; /* TODO: avoid overflow here */
|
||||
return malloc(numBytes);
|
||||
|
Loading…
x
Reference in New Issue
Block a user