Skip to content

Commit

Permalink
feat: add script component to ECS extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan hoffstadt authored and hoffstadt committed May 21, 2024
1 parent 88c06d1 commit 6780c65
Show file tree
Hide file tree
Showing 16 changed files with 404 additions and 96 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: |
set VULKAN_SDK=C:\VulkanSDK\1.3.224.1
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python gen_build.py
python gen_examples.py
cd ../src
Expand All @@ -68,13 +68,14 @@ jobs:
if not exist ../out/pl_ref_renderer_ext.dll exit 1
if not exist ../out/pl_draw_ext.dll exit 1
if not exist ../out/pl_ui_ext.dll exit 1
if not exist ../out/pl_camera_script.dll exit 1
if not exist ../out/pilotlight.lib exit 1
- name: Package Pilot Light
shell: cmd
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python package.py
- name: Upload Pilot Light
Expand All @@ -100,7 +101,7 @@ jobs:
- name: Build Pilot Light
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 gen_build.py
python3 gen_examples.py
cd ../src
Expand Down Expand Up @@ -132,12 +133,13 @@ jobs:
test -f ./out/pl_ref_renderer_ext.dylib || exit 1
test -f ./out/pl_draw_ext.dylib || exit 1
test -f ./out/pl_ui_ext.dylib || exit 1
test -f ./out/pl_camera_script.dylib || exit 1
test -f ./out/pilotlight.a || exit 1
- name: Package Pilot Light
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 package.py
- name: Upload Pilot Light
Expand Down Expand Up @@ -177,7 +179,7 @@ jobs:
- name: Build Pilot Light
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 gen_build.py
python3 gen_examples.py
cd ../src
Expand Down Expand Up @@ -209,12 +211,13 @@ jobs:
test -f ./out/pl_ref_renderer_ext.so || exit 1
test -f ./out/pl_draw_ext.so || exit 1
test -f ./out/pl_ui_ext.so || exit 1
test -f ./out/pl_camera_script.so || exit 1
test -f ./out/pilotlight.a || exit 1
- name: Package Pilot Light
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 package.py
pwd
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
echo "You may use a free license. More information at https://www.viva64.com/en/b/0457/"
exit 0
fi
cd scripts
cd tools
python3 gen_build.py
cd ../src
chmod +x build.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
shell: cmd
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python gen_tests.py
cd ../tests
call build.bat -c debug
Expand All @@ -58,7 +58,7 @@ jobs:
- name: Run Tests
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 gen_tests.py
cd ../tests
chmod +x build.sh
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Run Tests
run: |
cd $GITHUB_WORKSPACE
cd scripts
cd tools
python3 gen_tests.py
cd ../tests
chmod +x build.sh
Expand Down
28 changes: 1 addition & 27 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
ptAppData->tMainCamera = gptEcs->create_perspective_camera(ptMainComponentLibrary, "main camera", (plVec3){-9.6f, 2.096f, 0.86f}, PL_PI_3, ptIO->afMainViewportSize[0] / ptIO->afMainViewportSize[1], 0.1f, 30.0f, &ptMainCamera);
gptCamera->set_pitch_yaw(ptMainCamera, -0.245f, 1.816f);
gptCamera->update(ptMainCamera);
gptEcs->attach_script(ptMainComponentLibrary, "pl_camera_script", PL_SCRIPT_FLAG_PLAYING, ptAppData->tMainCamera, NULL);

// create cull camera
plCameraComponent* ptCullCamera = NULL;
Expand Down Expand Up @@ -386,33 +387,6 @@ pl_app_update(plAppData* ptAppData)

plCameraComponent* ptCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera);
plCameraComponent* ptCullCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera);

static const float fCameraTravelSpeed = 4.0f;
static const float fCameraRotationSpeed = 0.005f;

// camera space
bool bOwnKeyboard = ptIO->bWantCaptureKeyboard;
if(!bOwnKeyboard)
{
if(gptIO->is_key_down(PL_KEY_W)) gptCamera->translate(ptCamera, 0.0f, 0.0f, fCameraTravelSpeed * ptIO->fDeltaTime);
if(gptIO->is_key_down(PL_KEY_S)) gptCamera->translate(ptCamera, 0.0f, 0.0f, -fCameraTravelSpeed* ptIO->fDeltaTime);
if(gptIO->is_key_down(PL_KEY_A)) gptCamera->translate(ptCamera, -fCameraTravelSpeed * ptIO->fDeltaTime, 0.0f, 0.0f);
if(gptIO->is_key_down(PL_KEY_D)) gptCamera->translate(ptCamera, fCameraTravelSpeed * ptIO->fDeltaTime, 0.0f, 0.0f);

// world space
if(gptIO->is_key_down(PL_KEY_F)) { gptCamera->translate(ptCamera, 0.0f, -fCameraTravelSpeed * ptIO->fDeltaTime, 0.0f); }
if(gptIO->is_key_down(PL_KEY_R)) { gptCamera->translate(ptCamera, 0.0f, fCameraTravelSpeed * ptIO->fDeltaTime, 0.0f); }
}

bool bOwnMouse = ptIO->bWantCaptureMouse;
if(!bOwnMouse && gptIO->is_mouse_dragging(PL_MOUSE_BUTTON_LEFT, 1.0f))
{
const plVec2 tMouseDelta = gptIO->get_mouse_drag_delta(PL_MOUSE_BUTTON_LEFT, 1.0f);
gptCamera->rotate(ptCamera, -tMouseDelta.y * fCameraRotationSpeed, -tMouseDelta.x * fCameraRotationSpeed);
gptIO->reset_mouse_drag_delta(PL_MOUSE_BUTTON_LEFT);
}

gptCamera->update(ptCamera);
gptCamera->update(ptCullCamera);

// run ecs system
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Next:
### Windows
Example for running example 0:
```bash
cd pilotlight/scripts
cd pilotlight/tools
python gen_examples.py
cd ../examples
build.bat
Expand All @@ -19,7 +19,7 @@ pilot_light.exe -a example_0
### MacOS & Linux
Example for running example 0:
```bash
cd pilotlight/scripts
cd pilotlight/tools
python3 gen_examples.py
cd ../examples
chmod +x build.sh
Expand Down
2 changes: 2 additions & 0 deletions extensions/pl_draw_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,8 @@ pl_cleanup_font_atlas(void)
}
pl_sb_free(gptCtx->tFontAtlas.sbtCustomRects);
pl_sb_free(gptCtx->tFontAtlas.sbtFonts);
pl_sb_free(gptCtx->tFontAtlas.sbtFontFreeIndices);
pl_sb_free(gptCtx->tFontAtlas.sbtFontGenerations);
pl_sb_free(gptCtx->tFontAtlas._sbtPrepData);
PL_FREE(gptCtx->tFontAtlas.pucPixelsAsAlpha8);
PL_FREE(gptCtx->tFontAtlas.pucPixelsAsRGBA32);
Expand Down
Loading

0 comments on commit 6780c65

Please sign in to comment.