Added evmod_assets and started using it for scripts
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -23,7 +23,7 @@ subproject('evmod_glfw')
|
|||||||
subproject('evmod_ecs')
|
subproject('evmod_ecs')
|
||||||
subproject('evmod_physics')
|
subproject('evmod_physics')
|
||||||
subproject('evmod_script')
|
subproject('evmod_script')
|
||||||
subproject('evmod_assetsystem')
|
subproject('evmod_assets')
|
||||||
subproject('evmod_game')
|
subproject('evmod_game')
|
||||||
|
|
||||||
evmodglfw_dep = dependency('evmod_glfw')
|
evmodglfw_dep = dependency('evmod_glfw')
|
||||||
@@ -31,7 +31,7 @@ evmodecs_dep = dependency('evmod_ecs')
|
|||||||
evmodphysics_dep = dependency('evmod_physics')
|
evmodphysics_dep = dependency('evmod_physics')
|
||||||
evmodscript_dep = dependency('evmod_script')
|
evmodscript_dep = dependency('evmod_script')
|
||||||
evmodgame_dep = dependency('evmod_game')
|
evmodgame_dep = dependency('evmod_game')
|
||||||
evmod_assetsystem_dep = dependency('evmod_assetsystem')
|
evmod_assets_dep = dependency('evmod_assets')
|
||||||
|
|
||||||
# Setup build directory
|
# Setup build directory
|
||||||
subdir('buildscripts')
|
subdir('buildscripts')
|
||||||
@@ -47,7 +47,7 @@ sandbox_exe = executable(
|
|||||||
evmodphysics_dep,
|
evmodphysics_dep,
|
||||||
evmodscript_dep,
|
evmodscript_dep,
|
||||||
evmodgame_dep,
|
evmodgame_dep,
|
||||||
evmod_assetsystem_dep
|
evmod_assets_dep,
|
||||||
],
|
],
|
||||||
install : true,
|
install : true,
|
||||||
c_args: sandbox_args,
|
c_args: sandbox_args,
|
||||||
|
|||||||
18
res/scripts/Scene0/camera.lua
Normal file
18
res/scripts/Scene0/camera.lua
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
this.on_init = function()
|
||||||
|
this.speed = 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_fixedupdate = function()
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Up) then
|
||||||
|
this.position = this.position + Vec3:new(0, 1, 0) * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Down) then
|
||||||
|
this.position = this.position - Vec3:new(0, 1, 0) * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Right) then
|
||||||
|
this.position = this.position + Vec3:new(1, 0, 0) * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Left) then
|
||||||
|
this.position = this.position - Vec3:new(1, 0, 0) * this.speed
|
||||||
|
end
|
||||||
|
end
|
||||||
15
res/scripts/Scene0/child.lua
Normal file
15
res/scripts/Scene0/child.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
this.on_init = function ()
|
||||||
|
this.custom_eulerangles = Vec3:new()
|
||||||
|
this.custom_angularvelocity = Vec3:new(0, 0.01, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_fixedupdate = function ()
|
||||||
|
print('Scene0 OnFixedUpdate Entity #' .. this.entityID)
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Left) then
|
||||||
|
this.custom_eulerangles:add(Vec3:new(0,0.01,0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Right) then
|
||||||
|
this.custom_eulerangles:sub(Vec3:new(0,0.01,0))
|
||||||
|
end
|
||||||
|
this.eulerAngles = this.custom_eulerangles
|
||||||
|
end
|
||||||
22
res/scripts/Scene0/player.lua
Normal file
22
res/scripts/Scene0/player.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
this.on_collisionenter = function(other)
|
||||||
|
other.position = other.position + Vec3:new(3.2, 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_update = function ()
|
||||||
|
rb = this:getComponent(Rigidbody)
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Space) then
|
||||||
|
rb:addForce(Vec3:new(0, 100, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.D) then
|
||||||
|
rb:addForce(Vec3:new(10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.A) then
|
||||||
|
rb:addForce(Vec3:new(-10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.W) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, -10))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.S) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, 10))
|
||||||
|
end
|
||||||
|
end
|
||||||
0
res/scripts/Scene1/camera.lua
Normal file
0
res/scripts/Scene1/camera.lua
Normal file
23
res/scripts/Scene1/child.lua
Normal file
23
res/scripts/Scene1/child.lua
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
this.on_init = function ()
|
||||||
|
this.custom_eulerangles = Vec3:new()
|
||||||
|
this.custom_angularvelocity = Vec3:new(0, 0.01, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_update = function ()
|
||||||
|
rb = this:getComponent(Rigidbody)
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Enter) then
|
||||||
|
rb:addForce(Vec3:new(0, 100, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Right) then
|
||||||
|
rb:addForce(Vec3:new(10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Left) then
|
||||||
|
rb:addForce(Vec3:new(-10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Up) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, -10))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Down) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, 10))
|
||||||
|
end
|
||||||
|
end
|
||||||
22
res/scripts/Scene1/player.lua
Normal file
22
res/scripts/Scene1/player.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
this.on_collisionenter = function(other)
|
||||||
|
other.position = other.position + Vec3:new(0.2, 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_update = function ()
|
||||||
|
rb = this:getComponent(Rigidbody)
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Space) then
|
||||||
|
rb:addForce(Vec3:new(0, 100, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.D) then
|
||||||
|
rb:addForce(Vec3:new(10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.A) then
|
||||||
|
rb:addForce(Vec3:new(-10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.W) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, -10))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.S) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, 10))
|
||||||
|
end
|
||||||
|
end
|
||||||
159
src/main.c
159
src/main.c
@@ -10,7 +10,7 @@
|
|||||||
#include IMPORT_MODULE_H
|
#include IMPORT_MODULE_H
|
||||||
#define IMPORT_MODULE evmod_script
|
#define IMPORT_MODULE evmod_script
|
||||||
#include IMPORT_MODULE_H
|
#include IMPORT_MODULE_H
|
||||||
#define IMPORT_MODULE evmod_assetsystem
|
#define IMPORT_MODULE evmod_assets
|
||||||
#include IMPORT_MODULE_H
|
#include IMPORT_MODULE_H
|
||||||
#define IMPORT_MODULE evmod_game
|
#define IMPORT_MODULE evmod_game
|
||||||
#include IMPORT_MODULE_H
|
#include IMPORT_MODULE_H
|
||||||
@@ -53,69 +53,20 @@ init_scenes()
|
|||||||
Camera->setAspectRatio(scenes[0], camera, (F32)width / (F32)height);
|
Camera->setAspectRatio(scenes[0], camera, (F32)width / (F32)height);
|
||||||
Object->setPosition(scenes[0], camera, Vec3new(0, 0, -5));
|
Object->setPosition(scenes[0], camera, Vec3new(0, 0, -5));
|
||||||
|
|
||||||
ScriptHandle childBoxScript = Script->new("Entity1Script1",
|
AssetHandle childBoxScriptAsset = Asset->load("scripts://Scene0/child.lua");
|
||||||
"this.on_init = function () "
|
TextAsset childScript = TextLoader->loadAsset(childBoxScriptAsset);
|
||||||
" this.custom_eulerangles = Vec3:new() "
|
ScriptHandle childBoxScript = Script->new("ChildScriptScene0", childScript.text);
|
||||||
" this.custom_angularvelocity = Vec3:new(0, 0.01, 0) "
|
Asset->free(childBoxScriptAsset);
|
||||||
"end "
|
|
||||||
" "
|
|
||||||
"this.on_fixedupdate = function () "
|
|
||||||
" print('Scene0 OnFixedUpdate Entity #' .. this.entityID)"
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Left) then "
|
|
||||||
" this.custom_eulerangles:add(Vec3:new(0,0.01,0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Right) then "
|
|
||||||
" this.custom_eulerangles:sub(Vec3:new(0,0.01,0)) "
|
|
||||||
" end "
|
|
||||||
" this.eulerAngles = this.custom_eulerangles "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
ScriptHandle playerBoxScript = Script->new("Entity2Script1",
|
AssetHandle playerBoxScriptAsset = Asset->load("scripts://Scene0/player.lua");
|
||||||
"this.on_collisionenter = function(other) "
|
TextAsset playerScript = TextLoader->loadAsset(playerBoxScriptAsset);
|
||||||
" other.position = other.position + Vec3:new(0.2, 0, 0) "
|
ScriptHandle playerBoxScript = Script->new("PlayerScriptScene0", playerScript.text);
|
||||||
"end "
|
Asset->free(playerBoxScriptAsset);
|
||||||
" "
|
|
||||||
"this.on_update = function () "
|
|
||||||
" rb = this:getComponent(Rigidbody) "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Space) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 100, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.D) then "
|
|
||||||
" rb:addForce(Vec3:new(10, 0, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.A) then "
|
|
||||||
" rb:addForce(Vec3:new(-10, 0, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.W) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 0, -10)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.S) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 0, 10)) "
|
|
||||||
" end "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
ScriptHandle cameraScript = Script->new("CameraScript1",
|
AssetHandle cameraScriptAsset = Asset->load("scripts://Scene0/camera.lua");
|
||||||
"this.on_init = function() "
|
TextAsset cameraScriptText = TextLoader->loadAsset(cameraScriptAsset);
|
||||||
" this.speed = 3 "
|
ScriptHandle cameraScript = Script->new("CameraScriptScene0", cameraScriptText.text);
|
||||||
"end "
|
Asset->free(cameraScriptAsset);
|
||||||
|
|
||||||
"this.on_fixedupdate = function() "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Up) then "
|
|
||||||
" this.position = this.position + Vec3:new(0, 1, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Down) then "
|
|
||||||
" this.position = this.position - Vec3:new(0, 1, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Right) then "
|
|
||||||
" this.position = this.position + Vec3:new(1, 0, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Left) then "
|
|
||||||
" this.position = this.position - Vec3:new(1, 0, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
GenericHandle ecs_handle = Scene->getECSWorld(scenes[0]);
|
GenericHandle ecs_handle = Scene->getECSWorld(scenes[0]);
|
||||||
PhysicsWorldHandle physics_handle = Scene->getPhysicsWorld(scenes[0]);
|
PhysicsWorldHandle physics_handle = Scene->getPhysicsWorld(scenes[0]);
|
||||||
@@ -165,69 +116,20 @@ init_scenes()
|
|||||||
Camera->setAspectRatio(scenes[1], camera, (F32)width / (F32)height);
|
Camera->setAspectRatio(scenes[1], camera, (F32)width / (F32)height);
|
||||||
Object->setPosition(scenes[1], camera, Vec3new(0, 0, -5));
|
Object->setPosition(scenes[1], camera, Vec3new(0, 0, -5));
|
||||||
|
|
||||||
ScriptHandle childBoxScript = Script->new("Entity1Script2",
|
AssetHandle childBoxScriptAsset = Asset->load("scripts://Scene1/child.lua");
|
||||||
"this.on_init = function () "
|
TextAsset childScript = TextLoader->loadAsset(childBoxScriptAsset);
|
||||||
" this.custom_eulerangles = Vec3:new() "
|
ScriptHandle childBoxScript = Script->new("ChildScriptScene1", childScript.text);
|
||||||
" this.custom_angularvelocity = Vec3:new(0, 0.01, 0) "
|
Asset->free(childBoxScriptAsset);
|
||||||
"end "
|
|
||||||
" "
|
|
||||||
"this.on_fixedupdate = function () "
|
|
||||||
" print('Scene1 OnFixedUpdate Entity #' .. this.entityID)"
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Left) then "
|
|
||||||
" this.custom_eulerangles:add(Vec3:new(0,0.01,0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Right) then "
|
|
||||||
" this.custom_eulerangles:sub(Vec3:new(0,0.01,0)) "
|
|
||||||
" end "
|
|
||||||
" this.eulerAngles = this.custom_eulerangles "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
ScriptHandle playerBoxScript = Script->new("Entity2Script2",
|
AssetHandle playerBoxScriptAsset = Asset->load("scripts://Scene1/player.lua");
|
||||||
"this.on_collisionenter = function(other) "
|
TextAsset playerScript = TextLoader->loadAsset(playerBoxScriptAsset);
|
||||||
" other.position = other.position + Vec3:new(0.2, 0, 0) "
|
ScriptHandle playerBoxScript = Script->new("PlayerScriptScene1", playerScript.text);
|
||||||
"end "
|
Asset->free(playerBoxScriptAsset);
|
||||||
" "
|
|
||||||
"this.on_update = function () "
|
|
||||||
" rb = this:getComponent(Rigidbody) "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Space) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 100, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.D) then "
|
|
||||||
" rb:addForce(Vec3:new(10, 0, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.A) then "
|
|
||||||
" rb:addForce(Vec3:new(-10, 0, 0)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.W) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 0, -10)) "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.S) then "
|
|
||||||
" rb:addForce(Vec3:new(0, 0, 10)) "
|
|
||||||
" end "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
ScriptHandle cameraScript = Script->new("CameraScript2",
|
AssetHandle cameraScriptAsset = Asset->load("scripts://Scene1/camera.lua");
|
||||||
"this.on_init = function() "
|
TextAsset cameraScriptText = TextLoader->loadAsset(cameraScriptAsset);
|
||||||
" this.speed = 3 "
|
ScriptHandle cameraScript = Script->new("CameraScriptScene1", cameraScriptText.text);
|
||||||
"end "
|
Asset->free(cameraScriptAsset);
|
||||||
|
|
||||||
"this.on_fixedupdate = function() "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Up) then "
|
|
||||||
" 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, 0, 1) * this.speed "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Right) then "
|
|
||||||
" this.position = this.position + Vec3:new(1, 0, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
" if Input.getKeyDown(Input.KeyCode.Left) then "
|
|
||||||
" this.position = this.position - Vec3:new(1, 0, 0) * this.speed "
|
|
||||||
" end "
|
|
||||||
"end "
|
|
||||||
);
|
|
||||||
|
|
||||||
GenericHandle ecs_handle = Scene->getECSWorld(scenes[1]);
|
GenericHandle ecs_handle = Scene->getECSWorld(scenes[1]);
|
||||||
PhysicsWorldHandle physics_handle = Scene->getPhysicsWorld(scenes[1]);
|
PhysicsWorldHandle physics_handle = Scene->getPhysicsWorld(scenes[1]);
|
||||||
@@ -275,7 +177,7 @@ int main(int argc, char **argv)
|
|||||||
evolmodule_t window_mod = evol_loadmodule("window"); DEBUG_ASSERT(window_mod);
|
evolmodule_t window_mod = evol_loadmodule("window"); DEBUG_ASSERT(window_mod);
|
||||||
evolmodule_t input_mod = evol_loadmodule("input"); DEBUG_ASSERT(input_mod);
|
evolmodule_t input_mod = evol_loadmodule("input"); DEBUG_ASSERT(input_mod);
|
||||||
evolmodule_t physics_mod = evol_loadmodule("physics"); DEBUG_ASSERT(physics_mod);
|
evolmodule_t physics_mod = evol_loadmodule("physics"); DEBUG_ASSERT(physics_mod);
|
||||||
evolmodule_t asset_mod = evol_loadmodule("asset-importer"); DEBUG_ASSERT(asset_mod);
|
evolmodule_t asset_mod = evol_loadmodule("assetmanager"); DEBUG_ASSERT(asset_mod);
|
||||||
evolmodule_t game_mod = evol_loadmodule("game"); DEBUG_ASSERT(game_mod);
|
evolmodule_t game_mod = evol_loadmodule("game"); DEBUG_ASSERT(game_mod);
|
||||||
|
|
||||||
imports(script_mod , (Script))
|
imports(script_mod , (Script))
|
||||||
@@ -283,6 +185,15 @@ int main(int argc, char **argv)
|
|||||||
imports(window_mod , (Window))
|
imports(window_mod , (Window))
|
||||||
imports(input_mod , (Input))
|
imports(input_mod , (Input))
|
||||||
imports(physics_mod, (PhysicsWorld, Rigidbody, CollisionShape))
|
imports(physics_mod, (PhysicsWorld, Rigidbody, CollisionShape))
|
||||||
|
imports(asset_mod , (AssetManager, Asset, TextLoader))
|
||||||
|
|
||||||
|
AssetManager->mount("../res", "res:/");
|
||||||
|
AssetManager->mount("../res/scripts", "scripts:/");
|
||||||
|
|
||||||
|
AssetHandle handle = Asset->load("scripts://script.lua");
|
||||||
|
TextAsset txt = TextLoader->loadAsset(handle);
|
||||||
|
ev_log_debug("Script: \n%s\n", txt.text);
|
||||||
|
Asset->free(handle);
|
||||||
|
|
||||||
IMPORT_EVENTS_evmod_glfw(window_mod);
|
IMPORT_EVENTS_evmod_glfw(window_mod);
|
||||||
|
|
||||||
|
|||||||
3
subprojects/evmod_assets.wrap
Normal file
3
subprojects/evmod_assets.wrap
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[wrap-git]
|
||||||
|
url = https://github.com/evol3D/evol-mod-assetmanager
|
||||||
|
revision = master
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
[wrap-git]
|
|
||||||
url = https://github.com/evol3D/evol-mod-assetsystem
|
|
||||||
revision = master
|
|
||||||
|
|
||||||
[provide]
|
|
||||||
dependency_names = evmod_assetsystem
|
|
||||||
Reference in New Issue
Block a user