Changeset 75

Show
Ignore:
Timestamp:
07/13/08 22:30:03 (5 months ago)
Author:
JoeCoder
Message:

This build is broken, please ignore.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo2/main.d

    r73 r75  
    2323int main() 
    2424{ 
    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      
    6025    // Init (resolution, depth, fullscreen, aa-samples) 
    6126    Device.init(800, 600, 32, false, 1); 
     27    //Device.init(1024, 768, 32, true); 
     28    //Device.init(1440, 900, 32, true); 
    6229     
    6330    // Paths 
     
    9259    camera.setView(2, 20000, 60, 0, 1); // wide angle view 
    9360     
    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){ 
    11770        if (key == SDLK_ESCAPE) 
    11871            Device.exit(0); 
    11972         
    120         if (key == SDLK_SPACE){ 
    121           Flare flare = new Flare(ship.getScene()); 
     73        if (key == SDLK_SPACE) 
     74        { Flare flare = new Flare(ship.getScene()); 
    12275            flare.setPosition(ship.getAbsolutePosition()); 
    12376            flare.setVelocity(Vec3f(0, 0, -150).rotate(ship.ship.getAbsoluteTransform())+ship.getVelocity()); 
     
    13083        } 
    13184         
    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();  
    13487            writefln("garbage collected"); 
    13588        } 
    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){ 
    148106        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 
    224141    // Music 
    225     SoundNode music = new SoundNode(camera); 
     142    auto music = new SoundNode(camera); 
    226143    music.setSound("music/celery - pages.ogg"); 
    227144    music.setLooping(true); 
     
    229146 
    230147    // Lights 
    231     LightNode l1 = new LightNode(scene); 
     148    auto l1 = new LightNode(scene); 
    232149    l1.setDiffuse(Color(1, .85, .7)); 
    233150    l1.setLightRadius(7000); 
     
    235152 
    236153    // Star 
    237     SpriteNode star = new SpriteNode(l1); 
     154    auto star = new SpriteNode(l1); 
    238155    star.setMaterial("space/star.xml"); 
    239156    star.setSize(Vec3f(2500)); 
     
    242159    auto planet = new ModelNode(scene); 
    243160    planet.setModel("space/planet.ms3d"); 
    244     planet.setSize(Vec3f(600)); 
     161    planet.setSize(Vec3f(60)); 
    245162    planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 
    246163     
     
    253170    } 
    254171    scene.onUpdate(&update); 
    255      
    256     bg.recalculate(); 
     172 
    257173     
    258174    // Rendering / Input Loop 
     
    262178    Log.write("Starting rendering loop."); 
    263179    std.gc.fullCollect(); 
    264     while(1){ 
     180    while(1) 
     181    { 
    265182        float dtime = delta.get(); 
    266183        delta.reset(); 
     
    268185        Input.processInput(); 
    269186        camera.toTexture(); 
    270         bg.render(); 
    271          
     187        view.render(); 
    272188         
    273189        // Print framerate 
  • trunk/demo2/ship.d

    r71 r75  
    6262 
    6363        // Accelerate forward 
    64         if (Input.keydown[SDLK_UP] || Input.keydown[SDLK_w]) 
     64        if (Input.keyDown[SDLK_UP] || Input.keyDown[SDLK_w]) 
    6565        { 
    6666            accelerate(Vec3f(0, 0, -speed).rotate(pitch.getTransform()).rotate(getTransform())); 
     
    6969 
    7070        // Accelerate left, right, and backward 
    71         if (Input.keydown[SDLK_LEFT] || Input.keydown[SDLK_a]) 
     71        if (Input.keyDown[SDLK_LEFT] || Input.keyDown[SDLK_a]) 
    7272            accelerate(Vec3f(-speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 
    73         if (Input.keydown[SDLK_RIGHT] || Input.keydown[SDLK_d]) 
     73        if (Input.keyDown[SDLK_RIGHT] || Input.keyDown[SDLK_d]) 
    7474            accelerate(Vec3f(speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 
    75         if (Input.keydown[SDLK_DOWN] || Input.keydown[SDLK_s]) 
     75        if (Input.keyDown[SDLK_DOWN] || Input.keyDown[SDLK_s]) 
    7676            accelerate(Vec3f(0, 0, speed/3).rotate(pitch.getTransform()).rotate(getTransform())); 
    7777 
  • trunk/src/demo1/main.d

    r72 r75  
    5858    camera.setView(2, 20000, 60, 0, 1); // wide angle view 
    5959 
    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); 
    6565 
    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) 
    8569            Device.exit(0); 
    8670         
     
    8973            writefln("garbage collected"); 
    9074        } 
    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    }; 
    9287     
    93     disp.onMousedown = &onMousedown;     
    94     disp.onResize = &onResize; 
    95     disp.onMousemove = &onMousemove; 
    96     disp.onKeydown = &onKeydown; 
    9788         
    9889    // Music 
    99     SoundNode music = new SoundNode(camera); 
     90    auto music = new SoundNode(camera); 
    10091    music.setSound("music/celery - pages.ogg"); 
    10192    music.setLooping(true); 
     
    10394 
    10495    // Lights 
    105     LightNode l1 = new LightNode(scene); 
     96    auto l1 = new LightNode(scene); 
    10697    l1.setDiffuse(Color(1, .85, .7)); 
    10798    l1.setLightRadius(7000); 
     
    109100 
    110101    // Star 
    111     SpriteNode star = new SpriteNode(l1); 
     102    auto star = new SpriteNode(l1); 
    112103    star.setMaterial("space/star.xml"); 
    113104    star.setSize(Vec3f(2500)); 
     
    119110    planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 
    120111     
    121      
    122      
    123      
    124     //planet.getModel().clearAttribute("gl_Normal"); 
    125      
    126112    // Asteroids 
    127113    asteroidBelt(800, 1400, planet); 
    128114     
    129     //delete planet; 
    130  
    131115    // Add to the scene's update loop 
    132116    void update(Node self){ 
     
    134118    } 
    135119    scene.onUpdate(&update); 
    136  
    137     Device.resizeWindow(800, 600); 
    138     //disp.recalculateTexture(); 
    139120     
    140121    // Rendering / Input Loop 
     
    143124    Timer delta = new Timer(); 
    144125    Log.write("Starting rendering loop."); 
     126    std.gc.fullCollect(); 
    145127    while(1) 
    146128    { 
    147129        float dtime = delta.get(); 
    148         // Cap framerate 
    149         //if (dtime < 1/90.0) 
    150         //{ std.c.time.usleep(cast(uint)1000.0); 
    151         //  continue; 
    152         //} 
    153130        delta.reset(); 
    154131 
    155132        Input.processInput(); 
    156133        camera.toTexture(); 
    157         disp.render(); 
     134        view.render(); 
    158135 
    159136        // Print framerate 
     
    163140                fps/frame.get(), camera.getNodeCount(), camera.getPolyCount(), camera.getVertexCount()); 
    164141            SDL_WM_SetCaption(caption.ptr, null); 
    165             delete caption; 
     142            //delete caption; 
    166143            frame.reset(); 
    167144            fps = 0; 
    168145        } 
    169146         
     147        // Cap framerate 
     148        //if (dtime < 1/60.0) 
     149        //  std.c.time.usleep(cast(uint)(1000)); 
    170150        scene.swapTransformRead(); 
    171151    } 
  • trunk/src/demo1/ship.d

    r71 r75  
    6363        // Set the acceleration speed 
    6464        float speed = 50*delta; 
    65         if (Input.keydown[SDLK_q]) 
     65        if (Input.keyDown[SDLK_q]) 
    6666            speed *= 20; // Hyperdrive 
    6767 
    6868        // Accelerate forward 
    69         if (Input.keydown[SDLK_UP] || Input.keydown[SDLK_w]) 
     69        if (Input.keyDown[SDLK_UP] || Input.keyDown[SDLK_w]) 
    7070        { 
    7171            accelerate(Vec3f(0, 0, -speed).rotate(pitch.getTransform()).rotate(getTransform())); 
     
    9797 
    9898        // Accelerate left, right, and backward 
    99         if (Input.keydown[SDLK_LEFT] || Input.keydown[SDLK_a]) 
     99        if (Input.keyDown[SDLK_LEFT] || Input.keyDown[SDLK_a]) 
    100100            accelerate(Vec3f(-speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 
    101         if (Input.keydown[SDLK_RIGHT] || Input.keydown[SDLK_d]) 
     101        if (Input.keyDown[SDLK_RIGHT] || Input.keyDown[SDLK_d]) 
    102102            accelerate(Vec3f(speed/6, 0, 0).rotate(pitch.getTransform()).rotate(getTransform())); 
    103         if (Input.keydown[SDLK_DOWN] || Input.keydown[SDLK_s]) 
     103        if (Input.keyDown[SDLK_DOWN] || Input.keyDown[SDLK_s]) 
    104104            accelerate(Vec3f(0, 0, speed/3).rotate(pitch.getTransform()).rotate(getTransform())); 
    105105 
     
    132132            spring.setStiffness(spring.getStiffness*(delta+1)); 
    133133        // Fire a flare 
    134         if (Input.keydown[SDLK_SPACE]) 
     134        if (Input.keyDown[SDLK_SPACE]) 
    135135        { 
    136136            Flare flare = new Flare(ship.getScene());