Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

998170 Posts in 39143 Topics- by 30553 Members - Latest Member: drako30

April 17, 2014, 10:43:51 PM
TIGSource ForumsFeedbackDevLogsSpaceHero Command
Pages: 1 ... 44 45 [46] 47 48 ... 57
Print
Author Topic: SpaceHero Command  (Read 56854 times)
Lynx
Level 5
*****


Upstart Feline Miscreant


View Profile WWW Email
« Reply #675 on: November 14, 2012, 05:25:37 PM »

Okay, I think I see what you're trying to get at.  The highlighted_alpha etc. must be complex structures in their own right; if they were simple integers or floats, then you could trivially set them to 0.0 right there.

What I could imagine doing would be making them be fields of class Alpha, which has a setTarget function.  Then you would have:

Code:
    MapUiCell mapUiXY = map_ui[x][y];
    mapUiXY.highlighted_alpha.setTarget(0.0);
    mapUiXY.selected_alpha.setTarget(0.0);
    mapUiXY.arrow_gfx_alpha.setTarget(0.0);

Logged

Currently developing dot sneak - a minimalist stealth game
eigenbom
Level 10
*****



View Profile WWW
« Reply #676 on: November 14, 2012, 06:02:09 PM »

@Lynx, its fading the alpha, so I presume the target value is achieved over some period of time, not just set straight away.

Another approach could be to model animations themselves as entities (sticking with pseudo-C) ...

Code:
#define LERP_TO 4 // some unique type id
struct LerpToAction {
  float* source;
  float from;
  float to;
  float duration;
  int type;
};
void Fade_something(){
  LerpToAction lerpTo = new LerpToAction(&map[x][y].alpha, map[x][y].alpha, 0.f, 1.f);
  Add_animation(&lerpToAction);
}
void main(){
  loop {
    for(Action in globalActions){
      // do it!
    }
  }
 
}

but then you're spending more time on an engine instead of on a gam. which is good or bad.
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #677 on: November 14, 2012, 11:49:10 PM »

Okay, I think I see what you're trying to get at.  The highlighted_alpha etc. must be complex structures in their own right; if they were simple integers or floats, then you could trivially set them to 0.0 right there.

What I could imagine doing would be making them be fields of class Alpha, which has a setTarget function.  Then you would have:

Code:
    MapUiCell mapUiXY = map_ui[x][y];
    mapUiXY.highlighted_alpha.setTarget(0.0);
    mapUiXY.selected_alpha.setTarget(0.0);
    mapUiXY.arrow_gfx_alpha.setTarget(0.0);



Yeah, if I was going the C++ route then that's the kind of approach I would take.
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
happymonster
Level 10
*****



View Profile WWW
« Reply #678 on: November 15, 2012, 02:15:00 PM »

Strangely enough.. rewriting and improving code is rather addictive.

I say that because previously I've always wanted to add new code more than change existing stuff.  Who, Me?
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
Lynx
Level 5
*****


Upstart Feline Miscreant


View Profile WWW Email
« Reply #679 on: November 15, 2012, 02:32:59 PM »

I'm no stranger to rewriting and improving code, I've been rewriting my own game prototype-- not just changing basic calls to WebGL to work in HTML5 Canvas, but rebuilding the code to hopefully support a more robust engine going forward.  So I totally understand that feeling.

I like eigenbom's solution if you're trying to stay with pure C.
Logged

Currently developing dot sneak - a minimalist stealth game
eigenbom
Level 10
*****



View Profile WWW
« Reply #680 on: November 15, 2012, 02:40:58 PM »

Rewriting my main() recently was so uber satisfying for me. Smiley Check this business out... (excuse me for polluting your devlog!)

