Jump to content

  • Log In with Google      Sign In   
  • Create Account


fastcall22

Member Since 04 Feb 2008
Online Last Active Today, 10:30 AM
****-

#5113828 triangles per second

Posted by fastcall22 on 02 December 2013 - 01:38 PM

42.

42 triangles.


EDIT:
I'd be more concerned about fillrate than triangles. Using stencil shadows, you'll be utilizing quite a bit more rendering time filling the stencil buffer for the shadows of those 42 triangles than you would be otherwise...


#5112489 (winapi) mouse hell

Posted by fastcall22 on 27 November 2013 - 11:03 AM

why this (the way I used it is bad i wrote some description previously I can add)

does the games use the way you write -it still seem bad for me

what exactly shoul i do, SetCursorPos(centreof window) in every WM_MOUSEMOVE handler?

As tonemgub suggested, you should always treat the center of the screen as the "previous mouse position":
 
case WM_MOUSEMOVE: {
    int x = GET_X_PARAM(lParam);
    int y = GET_Y_PARAM(lParam);
    
    int dx = x - center_x;
    int dy = y - center_y;
    
    if ( dx || dy ) {
        on_mouse_move( dx, dy );
        SetCursorPos( center_x, center_y );
    }
} break;
A WM_MOUSEMOVE is still generated when snapping the cursor back to the center of the screen, but the event is ignored, since dx and dy would be 0. As far as I know, most FPS games use this approach.
 

Also can I get more than one mousemove per frame

Yes, it may be possible to receive multiple WM_MOUSEMOVE events per frame. You may want to handle accordingly:
void on_mouse_move( int dx, int dy ) {
    total_dx += dx;
    total_dy += dy;
}

void on_update( float dt ) {
    update_camera_look(total_dx * sensitivity_x * dt, total_dy * sensitivity_y * dt);
    total_dx = 0;
    total_dy = 0;
}



#5111235 C++ template default parameter with enable_if

Posted by fastcall22 on 22 November 2013 - 01:40 AM

Disclaimer: Inexperienced in generic programming.

Hmm? Test1 works, because T=int, bypassing the default template parameter. Not sure about the exact reasons for Test2, other than T is declared twice. I wasn't able to work around it:


#include <type_traits>
#pragma warning(1 : 4519)

class Base { };
 
class A {
public:
	// C4519
	template <class T = std::enable_if<std::is_base_of<Base, T>::value>::type>
	void Test1() { }

	// C4519
	template <class T, typename G = std::enable_if<std::is_base_of<Base, T>::value>::type>
	void Test2() { }
};

int main() { 
	A a;
	a.Test1<int>();		// Ok (bad)
	a.Test2<Base>();	// C2783:  Could not deduce template argument for G
	a.Test2<int>();		// C2783:  Could not deduce template argument for G
}
However, this appears to work:
#include <type_traits>

class Base {
public:
    virtual ~Base() {
    }
};

class Derived : Base {
};

class A {
private:
    template<typename T>
    void ff() {
    }
    
public:
    template<typename T>
    void f() {
        typedef std::enable_if<std::is_base_of<Base,T>::value,T>::type Q;
        ff<Q>();
    }
};

int main() {
    A a;
    a.f<int>();     // error C2039: 'type' is not a member of enable_if<false,int>
    a.f<Base>();    // ok
    a.f<Derived>(); // ok
}



#5111106 How do I make a very basic inventory.

Posted by fastcall22 on 21 November 2013 - 04:01 PM

Create an item structure that handles the responsibilities of an item in your game. An item might have properties such as its icon, its name, its description, its capabilities (whether it can be consumed/equipped, how it can be used, etc), and a procedure to be executed when activated. Create an inventory structure to contain and maintain the items, using an appropriate data structure. When a frame is drawn, iterate over the contents of your inventory, and draw the item's icon in the appropriate position. Next, use a collision handler such that when the player collides with an item in the field, the item is removed from the world and into the player's inventory.


#5109537 C++ Outside the box smart pointers

Posted by fastcall22 on 15 November 2013 - 01:20 PM

I hate making parameters that take smart pointer templated arguments, so I took these hates and started thinking about how would I remove them.

So, typedefs then?
struct Object {
    void frobnicate();
};

typedef shared_ptr<Object> shared_object;

void f( const shared_object& obj_ptr ) {
    obj_ptr->frobnicate();
}

This is meant to keep a ref count and only actually free the object when that ref count reaches 0.

An intrusive smart pointer then?

When one pointer is assigned to another I would need to know this so that I can automatically call AddRef() instead of right now I explicitly call it.

Aside from globally overriding operator= for pointer types, I cannot see any easy way to do this. If you do decide to override operator=, you're asking for trouble when the compiler, for whatever reason doesn't select your version, selects the default operator=... Then there's the whole other can of worms you open with this approach: Does the data pointed to by your pointer type point to the stack, the heap, or some other manually managed block of memory?

There's nothing wrong with reinventing the wheel for educational purposes, but you will need to be very careful with what you write. Write lots of test cases! Your code appears to work, because the destructor for Test is trivial (and among other things).


#5106571 cache friendly lock free concept?

Posted by fastcall22 on 02 November 2013 - 05:26 PM

Mattias, doesn't that example apply to multiple threads running the same code? Slicer4ever's code has two threads running separate code. Hold on. Not an expert in multithreaded programming, but...
The network thread acts on LOCK_REQUESTED/UNLOCK_REQUESTED and sets to LOCKED/UNLOCKED, whereas the game thread acts on LOCKED/UNLOCKED and sets to UNLOCK_REQUESTED/LOCK_REQUESTED. A thread cannot renter its "critical sections" until the other thread unsets the LockState. Assuming that LockState is executed and committed after at the end of the threads' "critical sections", isn't the worse case scenario then a thread may need to reenter its loop? Or, am I misunderstanding something here?


#5105772 [C++][ALLEGRO5] How to make a Title screen and different screen states?

Posted by fastcall22 on 30 October 2013 - 03:41 PM

How do I make , for example a Title screen and when an option is selected, for example "Play game", the screen switches to the gameplay screen?
Do I have to clear the screen and then enter the game loop?
Do I need to make Individual loops inside the main gameoop for different screens, if yes, can you provide a quick example?

I still don't understand the screen states.

Read up on state machines, they'll help out here. What you want to do in this case is to use a state machine and transition to and from states. Implementations can be simple or complex, but you should only use one game loop.

Here's a small example: 
set state to 'title screen'
while game is still running:
    handle input
    
    update according to state:
        when state is 'title screen':
            update timer
            update fade animation
            if timer expired or user pressed skip button:
                set state to menu
        
        when state is 'menu':
            navigate menu according to user input
            if user pressed 'start game' GUI button:
                set state to 'game'
            
        when state is 'game':
            if user pressed menu button:
                set state to 'menu'
            update game
    
    render according to state:
        when state is 'title screen':
            draw splash screen
            draw fade transition

        when state is 'menu':
            draw menu
            draw selected item
            
        when state is 'game':
            draw game
    
    present image



#5105764 Game timer dilema

Posted by fastcall22 on 30 October 2013 - 03:08 PM

Take a look at Gaffer's Fix Your Timestep. He recommends you update your game at a fixed rate and render as fast as possible interpolating between updates:
updates_per_second = 40
ticks_per_update = ticks_per_second / updates_per_second
time_per_update = 1 / updates_per_second 
accumulator = 0

while window_opened():
    accumulator += elapsed_ticks()

    while accumulator > ticks_per_update:
        game.update(time_per_update)
        accumulator -= ticks_per_update
    
    # interpolation is between 0 (previous state) and 1 (current state)
    interpolation = accumulator / ticks_per_update  

    game.render( interpolation )

# Somewhere in the game:
function object.draw(interp):
    interp_pos = (current_position - previous_position) * interp + previous_position

    draw(this, interp_pos)

But "distance traveled per time" is double edged sword. If device lags for 3 seconds, i might get dead.

You can add some logic to prevent the game loop from locking up on itself by detecting and discarding multiple updates:
    # if updating falls behind, sacrifice a few updates and accept lag
    if accumulator / ticks_per_update > 3:
        accumulator %= ticks_per_update

Other option i thought of, hardcap FPS to 30. But then... how do i manage stuff like "buffs" and etc?... base them on time or frames passed?

Either approach will work; just keep updates_per_second in mind if you use frames to keep track of timing.


#5105178 Techno-Babble screens

Posted by fastcall22 on 28 October 2013 - 04:11 PM

