diff --git a/src/Entity.c b/src/Entity.c index 5d514e7..5c45e7d 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -59,15 +59,22 @@ void Entity_GetTransform(struct Entity* e, Vec3 pos, Vec3 scale, struct Matrix* struct Matrix tmp; Matrix_Scale(m, scale.X, scale.Y, scale.Z); - Matrix_RotateZ(&tmp, -e->RotZ * MATH_DEG2RAD); - Matrix_MulBy(m, &tmp); - Matrix_RotateX(&tmp, -e->RotX * MATH_DEG2RAD); - Matrix_MulBy(m, &tmp); - Matrix_RotateY(&tmp, -e->RotY * MATH_DEG2RAD); - Matrix_MulBy(m, &tmp); + if (e->RotZ) { + Matrix_RotateZ( &tmp, -e->RotZ * MATH_DEG2RAD); + Matrix_MulBy(m, &tmp); + } + if (e->RotX) { + Matrix_RotateX( &tmp, -e->RotX * MATH_DEG2RAD); + Matrix_MulBy(m, &tmp); + } + if (e->RotY) { + Matrix_RotateY( &tmp, -e->RotY * MATH_DEG2RAD); + Matrix_MulBy(m, &tmp); + } + Matrix_Translate(&tmp, pos.X, pos.Y, pos.Z); - Matrix_MulBy(m, &tmp); - /* return rotZ * rotX * rotY * scale * translate; */ + Matrix_MulBy(m, &tmp); + /* return scale * rotZ * rotX * rotY * translate; */ } void Entity_GetPickingBounds(struct Entity* e, struct AABB* bb) { diff --git a/src/ExtMath.c b/src/ExtMath.c index 7fdd028..264ebc3 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -10,6 +10,10 @@ float Math_AbsF(float x) { return fabsf(x); /* MSVC intrinsic */ } float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } #endif +#ifdef CC_BUILD_DREAMCAST +double make_actions_build_compile(void) { fabs(4); } +#endif + float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ } int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ } diff --git a/src/Game.c b/src/Game.c index 0459b70..290f234 100644 --- a/src/Game.c +++ b/src/Game.c @@ -49,6 +49,7 @@ int Game_MaxViewDistance = DEFAULT_MAX_VIEWDIST; int Game_FpsLimit, Game_Vertices; cc_bool Game_SimpleArmsAnim; +static cc_bool gameRunning; cc_bool Game_ClassicMode, Game_ClassicHacks; cc_bool Game_AllowCustomBlocks; @@ -365,7 +366,7 @@ static void LoadPlugins(void) { } #endif -void Game_Free(void* obj); +static void Game_Free(void* obj); static void Game_Load(void) { struct IGameComponent* comp; Game_UpdateDimensions(); @@ -615,7 +616,7 @@ static void Game_RenderFrame(double delta) { Gfx_EndFrame(); } -void Game_Free(void* obj) { +static void Game_Free(void* obj) { struct IGameComponent* comp; /* Most components will call OnContextLost in their Free functions */ /* Set to false so components will always free managed textures too */ @@ -627,6 +628,7 @@ void Game_Free(void* obj) { if (comp->Free) comp->Free(); } + gameRunning = false; Logger_WarnFunc = Logger_DialogWarn; Gfx_Free(); Options_SaveIfChanged(); @@ -638,7 +640,7 @@ void Game_Free(void* obj) { delta = Stopwatch_ElapsedMicroseconds(Game_FrameStart, render) / (1000.0 * 1000.0);\ \ Window_ProcessEvents(delta);\ - if (!WindowInfo.Exists) return;\ + if (!gameRunning) return;\ \ if (delta > 1.0) delta = 1.0; /* avoid large delta with suspended process */ \ if (delta > 0.0) { Game_FrameStart = render; Game_RenderFrame(delta); } @@ -681,6 +683,7 @@ void Game_Run(int width, int height, const cc_string* title) { Window_Create3D(width, height); Window_SetTitle(title); Window_Show(); + gameRunning = true; Game_Load(); Event_RaiseVoid(&WindowEvents.Resized); diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index beccd58..6191e3d 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -125,21 +125,37 @@ static void SetDefaultState(void) { Gfx_SetAlphaTest(false); Gfx_SetDepthWrite(true); } +static void InitCitro3D(void) { + C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); + target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); + C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); + + SetDefaultState(); + AllocShaders(); +} static GfxResourceID white_square; void Gfx_Create(void) { + if (!Gfx.Created) InitCitro3D(); + Gfx.MaxTexWidth = 512; Gfx.MaxTexHeight = 512; Gfx.Created = true; gfx_vsync = true; - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); + Gfx_RestoreState(); +} - SetDefaultState(); +void Gfx_Free(void) { + Gfx_FreeState(); + // FreeShaders() + // C3D_Fini() +} + +cc_bool Gfx_TryRestoreContext(void) { return true; } + +void Gfx_RestoreState(void) { InitDefaultResources(); - AllocShaders(); // 8x8 dummy white texture // (textures must be at least 8x8, see C3D_TexInitWithParams source) @@ -150,16 +166,11 @@ void Gfx_Create(void) { white_square = Gfx_CreateTexture(&bmp, 0, false); } -void Gfx_Free(void) { - FreeShaders(); +void Gfx_FreeState(void) { FreeDefaultResources(); Gfx_DeleteTexture(&white_square); } -cc_bool Gfx_TryRestoreContext(void) { return true; } -void Gfx_RestoreState(void) { } -void Gfx_FreeState(void) { } - /*########################################################################################################################* *---------------------------------------------------------Textures--------------------------------------------------------* *#########################################################################################################################*/ diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index c34b7f9..ca9b987 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -48,12 +48,13 @@ static void InitGX(void) { } void Gfx_Create(void) { + if (!Gfx.Created) InitGX(); + Gfx.MaxTexWidth = 512; Gfx.MaxTexHeight = 512; Gfx.Created = true; gfx_vsync = true; - InitGX(); Gfx_RestoreState(); } diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index 17f7d1f..f3282ae 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -72,10 +72,23 @@ static void guInit(void) { static GfxResourceID white_square; void Gfx_Create(void) { + if (!Gfx.Created) guInit(); + Gfx.MaxTexWidth = 512; Gfx.MaxTexHeight = 512; Gfx.Created = true; - guInit(); + gfx_vsync = true; + + Gfx_RestoreState(); +} + +void Gfx_Free(void) { + Gfx_FreeState(); +} + +cc_bool Gfx_TryRestoreContext(void) { return true; } + +void Gfx_RestoreState(void) { InitDefaultResources(); // 1x1 dummy white texture @@ -85,14 +98,11 @@ void Gfx_Create(void) { white_square = Gfx_CreateTexture(&bmp, 0, false); } -void Gfx_Free(void) { +void Gfx_FreeState(void) { FreeDefaultResources(); Gfx_DeleteTexture(&white_square); } -cc_bool Gfx_TryRestoreContext(void) { return true; } -void Gfx_RestoreState(void) { } -void Gfx_FreeState(void) { } #define GU_Toggle(cap) if (enabled) { sceGuEnable(cap); } else { sceGuDisable(cap); } /*########################################################################################################################* @@ -424,4 +434,4 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, ICOUNT(verticesCount), gfx_indices, gfx_vertices + startVertex * SIZEOF_VERTEX_TEXTURED); } -#endif \ No newline at end of file +#endif diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index 9ee472d..a1aaaf2 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -65,20 +65,20 @@ static void* gxm_shader_patcher_fragment_usse_addr; static unsigned int shader_patcher_fragment_usse_offset; -#include "../misc/vita/colored_fs.h" -#include "../misc/vita/colored_vs.h" -static SceGxmProgram* gxm_colored_VP = (SceGxmProgram *)&colored_vs; -static SceGxmProgram* gxm_colored_FP = (SceGxmProgram *)&colored_fs; +#include "../misc/vita/colored_f.h" +#include "../misc/vita/colored_v.h" +static SceGxmProgram* gxm_colored_VP = (SceGxmProgram *)&colored_v; +static SceGxmProgram* gxm_colored_FP = (SceGxmProgram *)&colored_f; -#include "../misc/vita/textured_fs.h" -#include "../misc/vita/textured_vs.h" -static SceGxmProgram* gxm_textured_VP = (SceGxmProgram *)&textured_vs; -static SceGxmProgram* gxm_textured_FP = (SceGxmProgram *)&textured_fs; +#include "../misc/vita/textured_f.h" +#include "../misc/vita/textured_v.h" +static SceGxmProgram* gxm_textured_VP = (SceGxmProgram *)&textured_v; +static SceGxmProgram* gxm_textured_FP = (SceGxmProgram *)&textured_f; -#include "../misc/vita/colored_alpha_fs.h" -static SceGxmProgram* gxm_colored_alpha_FP = (SceGxmProgram *)&colored_alpha_fs; -#include "../misc/vita/textured_alpha_fs.h" -static SceGxmProgram* gxm_textured_alpha_FP = (SceGxmProgram *)&textured_alpha_fs; +#include "../misc/vita/colored_alpha_f.h" +static SceGxmProgram* gxm_colored_alpha_FP = (SceGxmProgram *)&colored_alpha_f; +#include "../misc/vita/textured_alpha_f.h" +static SceGxmProgram* gxm_textured_alpha_FP = (SceGxmProgram *)&textured_alpha_f; typedef struct CCVertexProgram { @@ -523,11 +523,7 @@ static void SetDefaultStates(void) { sceGxmSetBackDepthFunc(gxm_context, SCE_GXM_DEPTH_FUNC_LESS_EQUAL); } -void Gfx_Create(void) { - Gfx.MaxTexWidth = 512; - Gfx.MaxTexHeight = 512; - Gfx.Created = true; - +static void InitGPU(void) { InitGXM(); AllocRingBuffers(); AllocGXMContext(); @@ -547,13 +543,33 @@ void Gfx_Create(void) { AllocTexturedVertexProgram(1); CreateFragmentPrograms(3, gxm_textured_FP, gxm_textured_VP); CreateFragmentPrograms(9, gxm_textured_alpha_FP, gxm_textured_VP); +} + +void Gfx_Create(void) { + if (!Gfx.Created) InitGPU(); + + Gfx.MaxTexWidth = 512; + Gfx.MaxTexHeight = 512; + Gfx.Created = true; + gfx_vsync = true; Gfx_SetDepthTest(true); - InitDefaultResources(); Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED); frontBufferIndex = NUM_DISPLAY_BUFFERS - 1; backBufferIndex = 0; + Gfx_RestoreState(); +} + +void Gfx_Free(void) { + Gfx_FreeState(); +} + +cc_bool Gfx_TryRestoreContext(void) { return true; } + +void Gfx_RestoreState(void) { + InitDefaultResources(); + // 1x1 dummy white texture struct Bitmap bmp; BitmapCol pixels[1] = { BITMAPCOLOR_WHITE }; @@ -562,15 +578,11 @@ void Gfx_Create(void) { // TODO } -void Gfx_Free(void) { +void Gfx_FreeState(void) { FreeDefaultResources(); Gfx_DeleteTexture(&white_square); } -cc_bool Gfx_TryRestoreContext(void) { return true; } -void Gfx_RestoreState(void) { } -void Gfx_FreeState(void) { } - /*########################################################################################################################* *--------------------------------------------------------GPU Textures-----------------------------------------------------* diff --git a/src/Input.c b/src/Input.c index 7ce09ab..69a4c01 100644 --- a/src/Input.c +++ b/src/Input.c @@ -191,7 +191,8 @@ static void ClearTouches(void) { } #define Pad_Names \ "PAD_A", "PAD_B", "PAD_X", "PAD_Y", "PAD_L", "PAD_R", \ "PAD_LEFT", "PAD_RIGHT", "PAD_UP", "PAD_DOWN", \ -"PAD_START", "PAD_SELECT", "PAD_ZL", "PAD_ZR" +"PAD_START", "PAD_SELECT", "PAD_ZL", "PAD_ZR", \ +"PAD_LSTICK", "PAD_RSTICK" /* Names for each input button when stored to disc */ static const char* const storageNames[INPUT_COUNT] = { diff --git a/src/Input.h b/src/Input.h index 448435d..8651275 100644 --- a/src/Input.h +++ b/src/Input.h @@ -48,6 +48,7 @@ enum InputButtons { CCPAD_A, CCPAD_B, CCPAD_X, CCPAD_Y, CCPAD_L, CCPAD_R, CCPAD_LEFT, CCPAD_RIGHT, CCPAD_UP, CCPAD_DOWN, CCPAD_START, CCPAD_SELECT, CCPAD_ZL, CCPAD_ZR, + CCPAD_LSTICK, CCPAD_RSTICK, INPUT_COUNT, diff --git a/src/IsometricDrawer.c b/src/IsometricDrawer.c index 471ed49..ea65bf2 100644 --- a/src/IsometricDrawer.c +++ b/src/IsometricDrawer.c @@ -124,7 +124,6 @@ void IsometricDrawer_BeginBatch(struct VertexTextured* vertices, int* state) { } void IsometricDrawer_AddBatch(BlockID block, float size, float x, float y) { - struct VertexTextured* beg = iso_vertices; if (Blocks.Draw[block] == DRAW_GAS) return; iso_posX = x; iso_posY = y; diff --git a/src/Logger.c b/src/Logger.c index c2b2589..907356b 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -273,10 +273,20 @@ static void DumpFrame(cc_string* trace, void* addr) { *-------------------------------------------------------Backtracing-------------------------------------------------------* *#########################################################################################################################*/ #if defined CC_BUILD_WIN +/* This callback function is used so stack Walking works using StackWalk properly on Windows 9x: */ +/* - on Windows 9x process ID is passed instead of process handle as the "process" argument */ +/* - the SymXYZ functions expect a process ID on Windows 9x, so that works fine */ +/* - if NULL is passed as the "ReadMemory" argument, the default callback using ReadProcessMemory is used */ +/* - however, ReadProcessMemory expects a process handle, and so that will fail since it's given a process ID */ +/* So to work around this, instead manually call ReadProcessMemory with the current process handle */ +static BOOL __stdcall ReadMemCallback(HANDLE process, DWORD_PTR baseAddress, PVOID buffer, DWORD size, PDWORD numBytesRead) { + return ReadProcessMemory(GetCurrentProcess(), (LPCVOID)baseAddress, buffer, size, numBytesRead); +} + static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) { STACKFRAME frame = { 0 }; - HANDLE process, thread; int count, type; + HANDLE thread; frame.AddrPC.Mode = AddrModeFlat; frame.AddrFrame.Mode = AddrModeFlat; @@ -296,12 +306,11 @@ static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) { /* Always available after XP, so use that */ return RtlCaptureStackBackTrace(0, max, (void**)addrs, NULL); #endif - process = GetCurrentProcess(); - thread = GetCurrentThread(); + thread = GetCurrentThread(); for (count = 0; count < max; count++) { - if (!StackWalk(type, process, thread, &frame, ctx, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) break; + if (!StackWalk(type, curProcess, thread, &frame, ctx, ReadMemCallback, SymFunctionTableAccess, SymGetModuleBase, NULL)) break; if (!frame.AddrFrame.Offset) break; addrs[count] = frame.AddrPC.Offset; } @@ -1029,7 +1038,7 @@ void Logger_Hook(void) { DynamicLib_LoadAll(&imagehlp, funcs, Array_Elems(funcs), &lib); /* Windows 9x requires process IDs instead - see old DBGHELP docs */ - /* https://documentation.help/DbgHelp/documentation.pdf */ + /* https://documentation.help/DbgHelp/documentation.pdf */ osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); osInfo.dwPlatformId = 0; GetVersionExA(&osInfo); diff --git a/src/Model.c b/src/Model.c index 6ff17f6..dfcb9de 100644 --- a/src/Model.c +++ b/src/Model.c @@ -1896,6 +1896,7 @@ static void ZombieModel_Register(void) { *#########################################################################################################################*/ static BlockID bModel_block = BLOCK_AIR; static int bModel_index, bModel_texIndices[8]; +static struct VertexTextured* bModel_vertices; static float BlockModel_GetNameY(struct Entity* e) { BlockID block = e->ModelBlock; @@ -1957,13 +1958,15 @@ static void BlockModel_SpriteZQuad(cc_bool firstPart, cc_bool mirror) { else { rec.U1 = 0.5f; xz1 = 5.5f/16.0f; } } - ptr = &Models.Vertices[(bModel_index - 1) << 2]; + ptr = bModel_vertices; v.Col = col; v.X = xz1; v.Y = 0.0f; v.Z = xz1; v.U = rec.U2; v.V = rec.V2; *ptr++ = v; v.Y = 1.0f; v.V = rec.V1; *ptr++ = v; v.X = xz2; v.Z = xz2; v.U = rec.U1; *ptr++ = v; v.Y = 0.0f; v.V = rec.V2; *ptr++ = v; + + bModel_vertices = ptr; } static void BlockModel_SpriteXQuad(cc_bool firstPart, cc_bool mirror) { @@ -1985,21 +1988,30 @@ static void BlockModel_SpriteXQuad(cc_bool firstPart, cc_bool mirror) { else { rec.U2 = 0.5f; x2 = 5.5f/16.0f; z2 = -5.5f/16.0f; } } - ptr = &Models.Vertices[(bModel_index - 1) << 2]; + ptr = bModel_vertices; v.Col = col; v.X = x1; v.Y = 0.0f; v.Z = z1; v.U = rec.U2; v.V = rec.V2; *ptr++ = v; v.Y = 1.0f; v.V = rec.V1; *ptr++ = v; v.X = x2; v.Z = z2; v.U = rec.U1; *ptr++ = v; v.Y = 0.0f; v.V = rec.V2; *ptr++ = v; + + bModel_vertices = ptr; } +#define BLOCKMODEL_SPRITE_COUNT (8 * 4) +#define BLOCKMODEL_CUBE_COUNT (6 * 4) static void BlockModel_BuildParts(cc_bool sprite) { struct VertexTextured* ptr; Vec3 min, max; TextureLoc loc; + ptr = Gfx_LockDynamicVb(Models.Vb, VERTEX_FORMAT_TEXTURED, + sprite ? BLOCKMODEL_SPRITE_COUNT : BLOCKMODEL_CUBE_COUNT); + if (sprite) { + bModel_vertices = ptr; + BlockModel_SpriteXQuad(false, false); BlockModel_SpriteXQuad(false, true); BlockModel_SpriteZQuad(false, false); @@ -2015,7 +2027,6 @@ static void BlockModel_BuildParts(cc_bool sprite) { Drawer.Tinted = Blocks.Tinted[bModel_block]; Drawer.TintCol = Blocks.FogCol[bModel_block]; - ptr = Models.Vertices; min = Blocks.RenderMinBB[bModel_block]; max = Blocks.RenderMaxBB[bModel_block]; @@ -2029,11 +2040,12 @@ static void BlockModel_BuildParts(cc_bool sprite) { loc = BlockModel_GetTex(FACE_XMIN); Drawer_XMin(1, Models.Cols[4], loc, &ptr); loc = BlockModel_GetTex(FACE_YMAX); Drawer_YMax(1, Models.Cols[0], loc, &ptr); } + + Gfx_UnlockDynamicVb(Models.Vb); } static void BlockModel_DrawParts(void) { int lastTexIndex, i, offset = 0, count = 0; - Gfx_SetDynamicVbData(Models.Vb, Models.Vertices, bModel_index * 4); lastTexIndex = bModel_texIndices[0]; for (i = 0; i < bModel_index; i++, count += 4) { diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 06d8816..86d06bc 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -471,6 +471,8 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { *-------------------------------------------------------Encryption--------------------------------------------------------* *#########################################################################################################################*/ static cc_result GetMachineID(cc_uint32* key) { + // doesn't really matter if called multiple times + psInit(); return PS_GetDeviceId(key); } #endif \ No newline at end of file diff --git a/src/Platform_WinApi.c b/src/Platform_Windows.c similarity index 100% rename from src/Platform_WinApi.c rename to src/Platform_Windows.c diff --git a/src/Screens.c b/src/Screens.c index 7f56ea7..9c07834 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -70,13 +70,19 @@ static struct HUDScreen { struct TextWidget line1, line2; struct TextAtlas posAtlas; double accumulator; - int frames; + int frames, posCount; cc_bool hacksChanged; float lastSpeed; int lastFov; + int lastX, lastY, lastZ; struct HotbarWidget hotbar; } HUDScreen_Instance; -#define HUD_MAX_VERTICES (4 + TEXTWIDGET_MAX * 2 + HOTBAR_MAX_VERTICES) + +/* Each integer can be at most 10 digits + minus prefix */ +#define POSITION_VAL_CHARS 11 +/* [PREFIX] [(] [X] [,] [Y] [,] [Z] [)] */ +#define POSITION_HUD_CHARS (1 + 1 + POSITION_VAL_CHARS + 1 + POSITION_VAL_CHARS + 1 + POSITION_VAL_CHARS + 1) +#define HUD_MAX_VERTICES (4 + TEXTWIDGET_MAX * 2 + HOTBAR_MAX_VERTICES + POSITION_HUD_CHARS * 4) static void HUDScreen_RemakeLine1(struct HUDScreen* s) { cc_string status; char statusBuffer[STRING_SIZE * 2]; @@ -106,36 +112,30 @@ static void HUDScreen_RemakeLine1(struct HUDScreen* s) { s->dirty = true; } -static void HUDScreen_DrawPosition(struct HUDScreen* s) { - struct VertexTextured vertices[4 * 64]; - struct VertexTextured* ptr = vertices; - +static void HUDScreen_BuildPosition(struct HUDScreen* s, struct VertexTextured* data) { + struct VertexTextured* cur = data; struct TextAtlas* atlas = &s->posAtlas; struct Texture tex; IVec3 pos; - int count; /* Make "Position: " prefix */ tex = atlas->tex; tex.X = 2; tex.Width = atlas->offset; - Gfx_Make2DQuad(&tex, PACKEDCOL_WHITE, &ptr); + Gfx_Make2DQuad(&tex, PACKEDCOL_WHITE, &cur); IVec3_Floor(&pos, &LocalPlayer_Instance.Base.Position); atlas->curX = atlas->offset + 2; /* Make (X, Y, Z) suffix */ - TextAtlas_Add(atlas, 13, &ptr); - TextAtlas_AddInt(atlas, pos.X, &ptr); - TextAtlas_Add(atlas, 11, &ptr); - TextAtlas_AddInt(atlas, pos.Y, &ptr); - TextAtlas_Add(atlas, 11, &ptr); - TextAtlas_AddInt(atlas, pos.Z, &ptr); - TextAtlas_Add(atlas, 14, &ptr); + TextAtlas_Add(atlas, 13, &cur); + TextAtlas_AddInt(atlas, pos.X, &cur); + TextAtlas_Add(atlas, 11, &cur); + TextAtlas_AddInt(atlas, pos.Y, &cur); + TextAtlas_Add(atlas, 11, &cur); + TextAtlas_AddInt(atlas, pos.Z, &cur); + TextAtlas_Add(atlas, 14, &cur); - Gfx_BindTexture(atlas->tex.ID); - /* TODO: Do we need to use a separate VB here? */ - count = (int)(ptr - vertices); - Gfx_UpdateDynamicVb_IndexedTris(Models.Vb, vertices, count); + s->posCount = (int)(cur - data); } static cc_bool HUDScreen_HasHacksChanged(struct HUDScreen* s) { @@ -313,6 +313,8 @@ static void HUDScreen_UpdateFPS(struct HUDScreen* s, double delta) { static void HUDScreen_Update(void* screen, double delta) { struct HUDScreen* s = (struct HUDScreen*)screen; + IVec3 pos; + HUDScreen_UpdateFPS(s, delta); HotbarWidget_Update(&s->hotbar, delta); if (Game_ClassicMode) return; @@ -320,6 +322,10 @@ static void HUDScreen_Update(void* screen, double delta) { if (IsOnlyChatActive() && Gui.ShowFPS) { if (HUDScreen_HasHacksChanged(s)) HUDScreen_RemakeLine2(s); } + + IVec3_Floor(&pos, &LocalPlayer_Instance.Base.Position); + if (pos.X != s->lastX || pos.Y != s->lastY || pos.Z != s->lastZ) + s->dirty = true; } #define CH_EXTENT 16 @@ -349,6 +355,9 @@ static void HUDScreen_BuildMesh(void* screen) { Widget_BuildMesh(&s->line1, ptr); Widget_BuildMesh(&s->line2, ptr); Widget_BuildMesh(&s->hotbar, ptr); + + if (!Game_ClassicMode) + HUDScreen_BuildPosition(s, data); Gfx_UnlockDynamicVb(s->vb); } @@ -364,7 +373,8 @@ static void HUDScreen_Render(void* screen, double delta) { Widget_Render2(&s->line2, 8); } else if (IsOnlyChatActive() && Gui.ShowFPS) { Widget_Render2(&s->line2, 8); - HUDScreen_DrawPosition(s); + Gfx_BindTexture(s->posAtlas.tex.ID); + Gfx_DrawVb_IndexedTris_Range(s->posCount, 12 + HOTBAR_MAX_VERTICES); /* TODO swap these two lines back */ } diff --git a/src/Window_3DS.c b/src/Window_3DS.c index 9be979e..42861cc 100644 --- a/src/Window_3DS.c +++ b/src/Window_3DS.c @@ -70,7 +70,7 @@ void Window_Show(void) { } void Window_SetSize(int width, int height) { } void Window_Close(void) { - /* TODO implement */ + Event_RaiseVoid(&WindowEvents.Closing); } /*########################################################################################################################* diff --git a/src/Window_Android.c b/src/Window_Android.c index 4f5e2e5..3bf71a9 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -26,6 +26,7 @@ static void RefreshWindowBounds(void) { Event_RaiseVoid(&WindowEvents.Resized); } +// https://developer.android.com/ndk/reference/group/input static int MapNativeKey(int code) { if (code >= AKEYCODE_0 && code <= AKEYCODE_9) return (code - AKEYCODE_0) + '0'; if (code >= AKEYCODE_A && code <= AKEYCODE_Z) return (code - AKEYCODE_A) + 'A'; @@ -96,6 +97,8 @@ static int MapNativeKey(int code) { case AKEYCODE_BUTTON_START: return CCPAD_START; case AKEYCODE_BUTTON_SELECT: return CCPAD_SELECT; + case AKEYCODE_BUTTON_THUMBL: return CCPAD_LSTICK; + case AKEYCODE_BUTTON_THUMBR: return CCPAD_RSTICK; } return INPUT_NONE; } @@ -299,7 +302,7 @@ static void RemakeWindowSurface(void) { /* Loop until window gets created by main UI thread */ /* (i.e. until processSurfaceCreated is received) */ while (!winCreated) { - Window_ProcessEvents(0.0); + Window_ProcessEvents(0.01); Thread_Sleep(10); } diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index bd86ed7..bc74a72 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -16,6 +16,7 @@ #include #endif +static cc_bool needsFBUpdate; static cc_bool launcherMode; static void* xfb; static GXRModeObj* rmode; @@ -28,16 +29,10 @@ int Display_ScaleY(int y) { return y; } static void OnPowerOff(void) { - Event_RaiseVoid(&WindowEvents.Closing); WindowInfo.Exists = false; + Window_Close(); } - -void Window_Init(void) { - // TODO: SYS_SetResetCallback(reload); too? not sure how reset differs on GC/WII - #if defined HW_RVL - SYS_SetPowerCallback(OnPowerOff); - #endif - +static void InitVideo(void) { // Initialise the video system VIDEO_Init(); @@ -61,6 +56,14 @@ void Window_Init(void) { VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); +} + +void Window_Init(void) { + // TODO: SYS_SetResetCallback(reload); too? not sure how reset differs on GC/WII + #if defined HW_RVL + SYS_SetPowerCallback(OnPowerOff); + #endif + InitVideo(); DisplayInfo.Width = rmode->fbWidth; DisplayInfo.Height = rmode->xfbHeight; @@ -81,11 +84,17 @@ void Window_Init(void) { PAD_Init(); } -void Window_Create2D(int width, int height) { launcherMode = true; } -void Window_Create3D(int width, int height) { launcherMode = false; } +void Window_Create2D(int width, int height) { + needsFBUpdate = true; + launcherMode = true; +} + +void Window_Create3D(int width, int height) { + launcherMode = false; +} void Window_Close(void) { - /* TODO implement */ + Event_RaiseVoid(&WindowEvents.Closing); } @@ -465,6 +474,13 @@ static u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2) } void Window_DrawFramebuffer(Rect2D r) { + // When coming back from the 3D game, framebuffer might have changed + if (needsFBUpdate) { + VIDEO_SetNextFramebuffer(xfb); + VIDEO_Flush(); + needsFBUpdate = false; + } + VIDEO_WaitVSync(); r.X &= ~0x01; // round down to nearest even horizontal index diff --git a/src/Window_PSP.c b/src/Window_PSP.c index 91ffa56..4d26678 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -58,7 +58,7 @@ void Window_Show(void) { } void Window_SetSize(int width, int height) { } void Window_Close(void) { - /* TODO implement */ + Event_RaiseVoid(&WindowEvents.Closing); } diff --git a/src/Window_PSVita.c b/src/Window_PSVita.c index 7c67eb0..a128f18 100644 --- a/src/Window_PSVita.c +++ b/src/Window_PSVita.c @@ -61,7 +61,7 @@ void Window_Show(void) { } void Window_SetSize(int width, int height) { } void Window_Close(void) { - /* TODO implement */ + Event_RaiseVoid(&WindowEvents.Closing); } @@ -122,7 +122,7 @@ static void ProcessTouchInput(void) { if (touch.reportNum > 0) { int x = touch.report[0].x; int y = touch.report[0].y; - ProcessTouchPress(X, Y); + ProcessTouchPress(x, y); } Input_SetNonRepeatable(CCMOUSE_L, touch.reportNum > 0); } diff --git a/src/Window_Web.c b/src/Window_Web.c index 1aadbfe..7db422e 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -540,8 +540,10 @@ static void ProcessGamepadButtons(EmscriptenGamepadEvent* ev) { Input_SetNonRepeatable(CCPAD_ZL, GetGamepadButton(6)); Input_SetNonRepeatable(CCPAD_ZR, GetGamepadButton(7)); - Input_SetNonRepeatable(CCPAD_SELECT, GetGamepadButton(8)); - Input_SetNonRepeatable(CCPAD_START, GetGamepadButton(9)); + Input_SetNonRepeatable(CCPAD_SELECT, GetGamepadButton( 8)); + Input_SetNonRepeatable(CCPAD_START, GetGamepadButton( 9)); + Input_SetNonRepeatable(CCPAD_LSTICK, GetGamepadButton(10)); + Input_SetNonRepeatable(CCPAD_RSTICK, GetGamepadButton(11)); Input_SetNonRepeatable(CCPAD_UP, GetGamepadButton(12)); Input_SetNonRepeatable(CCPAD_DOWN, GetGamepadButton(13)); diff --git a/src/Window_Xbox.c b/src/Window_Xbox.c index 8ee3a2f..f1c4126 100644 --- a/src/Window_Xbox.c +++ b/src/Window_Xbox.c @@ -74,7 +74,7 @@ void Window_Init(void) { WindowInfo.Focused = true; WindowInfo.Exists = true; - Input.GamepadSource = true; + Input.Sources = INPUT_SOURCE_GAMEPAD; usbh_core_init(); usbh_xid_init(); @@ -98,7 +98,7 @@ void Window_Show(void) { } void Window_SetSize(int width, int height) { } void Window_Close(void) { - /* TODO implement */ + Event_RaiseVoid(&WindowEvents.Closing); } @@ -130,6 +130,8 @@ static void HandleButtons(xid_gamepad_in* gp) { Input_SetNonRepeatable(CCPAD_START, mods & XINPUT_GAMEPAD_START); Input_SetNonRepeatable(CCPAD_SELECT, mods & XINPUT_GAMEPAD_BACK); + Input_SetNonRepeatable(CCPAD_LSTICK, mods & XINPUT_GAMEPAD_LEFT_THUMB); + Input_SetNonRepeatable(CCPAD_RSTICK, mods & XINPUT_GAMEPAD_RIGHT_THUMB); Input_SetNonRepeatable(CCPAD_LEFT, mods & XINPUT_GAMEPAD_DPAD_LEFT); Input_SetNonRepeatable(CCPAD_RIGHT, mods & XINPUT_GAMEPAD_DPAD_RIGHT);