游戏开发论坛

 找回密码
 立即注册
搜索
查看: 12366|回复: 32

爱国的进来。。。。

[复制链接]

4

主题

18

帖子

18

积分

新手上路

Rank: 1

积分
18
发表于 2005-3-19 17:37:00 | 显示全部楼层 |阅读模式
      做为中国人,要团结。而团结的主要成份是有什么事情大家共想,有什么难题大家共解,有什么好东西大家共用。
      只有这样才不会被外国人赶上,中国的游戏崛不起来是什么原因,就是有些人把自己的私处藏得深不可测。有经验的怕被人家学走,有好代码的怕人家抄写。其实这些人失去的永远都比得到的多,哲理太深,这里不谈。只希望佛祖能感化你们这些无知的人。
      如果你想让外国人称中国游戏好,中国人真聪明,中国人真团结,那你就把代码发到下面,注明一下。如果你是个自私,自利,天天担心明天会被人抢啦饭盒的话,看完这帖后,那我只好请你别走出去,


                                              滚出去

103

主题

1432

帖子

1458

积分

金牌会员

Rank: 6Rank: 6

积分
1458
QQ
发表于 2005-3-19 17:51:00 | 显示全部楼层

Re:爱国的进来。。。。


中国的游戏也不见得崛不起。
其原因更非是对知识产权的保护。

关键是中国人普遍缺乏耐心。
就如古人的遗训,冰封三尺,非一日之寒,不要抱太多不切实际的期望。

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 18:04:00 | 显示全部楼层

贴算法和算法的解释可能好些,代码只不过是实现的方法

rt没听说ACM光贴代码的,文章倒不少。

4

主题

14

帖子

24

积分

注册会员

Rank: 2

积分
24
发表于 2005-3-19 19:30:00 | 显示全部楼层

63

主题

871

帖子

891

积分

高级会员

Rank: 4

积分
891
QQ
发表于 2005-3-19 19:32:00 | 显示全部楼层

Re: 爱国的进来。。。。

楼主大概受了一些打击吧 [em23]

4

主题

14

帖子

24

积分

注册会员

Rank: 2

积分
24
发表于 2005-3-19 19:34:00 | 显示全部楼层

另外,对楼主表示12分的鄙视。

这种人没资格当中国人。

4

主题

18

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2005-3-19 19:48:00 | 显示全部楼层

Re:爱国的进来。。。。

     我要的是3D引擎的代码。。。买啦好多书。。。
              好多函数都讲得不明不白的。。。。。气人呀。。同志们。。
        我只想看看别人的代码去了解一些函数的用法。。
               

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 20:06:00 | 显示全部楼层

主啊,我来满足楼主的需要吧。

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2005 The OGRE Team
Also see acknowledgements in Readme.html

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
-----------------------------------------------------------------------------
*/
//---- ORIGINAL COPYRIGHT FOLLOWS -------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------------------
// Copyright 2000, Paul Nettle. All rights reserved.
//
// You are free to use this source code in any commercial or non-commercial product.
//
// mmgr.cpp - Memory manager & tracking software
//
// The most recent version of this software can be found at: ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers/
//
// [NOTE: Best when viewed with 8-character tabs]
//
// ---------------------------------------------------------------------------------------------------------------------------------
#ifndef __MemoryManager_H__
#define __MemoryManager_H__

#include "OgrePlatform.h"
#include "OgreStdHeaders.h"

namespace Ogre {