Code:
int main(int argc, char** argv)
{
        gGame = NULL;

        /////////////////////////////////////////
        // Setup logger and log welcome message
        /////////////////////////////////////////
        static const std::string LOG_FILE_NAME = ResourcePath() + "log.txt";

        mm::log = new TeeLogger(new ConsoleLogger(), new FileLogger(LOG_FILE_NAME));
               
        /////////////////////////////////////////////
        // Create Game
        /////////////////////////////////////////////

        gGame = new Game();

        /////////////////////////////////////////////
        // Create Root, SFML Window, and setup GUI
        /////////////////////////////////////////////

        Root::Initialise(GetArgumentsDictionaryFromCommandLine(argc, argv));
        Root::Instance()->createWindow();       
        LogSystemInfo();
        gGame->setupGUI();     

        LogWelcomeMessage();

        /////////////////////////////////////////////
        // Load loading screen and cursors
        /////////////////////////////////////////////   

        gGame->loadLoadingScreen();
        gGame->loadCursors();

        sf::Clock loadScreenUpdateClock;

        /////////////////////////////////////////////
        // Start loading resources
        /////////////////////////////////////////////   

        LOG_INFO(MM_LOG) << "Loading core resources.";

        sf::Thread loadingThread(&Root::loadCorePackage, Root::Instance());
        sf::Thread setupGameThread(&Game::setupGame, gGame);
        loadingThread.launch();
        bool hasLoadedCorePackage = false;

        /////////////////////////////////////////////
        // Setup profiler
        /////////////////////////////////////////////

        FunctionProfileVisualiser fProfiler;
        SetupProfiler(fProfiler);

        /////////////////////////////////////////////
        // Begin Loop
        /////////////////////////////////////////////

        LOG_INFO(MM_LOG) << "Starting...";
        bool requestResize = false;
        sf::Event::SizeEvent lastResizeRequest;
        sf::Clock lastResizeRequestTimer;
        sf::Clock frameTimer;   
        float lastFrameTime = 1./60;   
        bool gameOn = true;
        while (gameOn)
        {               
                if (!gGame->hasStartedGame()){

                        ////////////////////////////////////////
                        // Loading screen loop
                        ////////////////////////////////////////

                        sf::Event event;
                        while (Root::Instance()->window->pollEvent(event)) {
                                if (event.type == sf::Event::Closed){
                                        gameOn = false;
                                        loadingThread.terminate();
                                        setupGameThread.terminate();                                   
                                }
                                else {
                                        gGame->handleEventInLoadingScreen(event);
                                }
                        }

                        if (loadScreenUpdateClock.getElapsedTime().asMilliseconds() > 200){
                                loadScreenUpdateClock.restart();

                                if (gGame->hasSetupGame())
                                        gGame->startGame();
                                else
                                        ComputeProgressAndUpdateLoadingScreen(setupGameThread);                                 
                        }
                }
                else {

                        ////////////////////////////////////////
                        // In-game loop
                        ////////////////////////////////////////

                        frameTimer.restart();

                        // Process Input and Events
                        sf::Vector2i mousePos = sf::Mouse::getPosition(*Root::Instance()->window);
                        gui::Widget::setMousePos(mousePos);

                        {
                                PROFILE("Input");

                                sf::Event event;
                                while (Root::Instance()->window->pollEvent(event))
                                {
                                        // omitted..
                                }
                        }

                        /////////////////////////////////
                        // Handle window resize
                        /////////////////////////////////
                        if (requestResize && lastResizeRequestTimer.getElapsedTime().asMilliseconds() > 500){
                                requestResize = false;
                                gGame->handleWindowResizeInGame(lastResizeRequest.width,lastResizeRequest.height);
                        }
                        else if (requestResize){
                                // just skip everything..
                                Root::Instance()->window->display();   
                                continue;
                        }

                        /// TODO: do filesystem checkr
                        // if (fileSystemClock.GetElapsedTime() > 500){
                        //      gGame->fileSystemWatcher->check();
                        //      fileSystemClock.Reset();
                        // }
                       
                        /////////////////////////////////////
                        // Game Update
                        /////////////////////////////////////                   

                        gGame->updateWorld(lastFrameTime);
                        gGame->updateGUI(lastFrameTime);
                        gGame->processAllMessages();

                        gGame->doMoonmanAction(); // mine, use block, etc

                        gGame->doEditAction();         
                        gGame->updateEditFocus();                       

                        gGame->updateCamera(lastFrameTime);

                        ////////////////////////////////
                        // Rendering
                        ////////////////////////////////

                        gGame->renderWorldAndUI(lastFrameTime);
                        gGame->renderCursor();
                                               
                        ///////////////////////////////////////
                        // Profiling and fps
                        ///////////////////////////////////////
                                               
                        if (gGame->profilingEnabled())
                                UpdateAndDrawProfiler(*Root::Instance()->window, fProfiler, frameTimer.getElapsedTime().asMicroseconds());
                        UpdateAndDrawFps(*Root::Instance()->window, lastFrameTime);                     

                        /////////////////////////////////////////
                        // flush
                        /////////////////////////////////////////

                        Root::Instance()->window->display();   

                        ////////////////////////////////////////////////////
                        // Compute total frame time
                        // NB: This has to be done AFTER window->display()
                        ////////////////////////////////////////////////////

                        lastFrameTime = frameTimer.getElapsedTime().asSeconds();                       
                }
        }

        gGame->setConsoleVisible(true);

        // shut down everything...
        // Save first..
        if (gGame->hasStartedGame()){
                LOG_INFO(MM_LOG) << "Saving before shutdown";
                Root::Instance()->saveGameStateToFile(gGame->worldSaveFileName());
                Root::Instance()->saveSettings();
        }

        Root::Instance()->window->close();
        Root::ShutDown();

        delete gGame;
        return EXIT_SUCCESS;
}




Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #681 on: November 16, 2012, 04:04:35 PM »

