简体   繁体   English

游戏中使用的虚拟机

[英]Virtual machine to be used in a game

I am looking for a virtual machine I can embed inside a game. 我正在寻找可以嵌入游戏中的虚拟机。

The idea is that I create a game world and two avatars. 我的想法是创建一个游戏世界和两个头像。 Inside the avatars I embed a virtual machine that can interact with the avatar in the game world using an api, like: 在化身内部,我嵌入了一个虚拟机,该虚拟机可以使用api与游戏世界中的化身进行交互,例如:

move_forward()
turn_left()
turn_right()
sense()
etc.

In each tick i will allow each VM to update X ticks progressing each. 在每个滴答声中,我将允许每个VM更新X滴答声,从而使每个进程进展。 Two different programs would then be uploaded to each VM and be executed independently. 然后将两个不同的程序上载到每个VM,并独立执行。 The whole setup should be robust against crashing programs inside the VM. 整个设置应具有强大的功能,可防止VM中的程序崩溃。

I would prefer to work in Python, and my environment is C# but I am open for suggestione. 我更喜欢在Python中工作,我的环境是C#,但我愿意接受建议。

The idea is heavily inspired by the game GunTactyx, but I find the language used there too narrow, as I aim it to be a learning platform to move further into programming. 这个想法受到了GunTactyx游戏的极大启发,但是我发现那里使用的语言过于狭窄,因为我希望它是一个学习平台,可以进一步进入编程领域。

Do you know any VM that allow me to do this? 您知道允许我执行此操作的任何VM吗?

kind regards 亲切的问候

Jesper 杰斯珀

I would use Lua, which in my experience is more heavily used in games than python. 我会用Lua,根据我的经验,Lua在游戏中比python更常用。

You can use debug hooks or coroutines to limit the number of instructions being executed at a time. 您可以使用调试挂钩或协程来限制一次执行的指令数。 Here is a post on someone doing something similar to you: http://lua-users.org/lists/lua-l/2009-03/msg00008.html 这是关于某人做与您相似的事情的帖子: http : //lua-users.org/lists/lua-l/2009-03/msg00008.html

In terms of robustness against crashing: "Because Lua is an extension language, frequently embedded in an application, it cannot simply crash or exit when an error happens. Instead, whenever an error occurs, Lua ends the current chunk and returns to the application." 关于防止崩溃的鲁棒性:“因为Lua是一种扩展语言,通常嵌入在应用程序中,所以它不能简单地在发生错误时崩溃或退出。相反,每当发生错误时,Lua都会终止当前块并返回到应用程序。 ” http://www.lua.org/pil/8.3.html http://www.lua.org/pil/8.3.html

If you want to use C# to wrap Lua, try 如果要使用C#包装Lua,请尝试

http://luaforge.net/projects/luainterface/ http://luaforge.net/projects/luainterface/

https://github.com/NLua/NLua https://github.com/NLua/NLua

Also check out this post for a discussion on Lua Vs Python: 另请查看此帖子,以获取有关Lua Vs Python的讨论:

https://stackoverflow.com/questions/356160/which-game-scripting-language-is-better-to-use-lua-or-python https://stackoverflow.com/questions/356160/which-game-scripting-language-is-better-to-use-lua-or-python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM