Jump to content

  • Log In with Google      Sign In   
  • Create Account

SteveHatcher

Member Since 27 Nov 2013
Offline Last Active Yesterday, 01:35 AM

#5284002 Gamestate and Intro, Main Menu, Playing state

Posted by SteveHatcher on 29 March 2016 - 12:47 AM

Hi All,

 

I have added a game state FSM based on the 'Miner' Demo of Matt Bucklands 'Programming Game AI by Example'.

 

I would like some advice on how to link the Intro Splash Screen, Main menu (which just will have Play game, Settings, Quit), and then the actual Game with it. I am working with what will hopefully be a component based engine .

 

In my game::init() function I have

 

m_gameState.ChangeState(SplashScreen::Instance());

 

as I want the program to first display a quick logo.

 

game::update() function I will have

 

GameState state(m_gameState.getGameState());

if (state == GS_Playing)
{
        // update game specifc systems here
}

 

First thing, how should I handle things like the splash screen and main menu? When should they get loaded / rendered? Should there be a specific system for them (MenuSystem)? Do they need to be updated in the game::update() loop, or just the game::render() loop?

 

I would love any advice on how to handle this, or links to a sample project that show this.

 

Thanks




#5271487 How to actually measure stuff like cache hit, prefetch, ram traversal?

Posted by SteveHatcher on 16 January 2016 - 07:53 PM

Hi Guys,

 

This question is mostly out of pure interest.

 

Reading a lot of topics on this forum about game engine design and code, I often come across posts that say something like "this way you are more likely to load the next bit of data into the memory that the cpu will need, increasing cache coherency...", usually in topics about data oriented design (DOD).

 

From my understanding, DOD is something to do with stuff being in contiguous memory that the cpu cycles over each game loop, and it seems easier to achieve this using DOD rather than inheritance?

 

Secondly... how can you actually measure this stuff? I know in a very very simply game engine it doesn't really matter, but I have a learning game written using both ECS and just OOP that essentially does the same thing. (sprite moving around, shoots, gets shot at by enemies). How can I compare which implementation is actually better, and what areas of each one are working well?

 

I hope my question makes sense.

 

Thanks




#5251322 Examples of win32 Gui code?

Posted by SteveHatcher on 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




#5249018 Programming scientific GUI's, data and gui layout?

Posted by SteveHatcher on 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.

Attached Thumbnails

  • gui.png



#5243333 First game AI pathfinding

Posted by SteveHatcher on 29 July 2015 - 12:07 AM

@ferrous Thanks, I would like to code a variety of solutions for learning purposes, and then implement the one I find is the best into my game. I have heard that steering behaviour can sometimes be used instead of pathfinding. I am probably overshooting with ambition here but eventaully when a few enemy ships are around I would like them to also be able to not run into eachother.. but first things first.

 

@xoxos I like the idea of temporal behaviour switching, that would be easy to code and could look quite cool. I guess it could mimic the 'randomness' of humans. E.g. fly towards player for 1-3 seconds, then shift to the left then back off.

 

@braindigitalis Thanks for the input. I am quite confident with maths (use MATLAB a lot for work), so not worried about that aspect of it. I am using C++ with VS2013. I am using the directX tool kit to do my spirte rendering for me, and entityX ECS framework for game objects that have complex behaviours and / or components (such as ships with different guns / effects).

 

Thanks all. I will start with some basic implementations and go from there.




#5243212 First game AI pathfinding

Posted by SteveHatcher on 28 July 2015 - 11:21 AM

Hello,

 

I am a relatively new programmer building a spaceship game and I'm at the point where I would like to add in some (basic) interesting A.I.

 

Right now there are two AI 'options'. One of them is just moving directly towards the player. The other is shooting at the player. I want to make the movement more interesting (right now it is just in a straight line towards the player.)

 

I would also like to take this opportunity to learn pathfinding. My idea is to 'draw' some invisible barriers that the enemy ships cannot pass (walls if this would be a ground based game). The enemies would have to strafe around these barriers to get a clear 'shot' on the player. Of course the barriers are not actually visible in the game world, so I think it would make for a cool effect. Attached is an illustration of the idea.

pic1.png

pic2.png

In pic 2, the red barrier (could be another map layer that is 'collidable') blocks the line of sight from the ship, so it has to scoot around the side to get a clear shot.

 

My questions:

1. What terms should I be looking up / reading that are relevant to this cause?  I have read about A star pathfinding… is that applicable in this situation? Remember I don’t want the ship to literally hug the wall, but a ‘smooth’ strafe around the side of it. (Starcraft 2 style… I wish)

 

2. How does pathfinding and AI interact? Who is the ‘boss’ so to speak. Is it pathfinding that tells AI “go here now, go here now” or is it AI that asks pathfinding “Where do I go, is this clear, can I shoot now?” What is the order in the update loop?

 

3. Is this kind of situation a constant (per update loop) “polling” type situation (like controller input), or an event type situation (like perhaps two objects colliding), or a combination of both.

 

