Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Apr 2010
Offline Last Active Private

#5263742 Math for game developers?

Posted by Khatharr on Yesterday, 05:16 PM


#5263281 Help with a specific script?

Posted by Khatharr on 23 November 2015 - 11:48 AM

Not many people are familiar with RGSS. I know the XP variant, but it looks like there have been a lot of changes since then. You may have better luck looking for an RMMV dedicated forum.

#5263212 About Portfolios

Posted by Khatharr on 22 November 2015 - 08:30 PM

If you're talking about project examples then:


a) A project where you did writing.

b) A project that you programmed.

c) A project where you did design work.

#5263211 If I make an RPG with RPG maker MV, can I sell it on Steam?

Posted by Khatharr on 22 November 2015 - 08:27 PM

RPG Maker games that use RTPs are generally not received well, since they all look very much alike.


There are a few RPG Maker games that distinguished themselves and did a bit better, such as the Cherry Tree High games and Stray Cat Crossing.

#5263075 Random errors in Release builds

Posted by Khatharr on 21 November 2015 - 09:13 PM

Please don't mark threads as "solved", as it discourages further discussion.

#5262909 MyClass myClass VS myClass = new MyClass()

Posted by Khatharr on 20 November 2015 - 01:09 PM

I've never overflowed the stack outside of bugs and intentional tomfoolery. In fact, I find the default stack length on Win7/VS2015 to be uncomfortably large as it takes too long to overflow when I screw up a recursion or something. (Looking it up, apparently it's only 1MB, lol)
The rule of thumb is to use pointers when you need nullable, reassignable, or late-binding references, use references when you need simple references, and just do everything else by value/on the stack. Raw resource management, including 'new' and 'delete', in the application layer are officially considered an abomination. Use some kind of RAII instead, preferably the native smart pointers and containers for memory.
As you get used to this model you'll find that unique_ptr is nice to have, shared_ptr is a little bit scary (it's not hard to use, but it can sometimes mean that you're doing something silly), and doing everything in-place makes life a lot simpler.
I'm not sure whether you know it already or not, but one thing I see people get stuck on at this level is how to initialize member objects that need constructor arguments. When you see someone using pointers for all their class members it's because they don't know about this. You pass constructor args to member objects with the initializer list on the constructor:
class Foo { //Construction requires an argument!
public: Foo(int val) { value = val; }
  int value;

class Bar {
  Foo a; //How can you initialize this? It needs a ctor argument!
  Foo b;
  Foo c;

Bar::Bar() : a(42), b(16), c(-1) { //You do it like this. 
  //^ The initializers happen before the function body.

You can pass arguments from the owning ctor as well. That is, if Bar::Bar() was Bar::Bar(int arg) then you could say:
Bar::Bar(int arg) : a(arg), b(arg), c(42) { /* stuff */ }

#5262126 Why isn't this working?

Posted by Khatharr on 15 November 2015 - 09:58 AM

Correct, however, I'd caution you regarding the use of member references. They can get really cantankerous if you start moving objects around. Dangling references are no fun at all. They're legal C++, but if you use them just be very careful and if you encounter a "weird" bug, suspect them immediately.

#5261349 How to do a color reduction calculation?

Posted by Khatharr on 10 November 2015 - 08:40 AM

Assuming you're referring to a single color channel you just cast it to float and then divide it by 255.

#5261230 Can a full program be stored in a photo image

Posted by Khatharr on 09 November 2015 - 04:19 PM

Can anyone suggest a better approach?


Digital storage.

#5260992 Possible to forward declare a sub class?

Posted by Khatharr on 08 November 2015 - 06:02 AM

You don't (necessarily) need to pimpl here. The reason you were having a problem is not that you had a pointer to an incomplete type. It's that you were trying to make use of that incomplete type.
This works:

#pragma once

class One {
	int doSomething();

	class Two; //forward declaration =/= full declaration

  /* full declaration would work
  class Two {
    int test();

	Two* cTwo;

  Two* createTwo();

class One::Two { //this is a full declaration (you could also just nest it in One)
  int test();

//you could put the One::Two declaration in a different header, but you'd need to include that header anywhere that One::Two is used.

#include "derp.h"

int One::doSomething() {
  cTwo = createTwo();
  return 0;

One::Two* One::createTwo() {
   return new Two();

int One::Two::test() {
  return 0;


#include <iostream>

#include "derp.h"

int main() {
  One foo;

  std::cout << foo.cTwo->test() << "\n";

Nested types can be very handy in places where they're appropriate, but understanding where those places are is a bit advanced in terms of design. Why are you trying to nest this type?

#5260533 Smash Bros Style Camera

Posted by Khatharr on 04 November 2015 - 11:58 AM

First, avoid putting long statements in switches as it quickly gets too messy. Break the subroutine out into a new function and just call it from the switch. It will make life easier for you.
Abs the vector components instead of the max value. If the zoom is inverted then it means the fractions for the ratios are inverted, so just flip them over (invert the comparison as well).
There's a cleaner way of doing this though, since you're already iterating the characters to find the camera position. Instead of finding the position and then the zoom, just find the bounding box which contains everything you want and then derive what you need from that:

Rectangle rect = new Rectangle(playerList[0].Position.X, playerList[0].Position.Y, 0, 0);

foreach (Player P in playerList)
    int x = (int)P.position.X;
    int y = (int)P.position.Y;
    if (x < rect.Left  ) { rect.X      = x; }
    if (x > rect.Right ) { rect.Width  = x - rect.X; }
    if (y < rect.Top   ) { rect.Y      = y; }
    if (y > rect.Bottom) { rect.Height = y - rect.Y; }

//You may want to increase the rect size at this point by subtracting 
//some from the x and y and adding to the width and height. Alternatively
//you could just find some factor very close to 1.0f to multiply the 'zoom'
//by before applying it.

Vector2 cameraPos = new Vector2((float)rect.X, (float)rect.Y);
cameraPos.X += (float)rect.Width  / 2;
cameraPos.Y += (float)rect.Height / 2;

//this part may be inverted??? if so flip the divisions and use max instead of min
float xZoomReq = (float)Game1.screenWidth  / rect.Width;
float yZoomReq = (float)Game1.screenHeight / rect.Height;
float zoom = Math.Min(xZoomReq, yZoomReq);

//At this point you can compare the result against min/max zoom values.
//These are numbers you should determine yourself through experimentation,
//as would be the buffer size mentioned above.

For reasons unknown to any sane person, there's no float rectangle struct, so the math is a bit rough and I may have missed some casting. You don't need super-high precision here though, since you're probably going to monkey with the final result a little anyway.

#5260464 Smash Bros Style Camera

Posted by Khatharr on 04 November 2015 - 02:49 AM

Do you have zoom functionality available? For 2D this is actually quite simple to calculate.


Once you're centered you should have an x/y world coordinate that you're placing the camera at. You need to do a little (very little) vector math on the players to find out which one is farthest from that point in the x dimension and which one is farthest in the y dimension.


To find the relative coordinate of a player from the center-point, just:


relative_pos = player.pos - centerpoint


using 2D vectors. Create max_abs_x and max_abs_y variables and set them both to zero (or some minimum value that you decide). Iterate through the players and determine their relative positions, then abs the x and y and if either of them is larger than the value in your max variables then replace that value with the new larger one. You'll end up with a pair of values representing the half-width of the minimum area you need to represent. You can add a buffer at this point if you want so that the players aren't at the absolute screen edge.


Once you have that you just need to consider the size of the viewport compared to the result.


Say you have a viewport that's 800x600. The half-width dimensions of the viewport are 400 and 300. If your max_abs_x is 500 and your max_abs_y is 500 then you can get the ratios:


x_ratio = 500 / 400 = 1.25

y_ratio = 500 / 300 = 1.66~


So you can see that the larger of the two is the y, so you need to zoom to a factor of 1.66~.


Depending on how your zoom is implemented you may be able to just plug that in directly.


You'd only need to get a little more complicated if you're working with a 3D'ish camera and need to move the camera back and forth or play with the field of view.

#5259974 How do I re-size a binary file?

Posted by Khatharr on 01 November 2015 - 05:54 AM

Still can't just post the whole thing?


That is so frustrating

#5259952 NonCopyable everywhere ?

Posted by Khatharr on 31 October 2015 - 08:30 PM

I use NonCopyable thoroughly in my engine for a few reasons
- it's possible to implement copying but YAGNI, so I'll only do it when I need it rather than needlessly writing unused code. I find YAGNI to be an important way to not end up in permanent engine-development hell.
- It's possible to implement but would be a significant performance cost, and there's probably a better way to do whatever it is that is making you think that you need a copy, so I'm discouraging you.
- multiple copy semantics are equally valid (e.g. deep/shallow), and I don't want an automatic opetator to have vague or unexpected behaviour, so copying via explicit named functions is available instead.
- Copying *could* be possible, but by assuming that it can't happen, I can simplify the code design (e.g. maybe it means I can avoid reference counting), plus YAGNI.

FWIW, I also use a NoCreate class, which has private, non-implemented constructors and destructors smile.png


Sure, it doesn't bother me in application code, but when I find it in APIs it makes my eye twitch.

#5259951 Trying to initialize an array created with 'new'

Posted by Khatharr on 31 October 2015 - 08:24 PM


The difference is that [3] would cause a compile error if the literal didn't have three members (stops you from making mistakes).

It results in a compile error if you have too many, but not if you have too few.


Wow, that's gross.

It would appear that VS2015 also ignores the braced initializer for array new, and does not indicate a syntax problem. I'm sending a report presently.