    /** @page memory_manager The memory manager information page
       
                @subsection desc Description
                        The memory manager is a class that handles memory (de)allocation requests.
        @par
            This class works like a wrapper between the actual C memory allocation
            functions (*alloc, free) and the memory (de)allocation requests of the
            application.
        @par
            Why would such a class be needed? First of all, because we had some
            major issues with memory getting misued (read: deleted) over DLL
            boundaries. One thing this memory manager does is solve the problem by
            allocating all the memory in the OgreMain.dll/so process.
        @par
            Another use would be leak detection and memory misuse detection. With
            a custom memory manager, calls to new/delete and *alloc/free could be
            overseed and logged.
        @par
            Yet another use is the optimization of memory allocation for certain
            object types. One of the most common examples is a small object
            allocator.
                @subsection types Manager types
                        There actually are two classes, one is the standard memory manager
                        which only addresses memory allocation problems when deallocating
                        across processes.
                @par
                        The other is a modified version of the debugging memory manager written
                        by Paul 'MidNight' Nettle (aka. the Fluid Studios Memory Manager).
                        Obviously, the second one should be used only when debugging your
                        application as it adds some visible overhead.
                @par
                        You can switch between the two memory managers by setting the value of
                        the OGRE_DEBUG_MEMORY_MANAGER macro in OgreConfig.h
        @subsection notes Implementation Note
            The class contains a static member of type MemoryManager. That is
            because we want the memory manager to be created even before we
            override the new([])/delete([]) operators.
                @subsection see See also
                        <a href="http://www.flipcode.com/cgi-bin/msg.cgi?showThread=12September2000-PresentingAMemoryManager&forum=askmid&id=-1"&gtaul Nettle's Memory Manager page at flipCode</a> - you can get the original source form here.
    */

#if OGRE_DEBUG_MEMORY_MANAGER && OGRE_DEBUG_MODE

#ifndef __FUNCTION__
#define __FUNCTION__ "???"
#endif

}

//-----------------------------------------------------------------------------
// We have to declare the global new([])/delete([]) operators before declaring
// the Ogre::MemoryManager class since it lists them as friend functions
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
void operator delete(void *reportedAddress);
void operator delete[](void *reportedAddress);
//-----------------------------------------------------------------------------

namespace Ogre {

    /** For internal use only.
        \internal.
        @remarks
            This structure holds the allocation tracking information. So,
            for each allocation made, the overhead this memory manager adds
            is the size of this structure, the lengths of the names of the
            file and function in which the allocation was made and the
            padding size (which can be adjusted).
    */
    typedef struct tag_au
    {
        size_t actualSize;
        size_t reportedSize;

        void *actualAddress;
        void *reportedAddress;

        char sourceFile[40];
        char sourceFunc[40];

        unsigned int sourceLine;
        unsigned int allocationType;

        bool breakOnDealloc;
        bool breakOnRealloc;

        unsigned int allocationNumber;
        unsigned int processID;

        struct tag_au *next;
        struct tag_au *prev;
    } sAllocUnit;

    typedef struct
    {
        size_t totalReportedMemory;
        size_t totalActualMemory;

        size_t peakReportedMemory;
        size_t peakActualMemory;

        size_t accumulatedReportedMemory;
        size_t accumulatedActualMemory;
        size_t accumulatedAllocUnitCount;

        size_t totalAllocUnitCount;
        size_t peakAllocUnitCount;
    } sMStats;
   
    enum
    {
        m_alloc_unknown        = 0,
        m_alloc_new            = 1,
        m_alloc_new_array      = 2,
        m_alloc_malloc         = 3,
        m_alloc_calloc         = 4,
        m_alloc_realloc        = 5,
        m_alloc_delete         = 6,
        m_alloc_delete_array   = 7,
        m_alloc_free           = 8
    };

        /** See the \ref memory_manager.
        */
    class _OgreExport MemoryManager
    {
        friend void * :perator new(size_t);
        friend void * ::operator new[](size_t);
        friend void ::operator delete(void*);
        friend void ::operator delete[](void*);

    public:
        static MemoryManager sMemManager;

    private:
        /// This is used in the process tracking part of the memory manager.
        unsigned m_uProcessIDs;
        /// This is set to true when deinitialization takes place.
        bool m_bDeinitTime;

#ifndef __BORLANDC__
    private:
#else
    public:
#endif
        //-------------------------------------------------------------------------
        // Wrappers for the new/delete functions        
        void *op_new_sc( size_t reportedSize, unsigned processID );
        void *op_new_vc( size_t reportedSize, unsigned processID );

        void *op_new_sc( size_t reportedSize, const char *sourceFile, int sourceLine, unsigned processID );
        void *op_new_vc( size_t reportedSize, const char *sourceFile, int sourceLine, unsigned processID );

        void op_del_sc( void *reportedAddress, unsigned processID );
        void op_del_vc( void *reportedAddress, unsigned processID );
        //-------------------------------------------------------------------------

        /** This function is intended for internal use only.
            \internal
            @remarks
                This function is used to return an unique handle for each process
                calling it. The returned unsigned int is then passed to the memory
                manager every time a re/de/allocation request is made, in order
                to check that deallocations don't occur in processes other than the
                ones in which allcations were made and so on.
            @par
                Actually, the problem of re/de/allocating in other processes was
                solved with the addition of the new memory manager, but you may
                want to limit the occurence of such events anyway, and this function
                helps you do just that.
        */
        unsigned _getProcessID();

