Пример #1
0
//------------------------------------------------------------------------------
std::string QSystem::_getMemoryStats(void)
{
    std::ostringstream stringStream;
#ifdef MARMALADE
    int32 total = s3eMemoryGetInt(S3E_MEMORY_SIZE) / 1024;
    int32 free = s3eMemoryGetInt(S3E_MEMORY_FREE) / 1024;
    int32 lfb = s3eMemoryGetInt(S3E_MEMORY_LFB) / 1024;

    stringStream << free;
    stringStream << "kb of ";
    stringStream << total;
    stringStream << "kb memory remaining.  Largest block is ";
    stringStream << lfb;
    stringStream << "kb";
#endif
    return stringStream.str();
}
Пример #2
0
	void DebugActor::doUpdate(const UpdateState &us)
	{
		static int fps = 0;
		++_frames;
		if (_frames > 50)
		{
			timeMS this_time = getTimeMS();
			if (this_time != _startTime)
			{
				fps = int(((float)_frames/(this_time - _startTime))*1000);
			}
			_startTime = this_time;
			_frames = 0;
		}

		int mem_used = -1;
		int mem_free = -1;

#ifdef __S3E__
		mem_used = s3eMemoryGetInt(S3E_MEMORY_USED);
		mem_free = s3eMemoryGetInt(S3E_MEMORY_FREE);
#endif

		stringstream s;
		s << "fps=" << fps << " mem=" << mem_used << endl;
		s << "mfree=" << mem_free << endl;

#ifdef OXYGINE_DEBUG_TRACE_LEAKS
		s << "objects=" << (int)ObjectBase::__getCreatedObjects().size() << endl;
#endif
		s << "batches="<< _videoStats.batches << " triangles=" << _videoStats.triangles << endl;
		s << "update=" << getRoot()->_statUpdate << "ms ";
		s << "render=" << getRoot()->_statRender << "ms ";
		s << "textures=" << NativeTexture::created << " ";
		s << "\nlisteners=" << getRoot()->getListenersCount() << "";

		s << "\n";
		s << _debugText;
		_debugText = "";

		_text->setText(s.str());

		
		setHeight(_text->getTextRect().size.y + 2.0f);
		_bg->setSize(getSize());


		float scale = getScaleX();
		Vector2 parentSize = getParent()->getSize();
		Vector2 realSize = getSize() * scale;

		setX(0);
		setY(0);

		switch(_corner)
		{			
		case 1:
			setX(parentSize.x - realSize.x);
			setY(0);
			break;
		case 2:
			setPosition(parentSize - realSize);
			break;
		case 3:
			setX(0);
			setY(parentSize.y - realSize.y);
			break;
		}
	}
Пример #3
0
    void DebugActor::doUpdate(const UpdateState& us)
    {
        static int fps = 0;
        ++_frames;
        if (_frames > 50)
        {
            timeMS this_time = getTimeMS();
            if (this_time != _startTime)
            {
                fps = int(((float)_frames / (this_time - _startTime)) * 1000);
            }
            _startTime = this_time;
            _frames = 0;
        }

        std::stringstream s;
        s << "fps=" << fps << std::endl;



#ifdef __S3E__
        int mem_used = -1;
        int mem_free = -1;

        mem_used = s3eMemoryGetInt(S3E_MEMORY_USED);
        mem_free = s3eMemoryGetInt(S3E_MEMORY_FREE);

        s << "mfree=" << mem_free << " mem=" << mem_used << std::endl;
#endif



#ifdef OXYGINE_DEBUG_TRACE_LEAKS
        s << "objects=" << (int)ObjectBase::__getCreatedObjects().size() << std::endl;
#endif
#ifdef OXYGINE_TRACE_VIDEO_STATS
        s << "batches=" << _videoStats.batches << " triangles=" << _videoStats.triangles << std::endl;
#endif
        s << "update=" << getStage()->_statUpdate << "ms ";
        s << "render=" << getStage()->_statRender << "ms ";
        s << "textures=" << NativeTexture::created << " ";
        s << "\nlisteners=" << getStage()->getListenersCount() << "";

        if (!_debugText.empty())
        {
            s << "\n";
            s << _debugText;
        }
        _debugText = "";

        _text->setText(s.str());


        setHeight(_text->getTextRect().size.y + _text->getY() + 3);
        _bg->setSize(getSize());


        Vector2 ds = core::getDisplaySize();

        Vector2 pos(0, 0);

        switch (_corner)
        {
            case 1:
                pos.x = ds.x;
                break;
            case 2:
                pos = ds;
                break;
            case 3:
                pos.y = ds.y;
                break;
        }

        pos = getStage()->global2local(pos);

        Vector2 realSize = getScaledSize();
        switch (_corner)
        {
            case 1:
                pos.x -= realSize.x;
                break;
            case 2:
                pos -= realSize;
                break;
            case 3:
                pos.y -= realSize.y;
                break;
        }

        setPosition(pos);
        setScale(1.0f / getStage()->getScaleX());
    }
