tidy up .cw and .schematic exporter

This commit is contained in:
UnknownShadow200 2018-04-18 12:54:40 +10:00
parent d88f896998
commit 4b32d3c6a8
9 changed files with 156 additions and 139 deletions

View File

@ -21,28 +21,28 @@ namespace ClassicalSharp.Map {
this.game = game;
map = game.World;
nbt.Write(NbtTagType.Compound); nbt.Write("ClassicWorld");
nbt.Write(NbtTagType.Compound, "ClassicWorld");
nbt.Write(NbtTagType.Int8);
nbt.Write("FormatVersion"); nbt.WriteUInt8(1);
nbt.Write(NbtTagType.Int8, "FormatVersion");
nbt.WriteUInt8(1);
nbt.Write(NbtTagType.Int8Array);
nbt.Write("UUID"); nbt.WriteInt32(16);
nbt.Write(NbtTagType.Int8Array, "UUID");
nbt.WriteInt32(16);
nbt.WriteBytes(map.Uuid.ToByteArray());
nbt.Write(NbtTagType.Int16);
nbt.Write("X"); nbt.WriteInt16((short)map.Width);
nbt.Write(NbtTagType.Int16, "X");
nbt.WriteInt16((short)map.Width);
nbt.Write(NbtTagType.Int16);
nbt.Write("Y"); nbt.WriteInt16((short)map.Height);
nbt.Write(NbtTagType.Int16, "Y");
nbt.WriteInt16((short)map.Height);
nbt.Write(NbtTagType.Int16);
nbt.Write("Z"); nbt.WriteInt16((short)map.Length);
nbt.Write(NbtTagType.Int16, "Z");
nbt.WriteInt16((short)map.Length);
WriteSpawnCompoundTag();
nbt.Write(NbtTagType.Int8Array);
nbt.Write("BlockArray"); nbt.WriteInt32(map.blocks.Length);
nbt.Write(NbtTagType.Int8Array, "BlockArray");
nbt.WriteInt32(map.blocks.Length);
nbt.WriteBytes(map.blocks);
WriteMetadata();
@ -52,55 +52,53 @@ namespace ClassicalSharp.Map {
}
void WriteSpawnCompoundTag() {
nbt.Write(NbtTagType.Compound); nbt.Write("Spawn");
nbt.Write(NbtTagType.Compound, "Spawn");
LocalPlayer p = game.LocalPlayer;
Vector3 spawn = p.Position; // TODO: Maybe also keep real spawn too?
nbt.Write(NbtTagType.Int16);
nbt.Write("X"); nbt.WriteInt16((short)spawn.X);
nbt.Write(NbtTagType.Int16, "X");
nbt.WriteInt16((short)spawn.X);
nbt.Write(NbtTagType.Int16);
nbt.Write("Y"); nbt.WriteInt16((short)spawn.Y);
nbt.Write(NbtTagType.Int16, "Y");
nbt.WriteInt16((short)spawn.Y);
nbt.Write(NbtTagType.Int16);
nbt.Write("Z"); nbt.WriteInt16((short)spawn.Z);
nbt.Write(NbtTagType.Int16, "Z");
nbt.WriteInt16((short)spawn.Z);
nbt.Write(NbtTagType.Int8);
nbt.Write("H");
nbt.Write(NbtTagType.Int8, "H");
nbt.WriteUInt8(Utils.DegreesToPacked(p.SpawnRotY));
nbt.Write(NbtTagType.Int8);
nbt.Write("P");
nbt.Write(NbtTagType.Int8, "P");
nbt.WriteUInt8(Utils.DegreesToPacked(p.SpawnHeadX));
nbt.Write(NbtTagType.End);
}
void WriteMetadata() {
nbt.Write(NbtTagType.Compound); nbt.Write("Metadata");
nbt.Write(NbtTagType.Compound); nbt.Write("CPE");
nbt.Write(NbtTagType.Compound, "Metadata");
nbt.Write(NbtTagType.Compound, "CPE");
LocalPlayer p = game.LocalPlayer;
nbt.WriteCpeExtCompound("ClickDistance", 1);
nbt.Write(NbtTagType.Int16);
nbt.Write("Distance"); nbt.WriteInt16((short)(p.ReachDistance * 32));
nbt.Write(NbtTagType.Int16, "Distance");
nbt.WriteInt16((short)(p.ReachDistance * 32));
nbt.Write(NbtTagType.End);
nbt.WriteCpeExtCompound("EnvWeatherType", 1);
nbt.Write(NbtTagType.Int8);
nbt.Write("WeatherType"); nbt.WriteUInt8((byte)map.Env.Weather);
nbt.Write(NbtTagType.Int8, "WeatherType");
nbt.WriteUInt8((byte)map.Env.Weather);
nbt.Write(NbtTagType.End);
nbt.WriteCpeExtCompound("EnvMapAppearance", 1);
nbt.Write(NbtTagType.Int8);
nbt.Write("SideBlock"); nbt.WriteUInt8(map.Env.SidesBlock);
nbt.Write(NbtTagType.Int8);
nbt.Write("EdgeBlock"); nbt.WriteUInt8(map.Env.EdgeBlock);
nbt.Write(NbtTagType.Int16);
nbt.Write("SideLevel"); nbt.WriteInt16((short)map.Env.EdgeHeight);
nbt.Write(NbtTagType.String);
nbt.Write(NbtTagType.Int8, "SideBlock");
nbt.WriteUInt8(map.Env.SidesBlock);
nbt.Write(NbtTagType.Int8, "EdgeBlock");
nbt.WriteUInt8(map.Env.EdgeBlock);
nbt.Write(NbtTagType.Int16, "SideLevel");
nbt.WriteInt16((short)map.Env.EdgeHeight);
nbt.Write(NbtTagType.String, "TextureURL");
string url = game.World.TextureUrl == null ? "" : game.World.TextureUrl;
nbt.Write("TextureURL"); nbt.Write(url);
nbt.Write(url);
nbt.Write(NbtTagType.End);
nbt.WriteCpeExtCompound("EnvColors", 1);
@ -124,34 +122,34 @@ namespace ClassicalSharp.Map {
}
void WriteColourCompound(string name, FastColour col) {
nbt.Write(NbtTagType.Compound); nbt.Write(name);
nbt.Write(NbtTagType.Compound, name);
nbt.Write(NbtTagType.Int16);
nbt.Write("R"); nbt.WriteInt16(col.R);
nbt.Write(NbtTagType.Int16);
nbt.Write("G"); nbt.WriteInt16(col.G);
nbt.Write(NbtTagType.Int16);
nbt.Write("B"); nbt.WriteInt16(col.B);
nbt.Write(NbtTagType.Int16, "R");
nbt.WriteInt16(col.R);
nbt.Write(NbtTagType.Int16, "G");
nbt.WriteInt16(col.G);
nbt.Write(NbtTagType.Int16, "B");
nbt.WriteInt16(col.B);
nbt.Write(NbtTagType.End);
}
unsafe void WriteBlockDefinitionCompound(byte id) {
nbt.Write(NbtTagType.Compound); nbt.Write("Block" + id);
nbt.Write(NbtTagType.Compound, "Block" + id);
bool sprite = BlockInfo.Draw[id] == DrawType.Sprite;
nbt.Write(NbtTagType.Int8);
nbt.Write("ID"); nbt.WriteUInt8(id);
nbt.Write(NbtTagType.String);
nbt.Write("Name"); nbt.Write(BlockInfo.Name[id]);
nbt.Write(NbtTagType.Int8);
nbt.Write("CollideType"); nbt.WriteUInt8((byte)BlockInfo.Collide[id]);
nbt.Write(NbtTagType.Int8, "ID");
nbt.WriteUInt8(id);
nbt.Write(NbtTagType.String, "Name");
nbt.Write(BlockInfo.Name[id]);
nbt.Write(NbtTagType.Int8, "CollideType");
nbt.WriteUInt8((byte)BlockInfo.Collide[id]);
float speed = BlockInfo.SpeedMultiplier[id];
nbt.Write(NbtTagType.Real32);
nbt.Write("Speed"); nbt.WriteInt32(*((int*)&speed));
nbt.Write(NbtTagType.Real32, "Speed");
nbt.WriteInt32(*((int*)&speed));
nbt.Write(NbtTagType.Int8Array);
nbt.Write("Textures"); nbt.WriteInt32(6);
nbt.Write(NbtTagType.Int8Array, "Textures");
nbt.WriteInt32(6);
nbt.WriteUInt8(BlockInfo.GetTextureLoc(id, Side.Top));
nbt.WriteUInt8(BlockInfo.GetTextureLoc(id, Side.Bottom));
nbt.WriteUInt8(BlockInfo.GetTextureLoc(id, Side.Left));
@ -159,33 +157,34 @@ namespace ClassicalSharp.Map {
nbt.WriteUInt8(BlockInfo.GetTextureLoc(id, Side.Front));
nbt.WriteUInt8(BlockInfo.GetTextureLoc(id, Side.Back));
nbt.Write(NbtTagType.Int8);
nbt.Write("TransmitsLight"); nbt.WriteUInt8(BlockInfo.BlocksLight[id] ? 0 : 1);
nbt.Write(NbtTagType.Int8);
nbt.Write("WalkSound"); nbt.WriteUInt8((byte)BlockInfo.DigSounds[id]);
nbt.Write(NbtTagType.Int8);
nbt.Write("FullBright"); nbt.WriteUInt8(BlockInfo.FullBright[id] ? 1 : 0);
nbt.Write(NbtTagType.Int8, "TransmitsLight");
nbt.WriteUInt8(BlockInfo.BlocksLight[id] ? 0 : 1);
nbt.Write(NbtTagType.Int8, "WalkSound");
nbt.WriteUInt8(BlockInfo.DigSounds[id]);
nbt.Write(NbtTagType.Int8, "FullBright");
nbt.WriteUInt8(BlockInfo.FullBright[id] ? 1 : 0);
nbt.Write(NbtTagType.Int8, "Shape");
int shape = sprite ? 0 : (int)(BlockInfo.MaxBB[id].Y * 16);
nbt.Write(NbtTagType.Int8);
nbt.Write("Shape"); nbt.WriteUInt8(shape);
nbt.WriteUInt8(shape);
nbt.Write(NbtTagType.Int8, "BlockDraw");
byte draw = sprite ? BlockInfo.SpriteOffset[id] : BlockInfo.Draw[id];
nbt.Write(NbtTagType.Int8);
nbt.Write("BlockDraw"); nbt.WriteUInt8(draw);
nbt.WriteUInt8(draw);
FastColour col = BlockInfo.FogColour[id];
nbt.Write(NbtTagType.Int8Array);
nbt.Write("Fog"); nbt.WriteInt32(4);
nbt.Write(NbtTagType.Int8Array, "Fog");
nbt.WriteInt32(4);
byte fog = (byte)(128 * BlockInfo.FogDensity[id] - 1);
nbt.WriteUInt8(BlockInfo.FogDensity[id] == 0 ? (byte)0 : fog);
nbt.WriteUInt8(col.R); nbt.WriteUInt8(col.G); nbt.WriteUInt8(col.B);
Vector3 min = BlockInfo.MinBB[id], max = BlockInfo.MaxBB[id];
nbt.Write(NbtTagType.Int8Array);
nbt.Write("Coords"); nbt.WriteInt32(6);
nbt.Write(NbtTagType.Int8Array, "Coords");
nbt.WriteInt32(6);
nbt.WriteUInt8((byte)(min.X * 16)); nbt.WriteUInt8((byte)(min.Y * 16));
nbt.WriteUInt8((byte)(min.Z * 16)); nbt.WriteUInt8((byte)(max.X * 16));
nbt.WriteUInt8((byte)(max.Y * 16)); nbt.WriteUInt8((byte)(max.Z * 16));
nbt.Write(NbtTagType.End);
}
}

View File

@ -13,29 +13,27 @@ namespace ClassicalSharp.Map {
NbtFile nbt = new NbtFile(writer);
World map = game.World;
nbt.Write(NbtTagType.Compound); nbt.Write("Schematic");
nbt.Write(NbtTagType.Compound, "Schematic");
nbt.Write(NbtTagType.String);
nbt.Write("Materials"); nbt.Write("Classic");
nbt.Write(NbtTagType.String, "Materials");
nbt.Write("Classic");
nbt.Write(NbtTagType.Int16);
nbt.Write("Width"); nbt.WriteInt16((short)map.Width);
nbt.Write(NbtTagType.Int16, "Width");
nbt.WriteInt16((short)map.Width);
nbt.Write(NbtTagType.Int16);
nbt.Write("Height"); nbt.WriteInt16((short)map.Height);
nbt.Write(NbtTagType.Int16, "Height");
nbt.WriteInt16((short)map.Height);
nbt.Write(NbtTagType.Int16);
nbt.Write("Length"); nbt.WriteInt16((short)map.Length);
nbt.Write(NbtTagType.Int16, "Length");
nbt.WriteInt16((short)map.Length);
WriteBlocks(nbt, map.blocks);
WriteBlockData(nbt, map.blocks.Length);
nbt.Write(NbtTagType.List);
nbt.Write("Entities");
nbt.Write(NbtTagType.List, "Entities");
nbt.Write(NbtTagType.Compound); nbt.WriteInt32(0);
nbt.Write(NbtTagType.List);
nbt.Write("TileEntities");
nbt.Write(NbtTagType.List, "TileEntities");
nbt.Write(NbtTagType.Compound); nbt.WriteInt32(0);
nbt.Write(NbtTagType.End);
@ -45,8 +43,7 @@ namespace ClassicalSharp.Map {
void WriteBlocks(NbtFile nbt, byte[] blocks) {
const int chunkSize = 64 * 1024 * 32;
nbt.Write(NbtTagType.Int8Array);
nbt.Write("Blocks");
nbt.Write(NbtTagType.Int8Array, "Blocks");
nbt.WriteInt32(blocks.Length);
for (int i = 0; i < blocks.Length; i += chunkSize) {
@ -58,8 +55,7 @@ namespace ClassicalSharp.Map {
void WriteBlockData(NbtFile nbt, int blocksLength) {
const int chunkSize = 64 * 1024;
byte[] chunk = new byte[chunkSize];
nbt.Write(NbtTagType.Int8Array);
nbt.Write("Data");
nbt.Write(NbtTagType.Int8Array, "Data");
nbt.WriteInt32(blocksLength);
for (int i = 0; i < blocksLength; i += chunkSize) {

View File

@ -40,6 +40,8 @@ namespace ClassicalSharp.Map {
public void Write(NbtTagType v) { writer.Write((byte)v); }
public void Write(NbtTagType v, string name) { writer.Write((byte)v); Write(name); }
public void WriteInt32(int v) { writer.Write(IPAddress.HostToNetworkOrder(v)); }
public void WriteInt16(short v) { writer.Write(IPAddress.HostToNetworkOrder(v)); }
@ -60,10 +62,9 @@ namespace ClassicalSharp.Map {
}
public void WriteCpeExtCompound(string name, int version) {
Write(NbtTagType.Compound); Write(name);
Write(NbtTagType.Int32);
Write("ExtensionVersion"); WriteInt32(version);
Write(NbtTagType.Compound, name);
Write(NbtTagType.Int32, "ExtensionVersion");
WriteInt32(version);
}

View File

@ -184,11 +184,13 @@ void Fcm_Load(Stream* stream) {
#define NBT_TAG_COMPOUND 10
#define NBT_TAG_INT32_ARRAY 11
#define NBT_SMALL_SIZE (STRING_SIZE * 2)
struct NbtTag_;
typedef struct NbtTag_ {
struct NbtTag_* Parent;
UInt8 TagID;
UInt8 NameBuffer[String_BufferSize(STRING_SIZE)];
UInt8 NameBuffer[String_BufferSize(NBT_SMALL_SIZE)];
UInt32 NameSize;
UInt32 DataSize; /* size of data for arrays */
union {
@ -198,7 +200,7 @@ typedef struct NbtTag_ {
Int64 Value_I64;
Real32 Value_R32;
Real64 Value_R64;
UInt8 DataSmall[String_BufferSize(STRING_SIZE)];
UInt8 DataSmall[String_BufferSize(NBT_SMALL_SIZE)];
UInt8* DataBig; /* malloc for big byte arrays */
};
} NbtTag;
@ -237,18 +239,29 @@ UInt8 NbtTag_U8_At(NbtTag* tag, Int32 i) {
if (tag->TagID != NBT_TAG_INT8_ARRAY) { ErrorHandler_Fail("Expected I8_Array NBT tag"); }
if (i >= tag->DataSize) { ErrorHandler_Fail("Tried to access past bounds of I8_Array tag"); }
if (tag->DataSize < STRING_SIZE) return tag->DataSmall[i];
if (tag->DataSize < NBT_SMALL_SIZE) return tag->DataSmall[i];
return tag->DataBig[i];
}
UInt32 Nbt_ReadString(Stream* stream, UInt8* buffer) {
UInt16 nameLen = Stream_ReadUInt16_BE(stream);
if (nameLen > NBT_SMALL_SIZE) ErrorHandler_Fail("NBT String too long");
/* TODO: this is wrong, we need to UTF8 decode here*/
encoding.utf8.decode(buffer, nameLen);
Stream_Read(stream, buffer, nameLen);
return nameLen;
}
void Nbt_ReadTag(UInt8 typeId, bool readTagName, Stream* stream, NbtTag* parent) {
if (typeId == NBT_TAG_END) return;
NbtTag tag;
tag.NameBuffer[0] = NULL;
tag.Name = readTagName ? ReadString() : null;
tag.TagID = typeId;
tag.Parent = parent;
tag.NameSize = readTagName ? Nbt_ReadString(stream, tag.NameBuffer) : 0;
tag.DataSize = 0;
UInt8 childTagId;
UInt32 i, count;
@ -267,11 +280,23 @@ void Nbt_ReadTag(UInt8 typeId, bool readTagName, Stream* stream, NbtTag* parent)
case NBT_TAG_REAL64:
/* TODO: Is this union abuse even legal */
tag.Value_I64 = Stream_ReadInt64_BE(stream); break;
case NBT_TAG_INT8_ARRAY:
count = Stream_ReadUInt32_BE(stream);
tag.Value = reader.ReadBytes(count); break;
count = Stream_ReadUInt32_BE(stream);
tag.DataSize = count;
if (count < NBT_SMALL_SIZE) {
Stream_Read(stream, tag.DataSmall, count);
} else {
tag.DataBig = Platform_MemAlloc(count);
if (tag.DataBig == NULL) ErrorHandler_Fail("Nbt_ReadTag - allocating memory");
Stream_Read(stream, tag.DataBig, count);
}
break;
case NBT_TAG_STRING:
tag.Value = ReadString(); break;
tag.DataSize = Nbt_ReadString(stream, tag.DataSmall);
break;
case NBT_TAG_LIST:
childTagId = Stream_ReadUInt8(stream);
@ -294,5 +319,4 @@ void Nbt_ReadTag(UInt8 typeId, bool readTagName, Stream* stream, NbtTag* parent)
default:
ErrorHandler_Fail("Unrecognised NBT tag");
}
return tag;
}

View File

@ -105,7 +105,7 @@ void Gui_Init(void) {
void Gui_Reset(void) {
Int32 i;
for (i = 0; i < Gui_OverlaysCount; i++) {
Gui_Overlays[i]->VTABLE->Free((GuiElement*)Gui_Overlays[i]);
Elem_Free(Gui_Overlays[i]);
}
Gui_OverlaysCount = 0;
}
@ -113,11 +113,9 @@ void Gui_Reset(void) {
void Gui_Free(void) {
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, Gui_FileChanged);
Gui_SetNewScreen(NULL);
Gui_Status->VTABLE->Free((GuiElement*)Gui_Status);
Elem_Free(Gui_Status);
if (Gui_Active != NULL) {
Gui_Active->VTABLE->Free((GuiElement*)Gui_Active);
}
if (Gui_Active != NULL) { Elem_Free(Gui_Active); }
Gfx_DeleteTexture(&Gui_GuiTex);
Gfx_DeleteTexture(&Gui_GuiClassicTex);
Gfx_DeleteTexture(&Gui_IconsTex);
@ -142,9 +140,7 @@ Screen* Gui_GetUnderlyingScreen(void) {
void Gui_SetScreen(Screen* screen, bool freeOld) {
InputHandler_ScreenChanged(Gui_Active, screen);
if (Gui_Active != NULL && freeOld) {
Gui_Active->VTABLE->Free((GuiElement*)Gui_Active);
}
if (Gui_Active != NULL && freeOld) { Elem_Free(Gui_Active); }
if (screen == NULL) {
Window_SetCursorVisible(false);
@ -153,17 +149,12 @@ void Gui_SetScreen(Screen* screen, bool freeOld) {
Window_SetCursorVisible(true);
}
if (screen != NULL) {
screen->VTABLE->Init((GuiElement*)screen);
}
if (screen != NULL) { Elem_Init(screen); }
Gui_Active = screen;
}
void Gui_SetNewScreen(Screen* screen) { Gui_SetScreen(screen, true); }
void Gui_RefreshHud(void) {
Gui_HUD->VTABLE->Recreate((GuiElement*)Gui_HUD);
}
void Gui_RefreshHud(void) { Elem_Recreate(Gui_HUD); }
void Gui_ShowOverlay(Screen* overlay, bool atFront) {
if (Gui_OverlaysCount == GUI_MAX_OVERLAYS) {
@ -185,27 +176,27 @@ void Gui_ShowOverlay(Screen* overlay, bool atFront) {
Gui_OverlaysCount++;
if (Gui_OverlaysCount == 1) Game_SetCursorVisible(visible); /* Save cursor visibility state */
overlay->VTABLE->Init((GuiElement*)overlay);
Elem_Init(overlay);
}
void Gui_RenderGui(Real64 delta) {
GfxCommon_Mode2D(Game_Width, Game_Height);
if (Gui_Active == NULL || !Gui_Active->HidesHUD) {
Gui_Status->VTABLE->Render((GuiElement*)Gui_Status, delta);
Elem_Render(Gui_Status, delta);
}
if (Gui_Active == NULL || !Gui_Active->HidesHUD && !Gui_Active->RenderHUDOver) {
Gui_HUD->VTABLE->Render((GuiElement*)Gui_HUD, delta);
Elem_Render(Gui_HUD, delta);
}
if (Gui_Active != NULL) {
Gui_Active->VTABLE->Render((GuiElement*)Gui_Active, delta);
Elem_Render(Gui_Active, delta);
}
if (Gui_Active != NULL && !Gui_Active->HidesHUD && Gui_Active->RenderHUDOver) {
Gui_HUD->VTABLE->Render((GuiElement*)Gui_HUD, delta);
Elem_Render(Gui_HUD, delta);
}
if (Gui_OverlaysCount > 0) {
Gui_Overlays[0]->VTABLE->Render((GuiElement*)Gui_Overlays[0], delta);
Elem_Render(Gui_Overlays[0], delta);
}
GfxCommon_Mode3D();
}

View File

@ -178,7 +178,8 @@ bool InputHandler_HandleCoreKey(Key key) {
} else if (GameMode_HandlesKeyDown(key)) {
} else if (key == KeyBind_Get(KeyBind_IDOverlay)) {
if (Gui_OverlaysCount > 0) return true;
Gui_ShowOverlay(new TexIdsOverlay(), false);
Screen* overlay = TexIdsOverlay_MakeInstance();
Gui_ShowOverlay(overlay, false);
} else {
return false;
}
@ -331,7 +332,7 @@ void InputHandler_MouseWheel(void* obj, Real32 delta) {
if (!hotbar && Camera_ActiveCamera->Zoom(delta)) return;
if (InputHandler_DoFovZoom(delta) || !Inventory_CanChangeHeldBlock) return;
game.Gui.hudScreen.hotbar.HandlesMouseScroll(delta);
Gui.hudScreen.hotbar.HandlesMouseScroll(delta);
}
void InputHandler_MouseMove(void* obj, Int32 xDelta, Int32 yDelta) {

View File

@ -38,13 +38,14 @@ typedef struct ListScreen_ {
StringsBuffer Entries; /* NOTE: this is the last member so we can avoid memsetting it to 0 */
} ListScreen;
typedef void (*Menu_ContextRecreated)(GuiElement* elem);
typedef void (*Menu_ContextFunc)(void* obj);
#define MenuScreen_Layout \
Screen_Layout \
Widget** WidgetsPtr; \
Int32 WidgetsCount; \
FontDesc TitleFont, TextFont; \
Menu_ContextRecreated ContextRecreated;
Menu_ContextFunc ContextLost; \
Menu_ContextFunc ContextRecreated;
typedef struct MenuScreen_ { MenuScreen_Layout } MenuScreen;
@ -453,9 +454,12 @@ void MenuScreen_ContextLost(void* obj) {
Menu_FreeWidgets(screen->WidgetsPtr, screen->WidgetsCount);
}
void MenuScreen_ContextRecreated(void* obj) {
MenuScreen* screen = (MenuScreen*)obj;
screen->ContextRecreated((GuiElement*)screen);
void MenuScreen_ContextLost_Callback(void* obj) {
((MenuScreen*)obj)->ContextLost(obj);
}
void MenuScreen_ContextRecreated_Callback(void* obj) {
((MenuScreen*)obj)->ContextRecreated(obj);
}
void MenuScreen_Init(GuiElement* elem) {
@ -468,8 +472,8 @@ void MenuScreen_Init(GuiElement* elem) {
Platform_MakeFont(&screen->TextFont, &Game_FontName, 16, FONT_STYLE_NORMAL);
}
Event_RegisterVoid(&GfxEvents_ContextLost, screen, MenuScreen_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, screen, MenuScreen_ContextRecreated);
Event_RegisterVoid(&GfxEvents_ContextLost, screen, MenuScreen_ContextLost_Callback);
Event_RegisterVoid(&GfxEvents_ContextRecreated, screen, MenuScreen_ContextRecreated_Callback);
}
void MenuScreen_Render(GuiElement* elem, Real64 delta) {
@ -491,8 +495,8 @@ void MenuScreen_Free(GuiElement* elem) {
Platform_FreeFont(&screen->TextFont);
}
Event_UnregisterVoid(&GfxEvents_ContextLost, screen, MenuScreen_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, screen, MenuScreen_ContextRecreated);
Event_UnregisterVoid(&GfxEvents_ContextLost, screen, MenuScreen_ContextLost_Callback);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, screen, MenuScreen_ContextRecreated_Callback);
}
void MenuScreen_OnResize(GuiElement* elem) {
@ -500,7 +504,7 @@ void MenuScreen_OnResize(GuiElement* elem) {
Menu_RepositionWidgets(screen->WidgetsPtr, screen->WidgetsCount);
}
void MenuScreen_MakeInstance(MenuScreen* screen, Widget** widgets, Int32 count, Menu_ContextRecreated contextRecreated) {
void MenuScreen_MakeInstance(MenuScreen* screen, Widget** widgets, Int32 count, Menu_ContextFunc contextRecreated) {
Platform_MemSet(screen, 0, sizeof(MenuScreen));
screen->VTABLE = &MenuScreen_VTABLE;
Screen_Reset((Screen*)screen);
@ -521,6 +525,7 @@ void MenuScreen_MakeInstance(MenuScreen* screen, Widget** widgets, Int32 count,
screen->HandlesAllInput = true;
screen->WidgetsPtr = widgets;
screen->WidgetsCount = count;
screen->ContextLost = MenuScreen_ContextLost;
screen->ContextRecreated = contextRecreated;
}
@ -1698,7 +1703,7 @@ bool KeyBindingsScreen_HandlesMouseDown(GuiElement* elem, Int32 x, Int32 y, Mous
return true;
}
KeyBindingsScreen* KeyBindingsScreen_Make(Int32 bindsCount, KeyBind* binds, const UInt8** descs, ButtonWidget* buttons, Widget** widgets, Menu_ContextRecreated contextRecreated) {
KeyBindingsScreen* KeyBindingsScreen_Make(Int32 bindsCount, KeyBind* binds, const UInt8** descs, ButtonWidget* buttons, Widget** widgets, Menu_ContextFunc contextRecreated) {
KeyBindingsScreen* screen = &KeyBindingsScreen_Instance;
MenuScreen_MakeInstance((MenuScreen*)screen, widgets, bindsCount + 4, contextRecreated);
KeyBindingsScreen_VTABLE = *screen->VTABLE;
@ -2115,8 +2120,7 @@ void MenuOptionsScreen_Input(GuiElement* screenElem, GuiElement* widget) {
widgets[screen->WidgetsCount - 3] = (Widget*)(&screen->Default);
}
MenuOptionsScreen* MenuOptionsScreen_MakeInstance(Widget** widgets, Int32 count, Menu_ContextRecreated contextRecreated, MenuInputValidator* validators,
const UInt8** descriptions, const UInt8** defaultValues, ButtonWidget* buttons, Int32 descsCount) {
MenuOptionsScreen* MenuOptionsScreen_MakeInstance(Widget** widgets, Int32 count, Menu_ContextFunc contextRecreated, MenuInputValidator* validators, const UInt8** descriptions, const UInt8** defaultValues, ButtonWidget* buttons, Int32 descsCount) {
MenuOptionsScreen* screen = &MenuOptionsScreen_Instance;
Platform_MemSet(screen, 0, sizeof(MenuOptionsScreen));
MenuScreen_MakeInstance((MenuScreen*)screen, widgets, count, contextRecreated);
@ -2132,6 +2136,7 @@ MenuOptionsScreen* MenuOptionsScreen_MakeInstance(Widget** widgets, Int32 count,
screen->VTABLE->Render = MenuOptionsScreen_Render;
screen->VTABLE->Free = MenuOptionsScreen_Free;
screen->ContextLost = MenuOptionsScreen_ContextLost;
screen->Validators = validators;
screen->Descriptions = descriptions;
screen->DefaultValues = defaultValues;

View File

@ -978,7 +978,7 @@ bool ChatScreen_HandlesMouseDown(GuiElement* elem, Int32 x, Int32 y, MouseButton
String_AppendColorless(&url, &text);
if (Utils_IsUrlPrefix(&url, 0)) {
Overlay overlay = new UrlWarningOverlay(url);
Screen* overlay = UrlWarningOverlay_MakeInstance(&url);
Gui_ShowOverlay(overlay, false);
} else if (Game_ClickableChat) {
InputWidget_AppendString(&screen->Input.Base, &text);

View File

@ -52,7 +52,7 @@ void ServerConnection_BeginGeneration(Int32 width, Int32 height, Int32 length, I
Gui_SetNewScreen(GeneratingScreen_MakeInstance());
Gen_Width = width; Gen_Height = height; Gen_Length = length; Gen_Seed = seed;
gen.GenerateAsync(game);
gen.GenerateAsync();
}
void ServerConnection_EndGeneration(void) {