4. I have read that things in game programming should be decoupled as much as possible, is that also relevant in this case?

 

Thanks for all and any assistance.




#5226921 Adding non ECS features in an ECS engine (tilemap)?

Posted by SteveHatcher on 03 May 2015 - 02:35 AM

Why do you need to use ECS to accomplish your goal (a game)?

Why does every class member start with “m_” except the “graphics” class member?  What kind of sloppiness is this?

 

 

L. Spiro

 

 

I love your posts Spiro. They are always incredibly helpful, but also strike the fear of god into me...

 

Why do you need to use ECS to accomplish your goal (a game)?

 

To be honest I am not good enough at C++ to know what I do or do not need... but when I was working with my original OOP game and wanted to start adding in enemies with different guns and shields and all sorts of fancy ideas in my head, posts that I found (not just on gamedev) kept saying ECS this ECS this ECS this so I wanted to see what the fuss is about and give it a go.

 

Why does every class member start with “m_” except the “graphics” class member?  What kind of sloppiness is this?

 

Well spotted, I did not even realize that lol.. I do not really want to use the m_ prefix at all. But I found when I was initializing objects in their constructor using initialized lists, I kept getting confused about the private member I was trying to initialize, and the passed in variable or object I was initializing it with... so I say in my head (m_ goes Outside the brackets...)

thanks




#5226452 What is this stuff called in c++

Posted by SteveHatcher on 30 April 2015 - 02:24 AM

@ProgrammerDX

 

Yes it is similar to that. Its going to take me quite some time to understand what is going on there though. I need really basic examples that literally just do operations on numbers to make the link to an actual engines implementation.

 

@Juliean

 

Thanks a lot for your comprehensive explanation. Definitely clears a lot up for me better than what readings I could find on the net. I understand only what of templates was covered in the C++ book I read (Starting Out with C++ from Control Structures to Objects). I will revise that chapter to clue up on them again since the key things here seem to be templates.

 

Unless I'm mistaken, EntityX uses the CRTP in this case to generate a unique TypeID for the derived system. This is possible since by inheriting from Receiver<Game>, the compiler generates a seperate template instantiation. Somewhere inside the code, there is a static variable that is incremented every time a certain GetID()-function is called, but only once for every different instantation. Looks like this implementationwise:

 

Yes it does seem to be doing something like that when I step into the code. Now for once I actually have a clue as to what use the CRTP is.

Reading through the rest of your post while looking at the source code gives me a lot of help so thanks again.

 

@wicked520

 

That's the kind of key words I am looking for. Thanks.

 

@wintertime

 

It is primarily the strange looking code that I have not seen in my book before, combined with not knowing what this stuff is CALLED that I was struggling with. Your psot gave me a lot of what I needed too.

 

Thanks everyone I have learnt a lot, and have a lot of reading to do now on these new keywords.




#5225485 Dx11, directxmath and d3dx

Posted by SteveHatcher on 25 April 2015 - 11:57 AM

And if you're going to use directXTK, you can also use SimpleMath which wraps DirectXMath

 

https://directxtk.codeplex.com/wikipage?title=SimpleMath




#5222013 How to pass DeviceContext to other classes?

Posted by SteveHatcher on 08 April 2015 - 01:26 AM

I asked a very similar question here: https://directxtk.codeplex.com/discussions/611607

 

Basically when you create your device and deviceContext, these initialized objects "live" in the private member section of your game class as you wrote. Now you want to load a texture, and you see you need the device and/or deviceContext for that, so you need to have a place for them in your MyTexture class. You can either just create temporary objects of the device and device context in the constructor as Josh suggested, or store them in your MyTexture as private members.




#5218217 How to initialize a class member variable when using compositon?

Posted by SteveHatcher on 22 March 2015 - 03:04 AM

I am struggling to understand a concept when using composition in c++. I have created a demo program to illustrate my confusion. The program might seem a bit pointless but its only purpose is to illustrate my question.

#include <iostream>
using namespace std;

class Shape
{
private:
    double width;
    double length;
    double area;

public:
    void init(int, int);
    double getArea() const
    {
        return area;
    }

};

class Rectangle : public Shape
{
private:
    
public:

};

void Shape::init(int wid, int hei)
{
    width = wid;
    length = hei;

    area = length * width;
}

class ShapeArea
{
private:
    Rectangle rectShape;
    int area;

public:
    ShapeArea()
    {
        area = rectShape.getArea();
    }
};

int main()
{
    Rectangle rectShape;
    rectShape.init(5, 5);
    
    ShapeArea newshape;

    getchar();
    return 0;
}

In this program I create a rectShape object, and initialize its width and length as 5, and the program calculates its area, and stores them all as member variables.

 

Now I have created a class called ShapeArea, and using composition given it Rectangle object called rectShape.

class ShapeArea
{
private:
    Rectangle rectShape;
    int area;

public:
    ShapeArea()
    {
        area = rectShape.getArea();
    }
};

