Compare commits

...

6 Commits

Author SHA1 Message Date
En Yi 8a731637f7 Merge branch 'main' into profiling 2024-09-08 23:06:26 +08:00
En Yi 4abe996640 Add urchin enemy
Changelog:
- Ctransform component now has a bounce coeffcient which determines
  velocity reflection on contact.
2024-09-08 23:05:12 +08:00
En Yi f6847f1ffd Merge branch 'main' into profiling 2024-09-02 22:45:47 +08:00
En Yi 3041f5df54 Merge branch 'remove_edge_check' into profiling 2024-09-02 22:02:37 +08:00
En Yi ca5c653b9d Test integrate tracy into scenes 2024-08-24 21:44:23 +08:00
En Yi b2beaea248 Experiment with Tracy profiler 2024-08-24 19:14:53 +08:00
10 changed files with 141 additions and 15 deletions

3
.gitmodules vendored 100644
View File

@ -0,0 +1,3 @@
[submodule "tracy"]
path = tracy
url = https://github.com/wolfpld/tracy.git

View File

@ -2,7 +2,7 @@ set(PROJECT_NAME HATPC_remake)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_FLAGS "-Wall -Wextra")
cmake_minimum_required(VERSION 3.22.1)
project(${PROJECT_NAME} C)
project(${PROJECT_NAME} C CXX)
set(CMAKE_C_STANDARD 99)
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
set(LIBZSTD_DIR /usr/local/lib CACHE FILEPATH "directory to zstd")
@ -45,6 +45,30 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
${GAME_LIBS}
)
add_executable(sandbox_trace
scene_test.c
tracy/public/TracyClient.cpp
)
target_compile_definitions(sandbox_trace
PUBLIC
TRACY_ENABLE
TRACY_ON_DEMAND
)
target_include_directories(sandbox_trace
PRIVATE
${CMAKE_CURRENT_LIST_DIR}
PUBLIC
tracy/public/
)
target_link_libraries(sandbox_trace
PUBLIC
lib_scenes_trace
pthread
dl
)
add_executable(scene_test
scene_test.c
)
@ -54,6 +78,7 @@ target_include_directories(scene_test
${CMAKE_CURRENT_LIST_DIR}
)
if (NOT EMSCRIPTEN)
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)

View File

@ -54,6 +54,7 @@ typedef struct _CTransform_t {
Vector2 shape_factor;
float grav_delay;
float grav_timer;
float bounce_coeff;
MovementMode_t movement_mode;
bool active;
} CTransform_t;

View File

@ -1,3 +1,6 @@
#ifdef TRACY_ENABLE
#include "tracy/TracyC.h"
#endif
#include "scene_impl.h"
#include "ent_impl.h"
#include "assets_loader.h"
@ -89,10 +92,22 @@ int main(void)
float frame_time = GetFrameTime();
float delta_time = fminf(frame_time, DT);
#ifdef TRACY_ENABLE
TracyCZoneN(ctx, "Overall", true)
#endif
#ifdef TRACY_ENABLE
TracyCZoneN(ctx1, "Update", true)
#endif
update_scene(&scene.scene, delta_time);
update_entity_manager(&scene.scene.ent_manager);
#ifdef TRACY_ENABLE
TracyCZoneEnd(ctx1)
#endif
// This is needed to advance time delta
render_scene(&scene.scene);
#ifdef TRACY_ENABLE
TracyCZoneEnd(ctx)
#endif
update_sfx_list(&engine);
if (WindowShouldClose()) break;
}

View File

@ -20,3 +20,32 @@ target_link_libraries(lib_scenes
PUBLIC
lib_engine
)
add_library(lib_scenes_trace STATIC
assets_loader.c
player_ent.c
items_ent.c
water_flow.c
editor_scene.c
menu_scene.c
level_select_scene.c
game_scene.c
game_systems.c
scene_systems.c
camera_systems.c
engine_impl.c
)
target_compile_definitions(lib_scenes_trace
PUBLIC
TRACY_ENABLE
TRACY_ON_DEMAND
)
target_include_directories(lib_scenes_trace
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
)
target_link_libraries(lib_scenes_trace
PUBLIC
lib_engine
)

View File

@ -1130,6 +1130,7 @@ static void at_level_dead(Scene_t* scene)
{
p_pstate->locked = true;
}
change_level_state(data, LEVEL_STATE_STARTING);
}
@ -1216,6 +1217,11 @@ void init_sandbox_scene(LevelScene_t* scene)
scene->data.player_spawn = p_player->position;
scene->data.camera.target_pos = p_player->position;
scene->data.camera.cam.target = p_player->position;
Entity_t* p_urchin = create_urchin(&scene->scene.ent_manager);
p_urchin->position = p_player->position;
p_urchin->position.x += 64;
p_urchin->position.y -= 240;
}
update_entity_manager(&scene->scene.ent_manager);

View File

