Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


GameCodingNinja

Member Since 18 Aug 2005
Offline Last Active Jan 02 2015 12:39 PM

Topics I've Started

Animated load screens with OpenGL, a simple solution

31 December 2014 - 12:09 AM

I came up with a simple solution for animated loading screens since I really don't like the few options that are available for trying to multi-thread parts of OpenGL. My simple solution allows you to load everything from the main thread and run your animation from newly spawned thread. This only works if your using SDL.

The simple solution is...

Use SDL's bitmap software rendering tools to load and render your "loading" animation from a thread. Since this is a completely separate rendering system, there's no OpenGL conflicts. Also, your engine probably has some dependencies that need to be loaded just to get part of your system up and running before even a simple image can be displayed as well as start up the render loop. That's no longer an issue.

I just start the thread that plays the "loading" animation and then load everything. This is happening outside of the game loop, independent of the engine, from within one function.

Here's my code to animate from a thread to show how easy it is to do. I'm just fading the logo in and out while loading sound, textures, etc with my engine.

I thought this was such a cool solution so I thought I'd share. Works great for me. biggrin.png

int CStartUpState::Animate()
{
    // Get window surface
    SDL_Surface * pScreenSurface = SDL_GetWindowSurface( CDevice::Instance().GetWindow() );
    if( pScreenSurface == NULL )
        NGenFunc::PostDebugMsg( "Surface Creation error! - " + std::string(SDL_GetError()) );

    // Create a bitmap surface
    SDL_Surface * pLogoSurface = SDL_LoadBMP( "data/textures/startup/logo.bmp" );
    if( pLogoSurface == NULL )
        NGenFunc::PostDebugMsg( "Logo Surface Creation error! - " + std::string(SDL_GetError()) );

    // Calculate the rect position and scaled size
    SDL_Rect rect;
    rect.w = pLogoSurface->w * CSettings::Instance().GetScreenRatio().GetH();
    rect.h = pLogoSurface->h * CSettings::Instance().GetScreenRatio().GetH();
    rect.x = (pScreenSurface->w - rect.w) / 2;
    rect.y = (pScreenSurface->h - rect.h) / 2;

    SDL_Delay( 200 );

    FadeTo( 500, 0, 255, pLogoSurface, pScreenSurface, rect );

    SDL_Delay( 2000 );

    FadeTo( 500, 255, 0, pLogoSurface, pScreenSurface, rect );

    SDL_Delay( 200 );

    SDL_FreeSurface( pLogoSurface );
    SDL_FreeSurface( pScreenSurface );

    return thread::THREAD_EXIT_CODE;

}  // Animate


void CStartUpState::FadeTo(
    float time, float current, float final, SDL_Surface * pSource, SDL_Surface * pTarget, SDL_Rect & rect )
{
    float inc = (final - current) / time;

    while( time > 0 )
    {
        // First thing we need to do is get our elapsed time
        CHighResTimer::Instance().CalcElapsedTime();

        time -= CHighResTimer::Instance().GetElapsedTime();

        current += inc * CHighResTimer::Instance().GetElapsedTime();

        SDL_SetSurfaceColorMod( pSource, current, current, current );

        if( time < 0 )
        {
            SDL_SetSurfaceColorMod( pSource, final, final, final );
            break;
        }

        SDL_BlitScaled( pSource, NULL, pTarget, &rect );
        SDL_UpdateWindowSurface( CDevice::Instance().GetWindow() );

        SDL_Delay( 5 );
    }

}   // FadeTo

This is where it all happens. The first line of code starts the thread for animating loading screen. The following lines of code is loading everything I need for the engine at this time. The last line waits for the thread to finish. All within one function, completely independent of the OpenGL/SDL game engine.

