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

Login with username, password and session length

 
Advanced search

1059239 Posts in 43058 Topics- by 35015 Members - Latest Member: bersaelor

October 31, 2014, 04:01:53 AM
TIGSource ForumsFeedbackDevLogsSpaceHero Command
Pages: 1 ... 32 33 [34] 35 36 ... 43
Print
Author Topic: SpaceHero Command  (Read 70396 times)
happymonster
Level 10
*****



View Profile WWW
« Reply #660 on: November 06, 2012, 02:17:51 PM »

Had a very busy social life these last few days and just saw Skyfall which is very good.

In another news, Julian Gollop has started a remake of Chaos! As I've done two full remakes of the game, I've very pleased to hear this..  Gomez
Logged

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



View Profile WWW
« Reply #661 on: November 13, 2012, 11:26:03 AM »

Nothing too exciting to report - re-factoring continues (albeit slowly because I've had a busy social life these last few weeks)

Still a lot to do, I should never have let it get in this state!  Apoplectic
Logged

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



View Profile WWW
« Reply #662 on: November 13, 2012, 02:07:02 PM »

you_can_do_it_dude()!
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #663 on: November 13, 2012, 02:29:59 PM »

Yes I can..!

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 #664 on: November 13, 2012, 02:40:50 PM »

Caveat, do you mean to be passing a reference TO the structure fields, instead of the value contained within the structure fields?
Logged

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



View Profile WWW
« Reply #665 on: November 13, 2012, 02:45:35 PM »

Yes, it should pass a reference to the structure.
Logged

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



View Profile WWW
« Reply #666 on: November 13, 2012, 02:52:18 PM »

Oooh ok, which is better (in all respects), this:

Code:
for(.i..){
  int x = blah(i);
  do_something(x);
}

or this:

Code:
int x;
for(.i..){
  x = blah(i);
  do_something(x);
}
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #667 on: November 13, 2012, 03:01:23 PM »

Good point, well made!  Hand Clap
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 #668 on: November 13, 2012, 04:34:47 PM »

Code:
for(.i..){
  do_something(blah(i));
}

Reason I ask about passing a reference to the field is because that only makes sense if you want the function to modify the field passed in...  And it's generally bad programming practice to have functions that do things to the parameters passed in as a side effect.

In other words, I would prefer:

Code:
x = blah(x);

Versus:

Code:
blahModifiesX(&x);
Logged

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



View Profile WWW
« Reply #669 on: November 13, 2012, 06:17:59 PM »

Code:
for(.i..){
  do_something(blah(i));
}

nope! its less readable and i think no more efficient, especially if you const the x (but you probably dont have to for it to be optimised out anyway..)
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #670 on: November 14, 2012, 12:05:29 AM »

Lynx:

But it's not a side effect. The function takes the address of a struct and then modifies an internal variable inside it. There is no need to return back the pointer to the struct as it won't be used.

Logged

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


high-heeled cyberbully


View Profile
« Reply #671 on: November 14, 2012, 12:23:58 AM »

In lynx's scenario the blah function would only return a modified version of x, not operate on the original.
Logged

eigenbom
Level 10
*****



View Profile WWW
« Reply #672 on: November 14, 2012, 01:00:45 PM »

Yeh, it's not a side-effect, it's the primary purpose of that function, which is clear given that its called Set_.....
Logged

happymonster
Level 10
*****



View Profile WWW
« Reply #673 on: November 14, 2012, 02:07:43 PM »

How would you do it instead?

I might end up encapsulating the Alpha struct anyway, but I can't think of any easy way to do that in C without using some C++ (which I'm very much a novice with).
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 #674 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 #675 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 #676 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 #677 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 #678 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 #679 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

Pages: 1 ... 32 33 [34] 35 36 ... 43
Print
Jump to:  

Theme orange-lt created by panic