Jump to content

  • Log In with Google      Sign In   
  • Create Account

fastcall22

Member Since 04 Feb 2008
Offline Last Active Today, 01:07 AM

#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.

EDIT:
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.


#5166056 How to verify Mobile Game Client session with JSON?

Posted by fastcall22 on 10 July 2014 - 12:19 PM

example.com/update.php?player_id=1&gold=100&session_id=1234asdf


If, and only if, the URL is generated by the server and then sent to the client, then you could use a hash to confirm that the URL hasn't been tampered with:

$url = 'http://example.com/update.php?player_id=1&gold=100&session_id=1234asdf';
$url .= '&hash='.secret_hash($url);
print $url;
http://example.com/update.php?player_id=1&gold=100&session_id=1234asdf&hash=0123456789ABCDEF

If a malicious player were to change the gold, then the hash wouldn't match on the server and the request would be denied.
Again, as hplus has suggested, it would be better if the URL described an action a player is doing, rather than "raw game code".


#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 )
		break;
}
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";
	return;
}

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):
    processEvent(e)

  update()
  render()



#5164100 C++ Multi-Byte - prepare string of extensions for OpenFileDialog

Posted by fastcall22 on 01 July 2014 - 01:24 PM

how is the generation of a string

L"Hello\0World\0How\0Are\0You\0'

done?

Well, in your case, it would just be replacing ';' with '\0'.

So, maybe something like this:
std::wstring ext;
ext.reserve(str.length()+1);

std::transform(str.begin(),str.end(),back_inserter(ext),[](char t) -> wchar_t {
	return t == ';' ? 0 : t;
});
ext.push_back(0); // (This is necessary to indicate where the array of strings end)

wchar_t* buf = ext.c_str(); // An extra null terminator should be appended here.

// str = "Hello;World;How;Are;You"
// buf = L"Hello\0World\0How\0Are\0You\0\0"
EDIT:
Code sample here: http://ideone.com/wqrckP


#5164079 Non-fixed width fonts in games

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

Usually when doing font rendering in games, a select number of glyphs are packed into an image. This image also has metadata, either stored alongside the image or in a separate file, which stores information about where in the image a glyph is, how large the glyph is, what kind of kerning adjustments are needed with which pair of glyphs, and etc. Take a look at bmfont and how it generates its font files. (Sample here: Quick tutorial variable width bitmap fonts.)

Once you have the image and the metadata, it is only a matter of storing this data into a data structure. An associative array or tree is usually the best approach, especially when you take into concern characters outside of the ASCII range.


On the topic of TTF, these files can be thought of executable scripts which transforms a state into a series of outlines.


#5163891 how to show()/remove() a textarea with jquery

Posted by fastcall22 on 30 June 2014 - 12:56 PM

$('.Option > textarea:last').last().remove();

.
.
.

$('<textarea ></textarea>').fadeIn('fast').appendTo('.Option');


I, um... wat.

ಠ__ಠ


#5163687 SDL.h: no such directory found

Posted by fastcall22 on 29 June 2014 - 01:56 PM

http://i.imgur.com/kEgaRqg.png


... Uhh, those should be lower case Ls, not pipes |... See GCC link options. Pipes are used to pipe output from programs elsewhere (to a file, another program, etc).




PARTNERS