void CStartUpState::Load()
{
    // Start the animated loading thread
    loadThread.Start( this, &CStartUpState::Animate, "startupStateThread" );

    // Load in any fonts
    CFontMgr::Instance().LoadFromXML( "data/textures/fonts/font.lst" );

    // Shaders must always be loaded first because they are accessed from object data
    CShaderMgr::Instance().LoadFromXML( "data/shaders/shader.cfg" );

    // Load all of the meshes and materials in these groups
    CObjectDataMgr2D::Instance().LoadListTable( "data/objects/2d/objectDataList/dataListTable.lst" );
    CObjectDataMgr2D::Instance().LoadGroup("(menu)");
    CObjectDataMgr2D::Instance().LoadGroup( "(title_screen)" );

    // Load sound resources for the menu
    CSoundMgr::Instance().LoadListTable( "data/sound/soundListTable.lst" );
    CSoundMgr::Instance().LoadGroup("(menu)");

    // Creates the script manager and loads the list table
    CScriptManager::Instance().LoadListTable( "data/objects/2d/scripts/scriptListTable.lst" );

    // Register the script items
    RegisterStdString( CScriptManager::Instance().GetEnginePtr() );
    NScriptGlobals::Register( CScriptManager::Instance().GetEnginePtr() );
    NScriptColor::Register( CScriptManager::Instance().GetEnginePtr() );
    CSpriteScriptComponent2d::Register( CScriptManager::Instance().GetEnginePtr() );

    // Load group specific script items
    CScriptManager::Instance().LoadGroup("(menu)");

    // Create the menu system
    CMenuManager::Instance().LoadFromXML( "data/objects/2d/menu/tree.list" );
    CMenuManager::Instance().ActivateTree("main");

    // Init the currently plugged in game controllers
    CDevice::Instance().InitStartupGamepads();

    // Load the action manager
    CActionManager::Instance().LoadActionFromXML( "data/settings/controllerMapping.cfg" );

    // Wait for the thread to finish
    loadThread.WaitForThread();

}   // Load

SDL_SetWindowDisplayMode problem

29 December 2014 - 01:22 PM

I'm builing an engine around SLD2 and I've been working on the code to allow for changing the resolution and full screen mode. Everything works fine except for changing the resolution while in full screen mode. It seems like SDL_SetWindowDisplayMode doesn't works unless it is done in combination with a change to full screen mode.

 

*I can make this work if I force it back out of full screen mode and then back in again and the resolution change while in full screen then works. This is an odd way to handle it.

if( resChanged )
{
    if( oldFullScreenState && fullScreenState )
        CDevice::Instance().SetFullScreen( 0 );

    if( fullScreenState )
    {
        SDL_DisplayMode mode;
        SDL_GetCurrentDisplayMode(0, &mode);

        mode.w = CSettings::Instance().GetSize().GetW();
        mode.h = CSettings::Instance().GetSize().GetH();

        if( SDL_SetWindowDisplayMode( CDevice::Instance().GetWindow(), &mode ) < 0 )
            NGenFunc::PostDebugMsg( boost::str( boost::format("Warning: Unable to set display mode! SDL GL Error: %s\n") % SDL_GetError() ) );
    }
    else
    {
        SDL_SetWindowSize(
            CDevice::Instance().GetWindow(),
            CSettings::Instance().GetSize().GetW(),
            CSettings::Instance().GetSize().GetH() );

        SDL_SetWindowPosition(
            CDevice::Instance().GetWindow(),
            SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED );
    }

    if( fullScreenChanged || fullScreenState )
        CDevice::Instance().SetFullScreen( fullScreenState );

    // Reset the world transform to recalculate mouse collision
    CMenuManager::Instance().ResetWorldTransform();

    // Need to reset the view port the changing the resolution
    glViewport(0, 0, CSettings::Instance().GetSize().GetW(), CSettings::Instance().GetSize().GetH());
}

Wierd compiler errors that can be fixed by removing spaces before code

16 December 2014 - 08:55 PM

On my script, I started having the compiler error when I added the last 3 functions. The error info suggests lines beyond the actual code.

 

Below is the code in question (menu.ang).

