|
SleakEngine 1.0.0
C++23 multi-backend game engine
|
Getting Started got a window on screen. This guide fills that window with real content: imported models, a controllable character, collision, keyboard input, on-screen UI, and a second scene to switch to.
Read it start to finish or jump to the section you need.
Sleak::ModelLoader::Load imports a model file through Assimp and returns the root of a Sleak::GameObject hierarchy, with meshes, materials, and (for rigged files) a skeleton and animation clips already attached. You own the returned root: add it to the scene and the scene takes over.
ModelLoadOptions also carries rotation, flipNormals, and flipWinding. Reach for the flip flags when a model imports inside out or with black faces: they are almost always an exporter handedness mismatch, not a shading bug.
Textures are cached per load, so a model that reuses one texture across twenty materials loads it once.
A rigged import gets a Sleak::AnimatorComponent. Extra clips from separate files attach to the same skeleton with ModelLoader::LoadAnimationsOnly, which is the standard workflow when your mesh and your animations ship as different files.
Play also takes an integer clip index, and GetClips() hands you the full list if you want to build a clip picker.
The camera is a Sleak::GameObject, so it can carry a collider and a rigidbody like anything else. That is how you get a first-person character that falls, lands, and cannot walk through walls.
Order matters here. AddObject is what registers the collider with the scene's Sleak::Physics::PhysicsWorld, walking the whole child hierarchy as it goes, so add the object after its components are attached.
Pick the body type to match how the object moves:
| Sleak::BodyType | Behavior |
|---|---|
| Static | Never moves. Infinite mass. Level geometry. |
| Kinematic | Moves under your control, pushes others, is not pushed. |
| Dynamic | Mass-based response, affected by its own gravity setting. |
FirstPersonController models Unreal's character movement: acceleration and braking on the ground, minimal air control, and a jump impulse. Tune it with SetMaxWalkSpeed, SetSprintSpeedMultiplier, SetJumpZVelocity, SetMaxAcceleration, SetBrakingDeceleration, SetGroundFriction, and SetAirControl. SetFlying(true) swaps to noclip-style free flight, which is useful while you are still building the level.
For a debug or spectator camera with no physics at all, use Sleak::FreeLookCameraController instead, as in Getting Started.
Anything with a collider joins the broadphase. Static geometry gets an AABB and a Static body:
ColliderComponent also constructs from a BoundingSphere, a BoundingCapsule, or straight from MeshData when you want the shape derived from the geometry.
Sleak::Physics::PhysicsWorld answers questions about the scene without you tracking objects yourself. Get it from the scene, then cast:
OverlapSphere, OverlapAABB, and SphereSweep round out the query set. Every one of them takes an optional layerMask, so pair it with ColliderComponent::SetLayer to keep, say, a bullet raycast from hitting trigger volumes.
Input arrives as events. Register a member function once, and the dispatcher calls it for every event of that type.
if_key_press(KEY__F) expands to a check on the local variable named e, so name your event parameter e. It ignores OS auto-repeat, which is what you want for a toggle. Use if_key_down when you want the repeat, and read e.GetKeyCode() directly for anything more involved.
Unregister what you register. Handlers outlive the scene otherwise, and the next event dispatched calls into freed memory. Do it in OnDeactivate or the destructor:
The event types you will use most are Sleak::Events::Input::KeyPressedEvent, KeyReleasedEvent, MouseMovedEvent, MouseButtonPressedEvent, and Sleak::Events::WindowResizeEvent. See Events and Input for the full hierarchy.
Sleak::UI is available from any scene update. It is immediate mode: you call it every frame, and there is no widget tree to maintain.
Widgets return true on the frame they change, which is why the pattern is always if (UI::Checkbox(...)) apply(...). Beyond text and buttons you get DragFloat, Combo, InputText, Selectable, ProgressBar, list boxes, child regions, style push and pop, and direct 2D drawing through DrawLine, DrawRect, DrawFilledRect, and DrawImage.
Never include imgui.h from your game. Dear ImGui is a private dependency of the engine target; if Sleak::UI is missing something you need, that wrapper is where it should be added.
Register every scene up front, then switch whenever you like:
When you switch scenes at runtime, and especially when you tear one down, flush the GPU first. Destroying resources the GPU is still reading from crashes the driver.
RemoveScene unloads and deletes the scene, and unloading destroys every object it owns.
Per-frame quality settings live on the Application and can be changed at any time, which makes them easy to wire straight into a settings panel:
Post-processing settings apply to the deferred path, which not every backend implements. Check first rather than assuming:
To ship a whole quality preset in one call, fill a Sleak::GraphicsConfig and pass it to Application::ApplyGraphicsConfig.