-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,479 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
## Examples | ||
The following examples have been provided to help newcomers become acclimated to using **Pilot Light**. The examples can be found in the **examples** directory. | ||
|
||
To run the examples, first follow the build instructions [here](https://github.com/PilotLightTech/pilotlight/wiki/Building). | ||
|
||
Next: | ||
|
||
### Windows | ||
Example for running example 0: | ||
```bash | ||
cd pilotlight/scripts | ||
python gen_examples.py | ||
cd ../examples | ||
build.bat | ||
|
||
cd ../out | ||
pilot_light.exe -a example_0 | ||
``` | ||
### MacOS & Linux | ||
Example for running example 0: | ||
```bash | ||
cd pilotlight/scripts | ||
python3 gen_examples.py | ||
cd ../examples | ||
chmod +x build.sh | ||
./build.sh | ||
|
||
cd ../out | ||
pilot_light -a example_0 | ||
``` | ||
|
||
## Example 0 - Minimal App (example_0.c) | ||
Demonstrates the bare minimumal app. This app loads, runs 50 iterations of the update function (printing to console), then exits. | ||
|
||
## Example 1 - API Loading (example_1.c) | ||
Demonstrates: | ||
* loading APIs | ||
* hot reloading | ||
|
||
## Example 2 - UI Library (example_2.c) | ||
Demonstrates: | ||
* loading APIs | ||
* hot reloading | ||
* loading extensions | ||
* UI library | ||
|
||
## Example 3 - 3D Debug Drawing (example_3.c) | ||
* loading APIs | ||
* hot reloading | ||
* loading extensions | ||
* 3D debug drawing extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
example_0.c | ||
- demonstrates minimal app | ||
*/ | ||
|
||
/* | ||
Index of this file: | ||
// [SECTION] includes | ||
// [SECTION] pl_app_load | ||
// [SECTION] pl_app_shutdown | ||
// [SECTION] pl_app_resize | ||
// [SECTION] pl_app_update | ||
*/ | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] includes | ||
//----------------------------------------------------------------------------- | ||
|
||
#include <stdio.h> | ||
#include "pilotlight.h" | ||
#include "pl_ui.h" | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_load | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void* | ||
pl_app_load(plApiRegistryI* ptApiRegistry, void* pAppData) | ||
{ | ||
|
||
// NOTE: on first load, "pAppData" will be NULL | ||
|
||
// retrieve the data registry API, this is the API used for sharing data | ||
// between extensions & the runtime | ||
const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); | ||
|
||
// retrieve the UI context (provided by the runtime) and | ||
// set it (required to use plIO for "talking" with runtime) | ||
plUiContext* ptUIContext = ptDataRegistry->get_data("context"); | ||
pl_set_context(ptUIContext); | ||
|
||
// return optional application memory | ||
return NULL; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_shutdown | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_shutdown(void* pAppData) | ||
{ | ||
printf("shutting down\n"); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_resize | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_resize(void* pAppData) | ||
{ | ||
// NOTE: this function is not used here since this example doesn't have a window | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_update | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_update(void* pAppData) | ||
{ | ||
|
||
pl_new_frame(); // must be called once at the beginning of a frame | ||
|
||
static int iIteration = 0; | ||
|
||
printf("iteration: %d\n", iIteration++); | ||
|
||
// shutdown main event loop after 50 iterations | ||
if(iIteration == 50) | ||
{ | ||
plIO* ptIO = pl_get_io(); | ||
ptIO->bRunning = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
example_1.c | ||
- demonstrates loading APIs | ||
- demonstrates hot reloading | ||
*/ | ||
|
||
/* | ||
Index of this file: | ||
// [SECTION] includes | ||
// [SECTION] structs | ||
// [SECTION] apis | ||
// [SECTION] pl_app_load | ||
// [SECTION] pl_app_shutdown | ||
// [SECTION] pl_app_resize | ||
// [SECTION] pl_app_update | ||
*/ | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] includes | ||
//----------------------------------------------------------------------------- | ||
|
||
#include <stdio.h> | ||
#include <string.h> // memset | ||
#include "pilotlight.h" | ||
#include "pl_ui.h" | ||
#include "pl_os.h" // window api | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] structs | ||
//----------------------------------------------------------------------------- | ||
|
||
typedef struct _plAppData | ||
{ | ||
plWindow* ptWindow; | ||
} plAppData; | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] apis | ||
//----------------------------------------------------------------------------- | ||
|
||
const plWindowI* gptWindows = NULL; | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_load | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void* | ||
pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) | ||
{ | ||
// NOTE: on first load, "pAppData" will be NULL but on reloads | ||
// it will be the value returned from this function | ||
|
||
// retrieve the data registry API, this is the API used for sharing data | ||
// between extensions & the runtime | ||
const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); | ||
|
||
// retrieve the UI context (provided by the runtime) and | ||
// set it (required to use plIO for "talking" with runtime & keyboard/mouse input) | ||
plUiContext* ptUIContext = ptDataRegistry->get_data("context"); | ||
pl_set_context(ptUIContext); | ||
|
||
// if "ptAppData" is a valid pointer, then this function is being called | ||
// during a hot reload. | ||
if(ptAppData) | ||
{ | ||
printf("Hot reload!\n"); | ||
|
||
// re-retrieve the windows API since we are now in | ||
// a different dll/so | ||
gptWindows = ptApiRegistry->first(PL_API_WINDOW); | ||
|
||
// return the same memory again | ||
return ptAppData; | ||
} | ||
|
||
// this path is taken only during first load, so we | ||
// allocate app memory here | ||
ptAppData = malloc(sizeof(plAppData)); | ||
memset(ptAppData, 0, sizeof(plAppData)); | ||
|
||
// load required apis (NULL if not available) | ||
gptWindows = ptApiRegistry->first(PL_API_WINDOW); | ||
|
||
// use window API to create a window | ||
const plWindowDesc tWindowDesc = { | ||
.pcName = "Example 1", | ||
.iXPos = 200, | ||
.iYPos = 200, | ||
.uWidth = 600, | ||
.uHeight = 600, | ||
}; | ||
ptAppData->ptWindow = gptWindows->create_window(&tWindowDesc); | ||
|
||
// return app memory | ||
return ptAppData; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_shutdown | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_shutdown(plAppData* ptAppData) | ||
{ | ||
// perform any cleanup here | ||
gptWindows->destroy_window(ptAppData->ptWindow); | ||
|
||
// free app memory | ||
free(ptAppData); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_resize | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_resize(plAppData* ptAppData) | ||
{ | ||
// perform any operations required during a window resize | ||
plIO* ptIO = pl_get_io(); | ||
printf("resize to %d, %d\n", (int)ptIO->afMainViewportSize[0], (int)ptIO->afMainViewportSize[1]); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// [SECTION] pl_app_update | ||
//----------------------------------------------------------------------------- | ||
|
||
PL_EXPORT void | ||
pl_app_update(plAppData* ptAppData) | ||
{ | ||
|
||
pl_new_frame(); // must be called once at the beginning of a frame | ||
|
||
// check for key press | ||
if(pl_is_key_pressed(PL_KEY_P, true)) | ||
{ | ||
printf("P key pressed!\n"); | ||
} | ||
|
||
} |
Oops, something went wrong.