void Menu_TransIn( CSpriteScript2d @script )
{
    script.SetAlpha( 0 );
    FadeTo( 250, script.GetDefaultAlpha(), script );
}

void Menu_TransOut( CSpriteScript2d @script )
{
    FadeTo( 250, 0, script );
}

void Control_TransIn( CSpriteScript2d @script )
{
    g_allowEvent = true;

    script.SetAlpha( 0 );
    FadeTo( 250, script.GetDefaultAlpha(), script );

    if( g_allowEvent )
    {
        g_allowEvent = false;
        DispatchEvent( EGE_MENU_TRANS_IN, ETC_END );
    }
}

void Control_TransOut( CSpriteScript2d @script )
{
    g_allowEvent = true;

    FadeTo( 250, 0, script );

    if( g_allowEvent )
    {
        g_allowEvent = false;
        DispatchEvent( EGE_MENU_TRANS_OUT, ETC_END );
    }
}

void Control_Inactive( CSpriteScript2d @script )
{
    script.SetDefaultColor();
}

void Control_Hidden( CSpriteScript2d @script )
{
    script.SetVisible( false );
}

void Control_Active( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.3 );

    CColor lowColor = script.GetDefaultColor();
    lowColor.TransformHSV( 0, 1, .5 );

    while(true)
    {
        ColorTo( 500, hiColor, script );
        ColorTo( 500, lowColor, script );
    }
}

void Control_Solid_Active( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.1 );

    CColor lowColor = script.GetDefaultColor();
    lowColor.TransformHSV( 0, 1, .5 );

    while(true)
    {
        ColorTo( 500, hiColor, script );
        ColorTo( 500, lowColor, script );
    }
}

void Control_Face_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.7 );

    CColor lowColor = script.GetDefaultColor();
    lowColor.TransformHSV( 0, 1, .6 );

    script.SetColor( hiColor );

    ColorTo( 120, lowColor, script );
    ColorTo( 120, hiColor, script );

    script.SetColor( script.GetDefaultColor() );

    DispatchEvent( EGE_MENU_SELECT_EXECUTE );
}

void Control_Frame_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.7 );

    CColor lowColor = script.GetDefaultColor();
    lowColor.TransformHSV( 0, 1, .6 );

    script.SetColor( hiColor );

    ColorTo( 120, lowColor, script );
    ColorTo( 120, hiColor, script );

    script.SetVisible( false );
}

void Control_Solid_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.5 );

    CColor lowColor = script.GetDefaultColor();
    lowColor.TransformHSV( 0, 1, .6 );

    script.SetColor( hiColor );

    ColorTo( 120, lowColor, script );
    ColorTo( 100, hiColor, script );

    script.SetVisible( false );
}

void Control_Fast_Face_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.7 );

    script.SetColor( hiColor );

    Hold( 50 );

    script.SetDefaultColor();
}

void Control_Fast_Frame_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.7 );

    script.SetColor( hiColor );

    Hold( 50 );

    script.SetVisible( false );
}

void Control_Fast_Solid_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

    CColor hiColor = script.GetDefaultColor();
    hiColor.TransformHSV( 0, 1, 1.5 );

    script.SetColor( hiColor );

    Hold( 50 );

    script.SetVisible( false );
}

Below is the error info. The "}" of the very last function is line 188. There's no code after this point.

data/objects/2d/scripts/menu.ang (189, 2) : ERROR : Expected identifier
data/objects/2d/scripts/menu.ang (189, 2) : ERROR : Instead found '('
data/objects/2d/scripts/menu.ang (192, 12) : ERROR : Expected identifier
data/objects/2d/scripts/menu.ang (192, 12) : ERROR : Instead found '.'
data/objects/2d/scripts/menu.ang (194, 11) : ERROR : Expected identifier
data/objects/2d/scripts/menu.ang (194, 11) : ERROR : Instead found '.'
data/objects/2d/scripts/menu.ang (196, 9) : ERROR : Expected identifier
data/objects/2d/scripts/menu.ang (196, 9) : ERROR : Instead found '('

