Daniele Bartolini 8 лет назад
Родитель
Сommit
0fe3684a62

+ 2 - 4
src/device/device.cpp

@@ -113,6 +113,8 @@ struct BgfxCallback : public bgfx::CallbackI
 
 struct BgfxAllocator : public bx::AllocatorI
 {
+	ProxyAllocator _allocator;
+
 	BgfxAllocator(Allocator& a)
 		: _allocator(a, "bgfx")
 	{
@@ -134,10 +136,6 @@ struct BgfxAllocator : public bx::AllocatorI
 		_allocator.deallocate(_ptr);
 		return p;
 	}
-
-private:
-
-	ProxyAllocator _allocator;
 };
 
 static void console_command_script(ConsoleServer& /*cs*/, TCPSocket /*client*/, const char* json, void* user_data)

+ 1 - 2
src/device/device.h

@@ -66,8 +66,7 @@ struct Device
 
 	bool process_events(bool vsync);
 
-public:
-
+	///
 	Device(const DeviceOptions& opts, ConsoleServer& cs);
 
 	/// Runs the engine.

+ 4 - 6
src/device/main_android.cpp

@@ -41,6 +41,10 @@ s32 func(void* data)
 
 struct AndroidDevice
 {
+	DeviceEventQueue _queue;
+	Thread _main_thread;
+	MainThreadArgs _margs;
+
 	void run(struct android_app* app, DeviceOptions& opts)
 	{
 		_margs.opts = &opts;
@@ -206,12 +210,6 @@ struct AndroidDevice
 	{
 		((AndroidDevice*) app->userData)->process_command(app, cmd);
 	}
-
-public:
-
-	DeviceEventQueue _queue;
-	Thread _main_thread;
-	MainThreadArgs _margs;
 };
 
 struct WindowAndroid : public Window

+ 7 - 11
src/device/main_linux.cpp

@@ -310,6 +310,13 @@ s32 func(void* data)
 
 struct LinuxDevice
 {
+	::Display* _x11_display;
+	Atom _wm_delete_message;
+	XRRScreenConfiguration* _screen_config;
+	bool _x11_detectable_autorepeat;
+	DeviceEventQueue _queue;
+	Joypad _joypad;
+
 	LinuxDevice()
 		: _x11_display(NULL)
 		, _screen_config(NULL)
@@ -478,15 +485,6 @@ struct LinuxDevice
 		XCloseDisplay(_x11_display);
 		return EXIT_SUCCESS;
 	}
-
-public:
-
-	::Display* _x11_display;
-	Atom _wm_delete_message;
-	XRRScreenConfiguration* _screen_config;
-	bool _x11_detectable_autorepeat;
-	DeviceEventQueue _queue;
-	Joypad _joypad;
 };
 
 static LinuxDevice s_ldvc;
@@ -497,8 +495,6 @@ struct WindowX11 : public Window
 	Cursor _x11_hidden_cursor;
 	Atom _wm_delete_message;
 
-public:
-
 	WindowX11()
 		: _x11_window(None)
 		, _x11_hidden_cursor(None)

+ 4 - 6
src/device/main_windows.cpp

@@ -341,6 +341,10 @@ s32 func(void* data)
 
 struct WindowsDevice
 {
+	HWND _hwnd;
+	DeviceEventQueue _queue;
+	Joypad _joypad;
+
 	WindowsDevice()
 		: _hwnd(NULL)
 	{
@@ -532,12 +536,6 @@ struct WindowsDevice
 	}
 
 	static LRESULT CALLBACK window_proc(HWND hwnd, UINT id, WPARAM wparam, LPARAM lparam);
-
-public:
-
-	HWND _hwnd;
-	DeviceEventQueue _queue;
-	Joypad _joypad;
 };
 
 static WindowsDevice s_wdvc;

+ 20 - 3
src/resource/compile_options.h