In its constructor, I am allowed to call rectShape.getArea(), because getArea() is a member function of class Rectangle (derived from class Shape). The problem I am facing is that the rectShape object it is using to call this function is filled with random values in memory.

 

So my question is, in this design, how do I tell class ShapeArea that the rectShape Rectangle object I want to call the getArea() function of, is the one I have already created earlier in the program? Ideally I want the newshape object I create to have the value "25" as area.

I hope this question is clear.

 

Thanks




#5212706 Where can one learn DirectX 11

Posted by SteveHatcher on 24 February 2015 - 08:20 AM

Depends how you learn best, I learn best by diving right into code and then googling functions. These tutorials can get you on your feet with DX11

 

https://code.msdn.microsoft.com/Direct3D-Tutorial-Win32-829979ef




#5210036 Can't figure out why DXTK crashes at Draw()

Posted by SteveHatcher on 11 February 2015 - 08:30 AM

"For your own sake, are you going to step through the same code in the debugger, over and over, every time you have a problem? That's up to you, but, if you're new to coding, that's not the best way to learn good coding practice."

 

I should have taken your advice earlier, I found the problem, and it was from me forgetting to pass the graphics class to my mgeSprite constructor. I would have found this with some in-function error checking.

Spiro's and your post about the local variables getting erased proimped me to go through it all and check these things.

 

I needed to use

 

spr = new mgeSprite(graphics, tex, 96, 64, 32, 32);

 

and then assign the graphics object to my new sprite object inside the mgeSprite class e.g.

 

mgeSprite::mgeSprite(Graphics *g, ID3D11ShaderResourceView* texture, float texx, float texy, float w, float h)
{
    graphics = g;

 

The problem I think was when I was getting down to

 

void mgeSprite::Render(float x, float y)
{
    graphics->drawSpriteQuad(&quad);
}

 

The graphics-> object at that point was not the right one.

 

Id have never found this without the help. And I will go through the code as it is now and add some error checking. Thanks again for the advice and constructive criticism.




#5208004 When to use pointers or objects in 'Composition'?

Posted by SteveHatcher on 01 February 2015 - 01:08 AM

Before I start please know I am a beginner so I may be asking a silly question or getting terminology wrong.

 

I have a simple program which initializes a win32 window, and then initializes directX 11 in that window.

 

The directX initialization is held in a class Graphics

 

The win32 window is held in a class MainWindow. My program flow goes as follows:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    window = new MainWindow;
    window->initialize(hwnd, hInstance, nCmdShow);

the MainWindow::initialize function does all of that registering a win32 class and creating the window. At the bottom of this function is where I want to initialize directX within the window. This is where I get confused. As far as I am aware there seems to be three ways to do this.

 

METHOD 1. Use inheritance.

class MainWindow : public Graphics
{
private:
    HWND hwnd;
    HINSTANCE hInstance;
    HRESULT hr;
    int nCmdShow;

public:
    MainWindow();
    ~MainWindow();
    void initialize(HWND hwnd, HINSTANCE hInstance, int nCmdShow);
    static LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
};

then after the ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); of my MainWindow::initialize() function, I can write.

    Graphics graphics;
    
    graphics.initialize(hwnd, 640, 480, false);
    graphics.showBackbuffer();

METHOD 2. Composition with an object.

Removing the inheritance line : public Graphics, means I need to put a Graphics object in my MainWindow member variable section e.g.

class MainWindow
{
private:
    HWND hwnd;
    HINSTANCE hInstance;
    Graphics graphics; <------------- ADDED THIS
    HRESULT hr;
    int nCmdShow;

I can now leave the same code as before, but remove the Graphics graphics; object declaration since it has already been done.

 

METHOD 3. Composition with a pointer to a graphics object.

The third method is to declare a pointer to a graphics object (which will be created later), in class MainWindow e.g.

class MainWindow
{
private:
    HWND hwnd;
    HINSTANCE hInstance;
    Graphics *graphics; <------------- ADDED THIS
    HRESULT hr;
    int nCmdShow;

This time, to initialize my directX window I write

    graphics = new Graphics();
    graphics->initialize(hwnd, 640, 480, false);
    graphics->showBackbuffer();

At this stage I am very confused. They all essentially get me where I want to be, but there would be a lot of behind the scenes stuff going on of which I have no idea.

 

So could someone clarify which method is best to use in this example?

 

Thanks

 

 

 




#5203204 Using DrawText or TextOut over DirectX?

Posted by SteveHatcher on 09 January 2015 - 08:33 PM

Hi Buckeye,

 

Thanks for your help, with your updates I managed to get it working. Seems like a nice clean way to get some debug info on screen. I had a play around with it and noticed it can also work with DrawText which I am a bit more familiar with.

Thanks again for your help

 

@Washu don't worry I haven't forgotten about you. I am going to have a go at yours next, whichever I end up using I find this an extremely good learning experience for the complicated world of DXGI stuff.






PARTNERS