Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 04 Feb 2008
Offline Last Active Private

#5170944 Isn't "delete" so pesky to type? Wish there was a better way?

Posted by fastcall22 on 01 August 2014 - 01:21 PM

if ( Washu == phil67rpg, fir, cthulu )

#5169357 'pass through member function'

Posted by fastcall22 on 26 July 2014 - 01:41 PM

You could treat Class A as an iterator:
class B;
class A {
	B& operator*() {
		return vec[idx];

	B* operator->() {
		return &vec[idx];
	int idx;
	vector<B> vec;

class B {
	void frobnicate();

void test(A& a) {

#5168696 Color bar Interpolation

Posted by fastcall22 on 23 July 2014 - 11:59 AM

Use either of the HSL or HSV color spaces, interpolate in that space, and then convert to RGB when needed.

#5168419 [Help] c++ Allegro, PuyoPuyo colors comparative?

Posted by fastcall22 on 22 July 2014 - 11:29 AM

well something like that ....establishing all the possible IF opcions :S... but there is a easier way to detect the collisions??

This is important step in your growth as a programmer: When you realize what you have learned is infeasible here and that there must be an easier way. While it is certainly possible to code the logic entirely of IF-statements, it quickly becomes unmanageable and buggy. So, as a programmer, you must solve the problem in a generic way. For instance, the procedure could look something like this, in pseudo code:

1. For every unvisited tile on the board:
2.	For each unvisited neighbor of this tile:
3.		Visit each neighbor of the same color:
4.			Count and mark this neighbor tile
5.			Move to this tile and repeat step 2 for this neighbor tile
6.	If there are no more neighbors, and we have moved to this tile:
7.		Move back, and continue on step 5
8.	If we found four or more tiles of the same color neighboring this tile:
9.		Score and remove these tiles
Notice steps 2, 5, and 7: Recursion might be helpful here.

#5166869 Game doesn't crash if currently printing

Posted by fastcall22 on 14 July 2014 - 05:31 PM

Well, it's a bit more complicated than that:

void thing(const char* text) { 
    // Do stuff with text


int main() {
    const char* a = "abc";
    const char b[] = "def"
    char* c = malloc(4);
    char* d = new char[4];

    thing("mno"); // No!
    thing(a);     // No!
    thing(b);     // No!
    thing(c);     // Okay
    thing(d);     // No!

    // free(c);
    // delete[] d;
Here, thing is assuming ownership of text which isn't always the desired behavior, as shown in the sample program here.

#5166832 Storing position of member variable

Posted by fastcall22 on 14 July 2014 - 03:45 PM

Actually, if you're using any of the latest Visual Studio versions, there should be a local database file with your project that contains metadata about your project. Usually, this database is used for intellisense, but you can connect to the database externally and perform SQL queries against it. With this, you can query information about your project, classes, and its members. Extending this, you could write a PowerShell script to automatically generate reflection information from all of your classes. Then you could add this to your build process, and... well, I'm getting ahead of myself, here. smile.png

#5166827 Win32 BOOL and bool ?

Posted by fastcall22 on 14 July 2014 - 03:36 PM

The Win32 API is a C library. C does not have a boolean type. Therefore, Win32 has defined BOOL as being an integer having zero and nonzero for false and true respectively.

See Win32 Data Types.

#5166808 Adding Collider To a LineRenderer - Unity3D

Posted by fastcall22 on 14 July 2014 - 02:40 PM

You could always split the curve into smaller straight segments.

#5166780 Is c++ good

Posted by fastcall22 on 14 July 2014 - 12:56 PM

If you're worried about "wasting time" learning C++, then stop worrying. The most important thing you can learn while learning a language is learning the concepts of programming themselves. Once you've picked up these concepts, it's only a matter of learning how a language describes those concepts (and sometimes the syntax).

#5166483 optymizations by self modifying code

Posted by fastcall22 on 12 July 2014 - 05:17 PM

Those stories about people optymizing wrong places sound a bit strange to me - i naver had such a situation, It was always clear what is a hotspot and indeed every 'optymization session' i was

Except you have had such a situation.

In your speeding this with sse or sse intrinsics thread, you were looking to optimize an inner loop with SSE. Ohforf showed you could speed up your code by 200% just by using a more efficient algorithm without SSE.

#5165676 how to make a form that you can save status and continue later

Posted by fastcall22 on 08 July 2014 - 05:03 PM

Have a button (or async request on a timer) POST the form in its current state to the server.
The server then commits the state to some form of storage.
When the user requests that page in the future, the server looks up the form in storage (if available) and serves a page with a partially filled out form.

#5165608 c++ help

Posted by fastcall22 on 08 July 2014 - 12:34 PM

Now i want to make a file that i can import into the program. In the file are different products with all an explanation of the price (priceProduct in the above code) quantity of the product and that kind of things, so that i only have to write the universal code above once and it can be used for all the products if.

I think i have to do something with classes, but i'm not sure. I even don't know if this is possible. If it is: could you explain how to do it to.

This indeed possible, and it can be made easier with structured data. I'll explain.

I. Organizing your data

First we'd like to know what kind of stuff we'd like to know about our product. You mentioned you'd like to have the name, price, and quantity of the product. So, we'll start there.

struct Product {
	string name;
	double price;
	int qty;
Here, we declare a structure called "Product" as having three members: Name, price, and quantity. Any object of type "Product" will have these three properties. So how do we create and use a "Product"? Well, like any another variable, really:
Product milk;
milk.name = "milk";
milk.price = 2.75;
milk.qty = 8;

// or
// Product milk = { "milk", 2.75, 8 };

cout << "Product Name:\t" << milk.name << endl
	<< "Product Price:\t" << milk.price << endl
	<< "Product Quantity:\t" << milk.qty << endl;
Now we need a way to store all of the products together.

II. Managing the data generically

Here we can use arrays. We could use std::vector for a dynamically sized array, but that is outside of the scope of this post. We'll use a static array instead:

const int MAX_PRODUCTS = 100;
Product products[MAX_PRODUCTS];
int numProducts = 0;
Now, we can add and manage the products programmatically:
// Populate the array of products
numProducts = 0;
products[numProducts++] = Product { "Milk", 2.75, 8 };
products[numProducts++] = Product { "Cookies", 4.60, 4 };
products[numProducts++] = Product { "Bread", 3.50, 12 };
products[numProducts++] = Product { "Eggs", 4.25, 16 };

// Display the array's contents.
for ( int idx = 0; idx < numProducts; ++idx ) {
	cout << "Product Name:\t" << products[idx].name << endl
		<< "Product Price:\t" << products[idx].price << endl
		<< "Product Quantity:\t" << products[idx].qty << endl
		<< endl;
With the array, we will no longer be able to refer to products by variable name (such as "milk" in the previous example). We'll either need to use pointers or indexes. Here's a sample using an index to find a product in the array:
string queryName;
cout << "Enter product name: ";
getline(cin, queryName);

int idx = 0;
for ( ; idx < numProducts; ++idx ) {
	if ( products[idx].name == queryName )
if ( idx < numProducts ) {
	// do something with products[idx]
} else {
	cout << "Unable to find \"" << queryName << "\"" << endl;

III. Structuring your file

Now, let's get to dynamically loading the products. Let's first create a file and create it with tab-separated values:

Milk	2.75	8
Cookies	4.60	4
Bread	3.50	12
Eggs	4.25	16
Next, let's place this file somewhere where your program can see it. Check your project settings for the working directory of your program. Place the file there.
// include fstream, sstream
ifstream fs("products.txt");
if ( !fs ) {
	cout << "Unable to open file";

string line;
numProducts = 0;
while ( getline(fs,line) ) { // Read one line at a time
	istringstream is(line); // Temporary stream for the line

	Product temp;
	if ( getline(is,temp.name,'\t') && is >> temp.price >> temp.qty ) {
		products[numProducts++] = temp;
	} else
		; // Error reading the line

So there you go. Hopefully it should be clear how this should work.

#5165375 raw binary to obj conversion

Posted by fastcall22 on 07 July 2014 - 04:10 PM

Have you looked into disassemblers?

#5165158 SDL Keyboard input

Posted by fastcall22 on 06 July 2014 - 06:27 PM

Also, it does not appear your Play_annimatedSprite routine doesn't have the ability to be interrupted. If Play_animatedSprite were called for an animation such as (1 3 1 125), then (1 3 2 125) cannot be used until "animationDelay + speed < SDL_GetTicks()" is true

#5165157 SDL Keyboard input

Posted by fastcall22 on 06 July 2014 - 06:22 PM

You're only handling one event per frame. There can be anywhere from 0 to a few hundred of events per frame. If you only process one event per frame, then a keyboard or mouse event could take up to several seconds before it is processed.

A typical game loop looks something like this:
while running:
  event e
  while nextEvent(&e):