@@ -35,7 +35,7 @@
 
 namespace crown
 {
-class CompileOptions
+struct CompileOptions
 {
 	DataCompiler& _data_compiler;
 	Filesystem& _data_filesystem;
@@ -43,48 +43,65 @@ class CompileOptions
 	const char* _platform;
 	Vector<DynamicString> _dependencies;
 
-public:
-
+	///
 	CompileOptions(DataCompiler& dc, Filesystem& data_filesystem, Buffer& output, const char* platform);
 
+	///
 	void error(const char* msg, va_list args);
 
+	///
 	void error(const char* msg, ...);
 
+	///
 	bool file_exists(const char* path);
 
+	///
 	bool resource_exists(const char* type, const char* name);
 
+	///
 	Buffer read_temporary(const char* path);
 
+	///
 	void write_temporary(const char* path, const char* data, u32 size);
 
+	///
 	void write_temporary(const char* path, const Buffer& data);
 
+	///
 	Buffer read(const char* path);
 
+	///
 	void get_absolute_path(const char* path, DynamicString& abs);
 
+	///
 	void get_temporary_path(const char* suffix, DynamicString& abs);
 
+	///
 	void delete_file(const char* path);
 
+	///
 	void write(const void* data, u32 size);
 
+	///
 	template <typename T>
 	void write(const T& data)
 	{
 		write(&data, sizeof(data));
 	}
 
+	///
 	void write(const Buffer& data);
 
+	///
 	const char* platform() const;
 
+	///
 	const Vector<DynamicString>& dependencies() const;
 
+	///
 	void add_dependency(const char* path);
 
+	///
 	int run_external_compiler(const char* const* argv, StringStream& output);
 };
 

+ 2 - 2
src/resource/compiler_types.h

@@ -7,7 +7,7 @@
 
 namespace crown
 {
-class DataCompiler;
-class CompileOptions;
+struct CompileOptions;
+struct DataCompiler;
 
 } // namespace crown

+ 1 - 3
src/resource/data_compiler.cpp

@@ -41,14 +41,12 @@ namespace { const crown::log_internal::System COMPILER = { "Compiler" }; }
 
 namespace crown
 {
-class LineReader
+struct LineReader
 {
 	const char* _str;
 	const u32 _len;
 	u32 _pos;
 
-public:
-
 	LineReader(const char* str)
 		: _str(str)
 		, _len(strlen32(str))

+ 7 - 3
src/resource/data_compiler.h

@@ -17,7 +17,7 @@ namespace crown
 /// Compiles source data into binary.
 ///
 /// @ingroup Resource
-class DataCompiler
+struct DataCompiler
 {
 	typedef void (*CompileFunction)(const char* path, CompileOptions& opts);
 
@@ -46,12 +46,16 @@ class DataCompiler
 	void filemonitor_callback(FileMonitorEvent::Enum fme, bool is_dir, const char* path, const char* path_renamed);
 	static void filemonitor_callback(void* thiz, FileMonitorEvent::Enum fme, bool is_dir, const char* path_original, const char* path_modified);
 
-public:
-
+	///
 	DataCompiler(ConsoleServer& cs);
+
+	///
 	~DataCompiler();
 
+	///
 	void map_source_dir(const char* name, const char* source_dir);
+
+	///
 	void source_dir(const char* resource_name, DynamicString& source_dir);
 
 	/// Adds a @a glob pattern to ignore when scanning the source directory.

+ 3 - 3
src/resource/resource_loader.h

@@ -29,7 +29,7 @@ struct ResourceRequest
 /// Loads resources in a background thread.
 ///
 /// @ingroup Resource
-class ResourceLoader
+struct ResourceLoader
 {
 	Filesystem& _data_filesystem;
 
@@ -46,10 +46,10 @@ class ResourceLoader
 	s32 run();
 	static s32 thread_proc(void* thiz);
 
-public:
-
 	/// Read resources from @a data_filesystem.
 	ResourceLoader(Filesystem& data_filesystem);
+
+	///
 	~ResourceLoader();
 
 	/// Returns whether the resource (type, name) can be loaded.

+ 3 - 3
src/resource/resource_manager.h

@@ -17,7 +17,7 @@ namespace crown
 /// Keeps track and manages resources loaded by ResourceLoader.
 ///
 /// @ingroup Resource
-class ResourceManager
+struct ResourceManager
 {
 	typedef void* (*LoadFunction)(File& file, Allocator& a);
 	typedef void (*OnlineFunction)(StringId64 name, ResourceManager& rm);
@@ -71,10 +71,10 @@ class ResourceManager
 	void on_unload(StringId64 type, void* data);
 	void complete_request(StringId64 type, StringId64 name, void* data);
 
-public:
-
 	/// Uses @a rl to load resources.
 	ResourceManager(ResourceLoader& rl);
+
+	///
 	~ResourceManager();
 
 	/// Loads the resource (@a type, @a name).

+ 3 - 2
src/resource/resource_package.h

@@ -19,9 +19,10 @@ struct ResourcePackage
 	StringId64 _package_id;
 	const PackageResource* _package;
 
-public:
-
+	///
 	ResourcePackage(StringId64 id, ResourceManager& resman);
+
+	///
 	~ResourcePackage();
 
 	/// Loads all the resources in the package.

+ 2 - 2
src/resource/resource_types.h

@@ -8,8 +8,8 @@
 /// @defgroup Resource Resource
 namespace crown
 {
-class ResourceLoader;
-class ResourceManager;
+struct ResourceLoader;
+struct ResourceManager;
 struct ResourcePackage;
 
 struct ActorResource;

+ 0 - 1
src/resource/sprite_resource.h

@@ -11,7 +11,6 @@
 #include "resource_types.h"
 #include "string_id.h"
 #include "types.h"
-#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 2 - 3
src/resource/unit_compiler.h

@@ -12,7 +12,7 @@
 
 namespace crown
 {
-class UnitCompiler
+struct UnitCompiler
 {
 	typedef Buffer (*CompileFunction)(const char* json, CompileOptions& opts);
 
@@ -58,8 +58,7 @@ class UnitCompiler
 	Buffer compile_component(StringId32 type, const char* json);
 	void add_component_data(StringId32 type, const Buffer& data, u32 unit_index);
 
-public:
-
+	///
 	UnitCompiler(CompileOptions& opts);
 
 	Buffer read_unit(const char* name);

+ 23 - 0
src/world/debug_gui.h

@@ -40,23 +40,46 @@ struct DebugGui
 	Matrix4x4 _world;
 	bgfx::VertexDecl _pos_tex_col;
 
+	///
 	DebugGui(ResourceManager& rm, ShaderManager& sm, MaterialManager& mm, u16 width, u16 height);
+
+	///
 	~DebugGui();
 
+	///
 	Vector2 resolution() const;
+
+	///
 	void move(const Vector2& pos);
 
+	///
 	Vector2 screen_to_gui(const Vector2& pos);
 
+	///
 	void triangle(const Vector3& a, const Vector3& b, const Vector3& c, StringId64 material, const Color4& color);
 
+	///
 	void rect3d(const Vector3& pos, const Vector2& size, StringId64 material, const Color4& color);
+
+	///
 	void rect(const Vector2& pos, const Vector2& size, StringId64 material, const Color4& color);
+
+	///
 	void image3d(const Vector3& pos, const Vector2& size, StringId64 material, const Color4& color);
+
+	///
 	void image(const Vector2& pos, const Vector2& size, StringId64 material, const Color4& color);
+
+	///
 	void image3d_uv(const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, StringId64 material, const Color4& color);
+
+	///
 	void image_uv(const Vector2& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, StringId64 material, const Color4& color);
+
+	///
 	void text3d(const Vector3& pos, u32 font_size, const char* str, StringId64 font, StringId64 material, const Color4& color);
+
+	///
 	void text(const Vector2& pos, u32 font_size, const char* str, StringId64 font, StringId64 material, const Color4& color);
 };
 

+ 2 - 0
src/world/debug_line.h

@@ -41,6 +41,8 @@ struct DebugLine
 
 	/// Whether to enable @a depth_test
 	DebugLine(ShaderManager& sm, bool depth_test);
+
+	///
 	~DebugLine();
 
 	/// Adds a line from @a start to @a end with the given @a color.

+ 4 - 2
src/world/level.h

@@ -25,11 +25,13 @@ struct Level
 	const LevelResource* _resource;
 	Array<UnitId> _unit_lookup;
 
-public:
-
+	///
 	Level(Allocator& a, UnitManager& um, World& w, const LevelResource& lr);
+
+	///
 	~Level();
 
+	///
 	void load(const Vector3& pos, const Quaternion& rot);
 };
 

+ 1 - 0
src/world/material.h

@@ -19,6 +19,7 @@ struct Material
 	const MaterialResource* _resource;
 	char* _data;
 
+	///
 	void bind(ResourceManager& rm, ShaderManager& sm, u8 view = 0) const;
 
 	/// Sets the @a value of the variable @a name.

+ 10 - 2
src/world/material_manager.h

@@ -20,14 +20,22 @@ struct MaterialManager
 	ResourceManager* _resource_manager;
 	SortMap<StringId64, Material*> _materials;
 
-public:
-
+	///
 	MaterialManager(Allocator& a, ResourceManager& rm);
+
+	///
 	~MaterialManager();
 
+	///
 	void* load(File& file, Allocator& a);
+
+	///
 	void online(StringId64 id, ResourceManager& rm);
+
+	///
 	void offline(StringId64 id, ResourceManager& rm);
+
+	///
 	void unload(Allocator& a, void* res);
 
 	/// Creates the material @a id.

+ 3 - 9
src/world/physics_world_bullet.cpp

@@ -105,9 +105,9 @@ static Quaternion to_quaternion(const btQuaternion& q)
 	return quaternion(q.x(), q.y(), q.z(), q.w());
 }
 
-class MyDebugDrawer : public btIDebugDraw
+struct MyDebugDrawer : public btIDebugDraw
 {
-public:
+	DebugLine* _lines;
 
 	MyDebugDrawer(DebugLine& dl)
 		: _lines(&dl)
@@ -148,13 +148,9 @@ public:
 			| DBG_FastWireframe
 			;
 	}
-
-public:
-
-	DebugLine* _lines;
 };
 
-class MyFilterCallback : public btOverlapFilterCallback
+struct MyFilterCallback : public btOverlapFilterCallback
 {
 	bool needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const
 	{
@@ -1020,8 +1016,6 @@ struct PhysicsWorldImpl
 		((PhysicsWorldImpl*)user_ptr)->unit_destroyed_callback(id);
 	}
 
-private:
-
 	ColliderInstance make_collider_instance(u32 i) { ColliderInstance inst = { i }; return inst; }
 	ActorInstance make_actor_instance(u32 i) { ActorInstance inst = { i }; return inst; }
 	ControllerInstance make_controller_instance(u32 i) { ControllerInstance inst = { i }; return inst; }

+ 2 - 4
src/world/physics_world_noop.cpp

@@ -25,6 +25,8 @@ namespace physics_globals
 
 struct PhysicsWorldImpl
 {
+	EventStream _events;
+
 	PhysicsWorldImpl(Allocator& a)
 		: _events(a)
 	{
@@ -297,14 +299,10 @@ struct PhysicsWorldImpl
 	{
 	}
 
-private:
-
 	ColliderInstance make_collider_instance(u32 i) { ColliderInstance inst = { i }; return inst; }
 	ActorInstance make_actor_instance(u32 i) { ActorInstance inst = { i }; return inst; }
 	ControllerInstance make_controller_instance(u32 i) { ControllerInstance inst = { i }; return inst; }
 	JointInstance make_joint_instance(u32 i) { JointInstance inst = { i }; return inst; }
-
-	EventStream _events;
 };
 
 PhysicsWorld::PhysicsWorld(Allocator& a, ResourceManager& rm, UnitManager& um, DebugLine& dl)

+ 3 - 2
src/world/render_world.h

@@ -20,9 +20,10 @@ namespace crown
 /// @ingroup World
 struct RenderWorld
 {
-public:
-
+	///
 	RenderWorld(Allocator& a, ResourceManager& rm, ShaderManager& sm, MaterialManager& mm, UnitManager& um);
+
+	///
 	~RenderWorld();
 
 	/// Creates a new mesh instance.

+ 3 - 0
src/world/scene_graph.h

@@ -64,7 +64,10 @@ struct SceneGraph
 	InstanceData _data;
 	HashMap<UnitId, u32> _map;
 
+	///
 	SceneGraph(Allocator& a, UnitManager& um);
+
+	///
 	~SceneGraph();
 
 	/// Creates a new transform instance for unit @a id.

+ 10 - 2
src/world/shader_manager.h

@@ -30,14 +30,22 @@ struct ShaderManager
 
 	void add_shader(StringId32 name, u64 state, bgfx::ProgramHandle program);
 
-public:
-
+	///
 	ShaderManager(Allocator& a);
 
+	///
 	void* load(File& file, Allocator& a);
+
+	///
 	void online(StringId64 id, ResourceManager& rm);
+
+	///
 	void offline(StringId64 id, ResourceManager& rm);
+
+	///
 	void unload(Allocator& a, void* res);
+
+	///
 	void submit(StringId32 shader_id, u8 view_id);
 };
 

+ 7 - 7
src/world/unit_manager.cpp

@@ -3,9 +3,9 @@
  * License: https://github.com/taylor001/crown/blob/master/LICENSE
  */
 
-#include "unit_manager.h"
 #include "array.h"
 #include "queue.h"
+#include "unit_manager.h"
 #include "world.h"
 
 #define MINIMUM_FREE_INDICES 1024
@@ -63,19 +63,19 @@ void UnitManager::destroy(UnitId id)
 	trigger_destroy_callbacks(id);
 }
 
-void UnitManager::register_destroy_function(DestroyFunction fn, void* user_ptr)
+void UnitManager::register_destroy_function(DestroyFunction fn, void* user_data)
 {
 	DestroyData dd;
 	dd.destroy = fn;
-	dd.user_ptr = user_ptr;
+	dd.user_data = user_data;
 	array::push_back(_destroy_callbacks, dd);
 }
 
-void UnitManager::unregister_destroy_function(void* user_ptr)
+void UnitManager::unregister_destroy_function(void* user_data)
 {
 	for (u32 i = 0, n = array::size(_destroy_callbacks); i < n; ++i)
 	{
-		if (_destroy_callbacks[i].user_ptr == user_ptr)
+		if (_destroy_callbacks[i].user_data == user_data)
 		{
 			_destroy_callbacks[i] = _destroy_callbacks[n - 1];
 			array::pop_back(_destroy_callbacks);
@@ -83,13 +83,13 @@ void UnitManager::unregister_destroy_function(void* user_ptr)
 		}
 	}
 
-	CE_FATAL("Bad destroy function");
+	CE_FATAL("Unknown destroy function");
 }
 
 void UnitManager::trigger_destroy_callbacks(UnitId id)
 {
 	for (u32 i = 0; i < array::size(_destroy_callbacks); ++i)
-		_destroy_callbacks[i].destroy(id, _destroy_callbacks[i].user_ptr);
+		_destroy_callbacks[i].destroy(id, _destroy_callbacks[i].user_data);
 }
 
 } // namespace crown

+ 8 - 9
src/world/unit_manager.h

@@ -17,23 +17,22 @@ namespace crown
 /// @ingroup World
 struct UnitManager
 {
-	Array<u8> _generation;
-	Queue<u32> _free_indices;
-
-	typedef void (*DestroyFunction)(UnitId unit, void* user_ptr);
+	typedef void (*DestroyFunction)(UnitId unit, void* user_data);
 
 	struct DestroyData
 	{
 		DestroyFunction destroy;
-		void* user_ptr;
+		void* user_data;
 	};
 
+	Array<u8> _generation;
+	Queue<u32> _free_indices;
 	Array<DestroyData> _destroy_callbacks;
 
-public:
-
+	///
 	UnitManager(Allocator& a);
 
+	///
 	UnitId make_unit(u32 idx, u8 gen);
 
 	/// Creates a new empty unit.
@@ -48,9 +47,9 @@ public:
 	/// Destroys the unit @a id.
 	void destroy(UnitId id);
 
-	void register_destroy_function(DestroyFunction fn, void* user_ptr);
+	void register_destroy_function(DestroyFunction fn, void* user_data);
 
-	void unregister_destroy_function(void* user_ptr);
+	void unregister_destroy_function(void* user_data);
 
 	void trigger_destroy_callbacks(UnitId id);
 };

+ 3 - 2
src/world/world.h

@@ -65,9 +65,10 @@ struct World
 
 	CameraInstance camera_make_instance(u32 i) { CameraInstance inst = { i }; return inst; }
 
-public:
-
+	///
 	World(Allocator& a, ResourceManager& rm, ShaderManager& sm, MaterialManager& mm, UnitManager& um, LuaEnvironment& env);
+
+	///
 	~World();
 
 	/// Spawns a new instance of the unit @a name at the given @a position and @a rotation.