Преглед изворни кода

pass ref Window instead of Window*

Zoadian пре 11 година
родитељ
комит
2de9ac36f2
2 измењених фајлова са 47 додато и 38 уклоњено
  1. 23 14
      source/app.d
  2. 24 24
      source/three/window.d

+ 23 - 14
source/app.d

@@ -40,6 +40,10 @@ void main() {
 	OpenGlTiledDeferredRenderer renderer;
 	bool keepRunning = true;
 
+
+	//------------------------------------------------
+	// Load and Construct Rendering Pipeline
+	//------------------------------------------------
 	DerelictGL3.load();
 	DerelictGLFW3.load();
 	DerelictFI.load();
@@ -68,14 +72,24 @@ void main() {
 	renderTarget.construct(window.width, window.height); scope(exit) renderTarget.destruct();
 	renderer.construct(window.width, window.height); scope(exit) renderer.destruct();
 
+
+	//------------------------------------------------
+	// Create Scene
+	//------------------------------------------------
 	scene.mesh.loadModel("C:/Coding/models/Collada/duck.dae");
 
 
+	//------------------------------------------------
+	// Generate TweakBar
+	//------------------------------------------------
 	TwWindowSize(window.width, window.height);
 	auto tweakBar = TwNewBar("TweakBar");
 
 
-	window.onKey = (Window* pWindow, Key key, ScanCode scanCode, KeyAction action, KeyMod keyMod) {
+	//------------------------------------------------
+	// Connect Window callbacks
+	//------------------------------------------------
+	window.onKey = (ref Window rWindow, Key key, ScanCode scanCode, KeyAction action, KeyMod keyMod) {
 		if(window is window && action == KeyAction.Pressed) {
 			if(key == Key.Escape) {
 				keepRunning = false;
@@ -83,18 +97,18 @@ void main() {
 		}
 	};
 
-	window.onClose = (Window* pWindow) {
+	window.onClose = (ref Window rWindow) {
 		keepRunning = false;
 	};
 
-	window.onSize = (Window* pWindow, int width, int height) {
+	window.onSize = (ref Window rWindow, int width, int height) {
 		TwWindowSize(width, height);		
 	};
 
-	window.onPosition = (Window* pWindow, int x, int y) {		
+	window.onPosition = (ref Window rWindow, int x, int y) {
 	};
 
-	window.onButton = (Window* pWindow , int button, ButtonAction action) {
+	window.onButton = (ref Window rWindow , int button, ButtonAction action) {
 		TwMouseAction twaction = action == ButtonAction.Pressed ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;
 		TwMouseButtonID twbutton;
 		
@@ -108,19 +122,14 @@ void main() {
 		TwMouseButton(twaction, twbutton);		
 	};
 
-	window.onCursorPos = (Window* pWindow, double x, double y) {
+	window.onCursorPos = (ref Window rWindow, double x, double y) {
 		TwMouseMotion(cast(int)x, window.height - cast(int)y);
 	};
 
 
-
-
-
-
-
-
-
-
+	//------------------------------------------------
+	// Main Loop
+	//------------------------------------------------
 	while(keepRunning) {
 		window.pollEvents();
 

+ 24 - 24
source/three/window.d

@@ -10,18 +10,18 @@ private:
 	ButtonAction[int] _buttonStates;
 
 public:							
-	void delegate(Window*, int, int) onPosition;	 
-	void delegate(Window*, int, int) onSize;	 
-	void delegate(Window*) onClose;		
-	void delegate(Window*) onRefresh;			
-	void delegate(Window*, FocusAction) onFocus;	  
-	void delegate(Window*, IconifyAction) onIconify;	
-	void delegate(Window*, bool) onCursorEnter;		
-	void delegate(Window*, int, ButtonAction) onButton;	
-	void delegate(Window*, double, double) onCursorPos; 
-	void delegate(Window*, double, double) onScroll;	
-	void delegate(Window*, Key, ScanCode, KeyAction, KeyMod) onKey;   
-	void delegate(Window*, int) onChar;
+	void delegate(ref Window, int, int) onPosition;	 
+	void delegate(ref Window, int, int) onSize;	 
+	void delegate(ref Window) onClose;		
+	void delegate(ref Window) onRefresh;			
+	void delegate(ref Window, FocusAction) onFocus;	  
+	void delegate(ref Window, IconifyAction) onIconify;	
+	void delegate(ref Window, bool) onCursorEnter;		
+	void delegate(ref Window, int, ButtonAction) onButton;	
+	void delegate(ref Window, double, double) onCursorPos; 
+	void delegate(ref Window, double, double) onScroll;	
+	void delegate(ref Window, Key, ScanCode, KeyAction, KeyMod) onKey;   
+	void delegate(ref Window, int) onChar;
 }
 
 alias ScanCode = int;
@@ -308,64 +308,64 @@ private extern(C) void _GLFWwindowposfun(GLFWwindow* glfwWindow, int x, int y) {
 	window._y = y;
 	window._width = w;
 	window._height = h;
-	if(window.onPosition) window.onPosition(window, x, y);
+	if(window.onPosition) window.onPosition(*window, x, y);
 }
 
 private extern(C) void _GLFWwindowsizefun(GLFWwindow* glfwWindow, int width, int height) {												 
 	Window* window = _castWindow(glfwWindow);
 	window._width = width;
 	window._height = height;
-	if(window.onSize) window.onSize(window, width, height);
+	if(window.onSize) window.onSize(*window, width, height);
 }
 
 private extern(C) void _GLFWwindowclosefun(GLFWwindow* glfwWindow) {				  
 	Window* window = _castWindow(glfwWindow);
-	if(window.onClose) window.onClose(window);
+	if(window.onClose) window.onClose(*window);
 }
 
 private extern(C) void _GLFWwindowrefreshfun(GLFWwindow* glfwWindow) {													 
 	Window* window = _castWindow(glfwWindow);
-	if(window.onRefresh) window.onRefresh(window);
+	if(window.onRefresh) window.onRefresh(*window);
 }
 
 private extern(C) void _GLFWwindowfocusfun(GLFWwindow* glfwWindow, int focused) {													 
 	Window* window = _castWindow(glfwWindow);
-	if(window.onFocus) window.onFocus(window, (focused == GL_TRUE) ? FocusAction.Focused : FocusAction.Defocused);
+	if(window.onFocus) window.onFocus(*window, (focused == GL_TRUE) ? FocusAction.Focused : FocusAction.Defocused);
 }
 
 private extern(C) void _GLFWwindowiconifyfun(GLFWwindow* glfwWindow, int iconified) {												 
 	Window* window = _castWindow(glfwWindow);
-	if(window.onIconify) window.onIconify(window, (iconified == GL_TRUE) ? IconifyAction.Iconified : IconifyAction.Restored);
+	if(window.onIconify) window.onIconify(*window, (iconified == GL_TRUE) ? IconifyAction.Iconified : IconifyAction.Restored);
 }
 
 private extern(C) void _GLFWcursorenterfun(GLFWwindow* glfwWindow, int entered) {
 	Window* window = _castWindow(glfwWindow);
-	if(window.onCursorEnter) window.onCursorEnter(window, (entered == GL_TRUE) ? CursorAction.Entered : CursorAction.Leaved);
+	if(window.onCursorEnter) window.onCursorEnter(*window, (entered == GL_TRUE) ? CursorAction.Entered : CursorAction.Leaved);
 }
 
 private extern(C) void _GLFWmousebuttonfun(GLFWwindow* glfwWindow, int button, int action) { 
 	Window* window = _castWindow(glfwWindow);
 	window._buttonStates[button] = (action == GLFW_PRESS) ? ButtonAction.Pressed : ButtonAction.Released;
-	if(window.onButton) window.onButton(window, button, (action == GLFW_PRESS) ? ButtonAction.Pressed : ButtonAction.Released);
+	if(window.onButton) window.onButton(*window, button, (action == GLFW_PRESS) ? ButtonAction.Pressed : ButtonAction.Released);
 }
 
 private extern(C) void _GLFWcursorposfun(GLFWwindow* glfwWindow, double x, double y) {
 	Window* window = _castWindow(glfwWindow);
-	if(window.onCursorPos) window.onCursorPos(window, x, window._height - y);
+	if(window.onCursorPos) window.onCursorPos(*window, x, window._height - y);
 }
 
 private extern(C) void _GLFWscrollfun(GLFWwindow* glfwWindow, double x, double y) {	
 	Window* window = _castWindow(glfwWindow);
-	if(window.onScroll) window.onScroll(window, x, y);
+	if(window.onScroll) window.onScroll(*window, x, y);
 }
 
 private extern(C) void _GLFWkeyfun(GLFWwindow* glfwWindow, int key, int scancode, int action, int mods) {  
 	Window* window = _castWindow(glfwWindow);
 	window._keyStates[key] = (action == GLFW_PRESS || action == GLFW_REPEAT) ? KeyAction.Pressed : KeyAction.Released;
-	if(window.onKey) window.onKey(window, cast(Key)key, cast(ScanCode)scancode, cast(KeyAction)action, cast(KeyMod)mods);
+	if(window.onKey) window.onKey(*window, cast(Key)key, cast(ScanCode)scancode, cast(KeyAction)action, cast(KeyMod)mods);
 }
 
 private extern(C) void _GLFWcharfun(GLFWwindow* glfwWindow, uint character) { 
 	Window* window = _castWindow(glfwWindow);
-	if(window.onChar) window.onChar(window, character);
+	if(window.onChar) window.onChar(*window, character);
 }