Commit ae6c8020 authored by Matej Vašek's avatar Matej Vašek
Browse files

feat: Update to latest engine version, use new input system

parent 3063b37d
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28 FATAL_ERROR)

project(age_app_template)

@@ -34,7 +34,7 @@ endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(SDL2 CONFIG REQUIRED)
find_package(SDL3 CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(Boost REQUIRED)
@@ -55,12 +55,11 @@ else()
endif()

set(AGE_3RD_PARTY_LIBRARIES_TO_LINK_WITH
    $<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
    $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
        $<TARGET_NAME_IF_EXISTS:SDL3::SDL3main>
        $<IF:$<TARGET_EXISTS:SDL3::SDL3>,SDL3::SDL3,SDL3::SDL3-static>
        ${OPENGL_LIBRARIES}
        glad::glad
        ${AGE_MATH_LIBRARY_TO_LINK_WITH}
    ${Boost_LIBRARIES}
)

set(AGE_TESTING_LIBRARY_TO_LINK_WITH
+1312 −974

File changed.

Preview size limit exceeded, changes collapsed.

+236 −218

File changed.

Preview size limit exceeded, changes collapsed.

+106 −47
Original line number Diff line number Diff line
@@ -4,12 +4,17 @@
let updaters = i"/osi/runners/updaters";
let camera_frame = i"/game/camera/frame";
let camera_system = i"/gfx/camera_system.lib";
let mouse = i"/osi/mouse"; 
let keyboard = i"/osi/keyboard"; 
let input_system = i"/osi/input_system.lib";
let window = i"/osi/window";
let timer = i"/osi/timer";
let math = i"/game/math.lib";

let allow_movement_action = i"";
let rotate_camera_action = i"";
let zoom_camera_action = i"";
let move_camera_action = i"";


# Event executed when content of the sender item is on_content_changed
# In our case it's executed after script reload
fn on_content_changed(sender: item)
@@ -38,6 +43,82 @@ fn init_updater()

    let folder = camera_system.default_camera_folder();
    camera_system.set_frame(folder, camera_frame);

    allow_movement_action = input_system.create_action_float("allow_movement",
        [
            { "type": "osi::InputBinding", "args": [ "gamepad", i"/osi/input/device_types/gamepad/button_south", [] ] },
            { "type": "osi::InputBinding", "args": [ "pointer",   i"/osi/input/device_types/pointer/press", [
                { "type": "osi::MultiPressProcessor", "args": [ "double_click", 2, 0.0, "hold", 0.0 ] }
            ]]}
        ],
        []
    );

    rotate_camera_action = input_system.create_action_vec2("rotate_camera",
        [
            { "type": "osi::InputBinding", "args": [ "pointer", i"/osi/input/device_types/pointer/delta", [
                { "type": "osi::ScaleProcessor", "args": [ 0.0005, "radian_per_dpi" ] }
            ]]},
            { "type": "osi::InputBinding", "args": [ "gamepad", i"/osi/input/device_types/gamepad/right_stick", [
                { "type": "osi::RepeatProcessor", "args": [ "repeat", true ] }
            ]]}
        ],
        [
            { "type": "osi::ScaleProcessor", "args": [ 3.0, "rotate_speed" ] }
        ]
    );

    zoom_camera_action = input_system.create_action_float("zoom_camera",
        [
            { "type": "osi::InputBinding", "args": [ "pointer", i"/osi/input/device_types/mouse/scroll/y", []] },
            { "type": "osi::InputBindingComposite", "args": [ "gamepad",
                i"/osi/input/device_types/gamepad/left_shoulder",
                i"/osi/input/device_types/gamepad/right_shoulder",
                []
            ]}
        ],
        [
            { "type": "osi::InvertProcessor", "args": ["invert_zoom"] },
            { "type": "osi::ScaleProcessor", "args": [ 0.75, "zoom_speed" ] }
        ]
    );

    move_camera_action = input_system.create_action_vec3("move_camera",
        [
            { "type": "osi::InputBindingComposite", "args":
                [
                    "WASDQE",
                    i"/osi/input/device_types/keyboard/key_controls/a",
                    i"/osi/input/device_types/keyboard/key_controls/d",
                    i"/osi/input/device_types/keyboard/key_controls/q",
                    i"/osi/input/device_types/keyboard/key_controls/e",
                    i"/osi/input/device_types/keyboard/key_controls/w",
                    i"/osi/input/device_types/keyboard/key_controls/s",
                    []
                ]
            },
            {
                "type": "osi::InputBindingComposite", "args":
                [
                    "gamepad",
                    i"/osi/input/device_types/gamepad/left_stick/left",
                    i"/osi/input/device_types/gamepad/left_stick/right",
                    i"/osi/input/device_types/gamepad/left_trigger",
                    i"/osi/input/device_types/gamepad/right_trigger",
                    i"/osi/input/device_types/gamepad/left_stick/up",
                    i"/osi/input/device_types/gamepad/left_stick/down",
                    []
                ]
            }
        ],
        [
            { "type": "osi::ScaleProcessor", "args": [ 5.0, "move_speed" ] }
        ]
    );


    rotate_camera_action.performed().subscribe(self, "rotate_camera");
    zoom_camera_action.performed().subscribe(self, "zoom_camera");
}

fn release()
@@ -45,51 +126,29 @@ fn release()
    updaters.find("game").erase(self_name() + ".link");
}

