Changeset 75
- Timestamp:
- 07/13/08 22:30:03 (5 months ago)
- Files:
-
- trunk/demo2 (copied) (copied from trunk/src/demo2)
- trunk/demo2/gameobj.d (copied) (copied from trunk/src/demo2/gameobj.d)
- trunk/demo2/main.d (copied) (copied from trunk/src/demo2/main.d) (9 diffs)
- trunk/demo2/ship.d (modified) (2 diffs)
- trunk/src/demo1/main.d (modified) (8 diffs)
- trunk/src/demo1/ship.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo2/main.d
r73 r75 23 23 int main() 24 24 { 25 /*26 Object[] array1;27 Object[uint] array2;28 29 Timer a = new Timer();30 for (int j=0; j<100; j++)31 for (int i=0; i<1000; i++)32 array1 ~= new Object();33 writefln("array create: " ~ a.toString());34 35 36 a.reset();37 for (int j=0; j<100; j++)38 for (int i=0; i<1000; i++)39 {};40 writefln("array loop: " ~ a.toString());41 42 a.reset();43 for (int j=0; j<100; j++)44 for (int i=0; i<1000; i++)45 { Object b = new Object;46 array2[b.toHash()] = b;47 }48 writefln("aa create: " ~ a.toString());49 //array2.rehash;50 51 Timer c = new Timer();52 for (int j=0; j<100; j++)53 foreach (i; array2)54 {}55 writefln("aa loop: " ~ c.toString());56 57 return 0;58 */59 60 25 // Init (resolution, depth, fullscreen, aa-samples) 61 26 Device.init(800, 600, 32, false, 1); 27 //Device.init(1024, 768, 32, true); 28 //Device.init(1440, 900, 32, true); 62 29 63 30 // Paths … … 92 59 camera.setView(2, 20000, 60, 0, 1); // wide angle view 93 60 94 Surface bg = new Surface(null); 95 bg.setTexture(camera.getTexture()); 96 bg.topLeft = Vec2f(0,0); 97 bg.bottomRight = Vec2f(1, 1); 98 bg.setVisibility(true); 99 100 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 101 self.grabMouse(!ship.input); 102 ship.input = !ship.input; 103 } 104 105 void onMousemove(Surface self, byte buttons, Vec2i rel){ 106 if(ship.input){ 107 ship.mouseDelta = ship.mouseDelta.add(rel); 108 } 109 } 110 111 void onResize(Surface self){ 112 camera.setResolution(self.size.x, self.size.y); 113 writefln("Camera resolution changed to ", self.size.x, " x ", self.size.y); 114 } 115 116 void onKeydown(Surface self, byte key){ 61 62 // Main surface where camera output is rendered. 63 Surface view = new Surface(null); 64 view.style.backgroundMaterial = camera.getTexture(); 65 view.style.set("bottom: 0; right: 0"); 66 Device.setSurface(view); 67 68 // Events for main surface. 69 view.onKeyDown = delegate void (Surface self, byte key){ 117 70 if (key == SDLK_ESCAPE) 118 71 Device.exit(0); 119 72 120 if (key == SDLK_SPACE) {121 Flare flare = new Flare(ship.getScene());73 if (key == SDLK_SPACE) 74 { Flare flare = new Flare(ship.getScene()); 122 75 flare.setPosition(ship.getAbsolutePosition()); 123 76 flare.setVelocity(Vec3f(0, 0, -150).rotate(ship.ship.getAbsoluteTransform())+ship.getVelocity()); … … 130 83 } 131 84 132 if(key == SDLK_c) {133 std.gc.fullCollect();85 if(key == SDLK_c) // Perform garbage collection, which used to crash. 86 { std.gc.fullCollect(); 134 87 writefln("garbage collected"); 135 88 } 136 } 137 138 bg.onMousedown = &onMousedown; 139 bg.onResize = &onResize; 140 bg.onMousemove = &onMousemove; 141 bg.onKeydown = &onKeydown; 142 143 GPUTexture active = new GPUTexture("test/clear.png"); 144 GPUTexture inactive = new GPUTexture("test/clearInactive.png"); 145 GPUTexture inactive2 = new GPUTexture("test/clearInactive2.png"); 146 147 void onMousedown2(Surface self, byte buttons, Vec2i coordinates){ 89 }; 90 view.onMouseDown = delegate void (Surface self, byte buttons, Vec2i coordinates){ 91 self.grabMouse(!ship.input); 92 ship.input = !ship.input; 93 }; 94 view.onMouseMove = delegate void (Surface self, byte buttons, Vec2i rel){ 95 if(ship.input) 96 ship.mouseDelta = ship.mouseDelta + rel; 97 }; 98 view.onResize = delegate void (Surface self, Vec2f amount){ 99 camera.setResolution(cast(int)self.width, cast(int)self.height); 100 }; 101 102 103 104 // Create 105 void onMouseDown2(Surface self, byte buttons, Vec2i coordinates){ 148 106 self.raise(); 149 self.startDrag(); 150 } 151 void onMouseup2(Surface self, byte buttons, Vec2i coordinates){ 152 self.endDrag(); 153 } 154 void onMousemove2(Surface self, byte buttons, Vec2i diff){ 155 if(buttons == 1) self.drag(diff); 156 } 157 void onMouseenter(Surface self, byte buttons, Vec2i coordinates){ 158 self.setTexture(active); 159 } 160 void onMouseleave(Surface self, byte buttons, Vec2i coordinates){ 161 self.setTexture(inactive2); 162 } 163 164 Surface clear = new Surface(bg); 165 clear.setTexture(inactive2); 166 clear.topLeft = Vec2f(.65,0); 167 clear.bottomRight = Vec2f(1, .25); 168 clear.fill = stretched; 169 clear.setVisibility(true); 170 clear.onMousedown = &onMousedown2; 171 clear.onMousemove = &onMousemove2; 172 clear.onMouseup = &onMouseup2; 173 clear.onMouseenter = &onMouseenter; 174 clear.onMouseleave = &onMouseleave; 175 176 Surface clear2 = new Surface(clear); 177 clear2.setTexture(inactive2); 178 clear2.topLeft = Vec2f(.65,0); 179 clear2.bottomRight = Vec2f(1, .25); 180 clear2.fill = stretched; 181 clear2.setVisibility(true); 182 clear2.onMousedown = &onMousedown2; 183 clear2.onMousemove = &onMousemove2; 184 clear2.onMouseup = &onMouseup2; 185 clear2.onMouseenter = &onMouseenter; 186 clear2.onMouseleave = &onMouseleave; 187 188 Surface clear3 = new Surface(bg); 189 clear3.setTexture(inactive2); 190 clear3.topLeft = Vec2f(.65,0); 191 clear3.bottomRight = Vec2f(1, .25); 192 clear3.fill = stretched; 193 clear3.setVisibility(true); 194 clear3.onMousedown = &onMousedown2; 195 clear3.onMousemove = &onMousemove2; 196 clear3.onMouseup = &onMouseup2; 197 clear3.onMouseenter = &onMouseenter; 198 clear3.onMouseleave = &onMouseleave; 199 200 Surface clear4 = new Surface(bg); 201 clear4.setTexture(inactive2); 202 clear4.topLeft = Vec2f(.4,0); 203 clear4.bottomRight = Vec2f(1, .25); 204 clear4.fill = stretched; 205 clear4.setVisibility(true); 206 clear4.onMousedown = &onMousedown2; 207 clear4.onMousemove = &onMousemove2; 208 clear4.onMouseup = &onMouseup2; 209 clear4.onMouseenter = &onMouseenter; 210 clear4.onMouseleave = &onMouseleave; 211 212 Surface clear5 = new Surface(bg); 213 clear5.setTexture(inactive); 214 clear5.topLeft = Vec2f(.65,0); 215 clear5.bottomRight = Vec2f(1, .4); 216 clear5.fill = stretched; 217 clear5.setVisibility(true); 218 clear5.onMousedown = &onMousedown2; 219 clear5.onMousemove = &onMousemove2; 220 clear5.onMouseup = &onMouseup2; 221 clear5.onMouseenter = &onMouseenter; 222 clear5.onMouseleave = &onMouseleave; 223 107 self.focus(); 108 } 109 void onMouseUp2(Surface self, byte buttons, Vec2i coordinates){ 110 self.blur(); 111 } 112 void onMouseMove2(Surface self, byte buttons, Vec2i diff){ 113 if(buttons == 1) 114 self.move(cast(Vec2f)diff, true); 115 } 116 void onMouseOver(Surface self, byte buttons, Vec2i coordinates){ 117 self.style.set("background-material: url('gui/skin/clear3.png')"); 118 } 119 void onMouseOut(Surface self, byte buttons, Vec2i coordinates){ 120 self.style.set("background-material: url('gui/skin/clear2.png')"); 121 } 122 123 auto window1 = new Surface(view); 124 window1.style.set("top: 5%; right: 3%; width: 160; height: 120; background-position: 5px 5px; " ~ 125 "background-repeat: nineslice; background-material: url('gui/skin/clear2.png')"); 126 window1.onMouseDown = &onMouseDown2; 127 window1.onMouseMove = &onMouseMove2; 128 window1.onMouseUp = &onMouseUp2; 129 window1.onMouseOver = &onMouseOver; 130 window1.onMouseOut = &onMouseOut; 131 132 auto window2 = new Surface(window1); 133 window2.style.set("top: 10; right: 10; width: 50; height: 30; background-position: 5px 5px; " ~ 134 "background-repeat: nineslice; background-material: url('gui/skin/clear2.png')"); 135 window2.onMouseDown = &onMouseDown2; 136 window2.onMouseMove = &onMouseMove2; 137 window2.onMouseUp = &onMouseUp2; 138 window2.onMouseOver = &onMouseOver; 139 window2.onMouseOut = &onMouseOut; 140 224 141 // Music 225 SoundNodemusic = new SoundNode(camera);142 auto music = new SoundNode(camera); 226 143 music.setSound("music/celery - pages.ogg"); 227 144 music.setLooping(true); … … 229 146 230 147 // Lights 231 LightNodel1 = new LightNode(scene);148 auto l1 = new LightNode(scene); 232 149 l1.setDiffuse(Color(1, .85, .7)); 233 150 l1.setLightRadius(7000); … … 235 152 236 153 // Star 237 SpriteNodestar = new SpriteNode(l1);154 auto star = new SpriteNode(l1); 238 155 star.setMaterial("space/star.xml"); 239 156 star.setSize(Vec3f(2500)); … … 242 159 auto planet = new ModelNode(scene); 243 160 planet.setModel("space/planet.ms3d"); 244 planet.setSize(Vec3f(60 0));161 planet.setSize(Vec3f(60)); 245 162 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 246 163 … … 253 170 } 254 171 scene.onUpdate(&update); 255 256 bg.recalculate(); 172 257 173 258 174 // Rendering / Input Loop … … 262 178 Log.write("Starting rendering loop."); 263 179 std.gc.fullCollect(); 264 while(1){ 180 while(1) 181 { 265 182 float dtime = delta.get(); 266 183 delta.reset(); … … 268 185 Input.processInput(); 269 186 camera.toTexture(); 270 bg.render(); 271 187 view.render(); 272 188 273 189 // Print framerate trunk/demo2/ship.d
r71 r75 62 62 63 63 // Accelerate forward 64 if (Input.key down[SDLK_UP] || Input.keydown[SDLK_w])64 if (Input.keyDown[SDLK_UP] || Input.keyDown[SDLK_w]) 65 65 { 66 66 accelerate(Vec3f(0, 0, -speed).rotate(pitch.getTransform()).rotate(getTransform())); … … 69 69 70 70 // Accelerate left, right, and backward 71 if (Input.key down[SDLK_LEFT] || Input.keydown[SDLK_a])71 if (Input.keyDown[SDLK_LEFT] || Input.keyDown[SDLK_a]) 72 72 accelerate(Vec3f(-speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 73 if (Input.key down[SDLK_RIGHT] || Input.keydown[SDLK_d])73 if (Input.keyDown[SDLK_RIGHT] || Input.keyDown[SDLK_d]) 74 74 accelerate(Vec3f(speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 75 if (Input.key down[SDLK_DOWN] || Input.keydown[SDLK_s])75 if (Input.keyDown[SDLK_DOWN] || Input.keyDown[SDLK_s]) 76 76 accelerate(Vec3f(0, 0, speed/3).rotate(pitch.getTransform()).rotate(getTransform())); 77 77 trunk/src/demo1/main.d
r72 r75 58 58 camera.setView(2, 20000, 60, 0, 1); // wide angle view 59 59 60 Surface disp = new Surface(null);61 disp.topLeft = Vec2f(0,0);62 disp.bottomRight = Vec2f(1, 1);63 disp.setVisibility(true);64 disp.setTexture(camera.getTexture());60 // Main surface where camera output is rendered. 61 Surface view = new Surface(null); 62 view.style.backgroundMaterial = camera.getTexture(); 63 view.style.set("bottom: 0; right: 0"); 64 Device.setSurface(view); 65 65 66 67 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 68 self.grabMouse(!ship.input); 69 ship.input = !ship.input; 70 } 71 72 void onMousemove(Surface self, byte buttons, Vec2i rel){ 73 if(ship.input){ 74 ship.mouseDelta = ship.mouseDelta.add(rel); 75 } 76 } 77 78 void onResize(Surface self){ 79 camera.setResolution(self.size.x, self.size.y); 80 writefln("Camera resolution changed to ", self.size.x, " x ", self.size.y); 81 } 82 83 void onKeydown(Surface self, byte key){ 84 if (Input.keydown[SDLK_ESCAPE]) 66 // Events for main surface. 67 view.onKeyDown = delegate void (Surface self, byte key){ 68 if (key == SDLK_ESCAPE) 85 69 Device.exit(0); 86 70 … … 89 73 writefln("garbage collected"); 90 74 } 91 } 75 }; 76 view.onMouseDown = delegate void (Surface self, byte buttons, Vec2i coordinates){ 77 self.grabMouse(!ship.input); 78 ship.input = !ship.input; 79 }; 80 view.onMouseMove = delegate void (Surface self, byte buttons, Vec2i rel){ 81 if(ship.input) 82 ship.mouseDelta = ship.mouseDelta + rel; 83 }; 84 view.onResize = delegate void (Surface self, Vec2f amount){ 85 camera.setResolution(cast(int)self.width, cast(int)self.height); 86 }; 92 87 93 disp.onMousedown = &onMousedown;94 disp.onResize = &onResize;95 disp.onMousemove = &onMousemove;96 disp.onKeydown = &onKeydown;97 88 98 89 // Music 99 SoundNodemusic = new SoundNode(camera);90 auto music = new SoundNode(camera); 100 91 music.setSound("music/celery - pages.ogg"); 101 92 music.setLooping(true); … … 103 94 104 95 // Lights 105 LightNodel1 = new LightNode(scene);96 auto l1 = new LightNode(scene); 106 97 l1.setDiffuse(Color(1, .85, .7)); 107 98 l1.setLightRadius(7000); … … 109 100 110 101 // Star 111 SpriteNodestar = new SpriteNode(l1);102 auto star = new SpriteNode(l1); 112 103 star.setMaterial("space/star.xml"); 113 104 star.setSize(Vec3f(2500)); … … 119 110 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 120 111 121 122 123 124 //planet.getModel().clearAttribute("gl_Normal");125 126 112 // Asteroids 127 113 asteroidBelt(800, 1400, planet); 128 114 129 //delete planet;130 131 115 // Add to the scene's update loop 132 116 void update(Node self){ … … 134 118 } 135 119 scene.onUpdate(&update); 136 137 Device.resizeWindow(800, 600);138 //disp.recalculateTexture();139 120 140 121 // Rendering / Input Loop … … 143 124 Timer delta = new Timer(); 144 125 Log.write("Starting rendering loop."); 126 std.gc.fullCollect(); 145 127 while(1) 146 128 { 147 129 float dtime = delta.get(); 148 // Cap framerate149 //if (dtime < 1/90.0)150 //{ std.c.time.usleep(cast(uint)1000.0);151 // continue;152 //}153 130 delta.reset(); 154 131 155 132 Input.processInput(); 156 133 camera.toTexture(); 157 disp.render();134 view.render(); 158 135 159 136 // Print framerate … … 163 140 fps/frame.get(), camera.getNodeCount(), camera.getPolyCount(), camera.getVertexCount()); 164 141 SDL_WM_SetCaption(caption.ptr, null); 165 delete caption;142 //delete caption; 166 143 frame.reset(); 167 144 fps = 0; 168 145 } 169 146 147 // Cap framerate 148 //if (dtime < 1/60.0) 149 // std.c.time.usleep(cast(uint)(1000)); 170 150 scene.swapTransformRead(); 171 151 } trunk/src/demo1/ship.d
r71 r75 63 63 // Set the acceleration speed 64 64 float speed = 50*delta; 65 if (Input.key down[SDLK_q])65 if (Input.keyDown[SDLK_q]) 66 66 speed *= 20; // Hyperdrive 67 67 68 68 // Accelerate forward 69 if (Input.key down[SDLK_UP] || Input.keydown[SDLK_w])69 if (Input.keyDown[SDLK_UP] || Input.keyDown[SDLK_w]) 70 70 { 71 71 accelerate(Vec3f(0, 0, -speed).rotate(pitch.getTransform()).rotate(getTransform())); … … 97 97 98 98 // Accelerate left, right, and backward 99 if (Input.key down[SDLK_LEFT] || Input.keydown[SDLK_a])99 if (Input.keyDown[SDLK_LEFT] || Input.keyDown[SDLK_a]) 100 100 accelerate(Vec3f(-speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 101 if (Input.key down[SDLK_RIGHT] || Input.keydown[SDLK_d])101 if (Input.keyDown[SDLK_RIGHT] || Input.keyDown[SDLK_d]) 102 102 accelerate(Vec3f(speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 103 if (Input.key down[SDLK_DOWN] || Input.keydown[SDLK_s])103 if (Input.keyDown[SDLK_DOWN] || Input.keyDown[SDLK_s]) 104 104 accelerate(Vec3f(0, 0, speed/3).rotate(pitch.getTransform()).rotate(getTransform())); 105 105 … … 132 132 spring.setStiffness(spring.getStiffness*(delta+1)); 133 133 // Fire a flare 134 if (Input.key down[SDLK_SPACE])134 if (Input.keyDown[SDLK_SPACE]) 135 135 { 136 136 Flare flare = new Flare(ship.getScene());