Пример #4
0
bool MarmaladeSystem::Initialize()
{
    LOG_INFO(LOGCAT_SYSTEM, "MarmaladeSystem initialization starting.\n");

    const char* marmaladeRuntimeVersion = s3eDeviceGetString(S3E_DEVICE_SDK_VERSION);
    LOG_INFO(LOGCAT_SYSTEM, "Marmalade Runtime Version %s, Linked Version %s\n", marmaladeRuntimeVersion, MARMALADE_VERSION_STRING);

    const char* s3eRuntimeVersion = s3eDeviceGetString(S3E_DEVICE_S3E_VERSION);
    LOG_INFO(LOGCAT_SYSTEM, "S3E Runtime Version: %s, Linked Version: %s\n", s3eRuntimeVersion, S3E_VERSION_STRING);

    const char* deviceID = s3eDeviceGetString(S3E_DEVICE_ID);
    const char* deviceOS = s3eDeviceGetString(S3E_DEVICE_OS);
    int deviceOsVersion = s3eDeviceGetInt(S3E_DEVICE_OS_VERSION);
    int osVersionMajor = (deviceOsVersion >> 16);
    int osVersionMinor =  deviceOsVersion & 0xffff;
    const char* deviceClass = s3eDeviceGetString(S3E_DEVICE_CLASS);
    const char* deviceArch = s3eDeviceGetString(S3E_DEVICE_ARCHITECTURE);
    const char* deviceChipset = s3eDeviceGetString(S3E_DEVICE_CHIPSET);
    int deviceTotalMemKB = s3eDeviceGetInt(S3E_DEVICE_MEM_TOTAL);
    int deviceFreeMemKB = s3eDeviceGetInt(S3E_DEVICE_MEM_FREE);
    int heapSize = s3eMemoryGetInt(S3E_MEMORY_SIZE);

    LOG_INFO(LOGCAT_SYSTEM, "Device ID: %s\n", deviceID);
    LOG_INFO(LOGCAT_SYSTEM, "Device OS: %s (%d.%d)\n", deviceOS, osVersionMajor, osVersionMinor);
    LOG_INFO(LOGCAT_SYSTEM, "Device Class: %s\n", deviceClass);
    LOG_INFO(LOGCAT_SYSTEM, "Device Architecture: %s\n", deviceArch);
    LOG_INFO(LOGCAT_SYSTEM, "Device Chipset: %s\n", deviceChipset);
    LOG_INFO(LOGCAT_SYSTEM, "Device Memory: %dKB free, %dKB total\n", deviceFreeMemKB, deviceTotalMemKB);
    LOG_INFO(LOGCAT_SYSTEM, "S3E Memory Heap Size: %d bytes\n", heapSize);

    bool keyboardHasAlpha = false;
    bool keyboardHasDirection = false;
    if (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_ALPHA))
    {
        keyboardHasAlpha = true;
        LOG_INFO(LOGCAT_SYSTEM, "Keyboard property: S3E_KEYBOARD_HAS_ALPHA\n");
    }
    if (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_NUMPAD))
        LOG_INFO(LOGCAT_SYSTEM, "Keyboard property: S3E_KEYBOARD_HAS_NUMPAD\n");
    if (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_DIRECTION))
    {
        keyboardHasDirection = true;
        LOG_INFO(LOGCAT_SYSTEM, "Keyboard property: S3E_KEYBOARD_HAS_DIRECTION\n");
    }

    // Android Xperia Play device detection
    // TODO: any other device ID's we need to worry about?
    bool isXperiaPlay = false;
    if (s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_ANDROID)
    {
        LOG_INFO(LOGCAT_SYSTEM, "Detected Android as host OS.\n");
        if (strlen(deviceID) >= 4)
        {
            // possible device ID's I currently know of:
            //   R800i, R800a, R800x
            if (strncmp(deviceID, "R800", 4) == 0)
            {
                LOG_INFO(LOGCAT_SYSTEM, "Device is an Xperia Play.\n");
                isXperiaPlay = true;
            }
            else
                LOG_INFO(LOGCAT_SYSTEM, "Device is not an Xperia Play.\n");
        }
    }

    bool keyboardHasPhysicalGameControls = false;
    if ((keyboardHasAlpha && keyboardHasDirection) || isXperiaPlay)
        keyboardHasPhysicalGameControls = true;

    if (keyboardHasPhysicalGameControls)
        LOG_INFO(LOGCAT_SYSTEM, "Keyboard device has enough physical keys for full game controls.\n");
    else
        LOG_INFO(LOGCAT_SYSTEM, "Keyboard device does not have enough physical keys for full game controls.\n");

    m_keyboard = new MarmaladeKeyboard(keyboardHasPhysicalGameControls);
    ASSERT(m_keyboard != NULL);
    LOG_INFO(LOGCAT_SYSTEM, "Keyboard input device ready.\n");

    bool isMultitouchAvailable = false;
    if (s3ePointerGetInt(S3E_POINTER_AVAILABLE))
    {
        s3ePointerType pointerType = (s3ePointerType)s3ePointerGetInt(S3E_POINTER_TYPE);
        if (pointerType == S3E_POINTER_TYPE_INVALID)
            LOG_ERROR(LOGCAT_SYSTEM, "Pointer type = S3E_POINTER_TYPE_INVALID\n");
        else if (pointerType == S3E_POINTER_TYPE_MOUSE)
        {
            LOG_INFO(LOGCAT_SYSTEM, "Pointer device is a mouse.\n");

            m_mouse = new MarmaladeMouse();
            ASSERT(m_mouse != NULL);
            LOG_INFO(LOGCAT_SYSTEM, "Mouse input device ready.\n");
        }
        else if (pointerType == S3E_POINTER_TYPE_STYLUS)
        {
            s3eStylusType stylusType = (s3eStylusType)s3ePointerGetInt(S3E_POINTER_STYLUS_TYPE);
            if (stylusType == S3E_STYLUS_TYPE_INVALID)
                LOG_ERROR(LOGCAT_SYSTEM, "Stylus type = S3E_STYLUS_TYPE_INVALID\n");
            else
            {
                if (stylusType == S3E_STYLUS_TYPE_STYLUS)
                    LOG_INFO(LOGCAT_SYSTEM, "Pointer device is a touchscreen using a stylus.\n");
                else if (stylusType == S3E_STYLUS_TYPE_FINGER)
                    LOG_INFO(LOGCAT_SYSTEM, "Pointer device is a touchscreen.\n");

                if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE))
                {
                    LOG_INFO(LOGCAT_SYSTEM, "Pointer device supports multitouch.\n");
                    isMultitouchAvailable = true;
                }
                else
                    LOG_INFO(LOGCAT_SYSTEM, "Pointer device does not support multitouch.\n");

                m_touchscreen = new MarmaladeTouchscreen(this, isMultitouchAvailable);
                ASSERT(m_touchscreen != NULL);
                LOG_INFO(LOGCAT_SYSTEM, "Touchscreen input device ready.\n");
            }
        }
    }
    else
        LOG_WARN(LOGCAT_SYSTEM, "No pointer device is available.\n");

    s3eDeviceRegister(S3E_DEVICE_PAUSE, _MarmaladeEventCallback_Pause, this);
    s3eDeviceRegister(S3E_DEVICE_UNPAUSE, _MarmaladeEventCallback_Resume, this);
    s3eDeviceRegister(S3E_DEVICE_EXIT, _MarmaladeEventCallback_Exit, this);
    s3eGLRegister(S3E_GL_SUSPEND, _MarmaladeEventCallback_GLSuspend, this);
    s3eGLRegister(S3E_GL_RESUME, _MarmaladeEventCallback_GLResume, this);
    s3eSurfaceRegister(S3E_SURFACE_SCREENSIZE, _MarmaladeEventCallback_ScreenResize, this);
    s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, _MarmaladeEventCallback_Key, this);
    s3eKeyboardRegister(S3E_KEYBOARD_CHAR_EVENT, _MarmaladeEventCallback_KeyChar, this);
    if (m_mouse != NULL || m_touchscreen != NULL)
    {
        if (isMultitouchAvailable)
        {
            s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, _MarmaladeEventCallback_PointerMultitouchButton, this);
            s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, _MarmaladeEventCallback_PointerMultitouchMotion, this);
        }
        else
        {
            s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, _MarmaladeEventCallback_PointerButton, this);
            s3ePointerRegister(S3E_POINTER_MOTION_EVENT, _MarmaladeEventCallback_PointerMotion, this);
        }
    }
    else
        LOG_WARN(LOGCAT_SYSTEM, "No mouse or touchscreen device was initialized.\n");

    LOG_INFO(LOGCAT_SYSTEM, "Registered S3E event callbacks.\n");

    LOG_INFO(LOGCAT_SYSTEM, "Initializing file system access.\n");
    m_filesystem = new MarmaladeFileSystem();
    ASSERT(m_filesystem != NULL);

    LOG_INFO(LOGCAT_SYSTEM, "Finished initialization.\n");

    return true;
}
Пример #5
0
    void DebugActor::render(RenderState const& parentRS)
    {
        timeMS tm = getTimeMS();

        static int fps = 0;
        ++_frames;
        if (_frames > 50)
        {
            if (tm != _startTime)
            {
                fps = int(((float)_frames / (tm - _startTime)) * 1000);
            }
            _startTime = tm;
            _frames = 0;
        }

        std::stringstream s;
        s << "fps=" << fps << std::endl;



#ifdef __S3E__
        int mem_used = -1;
        int mem_free = -1;

        mem_used = s3eMemoryGetInt(S3E_MEMORY_USED);
        mem_free = s3eMemoryGetInt(S3E_MEMORY_FREE);

        s << "mfree=" << mem_free << " mem=" << mem_used << std::endl;
#endif

        const IVideoDriver::Stats& vstats = IVideoDriver::_stats;

#ifdef OXYGINE_DEBUG_TRACE_LEAKS
        s << "objects=" << (int)ObjectBase::__getCreatedObjects().size() << std::endl;
#endif

#if OXYGINE_TRACE_VIDEO_STATS
        int primitives = 0;
        primitives += vstats.elements[IVideoDriver::PT_TRIANGLES] / 3;
        if (vstats.elements[IVideoDriver::PT_TRIANGLE_STRIP])
            primitives += vstats.elements[IVideoDriver::PT_TRIANGLE_STRIP] - 2;
        s << "batches=" << aligned(vstats.batches, 3) << " primitives=" << aligned(primitives, 3) << std::endl;
#endif

        s << "update=" << aligned(getStage()->_statUpdate, 2) << "ms ";
        s << "render=" << aligned(vstats.duration, 2) << "ms ";
        s << "textures=" << aligned(NativeTexture::created, 2) << " ";

#ifdef __APPLE__
        size_t mem;
        iosGetMemoryUsage(mem);
        s << "memory=" << mem / 1024 << "kb ";
#endif

#ifdef _WIN32
        PROCESS_MEMORY_COUNTERS_EX pmc;
        GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*) &pmc, sizeof(pmc));
        s << "memory=" << pmc.PrivateUsage / 1024 << "kb ";

