Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to pocketpy 2.0 #232

Merged
merged 54 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1326137
Initial commit.
Chukobyte Sep 18, 2024
dac3c3b
A bunch of changes.
Chukobyte Sep 18, 2024
5383d9e
Updates.
Chukobyte Sep 18, 2024
da9e08f
Clean.
Chukobyte Sep 18, 2024
bbc161d
Clean.
Chukobyte Sep 18, 2024
c12b9d7
Testing out stuff.
Chukobyte Sep 22, 2024
d1f0475
Test.
Chukobyte Sep 27, 2024
db55791
Clean.
Chukobyte Sep 27, 2024
cd412c7
Test.
Chukobyte Sep 27, 2024
62ffda0
Clean up>
Chukobyte Sep 27, 2024
b2105cd
Clean up.
Chukobyte Sep 27, 2024
2011965
Starting to implement python api.
Chukobyte Sep 28, 2024
73feba0
Adding pkpy tuple example.
Chukobyte Sep 28, 2024
4e0c134
Finished untested shader api.
Chukobyte Sep 28, 2024
c033891
More api.
Chukobyte Sep 29, 2024
be7b3f3
Clean.
Chukobyte Sep 29, 2024
c1d779c
Adding separate file for instance cache.
Chukobyte Oct 1, 2024
ecaa66e
More pkpy api stuff.
Chukobyte Oct 1, 2024
63b92f4
More api stuff.
Chukobyte Oct 2, 2024
9df855b
More things.
Chukobyte Oct 2, 2024
e92afe7
Update.
Chukobyte Oct 2, 2024
fbc55e9
Updates.
Chukobyte Oct 2, 2024
1e13038
Update.
Chukobyte Oct 2, 2024
7b6cd30
Have rough implementations of api calls except for nodes.
Chukobyte Oct 2, 2024
c5221b0
Using list instead of tuple to return collisions.
Chukobyte Oct 3, 2024
4f44840
Starting on nodes.
Chukobyte Oct 3, 2024
b356077
Checking arg types.
Chukobyte Oct 3, 2024
ec6f3ac
Update.
Chukobyte Oct 5, 2024
f937466
Updates.
Chukobyte Oct 5, 2024
650b011
Clean.
Chukobyte Oct 5, 2024
a87a8c1
Updates.
Chukobyte Oct 6, 2024
6ea5a7d
Updates.
Chukobyte Oct 6, 2024
43d764c
Rough implementation of all api functions except for anim sprite add …
Chukobyte Oct 6, 2024
a1ea39f
Update.
Chukobyte Oct 6, 2024
cc78ea0
Deleted stuff.
Chukobyte Oct 6, 2024
74a3712
Updates.
Chukobyte Oct 6, 2024
23e1be0
Updates.
Chukobyte Oct 6, 2024
63e6962
Updates.
Chukobyte Oct 6, 2024
319f82c
Updates.
Chukobyte Oct 7, 2024
cfe61ff
Updates.
Chukobyte Oct 7, 2024
c910fe7
Updates.
Chukobyte Oct 7, 2024
7bb51a5
Updates.
Chukobyte Oct 7, 2024
192dec0
Clean up.
Chukobyte Oct 7, 2024
367a844
Updates.
Chukobyte Oct 7, 2024
90d85a8
Updates.
Chukobyte Oct 7, 2024
ebf5c5e
Update.
Chukobyte Oct 8, 2024
b49d116
Update.
Chukobyte Oct 8, 2024
c108661
Updates.
Chukobyte Oct 8, 2024
f9d2239
Clean.
Chukobyte Oct 8, 2024
de96e2f
More updates.
Chukobyte Oct 9, 2024
e2d1257
More tests.
Chukobyte Oct 10, 2024
5b6af7e
Updates.
Chukobyte Oct 10, 2024
8697da3
Updates.
Chukobyte Oct 10, 2024
1f09f6e
Updates.
Chukobyte Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (NOT TARGET seika)
FetchContent_Declare(
seika_content
GIT_REPOSITORY https://github.com/Chukobyte/seika.git
GIT_TAG v0.1.5
GIT_TAG v0.1.6
)
FetchContent_MakeAvailable(seika_content)
endif ()
Expand All @@ -20,9 +20,10 @@ if (NOT TARGET pocketpy)
FetchContent_Declare(
pocketpy_content
GIT_REPOSITORY https://github.com/blueloveTH/pocketpy.git
GIT_TAG v1.4.5
GIT_TAG v2.0.0
)
FetchContent_MakeAvailable(pocketpy_content)
target_include_directories(pocketpy PUBLIC ${pocketpy_content_SOURCE_DIR} ${pocketpy_content_SOURCE_DIR}/include)
endif ()

