Jump to content

  • Log In with Google      Sign In   
  • Create Account

Khatharr

Member Since 24 Apr 2010
Offline Last Active Private

#5269724 need suggestion for IDE/Engine

Posted by Khatharr on 06 January 2016 - 07:32 PM

Unity and MonoGame are recommended for C#.

 

Unity has a massive amount of support data (huge reference library, concept tutorial videos, etc) and community. It's a full IDE, so it may be a little overwhelming at first, but intro videos can very quickly get you situated with the workflow.

 

MonoGame is pretty easy to work with and also has a decent community. MonoGame is an API rather than an IDE, so it doesn't involve learning a new environment.

 

You should probably take a look at the introductory materials for both and see which one is closer to meeting your needs.




#5269533 Advice on coding style

Posted by Khatharr on 05 January 2016 - 08:08 PM

That's exactly (part of) what const correctness does for you. It catches subtle errors like that which are otherwise valid code but don't do what you really want.

 

Good luck. Let us know if you have more questions. smile.png




#5269527 Advice on coding style

Posted by Khatharr on 05 January 2016 - 07:41 PM

Here's a hint:

 

Returns expected result:

int main()
{
	time fTime1(12, 42, 56);
	time fTime2( 1, 23, 42);
	time fTemp;
	
	fTemp = fTime1 - fTime2;
	fTemp.timeDisplay();
}

Does not return expected result:

int main()
{
	time fTime1(12, 42, 56);
	time fTime2( 1, 23, 42);
	time fTemp;
	
	fTemp = fTime1 + fTime2;
	fTemp.timeDisplay();
	
	
	fTemp = fTime1 - fTime2;
	fTemp.timeDisplay();
}

Super-hint: Harking back to const correctness, operator-(time); should be a const function. The const correct prototype should be:

time operator-(const time& t2) const;

The compiler will flat out tell you the problem once that's the case.




#5269514 Advice on coding style

Posted by Khatharr on 05 January 2016 - 05:50 PM

  1. It doesn't make sense to multiply a time by another time. It would make sense to multiply a duration by a scalar though.
  2. It doesn't make sense to increment or decrement this implementation of time because it's not unitary and it's not scalar.
  3. NO: operator + (time t2); YES: operator+(time t2);
  4. time t(0, 1000000, -12345); //invariants are not correctly enforced for m or s ranges
  5. while(seconds < 0) { seconds += 60; --minutes; } //use modulo and divide instead. also, you correct ranges in more than one place. make it a private member function
  6. time::timeDisplay(); //instead of writing functions that stream to cout, write functions that return string or take ostream& argument so that you can use other output methods.
  7. NO: operator+(time t2); YES: operator +(const time& t2); //const correctness is your friend
  8. Your compiler should be telling you about line 103. If not then increase your warning level.
  9. If the time/duration is negative how is that expressed? What if hours and minutes are positive and seconds is negative? What about hours being negative and the others positive? How does this work?
  10. If you implement a negation operator then you'll be able to implement the subtraction operator as "self + -other".
  11. You're using three values to express a single quantity. What if you were to use one large value (long long seconds?) and then just do the reporting differently?



#5269273 Java, still being a good option for game dev in 2016 or there are other optio...

Posted by Khatharr on 04 January 2016 - 04:38 PM

Probably my bad but I don't recall even a single game asking me or being bundled with any Java runtime (therefore written in Java)

 

Standalone JRE requirement is usually on the part of miscellaneous utility programs. I got tired of fighting with JRE a long time ago and decided 'nevar again'. I have no issue with games that bundle their own runtime though. My favorite roguelike is Pixel Dungeon, which is bundled (originally Android).




#5269107 Java, still being a good option for game dev in 2016 or there are other optio...

Posted by Khatharr on 03 January 2016 - 08:27 PM

http://launch4j.sourceforge.net/




#5269042 Criticism of C++

Posted by Khatharr on 03 January 2016 - 01:00 PM


* Rust might actually be on the right track, if they become a little more pragmatic.

 

Ooh? I'll have to look at it.




#5268932 Criticism of C++

Posted by Khatharr on 02 January 2016 - 09:39 PM

 



 



C++ is a flawed language - mostly due to the compilation model or decades of accumulated evolution - but most criticisms I've seen of it are even more flawed, and most of them basically boil down to "this language doesn't abstract away the underlying hardware enough for my taste."

 

Yup. Language wars are silly because it doesn't make sense to use only one language in the first place. Every language has its weak points and every language except for Java has its strong points. You just have to know what's available and use the right tool for the job.

 

 

Believe it or not, some people consider checked exceptions to be a good thing, so according to them even Java has its strong points.

 

You're making this too easy... I wasn't even aiming for you.




#5268911 Criticism of C++

Posted by Khatharr on 02 January 2016 - 07:47 PM

C++ is a flawed language - mostly due to the compilation model or decades of accumulated evolution - but most criticisms I've seen of it are even more flawed, and most of them basically boil down to "this language doesn't abstract away the underlying hardware enough for my taste."

 

Yup. Language wars are silly because it doesn't make sense to use only one language in the first place. Every language has its weak points and every language except for Java has its strong points. You just have to know what's available and use the right tool for the job.




#5268891 Criticism of C++

Posted by Khatharr on 02 January 2016 - 04:03 PM

