2#include <SDL2/SDL_events.h>
3#include <SDL2/SDL_mouse.h>
4#include <SDL2/SDL_render.h>
5#include <SDL2/SDL_scancode.h>
6#include <SDL2/SDL_timer.h>
7#include <SDL2/SDL_video.h>
65 if (tb_idx != -1 && menu_idx != -1)
80 if (ui_element != -1 && menu_idx != -1)
110 if (event.type == SDL_QUIT)
running = 0;
116 if (event.type == SDL_MOUSEBUTTONUP)
121 if (event.type == SDL_MOUSEBUTTONDOWN)
128 vec3 inv_dir = {1.0f/dir.
x, 1.0f/dir.
y, 1.0f/dir.
z};
136 const float light_size = 0.5f;
137 float closest_light_dist = INFINITY;
138 int closest_light = -1;
139 float closest_rprobe_dist = INFINITY;
140 int closest_rprobe = -1;
143 float closest_emitter_dist = INFINITY;
144 int closest_emitter = -1;
146 float closest_aportal_dist = INFINITY;
147 int closest_aportal = -1;
150 float closest_lprobe_volume_dist = INFINITY;
151 int closest_lprobe_volume = -1;
154 float closest_aprobe_volume_dist = INFINITY;
155 int closest_aprobe_volume = -1;
198 Light * l = &lights[i];
201 aabb.
extents = (
vec3){light_size, light_size, light_size};
207 if (closest_light_dist > dist)
209 closest_light_dist = dist;
217 if (closest_light != -1)
234 if (closest_lprobe_volume_dist > dist)
236 closest_lprobe_volume_dist = dist;
237 closest_lprobe_volume = i;
241 if (closest_lprobe_volume != -1)
260 if (closest_rprobe_dist > dist)
262 closest_rprobe_dist = dist;
269 if (closest_rprobe != -1)
294 if (closest_aprobe_volume_dist > dist)
296 closest_aprobe_volume_dist = dist;
297 closest_aprobe_volume = i;
301 if (closest_aprobe_volume != -1)
323 if (closest_aportal_dist > dist)
325 closest_aportal_dist = dist;
330 if (closest_aportal != -1)
344 const float emitter_size = 0.5f;
350 aabb.
extents = (
vec3){emitter_size, emitter_size, emitter_size };
356 if (closest_emitter_dist > dist)
358 closest_emitter_dist = dist;
363 if (closest_emitter != -1)
385 if (event.type == SDL_MOUSEMOTION && SDL_GetRelativeMouseMode()) {
387 int dx =
event.motion.xrel;
388 int dy =
event.motion.yrel;
390 float sensitivity = 0.0012f;
391 cam.
yaw -= dx * sensitivity;
395 float max_pitch = (
M_PI / 2.0f);
396 float min_pitch = -(
M_PI / 2.0f) + 0.01f;
398 SDL_clamp(
cam.
pitch, min_pitch, max_pitch);
412 ( SDL_Window **
window, SDL_Event * event_queue,
int * event_queue_count, SDL_Event * sdl_queue,
int * sdl_queue_count,
float physics_dt)
420 bool accept_toggle_input =
false;
424 accept_toggle_input =
true;
430 Uint32 buttons = SDL_GetMouseState(NULL, NULL);
431 bool lmouse_down = buttons & SDL_BUTTON(SDL_BUTTON_LEFT);
434 if (!SDL_GetRelativeMouseMode()) {
439 while (SDL_PollEvent(&event)) {
442 event_queue[(*event_queue_count)++] = event;
445 sdl_queue[(*sdl_queue_count)++] = event;
449 bool move_to_spawn =
false;
451 const Uint8 *keystates = SDL_GetKeyboardState(NULL);
455 if (keystates[SDL_SCANCODE_ESCAPE])
running = 0;
456 if (accept_toggle_input)
459 if (keystates[SDL_SCANCODE_F1])
464 if (keystates[SDL_SCANCODE_F2])
469 if (keystates[SDL_SCANCODE_F3])
474 if (keystates[SDL_SCANCODE_F4])
479 if (keystates[SDL_SCANCODE_F5])
484 if (keystates[SDL_SCANCODE_F6])
489 if (keystates[SDL_SCANCODE_F7])
494 if (keystates[SDL_SCANCODE_F8])
505 if (keystates[SDL_SCANCODE_W]) move_dir.
x += 1.0f;
506 if (keystates[SDL_SCANCODE_S]) move_dir.
x -= 1.0f;
507 if (keystates[SDL_SCANCODE_A]) move_dir.
y += 1.0f;
508 if (keystates[SDL_SCANCODE_D]) move_dir.
y -= 1.0f;
509 if (keystates[SDL_SCANCODE_Q])
515 if (accept_toggle_input)
518 if (keystates[SDL_SCANCODE_T])
524 if (keystates[SDL_SCANCODE_U])
538 if (keystates[SDL_SCANCODE_R])
545 move_to_spawn =
true;
548 if (keystates[SDL_SCANCODE_C])
553 if (keystates[SDL_SCANCODE_V])
558 if (keystates[SDL_SCANCODE_P]) {
560 SDL_SetWindowGrab(*
window, SDL_FALSE);
561 SDL_SetRelativeMouseMode(SDL_FALSE);
567 if (keystates[SDL_SCANCODE_O]) {
569 SDL_SetWindowGrab(*
window, SDL_TRUE);
570 SDL_SetRelativeMouseMode(SDL_TRUE);
574 if (keystates[SDL_SCANCODE_N]) {
579 if (keystates[SDL_SCANCODE_M]) {
597 if (keystates[SDL_SCANCODE_LSHIFT])
610 if (move_to_spawn)
return;
RayHit raycast_scene(vec3 start, vec3 dir, float initial_t, bool check_normal)
Raycasts through the scene and finds closest intersection to meshes.
bool ray_intersects_obb_with_point(OBB obb, vec3 origin, vec3 dir, vec3 *intersection_point)
Checks if a ray intersects an obb and outputs an intersection point.
bool ray_intersects_aabb_with_point(AABB aabb, vec3 origin, vec3 dir, vec3 inv_dir, vec3 *intersection_point)
Checks if a ray intersects an aabb and outputs an intersection point.
Acceleration structure generation and how we traverse them.
Audio probe baking, portal creation, probe volumes, and emitter functions.
void reset_skeleton(Skeleton *s, vec3 pos)
Resets a skeleton to be relative to a new position.
void update_skeleton(Skeleton *s, Camera *cam, vec3 vel)
Moves feet, then solves a skeleton's leg IKs and updates the springs accordingly.
void resolve_collisions(Camera *cam)
Resolves collisions between camera and geometry, uses player.
void apply_velocity(Camera *cam, vec3 move_dir, float dt)
Applies no-clip mode velocity to player with no gravity applied.
void update_body_from_legs(LegIK *left_leg, LegIK *right_leg, vec3 intended_vel, float dt)
Calculates velocity based on leg positions and integrates them into the player.
Camera cam
This is currently the player cam.
The debug editor UI for the engine.
Engine specific types and defines.
#define MAX_SDL_EVENTS
Max amount of events to poll in one render step.
Spring neck
Neck Spring (target based on pelvis).
vec3 pos
Currently anchors the Skeleton.
AABB aabb
Bounding box of area.
#define MAX_NUKLEAR_EVENTS
Max amount of events to poll in one render step.
bool on_ground
If the camera is on the ground.
bool noclip
If collision is enabled.
Vector mesh_nodes
MeshNodes.
SceneData scene_data
SceneData that is more-so scene specific.
Skeleton skeleton
Player Skeleton.
PhysicsComponent * pc
PhysicsComponent in PHYSICS_COMPONENTS.
Vector audio_portals
AudioPortals.
LegIK right_leg
Right leg.
bool sprinting
Currently unused flag for sprinting.
float neck_height
Height from ground to neck.
@ SELMODE_TEXTBOX
TextBox.
@ SELMODE_ASSETINSTANCE
AssetInstance.
@ SELMODE_RPROBE
ReflectionProbe.
@ SELMODE_APV
Audio ProbeVolume (APV).
@ SELMODE_LPV
Lighting ProbeVolume (LPV).
@ SELMODE_UIELEMENT
UIElement.
@ SELMODE_AEM
AudioEmitter.
@ SELMODE_APORTAL
AudioPortal.
vec3 rotation
Current rotation of the spring.
Globals GLOBALS
Engine Globals.
bool keyboard_locked
If the keyboard is unlocked to register text events in the editor UI.
Vector reflection_probes
ReflectionProbes in the scene.
Vector lighting_probe_volumes
All of the lighting probe volumes, regardless of if they have been loaded yet.
Vector audio_probe_volumes
All of the AudioProbe% volumes, regardless of if they have been loaded yet.
size_t material
The Material.
Camera * cam
Player Camera.
bool noclip
Enables flying (but not collisions).
vec4 cam_pos
The position of the Camera (padded).
ReflectionProbes used for parallax corrected cubemaps.
Sections of Meshes that are divided based on Material for batching and DrawCommand ordering purposes.
Functions that modify TextBoxes and load Fonts.
OBB obb
The OBB that defines the size.
The ProbeVolumes for APVs and LPVs, controlled by OBBs.
vec3 pos
The position of the AudioEmitter .
vec3 pos
The position of the AudioPortal.
#define MAX_AUDIO_EMITTERS
The maximum amount of AudioEmitters.
An AudioEmitter that plays audio possibily from a certain position or at a certain time.
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
int selected_lighting_probe_volume_id
int selected_asset_instance_id
int selected_audio_probe_volume_id
int selected_audio_emitter_id
bool wireframe_toggled
Shows wireframes around many structures: Lights, ReflectionProbes, AudioProbes, AudioPortals,...
int selected_ui_element_id
bool asset_instance_menu_open
int selected_audio_portal_id
int selected_material_mn_id
const char menu_names[][256]
The array for all editor menu names (to avoid Nuklear hashing problems).
void perform_newest_redo()
Performs top-most Redo (Undo->next) and moves pointers upward.
void perform_newest_undo()
Performs top-most Undo and moves the top-most pointer to the previous.
void toggle_performance_overlay()
Toggles the performance overlay menu: PERFORMANCE_OVERLAY_MENU.
#define EDITOR_APORTAL_SIZE
vec3 old_vel
Last step's velocity.
vec3 pos
Position of light.
int mesh
The Mesh it references.
int asset_instance
The AssetInstance it belongs to.
The CPU side structure for Lights.
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
TextBox text_boxes[1024]
The TextBoxes.
UIElement elements[1024]
The UIElements.
vec2 translation
X and Y coords where Y+ is down.
vec2 translation
Where to place the center of the TextBox on the GPU.
int get_ui_element_from_coords(vec2 pos, int *menu_idx)
Finds a UIElement based on a screen position.
void handle_ui_event(SDL_Event event, int mouse_x, int mouse_y)
Handles an incoming UI event.
vec2 screenspace_to_ui(vec2 pos)
Transfers a position to local UI space by multiplying it by a ratio of the two resolutions.
int get_text_box_from_coords(vec2 pos, int *menu_idx)
Finds a TextBox based on a screen position.
A structure holding a Font ID and text to be rendered and transformed with its properties.
UIElements that are contained within a UIMenu that may receive events, be contained within UIContaine...
Important globals for the entire engine and initialization functions that are mainly called on engine...
Vector submeshes
The SubMeshes split via Materials.
A Mesh with geometry data that is either initialized as static or dynamic and split into SubMeshes.
Saves and loads various files that store engine data.
int running
The variable that tracks if we need to exit main().
AudioEmitter AUDIO_EMITTERS[1024]
struct nk_context * NK_CTX
Nuklear context handle used for Editor UI.
EditorSettings EDITOR_SETTINGS
float dt
The 1.0f/60 simulation timestep.
vec3 spawn_point
Spawn point.
vec3 CAM_POS
Shorthand variable for the camera position.
int LMB_HELD
If the left mouse button is held.
Player player
The Player data.
vec3 vec3_scale(vec3 a, float b)
vec3 vec3_sub(vec3 a, vec3 b)
vec3 vec3_add(vec3 a, vec3 b)
float vec3_length(vec3 v)
Nodes for the acceleration structures of BVHs.
void SHADERS_INIT()
Deletes and then recompiles and links all engine shaders.
Initialization for ShaderPrograms.
The standalone UI library that controls text rendering, ui rendering, and events.
void calculate_aabb_bounds(AABB *aabb)
#define CAST_VEC(vec, type)
float wrap_angle_pi(float angle)
vec3 vec4_to_vec3(vec4 v)