    public:
        MemoryManager();
        ~MemoryManager();

        //-------------------------------------------------------------------------
        // Used by the macros     
        void setOwner(const char *file, const unsigned int line, const char *func);
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        // Allocation breakpoints        
        bool &breakOnRealloc(void *reportedAddress);
        bool &breakOnDealloc( void *reportedAddress );
        void breakOnAlloc( unsigned int count );
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        // The meat & potatoes of the memory tracking software

        /** This function is intended for internal use only.
            \internal
            @remarks
                This function is the actual memory allocator and acts as a bridge
                between OGRE and the C/C++ alloc/calloc functions.
            @par
                While memory allocation requests are made trough this function,
                the tracking of memory addresses is possible. Therefore, attempting
                to deallocate a portion of memory that was not allocated using
                this function will result in a warning given by the deallocator,
                dllocMem.
        */
        void * allocMem(
            const char *sourceFile,
            const unsigned int sourceLine,
            const char *sourceFunc,
            const unsigned int allocationType,
            const size_t reportedSize,
            const unsigned processID );

        /** This function is intended for internal use only.
            \internal
            @remarks
                This function is the actual memory reallocator and acts as a bridge
                between OGRE and the C/C++ realloc function.
            @par
                While memory reallocation requests are made trough this function,
                the tracking of memory addresses is possible. Therefore, attempting
                to deallocate a portion of memory that was not reallocated using
                this function will result in a warning given by the deallocator,
                dllocMem.
            @par
                As well, trying to reallocate memory that was not allocated using
                mallc/calloc will result in a warning.
        */
        void * rllocMem(
            const char *sourceFile,
            const unsigned int sourceLine,
            const char *sourceFunc,
            const unsigned int reallocationType,
            const size_t reportedSize,
            void *reportedAddress,
            const unsigned processID );

        /** This function is intended for internal use only.
            \internal
            @remarks
                This function is the actual memory deallocator and acts as a
                bridge between OGRE and the C/C++ free function.
            @par
                While memory deallocation requests are made trough this function,
                the tracking of memory addresses is possible. Therefore, attempting
                to deallocate a portion of memory that was not allocated using
                allocMem or rllocMem, trying to deallocate memory that was
                allocated with malloc using delete (and the corresponding
                permutations) or trying to deallocate memory allocated from from
                process will result in a warning.
            @note
                Actually, memory can be allocated in one process and deallocated
                in another, since the actual (de)allocation takes place in the
                memory space of the OgreMain library.
            @par
                Tracking this kind of (possible) errors exists because users may
                want to write their own memory allocator later on or they'd like
                to get rid of OGRE's memory allocator.
        */
        void dllocMem(
            const char *sourceFile,
            const unsigned int sourceLine,
            const char *sourceFunc,
            const unsigned int deallocationType,
            const void *reportedAddress,
            const unsigned processID );
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        // Utilitarian functions        
        bool validateAddr(const void *reportedAddress);
        bool validateAlloc(const sAllocUnit *allocUnit);
        bool validateAllAllocs();
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        // Unused RAM calculations        
        unsigned int calcUnused( const sAllocUnit *allocUnit );
        unsigned int calcAllUnused();
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        // Logging and reporting        
        void dumpAllocUnit( const sAllocUnit *allocUnit, const char *prefix = "" );
        void dumpMemReport( const char *filename = "memreport.log", const bool overwrite = true );
        sMStats getMemStats();            
        //-------------------------------------------------------------------------        
    };
}

/** This variable exists separately in each module that links to the OGRE library
    and is used to track the ID of the current process from the perspective
    of the memory manager.
    @see
        unsigned Ogre::MemoryManager::_getProcessID()
*/
static unsigned gProcessID = 0;

//-----------------------------------------------------------------------------
// Overridden global new([])/delete([]) functions
//
inline void *operator new(size_t reportedSize)
{
    if( !gProcessID )
        gProcessID = Ogre::MemoryManager::sMemManager._getProcessID();
    return Ogre::MemoryManager::sMemManager.op_new_sc( reportedSize, gProcessID );
}
inline void *operator new[](size_t reportedSize)
{
    if( !gProcessID )
        gProcessID = Ogre::MemoryManager::sMemManager._getProcessID();
    return Ogre::MemoryManager::sMemManager.op_new_vc( reportedSize, gProcessID );
}

