Jump to content

  • Log In with Google      Sign In   
  • Create Account

SteveHatcher

Member Since 27 Nov 2013
Offline Last Active Apr 26 2016 11:29 PM

Posts I've Made

In Topic: Gamestate and Intro, Main Menu, Playing state

31 March 2016 - 10:25 PM

I don't know the best answer to this but in my app I currently have a state machine and states. The state machine has a few methods:

 

Update(time)

Render

QueueState

PushState

PopState

and input type methods

 

Thanks, from what I have been reading down the track I will need to add a 'Stack' of states (just using a vector?) so I can have multiple screens or states open at once like you do. For now I just want to start simple and get the basics working.

 

 

The main loop just calls Update and Render.

 

Do you mean that in your game::update() loop all you call is gameState.update(), and let the gamestate class itself deal with all of the states, 'outside' of the main game loop?
Eg for each update step, instead of in game::update()

gameState.ChangeState(Intro),
gameState.ChangeState(Playing),

all you ever have called is

gameState.update()?

 

 

I would just initialise things, create a SplashScreen state, push it onto the state machine and then start the main loop. From there on it's the SplashState that decides what's happening,

 

Okay, so the state machine is the most 'outer layer' (besides the game loop), of the engine? Literally each update loop, the first thing the game engine does is check the state, and then executes the code only within that state?

 

 

States should take care of their own rendering (either directly or by getting themselves into some draw/command lists to render themselves), they should update themselves and they should deal with input themselves.

This is where I am a little stuck. From my reading and how I would like to go about things, I will have one 'RenderSystem' that just calls 'm_graphics->drawSprite(spriteData)'; each update loop. Previously I was using entitiyx ECS and would call it in the 'for (entityx::Entity entity : entities.entities_with_components(position, display))' loop, but I am moving away from ECS.

 

 

General Game/Engine Structure
Passing Data Between Game States

 

 

Thanks, I had actually read these articles already, the General Game Structure topic was great and got me started, but to be honest Passing Data Between Game States was a bit beyond me. I struggle to take programming concepts from just reading too... so am just trying to get stuck into it and then revisit things once I have a bit more of an idea.

 

 

Loaded on the next frame after being set.
Rendered every frame.

 

 

I think what I meant to ask is 'Where' should they get loaded / rendered. As in where about in the game engine. Should the gameState class itself handle all of this internally? Or should the main engine 'check' the game state class each loop and perform the relevant actions?

 

 

What does that mean?

 

 

My last attempt was using entityx ECS and game::update() called
    
void Game::update()
{
    GameState state(m_gameManager.getGameState());

    if (state == GS_Playing)
    {
        m_systemManager.update<PlayerControlSystem>(frameTime);
        m_systemManager.update<MovementSystem>(frameTime);
    }
}
    
so I am wondering do I use the same approach and have a

m_systemManager.update<MenuSystem>(frameTime);

 

that is controlled the same way the rest of the 'Game playing' Logic is, or are menus a separate thing?

 

 

These are not separate loops. There is only 1 game loop, which may update the game logic 0 or more times, and always renders one time.
Fixed-Time-Step Implementation

 

 

Sorry, by this I mean my game::run() loop, which looks like this (it is based on the game engine of Charles Kellys programming2dgames book:

void Game::run()
{

    // calculate elapsed time of last frame, save in frameTime
    QueryPerformanceCounter(&timeEnd);
    frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart) / (float)timerFreq.QuadPart;
    if (frameTime < MIN_FRAME_TIME)
    {
        sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime) * 1000);
        timeBeginPeriod(1);         // Request 1mS resolution for windows timer
        Sleep(sleepTime);           // release cpu for sleepTime
        timeEndPeriod(1);           // End 1mS timer resolution
        return;
    }

    if (frameTime > 0.0)
        fps = (fps*0.99f) + (0.01f / frameTime);  // average fps
    if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow
        frameTime = MAX_FRAME_TIME; // limit maximum frameTime
    timeStart = timeEnd;

    update();
    render();
}

 

 

Why would you hope for an over-engineered misguided system that you can’t possibly use correctly/fully and doesn’t serve your needs best?

ECS is a buzzword and solves a specific domain of problems suitable only to marketed engines such as Unity. It’s not for you and doesn’t help you in any way. Stop doing things just because they are buzzwords.

 

 

