Skip to content

Commit

Permalink
Sync all files again
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Oct 8, 2023
1 parent 7aba626 commit bfe7589
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 103 deletions.
23 changes: 15 additions & 8 deletions src/Entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/ExtMath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ }

Expand Down
9 changes: 6 additions & 3 deletions src/Game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
Expand All @@ -627,6 +628,7 @@ void Game_Free(void* obj) {
if (comp->Free) comp->Free();
}

gameRunning = false;
Logger_WarnFunc = Logger_DialogWarn;
Gfx_Free();
Options_SaveIfChanged();
Expand All @@ -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); }
Expand Down Expand Up @@ -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);
Expand Down
33 changes: 22 additions & 11 deletions src/Graphics_3DS.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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--------------------------------------------------------*
*#########################################################################################################################*/
Expand Down
3 changes: 2 additions & 1 deletion src/Graphics_GCWii.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
22 changes: 16 additions & 6 deletions src/Graphics_PSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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); }

/*########################################################################################################################*
Expand Down Expand Up @@ -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
#endif
58 changes: 35 additions & 23 deletions src/Graphics_PSVita.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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 };
Expand All @@ -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-----------------------------------------------------*
Expand Down
3 changes: 2 additions & 1 deletion src/Input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
1 change: 1 addition & 0 deletions src/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 0 additions & 1 deletion src/IsometricDrawer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions src/Logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit bfe7589

Please sign in to comment.