Now if I do the below to the last two functions, the code will compile and run as expected. All I did was remove the spaces before the lines of code. As you can see, most of the functions are similar.

void Control_Fast_Frame_Selected( CSpriteScript2d @script )
{
    script.SetVisible( true );
    script.SetDefaultColor();

CColor hiColor = script.GetDefaultColor();
hiColor.TransformHSV( 0, 1, 1.7 );

script.SetColor( hiColor );

Hold( 50 );

script.SetVisible( false );
}

void Control_Fast_Solid_Selected( CSpriteScript2d @script )
{
script.SetVisible( true );
script.SetDefaultColor();

CColor hiColor = script.GetDefaultColor();
hiColor.TransformHSV( 0, 1, 1.5 );

script.SetColor( hiColor );

Hold( 50 );

script.SetVisible( false );
}

The only thing I can think of is there's a limit to how big the code file is? Any ideas? I'm using version 2.29.2


AngelScript works in debug mode but not in release

05 October 2014 - 03:48 PM

I recently added AngelScript (2.29.1 WIP) to my engine. After getting it working and setting up some types and a few scripts, I then rebuilt everything in release mode to discover it wasn't working.  I'm building the source files into static libraries using the provided VC10 project files.

 

Also the MessageCallback is not being called to display any error info. With some testing I noticed registering my objects and global functions compile in release mode but if they are used in a script, there will be a build error with no error info.

 

Below is the value type I made. It's my color class holding 4 floats and a bunch of overloaded operators.


/************************************************************************
*    FILE NAME:       scriptcolor.cpp
*
*    DESCRIPTION:     CColor script object registration
************************************************************************/

// Physical component dependency
#include <script/scriptcolor.h>

// Standard lib dependencies
#include <assert.h>

// AngelScript lib dependencies
#include <angelscript.h>

// Game lib dependencies
#include <common/color.h>

namespace NScriptColor
{
    /************************************************************************
	*    desc:  Constructor
	************************************************************************/
    static void Constructor(void * thisPointer)
    {
	    new(thisPointer) CColor();
    }

    /************************************************************************
	*    desc:  Copy Constructor
	************************************************************************/
    static void CopyConstructor(const CColor & other, void * pThisPointer)
    {
	    new(pThisPointer) CColor(other);
    }

    static void ConstructorFromFloats(float r, float g, float b, float a, void * pThisPointer)
    {
	    new(pThisPointer) CColor(r, g, b, a);
    }

    /************************************************************************
	*    desc:  Destructor
	************************************************************************/
    static void Destructor(void * pThisPointer)
    {
	    ((CColor*)pThisPointer)->~CColor();
    }


    /************************************************************************
	*    desc:  Register the type
	************************************************************************/
    void Register( asIScriptEngine * pEngine )
    {
        // Register type
        assert( pEngine->RegisterObjectType("CColor", sizeof(CColor), asOBJ_VALUE | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CONSTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_CLASS_DESTRUCTOR ) > -1 );

        // Register the object operator overloads
	    assert( pEngine->RegisterObjectBehaviour("CColor", asBEHAVE_CONSTRUCT, "void f()",                  asFUNCTION(Constructor), asCALL_CDECL_OBJLAST) > -1 );
	    assert( pEngine->RegisterObjectBehaviour("CColor", asBEHAVE_CONSTRUCT, "void f(const CColor & in)", asFUNCTION(CopyConstructor), asCALL_CDECL_OBJLAST) > -1 );
	    assert( pEngine->RegisterObjectBehaviour("CColor", asBEHAVE_CONSTRUCT, "void f(float, float, float, float)", asFUNCTION(ConstructorFromFloats), asCALL_CDECL_OBJLAST) > -1 );
	    assert( pEngine->RegisterObjectBehaviour("CColor", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST) > -1 );

        // assignment operator
        assert( pEngine->RegisterObjectMethod("CColor", "CColor & opAssign(const CColor & in)", asMETHODPR(CColor, operator =, (const CColor &), CColor &), asCALL_THISCALL) > -1 );

        // binary operators
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opAdd ( const CColor & in )", asMETHODPR(CColor, operator +, (const CColor &) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opSub ( const CColor & in )", asMETHODPR(CColor, operator -, (const CColor &) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opMul ( const CColor & in )", asMETHODPR(CColor, operator *, (const CColor &) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opDiv ( const CColor & in )", asMETHODPR(CColor, operator /, (const CColor &) const, CColor), asCALL_THISCALL) > -1 );

