Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 Feb 2005
Offline Last Active Oct 02 2013 09:07 AM

Topics I've Started

Question with PHP accessing mysql

25 October 2012 - 09:05 AM

I have a custom web application I am playing around with written in php accessing a mysql database using a html interface.
Let me qualify this and say that I am very new to PHP and I may be unaware of something considered standard.

I am calling functions from inside my php (webpage) file that the user accesses with 2 or more variables like:

function TestFunctionRpt($orderby,$sort)

I sanitize both of my input variables using the PHP function "mysql_real_escape_string()".

Now my question is this, this seems very very simple am I actually protecting myself from SQL injection?
Is there anything else I need to look out for?

Also for reference my function is called like this inside my page.

[source lang="php"]<?php echo $mysite->TestFunctionRpt($_GET ['orderby'],$_GET ['sort'],$_GET['cust'],$_GET['startdate'],$_GET['enddate']);?>[/source]

Thank you for reading, hopefully you are having a great day!

C# SQL connector very slow

22 May 2012 - 11:41 AM

First off let me preface this by saying that I am very new to using C# to do anything with SQL so I may not know some of the basics =)

I am currently using MySql.Data.MySqlClient and have written a custom C# application to parse records from a CSV file and update some records in my table and insert some records as needed pretty simple stuff.

Now the underlying code to do this works great. My problem is that is it is very very slow, everytime I do a SELECT or UPDATE, it can take upwards to a second to complete.

For each record I am doing a select to find the reference ID for the line in the table.
I then use that reference number to update a couple of fields based on the data I parsed.

I am dealing with a table that has over 200000 records and yes I need to go through every single one because the data I am updating can go all the way back to the beginning so I can't LIMIT my select.

Since I am new to SQL in general is it better to batch updates? IE say I have 700 updates just mash as many as I can into a single SQL statement and push that?

I don't really understand the connection pooling since right now I am doing a select to find my reference number before I update, but really I am just looking for any advice =)

Thanks in advance!

Winsock Compression

16 December 2011 - 11:22 AM

I am currently running a custom winsock client/server implementation.

When a player connects to my server I need to send a lot of information (totaling 500k at maximum objects per zone)
Which seems like a ton to send out every time a player connects.

Is there a way I can use something like zlib to compress and then decompress my data (for each packet sent and received)
Or is this method flawed and I should just deal with the large data volume?

my zone size is 150x150
I am looking at 14 bytes per object, 0 to 22500 per zone.
10 bytes per tile, 22500 per zone.
24 bytes per entity, I am currently capping that at 2000.

So in a worst case scenario 585500 bytes for the initial update.
edit: + tcp/ip overhead per packet

All of this data can change over the course of the game and needs to be updated when the player logs in, so keeping a cache wouldn't be worth it.
I thought about maybe doing it chunk style ala minecraft but I would think I would end up sending much much more data in the long run.

Any thoughts?

Sorting Objects

09 December 2011 - 10:12 AM

I am sorting all of my objects in my game by their Y axis and creating a sorted look up for drawing things in the correct perspective.

The way I am currently doing it is with a STD::LIST, but for over 2000 objects it takes 1400 milliseconds to do the sort, I know I am probably going about this the incorrect way, sorting algorithms are really my weak point here so I am looking for some advice!

My lookup list is a STD::LIST of this class
class LookUp
		int DataLoc;
		int YLoc;
list <LookUp> ObjectLookUp; //my list

Here is my sorting code:

void  MyData::SortObjectsByY()
	DWORD StartTime = GetTickCount();

	ObjectLookUp.clear(); //clear our list
	LookUp p;
	p.DataLoc = 0;
	p.YLoc = Objects.GetObjectByPosition(0)->_PositionData.LocY;

	ObjectLookUp.push_front( p ); //add base player

	for(int i=1;i<(int)Objects.GetObjectCount();i++) //loop through all objects
		Object* p = Objects.GetObjectByPosition(i); //get pointer
		if(p->_PositionData.LocY < ObjectLookUp.front().YLoc) //lower than our start
			LookUp p2;
			p2.YLoc = p->_PositionData.LocY;
			p2.DataLoc = i;
		else if (p->_PositionData.LocY > ObjectLookUp.back().YLoc) //higher than our end
			LookUp p2;
			p2.YLoc = p->_PositionData.LocY;
			p2.DataLoc = i;
		else //somewhere in middle
			LookUp p2;
			p2.YLoc = p->_PositionData.LocY;
			p2.DataLoc = i;
			for (list<LookUp>::const_iterator iterator = ObjectLookUp.begin(), end = ObjectLookUp.end(); iterator != end; ++iterator) 
				if (iterator->YLoc > p->_PositionData.LocY || iterator->YLoc == p->_PositionData.LocY) //if its lower or equal
					ObjectLookUp.insert(iterator, p2);

	DWORD ENDTime = GetTickCount();
	cout << "Objectlookup size is: " << ObjectLookUp.size() << " took " << ENDTime - StartTime << " MS" << endl;


If you need an explanation of what is going on:

Our first object is pushed back to our LIST to create a start point (object zero)
DataLoc is the ID number of the object to look up information about it during rendering

Then I loop through the total number of objects I have currently determine if its higher or lower than the start or end point and if it is drop it in front.
If its not, I loop through the LIST and find where to insert it and insert it. (I think this is where my bottleneck is)

As of right now this is only handling static objects so I only have to do the sort on map generation, but I need to take into account my NPC's as well and they will be able to move around in real time... So doing this type of sort everytime a NPC moves on his Y axis is horrible.

Anyway, I appreciate any thoughts, thanks!

Edit: I think much of my performance is being lost because of the number of objects added to the list, normally in a vector I would reserve() memory space, but alas I cannot do that with a list.

Texture Rotation in DX9

28 October 2011 - 11:01 AM

I am supplying the U and V coordinates for my texture like below, what I would like to do is have the texture rotate from left to right but stay on my quad.
I haven't really been able to find much information about this, A lot of people suggest using a translation matrix, but I am defining my vertices directly and nothing goes through translation.

How was this done in YE OLDE times such as the texture "scrolling" done in games like doom, duke3d, etc?

TLVERTEX* vertices; //my vertices

	vertices[0].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
	vertices[0].x = (float)x;
	vertices[0].y = (float)y;
	vertices[0].z = 0.0f;
	vertices[0].rhw = 1.0f;
	vertices[0].u = 0.0f ;//1 - 0
	vertices[0].v = 0.0f ;//1 - 0
	vertices[1].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
	vertices[1].x = (float)x + 64;
	vertices[1].y = (float)y;
	vertices[1].z = 0.0f;
	vertices[1].rhw = 1.0f;
	vertices[1].u = 1.0f ;//0 - 1
	vertices[1].v = 0.0f ;//0 - 0

	vertices[2].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
	vertices[2].x = (float)x + 64;
	vertices[2].y = (float)y + 64;
	vertices[2].z = 0.0f;
	vertices[2].rhw = 1.0f;
	vertices[2].u = 1.0f ;//0 - 1
	vertices[2].v = 1.0f ;//0 - 0

	vertices[3].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
	vertices[3].x = (float)x;
	vertices[3].y = (float)y + 64;
	vertices[3].z = 0.0f;
	vertices[3].rhw = 1.0f;
	vertices[3].u = 0.0f ;//0 - 1
	vertices[3].v = 1.0f ;//0 - 0