# Called once per frame
fn next_round()
fn rotate_camera(input_ctx: object)
{
    # Checks if the MouseRight button is pressed
    if mouse.down().contains("MouseRight")
    if (allow_movement_action.phase() == "performed")
    {
        let linear_speed = 5.0;
        let rotation_speed_mult = 5.0;
        let mouse_angle = 
             (rotation_speed_mult / camera_system.default_camera().near()) *
             (vec2(mouse.pos_delta()) * window.pixel_size_in_meters());

        # Gets camera_basis using the context items and their methods from reflection
        let camera_basis = math.quat_to_mat3x3(camera_frame.frame()["rotation"]);
        
        # Moves the camera frame on key presses
        if keyboard.down().contains("W") || keyboard.down().contains("Up")
        {
            camera_frame.move_origin((-linear_speed * timer.dt()) * math.get_col(camera_basis, 2));
        camera_frame.move_rotation(math.angle_axis(input_ctx["value"].x, -{ 0.0, 0.0, 1.0 }));
        camera_frame.move_rotation(math.angle_axis(input_ctx["value"].y, camera_frame.basis()[0]));
    }
        elif keyboard.down().contains("S") || keyboard.down().contains("Down")
        {
            camera_frame.move_origin((linear_speed * timer.dt()) * math.get_col(camera_basis, 2));
}

        if keyboard.down().contains("A") || keyboard.down().contains("Left")
fn zoom_camera(input_ctx: object)
{
            camera_frame.move_origin((-linear_speed * timer.dt()) * math.get_col(camera_basis, 0));
        }
        elif keyboard.down().contains("D") || keyboard.down().contains("Right")
    if (allow_movement_action.phase() == "performed")
    {
            camera_frame.move_origin((linear_speed * timer.dt()) * math.get_col(camera_basis, 0));
        camera_frame.move_origin(input_ctx["value"] * camera_frame.basis()[2]);
    }
}

        if keyboard.down().contains("Q")
# Called once per frame
fn next_round()
{
            camera_frame.move_origin((-linear_speed * timer.dt()) * math.get_col(camera_basis, 1));
        }
        elif keyboard.down().contains("E")
    # Move camera
    if (allow_movement_action.phase() == "performed")
    {
            camera_frame.move_origin((linear_speed * timer.dt()) * math.get_col(camera_basis, 1));
        }

        # Rotates the camera frame
        camera_frame.move_rotation(math.agle_axis(-mouse_angle[1], math.get_col(camera_basis, 0)));
        camera_frame.move_rotation(math.agle_axis(-mouse_angle[0], { 0.0, 0.0, 1.0 }));
        camera_frame.move_origin(camera_frame.rotation() * (timer.dt() * move_camera_action.value()));
    }
}
+4 −0
Original line number Diff line number Diff line
set(AGE_LIBRARIES_TO_USE
    com
    gfx
    anim
    phx
    lfs
    math
    audio
    osi
    net
    script
    utils
    )
Loading