Ejemplo n.º 1
0
spBool 
spShapeLessThan(const spShape* a, const spShape* b)
{
    NULLCHECK(a); 
    NULLCHECK(b);
    return a < b ? spTrue : spFalse;
}
Ejemplo n.º 2
0
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
{
	NULLCHECK(option);
	NULLCHECK(defValue);

	CMeasurePlugin* measure = (CMeasurePlugin*)rm;
	CConfigParser& parser = measure->GetMeterWindow()->GetParser();
	return parser.ReadString(measure->GetName(), option, defValue, (bool)replaceMeasures).c_str();
}
Ejemplo n.º 3
0
spBool 
spShapesCanCollide(spShape* a, spShape* b)
{
    NULLCHECK(a); NULLCHECK(b);
    if (a->filter.group == spCollideAll && b->filter.group == spCollideAll) return spTrue;
    if (a->filter.group == b->filter.group) return spFalse;
    if (a->filter.type & b->filter.collide) return spTrue;
    if (b->filter.type & a->filter.collide) return spTrue;

    return spFalse;
}
Ejemplo n.º 4
0
// Deprecated!
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
{
	NULLCHECK(section);
	NULLCHECK(option);
	NULLCHECK(defValue);

	CConfigParser* parser = Rainmeter->GetCurrentParser();
	if (parser)
	{
		return parser->ReadString(section, option, defValue, false).c_str();
	}

	return defValue;
}
Ejemplo n.º 5
0
void spShapeInit(spShape* shape, spMassData* data, spBound* bound, spShapeType type)
{
    NULLCHECK(shape);
    NULLCHECK(data);
    NULLCHECK(bound);
    shape->mass_data = *data;
    shape->material = spDefaultMaterial;
    shape->bound = *bound;
    shape->type = type;
    shape->body = NULL;
    shape->next = NULL;
    shape->prev = NULL;
    shape->filter = spFilterCollideAll;
}
Ejemplo n.º 6
0
void 
spShapeFree(spShape** Shape)
{
    NULLCHECK(Shape);
    spShape* shape = *Shape;
    if (shape->body)
    {
        spBodyRemoveShape(shape->body, shape);
    }

    /// shape is a poly
    if (shape->type == SP_SHAPE_POLYGON)
    {
        spPolygonFree(Shape);
    }

    /// shape is a circle
    else if (shape->type == SP_SHAPE_CIRCLE)
    {
        spCircleFree(Shape);
    }

    /// shape is a segment
    else
    {
        spSegmentFree(Shape);
    }
}
Ejemplo n.º 7
0
/** Test whether AF_INET or AF_INET6 sockaddr is included in the given access
  * control list, returning 1 if it is, and 0 if not.
  */
static int is_included_in_acl(int list_length,
			      struct ip_and_mask (*list)[],
			      union mysockaddr *test)
{
    NULLCHECK(test);

    int i;

    for (i = 0; i < list_length; i++) {
	struct ip_and_mask *entry = &(*list)[i];
	int testbits;
	unsigned char *raw_address1 = NULL, *raw_address2 = NULL;

	debug("checking acl entry %d (%d/%d)", i, test->generic.sa_family,
	      entry->ip.family);

	if (test->generic.sa_family != entry->ip.family) {
	    continue;
	}

	if (test->generic.sa_family == AF_INET) {
	    debug("it's an AF_INET");
	    raw_address1 = (unsigned char *) &test->v4.sin_addr;
	    raw_address2 = (unsigned char *) &entry->ip.v4.sin_addr;
	} else if (test->generic.sa_family == AF_INET6) {
	    debug("it's an AF_INET6");
	    raw_address1 = (unsigned char *) &test->v6.sin6_addr;
	    raw_address2 = (unsigned char *) &entry->ip.v6.sin6_addr;
	} else {
	    fatal("Can't check an ACL for this address type.");
	}

	debug("testbits=%d", entry->mask);

	for (testbits = entry->mask; testbits > 0; testbits -= 8) {
	    debug("testbits=%d, c1=%02x, c2=%02x", testbits,
		  raw_address1[0], raw_address2[0]);
	    if (testbits >= 8) {
		if (raw_address1[0] != raw_address2[0]) {
		    goto no_match;
		}
	    } else {
		if ((raw_address1[0] & testmasks[testbits % 8]) !=
		    (raw_address2[0] & testmasks[testbits % 8])) {
		    goto no_match;
		}
	    }

	    raw_address1++;
	    raw_address2++;
	}

	return 1;

      no_match:;
	debug("no match");
    }

