Debug text & debug build options
use 'winedbg --gdb <file>' to start debugger
This commit is contained in:
parent
a802522eda
commit
4f9ea0a09a
@ -38,9 +38,9 @@ endif
|
||||
export INCLUDEFLAGS := $(Platform_INCLUDEFLAGS)
|
||||
|
||||
export CPPFLAGS = -DWIN32_LEAN_AND_MEAN
|
||||
export CFLAGS = $(INCLUDEFLAGS) $(BUILD_OPTIONS) -O2 -Wno-attributes -flto
|
||||
export CXXFLAGS = $(INCLUDEFLAGS) -DHELOS $(BUILD_OPTIONS) $(Platform_CXXFLAGS) -O2 -Wno-unused-result -flto -std=c++17
|
||||
export LDFLAGS = $(Platform_LDFLAGS) -s -O2 -flto
|
||||
export CFLAGS = $(INCLUDEFLAGS) $(BUILD_OPTIONS) -Wno-attributes -g
|
||||
export CXXFLAGS = $(INCLUDEFLAGS) -DHELOS $(BUILD_OPTIONS) $(Platform_CXXFLAGS) -Wno-unused-result -std=c++17 -g
|
||||
export LDFLAGS = $(Platform_LDFLAGS) -g
|
||||
export LDLIBS = $(Platform_LDLIBS) -lm -lstdc++
|
||||
|
||||
# Pattern rule for FASM assembly
|
||||
|
3
app.h
3
app.h
@ -5,6 +5,7 @@
|
||||
#include "player.h"
|
||||
#include "input.h"
|
||||
#include "types.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -26,6 +27,8 @@ void app_DeleteApp(App *app);
|
||||
void app_Advance(App *app, Duration deltaTime);
|
||||
void app_Render(App *app);
|
||||
|
||||
void app_DebugText(App *app, vector_Vector *vec_string);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
30
app_debug.c
Normal file
30
app_debug.c
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define PUSH_STRING(str) vector_Append(vec_string, str, strlen(str));
|
||||
|
||||
void app_DebugText(App *app, vector_Vector *vec_string) {
|
||||
vector_Clear(vec_string);
|
||||
char buf[256] = {};
|
||||
|
||||
Component_Player *player = app->player->player;
|
||||
if (!player) {
|
||||
PUSH_STRING("Player not available\n");
|
||||
} else {
|
||||
snprintf(
|
||||
buf, sizeof(buf) - 1,
|
||||
"Player:\n Pos: [%.4lf, %.4lf], Vec:[%.4lf, %.4lf]\n",
|
||||
player->super->position->position.x,
|
||||
player->super->position->position.y,
|
||||
player->super->position->velocity.x,
|
||||
player->super->position->velocity.y);
|
||||
PUSH_STRING(buf);
|
||||
}
|
||||
|
||||
char zero = '\0';
|
||||
vector_Push(vec_string, &zero);
|
||||
}
|
11
main.cpp
11
main.cpp
@ -3,7 +3,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "easyx.h"
|
||||
#include "types.h"
|
||||
#include "render_util.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
|
||||
int main() {
|
||||
@ -15,6 +18,9 @@ int main() {
|
||||
HWND win = initgraph(1280, 720);
|
||||
SetWindowTextA(win, "JacksEscape");
|
||||
|
||||
settextstyle(TEXTHEIGHT, 0, "Courier New");
|
||||
vector_Vector *debugText = vector_Create(1);
|
||||
|
||||
App *app = app_NewApp();
|
||||
while (!app->wantQuit) {
|
||||
if (time_Since(frameCounter).microseconds >= 1000000) { // 1 sec
|
||||
@ -31,8 +37,13 @@ int main() {
|
||||
BeginBatchDraw();
|
||||
cleardevice();
|
||||
app_Render(app);
|
||||
|
||||
app_DebugText(app, debugText);
|
||||
render_DrawText(10, 10, (const char *)vector_Data(debugText));
|
||||
|
||||
EndBatchDraw();
|
||||
|
||||
|
||||
Duration toSleep = {.microseconds = 1000000 / 60 - time_Reset(&lastFrame).microseconds};
|
||||
duration_Sleep(toSleep);
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ void physics_Advance(System_Physics *sys, Duration deltaTime) {
|
||||
i = tree_Node_Next(i)) {
|
||||
Component_Position *pos = *((Component_Position **)i->data);
|
||||
|
||||
// if (pos->super->hitbox && !pos->super->hitbox->fixed)
|
||||
// pos->velocity.y += gravity * duration_Seconds(deltaTime);
|
||||
if (pos->super->hitbox && !pos->super->hitbox->fixed)
|
||||
pos->velocity.y += gravity * duration_Seconds(deltaTime);
|
||||
|
||||
_physics_AdvanceEntity(sys, pos->super, deltaTime);
|
||||
}
|
||||
|
44
render_util.cpp
Normal file
44
render_util.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
#include "render_util.h"
|
||||
#include "easyx.h"
|
||||
#include "util/vector.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
static vector_Vector *tbuf;
|
||||
|
||||
void render_DrawText(int x, int y, const char *str) {
|
||||
if (!tbuf)
|
||||
tbuf = vector_Create(1);
|
||||
|
||||
int cx = x, cy = y;
|
||||
const char zero = 0;
|
||||
|
||||
vector_Clear(tbuf);
|
||||
int len = strlen(str);
|
||||
printf("%s, len=%d\n", str, len);
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
if (str[i] == '\n') {
|
||||
vector_Push(tbuf, &zero);
|
||||
printf("outtext: \"%s\"\n", vector_Data(tbuf));
|
||||
outtextxy(cx, cy, (LPCTSTR)vector_Data(tbuf));
|
||||
|
||||
cy += TEXTHEIGHT;
|
||||
vector_Clear(tbuf);
|
||||
} else
|
||||
vector_Push(tbuf, &str[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (vector_Size(tbuf) > 0) {
|
||||
vector_Push(tbuf, &zero);
|
||||
outtextxy(cx, cy, (LPCTSTR)vector_Data(tbuf));
|
||||
vector_Clear(tbuf);
|
||||
}
|
||||
}
|
||||
}
|
20
render_util.h
Normal file
20
render_util.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define TEXTHEIGHT 18
|
||||
|
||||
|
||||
// Draws text at the given on-screen position.
|
||||
//
|
||||
// unlike outtext(), this function takes consideration
|
||||
// for newlines.
|
||||
void render_DrawText(int x, int y, const char *str);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
2
types.h
2
types.h
@ -23,7 +23,7 @@ typedef struct {
|
||||
} Vec2;
|
||||
|
||||
|
||||
inline Vec2 vec2(double x, double y) {
|
||||
static inline Vec2 vec2(double x, double y) {
|
||||
Vec2 v = {.x = x, .y = y};
|
||||
return v;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void vector_Append(vector_Vector *vec, const void *data, uintptr_t n) {
|
||||
}
|
||||
|
||||
void vector_Resize(vector_Vector *vec, uintptr_t size) {
|
||||
uintptr_t newsize = vec->size + size * vec->objectSize;
|
||||
uintptr_t newsize = size;
|
||||
if (newsize > vec->cap) {
|
||||
// grow the buffer exponentially
|
||||
uint64_t newcap = vec->cap;
|
||||
|
Loading…
Reference in New Issue
Block a user