        assert( pEngine->RegisterObjectMethod("CColor", "CColor opAdd ( float )", asMETHODPR(CColor, operator +, (float) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opSub ( float )", asMETHODPR(CColor, operator -, (float) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opMul ( float )", asMETHODPR(CColor, operator *, (float) const, CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opDiv ( float )", asMETHODPR(CColor, operator /, (float) const, CColor), asCALL_THISCALL) > -1 );

        // compound assignment operators
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opAddAssign ( const CColor & in )", asMETHODPR(CColor, operator +=, (const CColor &), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opSubAssign ( const CColor & in )", asMETHODPR(CColor, operator -=, (const CColor &), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opMulAssign ( const CColor & in )", asMETHODPR(CColor, operator *=, (const CColor &), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opDivAssign ( const CColor & in )", asMETHODPR(CColor, operator /=, (const CColor &), CColor), asCALL_THISCALL) > -1 );

        assert( pEngine->RegisterObjectMethod("CColor", "CColor opAddAssign ( float )", asMETHODPR(CColor, operator +=, (float), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opSubAssign ( float )", asMETHODPR(CColor, operator -=, (float), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opMulAssign ( float )", asMETHODPR(CColor, operator *=, (float), CColor), asCALL_THISCALL) > -1 );
        assert( pEngine->RegisterObjectMethod("CColor", "CColor opDivAssign ( float )", asMETHODPR(CColor, operator /=, (float), CColor), asCALL_THISCALL) > -1 );

        // Class members
        assert( pEngine->RegisterObjectMethod("CColor", "void Set( float r, float g, float b, float a )", asMETHOD(CColor, Set), asCALL_THISCALL) > -1 );

        // Register property
        assert( pEngine->RegisterObjectProperty("CColor", "float r", asOFFSET(CColor, r)) > -1 );
	    assert( pEngine->RegisterObjectProperty("CColor", "float g", asOFFSET(CColor, g)) > -1 );
	    assert( pEngine->RegisterObjectProperty("CColor", "float b", asOFFSET(CColor, b)) > -1 );
	    assert( pEngine->RegisterObjectProperty("CColor", "float a", asOFFSET(CColor, a)) > -1 );
    }

}   // NScriptColor

This is my script class I'm using to pass in as a reference. This is how my scripts will affect my sprite class's behavior.

/************************************************************************
*    desc:  Register the class with AngelScript
************************************************************************/
void CScriptComponent2d::Register( asIScriptEngine * pEngine )
{
    // Register CScriptComponent2d reference and methods
    assert( pEngine->RegisterObjectType("CScriptComponent2d", 0, asOBJ_REF|asOBJ_NOCOUNT) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "void SetVisible(bool visible)", asMETHOD(CScriptComponent2d, SetVisible), asCALL_THISCALL) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "void SetColor(CColor & in)", asMETHOD(CScriptComponent2d, SetColor), asCALL_THISCALL) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "const CColor & GetColor()", asMETHOD(CScriptComponent2d, GetColor), asCALL_THISCALL) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "const CColor & GetDefaultColor()", asMETHOD(CScriptComponent2d, GetDefaultColor), asCALL_THISCALL) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "uint GetFrameCount()", asMETHOD(CScriptComponent2d, GetFrameCount), asCALL_THISCALL) > -1 );
    assert( pEngine->RegisterObjectMethod("CScriptComponent2d", "void SetFrame(uint index)", asMETHOD(CScriptComponent2d, SetFrame), asCALL_THISCALL) > -1 );

}   // Register