Scanlines?
Multiple windows?
Graphs?
Charts?
Hex dump?
A 3d wireframe model spinning in the background, with those little lines that point out to text highlighting important details?


... Porn?


#5105175 Memory usage increasing over time

Posted by fastcall22 on 28 October 2013 - 04:03 PM

It's full of useless features - too retarded-friendly, like everything tends to become over time.

Well, there's notepad.exe and cl.exe; knock yourself out. As un-userfriendly as it gets.
 

Why would one use two versions of GLFW in the same application? It's all the same crap.

You wouldn't use two different versions of a library in the same application, silly! If you have ever developed more than one application, then using the "latest" version of a library at the times of both applications' development are going to be different. Including glfw.h in the application developed years earlier is going to break when you change your environment's paths to always use the latest versions of your libraries. (Again, with Visual Studio's property pages, this is possible.)
 

Too retarded-friendly (like everything tends to become over time) and I couldn't find 2.7.7's documentation.

The newest version of glfw I downloaded came included with the documentation; even 2.7.7 had documentation! glfw-2.7.7.bin.WIN32.zip\glfw-2.7.7.bin.WIN32\docs\
 

I was talking about the name of the function, which is stupid. It's the first time I see the word 'should' in a program.

You can use a macro to hide it, if you really want to. You could even comment it!
// Wow, I'd rather rebuild an entire cross-platform library than to use the word "should" in a program.
#define glfwWindowIsOpen(window) (!glfwWindowShouldClose(window))



#5105118 Memory usage increasing over time

Posted by fastcall22 on 28 October 2013 - 01:28 PM

I won't use glfw3. It has become so stupid. There is no library for Visual Studio 2010.

What? It's right here: glfw-3.0.3.bin.WIN32.zip\glfw-3.0.3.bin.WIN32\lib-msvc100\glfw3.lib.

Only for the Visual Crap 2012.

Hmm? What do you have against Visual Studio 2012? It's solid and much more stable (in my experiences) than 2010.

Even the website looks stupid now.

It's a sign of the library community's health. To me, it appears much cleaner and organized.

Even the function names: glfwWindowShouldClose, what the Hell?

Check the documentation and read up on new functions you're not familiar with.

The header filename, glfw3.h? GLFW 2.7 was not glfw27.h, simply glfw.h.

Developing applications over time that eventually use different versions of the same library can make managing them in an IDE difficult. Visual Studio property pages help somewhat, but having an version number with the header and library names make it much more explicit and hard to mess up.

I don't give a **** to this stupid number, keep pressing this stupid down arrow if you want, ********.

This sort of caustic attitude isn't allowed these forums; try taking your frustrations to Twitter or Facebook.


#5104437 goto considered harmful within global macros

Posted by fastcall22 on 25 October 2013 - 12:59 PM

TRTWTF is nobody escaped expression in parenthesis:
 
#define CheckSuccess(condition) do { \
    if (!(condition)) { \
        goto onError; \
    } \
} while (0) 
Hurr durr Ph'nglui mglw'nafh Cthulhu CheckSuccess(obj.frobnicate() || obj.bang()) R'lyeh wgah'nagl fhtagn and what not...


#5103893 Before I learned the ++ ..

Posted by fastcall22 on 23 October 2013 - 03:23 PM

A sin table and a cos table?! Precision to the 100th degree? You must have had quite a bit of ram back then to afford such luxuries.


#5103738 Main loop timing

Posted by fastcall22 on 23 October 2013 - 09:24 AM

I recommend you read Gaffer's Fix Your Timestep article. In the article, Gaffer recommends you render as many times as possible, but only update your simulation at a fixed rate. Interpolation can be used in between updates to give a smooth feel.

 

A second question. ...since I switched from WinXP to Win7, ....the system limits the FPS to 60. Thats very kind, but how does it do that?

Vsync, usually. It could be that your video drivers have enabled vsync by default. Try checking your video driver's control panel.

On a related note, you can sleep(1) to yield your process's timeslice to the operating system. This can help reduce CPU and GPU usage. Be careful, though; as it may take upwards of 8 to 20 ms (47%-120% of a 60 fps frame) before your program regains control...


#5101904 How do you 'learn' a programming language?

Posted by fastcall22 on 16 October 2013 - 01:25 PM

not advancing until you understand the concepts

... and completing every exercise at the end of every chapter and redoing every exercise once you learned how to build it better.




PARTNERS