Jump to content

  • Log In with Google      Sign In   
  • Create Account

fastcall22

Member Since 04 Feb 2008
Offline Last Active Today, 11:49 AM

#5287263 HINSTANCE & HWND Corrupted when passed around functions

Posted by fastcall22 on 16 April 2016 - 11:16 PM

There isn’t enough code here to determine the actual cause (though I would first suspect the down-cast from IEventArgs& to WinEventArgs&). Setup a data breakpoint to see exactly when the value is corrupted.


#5287262 Multiple bullets?

Posted by fastcall22 on 16 April 2016 - 11:09 PM

Anyway, look into "std::vector".


Yes, you would be correct if the OP was using C++. But the tags on his topic states “Java,” so he should use java.util.ArrayList instead.

The same principles apply, though:
ArrayList<Bullet> bullets = new ArrayList<Bullet>();

bullets.add(new Bullet(x, y));

for ( Bullet b : bullets )
    b.update();
}    
At some point, you will need the ability to remove bullets. Use an iterator instead:
ListIterator<Bullet> itr = bullets.listIterator();
while ( itr.hasNext() )
    Bullet b = itr.next();

    if ( !b.update() )
        itr.remove();
}



#5287204 I can't build the Box2D physics library in Visual Studio 2015

Posted by fastcall22 on 16 April 2016 - 12:02 PM

You may have warning levels set on your project to treat warnings as errors (/WX). Usually these warnings indicate a possible bug with your code, but since this isn’t your code, you may be safe in ignoring these warnings.


Relevant code in b2CollideCircle:
	// Find the min separating edge.
	int32 normalIndex = 0;
	float32 separation = -b2_maxFloat;                            // (line 64)
	float32 radius = polygonA->m_radius + circleB->m_radius;
	int32 vertexCount = polygonA->m_count;
	const b2Vec2* vertices = polygonA->m_vertices;
	const b2Vec2* normals = polygonA->m_normals;

⋮
⋮

		b2Vec2 faceCenter = 0.5f * (v1 + v2);
		float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);  // (line 141)
		if (separation > radius)
		{
			return;
		}



#5287130 Computing an optimized mesh from a number of spheres?

Posted by fastcall22 on 15 April 2016 - 08:57 PM

Take a look at constructive solid geometry, it may be what you’re looking for.


#5287093 My octagon is a circle and my pentagon is wonky :'(

Posted by fastcall22 on 15 April 2016 - 02:22 PM

To expand on what SotL said, here’s a brief history on Windows terminals.

Prior to Windows 10, terminals used the System Typeface, which was a bitmap font carried over from the IBM days, and consequently stuck on Code Page 437. Unicode support was nonexistent, but at least you had pixel-perfect characters to make your rouge-like game.

Starting with Windows 10, the terminal was completely reworked and now supports Unicode and uses TrueType fonts with modern font rendering. It’s smooth as silk, but you no longer have square characters nor pixel perfect box drawing.

Additionally, since the terminal supports Unicode, you need to use the Unicode code points rather than Code Page 437 code points:
Before: cout << (char)251; // √
After: wcout << L'√' /* or: */ << (wchar_t)0x221A;


So, here are some of your options:

1. Configure your terminal to use "Terminal" with an 8x8 font size. This is the easiest solution. Inserting wide characters should map to the original Code Page 437 code points: 0x221A -> 251.

2. Account for font proportions in your code. This involves scaling the Y-axis such that 1 unit along the Y-axis appears to be the same length as 1 unit along the X-axis, even if it doesn’t quite match up 1:1 to rows and columns.

3. Use U+2584, U+2580, and U+2588 (▄, ▀, and █ respectively) to split a character into two. This is trickier to do, as you would need to render to an "off-page" image before you can determine what characters to use. Don’t forget to use wcout to insert a “wide-character” into cout.


#5286570 C++ Rotating 2D shape in list

Posted by fastcall22 on 12 April 2016 - 09:48 PM

Dammit, why did I never learn cool properties of complex numbers when I was in school?!


Yeah dude. Complex numbers, bro: http://acko.net/blog/how-to-fold-a-julia-fractal/


#5285717 Frame Independent Problem

Posted by fastcall22 on 07 April 2016 - 11:06 PM