# https://github.com/DaveGamble/cJSON
Expand Down
230 changes: 78 additions & 152 deletions crescent_py_api/pocketpy/crescent.py

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions crescent_py_api/pocketpy/crescent_internal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple, Optional
from typing import Tuple, Optional, List


# Mock class for engine's internal c python module
Expand All @@ -20,8 +20,8 @@ def node_get_child(parent_entity_id: int, child_entity_name: str) -> Optional["N
return None


def node_get_children(entity_id: int) -> Tuple["Node", ...]:
return ()
def node_get_children(entity_id: int) -> List["Node"]:
return []


def node_get_parent(entity_id: int) -> Optional["Node"]:
Expand Down Expand Up @@ -163,7 +163,7 @@ def sprite_set_origin(entity_id: int, x: float, y: float) -> None:
pass


def sprite_get_shader_instance(entity_id: int) -> int:
def sprite_get_shader_instance(entity_id: int) -> Optional[int]:
return 0


Expand All @@ -185,7 +185,7 @@ def animated_sprite_set_current_animation_frame(entity_id: int, frame: int) -> N
pass


def animated_sprite_add_animation(entity_id: int, name: str, speed: float, does_loop: bool, frame_count: int, *args) -> None:
def animated_sprite_add_animation(entity_id: int, name: str, speed: int, does_loop: bool, frames: List["AnimationFrame"]) -> None:
pass


Expand Down Expand Up @@ -229,7 +229,7 @@ def animated_sprite_set_origin(entity_id: int, x: float, y: float) -> None:
pass


def animated_sprite_get_shader_instance(entity_id: int) -> int:
def animated_sprite_get_shader_instance(entity_id: int) -> Optional[int]:
return 0


Expand Down Expand Up @@ -673,11 +673,11 @@ def packed_scene_load(path: str) -> int:

# --- Collision Handler --- #

def collision_handler_process_collisions(entity_id: float) -> Tuple["Node", ...]:
def collision_handler_process_collisions(entity_id: float) -> List["Node"]:
return ()


def collision_handler_process_mouse_collisions(pos_offset_x: float, pos_offset_y: float, collision_size_w: float, collision_size_h: float) -> Tuple["Node", ...]:
def collision_handler_process_mouse_collisions(pos_offset_x: float, pos_offset_y: float, collision_size_w: float, collision_size_h: float) -> List["Node"]:
return ()


Expand Down
15 changes: 0 additions & 15 deletions crescent_py_api/pocketpy/crescent_internal_py.py

This file was deleted.

4 changes: 0 additions & 4 deletions crescent_py_api/pocketpy/utils/pkpy_header_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@ def generate_source_header_file(
output_path="../../../engine/src/core/scripting/python/pocketpy/cre_pkpy_api_source.h",
source_inputs=[
SourceInput(file_path="../crescent.py", macro_name="CRE_PKPY_CRESCENT_SOURCE"),
SourceInput(
file_path="../crescent_internal_py.py",
macro_name="CRE_PKPY_CRESCENT_INTERNAL_PY_SOURCE",
),
],
)
1 change: 1 addition & 0 deletions editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ endif ()
file(GLOB_RECURSE CRESCENT_EDITOR_SRC src/core/*.cpp src/core/*.h)
add_library(${PROJECT_NAME} STATIC ${CRESCENT_EDITOR_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../engine/src)

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_libraries(${PROJECT_NAME} PUBLIC imgui implot seika font_awesome nlohmann_json zip)
Expand Down
1 change: 1 addition & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ endif ()
file(GLOB_RECURSE CRESCENT_SRC src/core/*.c src/core/*.h)
add_library(${PROJECT_NAME} STATIC ${CRESCENT_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_libraries(${PROJECT_NAME} PUBLIC Ws2_32 seika cJSON pocketpy)
Expand Down
4 changes: 2 additions & 2 deletions engine/src/core/ecs/components/script_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ ScriptComponent* script_component_create(const char* path, const char* name) {
ScriptComponent* scriptComponent = SKA_MEM_ALLOCATE(ScriptComponent);
ska_strcpy(scriptComponent->classPath, path);
ska_strcpy(scriptComponent->className, name);
scriptComponent->contextType = ScriptContextType_NONE;
scriptComponent->contextType = CreScriptContextType_NONE;
return scriptComponent;
}

ScriptComponent* script_component_create_ex(const char* path, const char* name, ScriptContextType contextType) {
ScriptComponent* script_component_create_ex(const char* path, const char* name, CreScriptContextType contextType) {
ScriptComponent* scriptComponent = script_component_create(path, name);
scriptComponent->contextType = contextType;
return scriptComponent;
Expand Down
14 changes: 4 additions & 10 deletions engine/src/core/ecs/components/script_component.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#pragma once

#include "core/scripting/script_context.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ScriptContextType {
ScriptContextType_NONE = -1, // INVALID
ScriptContextType_PYTHON = 0,
ScriptContextType_NATIVE = 1, // C/C++

ScriptContextType_TOTAL_TYPES = 2
} ScriptContextType;

// TODO: Give a way for components to clean up themselves (e.g. call '[component_name]_component_delete' when deleted)
// TODO: (Part2) This way we can have less memory overhead by having flexibility for objects to clean themselves up
typedef struct ScriptComponent {
char classPath[96];
char className[32];
ScriptContextType contextType;
CreScriptContextType contextType;
} ScriptComponent;

ScriptComponent* script_component_create(const char* path, const char* name);
ScriptComponent* script_component_create_ex(const char* path, const char* name, ScriptContextType contextType);
ScriptComponent* script_component_create_ex(const char* path, const char* name, CreScriptContextType contextType);
void script_component_delete(ScriptComponent* scriptComponent);
ScriptComponent* script_component_copy(const ScriptComponent* scriptComponent);

Expand Down
6 changes: 3 additions & 3 deletions engine/src/core/ecs/ecs_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void cre_ecs_manager_initialize() {
cre_font_rendering_ec_system_create_and_register();
cre_parallax_ec_system_create_and_register();
cre_particle_ec_system_create_and_register();
cre_script_ec_system_create_and_register();
cre_tilemap_ec_system_create_and_register();
cre_script_ec_system_create_and_register();
}

void cre_ecs_manager_initialize_ex(SkaTexture* colorRectTexture, SkaTexture* particle2DSquareTexture) {
Expand All @@ -97,8 +97,8 @@ void cre_ecs_manager_initialize_ex(SkaTexture* colorRectTexture, SkaTexture* par
cre_font_rendering_ec_system_create_and_register();
cre_parallax_ec_system_create_and_register();
cre_particle_ec_system_create_and_register_ex(particle2DSquareTexture);
cre_script_ec_system_create_and_register();
cre_tilemap_ec_system_create_and_register();
cre_script_ec_system_create_and_register();
}

void cre_ecs_manager_enable_fps_display_entity(bool enabled, const char* fontUID, f32 positionX, f32 positionY) {
Expand All @@ -122,7 +122,7 @@ void cre_ecs_manager_enable_fps_display_entity(bool enabled, const char* fontUID
ska_ecs_component_manager_set_component(currentFpsEntity, TEXT_LABEL_COMPONENT_INDEX, textLabelComponent);
// Script Component
ScriptComponent* scriptComponent = script_component_create("main", "FpsDisplay");
scriptComponent->contextType = ScriptContextType_NATIVE;
scriptComponent->contextType = CreScriptContextType_NATIVE;
ska_ecs_component_manager_set_component(currentFpsEntity, SCRIPT_COMPONENT_INDEX, scriptComponent);
// Update systems
ska_ecs_system_update_entity_signature_with_systems(currentFpsEntity);
Expand Down
53 changes: 30 additions & 23 deletions engine/src/core/ecs/systems/script_ec_system.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "script_ec_system.h"

#include <seika/assert.h>
#include <seika/logger.h>
#include <seika/data_structures/hash_map.h>
#include <seika/ecs/ecs.h>
#include <seika/assert.h>

#include "../ecs_globals.h"
#include "../components/script_component.h"
#include "../../scene/scene_manager.h"
#include "../../scripting/script_context.h"
#include "../../scripting/python/pocketpy/cre_pkpy_script_context.h"
#include "../../scripting/native/native_script_context.h"
#include "../../scripting/native/internal_classes/fps_display_class.h"
#include "core/ecs/ecs_globals.h"
#include "core/ecs/components/script_component.h"
#include "core/scene/scene_manager.h"
#include "core/scripting/script_context.h"
#include "core/scripting/python/pocketpy/pkpy_script_context.h"
#include "core/scripting/native/native_script_context.h"

static void on_ec_system_registered(SkaECSSystem* system);
static void on_ec_system_destroyed(SkaECSSystem* system);
Expand All @@ -24,7 +24,7 @@ static void script_system_instance_update(SkaECSSystem* system, f32 deltaTime);
static void script_system_instance_fixed_update(SkaECSSystem* system, f32 deltaTime);
static void network_callback(SkaECSSystem* system, const char* message);

static CREScriptContext* scriptContexts[ScriptContextType_TOTAL_TYPES];
static CREScriptContext* scriptContexts[CreScriptContextType_TOTAL_TYPES];
static size_t scriptContextsCount = 0;

void cre_script_ec_system_create_and_register() {
Expand All @@ -44,29 +44,36 @@ void cre_script_ec_system_create_and_register() {
}

void on_ec_system_registered(SkaECSSystem* system) {
// Python Context
scriptContexts[ScriptContextType_PYTHON] = cre_pkpy_script_context_create();
scriptContextsCount++;
SKA_ASSERT(scriptContexts[ScriptContextType_PYTHON] != NULL);
// Native Context
scriptContexts[ScriptContextType_NATIVE] = cre_native_create_script_context();
scriptContextsCount++;
// Register internal classed
cre_native_class_register_new_class(fps_display_native_class_create_new());
CREScriptContextTemplate templates[8];
size_t templateCount = 0;

templates[templateCount++] = cre_pkpy_get_script_context_template();
templates[templateCount++] = cre_native_get_script_context_template();

for (size_t i = 0; i < templateCount; i++) {
const CREScriptContextTemplate* template = &templates[i];
if (scriptContexts[template->contextType] != NULL) {
ska_logger_warn("Attempted to override script context type '%d', ignoring!", template->contextType);
continue;
}
scriptContexts[template->contextType] = cre_script_context_create_from_template(template);
scriptContexts[template->contextType]->on_script_context_init(scriptContexts[template->contextType]);
scriptContextsCount++;
}
}

void on_ec_system_destroyed(SkaECSSystem* system) {
for (size_t i = 0; i < scriptContextsCount; i++) {
if (scriptContexts[i]->on_script_context_destroy != NULL) {
scriptContexts[i]->on_script_context_destroy();
if (scriptContexts[i]->on_script_context_finalize != NULL) {
scriptContexts[i]->on_script_context_finalize(scriptContexts[i]);
}
}
scriptContextsCount = 0;
}

void on_entity_registered(SkaECSSystem* system, SkaEntity entity) {
const ScriptComponent* scriptComponent = (ScriptComponent*)ska_ecs_component_manager_get_component(entity, SCRIPT_COMPONENT_INDEX);
SKA_ASSERT(scriptComponent->contextType != ScriptContextType_NONE);
SKA_ASSERT(scriptComponent->contextType != CreScriptContextType_NONE);
const CREScriptContext* scriptContext = scriptContexts[scriptComponent->contextType];
SKA_ASSERT(scriptContext != NULL);
SKA_ASSERT(scriptContext->on_create_instance != NULL);
Expand All @@ -80,7 +87,7 @@ void on_entity_unregistered(SkaECSSystem* system, SkaEntity entity) {

void on_entity_start(SkaECSSystem* system, SkaEntity entity) {
const ScriptComponent* scriptComponent = (ScriptComponent*)ska_ecs_component_manager_get_component(entity, SCRIPT_COMPONENT_INDEX);
SKA_ASSERT_FMT(scriptComponent->contextType != ScriptContextType_NONE, "Invalid context type '%d' for entity '%d'", scriptComponent->contextType, entity);
SKA_ASSERT_FMT(scriptComponent->contextType != CreScriptContextType_NONE, "Invalid context type '%d' for entity '%d'", scriptComponent->contextType, entity);
scriptContexts[scriptComponent->contextType]->on_start(entity);
}

Expand Down Expand Up @@ -127,5 +134,5 @@ void script_system_instance_fixed_update(SkaECSSystem* system, f32 deltaTime) {

void network_callback(SkaECSSystem* system, const char* message) {
// Hard coding python for now TODO: Keep an array of script contexts that contain this callback
scriptContexts[ScriptContextType_PYTHON]->on_network_callback(message);
scriptContexts[CreScriptContextType_PYTHON]->on_network_callback(message);
}
2 changes: 1 addition & 1 deletion engine/src/core/json/json_file_loader_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static void cre_json_script_create_or_set_default(JsonSceneNode* node, cJSON* co
json_get_string(componentJson, "class_path"),
json_get_string(componentJson, "class_name")
);
scriptComponent->contextType = ScriptContextType_PYTHON;
scriptComponent->contextType = CreScriptContextType_PYTHON;
node->components[SCRIPT_COMPONENT_INDEX] = scriptComponent;
} else {
// No override for scripts for now...
Expand Down
2 changes: 1 addition & 1 deletion engine/src/core/scene/scene_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ bool cre_scene_manager_has_entity_tree_node(SkaEntity entity) {
return ska_hash_map_has(entityToTreeNodeMap, &entity);
}

void cre_scene_manager_add_node_as_child(SkaEntity childEntity, SkaEntity parentEntity) {
void cre_scene_manager_add_node_as_child(SkaEntity parentEntity, SkaEntity childEntity) {
SceneTreeNode* parentNode = cre_scene_manager_get_entity_tree_node(parentEntity);
SceneTreeNode* node = cre_scene_manager_pop_staged_entity_tree_node(childEntity);
node->parent = parentNode;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/core/scene/scene_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ f32 cre_scene_manager_get_node_full_time_dilation(SkaEntity entity);
SkaEntity cre_scene_manager_get_entity_child_by_name(SkaEntity parent, const char* childName);
SceneTreeNode* cre_scene_manager_get_entity_tree_node(SkaEntity entity);
bool cre_scene_manager_has_entity_tree_node(SkaEntity entity);
void cre_scene_manager_add_node_as_child(SkaEntity childEntity, SkaEntity parentEntity);
void cre_scene_manager_add_node_as_child(SkaEntity parentEntity, SkaEntity childEntity);
EntityArray cre_scene_manager_get_self_and_parent_nodes(SkaEntity entity);
void cre_scene_manager_invalidate_time_dilation_nodes_with_children(SkaEntity entity);

Expand Down
Loading
Loading