Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 30 Dec 2000
Online Last Active Today, 09:08 AM

#5041373 Scaling images

Posted by nobodynews on 09 March 2013 - 09:24 PM

You probably want to look into using the SDL_SoftStretch function. If you have a source 16x16 SDL_Surface* called (for example) image_16square and a destination 64x64 SDL_Surface* called (for example) image_64square you would call it like this:


SDL_SoftStretch(image_16square, NULL, image_64square, NULL);


Untested. This uses SDL 2.0. If you're using SDL 1.2 you should specify. Basically you'd lock both the 16x16 source surface and the 64x64 destination surface. Then you'd go through every pixel in the 16x16 surface and set the equivalent 4 pixels in the destination surface to the same value as that pixel.

#5032671 OOP with vectors

Posted by nobodynews on 15 February 2013 - 09:17 AM

There are almost certainly better solutions to your problem than what I'm about to suggest, but the quickest and dirtiest solution is to pass in a reference (I'd suggest by const) to the same vector of entities:


::updateLogic(const std::vector<Entity *> &entities)  { ... }


Or just std::vector<Entity> (you say a vector of pointers to instances, but the code you show is just a vector of instances so I'm not sure what you're actually doing). There are pitfalls to this method and you'll probably want to check that the entity which is being acted upon is not the same as the entity you're currently cycling through in the function body.


All that said, I highly suggest you explain *why* you want to do this and we can suggest better solutions.

#5028227 What is the difference in these 2 variables?

Posted by nobodynews on 02 February 2013 - 09:38 PM

Microsoft offers a clear explanation here. The important part is under the initializing value types section. Basically, the first way doesn't initialize the variable and you must initialize variables bofore you can use them in C#. So you have to assign a value to the variable before you could use it or you'll get a compiler error.  The second way calls the default constructor for an int type which that links says is equivalent to doing this: int a = 0;


I doubt there's any performance difference between the two methods.

#5013853 a few questions

Posted by nobodynews on 23 December 2012 - 10:59 PM

I think NoAdmiral was suggesting not using graphics but text like on the command line. "ASCII graphics" would be a common search term. That way you don't need to learn graphics programming on top of everything else. It was just an alternative suggestion to get closer to your end goal of MMORPG by skipping some steps that you might find more boring.

#5011492 I need help with vectors of vectors.

Posted by nobodynews on 16 December 2012 - 09:31 PM

The error is saying exactly the issue. You're pushing back a vector of bools and that code is expecting a bool. Try changing line 13 to this:


Of course a better solution is to make this function:

std::vector<std::vector<bool>> Create2DVectorOfBools(int x, int y)
  std::vector<bool> temp(y, false);
  std::vector<std::vector<bool>> mv(x, temp);

  return mv;

What this does is first creates a 1d vector of bools of length y and initializes every element in it to 'false' (see here for info on every constructor of std::vector http://msdn.microsoft.com/en-us/library/zzw4bwhd.aspx )
Then it creates a vector of vector of bools of length x and initializes every element in it to 'temp' (which, as stated, was initialized to length y).
Then it returns a copy of the resulting 2d vector.

#5005404 SFML application on exit dosent return 0

Posted by nobodynews on 29 November 2012 - 01:08 PM

Just because you didn't create your own destructor (deconstructor isn't the appropriate name, FYI) doesn't mean much. The compiler creates destructors on its own. And you maybe *should* have created destructors.

A few observations. First, tat's quite a lot of globals you have there. You have the following objects that aren't created in main():
objWindow, objFps, objTextures, objFunctions, ,objMainMenu, objOptions, objSquad, objSquadCreation, objAudio

The problem could be in any one of these or even objApp. My theory is that because many of the obj* objects are created and use objApp that there's an issue with how you're storing objApp in the other objects. objApp is destroyed before the globals and this could be causing issues somehow. So, two things you should do. First, create a block around objApp like this:

