Changeset 56
- Timestamp:
- 07/25/07 20:40:41 (1 year ago)
- Files:
-
- trunk/proj/buildme.d (modified) (2 diffs)
- trunk/res/obj (added)
- trunk/res/obj/cube.mtl (added)
- trunk/res/obj/cube.obj (added)
- trunk/res/obj/gargoyle.mtl (added)
- trunk/res/obj/gargoyle.obj (added)
- trunk/res/obj/sphere.mtl (added)
- trunk/res/obj/sphere.obj (added)
- trunk/res/obj/tieFighter.mtl (added)
- trunk/res/obj/tieFighter.obj (added)
- trunk/res/obj/torus.mtl (added)
- trunk/res/obj/torus.obj (added)
- trunk/src/demo1/main.d (modified) (4 diffs)
- trunk/src/demo1/ship.d (modified) (2 diffs)
- trunk/src/demo2/main.d (modified) (15 diffs)
- trunk/src/demo2/ship.d (modified) (2 diffs)
- trunk/src/yage/gui/surface.d (modified) (3 diffs)
- trunk/src/yage/node/scene.d (modified) (1 diff)
- trunk/src/yage/resource/all.d (modified) (1 diff)
- trunk/src/yage/resource/model.d (modified) (4 diffs)
- trunk/src/yage/resource/modelloader.d (deleted)
- trunk/src/yage/resource/ms3dloader.d (added)
- trunk/src/yage/resource/objloader.d (added)
- trunk/src/yage/system/device.d (modified) (5 diffs)
- trunk/src/yage/system/input.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/proj/buildme.d
r35 r56 1 #! ~/bin/dmd -run1 #!dmd -run 2 2 /** 3 3 * Copyright: Public Domain … … 36 36 // Paths are relative to the build script. 37 37 char[] mod_path = "../src"; // The root folder of all modules 38 char[][] src_path = ["../src/yage", "../src/demo 1"];// Array of folders to look for source files38 char[][] src_path = ["../src/yage", "../src/demo2"];// Array of folders to look for source files 39 39 char[][] imp_path = ["../src/derelict"]; // Array of folders to look for imports 40 40 char[][] lib_path = ["../lib"]; // Array of folders to scan for libraries trunk/src/demo1/main.d
r53 r56 40 40 Scene scene = new Scene(); 41 41 scene.start(60); // update 60 times per second 42 scope(exit)scene.stop(); 43 42 43 Device.onExit = &scene.stop; 44 44 45 // Skybox 45 46 Scene skybox = new Scene(); … … 66 67 67 68 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 68 self.grabMouse(!Input.getGrabMouse()); 69 self.grabMouse(!ship.input); 70 ship.input = !ship.input; 71 } 72 73 void onMousemove(Surface self, byte buttons, Vec2i rel){ 74 if(ship.input){ 75 ship.mouseDelta = ship.mouseDelta.add(rel); 76 } 69 77 } 70 78 71 79 void onResize(Surface self){ 72 80 camera.setResolution(self.size.x, self.size.y); 73 writefln(" Resolution changed to ", self.size.x, " x ", self.size.y);81 writefln("Camera resolution changed to ", self.size.x, " x ", self.size.y); 74 82 } 75 83 76 disp.onMousedown = &onMousedown; 84 void onKeydown(Surface self, byte key){ 85 if (Input.keydown[SDLK_ESCAPE]) 86 Device.exit(0); 87 } 88 89 disp.onMousedown = &onMousedown; 77 90 disp.onResize = &onResize; 78 91 disp.onMousemove = &onMousemove; 92 disp.onKeydown = &onKeydown; 93 79 94 // Music 80 95 SoundNode music = new SoundNode(camera); … … 106 121 107 122 // Add to the scene's update loop 108 Input.getMouseDelta(); 109 void update(BaseNode self) 110 { // check for exit 111 if (Input.keydown[SDLK_ESCAPE]) 112 Input.exit=true; 113 114 // Toggle mouse grab 115 // if (Input.button[1].up) 116 // { Input.button[1].up = false; 117 // Input.setGrabMouse(!Input.getGrabMouse()); 118 // } 123 void update(BaseNode self){ 119 124 ship.getSpring().update(1/60.0f); 120 125 } … … 129 134 Timer delta = new Timer(); 130 135 Log.write("Starting rendering loop."); 131 while( !Input.exit)136 while(1) 132 137 { 133 138 float dtime = delta.get(); trunk/src/demo1/ship.d
r49 r56 19 19 Spring spring; // spring to attach camera 20 20 SoundNode sound; 21 22 Vec2i mouseDelta; 23 bool input = false; 21 24 22 25 float ldamp=.5, xdamp=2, ydamp=2; … … 96 99 97 100 // Rotate 98 if (Input.getGrabMouse()) 99 { 100 Vec2f m = Input.getMouseDelta(); 101 angularAccelerate(Vec3f(0, m.x/16.0, 0)); 102 pitch.angularAccelerate(Vec3f(-m.y/24.0, 0, 0)); 101 if (input){ 102 angularAccelerate(Vec3f(0, -mouseDelta.x/16.0, 0)); 103 pitch.angularAccelerate(Vec3f(mouseDelta.y/24.0, 0, 0)); 104 mouseDelta.x = mouseDelta.y = 0; 103 105 } 104 106 trunk/src/demo2/main.d
r54 r56 1 1 /** 2 2 * Copyright: (c) 2005-2007 Eric Poggel 3 * Authors: Eric Poggel 3 * Authors: Eric Poggel, Joe Pusdesris (deformative0@gmail.com) 4 4 * License: <a href="lgpl.txt">LGPL</a> 5 5 * … … 18 18 19 19 import demo2.ship; 20 import demo2.gameobj; 20 21 21 22 // Current program entry point. This may change in the future. 22 int main() 23 { 24 25 // Init (resolution, depth, fullscreen, aa-samples) 23 int main(){ 24 25 // Init (resolution, depth, fullscreen, aa-samples) 26 26 Device.init(800, 600, 32, false, 1); 27 27 //Device.init(1024, 768, 32, true); 28 28 //Device.init(1440, 900, 32, true); 29 29 30 30 // Paths 31 31 Resource.addPath("../res/"); … … 40 40 Scene scene = new Scene(); 41 41 scene.start(60); // update 60 times per second 42 scope(exit)scene.stop(); 42 43 Device.onExit = &scene.stop; 43 44 44 45 // Skybox … … 57 58 CameraNode camera = new CameraNode(ship.getCameraSpot()); 58 59 camera.setView(2, 20000, 60, 0, 1); // wide angle view 60 61 //new Model("obj/cube.obj"); 59 62 60 63 Surface bg = new Surface(null); … … 65 68 66 69 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 67 self.grabMouse(!Input.getGrabMouse()); 70 self.grabMouse(!ship.input); 71 ship.input = !ship.input; 72 } 73 74 void onMousemove(Surface self, byte buttons, Vec2i rel){ 75 if(ship.input){ 76 ship.mouseDelta = ship.mouseDelta.add(rel); 77 } 68 78 } 69 79 … … 73 83 } 74 84 85 void onKeydown(Surface self, byte key){ 86 if (Input.keydown[SDLK_ESCAPE]) 87 Device.exit(0); 88 } 89 75 90 bg.onMousedown = &onMousedown; 76 91 bg.onResize = &onResize; 92 bg.onMousemove = &onMousemove; 93 bg.onKeydown = &onKeydown; 77 94 78 95 GPUTexture active = new GPUTexture("test/clear.png"); … … 87 104 self.endDrag(); 88 105 } 89 void onMousemove (Surface self, byte buttons, Vec2i coordinates){90 if(buttons == 1) self.drag( coordinates);106 void onMousemove2(Surface self, byte buttons, Vec2i diff){ 107 if(buttons == 1) self.drag(diff); 91 108 } 92 109 void onMouseenter(Surface self, byte buttons, Vec2i coordinates){ … … 104 121 clear.setVisibility(true); 105 122 clear.onMousedown = &onMousedown2; 106 clear.onMousemove = &onMousemove ;123 clear.onMousemove = &onMousemove2; 107 124 clear.onMouseup = &onMouseup2; 108 125 clear.onMouseenter = &onMouseenter; … … 116 133 clear2.setVisibility(true); 117 134 clear2.onMousedown = &onMousedown2; 118 clear2.onMousemove = &onMousemove ;135 clear2.onMousemove = &onMousemove2; 119 136 clear2.onMouseup = &onMouseup2; 120 137 clear2.onMouseenter = &onMouseenter; … … 128 145 clear3.setVisibility(true); 129 146 clear3.onMousedown = &onMousedown2; 130 clear3.onMousemove = &onMousemove ;147 clear3.onMousemove = &onMousemove2; 131 148 clear3.onMouseup = &onMouseup2; 132 149 clear3.onMouseenter = &onMouseenter; … … 140 157 clear4.setVisibility(true); 141 158 clear4.onMousedown = &onMousedown2; 142 clear4.onMousemove = &onMousemove ;159 clear4.onMousemove = &onMousemove2; 143 160 clear4.onMouseup = &onMouseup2; 144 161 clear4.onMouseenter = &onMouseenter; … … 152 169 clear5.setVisibility(true); 153 170 clear5.onMousedown = &onMousedown2; 154 clear5.onMousemove = &onMousemove ;171 clear5.onMousemove = &onMousemove2; 155 172 clear5.onMouseup = &onMouseup2; 156 173 clear5.onMouseenter = &onMouseenter; … … 176 193 // Planet 177 194 auto planet = new ModelNode(scene); 178 planet.setModel(" space/planet.ms3d");195 planet.setModel("obj/tieFighter.obj"); 179 196 planet.setScale(60); 180 197 planet.setAngularVelocity(0, -0.01, 0); … … 186 203 187 204 // Add to the scene's update loop 188 //Input.getMouseDelta(); 189 void update(BaseNode self) 190 { // check for exit 191 if (Input.keydown[SDLK_ESCAPE]) 192 Input.exit=true; 205 void update(BaseNode self){ 193 206 ship.getSpring().update(1/60.0f); 194 207 } … … 202 215 Timer delta = new Timer(); 203 216 Log.write("Starting rendering loop."); 204 while(!Input.exit) 205 { 217 while(1){ 206 218 float dtime = delta.get(); 207 219 delta.reset(); trunk/src/demo2/ship.d
r49 r56 19 19 Spring spring; // spring to attach camera 20 20 SoundNode sound; 21 22 Vec2i mouseDelta; 23 bool input = false; 21 24 22 25 float ldamp=.5, xdamp=2, ydamp=2; … … 96 99 97 100 // Rotate 98 if (Input.getGrabMouse()) 99 { 100 Vec2f m = Input.getMouseDelta(); 101 angularAccelerate(Vec3f(0, m.x/16.0, 0)); 102 pitch.angularAccelerate(Vec3f(-m.y/24.0, 0, 0)); 101 if (input){ 102 angularAccelerate(Vec3f(0, -mouseDelta.x/16.0, 0)); 103 pitch.angularAccelerate(Vec3f(mouseDelta.y/24.0, 0, 0)); 104 mouseDelta.x = mouseDelta.y = 0; 103 105 } 104 106 trunk/src/yage/gui/surface.d
r49 r56 33 33 * The children will be positioned relative to the borders of their parent. */ 34 34 class Surface{ 35 //Not sure that a Surface should have a style... I think surface should be a lower abstraction, for only geometry, rendering, and input. 36 //static final Style defaultStyle; //Default style should be more fitting as something that is global. 37 //Style style; 35 static final Style defaultStyle; 36 Style style; 38 37 39 38 //Change from GPUTexture to Texture or Material … … 76 75 void delegate(typeof(this) self) onFocus; //Done -- See Raise, no fall through 77 76 78 void delegate(typeof(this) self, byte key, byte modifiers) onKeydown; 79 80 void delegate(typeof(this) self, byte key, byte modifiers) onKeypress; 81 82 void delegate(typeof(this) self, byte key, byte modifiers) onKeyup; 77 void delegate(typeof(this) self, byte key) onKeydown; 78 void keydown(byte key){ 79 if(onKeydown)onKeydown(this, key); 80 else if(parent !is null) parent.keydown(key); 81 } 82 83 void delegate(typeof(this) self, byte key, byte modifiers) onKeypress; //Why is this here when we have down? 84 85 void delegate(typeof(this) self, byte key) onKeyup; 86 void keyup(byte key){ 87 if(onKeyup)onKeyup(this, key); 88 else if(parent !is null) parent.keyup(key); 89 } 83 90 84 91 void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousedown; //Done … … 88 95 } 89 96 90 void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousemove; //Done91 void mousemove(byte buttons, Vec2i coordinates){92 if(onMousemove)onMousemove(this, buttons, coordinates);93 else if(parent !is null) parent.mousemove(buttons, coordinates);97 void delegate(typeof(this) self, byte buttons, Vec2i rel) onMousemove; //Done 98 void mousemove(byte buttons, Vec2i rel){ 99 if(onMousemove)onMousemove(this, buttons, rel); 100 else if(parent !is null) parent.mousemove(buttons, rel); 94 101 } 95 102 trunk/src/yage/node/scene.d
r53 r56 208 208 209 209 /// Stop updating the Scene. 210 synchronized void stop() 211 {repeater.stop();210 synchronized void stop(){ 211 repeater.stop(); 212 212 } 213 213 trunk/src/yage/resource/all.d
r28 r56 21 21 import yage.resource.sound; 22 22 import yage.resource.texture; 23 import yage.resource.font; 23 24 } trunk/src/yage/resource/model.d
r32 r56 7 7 module yage.resource.model; 8 8 9 import std.gc; 9 10 import std.string; 10 11 import std.file; … … 21 22 import yage.resource.mesh; 22 23 import yage.resource.resource; 23 import yage.resource.modelloader;24 24 import yage.node.node; 25 25 import yage.system.constant; 26 26 import yage.system.device; 27 27 import yage.system.log; 28 29 import yage.resource.ms3dloader; 30 import yage.resource.objloader; 28 31 29 32 … … 61 64 protected Attribute[char[]] attributes; // An associative array to store as many attributes as necessary 62 65 63 mixin M odelLoader;64 66 mixin Ms3dLoader; 67 mixin ObjLoader; 65 68 66 69 /// Generate buffers in video memory for the vertex data. … … 191 194 loadMs3d(filename); 192 195 break; 196 case "obj": 197 loadObj(filename); 198 fullCollect(); 199 break; 193 200 default: 194 201 throw new Exception("Unrecognized file format '"~ext~"'."); trunk/src/yage/system/device.d
r46 r56 22 22 import yage.system.log; 23 23 import yage.system.constant; 24 import yage.system.input;25 24 import yage.core.vector; 25 26 import std.c.stdlib : exit; 26 27 27 28 // Enable specular highlights with textures. … … 29 30 const int SINGLE_COLOR_EXT = 0x81F9; 30 31 const int SEPARATE_SPECULAR_COLOR_EXT = 0x81FA; 32 33 extern(C) { 34 void _moduleDtor(); 35 void gc_term(); 36 } 31 37 32 38 /** … … 63 69 { if (initialized) 64 70 { try { // Order of un-initialization is causing trouble here with OpenAL 71 //writefln("Device destructor"); 65 72 SDL_Quit(); 66 73 //alcDestroyContext(al_context); … … 190 197 SDL_EnableUNICODE(true); 191 198 SDL_EnableKeyRepeat(1, 100); 192 //Input.setGrabMouse(true);193 199 194 200 // Initialize OpenAL … … 202 208 Log.write("Yage has been initialized."); 203 209 } 204 210 211 static void delegate() onExit; 212 //Perhaps this needs to be improved, or maybe it will be added to the D runtime and no longer be needed 213 static void exit(int code){ 214 if(onExit) onExit(); 215 216 _moduleDtor(); 217 gc_term(); 218 std.c.stdlib.exit(code); 219 } 220 205 221 /** 206 222 * Searches to see if the given extension is supported in hardware.*/ trunk/src/yage/system/input.d
r49 r56 1 1 /** 2 2 * Copyright: (c) 2005-2007 Eric Poggel 3 * Authors: Eric Poggel 3 * Authors: Eric Poggel, Joe Pusdesris (deformative0@gmail.com) 4 4 * License: <a href="lgpl.txt">LGPL</a> 5 5 */ … … 24 24 25 25 static int mousex, mousey; /// The current pixel location of the mouse cursor; (0, 0) is top left. 26 static int mousedx, mousedy; /// The number of pixels the mouse has moved since the last time input was queried.27 28 //I do not know if this does the same as moused, I was too lazy to mod it for my needs.29 static int xdiff, ydiff;30 26 31 27 /// A structure to track various state variables associated with each mouse button. … … 40 36 static Buttons[8] button; /// An array to track the state of the mouse buttons 41 37 //static wchar[] stream; /// Recently typed text (unicode) 42 static bool grabbed=0; /// The window grabs the mouse. 43 static bool exit = false; /// A termination request has been received. 38 static bool grabbed=false; /// The window grabs the mouse. 44 39 45 40 static Surface surfaceLock; … … 57 52 while(SDL_PollEvent(&event)) 58 53 { 59 switch(event.type) 60 { 61 // Standard keyboard 62 case SDL_KEYDOWN: 63 keydown[event.key.keysym.sym] = true; 64 keyup[event.key.keysym.sym] = false; 54 processEvent(event); 55 } 56 } 57 58 static void processEvent(SDL_Event event){ 59 switch(event.type){ 60 // Standard keyboard 61 case SDL_KEYDOWN: 62 keydown[event.key.keysym.sym] = true; 63 keyup[event.key.keysym.sym] = false; 65 64 66 // Record text input 67 //if(event.key.keysym.unicode) 68 // stream ~= event.key.keysym.unicode & 0x7F; 69 //printf("key '%s' down\n", SDL_GetKeyName(event.key.keysym.sym)); 70 break; 71 case SDL_KEYUP: 65 auto surface = getSurface(); 66 67 if(surface !is null) 68 surface.keydown(event.key.keysym.sym); 69 70 break; 71 case SDL_KEYUP: 72 72 keyup[event.key.keysym.sym] = true; 73 73 keydown[event.key.keysym.sym] = false; 74 break; 74 75 auto surface = getSurface(); 75 76 77 if(surface !is null) 78 surface.keyup(event.key.keysym.sym); 79 80 break; 76 81 // Mouse 77 case SDL_MOUSEBUTTONDOWN:78 button[event.button.button].down = true;79 button[event.button.button].up = false;80 button[event.button.button].xdown = mousex;81 button[event.button.button].ydown = mousey;82 case SDL_MOUSEBUTTONDOWN: 83 button[event.button.button].down = true; 84 button[event.button.button].up = false; 85 button[event.button.button].xdown = mousex; 86 button[event.button.button].ydown = mousey; 82 87 83 auto surface = getSurface();88 auto surface = getSurface(); 84 89 85 if(surface !is null) surface.mousedown(event.button.button, Vec2i(mousex,mousey)); 90 if(surface !is null) 91 surface.mousedown(event.button.button, Vec2i(mousex,mousey)); 86 92 87 break;88 case SDL_MOUSEBUTTONUP:89 button[event.button.button].down = false;90 button[event.button.button].up = true;91 button[event.button.button].xup = mousex;92 button[event.button.button].yup = mousey;93 break; 94 case SDL_MOUSEBUTTONUP: 95 button[event.button.button].down = false; 96 button[event.button.button].up = true; 97 button[event.button.button].xup = mousex; 98 button[event.button.button].yup = mousey; 93 99 94 auto surface = getSurface();100 auto surface = getSurface(); 95 101 96 if(surface !is null) surface.mouseup(event.button.button, Vec2i(mousex,mousey)); 102 if(surface !is null) 103 surface.mouseup(event.button.button, Vec2i(mousex,mousey)); 97 104 98 break;99 case SDL_MOUSEMOTION:105 break; 106 case SDL_MOUSEMOTION: 100 107 101 mousedx = event.motion.xrel; // these seem to behave differently on linux 102 mousedy = event.motion.yrel; // than on win32. Testing should be done. 108 if(grabbed){ 109 if(event.motion.x != mousex || event.motion.y != mousey) 110 SDL_WarpMouse(mousex, mousey); 111 else break; 103 112 104 if(grabbed){ 105 if(event.motion.x != mousex || event.motion.y != mousey) 106 SDL_WarpMouse(mousex, mousey); 107 else break; 108 109 } 110 else{ 111 mousex = event.motion.x; 112 mousey = event.motion.y; 113 } 114 115 auto surface = getSurface(); 113 } 114 else{ 115 mousex = event.motion.x; 116 mousey = event.motion.y; 117 } 118 119 auto surface = getSurface(); 116 120 117 //if the surface that the mouse is in has changed118 if(currentSurface !is surface){119 //If the old surface is not device120 if(currentSurface !is null)121 //Tell it that the mouse left122 currentSurface.mouseleave(surface, event.button.button, Vec2i(mousex,mousey));123 //If the new surface is not device124 if(surface !is null)125 //Tell it that the mosue entered126 surface.mouseenter(event.button.button, Vec2i(mousex,mousey));121 //if the surface that the mouse is in has changed 122 if(currentSurface !is surface){ 123 //If the old surface is not device 124 if(currentSurface !is null) 125 //Tell it that the mouse left 126 currentSurface.mouseleave(surface, event.button.button, Vec2i(mousex,mousey)); 127 //If the new surface is not device 128 if(surface !is null) 129 //Tell it that the mosue entered 130 surface.mouseenter(event.button.button, Vec2i(mousex,mousey)); 127 131 128 132 //The new current surface 129 133 currentSurface = surface; 130 }131 //Needs to be changed so that check is run once132 if(surface !is null)133 surface.mousemove(event.button.button, Vec2i(event.motion.xrel, event.motion.yrel));134 } 135 //Needs to be changed so that check is run once 136 if(surface !is null) 137 surface.mousemove(event.button.button, Vec2i(event.motion.xrel, event.motion.yrel)); 134 138 135 break;139 break; 136 140 137 141 // System 138 142 //case SDL_ACTIVEEVENT: 139 143 //case SDL_VIDEOEXPOSE: 140 case SDL_VIDEORESIZE: 141 Device.resizeWindow(event.resize.w, event.resize.h); 142 break; 143 case SDL_QUIT: 144 exit = true; 145 break; 146 default: 147 break; 148 } 144 case SDL_VIDEORESIZE: 145 Device.resizeWindow(event.resize.w, event.resize.h); 146 break; 147 case SDL_QUIT: 148 Device.exit(0); 149 break; 150 default: 151 break; 149 152 } 150 }151 152 /// Get the number of pixels the mouse has moved since the last time this function was called.153 static Vec2f getMouseDelta()154 { Vec2f result = Vec2f(mousedx, mousedy);155 mousedx = mousedy = 0;156 return result;157 153 } 158 154
