Changeset 593

Show
Ignore:
Timestamp:
06/01/08 13:15:39 (7 months ago)
Author:
LeoD
Message:

managed to speed up keyframe animation a lot. the slow part of it now is the VBO updating, not the calculation itself.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/run/defend.cfg

    r592 r593  
    4141     
    4242    // use a shader for rendering the terrain? 
    43     terrain_use_shaders = 0 
     43    terrain_use_shaders = 1 
  • trunk/src/defend/game/Game.d

    r592 r593  
    274274 
    275275        // Fog of war 
    276         fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension), false); 
     276        fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension), true); 
    277277 
    278278        // Create the HUD 
  • trunk/src/defend/terrain/Generator.d

    r583 r593  
    7070        { 
    7171            localCreate(cast(player_id_t)0, "house", 30, 30);            
    72             //localCreate(cast(player_id_t)0, "sheep", 32, 29); 
     72            localCreate(cast(player_id_t)0, "sheep", 32, 29); 
    7373             
    7474            if(players.isPlayer(cast(player_id_t)1)) 
  • trunk/src/engine/model/ModelMD2.d

    r583 r593  
    6666            ubyte[16] name; 
    6767            MD2Vertex[] vertices; 
     68             
     69            BoundingBox!(float) boundingBox; 
     70            vec3[] positions; 
    6871        } 
    6972    } 
     
    107110    class MD2ModelInstance : ModelInstance 
    108111    { 
    109         MD2Mesh mesh; 
    110          
    111112        AnimationType type; 
    112113        uint currentFrame; 
     
    170171            auto nextFrame = &frames[state.nextFrame]; 
    171172 
    172             int k = 0; 
    173  
    174             Vertex vertex; 
    175             vec3 currPos, nextPos; 
    176             int index; 
    177             vec3ub pos; 
    178  
    179             for(uint i = 0; i < header.numTriangles; i++) 
     173            auto target = vertices.getVertexT!(Mesh.Vertex)(0); 
     174            auto currPos = currFrame.positions.ptr; 
     175            auto nextPos = nextFrame.positions.ptr; 
     176 
     177            for(uint i = 0; i < header.numTriangles * 3; i++) 
    180178            { 
    181                 for(uint j = 0; j < 3; j++) 
    182                 { 
    183                     statistics.vertices_skinned++; 
    184                      
    185                     vertex.texture = texCoords[triangles[i].texCoords[j]]; 
    186                      
    187                     index = triangles[i].indices[j]; 
    188                     pos = currFrame.vertices[index].pos; 
    189                      
    190                     currPos.x = currFrame.scale.x * pos.x + currFrame.translate.x; 
    191                     currPos.y = currFrame.scale.y * pos.y + currFrame.translate.y; 
    192                     currPos.z = currFrame.scale.z * pos.z + currFrame.translate.z; 
    193                      
    194                     pos = nextFrame.vertices[index].pos; 
    195                      
    196                     nextPos.x = nextFrame.scale.x * pos.x + nextFrame.translate.x; 
    197                     nextPos.y = nextFrame.scale.y * pos.y + nextFrame.translate.y; 
    198                     nextPos.z = nextFrame.scale.z * pos.z + nextFrame.translate.z; 
    199                      
    200                     vertex.position.x = currPos.x + state.interp * (nextPos.x - currPos.x); 
    201                     vertex.position.y = currPos.y + state.interp * (nextPos.y - currPos.y); 
    202                     vertex.position.z = currPos.z + state.interp * (nextPos.z - currPos.z); 
    203                      
    204                     bbox.max.x = .max(bbox.max.x, vertex.position.x); 
    205                     bbox.max.y = .max(bbox.max.y, vertex.position.y); 
    206                     bbox.max.z = .max(bbox.max.z, vertex.position.z); 
    207                      
    208                     bbox.min.x = .min(bbox.min.x, vertex.position.x); 
    209                     bbox.min.y = .min(bbox.min.y, vertex.position.y); 
    210                     bbox.min.z = .min(bbox.min.z, vertex.position.z); 
    211                      
    212                     vertices.setVertex(k++, vertex); 
    213                 } 
     179                target.position.x = currPos.x + state.interp * (nextPos.x - currPos.x); 
     180                target.position.y = currPos.y + state.interp * (nextPos.y - currPos.y); 
     181                target.position.z = currPos.z + state.interp * (nextPos.z - currPos.z); 
     182 
     183                ++target; 
     184                ++currPos; 
     185                ++nextPos; 
    214186            } 
    215187             
     188            vertices.dirty(); 
    216189            vertices.synchronize(); 
    217190            super.render(); 
    218191             
    219             state.boundingBox = bbox; 
     192            state.boundingBox = currFrame.boundingBox; 
    220193        } 
    221194    } 
     
    301274            file.read(frame.name[]); 
    302275            file.read((cast(ubyte*)frame.vertices)[0 .. MD2Vertex.sizeof * frame.vertices.length]); 
     276             
     277            frame.positions = new vec3[header.numTriangles * 3]; 
     278 
     279            for(uint i = 0; i < header.numTriangles; i++) 
     280            { 
     281                for(uint j = 0; j < 3; j++) 
     282                { 
     283                    frame.positions[i * 3 + j] =  
     284                        frame.scale * frame.vertices[triangles[i].indices[j]].pos + frame.translate; 
     285                         
     286                    frame.boundingBox.addPoint(frame.positions[i * 3 + j]); 
     287                } 
     288            } 
    303289        } 
    304290         
     
    316302        mesh.texCoords = new vec2[texCoords.length]; 
    317303         
    318         for(uint i = 0; i < header.numTriangles; i++) 
    319         { 
    320             for(uint j = 0; j < 3; j++) 
     304        { 
     305            auto vertex = mesh.vertices.getVertexT!(Mesh.Vertex)(0); 
     306             
     307            for(uint i = 0; i < header.numTriangles; i++) 
    321308            { 
    322                 mesh.texCoords[triangles[i].texCoords[j]].x = 
    323                     cast(float)texCoords[triangles[i].texCoords[j]].s / header.skinWidth; 
    324                  
    325                 mesh.texCoords[triangles[i].texCoords[j]].y = 
    326                     cast(float)texCoords[triangles[i].texCoords[j]].t / header.skinHeight; 
     309                for(uint j = 0; j < 3; j++) 
     310                { 
     311                    vertex.texture.x = cast(float)texCoords[triangles[i].texCoords[j]].s / 
     312                                       header.skinWidth; 
     313                     
     314                    vertex.texture.y = cast(float)texCoords[triangles[i].texCoords[j]].t / 
     315                                       header.skinHeight; 
     316                     
     317                    vertex++; 
     318                } 
    327319            } 
    328320        } 
    329321         
     322        mesh.vertices.dirty(); 
     323        mesh.vertices.synchronize(); 
     324         
    330325        _meshes ~= mesh; 
    331326    } 
  • trunk/src/engine/rend/VertexArray.d

    r583 r593  
    5656     
    5757    /** 
     58     * Mark an area as dirty 
     59     */ 
     60    abstract void dirty(int begin = 0, int end = -1); 
     61     
     62    /** 
    5863     * Synchronize local vertex data with graphic card 
    5964     */ 
  • trunk/src/engine/rend/opengl/VertexArray.d

    r583 r593  
    6464    } 
    6565     
     66    override void dirty(int begin = 0, int end = -1) 
     67    { 
     68     
     69    } 
     70     
    6671    override void synchronize() 
    6772    { 
  • trunk/src/engine/rend/opengl/VertexBuffer.d

    r583 r593  
    7070    } 
    7171     
     72    override void dirty(int begin = 0, int end = -1) 
     73    { 
     74        firstSet = begin * size; 
     75        lastSet = (end == -1 ? count : end) * size; 
     76    } 
     77     
    7278    override void synchronize() 
    7379    {