This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 »
196
Function Peer Review / move_contact functions optimised for bbox
« on: December 31, 2010, 12:09:58 am »Code: [Select]
int move_contact(double direction, double max_distance, bool solid_only)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
double max_x = lengthdir_x(direction, max_distance);
double max_y = lengthdir_y(direction, max_distance);
for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(all); it != NULL; it = it->next)
{
const enigma::object_collisions* inst2 = (enigma::object_collisions*)it->inst;
if (inst2->id == inst1->id || solid_only && !inst2->solid) continue;
if (max_x > 0)
{
const double x1 = inst1->x + max_x, x2 = inst2->x + inst2->bbox_left;
if (x2 < x1)
{
max_x = x2 - inst1->x;
}
}
else if (max_x < 0)
{
const double x1 = inst1->x + max_x, x2 = inst2->x + inst2->bbox_right;
if (x2 > x1)
{
max_x = x2 - inst1->x;
}
}
if (max_y > 0)
{
const double y1 = inst1->y + max_y, y2 = inst2->y + inst2->bbox_top;
if (y2 < y1)
{
max_y = y2 - inst1->y;
}
}
else if (max_y < 0)
{
const double y1 = inst1->y + max_y, y2 = inst2->y + inst2->bbox_bottom;
if (y2 > y1)
{
max_y = y2 - inst1->y;
}
}
}
inst1->x += max_x;
inst1->y += max_y;
return 0;
}
inline int move_contact_solid(double direction, double speed) { return move_contact(direction, speed, true); }
inline int move_contact_all(double direction, double speed) { return move_contact(direction, speed, false); }
Haven't tested it yet, but this should work. Also am going under the assumption that objects don't collide when they share an edge.
197
General ENIGMA / Re: Some common GML issues, and dealing with them in Enigma?
« on: December 30, 2010, 11:46:55 pm »2. Referencing resources as stringsHaven't read the topic, but:
People often find themselves wanting to reference a resource index from it's corresponding string, being lazy they don't wish to map all the object indexes to strings manually, so is there a way this can be done easily in Enigma?
This will be nice, as it removes 90% of the use of execute_string().
Oftentimes, people do things like:
status = 'standing';
color = 'blue';
execute_string('sprite_index = player_' + color + '_' + status);
198
Proposals / Re: Additions to new platform system
« on: December 29, 2010, 02:34:17 pm »So because the user fails at setting up their own path variable, we give them assistance? I don't... nevermind...Example:
PATH=/usr/i486-mingw32/bin:$PATH make
I wouldn't want that to always be in my path. Just long enough to run the command.
199
Function Peer Review / Re: distance_to_object
« on: December 27, 2010, 10:48:17 pm »
But of course.
200
Function Peer Review / Re: distance_to_object
« on: December 27, 2010, 06:06:53 pm »
Updated code:
I'm almost certain that someone will modify this before it's put into ENIGMA, but this is what I have.
Code: [Select]
/* ********************* */
// Place this in some math header or something.
inline double range_difference(double left1, double right1, double left2, double right2)
{
double right = min(right1, right2), left = max(left1, left2);
return (left > right ? left - right : 0);
}
/* ********************* */
#include <limits>
double distance_to_object_point(int object)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
double distance = std::numeric_limits<double>::infinity();
double tempdist;
for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(object); it != NULL; it = it->next)
{
const enigma::object_collisions* inst2 = (enigma::object_collisions*)it->inst;
if (inst1 == inst2) continue;
tempdist = point_distance(inst1->x, inst1->y, inst2->x, inst2->y);
if (tempdist < distance)
{
distance = tempdist;
}
}
return (distance == std::numeric_limits<double>::infinity() ? 0 : distance);
}
double distance_to_object_bbox(int object)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
const double left1 = inst1->x + inst1->bbox_left, top1 = inst1->y + inst1->bbox_top,
right1 = inst1->x + inst1->bbox_right, bottom1 = inst1->y + inst1->bbox_bottom;
double distance = std::numeric_limits<double>::infinity();
double tempdist;
for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(object); it != NULL; it = it->next)
{
const enigma::object_collisions* inst2 = (enigma::object_collisions*)it->inst;
if (inst1 == inst2) continue;
const double left2 = inst2->x + inst1->bbox_left, top2 = inst2->y + inst1->bbox_top,
right2 = inst2->x + inst1->bbox_right, bottom2 = inst2->y + inst1->bbox_bottom;
tempdist = hypot(range_difference(left1, right1, left2, right2),
range_difference(top1, bottom1, top2, bottom2));
if (tempdist < distance)
{
distance = tempdist;
}
}
return (distance == std::numeric_limits<double>::infinity() ? 0 : distance);
}
inline double distance_to_point_point(double x, double y)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
return point_distance(inst1->x, inst1->y, x, y);
}
inline double distance_to_point_bbox(double x, double y)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
const double left1 = inst1->x + inst1->bbox_left, top1 = inst1->y + inst1->bbox_top,
right1 = inst1->x + inst1->bbox_right, bottom1 = inst1->y + inst1->bbox_bottom;
return hypot(abs(min(left1 - x, right1 -x),
min(top1 - x, bottom1 -x)));
}
// Possible option in configuration to choose which method is used?
inline double distance_to_object(int object) { return distance_to_object_bbox(object); }
inline double distance_to_point(double x, double y) { return distance_to_point_bbox(x, y); }
I'm almost certain that someone will modify this before it's put into ENIGMA, but this is what I have.
201
Proposals / Re: Additions to new platform system
« on: December 25, 2010, 10:58:25 am »
I'd go even further than that and store the final linking makefile inside of the platform directory, and the makefile in SHELL just calls whichever one matches the platform and sends it the proper list of files to link. The platform can decide what file extension to use and how to pack the game.
202
Function Peer Review / Re: distance_to_object
« on: December 25, 2010, 10:54:22 am »But I might accept Retro's bottom function. Provided, of course, that dist_ranges be made inline or into a macro.I honestly don't know why I didn't make it inline. I was probably rushing. If you're going to use the bottom method, I'd still keep both labeled.
Code: [Select]
#define distance_to_object(x) distance_to_object_point(x)
orCode: [Select]
inline double distance_to_object(int object) { return distance_to_object_point(object); }
203
Function Peer Review / Re: distance_to_object
« on: December 23, 2010, 02:41:32 pm »
Was it in C++ or GML?
204
Function Peer Review / distance_to_object
« on: December 20, 2010, 09:02:53 pm »Code: [Select]
#include <limits>
double distance_to_object_point(int object)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
double distance = std::numeric_limits<double>::infinity();
double tempdist;
for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(object); it != NULL; it = it->next)
{
const enigma::object_collisions* inst2 = (enigma::object_collisions*)it->inst;
if (inst1 == inst2) continue;
tempdist = point_distance(inst1->x, inst1->y, inst2->x, inst2->y);
if (tempdist < distance)
{
distance = tempdist;
}
}
return (distance == std::numeric_limits<double>::infinity() ? 0 : distance);
}
inline double dist_ranges(double left1, double right1, double left2, double right2)
{
double right = min(right1, right2), left = max(left1, left2);
return (left > right ? left - right : 0);
}
double distance_to_object_bbox(int object)
{
enigma::object_collisions* const inst1 = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
const double left1 = inst1->x + inst1->bbox_left, top1 = inst1->y + inst1->bbox_top,
right1 = inst1->x + inst1->bbox_right, bottom1 = inst1->y + inst1->bbox_bottom;
double distance = std::numeric_limits<double>::infinity();
double tempdist;
for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(object); it != NULL; it = it->next)
{
const enigma::object_collisions* inst2 = (enigma::object_collisions*)it->inst;
if (inst1 == inst2) continue;
const double left2 = inst2->x + inst1->bbox_left, top2 = inst2->y + inst1->bbox_top,
right2 = inst2->x + inst1->bbox_right, bottom2 = inst2->y + inst1->bbox_bottom;
tempdist = hypot(dist_ranges(left1, right1, left2, right2),
dist_ranges(top1, bottom1, top2, bottom2));
if (tempdist < distance)
{
distance = tempdist;
}
}
return (distance == std::numeric_limits<double>::infinity() ? 0 : distance);
}
Tested and both work. I don't know which method that GM uses, but here's two different algorithms.
205
General ENIGMA / Re: Linux Repositories
« on: December 19, 2010, 12:03:41 pm »
Oh, by the way, the package works, now.
206
Announcements / Re: Collisions update
« on: December 18, 2010, 09:16:30 pm »After I got back from the hospital, I started work on Enigma, since other people are actually working on that too, even though I despise C++ (and now I'm re-learning why).And why is that?
Also, I do know Java, but hardly any of its classes besides the basics.
207
Proposals / Re: Random speed ups and slow downs with compiled games
« on: December 17, 2010, 04:12:22 pm »
As far as I know, VSync is still turned on, unless Josh turned it off. You can probably force it with your driver settings.
208
Proposals / Re: Random speed ups and slow downs with compiled games
« on: December 16, 2010, 04:53:08 pm »
400-100 is likely just your CPU/GPU. That's probably normal.
209
Function Peer Review / Re: clamp()
« on: December 16, 2010, 03:37:13 pm »Clamp is more efficient than median, unless median is specialized for each argument count.Which is why min(max(x,min),max) is the best
210
General ENIGMA / Re: variable_* Functions
« on: December 16, 2010, 03:35:12 pm »
That makes sense, then. I just assumed that the binary's pointers would be inaccurate because it would be different if that one pointer was taken.