Commit Graph
6 Commits
Author SHA1 Message Date
waozi 2423b97a0c scene/property/signal/transform: drop the Kry/Kryon prefix from the public API
KryScene->Scene, KryNode->Node, KryonProperty*->Property*,
KrySignal*->Signal*, KryTransform2D->Transform2D, and the
KRY_NODE_/KRY_SCENE_/KRYON_PROPERTY_/KRY_SIGNAL_ enum and macro
families to NODE_/SCENE_/PROPERTY_/SIGNAL_. Header guards keep their
original names (internal). The lowercase kry_ module namespaces
(kry_json, kry_term, ...) and the raymath-shadowing helpers
(KryVector2*, KryClamp, KryLerp) stay prefixed: their unprefixed names
collide with the raylib API surface kryon tracks.
2026-08-16 20:35:15 -03:00
waozi 1757df0a5e Phase 6: TileMap + AudioSource nodes (all 12 Game2D kinds now implemented)
TileMap (src/scene/node_tilemap.c):
- Renders a grid of tile IDs from a single tileset texture via DrawTexturePro
  (raylib batches internally by texture). Tile IDs are 1-based; 0 = empty.
- TileLayer is a usage convention over TileMap (layered z-depth rendering),
  not a separate runtime kind.
- Props: asset_path, tile size, tiles_per_row, map_w/h, world tile size,
  tiles pointer (caller-owned), tint.

AudioSource (src/scene/node_audio_source.c):
- Wraps raylib's LoadSound/PlaySound (SFX) and LoadMusicStream/
  PlayMusicStream/UpdateMusicStream (streaming music). Loads lazily on first
  play via KryAudioSourcePlay; updates music each process tick; frees on
  destroy. KryAudioSourcePlay/Stop are public controls.
- Props: asset_path, kind (sound/music), volume, pitch, loop, play state;
  handle is a void* alloc sized by the impl (header stays free of raylib
  audio struct dependencies).

With this, all twelve Game2D node kinds that were inert stubs at the start of
this project (Scene/Node2D/Camera2D/Sprite2D/AnimatedSprite2D/TileMap/
TileLayer/CollisionShape2D/Area2D/Body2D/Timer/AudioSource) have working
runtime implementations.

Example: examples/24_tilemap.kry (a 10x6 tile grid cycling 3 tile IDs).
2026-08-12 09:33:14 -05:00
waozi 5dd8d3a78b Phase 5: animation system (keyframe tracks, AnimationPlayer, AnimatedSprite2D)
Runtime:
- include/kry_animation.h + src/scene/kry_animation.c: animation = ordered
  tracks of (time,value) keyframes; linear/step interpolation; hold-before/
  hold-after clamping; KryAnimationApply samples at time t and writes position/
  rotation/scale components onto target nodes via KryNodeGet
- src/scene/node_animation_player.c: AnimationPlayer node (registered on the
  KRY_NODE_TIMER slot) advances the current animation each process tick and
  applies it; on non-loop finish emits an 'animation_finished' signal via the
  Phase 2 signal bus. Loop + play/pause state in AnimationPlayerProps
- src/scene/node_animated_sprite2d.c: AnimatedSprite2D cycles frames of a grid
  sprite sheet at a given fps, drawing the current sub-rect via the shared
  picture texture cache
- include/node2d_props.h: AnimationPlayerProps (holds up to 4 animations) +
  AnimatedSprite2DProps + allocators

Example + test:
- examples/23_animation.kry: a Sprite2D whose y position is keyframe-animated
- tests/animation_test.c: linear/step interpolation, hold clamps, and
  KryAnimationApply writing position.x/rotation; wired into 'make test'
2026-08-12 09:30:19 -05:00
waozi e8eb0dd789 Phase 4: Box2D v3 physics integration
Vendor Box2D v3.1.1 (erincatto/box2d) as a submodule; wired into
mk/vendor.mk (CMake static archive, samples/tests/benchmarks off) and
CPPFLAGS_BASE (-Ivendor/box2d/include). libkryon.a now depends on it.

Runtime:
- include/scene_tree.h: KryScene carries an opaque b2WorldId + physics_enabled;
  KryScenePhysicsCreate/Destroy build/tear down the world; KryScenePhysicsTick
  steps it via a function pointer installed by physics_world.c (keeps
  scene_tree.c free of a box2d.h dependency)
- src/scene/physics_world.c: owns the only #include <box2d/box2d.h>; world
  creation/step, body+shape creation helpers, transform sync
- src/scene/node_body2d.c: static/kinematic/dynamic body; creates b2Body on
  ready, syncs transform on physics_process, debug-draws an outline
- src/scene/node_collision_shape2d.c: box/circle shape attached to the nearest
  Body2D ancestor on ready
- src/scene/node_area2d.c: trigger volume (sensor) node
- include/node2d_props.h: Body2DProps/CollisionShape2DProps/Area2DProps +
  allocators
- src/scene/scene_physics_internal.h: private bridge for Box2D-typed helpers

Example: examples/22_physics.kry (a dynamic box falling onto a static ground).
2026-08-12 09:06:23 -05:00
waozi 7358262243 Implement built-in scene nodes: Node2D, Camera2D, Sprite2D
- src/scene/node_2d.c: base transform node (no-op lifecycle, groups children)
- src/scene/node_camera2d.c: claims active_camera on ready when active; freed on destroy
- src/scene/node_sprite2d.c: world-space textured sprite via shared KryLoadPictureTexture
- src/scene/scene_builtins.c: KrySceneRegisterBuiltins + KryCamera2DPropsAlloc /
  KrySprite2DPropsAlloc helpers for scene builders
- include/node2d_props.h: declare the props alloc helpers
2026-08-11 03:22:26 -05:00
waozi 2bb8640279 Add retained scene tree foundation and rename UI Sprite to Picture
- include/kry_math.h: Vector2 math and KryTransform2D (compose/point/camera)
- include/scene_tree.h + src/scene/scene_tree.c: KryScene/KryNode retained
  node tree with array arena, parent/child links, world-transform update,
  lifecycle vtable (ready/process/physics_process/draw), KrySceneTick/
  PhysicsTick/Draw driver
- include/node2d_props.h: Camera2DProps, Sprite2DProps
- Rename UI Sprite widget to Picture (raylib owns Image as a struct):
  ui_sprite.h -> ui_picture.h, SpriteProps -> PictureProps,
  UISpriteFit -> UIPictureFit, UI_SPRITE_FIT_* -> UI_PICTURE_FIT_*,
  Sprite() -> Picture(); extract shared texture cache to
  src/ui/ui_picture_cache.c (KryLoadPictureTexture, KryPictureFitRect)
  shared by the Picture widget and the upcoming Sprite2D scene node
- Migrate example, docs, node registry to the Picture name
2026-08-11 03:11:34 -05:00