inline void operator delete(void *reportedAddress)
{
    Ogre::MemoryManager::sMemManager.op_del_sc( reportedAddress, gProcessID );   
}
inline void operator delete[](void *reportedAddress)
{
    Ogre::MemoryManager::sMemManager.op_del_vc( reportedAddress, gProcessID );
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// This header adds the *alloc/free macros, wrapping the C functions
#include "OgreMemoryMacros.h"
//-----------------------------------------------------------------------------

#else

        /** See the \ref memory_manager.
        */
    class _OgreExport MemoryManager
    {
    public:
        static MemoryManager sMemManager;

        MemoryManager();
        ~MemoryManager();

        /** Memory allocator - uses plain old malloc.
        */
        void *allocMem( const char *szFile, size_t uLine, size_t count ) throw ( );

        /** Memory re-allocator - uses plain old realloc.
        */
        void *rllocMem( const char *szFile, size_t uLine, void *ptr , size_t count ) throw ( );

        /** Memory allocator - uses plain old calloc.
        */
        void *cllocMem( const char *szFile, size_t uLine, size_t num, size_t size ) throw ( );

        /** Memory de-allocator - uses plain old free.
        */
        void dllocMem( const char *szFile, size_t uLine, void *ptr ) throw ( );
    };

}

//-----------------------------------------------------------------------------
// Overridden global new([])/delete([]) functions
//
inline void *operator new( size_t count )
{
    return Ogre::MemoryManager::sMemManager.allocMem( "", 0, count );
}

inline void *operator new[]( size_t count )
{   
    return Ogre::MemoryManager::sMemManager.allocMem( "", 0, count );
}

inline void operator delete( void* ptr )
{
    Ogre::MemoryManager::sMemManager.dllocMem( "", 0, ptr );
}

