Skip to content

Commit

Permalink
more work on porting to posix
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 17, 2018
1 parent fad22fe commit ea9a881
Show file tree
Hide file tree
Showing 36 changed files with 422 additions and 459 deletions.
10 changes: 8 additions & 2 deletions ClassicalSharp/2D/Screens/Menu/ListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ protected string GetCur(Widget w) {

ButtonWidget MakeText(int i) {
string text = Get(currentIndex + i);
return ButtonWidget.Create(game, 300, text, font, TextButtonClick)
ButtonWidget btn = ButtonWidget.Create(game, 300, "", font, TextButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, (i - 2) * 50);
UpdateText(btn, text);
return btn;
}

ButtonWidget Make(int x, string text, ClickHandler onClick) {
Expand All @@ -89,11 +91,15 @@ protected void SetCurrentIndex(int index) {
currentIndex = index;

for (int i = 0; i < items; i++) {
((ButtonWidget)widgets[i]).SetText(Get(currentIndex + i));
UpdateText((ButtonWidget)widgets[i], Get(currentIndex + i));
}
UpdateArrows();
}

protected virtual void UpdateText(ButtonWidget widget, string text) {
widget.SetText(text);
}

void UpdateArrows() {
widgets[5].Disabled = false;
widgets[6].Disabled = false;
Expand Down
1 change: 0 additions & 1 deletion ClassicalSharp/ClassicalSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@
<Compile Include="Network\Utils\NetWriter.cs" />
<Compile Include="Math\PickedPos.cs" />
<Compile Include="Math\Picking.cs" />
<Compile Include="Platform\Font.cs" />
<Compile Include="Platform\Platform.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
40 changes: 0 additions & 40 deletions ClassicalSharp/Platform/Font.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/Client/AsyncDownloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ static void AsyncDownloader_Add(String* url, bool priority, String* id, UInt8 ty

Platform_Log2("Adding %s (type %b)", &reqUrl, &type);

if (lastModified != NULL) {
if (lastModified) {
req.LastModified = *lastModified;
}
if (etag != NULL) {
if (etag) {
String reqEtag = String_FromEmptyArray(req.Etag); String_Set(&reqEtag, etag);
}
//request.Data = data; TODO: Implement this. do we need to copy or expect caller to malloc it?
Expand Down Expand Up @@ -206,7 +206,7 @@ bool AsyncDownloader_GetCurrent(struct AsyncRequest* request, Int32* progress) {
*progress = async_curProgress;
}
Platform_MutexUnlock(async_curRequestMutex);
return request->ID[0] != NULL;
return request->ID[0];
}

static void AsyncDownloader_ProcessRequest(struct AsyncRequest* request) {
Expand Down
14 changes: 7 additions & 7 deletions src/Client/BlockPhysics.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Block.h"
#include "Lighting.h"
#include "Options.h"
#include "TreeGen.h"
#include "MapGenerator.h"
#include "Platform.h"
#include "Game.h"
#include "ErrorHandler.h"
Expand Down Expand Up @@ -121,7 +121,7 @@ void Physics_SetEnabled(bool enabled) {
static void Physics_Activate(Int32 index) {
BlockID block = World_Blocks[index];
PhysicsHandler activate = Physics_OnActivate[block];
if (activate != NULL) activate(index, block);
if (activate) activate(index, block);
}

static void Physics_ActivateNeighbours(Int32 x, Int32 y, Int32 z, Int32 index) {
Expand Down Expand Up @@ -153,10 +153,10 @@ static void Physics_BlockChanged(void* obj, Vector3I p, BlockID oldBlock, BlockI

if (block == BLOCK_AIR) {
PhysicsHandler deleteHandler = Physics_OnDelete[oldBlock];
if (deleteHandler != NULL) deleteHandler(index, oldBlock);
if (deleteHandler) deleteHandler(index, oldBlock);
} else {
PhysicsHandler placeHandler = Physics_OnPlace[block];
if (placeHandler != NULL) placeHandler(index, block);
if (placeHandler) placeHandler(index, block);
}
Physics_ActivateNeighbours(p.X, p.Y, p.Z, index);
}
Expand All @@ -176,17 +176,17 @@ static void Physics_TickRandomBlocks(void) {
Int32 index = Random_Range(&physics_rnd, lo, hi);
BlockID block = World_Blocks[index];
PhysicsHandler tick = Physics_OnRandomTick[block];
if (tick != NULL) tick(index, block);
if (tick) tick(index, block);

index = Random_Range(&physics_rnd, lo, hi);
block = World_Blocks[index];
tick = Physics_OnRandomTick[block];
if (tick != NULL) tick(index, block);
if (tick) tick(index, block);

index = Random_Range(&physics_rnd, lo, hi);
block = World_Blocks[index];
tick = Physics_OnRandomTick[block];
if (tick != NULL) tick(index, block);
if (tick) tick(index, block);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static struct ChatCommand* Commands_GetMatch(STRING_PURE String* cmdName) {
String name = String_FromReadonly(cmd->Name);
if (!String_CaselessStarts(&name, cmdName)) continue;

if (match != NULL) {
if (match) {
Commands_Log("&e/client: Multiple commands found that start with: \"&f%s&e\".", cmdName);
return NULL;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Client/ChunkUpdater.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void ChunkUpdater_PerformAllocations(void) {

void ChunkUpdater_Refresh(void) {
ChunkUpdater_ChunkPos = Vector3I_MaxValue();
if (MapRenderer_Chunks != NULL && World_Blocks != NULL) {
if (MapRenderer_Chunks && World_Blocks) {
ChunkUpdater_ClearChunkCache();
ChunkUpdater_ResetChunkCache();

Expand Down Expand Up @@ -355,7 +355,7 @@ void ChunkUpdater_DeleteChunk(struct ChunkInfo* info) {
#endif
Int32 i;

if (info->NormalParts != NULL) {
if (info->NormalParts) {
struct ChunkPartInfo* ptr = info->NormalParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset < 0) continue;
Expand All @@ -367,7 +367,7 @@ void ChunkUpdater_DeleteChunk(struct ChunkInfo* info) {
info->NormalParts = NULL;
}

if (info->TranslucentParts != NULL) {
if (info->TranslucentParts) {
struct ChunkPartInfo* ptr = info->TranslucentParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset < 0) continue;
Expand All @@ -392,14 +392,14 @@ void ChunkUpdater_BuildChunk(struct ChunkInfo* info, Int32* chunkUpdates) {
}
Int32 i;

if (info->NormalParts != NULL) {
if (info->NormalParts) {
struct ChunkPartInfo* ptr = info->NormalParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset >= 0) { MapRenderer_NormalPartsCount[i]++; }
}
}

if (info->TranslucentParts != NULL) {
if (info->TranslucentParts) {
struct ChunkPartInfo* ptr = info->TranslucentParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset >= 0) { MapRenderer_TranslucentPartsCount[i]++; }
Expand Down
6 changes: 1 addition & 5 deletions src/Client/Client.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
<ClInclude Include="GameStructs.h" />
<ClInclude Include="TerrainAtlas.h" />
<ClInclude Include="TexturePack.h" />
<ClInclude Include="TreeGen.h" />
<ClInclude Include="Utils.h" />
<ClInclude Include="WeatherRenderer.h" />
<ClInclude Include="PackedCol.h" />
Expand All @@ -241,7 +240,6 @@
<ClInclude Include="ExtMath.h" />
<ClInclude Include="GraphicsAPI.h" />
<ClInclude Include="GraphicsCommon.h" />
<ClInclude Include="Noise.h" />
<ClInclude Include="Platform.h" />
<ClInclude Include="Random.h" />
<ClInclude Include="String.h" />
Expand Down Expand Up @@ -296,12 +294,11 @@
<ClCompile Include="Options.c" />
<ClCompile Include="PackedCol.c" />
<ClCompile Include="GraphicsCommon.c" />
<ClCompile Include="Noise.c" />
<ClCompile Include="Particle.c" />
<ClCompile Include="BlockPhysics.c" />
<ClCompile Include="PickedPosRenderer.c" />
<ClCompile Include="Picking.c" />
<ClCompile Include="PosixPlatform.c" />
<ClCompile Include="X11Platform.c" />
<ClCompile Include="Program.c" />
<ClCompile Include="Random.c" />
<ClCompile Include="Screens.c" />
Expand All @@ -314,7 +311,6 @@
<ClCompile Include="TerrainAtlas.c" />
<ClCompile Include="Texture.c" />
<ClCompile Include="TexturePack.c" />
<ClCompile Include="TreeGen.c" />
<ClCompile Include="Utils.c" />
<ClCompile Include="Vectors.c" />
<ClCompile Include="WeatherRenderer.c" />
Expand Down
16 changes: 2 additions & 14 deletions src/Client/Client.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Noise.h">
<Filter>Header Files\Generator</Filter>
</ClInclude>
<ClInclude Include="Typedefs.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
Expand Down Expand Up @@ -258,9 +255,6 @@
<ClInclude Include="PickedPosRenderer.h">
<Filter>Header Files\SelectionBox</Filter>
</ClInclude>
<ClInclude Include="TreeGen.h">
<Filter>Header Files\Generator</Filter>
</ClInclude>
<ClInclude Include="IsometricDrawer.h">
<Filter>Header Files\2D</Filter>
</ClInclude>
Expand Down Expand Up @@ -365,9 +359,6 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Noise.c">
<Filter>Source Files\Generator</Filter>
</ClCompile>
<ClCompile Include="WinPlatform.c">
<Filter>Source Files\Platform</Filter>
</ClCompile>
Expand Down Expand Up @@ -440,9 +431,6 @@
<ClCompile Include="PickedPosRenderer.c">
<Filter>Source Files\SelectionBox</Filter>
</ClCompile>
<ClCompile Include="TreeGen.c">
<Filter>Source Files\Generator</Filter>
</ClCompile>
<ClCompile Include="IsometricDrawer.c">
<Filter>Source Files\2D</Filter>
</ClCompile>
Expand Down Expand Up @@ -572,10 +560,10 @@
<ClCompile Include="WinDisplayDevice.c">
<Filter>Source Files\Platform</Filter>
</ClCompile>
<ClCompile Include="PosixPlatform.c">
<ClCompile Include="Socket.c">
<Filter>Source Files\Platform</Filter>
</ClCompile>
<ClCompile Include="Socket.c">
<ClCompile Include="X11Platform.c">
<Filter>Source Files\Platform</Filter>
</ClCompile>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void Entities_Free(void) {
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Entities_ContextRecreated);
Event_UnregisterVoid(&ChatEvents_FontChanged, NULL, Entities_ChatFontChanged);

if (ShadowComponent_ShadowTex != NULL) {
if (ShadowComponent_ShadowTex) {
Gfx_DeleteTexture(&ShadowComponent_ShadowTex);
}
}
Expand Down
16 changes: 4 additions & 12 deletions src/Client/Formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,9 @@ static UInt32 Nbt_ReadString(struct Stream* stream, UChar* strBuffer) {
UChar nameBuffer[NBT_SMALL_SIZE * 4];
Stream_Read(stream, nameBuffer, nameLen);

/* TODO: Check how slow reading strings this way is */
struct Stream memStream;
Stream_ReadonlyMemory(&memStream, nameBuffer, nameLen, &stream->Name);
UInt16 codepoint;

UInt32 i;
for (i = 0; i < NBT_SMALL_SIZE; i++) {
if (!Stream_ReadUtf8Char(&memStream, &codepoint)) break;
strBuffer[i] = Convert_UnicodeToCP437(codepoint);
}
return i;
String str = String_Init(strBuffer, 0, NBT_SMALL_SIZE);
String_DecodeUtf8(&str, nameBuffer, nameLen);
return str.length;
}

typedef bool (*Nbt_Callback)(struct NbtTag* tag);
Expand Down Expand Up @@ -573,7 +565,7 @@ static bool Cw_Callback_5(struct NbtTag* tag) {
static bool Cw_Callback(struct NbtTag* tag) {
UInt32 depth = 0;
struct NbtTag* tmp = tag->Parent;
while (tmp != NULL) { depth++; tmp = tmp->Parent; }
while (tmp) { depth++; tmp = tmp->Parent; }

switch (depth) {
case 1: return Cw_Callback_1(tag);
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Game.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void Game_UpdateBlock(Int32 x, Int32 y, Int32 z, BlockID block) {
BlockID oldBlock = World_GetBlock(x, y, z);
World_SetBlock(x, y, z, block);

if (Weather_Heightmap != NULL) {
if (Weather_Heightmap) {
WeatherRenderer_OnBlockChanged(x, y, z, oldBlock, block);
}
Lighting_OnBlockChanged(x, y, z, oldBlock, block);
Expand Down Expand Up @@ -231,7 +231,7 @@ void Game_SetDefaultSkinType(struct Bitmap* bmp) {
Int32 i;
for (i = 0; i < ENTITIES_MAX_COUNT; i++) {
struct Entity* entity = Entities_List[i];
if (entity == NULL || entity->TextureId != NULL) continue;
if (entity == NULL || entity->TextureId) continue;
entity->SkinType = Game_DefaultPlayerSkinType;
}
}
Expand Down
Loading

0 comments on commit ea9a881

Please sign in to comment.