diff --git a/res/project/game.proj b/res/project/game.proj index 822e358..e4a0dad 100644 --- a/res/project/game.proj +++ b/res/project/game.proj @@ -25,5 +25,5 @@ "path": "scenes://SideScene.evsc" } ], - "activeScene": "SideScene" + "activeScene": "MainScene" } diff --git a/res/project/res/scenes/MainScene.evsc b/res/project/res/scenes/MainScene.evsc index 66c9317..cff684a 100644 --- a/res/project/res/scenes/MainScene.evsc +++ b/res/project/res/scenes/MainScene.evsc @@ -13,7 +13,7 @@ { "type": "CameraComponent", "view": "Perspective", - "fov": 120, + "fov": 60, "near": 0.001, "far": 1000, "aspectRatio": 1.3333 diff --git a/res/project/res/scenes/SideScene.evsc b/res/project/res/scenes/SideScene.evsc index dedd80d..a76faaf 100644 --- a/res/project/res/scenes/SideScene.evsc +++ b/res/project/res/scenes/SideScene.evsc @@ -40,8 +40,9 @@ "mass": 1.0, "restitution": 1.0, "collisionShape": { - "type": "Sphere", - "radius": 1.0 + "type": "Capsule", + "radius": 1.0, + "height": 2.0 } }, { @@ -79,6 +80,32 @@ } ] }, + { + "id": "Ceiling", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 15.0, -15.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "rigidbodyType": "Ghost", + "mass": 0.0, + "restitution": 0.0, + "collisionShape": { + "type": "Box", + "halfExtents": [10.0, 10.0, 10.0] + } + }, + { + "type": "ScriptComponent", + "script_name": "SideGhostController", + "script_path": "scripts://SideScene/ghost.lua" + } + ] + }, { "id": "Ground", "components": [ diff --git a/res/project/res/scripts/MainScene/camera.lua b/res/project/res/scripts/MainScene/camera.lua index 3e958b9..bff7af0 100644 --- a/res/project/res/scripts/MainScene/camera.lua +++ b/res/project/res/scripts/MainScene/camera.lua @@ -1,10 +1,20 @@ this.on_init = function() this.speed = 0.1 this.original_position = this.position + this.angles = Vec3:new() + this.mouse_sens = 0.01 + Input.lockCursor() +end + +this.on_update = function() + local deltaMouseMovement = Input.getDeltaMousePos() + this.angles.x = this.angles.x - deltaMouseMovement.y * this.mouse_sens + this.angles.y = this.angles.y - deltaMouseMovement.x * this.mouse_sens + this.eulerAngles = this.angles end this.on_fixedupdate = function() - if Input.getKeyDown(Input.KeyCode.Enter) then + if Input.getKeyJustPressed(Input.KeyCode.Enter) then gotoScene('SideScene') end diff --git a/res/project/res/scripts/SideScene/camera.lua b/res/project/res/scripts/SideScene/camera.lua index ac6e347..906993d 100644 --- a/res/project/res/scripts/SideScene/camera.lua +++ b/res/project/res/scripts/SideScene/camera.lua @@ -1,18 +1,28 @@ this.on_init = function() this.speed = 0.1 this.original_position = this.position + this.cursor_locked = false end this.on_fixedupdate = function() - if Input.getKeyDown(Input.KeyCode.Enter) then + if Input.getKeyJustPressed(Input.KeyCode.Enter) then gotoScene('MainScene') end + if Input.getKeyDown(Input.KeyCode.L) then + if this.cursor_locked then + Input.unlockCursor() + else + Input.lockCursor() + end + this.cursor_locked = not this.cursor_locked + end + if Input.getKeyDown(Input.KeyCode.Up) then - this.position = this.position + Vec3:new(0, 1, 0) * this.speed + this.position = this.position - Vec3:new(0, 0, 1) * this.speed end if Input.getKeyDown(Input.KeyCode.Down) then - this.position = this.position - Vec3:new(0, 1, 0) * this.speed + this.position = this.position + Vec3:new(0, 0, 1) * this.speed end if Input.getKeyDown(Input.KeyCode.Right) then this.position = this.position + Vec3:new(1, 0, 0) * this.speed diff --git a/res/project/res/scripts/SideScene/ghost.lua b/res/project/res/scripts/SideScene/ghost.lua new file mode 100644 index 0000000..82e4f30 --- /dev/null +++ b/res/project/res/scripts/SideScene/ghost.lua @@ -0,0 +1,8 @@ +this.on_collisionenter = function(other) + print(other.name) +end + +this.on_update = function () + local player = getObject('Player.Child') + this.position = player.position + Vec3:new(0, 10, 0) +end diff --git a/res/project/res/scripts/SideScene/player.lua b/res/project/res/scripts/SideScene/player.lua index 90782f6..0f75d7c 100644 --- a/res/project/res/scripts/SideScene/player.lua +++ b/res/project/res/scripts/SideScene/player.lua @@ -1,6 +1,9 @@ -- this.on_collisionenter = function(other) -- other.position = other.position + Vec3:new(3.2, 0, 0) -- end +this.on_init = function() + print(this:getChild('Child').position:to_string()) +end this.on_update = function () rb = this:getComponent(Rigidbody) diff --git a/res/project/triangle.vert b/res/project/triangle.vert new file mode 100644 index 0000000..cc3647c --- /dev/null +++ b/res/project/triangle.vert @@ -0,0 +1,5 @@ +#version 450 + +void main() { + gl_Position = vec4(0); +} diff --git a/src/main.c b/src/main.c index 8a2c665..39bb729 100644 --- a/src/main.c +++ b/src/main.c @@ -18,10 +18,8 @@ DECLARE_EVENT_LISTENER(keyPressedListener, (KeyPressedEvent *event) { if(event->keyCode == 81) // tests if Q was pressed Window->setShouldClose(event->handle, true); - else if(event->keyCode == 49) // Numrow 1 - Game->setActiveScene(Scene->getFromName("MainScene")); - else if(event->keyCode == 50) // Numrow 2 - Game->setActiveScene(Scene->getFromName("SisyphusoScene")); + /* else if(event->keyCode == 49) // Numrow 1 */ + /* else if(event->keyCode == 50) // Numrow 2 */ /* else if(event->keyCode == 45) // Numrow - */ /* else if(event->keyCode == 61) // Numrow = */ }) @@ -37,7 +35,7 @@ int main(int argc, char **argv) evolmodule_t window_mod = evol_loadmodule("window"); DEBUG_ASSERT(window_mod); evolmodule_t input_mod = evol_loadmodule("input"); DEBUG_ASSERT(input_mod); - imports(asset_mod , (AssetManager, Asset, TextLoader, JSONLoader)) + imports(asset_mod , (AssetManager, Asset, TextLoader, JSONLoader, ShaderLoader)) imports(game_mod , (Game, Object, Camera, Scene)) imports(window_mod , (Window)) imports(input_mod , (Input)) @@ -63,6 +61,14 @@ int main(int argc, char **argv) AssetManager->mount(&project_dir, &project_mountpoint); evstring_free(project_mountpoint); + AssetHandle shader_asset = Asset->load("project://triangle.vert"); + ShaderAsset shader_bin = ShaderLoader->loadAsset(shader_asset, EV_SHADERASSETSTAGE_VERTEX, "TriangleVertex", "main", EV_SHADER_BIN); + ShaderAsset shader_asm = ShaderLoader->loadAsset(shader_asset, EV_SHADERASSETSTAGE_VERTEX, "TriangleVertex", "main", EV_SHADER_ASM); + + ev_log_debug("Shader Binary: %.*s", shader_bin.len, shader_bin.binary); + ev_log_debug("Shader Assembly: %.*s", shader_asm.len, shader_asm.binary); + + Asset->free(shader_asset); EV_DEFER( AssetHandle project_config = Asset->load("project://game.proj"), @@ -119,14 +125,14 @@ int main(int argc, char **argv) U32 result = 0; while(result == 0) { - ev_ProfileCPU(EventSystemProgress, 0) { - result |= EventSystem.progress(); - } - ev_ProfileCPU(WindowUpdate, 0) { result |= Window->update(windowHandle); } + ev_ProfileCPU(EventSystemProgress, 0) { + result |= EventSystem.progress(); + } + ev_ProfileCPU(GameProgress, 0) { result |= Game->progress(0.01666667f); }