function Update(float timeElapsed)
{
velocity *= timeElapsed;
setPosition(getPosition() + velocity); // Now, update the entity position based on velocity
velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
...
...


The problem isn’t with the timers, but rather the units. The code is demoting velocity from units per second to units. For example:

1. Set velocity to 10 units per second (u/s).
2. Multiplying velocity by elapsed time in seconds (s) gives you a distance in units (u).
3. The result is then fed back into velocity-- reinterpret_casting from u to u/s, as it were. (BAD!)
4. Multiplying the new velocity in units with a the elapsed time gives you u*s units. (NO!)
5. Repeat steps 3-5, but with u*s^N units for velocity each iteration.


Be mindful of the units of your operands whenever you do any sort of math:
float3 distance_traveled = velocity * timeElapsed;  // u/s * s -> u
setPosition( getPosition() + distance_traveled );   // u + u -> u
If your intention was to have damping:
const float DAMPING = 0.8f;        // (scalar) reduces velocity 20% every 1 second (roughly) 
velocity *= DAMPING * timeElapsed; // u/s * scalar -> u/s
float3 distance_traveled = velocity * timeElapsed; // u/s * s -> u 
setPosition( getPosition() + velocity * timeElapsed ); // u + u -> u



#5285505 Data Structures Help!

Posted by fastcall22 on 06 April 2016 - 05:30 PM

See: C++ FAQ Lite: Why can’t I separate the definition of my templates class from its declaration and put it inside a .cpp file?

I like to separate my template classes into hpp, impl, and cpp. For template classes that have a handful of known types (such as a vector4_t<T> for T in (float, int)), then the cpp supplies all the definitions using hpp and impl for those types, and everything else won’t need to know about the impl. Otherwise, I have the hpp include the impl at the end of the file and forego having a cpp file.


#5284902 point inside convex quad, using only integers?

Posted by fastcall22 on 03 April 2016 - 01:56 PM

Fixed point math. Fixed point is just fancy integer math in different units.

For a 2’s complement 32-bit integer, you can represent the integers from 2^-32 to 2^32-1. Or, 2^0 to 2^31 with a sign bit.
A fixed float works in a similar manner, but by sliding the scale: 2^(0-N) to 2^(31-N) with a sign bit.

The math involved has a few extra steps, but it’s probably less costly than to use floating point math (on the target hardware, that is).


#5283453 Best Engine for a Hacking Game

Posted by fastcall22 on 25 March 2016 - 03:40 PM

Use a raw 80x25 16-color terminal. That’d be pretty tight.


#5283192 Trying to change speed of a platform

Posted by fastcall22 on 24 March 2016 - 12:13 PM

While there isn’t anything wrong with relative moving, you may want to have a reference point, such that you don’t accumulate floating point errors. Additionally, you try to understand the units in the math involved, rather than using magic numbers:
 
// Assuming the platform has these properties:
Float3  Start;
Float3  End;
Float   Duration; // seconds it takes for platform to cycle from start and end

// And:
Float3  Delta = End - Start;

// then:
// “phase” cycles between 0 and 1 over “Duration” seconds
phase = (1+sin(PlatformTime / Duration * 2*pi))/2;

// “PlatformLocation” cycles between “Start” and “End” according to “phase”
PlatformLocation = Start + Delta * phase;

PlatformTime += DeltaTime;



#5282959 How can I locate a memory leak?

Posted by fastcall22 on 23 March 2016 - 01:57 PM

To locate a memory leak, you would typically build your project where new/malloc and delete/free is rerouted to a routine that tracks all allocations and deallocations throughout your program. Note that this does not extend to third party libraries. At the end of the program, a report is generated with the allocations that remain. Something like the following:

// not $100% exact...
#define new DBG_NEW
#define DBG_NEW new (__FILE__, __LINE__)

struct alloc_entry {
    alloc_entry* prev;
    alloc_entry* next;
    const char* file;
    int line;
    size_t size;
    void* p;
};

alloc_entry* alloc_list = 0;

void* operator new( const char* file, int line, size_t sz ) {
    void* ptr = malloc(sz);

    simple_list::insert(alloc_list, alloc_entry{0, alloc_list, file, line, sz, ptr});

    return ptr;
}

void operator delete(void* p) {
    if ( p )
        simple_list::remove_where(alloc_list, p);
}

void alloc_report() {
    for ( alloc_entry* p = alloc_list; p; p = p->next )
        fprintf(stderr, "%s@%d %i bytes\n", p->file, p->line, p->size);
}

int main() {
    delete new int;
    new int;

    alloc_report();
}

Memory leaks are caused in many ways, but the most common cause is improper object lifetime management. Objects on the stack have a very strict FILO lifetime, and are guaranteed to be cleaned up when its scope expires. In contrast, objects allocated on the heap do not have a defined lifetime, and can be deallocated in any order. Here are a few examples:

void error(void* p) {
    throw std::runtime_error("Test failure!");
}

int main(int, char*[]) {
    try {
        foobar* f = new foobar;

        error( new int );

        delete f;
    } catch ( const std::exception& ex ) {
        // new int does not get deleted
        // foobar does not get deleted
    }
}
To prevent memory leaks in the future, you must always keep in mind how long a dynamically allocated object is supposed to exist, who owns the object, who shares ownership with the object, and who is responsible for cleaning that object. Smart pointers help here, but aren’t absolutely necessary.


#5282782 Loading TMX files with SDL2 using Baylej's C library

Posted by fastcall22 on 22 March 2016 - 07:21 PM

bool TMXLoader::LoadMap(std::string location)
{
    tmx_map *map = tmx_load(location.c_str());
 
    return true;
}
Unless you are inspecting map on this line, the tmx_map is lost once this method returns.


#5281887 Why is the Fixed Function Pipeline performing better than using Vertex Buffer...

Posted by fastcall22 on 18 March 2016 - 11:36 AM

Eh? For 60 FPS, you have a budget of 16.67ms per frame. To go from 0.00733ms to 0.0177ms per frame is an increase from 0.044% to 0.106% of your total budget. While it’s a 2.5x increase, it’s still only < 0.1% of your total budget and is therefore not worth worrying about.

That aside, you are also making too many trips to the GPU. Rendering 1000 individual quads is many times more costly than making one individual call to draw 1000 quads. Also, the gameloop is missing from your code, if you’re having jittering, the gameloop is the next place I’d suspect.


EDIT:
To answer your question, “why is the Fixed Function Pipeline performing better than using Vertex Buffer Objects”: It is because you are doing it wrong.


#5280435 random Compiler Error C2143 - missing ";" before "*"

Posted by fastcall22 on 09 March 2016 - 04:47 PM

Visual Studio? You’ll need to configure your project to “Use Precompiled Headers”, and configure stdafx.cpp to “Create Precompiled Header”.




PARTNERS