inline void operator delete[]( void* ptr )
{
    Ogre::MemoryManager::sMemManager.dllocMem( "", 0, ptr );
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// This header adds the *alloc/free macros, wrapping the C functions
#include "OgreMemoryMacros.h"
//-----------------------------------------------------------------------------

#endif

#endif

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 20:07:00 | 显示全部楼层

Re:爱国的进来。。。。

#ifndef __asm_math_H__
#define __asm_math_H__

#include "OgrePrerequisites.h"

/*=============================================================================
ASM math routines posted by davepermen et al on flipcode forums
=============================================================================*/

const float pi = 4.0 * atan( 1.0 );
const float half_pi = 0.5 * pi;

/*=============================================================================
        NO EXPLICIT RETURN REQUIRED FROM THESE METHODS!!
=============================================================================*/
#if OGRE_COMPILER == OGRE_COMPILER_MSVC
#        pragma warning( push )
#        pragma warning( disable: 4035 )
#endif

float asm_arccos( float r ) {
    // return half_pi + arctan( r / -sqr( 1.f - r * r ) );
       
#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    float asm_one = 1.f;
    float asm_half_pi = half_pi;
    __asm {
        fld r // r0 = r
        fld r // r1 = r0, r0 = r
        fmul r // r0 = r0 * r
        fsubr asm_one // r0 = r0 - 1.f
        fsqrt // r0 = sqrtf( r0 )
        fchs // r0 = - r0
        fdiv // r0 = r1 / r0
        fld1 // {{ r0 = atan( r0 )
        fpatan // }}
        fadd asm_half_pi // r0 = r0 + pi / 2
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return float( acos( r ) );

#endif
}

float asm_arcsin( float r ) {
    // return arctan( r / sqr( 1.f - r * r ) );

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    const float asm_one = 1.f;
    __asm {
        fld r // r0 = r
        fld r // r1 = r0, r0 = r
        fmul r // r0 = r0 * r
        fsubr asm_one // r0 = r0 - 1.f
        fsqrt // r0 = sqrtf( r0 )
        fdiv // r0 = r1 / r0
        fld1 // {{ r0 = atan( r0 )
        fpatan // }}
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return float( asin( r ) );

#endif

}

float asm_arctan( float r ) {

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    __asm {
        fld r // r0 = r
        fld1 // {{ r0 = atan( r0 )
        fpatan // }}
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return float( atan( r ) );

#endif

}

float asm_sin( float r ) {

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    __asm {
        fld r // r0 = r
        fsin // r0 = sinf( r0 )
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return sin( r );

#endif

}

float asm_cos( float r ) {

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    __asm {
        fld r // r0 = r
        fcos // r0 = cosf( r0 )
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC
       
        return cos( r );

#endif
}

float asm_tan( float r ) {

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    // return sin( r ) / cos( r );
    __asm {
        fld r // r0 = r
        fsin // r0 = sinf( r0 )
        fld r // r1 = r0, r0 = r
        fcos // r0 = cosf( r0 )
        fdiv // r0 = r1 / r0
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC
       
        return tan( r );

#endif
}

// returns a for a * a = r
float asm_sqrt( float r )
{
#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    __asm {
        fld r // r0 = r
        fsqrt // r0 = sqrtf( r0 )
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return sqrt( r );

#endif
}

// returns 1 / a for a * a = r
// -- Use this for Vector normalisation!!!
float asm_rsq( float r )
{
#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    __asm {
        fld1 // r0 = 1.f
        fld r // r1 = r0, r0 = r
        fsqrt // r0 = sqrtf( r0 )
        fdiv // r0 = r1 / r0
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return 1. / sqrt( r );

#endif
}

// returns 1 / a for a * a = r
// Another version
float apx_rsq( float r ) {

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    const float asm_dot5 = 0.5f;
    const float asm_1dot5 = 1.5f;

    __asm {
        fld r // r0 = r
        fmul asm_dot5 // r0 = r0 * .5f
        mov eax, r // eax = r
        shr eax, 0x1 // eax = eax >> 1
        neg eax // eax = -eax
        add eax, 0x5F400000 // eax = eax & MAGICAL NUMBER
        mov r, eax // r = eax
        fmul r // r0 = r0 * r
        fmul r // r0 = r0 * r
        fsubr asm_1dot5 // r0 = 1.5f - r0
        fmul r // r0 = r0 * r
    } // returns r0

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return 1. / sqrt( r );

#endif
}

/* very MS-specific, commented out for now
   Finally the best InvSqrt implementation?
   Use for vector normalisation instead of 1/length() * x,y,z
*/
#if OGRE_COMPILER == OGRE_COMPILER_MSVC

__declspec(naked) float __fastcall InvSqrt(float fValue)
{
    __asm
    {
        mov        eax, 0be6eb508h
        mov        dword ptr[esp-12],03fc00000h
        sub        eax, dword ptr[esp + 4]
        sub        dword ptr[esp+4], 800000h
        shr        eax, 1
        mov        dword ptr[esp -  8], eax

        fld        dword ptr[esp -  8]
        fmul    st, st
        fld        dword ptr[esp -  8]
        fxch    st(1)
        fmul    dword ptr[esp +  4]
        fld        dword ptr[esp - 12]
        fld        st(0)
        fsub    st,st(2)

        fld        st(1)
        fxch    st(1)
        fmul    st(3),st
        fmul    st(3),st
        fmulp    st(4),st
        fsub    st,st(2)

        fmul    st(2),st
        fmul    st(3),st
        fmulp    st(2),st
        fxch    st(1)
        fsubp    st(1),st

        fmulp    st(1), st
        ret 4
    }
}

#endif

// returns a random number
FORCEINLINE float asm_rand()
{

#if OGRE_COMPILER == OGRE_COMPILER_MSVC
  #if 0
    #if OGRE_COMP_VER >= 1300

        static unsigned __int64 q = time( NULL );

        _asm {
                movq mm0, q

                // do the magic MMX thing
                pshufw mm1, mm0, 0x1E
                paddd mm0, mm1

                // move to integer memory location and free MMX
                movq q, mm0
                emms
        }

        return float( q );
    #endif
  #else
    // VC6 does not support pshufw
    return float( rand() );
  #endif
#else
    // GCC etc

        return float( rand() );

#endif
}

// returns the maximum random number
FORCEINLINE float asm_rand_max()
{

#if OGRE_COMPILER == OGRE_COMPILER_MSVC
  #if 0
    #if OGRE_COMP_VER >= 1300

        return std::numeric_limits< unsigned __int64 >::max();
        return 9223372036854775807.0f;
    #endif
  #else
    // VC6 does not support unsigned __int64
    return float( RAND_MAX );
  #endif

#else
    // GCC etc
        return float( RAND_MAX );

#endif
}

// returns log2( r ) / log2( e )
float asm_ln( float r ) {   

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

    const float asm_e = 2.71828182846f;
    const float asm_1_div_log2_e = .693147180559f;
    const float asm_neg1_div_3 = -.33333333333333333333333333333f;
    const float asm_neg2_div_3 = -.66666666666666666666666666667f;
    const float asm_2 = 2.f;

    int log_2 = 0;

    __asm {
        // log_2 = ( ( r >> 0x17 ) & 0xFF ) - 0x80;
        mov eax, r
        sar eax, 0x17
        and eax, 0xFF
        sub eax, 0x80
        mov log_2, eax

        // r = ( r & 0x807fffff ) + 0x3f800000;
        mov ebx, r
        and ebx, 0x807FFFFF
        add ebx, 0x3F800000
        mov r, ebx

        // r = ( asm_neg1_div_3 * r + asm_2 ) * r + asm_neg2_div_3;   // (1)
        fld r
        fmul asm_neg1_div_3
        fadd asm_2
        fmul r
        fadd asm_neg2_div_3
        fild log_2
        fadd
        fmul asm_1_div_log2_e
    }

#elif OGRE_COMPILER == OGRE_COMPILER_GNUC

        return log( r );

#endif
}

#if OGRE_COMPILER == OGRE_COMPILER_MSVC
#        pragma warning( pop )
#endif

#endif

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 20:08:00 | 显示全部楼层

Re:爱国的进来。。。。

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2005 The OGRE Team
Also see acknowledgements in Readme.html

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
-----------------------------------------------------------------------------
*/
//---- ORIGINAL COPYRIGHT FOLLOWS -------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------------------
// Copyright 2000, Paul Nettle. All rights reserved.
//
// You are free to use this source code in any commercial or non-commercial product.
//
// mmgr.cpp - Memory manager & tracking software
//
// The most recent version of this software can be found at: ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers/
//
// [NOTE: Best when viewed with 8-character tabs]
//
// ---------------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// How does this work?
// Remember that before the compiler starts to process a source file, it runs
// a neat tool called a preprocessor on it. What this preprocessor does in
// this case is replace all the instances of *alloc/free with the expanded
// macros - this way we cleverly replace all the calls to the standard C
// memory (de)allocation functions. The same is done for new/delete
//
// Of course, we have the drawback that we can't name a member function of
// a class *alloc or free and we can't overload the new/delete operators without
// first undefining these macros - ah, a C++ preprocessor with RE replacement,
// that would be a dream come true
//
#ifndef OGRE_MEMORY_MACROS
#define OGRE_MEMORY_MACROS

#if OGRE_DEBUG_MEMORY_MANAGER && OGRE_DEBUG_MODE
#   define new    (::Ogre::MemoryManager::sMemManager.setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? NULL                                                 : new
#   define delete (::Ogre::MemoryManager::sMemManager.setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? ::Ogre::MemoryManager::sMemManager.setOwner("",0,"") : delete
#   define malloc(sz)      ::Ogre::MemoryManager::sMemManager.allocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_malloc, sz,      gProcessID)
#   define calloc(sz)      ::Ogre::MemoryManager::sMemManager.allocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_calloc, sz,      gProcessID)
#   define realloc(ptr,sz) ::Ogre::MemoryManager::sMemManager.rllocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_realloc,sz, ptr, gProcessID)
#   define free(ptr)       ::Ogre::MemoryManager::sMemManager.dllocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_free,       ptr, gProcessID)
#else
#   define new new
#   define delete delete
#   define malloc( sz ) ::Ogre::MemoryManager::sMemManager.allocMem( __FILE__, __LINE__, sz )
#   define free( ptr ) ::Ogre::MemoryManager::sMemManager.dllocMem( __FILE__, __LINE__, ptr )
#   define realloc( ptr, sz ) ::Ogre::MemoryManager::sMemManager.rllocMem( __FILE__, __LINE__, ptr, sz )
#   define calloc( cnt, sz ) ::Ogre::MemoryManager::sMemManager.cllocMem( __FILE__, __LINE__, cnt, sz )
#endif // OGRE_DEBUG_MEMORY_MANAGER

#endif // OGRE_MEMORY_MACROS
//-----------------------------------------------------------------------------
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-24 23:15

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表