#endif

        if (!_debugText.empty())
        {
            s << "\n";
            s << _debugText;
        }
        _debugText = "";

        _text->setText(s.str());


        setHeight(_text->getTextRect().size.y + _text->getY() + 3);
        _bg->setSize(getSize());


        Vector2 ds = core::getDisplaySize();

        Vector2 pos(0, 0);

        switch (_corner)
        {
            case 1:
                pos.x = ds.x;
                break;
            case 2:
                pos = ds;
                break;
            case 3:
                pos.y = ds.y;
                break;
        }

        pos = getStage()->parent2local(pos);

        Vector2 realSize = getScaledSize();
        switch (_corner)
        {
            case 1:
                pos.x -= realSize.x;
                break;
            case 2:
                pos -= realSize;
                break;
            case 3:
                pos.y -= realSize.y;
                break;
        }

        //setPosition(pos);
        setScale(1.0f / getStage()->getScaleX());

        RenderState rs = parentRS;
        parentRS.material->finish();

        STDRenderer renderer;
        STDMaterial mat(&renderer);
        mat.apply(0);


        IVideoDriver* driver = renderer.getDriver();


        Rect vp(Point(0, 0), core::getDisplaySize());
        driver->setViewport(vp);
        renderer.initCoordinateSystem(vp.getWidth(), vp.getHeight());
        renderer.resetSettings();
        rs.material = &mat;
        Actor::render(rs);
        renderer.drawBatch();

        mat.finish();

        Material::setCurrent(0);

        timeMS dur = getTimeMS() - tm;

        IVideoDriver::_stats.start += dur;
    }