Here's my Global functions. Nothing too fancy. Just the bare basics.

/************************************************************************
*    FILE NAME:       scriptglobals.cpp
*
*    DESCRIPTION:     AngelScript global function registration
************************************************************************/

// Physical component dependency
#include <script/scriptglobals.h>

// Standard lib dependencies
#include <assert.h>

// AngelScript lib dependencies
#include <angelscript.h>

// Game lib dependencies
#include <utilities/highresolutiontimer.h>
#include <utilities/genfunc.h>

namespace NScriptGlobals
{
    /************************************************************************
    *    desc:  Suspend the script to the game loop                                                             
    ************************************************************************/
    void Suspend()
    {
        asIScriptContext *ctx = asGetActiveContext();

        // Suspend the context so the game loop can resumed
        if( ctx )
            ctx->Suspend();

    }   // Suspend


    /************************************************************************
	*    desc:  Register the global functions
	************************************************************************/
    void Register( asIScriptEngine * pEngine )
    {
        assert( pEngine->RegisterGlobalFunction("float GetElapsedTime()", asMETHOD(CHighResTimer, GetElapsedTime), asCALL_THISCALL_ASGLOBAL, &CHighResTimer::Instance()) > -1 );
        assert( pEngine->RegisterGlobalFunction("void Print(string &in)", asFUNCTION(NGenFunc::PostDebugMsg), asCALL_CDECL) > -1 );
        assert( pEngine->RegisterGlobalFunction("void Suspend()", asFUNCTION(Suspend), asCALL_CDECL) > -1 );
    }

}   // NScriptGlobals

Here's my test script.

void Fade( CScriptComponent2d @script )
{
    Hold( 500 );

    while( true )
    {
        Hold( 100 );

        ColorTo( 1000, CColor(1,1,1,0), script );

        Hold( 200 );

        ColorTo( 1000, CColor(1,1,1,1), script );
    }
}

void Animate( CScriptComponent2d @script )
{
    while( true )
    {
        Play( 24, script );
    }
}

And here's my utilities script that I'm building as a script library of general purpose functions.

/************************************************************************
*    FILE NAME:       utilities.ang
*
*    DESCRIPTION:     General purpose utility scripts
************************************************************************/

/************************************************************************
*    desc:  Color to the final color in time                                                             
************************************************************************/
void ColorTo( float time, CColor final, CScriptComponent2d & script )
{
    CColor current = script.GetColor();
    CColor inc = (final - script.GetColor()) / time;

    while( true )
    {
        time -= GetElapsedTime();

        current += inc * GetElapsedTime();
        script.SetColor( current );

        if( time < 0 )
        {
            script.SetColor( final );
            break;
        }

        Suspend();
    }

}   // ColorTo


/************************************************************************
*    desc:  Play the animation                                                             
************************************************************************/
void Play( float fps, CScriptComponent2d & script )
{
    float time = 1000.0 / fps;
    uint frameCount = script.GetFrameCount();

    for( uint i = 0; i < frameCount; ++i )
    {
        script.SetFrame( i );

        Hold( time );
    }

}   // ColorTo


/************************************************************************
*    desc:  Hold the script execution in time                                                            
************************************************************************/
void Hold( float time )
{
    while( true )
    {
        time -= GetElapsedTime();

        if( time < 0 )
            break;

        Suspend();
    }

}   // Hold

As stated above, everything works in debug mode and the only thing that works in release mode is an empty do nothing function. Even that won't work if I add the global function Print("test");

 

AngelScript is so amazing.

 

Thanks for your help!


No window frame when going from full screen back to windowed mode

06 January 2013 - 05:35 PM

I have read through tons of post here on this subject and looked at numerous code examples and for the life of me, I can't get this to work correctly. As far as I can tell, I'm not doing anything different then what I have been seeing.

 

