-
Custom Servers in Godot…
Posted on August 17th, 2019 No commentsI’ve been playing around with Godot some more…and did some of the tutorials listed in the Godot documentation.
I tried to do the custom server tutorial mentioned in the Godot documentation, and noticed some missing gaps with the documentation…this post helps to address them.
Source for the module directory part of the tutorial could be downloaded here…
http://www.indiegamepod.com/podcasts/hilbert_hotel_custom_server.zipThe script to attach to spatial node in the second part of the tutorial could be found here…
http://www.indiegamepod.com/podcasts/Spatial.gdFirst, a little bit about custom servers in Godot.
Godot has modules and Godot has servers. The graphics and physics of the game engine are “servers”…conceptually, it seems like “servers” have their own thread/resources and run in parallel with other servers.
This is a bit different than modules that seem to work within the framework of an individual thread.
This tutorial starts from the Hilbert Hotel custom server tutorial mentioned in the Godot documentation
https://docs.godotengine.org/en/3.1/development/cpp/custom_godot_servers.html
To create a custom server, go to your godot source folder…
Go to the “modules” subfolder
Make a new folder called “hilbert_hotel” within the modules folder.
Now create hilbert_hotel.h in the new folder…
Type in the stuff mentioned for hilbert_hotel.h here…
https://docs.godotengine.org/en/3.1/development/cpp/custom_godot_servers.htmlI had to add a few other things to get this to compile…
Note…add these *after* the includes for the core .h files mentioned in the documentation#include “_hilbert_hotel.h”
#include “InfiniteBus.h”Let’s move onto hilbert_hotel.cpp
Type in the stuff mentioned for hilbert_hotel.cpp here…
https://docs.godotengine.org/en/3.1/development/cpp/custom_godot_servers.htmlReplace this line…
InfiniteBus *)bus = bus_owner.getornull(id);with this…
InfiniteBus *bus = bus_owner.getornull(id);Next, make a file called from prime_225.h and copy the code for prime_225.h mentioned here…
https://docs.godotengine.org/en/3.1/development/cpp/custom_godot_servers.htmlNext make a file called InfiniteBus.h and then copy the code for InfiniteBus.h mentioned here…
https://docs.godotengine.org/en/3.1/development/cpp/custom_godot_servers.htmlTo allow Godot to properly used the custom server, a dummy class needs to be made. It is not quite clear why this class needs to be made, but Godot needs it to make sure it references the right class instance when the server is called in the code.
The dummy class will be called…
_HilbertHotelThis is basically a class of the main custom server class with an underscore added at the beginning.
In _hilbert_hotel.h … copy it from the tutorial page then add this to the top of the file…
#include “hilbert_hotel.h”#include “core/list.h”
#include “core/object.h”
#include “core/os/thread.h”
#include “core/os/mutex.h”
#include “core/rid.h”
#include “core/set.h”
#include “core/variant.h”In _hlibert_hotel.cpp…copy it from the tutorial page and add this at the top of the file…
#include “_hilbert_hotel.h”In the directory…be sure to add the file…
config.py
it should have the following…
def can_build(env, platform):
return Truedef configure(env):
passin the directory…be sure to add the following file named…
SCSub# Put this code into the SCSub file…
Import(‘env’)module_env = env.Clone()
module_env.add_source_files(env.modules_sources,”*.cpp”)
module_env.Append(CXXFLAGS=[‘-O2’, ‘-std=c++11’])###############################
This helps SCons build your custom server.Once done, go to the main godot folder … then run SCons to rebuild everything.
Once it builds properly…go to the
/bin directory where the newly built app is placed…open it up and use the server…here is what I did…I made a new scene and added script to the Spatial node to test it out…I had to comment out HilbertHotel.finish() to get it to work properly… extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = “text”# Called when the node enters the scene tree for the first time.
func _ready():
print(“Start Debugging”)
var ridHilbertHotel.connect(“occupy_room”, self, “_print_occupy_room”)
OS.delay_msec(2000)
rid = HilbertHotel.create_bus()
OS.delay_msec(2000)
HilbertHotel.create_bus()
OS.delay_msec(2000)
HilbertHotel.create_bus()
OS.delay_msec(2000)
print(HilbertHotel.get_bus_info(rid))
HilbertHotel.delete_bus(rid)
print(“ready done”)
OS.delay_msec(5000)
# COMMENT OUT THIS LINE HilbertHotel.finish()pass # Replace with function body.
# Called every frame. ‘delta’ is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _print_occupy_room(room_number, r_id):
print(“Room Number : ” + str(room_number) + ” RID: ” + str(r_id))
print(HilbertHotel.get_bus_info(r_id))Source for the module directory could be downloaded here…
http://www.indiegamepod.com/podcasts/hilbert_hotel_custom_server.zipThe script to attach to spatial node can be found here…
http://www.indiegamepod.com/podcasts/Spatial.gdLeave a reply