Changeset 56

Show
Ignore:
Timestamp:
07/25/07 20:40:41 (1 year ago)
Author:
Deformative
Message:

started obj loader and added Device.exit()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/proj/buildme.d

    r35 r56  
    1 #!~/bin/dmd -run 
     1#!dmd -run 
    22/** 
    33 * Copyright:  Public Domain 
     
    3636// Paths are relative to the build script. 
    3737char[]   mod_path = "../src";                       // The root folder of all modules 
    38 char[][] src_path = ["../src/yage", "../src/demo1"];// Array of folders to look for source files 
     38char[][] src_path = ["../src/yage", "../src/demo2"];// Array of folders to look for source files 
    3939char[][] imp_path = ["../src/derelict"];            // Array of folders to look for imports 
    4040char[][] lib_path = ["../lib"];                     // Array of folders to scan for libraries 
  • trunk/src/demo1/main.d

    r53 r56  
    4040    Scene scene = new Scene(); 
    4141    scene.start(60); // update 60 times per second 
    42     scope(exit)scene.stop(); 
    43  
     42     
     43    Device.onExit = &scene.stop; 
     44     
    4445    // Skybox 
    4546    Scene skybox = new Scene(); 
     
    6667     
    6768    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        } 
    6977    } 
    7078     
    7179    void onResize(Surface self){ 
    7280        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); 
    7482    } 
    7583     
    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;     
    7790    disp.onResize = &onResize; 
    78      
     91    disp.onMousemove = &onMousemove; 
     92    disp.onKeydown = &onKeydown; 
     93         
    7994    // Music 
    8095    SoundNode music = new SoundNode(camera); 
     
    106121 
    107122    // 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){ 
    119124        ship.getSpring().update(1/60.0f); 
    120125    } 
     
    129134    Timer delta = new Timer(); 
    130135    Log.write("Starting rendering loop."); 
    131     while(!Input.exit
     136    while(1
    132137    { 
    133138        float dtime = delta.get(); 
  • trunk/src/demo1/ship.d

    r49 r56  
    1919    Spring spring;      // spring to attach camera 
    2020    SoundNode sound; 
     21     
     22    Vec2i mouseDelta; 
     23    bool input = false; 
    2124 
    2225    float ldamp=.5, xdamp=2, ydamp=2; 
     
    9699 
    97100        // 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; 
    103105        } 
    104106 
  • trunk/src/demo2/main.d

    r54 r56  
    11/** 
    22 * Copyright:  (c) 2005-2007 Eric Poggel 
    3  * Authors:    Eric Poggel 
     3 * Authors:    Eric Poggel, Joe Pusdesris (deformative0@gmail.com) 
    44 * License:    <a href="lgpl.txt">LGPL</a> 
    55 * 
     
    1818 
    1919import demo2.ship; 
     20import demo2.gameobj; 
    2021 
    2122// Current program entry point.  This may change in the future. 
    22 int main() 
    23 
    24  
    25     // Init (resolution, depth, fullscreen, aa-samples) 
     23int main(){ 
     24     
     25    // Init (resolution, depth, fullscreen, aa-samples) 
    2626    Device.init(800, 600, 32, false, 1); 
    2727    //Device.init(1024, 768, 32, true); 
    2828    //Device.init(1440, 900, 32, true); 
    29  
     29     
    3030    // Paths 
    3131    Resource.addPath("../res/"); 
     
    4040    Scene scene = new Scene(); 
    4141    scene.start(60); // update 60 times per second 
    42     scope(exit)scene.stop(); 
     42     
     43    Device.onExit = &scene.stop; 
    4344 
    4445    // Skybox 
     
    5758    CameraNode camera = new CameraNode(ship.getCameraSpot()); 
    5859    camera.setView(2, 20000, 60, 0, 1); // wide angle view 
     60     
     61    //new Model("obj/cube.obj"); 
    5962     
    6063    Surface bg = new Surface(null); 
     
    6568         
    6669    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        } 
    6878    } 
    6979     
     
    7383    } 
    7484     
     85    void onKeydown(Surface self, byte key){ 
     86        if (Input.keydown[SDLK_ESCAPE]) 
     87            Device.exit(0); 
     88    } 
     89     
    7590    bg.onMousedown = &onMousedown;   
    7691    bg.onResize = &onResize; 
     92    bg.onMousemove = &onMousemove; 
     93    bg.onKeydown = &onKeydown; 
    7794     
    7895    GPUTexture active = new GPUTexture("test/clear.png"); 
     
    87104        self.endDrag(); 
    88105    } 
    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); 
    91108    } 
    92109    void onMouseenter(Surface self, byte buttons, Vec2i coordinates){ 
     
    104121    clear.setVisibility(true); 
    105122    clear.onMousedown = &onMousedown2; 
    106     clear.onMousemove = &onMousemove
     123    clear.onMousemove = &onMousemove2
    107124    clear.onMouseup = &onMouseup2; 
    108125    clear.onMouseenter = &onMouseenter; 
     
    116133    clear2.setVisibility(true); 
    117134    clear2.onMousedown = &onMousedown2; 
    118     clear2.onMousemove = &onMousemove
     135    clear2.onMousemove = &onMousemove2
    119136    clear2.onMouseup = &onMouseup2; 
    120137    clear2.onMouseenter = &onMouseenter; 
     
    128145    clear3.setVisibility(true); 
    129146    clear3.onMousedown = &onMousedown2; 
    130     clear3.onMousemove = &onMousemove
     147    clear3.onMousemove = &onMousemove2
    131148    clear3.onMouseup = &onMouseup2; 
    132149    clear3.onMouseenter = &onMouseenter; 
     
    140157    clear4.setVisibility(true); 
    141158    clear4.onMousedown = &onMousedown2; 
    142     clear4.onMousemove = &onMousemove
     159    clear4.onMousemove = &onMousemove2
    143160    clear4.onMouseup = &onMouseup2; 
    144161    clear4.onMouseenter = &onMouseenter; 
     
    152169    clear5.setVisibility(true); 
    153170    clear5.onMousedown = &onMousedown2; 
    154     clear5.onMousemove = &onMousemove
     171    clear5.onMousemove = &onMousemove2
    155172    clear5.onMouseup = &onMouseup2; 
    156173    clear5.onMouseenter = &onMouseenter; 
     
    176193    // Planet 
    177194    auto planet = new ModelNode(scene); 
    178     planet.setModel("space/planet.ms3d"); 
     195    planet.setModel("obj/tieFighter.obj"); 
    179196    planet.setScale(60); 
    180197    planet.setAngularVelocity(0, -0.01, 0); 
     
    186203 
    187204    // 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){ 
    193206        ship.getSpring().update(1/60.0f); 
    194207    } 
     
    202215    Timer delta = new Timer(); 
    203216    Log.write("Starting rendering loop."); 
    204     while(!Input.exit) 
    205     { 
     217    while(1){ 
    206218        float dtime = delta.get(); 
    207219        delta.reset(); 
  • trunk/src/demo2/ship.d

    r49 r56  
    1919    Spring spring;      // spring to attach camera 
    2020    SoundNode sound; 
     21     
     22    Vec2i mouseDelta; 
     23    bool input = false; 
    2124 
    2225    float ldamp=.5, xdamp=2, ydamp=2; 
     
    9699 
    97100        // 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; 
    103105        } 
    104106 
  • trunk/src/yage/gui/surface.d

    r49 r56  
    3333 * The children will be positioned relative to the borders of their parent. */ 
    3434class 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; 
    3837     
    3938    //Change from GPUTexture to Texture or Material 
     
    7675    void delegate(typeof(this) self) onFocus; //Done -- See Raise, no fall through 
    7776 
    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    } 
    8390 
    8491    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousedown; //Done 
     
    8895    } 
    8996 
    90     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousemove; //Done 
    91     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); 
    94101    } 
    95102 
  • trunk/src/yage/node/scene.d

    r53 r56  
    208208 
    209209    /// Stop updating the Scene. 
    210     synchronized void stop() 
    211     { repeater.stop(); 
     210    synchronized void stop(){ 
     211      repeater.stop(); 
    212212    } 
    213213 
  • trunk/src/yage/resource/all.d

    r28 r56  
    2121    import yage.resource.sound; 
    2222    import yage.resource.texture; 
     23    import yage.resource.font; 
    2324} 
  • trunk/src/yage/resource/model.d

    r32 r56  
    77module yage.resource.model; 
    88 
     9import std.gc; 
    910import std.string; 
    1011import std.file; 
     
    2122import yage.resource.mesh; 
    2223import yage.resource.resource; 
    23 import yage.resource.modelloader; 
    2424import yage.node.node; 
    2525import yage.system.constant; 
    2626import yage.system.device; 
    2727import yage.system.log; 
     28 
     29import yage.resource.ms3dloader; 
     30import yage.resource.objloader; 
    2831 
    2932 
     
    6164    protected Attribute[char[]] attributes; // An associative array to store as many attributes as necessary 
    6265 
    63     mixin ModelLoader; 
    64  
     66    mixin Ms3dLoader; 
     67    mixin ObjLoader; 
    6568 
    6669    /// Generate buffers in video memory for the vertex data. 
     
    191194                loadMs3d(filename); 
    192195                break; 
     196            case "obj": 
     197                loadObj(filename); 
     198                fullCollect(); 
     199                break; 
    193200            default: 
    194201                throw new Exception("Unrecognized file format '"~ext~"'."); 
  • trunk/src/yage/system/device.d

    r46 r56  
    2222import yage.system.log; 
    2323import yage.system.constant; 
    24 import yage.system.input; 
    2524import yage.core.vector; 
     25 
     26import std.c.stdlib : exit; 
    2627 
    2728// Enable specular highlights with textures. 
     
    2930const int SINGLE_COLOR_EXT = 0x81F9; 
    3031const int SEPARATE_SPECULAR_COLOR_EXT   = 0x81FA; 
     32 
     33extern(C) { 
     34    void _moduleDtor(); 
     35    void gc_term(); 
     36} 
    3137 
    3238/** 
     
    6369    {   if (initialized) 
    6470        {   try {   // Order of un-initialization is causing trouble here with OpenAL 
     71                //writefln("Device destructor"); 
    6572                SDL_Quit(); 
    6673                //alcDestroyContext(al_context); 
     
    190197        SDL_EnableUNICODE(true); 
    191198        SDL_EnableKeyRepeat(1, 100); 
    192         //Input.setGrabMouse(true); 
    193199 
    194200        // Initialize OpenAL 
     
    202208        Log.write("Yage has been initialized."); 
    203209    } 
    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     
    205221    /** 
    206222     * Searches to see if the given extension is supported in hardware.*/ 
  • trunk/src/yage/system/input.d

    r49 r56  
    11/** 
    22 * Copyright:  (c) 2005-2007 Eric Poggel 
    3  * Authors:    Eric Poggel 
     3 * Authors:    Eric Poggel, Joe Pusdesris (deformative0@gmail.com) 
    44 * License:    <a href="lgpl.txt">LGPL</a> 
    55 */ 
     
    2424 
    2525    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; 
    3026     
    3127    /// A structure to track various state variables associated with each mouse button. 
     
    4036    static Buttons[8] button;       /// An array to track the state of the mouse buttons 
    4137    //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. 
    4439 
    4540    static Surface surfaceLock; 
     
    5752        while(SDL_PollEvent(&event)) 
    5853        { 
    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; 
    6564 
    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: 
    7272                    keyup[event.key.keysym.sym] = true; 
    7373                    keydown[event.key.keysym.sym] = false; 
    74                     break; 
     74                     
     75                auto surface = getSurface(); 
    7576 
     77                if(surface !is null) 
     78                    surface.keyup(event.key.keysym.sym); 
     79                 
     80                break; 
    7681                // 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; 
    8287 
    83                    auto surface = getSurface(); 
     88                auto surface = getSurface(); 
    8489 
    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)); 
    8692 
    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; 
    9399 
    94                    auto surface = getSurface(); 
     100                auto surface = getSurface(); 
    95101 
    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)); 
    97104 
    98                    break; 
    99                case SDL_MOUSEMOTION: 
     105                break; 
     106            case SDL_MOUSEMOTION: 
    100107                     
    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; 
    103112                     
    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(); 
    116120 
    117                    //if the surface that the mouse is in has changed 
    118                    if(currentSurface !is surface){ 
    119                        //If the old surface is not device 
    120                        if(currentSurface !is null) 
    121                            //Tell it that the mouse left 
    122                            currentSurface.mouseleave(surface, event.button.button, Vec2i(mousex,mousey)); 
    123                        //If the new surface is not device 
    124                        if(surface !is null) 
    125                            //Tell it that the mosue entered 
    126                            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)); 
    127131                         
    128132                        //The new current surface 
    129133                        currentSurface = surface; 
    130                    
    131                    //Needs to be changed so that check is run once 
    132                    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)); 
    134138                     
    135                    break; 
     139                break; 
    136140 
    137141                // System 
    138142                //case SDL_ACTIVEEVENT: 
    139143                //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; 
    149152        } 
    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; 
    157153    } 
    158154