My bad, I am planning to use components as per http://gameprogrammingpatterns.com/component.html . My last attempt was an ECS engine and I should have listened to you guys and not gone down this track. I did find it quite 'convenient' but also did not find I was actually learning c++ game programming by using it, since the huge library was doing all of the heavy lifting for me. I was also having issues when it came to things that did not so obviously fit into the ECS pattern e.g. when I implemented a quadtree it was actually slower as I had to extract and pass in the entity ID's and do heaps of derefrencing rather than just filling it with all the objects and working on them directly. (which I think was the problem... I am not good enough at programming to say for sure...). One thing I did learn from ECS was how and why we want to separate out data and logic into these systems... so essentially I am trying to recreate that decoupling and flexibility but without some massive ECS library doing god knows what...

Thanks for all your comments guys.


In Topic: Game engine communication (character

30 November 2015 - 10:04 PM

Thanks guys, I have some questions if you will...

 

"In your second example,

    - "Character Animation" (I assume that's a system) knows what state the user is in. That's a bad dependency. It should have no knowledge of that.

    -FireballSpawner also should not know about user state. These kinds of things make your components/systems non-reusable."

 

I hear this "xxx should have no knowledge of what state yyy is in" quite a lot, often in cases where xxx and yyy will be something 'related' in a game like my example (a fireball casting animation and a fireball appearing).

 

In cases like these, what are the techniques for getting the information to where it needs to go? BeerNutts suggested events (which I often hear of), are they the way to go? Are there alternatives to events? And is this stuff called something in programming? (when I say stuff, I mean directing information from one part of a program to another but in a non hard-coded way, is it to do with events, observers, listeners... something else?)

 

Would I be right in saying a hard coded way would be more used in windows applications where everything is well defined at all stages of the program (nothing 'comes and goes' like in games)...

 

"Some highlevel code (this could be a script attached to the player object, maybe) knows that where there is a 'cast fireball' action, it needs to then switch to a casting animation, and a few moments later a fireball should be spawned."

 

In an ECS example what exactly would 'highlevel' and 'low level' code be? Is low level code a particular system?

 

"I don't really know how your system is set up, but let's say you have an AnimationComponent and corresponding system that manages playing those animations. It could be as simple as setting the current animation in the AnimationCompnent to "cast" or however you identify your animations. The animation system will then see that next time it runs, and switch to (or start transitioning to) that animation for that entity."

 

Okay, I actually have an AnnimationSystem setup in a way that can quite easily do that. So basically, the systems run each loop anyway, so its about letting the systems know what 'state' to be in when they are going to be checked?

 

Also yes, the key mapping is done a different way but I have ignored that for now, I am confused as to how to actually get the Animation to know the key has been pressed? Is this an event?

 

"As for the fireball, there is presumably some fireball prefab you can spawn, and then perhaps customize with attributes (direction, strength, distance, etc....) that depend on the player's skills. There's no FireballSpawner that knows about the player (that sounds like an overly-specific piece of code). There's just a prefab that gets created at the right time."

 

Ahh okay, so it would spawn a new 'fireball entity' using whatever attributes the game has to define the 'strength' of the fireball?

I am a bit confused now as to how the fireball entity knows to be created? Would this be in a "SpellSystem"? Is it similar to the AnimationSystem where it checks each loop if a fireball has been cast?

 

The main confusing me is all of these seemingly 'related' games mechanics should not know about the player, each other, or anything but themselves... so I have a hard time trying to understand how to code this...

 

"As you're designing your ECS, come up with a list of, say, 10-15 core scenarios that you want to accomplish (casting a fireball is a perfect example). Try to figure out in as much detail how this would be accomplished with your achitecture, down to who is setting which properties on what. Iterate/refactor/redesign until you have something where are your scenarios can be accomplished in a natural way."

 

This is exactly what I am trying to do.. this fireball example is I guess my first.. .and since I am very new at all this stuff and ECS... really had no idea where to go.

 

Thank you all for your time and effort in helping me!

 

 

 

 

 


In Topic: Examples of win32 Gui code?

14 September 2015 - 12:39 AM

Hi Servant, thanks for your detailed reply, I think I am getting the picture now. As you said, eventually it comes down to picking one and going for it...

 

 

As I said before, I'm biased in favor of Qt. Qt lets you make native applications looking the same visually like .NET does, but you can also theme them how you want and design your own widgets and such. Here's a complicated messy screenshot of my own project written in Qt. Mind the overuse of gradients and non-standard widgets - I get carried away. biggrin.png

 

 

wow, thats insane! So you made that whole program using Qt? Is all of the logic behind the scenes c++? The use of tabs and selectors etc is similar to how I want my GUI to look (although urs is a lot more complex)

 

So with QT it doesn't have to look like a typical windows program (for which I think of something like winRAR looks like...). Can the same effect be achieved with just the Win 32 API?

 

Thanks again for the info


In Topic: Examples of win32 Gui code?

09 September 2015 - 06:58 AM

Thanks guys, some great links here to get me started.

 

 

Win32 is old. It's expanded here and there, but alot of the "old" stuff is still how it's done. It's not like DirectX where Microsoft discards the API and gets to redesign it from the ground up - older applications must still work on newer systems, so the "old" Win32 is still Win32.

 

Were you wanting to learn the newer Microsoft APIs? You probably want WinRT or .NET then.

 

Are you just wanting to make desktop applications? I'm a huge fan of Qt (which is free even for closed-source commercial use if you link by DLL; don't get mislead by the website).

Qt provides cross-platform native-interface GUIs, and is very powerful, and also has fantastic documentation, a large community, and plenty of open-source example applications. It's best used with the QtCreator IDE, though.

 

I didn't know that about WinRT or .NET, I will look into them, thanks.

 

I am looking to make a desktop gui for myself and maybe a few others, for data processing. I have heard Qt is the way to go for making Win32 apps so I will probably play around a bit with the API to get a general feel for things then dive into Qt.

 

Quick question, I am getting a bit confused about all the terminology they are throwing around. In terms of the Win32 API, which is pretty much raw C and C++ (isint it?), where does WinRT and .NET fit into things?

 

I find examples of things I have used can help me understand. When making a game using D3D11 I used the DirectX tool kit, and SFML. Are WinRT and .NET anything like them?

 

Thanks


In Topic: Programming scientific GUI's, data and gui layout?

26 August 2015 - 10:46 AM

Hi Guys,

 

Thanks for all the input, some very sound advice here I am learning a lot. I think the biggest problem is as people have said, design patterns are more of a guideline, and there are no concrete 'correct' ways that can cover all the different combinations of data processing that may be undertaken.

 

Find a Gui toolkit for your programming language, and do the tutorial, make a button, print 'hello' when you push it, draw lines at the canvas, that sort of things. It should give you enough ideas of how to scale up to a more complete gui.
If you use C++ and don't know what Gui library to use, I'd recommend Qt. They have great tutorials and good documentation.

 

I am using MATLAB and quite comfortable with it and programming a GUI using OOP with it. I find reading about patterns like MVC is all well and good but without a proper example or implementation I really have no idea how to apply them to my own problems. I will give an example of the kind of things I am stuck with though. I attach a screenshot of my GUI as it stands now:

 

So the first thing the user does is press 'Add raw data', this opens a window where they can chose 1 or multiple data files. For the purposes of this example, each data file could be an .asc file, where each .asc file has a series of x and y data points. The file names are populated in the tab 'Raw Data', and the selected file name is plotted in the graph tab 'View 1'.

 

The user can select 1 or multiple files in the 'Raw Data' tab and click 'Double data values' to double the y values of the data points. The files that were doubled go into the tab 'Doubled Data', and when they are clicked on, will be displayed in 'View 1'.

 

The purpose of the View tabs could be different ways to show the data, such as line plot, scatter plot, bar chart...

 

My questions:

 

What exactly is the MVC setup for this?

 

Should 'Views' depend on the List boxes, or should the List boxes depends on the 'Views'. What I mean by this is when a data set is clicked on in 'Raw Data' should it check the View tabs with a switch statement to see which to display? And if I then click on a different 'View' should it query the List Box to see which file is highlighted, and then display that? But it would need to query both the 'Raw Data' and 'Doubled Data' List boxes, to first see which is 'Active' and then select the right file...? Basically there are so many combinations of things that I am struggling to see how best to have them communicate, and this is a tiny basic GUI...

 

Or am I linking the GUI elements with the data too tightly?

 

I have more people I need to quote and ask things but do not have time for now. I will get back to it. Thanks everyone for your input.


PARTNERS