games: Fix everything to work with current interfaces

This commit is contained in:
Perttu Ahola 2014-10-22 01:27:22 +03:00
parent 9921211cd0
commit 4b63edb951
8 changed files with 92 additions and 33 deletions

View File

@ -152,10 +152,9 @@ local player_node = scene:CreateChild("Player")
local player_shape = player_node:CreateComponent("CollisionShape")
do
--player_node.position = magic.Vector3(0, 30, 0)
--player_node.position = magic.Vector3(55, 30, 40)
player_node.position = magic.Vector3(-5, 1, 257)
player_node.position = magic.Vector3(55, 30, 40)
--player_node.position = magic.Vector3(-5, 1, 257)
player_node.direction = magic.Vector3(-1, 0, 0.4)
--player_node:Yaw(-177.49858)
---[[
local body = player_node:CreateComponent("RigidBody")
--body.mass = 70.0
@ -461,7 +460,6 @@ function setup_simple_voxel_data(node)
local d = node:GetVar("simple_voxel_d"):GetInt()
log:info(dump(node:GetName()).." voxel data size: "..data:GetSize())
buildat.set_8bit_voxel_geometry(node, w, h, d, data, voxel_reg, atlas_reg)
node:SetScale(magic.Vector3(1, 1, 1))
end
voxelworld.sub_ready(function()

View File

@ -284,7 +284,7 @@ struct Module: public interface::Module
log_v(MODULE, "Testbox: (%f, %f, %f)", p.x_, p.y_, p.z_);
});*/
static uint a = 0;
if(((a++) % 100) == 0){
if(((a++) % 150) == 0){
m_server->access_scene([&](Scene *scene){
Node *n = scene->GetChild("Testbox");
n->SetRotation(Quaternion(30, 60, 90));

View File

@ -39,7 +39,7 @@ function handle_keydown(event_type, event_data)
end
magic.SubscribeToEvent("KeyDown", "handle_keydown")
magic.sub_sync_node_added({}, function(node)
replicate.sub_sync_node_added({}, function(node)
local name = node:GetName()
if name == "Box" then
-- Models and materials can be created dynamically on the client side

View File

@ -135,7 +135,7 @@ struct Module: public interface::Module
{
log_d(MODULE, "entitytest::on_tick");
static uint a = 0;
if(((a++) % 50) == 0){
if(((a++) % 100) == 0){
m_server->access_scene([&](Scene *scene){
Node *n = scene->GetChild("Box");
n->SetPosition(Vector3(0.0f, 6.0f, 0.0f));

View File

@ -60,7 +60,7 @@ function setup_simple_voxel_data(node)
object.castShadows = true
end
magic.sub_sync_node_added({}, function(node)
replicate.sub_sync_node_added({}, function(node)
if not node:GetVar("simple_voxel_data"):IsEmpty() then
setup_simple_voxel_data(node)
end

View File

@ -91,13 +91,13 @@ struct Module: public interface::Module
// Load the same model in here and give it to the physics
// subsystem so that it can be collided to
SharedPtr<Model> model(interface::
SharedPtr<Model> model(interface::mesh::
create_simple_voxel_model(context, w, h, d, data.c_str()));
RigidBody *body = n->CreateComponent<RigidBody>();
RigidBody *body = n->CreateComponent<RigidBody>(LOCAL);
body->SetFriction(0.75f);
body->SetMass(1.0);
CollisionShape *shape = n->CreateComponent<CollisionShape>();
CollisionShape *shape = n->CreateComponent<CollisionShape>(LOCAL);
shape->SetConvexHull(model, 0, Vector3::ONE);
//shape->SetTriangleMesh(model, 0, Vector3::ONE);
//shape->SetBox(Vector3::ONE);
@ -149,12 +149,12 @@ struct Module: public interface::Module
// Load the same model in here and give it to the physics
// subsystem so that it can be collided to
SharedPtr<Model> model(interface::
SharedPtr<Model> model(interface::mesh::
create_simple_voxel_model(context, w, h, d, data.c_str()));
RigidBody *body = n->CreateComponent<RigidBody>();
RigidBody *body = n->CreateComponent<RigidBody>(LOCAL);
body->SetFriction(0.75f);
CollisionShape *shape = n->CreateComponent<CollisionShape>();
CollisionShape *shape = n->CreateComponent<CollisionShape>(LOCAL);
shape->SetTriangleMesh(model, 0, Vector3::ONE);
}
});
@ -163,13 +163,13 @@ struct Module: public interface::Module
void on_tick(const interface::TickEvent &event)
{
static uint a = 0;
if(((a++) % 50) == 0){
if(((a++) % 100) == 0){
float rx = (float)rand() / RAND_MAX * 180;
float ry = (float)rand() / RAND_MAX * 180;
float rz = (float)rand() / RAND_MAX * 180;
m_server->access_scene([&](Scene *scene){
Node *n = scene->GetChild("Testbox");
//n->SetPosition(Vector3(0.0f, 8.0f, 0.0f));
n->SetRotation(Quaternion(30, 60, 90));
//n->SetPosition(Vector3(0.0f, 6.0f, 0.0f));
//n->SetPosition(Vector3(0.0f, 4.0f, 0.0f));
n->SetRotation(Quaternion(rx, ry, rz));
n->SetPosition(Vector3(-0.5f, 8.0f, 0.0f));
});
return;

View File

@ -39,6 +39,66 @@ function handle_keydown(event_type, event_data)
end
magic.SubscribeToEvent("KeyDown", "handle_keydown")
local voxel_reg = buildat.createVoxelRegistry()
local atlas_reg = buildat.createAtlasRegistry()
do
local vdef = buildat.VoxelDefinition()
vdef.name.block_name = "empty"
vdef.name.segment_x = 0
vdef.name.segment_y = 0
vdef.name.segment_z = 0
vdef.name.rotation_primary = 0
vdef.name.rotation_secondary = 0
vdef.handler_module = ""
vdef.edge_material_id = buildat.VoxelDefinition.EDGEMATERIALID_EMPTY
vdef.physically_solid = true
voxel_reg:add_voxel(vdef)
end
do
local vdef = buildat.VoxelDefinition()
vdef.name.block_name = "foo"
vdef.name.segment_x = 0
vdef.name.segment_y = 0
vdef.name.segment_z = 0
vdef.name.rotation_primary = 0
vdef.name.rotation_secondary = 0
vdef.handler_module = ""
local textures = {}
for i = 1, 6 do
local seg = buildat.AtlasSegmentDefinition()
seg.resource_name = "main/green_texture.png"
seg.total_segments = magic.IntVector2(1, 1)
seg.select_segment = magic.IntVector2(0, 0)
table.insert(textures, seg)
end
vdef.textures = textures
vdef.edge_material_id = buildat.VoxelDefinition.EDGEMATERIALID_GROUND
vdef.physically_solid = true
voxel_reg:add_voxel(vdef)
end
do
local vdef = buildat.VoxelDefinition()
vdef.name.block_name = "bar"
vdef.name.segment_x = 0
vdef.name.segment_y = 0
vdef.name.segment_z = 0
vdef.name.rotation_primary = 0
vdef.name.rotation_secondary = 0
vdef.handler_module = ""
local textures = {}
for i = 1, 6 do
local seg = buildat.AtlasSegmentDefinition()
seg.resource_name = "main/pink_texture.png"
seg.total_segments = magic.IntVector2(1, 1)
seg.select_segment = magic.IntVector2(0, 0)
table.insert(textures, seg)
end
vdef.textures = textures
vdef.edge_material_id = buildat.VoxelDefinition.EDGEMATERIALID_GROUND
vdef.physically_solid = true
voxel_reg:add_voxel(vdef)
end
function setup_simple_voxel_data(node)
--buildat.set_simple_voxel_model(node, 3, 3, 3, "010111010111111111010111010")
--node:SetScale(magic.Vector3(0.5, 0.5, 0.5))
@ -48,13 +108,12 @@ function setup_simple_voxel_data(node)
--node:SetScale(magic.Vector3(2, 2, 2))
-- Should be something like "11101111"
local data = node:GetVar("simple_voxel_data"):GetString()
local data = node:GetVar("simple_voxel_data"):GetBuffer()
local w = node:GetVar("simple_voxel_w"):GetInt()
local h = node:GetVar("simple_voxel_h"):GetInt()
local d = node:GetVar("simple_voxel_d"):GetInt()
log:info(dump(node:GetName()).." voxel data size: "..#data)
buildat.set_8bit_voxel_geometry(node, w, h, d, data)
node:SetScale(magic.Vector3(1, 1, 1))
log:info(dump(node:GetName()).." voxel data size: "..data:GetSize())
buildat.set_8bit_voxel_geometry(node, w, h, d, data, voxel_reg, atlas_reg)
--local object = node:GetComponent("StaticModel")
--object.castShadows = true

View File

@ -38,6 +38,7 @@ struct Module: public interface::Module
interface::Module("geometry"),
m_server(server)
{
m_voxel_reg.reset(interface::createVoxelRegistry());
}
~Module()
@ -54,7 +55,6 @@ struct Module: public interface::Module
{
Context *context = scene->GetContext();
m_atlas_reg.reset(interface::createAtlasRegistry(context));
m_voxel_reg.reset(interface::createVoxelRegistry(m_atlas_reg.get()));
{
interface::VoxelDefinition vdef;
vdef.name.block_name = "air";
@ -158,21 +158,22 @@ struct Module: public interface::Module
// Crude way of dynamically defining a voxel model
n->SetVar(StringHash("simple_voxel_data"), Variant(
magic::String(data.c_str(), data.size())));
PODVector<uint8_t>((const uint8_t*)data.c_str(),
data.size())));
n->SetVar(StringHash("simple_voxel_w"), Variant(w));
n->SetVar(StringHash("simple_voxel_h"), Variant(h));
n->SetVar(StringHash("simple_voxel_d"), Variant(d));
// Load the same model in here and give it to the physics
// subsystem so that it can be collided to
SharedPtr<Model> model(interface::
SharedPtr<Model> model(interface::mesh::
create_8bit_voxel_physics_model(context, w, h, d, data,
m_voxel_reg.get()));
RigidBody *body = n->CreateComponent<RigidBody>();
RigidBody *body = n->CreateComponent<RigidBody>(LOCAL);
body->SetFriction(0.75f);
body->SetMass(1.0);
CollisionShape *shape = n->CreateComponent<CollisionShape>();
CollisionShape *shape = n->CreateComponent<CollisionShape>(LOCAL);
shape->SetConvexHull(model, 0, Vector3::ONE);
//shape->SetTriangleMesh(model, 0, Vector3::ONE);
//shape->SetBox(Vector3::ONE);
@ -223,20 +224,21 @@ struct Module: public interface::Module
// Crude way of dynamically defining a voxel model
n->SetVar(StringHash("simple_voxel_data"), Variant(
magic::String(data.c_str(), data.size())));
PODVector<uint8_t>((const uint8_t*)data.c_str(),
data.size())));
n->SetVar(StringHash("simple_voxel_w"), Variant(w));
n->SetVar(StringHash("simple_voxel_h"), Variant(h));
n->SetVar(StringHash("simple_voxel_d"), Variant(d));
// Load the same model in here and give it to the physics
// subsystem so that it can be collided to
SharedPtr<Model> model(interface::
SharedPtr<Model> model(interface::mesh::
create_8bit_voxel_physics_model(context, w, h, d, data,
m_voxel_reg.get()));
RigidBody *body = n->CreateComponent<RigidBody>();
RigidBody *body = n->CreateComponent<RigidBody>(LOCAL);
body->SetFriction(0.75f);
CollisionShape *shape = n->CreateComponent<CollisionShape>();
CollisionShape *shape = n->CreateComponent<CollisionShape>(LOCAL);
shape->SetTriangleMesh(model, 0, Vector3::ONE);
}
});
@ -245,7 +247,7 @@ struct Module: public interface::Module
void on_tick(const interface::TickEvent &event)
{
static uint a = 0;
if(((a++) % 50) == 0){
if(((a++) % 100) == 0){
m_server->access_scene([&](Scene *scene){
Node *n = scene->GetChild("Testbox");
//n->SetPosition(Vector3(0.0f, 8.0f, 0.0f));