Wouldn't it be better to separate out the title screen and ingame logic/rendering main loop into different functions? At the moment there seems a lot of lines in that ingame loop. Smiley
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
happymonster
Level 10
*****



View Profile WWW
« Reply #682 on: November 16, 2012, 04:07:11 PM »

I have a question:

If I wanted to abstract the data type internally from one source code file to another in C but be able to deal with arrays or maps of an object type, is this the best approach (once I've located a void pointer for the object in the array or map)?

Quote
char *Return_object_name( void **object )
{
    obj_t *obj = (struct obj_t *)object;
    return obj->name;
}
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
eigenbom
Level 10
*****



View Profile WWW
« Reply #683 on: November 16, 2012, 04:21:10 PM »

Yeh you're probably right, my main() was around 1000 lines before and now is around 200, so it's a dramatic improvement on what it was. Eventually the title screen and menu stuff will be hidden away in a class so that'll clean it up further. Still .. the big comments kind of act as code 'segmenters' for me, which is one way of modularising the code I suppose.

I have a question:

If I wanted to abstract the data type internally from one source code file to another in C but be able to deal with arrays or maps of an object type, is this the best approach (once I've located a void pointer for the object in the array or map)?

Quote
char *Return_object_name( void **object )
{
    obj_t *obj = (struct obj_t *)object;
    return obj->name;
}

this article on OO programming in C may help, but I don't know (except object should be a void* right?).
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #684 on: November 17, 2012, 02:20:07 AM »

Sorry, yes I meant to type void *

Thanks for the link..!
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
happymonster
Level 10
*****



View Profile WWW
« Reply #685 on: November 18, 2012, 07:23:43 AM »

Actually, I have spent some time this weekend encapsulating the Alpha struct using void* pointers. I'm happier with this now.  Smiley

Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
eigenbom
Level 10
*****



View Profile WWW
« Reply #686 on: November 18, 2012, 03:17:26 PM »

Actually, I have spent some time this weekend encapsulating the Alpha struct using void* pointers. I'm happier with this now.  Smiley

What's this for exactly?
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #687 on: November 21, 2012, 11:41:40 AM »

Opps, I missed your reply..!

The Alpha structs are for altering alpha values of various things (cursors, UI tiles, panels, etc..)

I'm currently re-factoring more of the code to use this kind of approach where data is completely private from other areas of the code. It's slow going, but something I've never really explored, so it's really helpful for my development as a programmer.
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
eigenbom
Level 10
*****



View Profile WWW
« Reply #688 on: November 21, 2012, 01:15:04 PM »

The Alpha structs are for altering alpha values of various things (cursors, UI tiles, panels, etc..)

I'm currently re-factoring more of the code to use this kind of approach where data is completely private from other areas of the code. It's slow going, but something I've never really explored, so it's really helpful for my development as a programmer.

Oh no, I was wondering why you are removing the type info altogether. I think I'm missing the point, but forward declaration would allow you to hide the implementation still but retain the types in the function signatures. Unless you are building a more generic system that operates on typeless chunks of data?

Code:
// alpha.h
struct alpha;
alpha* make(float val);
void change(alpha* alpha, float val);

Code:
// alpha.c
struct alpha {
  float a,b,c;
};

Code:
// main.c
#include "alpha.h"
..
alpha* alp = make(4.0);
change(alp,6);
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #689 on: November 21, 2012, 02:16:27 PM »

It's a more generic system really. I'm still experimenting with different things and seeing what I like best. Smiley
Logged

SpaceHero Command ... In Development
http://forums.tigsource.com/index.php?topic=23173.0
Pages: 1 ... 44 45 [46] 47 48 ... 57
Print
Jump to:  

Theme orange-lt created by panic