master
Perttu Ahola 2014-10-02 14:38:59 +03:00
parent c6a88ac4ce
commit cb6b59ac41
6 changed files with 53 additions and 41 deletions

View File

@ -81,7 +81,6 @@ dofile(__buildat_get_path("share").."/client/api.lua")
dofile(__buildat_get_path("share").."/client/packet.lua")
dofile(__buildat_get_path("share").."/client/extensions.lua")
dofile(__buildat_get_path("share").."/client/sandbox.lua")
dofile(__buildat_get_path("share").."/client/misc.lua")
local test = require("buildat/extension/test")
test.f()

View File

@ -1,16 +0,0 @@
-- Buildat: client/misc.lua
-- http://www.apache.org/licenses/LICENSE-2.0
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
local log = buildat.Logger("__client/misc")
-- Replicated scene from the server
__buildat_sync_scene = nil
-- Called by the client application
function __buildat_set_sync_scene(scene)
assert(scene)
log:verbose("__buildat_set_sync_scene(): ok")
__buildat_sync_scene = scene
end
-- vim: set noet ts=4 sw=4:

View File

@ -7,8 +7,9 @@ local magic = unsafe_magic.safe
local dump = buildat.dump
local M = {safe = {}}
-- TODO
--M.safe.scene = getmetatable(magic.Scene).wrap(__buildat_sync_scene)
M.safe.scene = __buildat_sync_scene
--M.safe.scene = __buildat_sync_scene
--__buildat_sandbox_debug_check_value(M.safe.scene)
return M

View File

@ -254,14 +254,32 @@ function M.define(dst, util)
return util.wrap_instance("Viewport", Viewport:new(scene, camera_component))
end),
},
instance = {
GetScene = util.wrap_function({"Viewport"},
function(self)
return util.wrap_instance("Scene", self:GetScene())
end
),
GetCamera = util.wrap_function({"Viewport"},
function(self)
return util.wrap_instance("Camera", self:GetCamera())
end
),
},
})
util.wc("Renderer", {
instance = {
SetViewport = util.wrap_function({"Renderer", "number", "Viewport"},
function(self, index, viewport)
self:SetViewport(index, viewport)
end),
function(self, index, viewport)
self:SetViewport(index, viewport)
end
),
GetViewport = util.wrap_function({"Renderer", "number"},
function(self, index)
return util.wrap_instance("Viewport", self:GetViewport(index))
end
),
},
})

View File

@ -6,15 +6,15 @@ local log = buildat.Logger("minigame")
local dump = buildat.dump
local cereal = require("buildat/extension/cereal")
local magic = require("buildat/extension/urho3d")
local entitysync = require("buildat/extension/entitysync")
-- 3D things
--scene = magic.Scene()
local scene = entitysync.scene
local plane_node = scene:CreateChild("Plane")
--[[
scene:CreateComponent("Octree")
-- Viewport 0 is created in C++. It is set to view the network-synchronized
-- scene with one camera.
-- NOTE: This won't work this way in the future.
local viewport = magic.renderer:GetViewport(0)
local scene = viewport:GetScene()
local camera = viewport:GetCamera()
-- Note that naming the scene nodes is optional
local plane_node = scene:CreateChild("Plane")
@ -40,16 +40,6 @@ light = light_node:CreateComponent("Light")
light.lightType = magic.LIGHT_DIRECTIONAL
light.brightness = 0.2
-- Add a camera so we can look at the scene
local camera_node = scene:CreateChild("Camera")
camera_node:CreateComponent("Camera")
camera_node.position = magic.Vector3(7.0, 7.0, 7.0)
--camera_node.rotation = Quaternion(0, 0, 0.0)
camera_node:LookAt(magic.Vector3(0, 1, 0))
-- And this thing so the camera is shown on the screen
local viewport = magic.Viewport:new(scene, camera_node:GetComponent("Camera"))
magic.renderer:SetViewport(0, viewport)
-- Add some text
local title_text = magic.ui.root:CreateChild("Text")
title_text:SetText("minigame/init.lua")

View File

@ -25,6 +25,10 @@
#include <XMLFile.h>
#include <Scene.h>
#include <LuaFunction.h>
#include <Viewport.h>
#include <Camera.h>
#include <Renderer.h>
#include <Octree.h>
#pragma GCC diagnostic pop
extern "C" {
#include <lua.h>
@ -59,6 +63,7 @@ struct CApp: public App, public magic::Application
Options m_options;
magic::SharedPtr<magic::Scene> m_scene;
magic::SharedPtr<magic::Node> m_camera_node;
CApp(magic::Context *context, const Options &options):
magic::Application(context),
@ -287,16 +292,31 @@ struct CApp: public App, public magic::Application
// files.
buildat_guard_enable(true);
// Create a scene that will be synchronized from the server and set it
// as a global
// Create a scene that will be synchronized from the server
m_scene = new magic::Scene(context_);
magic::WeakPtr<magic::LuaFunction> f =
m_scene->CreateComponent<magic::Octree>();
// Create a camera and a viewport for the scene. The scene can then be
// accessed in Lua by magic.renderer:GetViewport(0):GetScene().
m_camera_node = m_scene->CreateChild("Camera", magic::LOCAL);
magic::Camera* camera = m_camera_node->CreateComponent<magic::Camera>();
camera->SetFarClip(300.0f);
m_camera_node->SetPosition(magic::Vector3(7.0, 7.0, 7.0));
m_camera_node->LookAt(magic::Vector3(0, 1, 0));
magic::Renderer* renderer = GetSubsystem<magic::Renderer>();
magic::SharedPtr<magic::Viewport> viewport(new magic::Viewport(
context_, m_scene, m_camera_node->GetComponent<magic::Camera>()));
renderer->SetViewport(0, viewport);
// Won't work; accessing the resulting value in Lua segfaults.
/*magic::WeakPtr<magic::LuaFunction> f =
m_script->GetFunction("__buildat_set_sync_scene");
if(!f)
throw Exception("__buildat_set_sync_scene not found");
f->BeginCall();
f->PushUserType(m_scene.Get(), "Scene");
f->EndCall();
f->EndCall();*/
// Launch menu if requested
if(g_client_config.boot_to_menu){