Added evmod_assets and started using it for scripts

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-05-31 23:00:38 +02:00
parent 995312a8b6
commit fb5128df7b
10 changed files with 141 additions and 133 deletions

View File

@@ -23,7 +23,7 @@ subproject('evmod_glfw')
subproject('evmod_ecs')
subproject('evmod_physics')
subproject('evmod_script')
subproject('evmod_assetsystem')
subproject('evmod_assets')
subproject('evmod_game')
evmodglfw_dep = dependency('evmod_glfw')
@@ -31,7 +31,7 @@ evmodecs_dep = dependency('evmod_ecs')
evmodphysics_dep = dependency('evmod_physics')
evmodscript_dep = dependency('evmod_script')
evmodgame_dep = dependency('evmod_game')
evmod_assetsystem_dep = dependency('evmod_assetsystem')
evmod_assets_dep = dependency('evmod_assets')
# Setup build directory
subdir('buildscripts')
@@ -47,7 +47,7 @@ sandbox_exe = executable(
evmodphysics_dep,
evmodscript_dep,
evmodgame_dep,
evmod_assetsystem_dep
evmod_assets_dep,
],
install : true,
c_args: sandbox_args,

View 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

View 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

View 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

View File

View 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

View 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

View File

@@ -10,7 +10,7 @@
#include IMPORT_MODULE_H
#define IMPORT_MODULE evmod_script
#include IMPORT_MODULE_H
#define IMPORT_MODULE evmod_assetsystem
#define IMPORT_MODULE evmod_assets
#include IMPORT_MODULE_H
#define IMPORT_MODULE evmod_game
#include IMPORT_MODULE_H
@@ -53,69 +53,20 @@ init_scenes()
Camera->setAspectRatio(scenes[0], camera, (F32)width / (F32)height);
Object->setPosition(scenes[0], camera, Vec3new(0, 0, -5));
ScriptHandle childBoxScript = Script->new("Entity1Script1",
"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 "
);
AssetHandle childBoxScriptAsset = Asset->load("scripts://Scene0/child.lua");
TextAsset childScript = TextLoader->loadAsset(childBoxScriptAsset);
ScriptHandle childBoxScript = Script->new("ChildScriptScene0", childScript.text);
Asset->free(childBoxScriptAsset);
ScriptHandle playerBoxScript = Script->new("Entity2Script1",
"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 "
);
AssetHandle playerBoxScriptAsset = Asset->load("scripts://Scene0/player.lua");
TextAsset playerScript = TextLoader->loadAsset(playerBoxScriptAsset);
ScriptHandle playerBoxScript = Script->new("PlayerScriptScene0", playerScript.text);
Asset->free(playerBoxScriptAsset);
ScriptHandle cameraScript = Script->new("CameraScript1",
"this.on_init = function() "
" this.speed = 3 "
"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 "
);
AssetHandle cameraScriptAsset = Asset->load("scripts://Scene0/camera.lua");
TextAsset cameraScriptText = TextLoader->loadAsset(cameraScriptAsset);
ScriptHandle cameraScript = Script->new("CameraScriptScene0", cameraScriptText.text);
Asset->free(cameraScriptAsset);
GenericHandle ecs_handle = Scene->getECSWorld(scenes[0]);
PhysicsWorldHandle physics_handle = Scene->getPhysicsWorld(scenes[0]);
@@ -165,69 +116,20 @@ init_scenes()
Camera->setAspectRatio(scenes[1], camera, (F32)width / (F32)height);
Object->setPosition(scenes[1], camera, Vec3new(0, 0, -5));
ScriptHandle childBoxScript = Script->new("Entity1Script2",
"this.on_init = function () "
" this.custom_eulerangles = Vec3:new() "
" this.custom_angularvelocity = Vec3:new(0, 0.01, 0) "
"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 "
);
AssetHandle childBoxScriptAsset = Asset->load("scripts://Scene1/child.lua");
TextAsset childScript = TextLoader->loadAsset(childBoxScriptAsset);
ScriptHandle childBoxScript = Script->new("ChildScriptScene1", childScript.text);
Asset->free(childBoxScriptAsset);
ScriptHandle playerBoxScript = Script->new("Entity2Script2",
"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 "
);
AssetHandle playerBoxScriptAsset = Asset->load("scripts://Scene1/player.lua");
TextAsset playerScript = TextLoader->loadAsset(playerBoxScriptAsset);
ScriptHandle playerBoxScript = Script->new("PlayerScriptScene1", playerScript.text);
Asset->free(playerBoxScriptAsset);
ScriptHandle cameraScript = Script->new("CameraScript2",
"this.on_init = function() "
" this.speed = 3 "
"end "
"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 "
);
AssetHandle cameraScriptAsset = Asset->load("scripts://Scene1/camera.lua");
TextAsset cameraScriptText = TextLoader->loadAsset(cameraScriptAsset);
ScriptHandle cameraScript = Script->new("CameraScriptScene1", cameraScriptText.text);
Asset->free(cameraScriptAsset);
GenericHandle ecs_handle = Scene->getECSWorld(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 input_mod = evol_loadmodule("input"); DEBUG_ASSERT(input_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);
imports(script_mod , (Script))
@@ -283,6 +185,15 @@ int main(int argc, char **argv)
imports(window_mod , (Window))
imports(input_mod , (Input))
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);

View File

@@ -0,0 +1,3 @@
[wrap-git]
url = https://github.com/evol3D/evol-mod-assetmanager
revision = master

View File

@@ -1,6 +0,0 @@
[wrap-git]
url = https://github.com/evol3D/evol-mod-assetsystem
revision = master
[provide]
dependency_names = evmod_assetsystem