int main() {
  { // Add this!
  Application objApp;

  // the rest of your code here

  } // Add this! ObjApp is destroyed here instead of after the return

  return 0;

If the problem is when objApp is destroyed, then you'll get an error before you reach the return statement. Otherwise the problem is when one of the globals is destroyed.

Second thing you should do is post the code of Application and one or two of the objects that use objApp.

#5002519 Sleep and Electricity

Posted by nobodynews on 19 November 2012 - 07:11 PM

Electricity always moves by definition at a fixed speed in a given medium, so we can't just "stop" the signal and wait for something to happen. I imagined that the CPU was just one big circuit and that the electricity always flows but the circuit may cut off a loop or the circuit not to be actualized until a voltage from outside the system (i.e. the graphics device) re-activates it.

You seem to be confused a little about how circuitry works so here's a quick crash course.

Consider first a diode ( http://en.wikipedia.org/wiki/Diode ). A diode's behavior depends upon the source voltage. At low voltages a diode will consume a very low amount of electricity (an ideal diode consumes NO electricity because at infinite resistance no electricity can flow). At high voltage the diode does consume electricity (at which point the diode can be modeled like a normal resistor). Diodes aren't really used in CPUs though, it's just a simpler concept than...

The transistor ( http://en.wikipedia.org/wiki/Transistor ). You can imagine a transistor as behaving like a dam. A dam has a reservoir that's normally filled with water. The dam doesn't have to let any of the water out of the reservoir, a gate must be open first. If the gate is opened then if there's any water at the source of the reservoir then it can drain out. No water at the source and no water flows out the drain, regardless of whether the gate is open.

A transistor works the same way. A transistor has a 'gate', a 'source', and a 'drain'. In this case the gate is opened or closed depending on whether there's voltage there above a certain threshold. If any electricity is present at the source, it can flow through the drain when the gate is open. Like a diode, if the gate is closed then there shouldn't be any electricity usage. Of course also like a diode that's for an 'ideal' transistor'. A real transistor will leak some current, even with a closed gate. So if you shut off enough transistors for some reason this would result in much less current (and this power) being consumed.

Many processors support a standby mode where the CPU is made almost entirely inactive, until an interrupt is triggered awakening the processor. That said, I'm not sure if this processor feature is necessarily *used* by Microsoft in their OS. If it is, it's definitely not going to be used when a random program calls 'sleep', but when the OS decides to go standby mode at which time pretty much nothing is going to happen until the OS wakes up again.

And of course, what frob said about reducing clock frequency.

#4996572 How to start?

Posted by nobodynews on 02 November 2012 - 10:01 AM

There is no correct way. There is no universal language. You shouldn't learn 2-3 languages at the same time. Someday you should learn 2-3 languages really well and you'll probably use many more than that. Flash may or may not be dying but it has a huge install base that won't be going away for awhile; don't base your decision on that. Once you become good at one language learning a new language is much easier. I think beginners should wait on C++ because it has a higher learning curve than many other languages. If you were to pick two languages like C++ and C# then I believe it would take less time to learn C# then C++ than the other way around because of C++'s learning curve getting away with learning the fundamentals of programming.

My default suggestion for beginners is C# or Python, but Action Script would be fine as well. But above all I suggest you don't give up. There is no best path but the only path that gaurantee's failure is to quit. So don't worry so much about doing things right or wrong. If you have questions we're here to help.

Good luck.

#4987459 How to manage input from more than one potential source?

Posted by nobodynews on 06 October 2012 - 12:10 PM

I thought of using an integer for this, but that just seems sloppy... Like if I press key_w, held_amt++, if I press key_up, held_amt++, if I press mouse_2, held_amt++. Then when I release one of them, I do held_amt--, check if it is equal to zero, and then if it is, stop running...

I don't know, this just seems very sloppy to me.

Doesn't seem that sloppy to me given what you want to do.

What you could do is have an enum of possible actions (Action) mapped to an integer to count the number of inputs that are applied to that action like this:
std::map<Action, int> ActionBindings;
And for the callback system you want to associate a key with an action in another map like this:
std::map<Key, Action> KeyBindings;

When OnKeyUp/Down is called, map from the Key to the Action and then from the Action to the count for that Action. Then in the part of the code that performs actions just check for which actions are currently occurring and do actions based on that. Hope this helps.

#4970621 TouchInput structure

Posted by nobodynews on 17 August 2012 - 11:46 AM

When a timestamp wraps around the time difference is about 50 days (2^32 milliseconds / 1000 milliseconds per second / 60 seconds per minute / 60 minutes per hour / 24 hours per day = 49.71 days). You could decide that if you receive a message more than an arbitrary time (1 second, 1 hour, 1 day...) before the previous message that it must have occurred *after* the last message even though the times is technically < the last message. Or to integrate it with your code, something like this I believe would work:

if( ( touchstore[ i ].dwID == message[ mindex ].dwID ) && ( ( message[ mindex ].dwTime > touchstore[ i ].dwTime ) || (message [mindex].dwTime < (touchstore[ i ].dwTime - WrapAroundTimeDelta) )) )

Where WrapAroundTimeDelta is something like 86400000 milliseconds (24 hours) in the past.

#4962482 How much slower is boost::shared_ptr

Posted by nobodynews on 23 July 2012 - 10:03 PM

You should look into profiling

#4961814 AUTO_PTR issue.

Posted by nobodynews on 21 July 2012 - 07:09 PM

While researching this question I found a bunch of links saying "don't use auto_ptr in map". It looks like Microsoft agrees with them and actually made it a comipiler error by marking auto_ptr's constructor explicit. One solution would be to use a different kind of smart pointer that does support copy-semantics.

#4961753 Having problem using SDL_mixer

Posted by nobodynews on 21 July 2012 - 02:03 PM

You want the 'developer' binaries for SDL Mixer: SDL_mixer-devel-1.2.12-VC.zip for windows. Haven't tried using it myself.

#4860832 Fast way to load in a dictionary

Posted by nobodynews on 12 September 2011 - 01:33 PM

How large is the raw text file? 170k words at 10 chars a word is only 1.7MB and I wouldn't be surprised if the average number of characters in a word was less than 10. You also mention that after loading everything the memory usage goes down. In which case I think Antheus has the best idea he just over-estimed the memory usage. He really should have said:

char * text = new char[# of chars in text file];
int * offsets = new int[# of words in text file];

#4780814 Invalid Block type

Posted by nobodynews on 01 March 2011 - 08:44 PM

I looked into the assertion that was failing and since you said the problem occurs at the end of main that means you are likely double deleting some memory when a global gets destructed. So look into your global variables and try to find out what might be shared between them that is getting deleted 2+ times.