Oh great, Chubu is going to see this and get all uppity. -.-




#5268669 C++ without pointers

Posted by Khatharr on 31 December 2015 - 09:58 PM

A) What did you expect to happen in case 1? Why did you expect the destructor to not be called?

B) For case 2 you've invoked assign/copy on the original object. How is that defined (explicit/implicit)?




#5268157 State Machine in ECS

Posted by Khatharr on 27 December 2015 - 07:22 PM

Can't you just make the state machine a generic AI component?

 

The general idea for the AI FSM is to have a current state which has an 'update' that can run to persist in that state. Then you have transitions between states that handle cleaning up the current state and entering the new one. There are a few different approaches, but the general idea is the same.

 

For example, if you were making an FPS and you had a guard you could have the states 'patrol', 'chase', and 'fight'. The patrol state moves toward the next node along some preset path, the chase state moves toward the player, and the fight state takes aim and shoots at the player. For each state you can have three functions: enter, update, and leave. Alternatively you could use a class for each state where the constructor and destructor handle the enter and leave parts.

 

Within the update function for each state you check against some conditions and decide if you want to transition to a new state. For example, in the patrol state, if you see the player you want to transition into the chase state, so you either call a patrolToChaseTransition() function of the FSM, or else just replace the state object with a new 'chase' object. Within the chase object you transition to 'fight' if you're in weapon range, or transition to patrol if you lose sight of the player.

 

Since the FSM is acting on the entity it will obviously need access to the entity ID or whatever you're using to manipulate the entity.




#5267958 Advice on coding style

Posted by Khatharr on 25 December 2015 - 10:01 PM


at some point you're going to look at some old code of yours and have no idea what it does

 

Yusssss. And then shout, "Why didn't I comment this horrible mess!"




#5267900 Advice on coding style

Posted by Khatharr on 25 December 2015 - 06:08 AM


where no "official" style is suggested

 

LOL

 

The ISOCPP guidelines have a whole "supporting section" (section NL) on stylistic crap. It's one of my main beefs with the document at present: I really feel that it's a low blow to smuggle that kind of nonsense into an ISOCPP guidelines document, even if they couch it with language indicating that it's only a suggestion. It lends far too much credence to things that are wholly optional, and will serve no purpose other than to erode practical freedoms over time. From an influential group, a wink can be as good as an edict.

 

IMNSHO there are only two rules for style:

  1. Regardless of the style you use, be consistent throughout the whole project.
  2. If someone is paying you, do what they tell you to do.

 

 

In any case, the guidelines themselves should be taken with a grain of salt - since it's still the early stages of a working document - but they do include a lot of good advice from a lot of highly experienced people.




#5267735 Advice on coding style

Posted by Khatharr on 23 December 2015 - 08:40 PM

+1 re not writing comments that just repeat what the code already says.

 

Code should say "what"; comments should say "why".

 

I'm looking at this, though:

	switch(temptype)
	{
		case 0:	type = manager;break;
		case 1: type = laborer; break;
		case 2: type = executive;break;
		case 3: type = driver;break;
	}

Generally you want to give statements their own line so that they're more readable. If you want to join statements together visually then just put an empty line above and below them. However, in this specific case ("case n: singleSimpleStatement(); break;") I'm okay with this style (except put a space before the breaks) because it makes the switch easier to read. I use this myself in some cases.

 

However, this switch is - in and of itself - a DRY violation. You're performing the same action in each case with the only difference being a parameter. That's a signal that there's a better way to write the code. Check this out:

enum etype { manager, laborer, executive, driver };
etype etypeArray[] = { manager, laborer, executive, driver };
//...
type = etypeArray[temptype];

You could also just specify an enum base type and then just cast temptype to etype, but some people frown on that since enums should generally be thought of non-numerically.

 

I'd also point out that you're not sanitizing your user input. if the user enters "12" as a type here, for instance, then you're going to get undefined behavior. Can you try writing a function that prints out a message and then accepts a specified input value? I have a template function for this that I'll show you later, but it's a good exercise for you to try writing one.

 

Try writing defining this:

int getUserInt(const std::string& message, int minVal, int maxVal);

Such that you could say:

char question[] = "Please enter the following details about Jill - \nPosition (0)manager, (1)laborer, (2)executive, (3)driver: ";
temptype = getUserInt(question, 0, 3);

The function should print the message string, then wait for input. Once it gets input it should check to make sure that it's valid, and if it's not then it should state that the input was invalid and ask the question again. It should repeat this until it gets a valid response, then return that response.

 

Note that you should also reset cin after use because users can do strange things to you:

//seems simple enough... but danger lurks within!
std::cin >> someValue;

//fetch this now since it's about to be reset
bool ok = std::cin.good();

//this clears error flags from the stream (makes the stream state "good" again)
std::cin.clear();

//the user could enter something like "12 and a partidge in a pear tree"
//and your next attempts to stream from cin would get filled in with "and", "a", "partidge", "in", "a", "pear", "tree" respectively
//cin.ignore() purges the stream up to the first delimiter it finds (in this case '\n')
//see http://www.cplusplus.com/reference/istream/istream/ignore/
std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n');

if(ok) { /* input didn't cause a stream or conversion error */ }
else { /* input could not be interpreted - someValue was not set by cin */ }

Users are dangerous!






PARTNERS