    return 0;
}
Ejemplo n.º 8
0
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
{
	NULLCHECK(option);

	CMeasurePlugin* measure = (CMeasurePlugin*)rm;
	CConfigParser& parser = measure->GetMeterWindow()->GetParser();
	return parser.ReadFloat(measure->GetName(), option, defValue);
}
Ejemplo n.º 9
0
void 
spMassDataInit(spMassData* data, const spVector center, spFloat inertia, spFloat mass)
{
    NULLCHECK(data);
    data->inertia = inertia;
    data->mass = mass;
    data->com = center;
}
Ejemplo n.º 10
0
spConstraint* 
spMotorJointNew(spBody* a, spBody* b, spFloat w)
{
    spMotorJoint* joint = spMotorJointAlloc();
    NULLCHECK(joint);
    spMotorJointInit(joint, a, b, w);
    return (spConstraint*) joint;
}
Ejemplo n.º 11
0
spConstraint* 
spGearJointNew(spBody* a, spBody* b, spFloat ratio, spFloat phase)
{
    spGearJoint* joint = spGearJointAlloc();
    NULLCHECK(joint);
    spGearJointInit(joint, a, b, ratio, phase);
    return (spConstraint*) joint;
}
Ejemplo n.º 12
0
void 
spGearJointInit(spGearJoint* joint, spBody* a, spBody* b, spFloat ratio, spFloat phase)
{
    NULLCHECK(joint); NULLCHECK(a); NULLCHECK(b);
    joint->constraint = spConstraintConstruct(a, b, SP_GEAR_JOINT);
    joint->lambdaAccum = 0.0f;
    joint->ratioInv = ratio ? 1.0f / ratio : 0.0f;
    joint->ratio = ratio;
    joint->eMass = 0.0f;
    joint->phase = phase;
    joint->bias = 0.0f;
    spConstraintInitFuncs(&joint->constraint.funcs, 
        (spFreeFunc)Free, 
        (spPreSolveFunc)PreSolve, 
        (spWarmStartFunc)WarmStart, 
        (spSolveFunc)Solve);
}
Ejemplo n.º 13
0
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
{
	NULLCHECK(relativePath);

	CMeasurePlugin* measure = (CMeasurePlugin*)rm;
	g_Buffer = relativePath;
	measure->GetMeterWindow()->MakePathAbsolute(g_Buffer);
	return g_Buffer.c_str();
}
Ejemplo n.º 14
0
int acl_includes(struct acl *acl, union mysockaddr *addr)
{
    NULLCHECK(acl);

    if (0 == acl->len) {
	return !(acl->default_deny);
    } else {
	return is_included_in_acl(acl->len, acl->entries, addr);
    }
}
Ejemplo n.º 15
0
LPCWSTR __stdcall RmReplaceVariables(void* rm, LPCWSTR str)
{
	NULLCHECK(str);

	MeasurePlugin* measure = (MeasurePlugin*)rm;
	ConfigParser& parser = measure->GetMeterWindow()->GetParser();
	g_Buffer = str;
	parser.ReplaceVariables(g_Buffer);
	parser.ReplaceMeasures(g_Buffer);
	return g_Buffer.c_str();
}
Ejemplo n.º 16
0
void __stdcall RmLog(void* rm, int level, LPCWSTR message)
{
	NULLCHECK(message);

	MeasurePlugin* measure = (MeasurePlugin*)rm;

	// Ignore Debug messages from plugins unless in debug mode.
	if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
	{
		GetLogger().LogSection((Logger::Level)level, measure, message);
	}
}
Ejemplo n.º 17
0
void parse_port(char *s_port, struct sockaddr_in *out)
{
    NULLCHECK(s_port);

    int raw_port;

    raw_port = atoi(s_port);
    if (raw_port < 0 || raw_port > 65535) {
	fatal("Port number must be >= 0 and <= 65535");
    }
    out->sin_port = htobe16(raw_port);
}
Ejemplo n.º 18
0
BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage)
{
	NULLCHECK(pszMessage);

	// Ignore LOG_DEBUG messages from plugins unless in debug mode
	if (nLevel != LOG_DEBUG || Rainmeter->GetDebug())
	{
		Log(nLevel, pszMessage);
	}

	return TRUE;
}
Ejemplo n.º 19
0
BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message)
{
	NULLCHECK(message);

	// Ignore Debug messages from plugins unless in debug mode.
	if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
	{
		GetLogger().Log((Logger::Level)level, L"", message);
	}

	return TRUE;
}
Ejemplo n.º 20
0
/* FIXME: should change this to return negative on error like everything else */
int parse_ip_to_sockaddr(struct sockaddr *out, char *src)
{
    NULLCHECK(out);
    NULLCHECK(src);

    char temp[64];
    struct sockaddr_in *v4 = (struct sockaddr_in *) out;
    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *) out;

    /* allow user to start with [ and end with any other invalid char */
    {
	int i = 0, j = 0;
	if (src[i] == '[') {
	    i++;
	}
	for (; i < 64 && IS_IP_VALID_CHAR(src[i]); i++) {
	    temp[j++] = src[i];
	}
	temp[j] = 0;
    }

    if (temp[0] == '0' && temp[1] == '\0') {
	v4->sin_family = AF_INET;
	v4->sin_addr.s_addr = INADDR_ANY;
	return 1;
    }

    if (inet_pton(AF_INET, temp, &v4->sin_addr) == 1) {
	out->sa_family = AF_INET;
	return 1;
    }

    if (inet_pton(AF_INET6, temp, &v6->sin6_addr) == 1) {
	out->sa_family = AF_INET6;
	return 1;
    }

    return 0;
}
Ejemplo n.º 21
0
int parse_to_sockaddr(struct sockaddr *out, char *address)
{
    struct sockaddr_un *un = (struct sockaddr_un *) out;

    NULLCHECK(address);

    if (address[0] == '/') {
	un->sun_family = AF_UNIX;
	strncpy(un->sun_path, address, 108);	/* FIXME: linux only */
	return 1;
    }

    return parse_ip_to_sockaddr(out, address);
}
Ejemplo n.º 22
0
struct spCircle* 
spShapeCastCircle(const spShape* shape)
{
    NULLCHECK(shape);
    if (shape->type == SP_SHAPE_CIRCLE)
    {
        return (spCircle*)shape;
    }
    else
    {
        spWarning(spFalse, "the shape is not a circle!\n");
        return NULL;
    }
}
Ejemplo n.º 23
0
struct spPolygon* 
spShapeCastPolygon(const spShape* shape)
{
    NULLCHECK(shape);
    if (shape->type == SP_SHAPE_POLYGON)
    {
        return (spPolygon*)shape;
    }
    else
    {
        spWarning(spFalse, "the shape is not a polygon!\n");
        return NULL;
    }
}
Ejemplo n.º 24
0
struct spSegment* 
spShapeCastSegment(const spShape* shape)
{
    NULLCHECK(shape);
    if (shape->type == SP_SHAPE_SEGMENT)
    {
        return (spSegment*)shape;
    }
    else
    {
        spWarning(spFalse, "the shape is not a segment!\n");
        return NULL;
    }
}
Ejemplo n.º 25
0
spBool 
spShapeTestPoint(spShape* shape, spVector point)
{
    NULLCHECK(shape);
    switch (shape->type)
    {
    case SP_SHAPE_CIRCLE:
        return spCircleTestPoint((spCircle*) shape, point);
    case SP_SHAPE_POLYGON:
        return spPolygonTestPoint((spPolygon*) shape, point);
    case SP_SHAPE_SEGMENT:
        return spFalse;
    }
    return spFalse;
}
Ejemplo n.º 26
0
void RmLogF(void* rm, int level, LPCWSTR format, ...)
{
	NULLCHECK(format);

	MeasurePlugin* measure = (MeasurePlugin*)rm;

	// Ignore Debug messages from plugins unless in debug mode.
	if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
	{
		va_list args;
		va_start(args, format);
		GetLogger().LogSectionVF((Logger::Level)level, measure, format, args);
		va_end(args);
	}
}
Ejemplo n.º 27
0
static void 
Free(spMotorJoint** joint)
{
    NULLCHECK(*joint);
    spFree(joint);
}
Ejemplo n.º 28
0
void 
spShapeSetFilter(spShape* shape, const spFilter filter)
{
    NULLCHECK(shape);
    shape->filter = filter;
}
Ejemplo n.º 29
0
void 
spShapeSetRestitution(spShape* shape, spFloat restitution)
{
    NULLCHECK(shape);
    shape->material.restitution = restitution;
}
Ejemplo n.º 30
0
void 
spShapeSetFriction(spShape* shape, spFloat friction)
{
    NULLCHECK(shape);
    shape->material.friction = friction;
}