@ -16,6 +16,7 @@ Entity_t* create_boulder(EntityManager_t* ent_manager);
Entity_t* create_arrow(EntityManager_t* ent_manager, uint8_t dir);
Entity_t* create_bomb(EntityManager_t* ent_manager, Vector2 launch_dir);
Entity_t* create_explosion(EntityManager_t* ent_manager);
Entity_t* create_urchin(EntityManager_t* ent_manager);
Entity_t* create_chest(EntityManager_t* ent_manager);
Entity_t* create_level_end(EntityManager_t* ent_manager);

View File

@ -1,3 +1,7 @@
#ifdef TRACY_ENABLE
#include "tracy/TracyC.h"
#endif
#include "game_systems.h"
#include "scene_impl.h"
@ -725,6 +729,9 @@ void spike_collision_system(Scene_t* scene)
void tile_collision_system(Scene_t* scene)
{
#ifdef TRACY_ENABLE
TracyCZoneN(ctx, "TileCol", true)
#endif
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
@ -820,21 +827,20 @@ void tile_collision_system(Scene_t* scene)
}
}
if (collide_side & (1<<3))
if (
((collide_side & (1<<3)) && (p_ctransform->velocity.x < 0))
|| ((collide_side & (1<<2)) && (p_ctransform->velocity.x > 0))
)
{
if (p_ctransform->velocity.x < 0) p_ctransform->velocity.x = 0;
p_ctransform->velocity.x *= -p_ctransform->bounce_coeff;
}
if (collide_side & (1<<2))
if (
((collide_side & (1<<1)) && (p_ctransform->velocity.y < 0))
|| ((collide_side & (1)) && (p_ctransform->velocity.y > 0))
)
{
if (p_ctransform->velocity.x > 0) p_ctransform->velocity.x = 0;
}
if (collide_side & (1<<1))
{
if (p_ctransform->velocity.y < 0) p_ctransform->velocity.y = 0;
}
if (collide_side & (1))
{
if (p_ctransform->velocity.y > 0) p_ctransform->velocity.y = 0;
p_ctransform->velocity.y *= -p_ctransform->bounce_coeff;
}
float decimal;
@ -860,6 +866,10 @@ void tile_collision_system(Scene_t* scene)
p_ent->position.y = decimal;
}
}
#ifdef TRACY_ENABLE
TracyCZoneEnd(ctx)
#endif
}
void friction_coefficient_update_system(Scene_t* scene)
@ -1303,7 +1313,7 @@ void movement_update_system(Scene_t* scene)
{
p_ent->position.x = p_ent->position.x;
}
p_ctransform->velocity.x = 0;
p_ctransform->velocity.x *= -p_ctransform->bounce_coeff;
}
if(p_ent->position.y < 0 || p_ent->position.y + p_bbox->size.y > level_height)
@ -1317,7 +1327,7 @@ void movement_update_system(Scene_t* scene)
{
p_ent->position.y = p_ent->position.y;
}
p_ctransform->velocity.y = 0;
p_ctransform->velocity.y *= -p_ctransform->bounce_coeff;
}
}
else

View File

@ -1,3 +1,5 @@
#include "EC.h"
#include "assets_tag.h"
#include "ent_impl.h"
#include "constants.h"
#include "raymath.h"
@ -242,6 +244,39 @@ Entity_t* create_explosion(EntityManager_t* ent_manager)
return p_explosion;
}
Entity_t* create_urchin(EntityManager_t* ent_manager)
{
Entity_t* p_urchin = add_entity(ent_manager, NO_ENT_TAG);
if (p_urchin == NULL) return NULL;
CBBox_t* p_bbox = add_component(p_urchin, CBBOX_COMP_T);
set_bbox(p_bbox, TILE_SIZE, TILE_SIZE);
CTransform_t* p_ctransform = add_component(p_urchin, CTRANSFORM_COMP_T);
p_ctransform->movement_mode = KINEMATIC_MOVEMENT;
p_ctransform->bounce_coeff = 1.0f;
p_ctransform->velocity.x = -100;
p_ctransform->active = true;
add_component(p_urchin, CTILECOORD_COMP_T);
CHurtbox_t* p_hurtbox = add_component(p_urchin, CHURTBOX_T);
p_hurtbox->size = p_bbox->size;
p_hurtbox->def = 2;
p_hurtbox->damage_src = -1;
CHitBoxes_t* p_hitbox = add_component(p_urchin, CHITBOXES_T);
p_hitbox->n_boxes = 1;
p_hitbox->boxes[0] = (Rectangle){3, 3, 26, 26};
p_hitbox->atk = 3;
CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T);
p_cspr->sprites = item_sprite_map;
p_cspr->current_idx = 0;
return p_urchin;
}
Entity_t* create_chest(EntityManager_t* ent_manager)
{
Entity_t* p_chest = add_entity(ent_manager, CHEST_ENT_TAG);

1
tracy 160000

@ -0,0 +1 @@
Subproject commit 5d542dc09f3d9378d005092a4ad446bd405f819a