I start out in windowed mode and then change it to full screen mode and then change it back to windowed mode. Even though I'm resetting the styles via "SetWindowLong" and then calling "SetWindowPos", I'm left with a window with no window frame.

 

I've tested this ever way I can think of. Any idea of what I might be missing?

 

I define the styles in the constructor as class members...

CXWindow::CXWindow() :
...
windowedStyle(WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX),
windowedExStyle(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE),
fullScreenStyle(WS_POPUP|WS_VISIBLE),
fullScreenExStyle(WS_EX_TOPMOST)

 

This is how I create the window.

void CXWindow::CreateXWindow( const HINSTANCE hInst )
{
    uint dwExStyle;
    uint dwStyle;

	RECT rect;

	// Set the rect
    SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSize().w, (int)CSettings::Instance().GetSize().h );

    if( CSettings::Instance().GetFullScreen() )
    {
        dwExStyle = fullScreenExStyle;
        dwStyle = fullScreenStyle;
    }
	else
    {       
        // Setup the styles
        dwExStyle = windowedExStyle;
        dwStyle = windowedStyle;   
    }
    
    // Create the window
    hWnd = CreateWindowEx( dwExStyle,
						   CSettings::Instance().GetGameWndClassName().c_str(),
						   "",
                           dwStyle,
						   rect.left,
						   rect.top,
                           rect.right,
						   rect.bottom,
                           NULL,
						   NULL,
						   hInst,
						   NULL );

	if( hWnd == NULL )
		throw NExcept::CCriticalException("Create Window Error",
			boost::str( boost::format("There was an error creating the game window.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

	if( !CSettings::Instance().GetFullScreen() )
	{
		// Adjust the rect so that the client size of the window is the exact size of the needed resolution
		AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );

		// Position the window in the center of the screen
		SetWindowPos( hWnd,
					  HWND_NOTOPMOST,
					  (GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2, 
					  (GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
					  rect.right - rect.left,
					  rect.bottom - rect.top,
					  SWP_NOACTIVATE );
	}

}   // CreateXWindow

 

I call this prior to resetting the DirectX device. I've even recalled it after the device was reset.

void CXWindow::ResetWindowStyle()
{
	if( CSettings::Instance().WasScreenModeChanged() )
	{
		uint dwExStyle = windowedExStyle;
		uint dwStyle = windowedStyle;

		if( CSettings::Instance().GetFullScreen() )
		{
			dwExStyle = fullScreenExStyle;
			dwStyle = fullScreenStyle;
		}

		// Change the windows styles
		SetWindowLong( hWnd, GWL_STYLE, dwStyle);
		SetWindowLong( hWnd, GWL_EXSTYLE, dwExStyle);
	}

}	// ResetWindowStyle

 

This is what I call after the device reset. One odd thing to note is that in this function, "AdjustWindowRectEx" does not change the rect like it does when the window was first created. The rect remains unchanged.

void CXWindow::ResetWindowSize()
{
RECT rect;

	// Set the rect
    SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSizeChange().w, (int)CSettings::Instance().GetSizeChange().h );

	if( CSettings::Instance().WasResolutionChanged() || CSettings::Instance().WasScreenModeChanged() )
	{
		if( CSettings::Instance().WasResolutionChanged() )
		{
			// Recalculate the default size and ratio
			CSettings::Instance().CalcRatio( CSettings::Instance().GetSizeChange() );

			// Recalculate the projection matrixes
			CalcProjMatrix( CSettings::Instance().GetSizeChange(),
							CSettings::Instance().GetDefaultSize() );
		}

		if( !CSettings::Instance().WasScreenModeChanged() )
		{
			// Adjust the rect so that the client size of the window is the exact size of the needed resolution
			AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );

			// Position the window in the center of the screen
			SetWindowPos( hWnd,
						  HWND_TOP,
						  (GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2, 
						  (GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
						  rect.right - rect.left,
						  rect.bottom - rect.top,
						  SWP_FRAMECHANGED|SWP_SHOWWINDOW );
		}
	}

}	// ResetWindow

PARTNERS