C++ ::  Collision Free Hash On Unique Strings

Feb 28, 2013

I have following method to calculate a 16bit hash on a per definition unique string:

uint16_t IReferenceHolder::getHash(const std::string &ref) {
return std::inner_product(ref.begin(), ref.end(), ref.begin(), (uint16_t)0) % 65437;
}

Actually it calculates an inner product on each character adding it to the last result (see [URL] .....).

65437 is the nearest prime to 2^16. In fact I never need the full range of 16 bit, therefore 65437 different hashes are enough.

Empirically it seems - on unique strings - to be collision free. The strings have an maximum size of 255.

View 3 Replies


ADVERTISEMENT

C :: Finding Unique Strings Within A File?

Aug 10, 2014

I have been trying to write this program that reads a file of courses and then stores only the unique courses in an array of strings.

for some reason it crashes while reading the 2nd line.

printf within the function are just for me trying to trace the problem.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char** uniqueCourses(FILE *fp, int *wordCount);
int main()

[code].....

View 5 Replies View Related

C++ :: Map Collision - Camera Detection

Jan 20, 2015

Still working with SDL2 and c++ my map collision is messed up since I implemented my Camera.

I do understand that everything has a relative Position on the Screen, depending on the camera.

Problem No. 1: The camera is not moving as fast as the Player, despite having the absolutly same velocity (4/-4)??? How can this be O_o

Problem No. 2: My tile collision is totally messed now. Probably its because of the difference between the Player Position and the camera :/ So if you can solve Problem no. 1, Problem number 2 might work out on its own :)

I will upload the code to github [URL] .....

View 11 Replies View Related

C++ :: Determine Whether There Is A Collision Between 2 Meshes

Oct 19, 2013

How can I determine whether there is a collision between 2 meshes? I'd just like to see if one mesh is inside another.

View 10 Replies View Related

C++ :: 2D Platformer Collision Detection?

May 4, 2013

I've been working on my 2D platformer for a while, and I'm running into a couple of problems. It seems to become laggy even when only about 25 entities need to do collision detection with the 8 walls in the area.

Only one thing to note: the BOOST_FOREACH(const Edge& edge, this->GetCollisonBoxEdges()) { sections actually aren't a loop, all players and enemies are basically a vertical line for purposes of hitting walls, so that's why there is some weird stuff in there (like assuming the edge is oriented a certain way, etc).

Asset::WallCollision Asset::GetClosestWallCollision(const std::vector<const Room::Wall*>& walls) const {
typedef std::pair< sf::Vector2<CoordT>, sf::Vector2<CoordT> > Edge;
const Room::Wall* wall_hit = NULL, * landing_wall = NULL;
util::intersect_ret temp, closest;
VelocityT para_vel;
if(this->m_StandingOn) para_vel = this->m_StandingOn->get_unit_parallel_vector() * this->mVelocity.x;
else para_vel = this->mVelocity;

[code].....

View 3 Replies View Related

C++ :: SFML 2.0 Pixel Perfect Collision

Oct 15, 2013

I have the code and it compiles fine but it doesn't work. (i am using the coding made easy sfml 2.0 tutorials)

Code:

#include <SFML/Graphics.hpp>
#include <iostream>
#include <algorithm>
#include <vector>
class Player {
public:
sf::Sprite player;

[Code] ....

View 18 Replies View Related

C++ :: SDL - Tile Based Collision Detection

Oct 14, 2014

I'm still working on my Project and the next Problem has occured: How do I detect collisions on a tilebased map? My tiles are 16x16 and the map is based on the tutorial of [URL] ..... I really like this Approach because I can define for each tile of what type it should be (so a earth tile can be walkable and lead to a secret passage).

The first Number stands for what Kind of tile it should be (e.g. Grass, Earth, Water, Blank,...) and the number after ":" stands for the type of the tile (e.g. solid, walkable, do dmg to the Player,...).

e.g.
0:0 0:0 0:0 0:0 0:0 //No tile and walkable
0:0 0:0 0:0 0:0 0:0
0:0 0:0 0:0 0:0 0:0
1:1 1:1 1:1 1:1 1:1 //Grass tile and solid
2:1 2:1 2:1 2:1 2:1 //Earth tile and solid

It's working just fine with loading the Images, but i've got no clue about the collision. I've already read a lot of stuff on the Internet but I don't get how to Combine it the structure from above. For example lazyfoo describes the collision with one object like one wall. So how can I check the Player Position with each tile?

For now there's no camera, but I plan to implement one later...

I'm trying to make a 2D platformer

View 5 Replies View Related

C++ :: Implementing Collision Detection Correctly

Sep 10, 2014

I'm making a 2D Terraria-like (side-scrolling RPG with destroyable blocks) game with SFML 2.1, and I have no clue how to correctly implement collision detection. Meaning that I have been successful at making it work, but it's not clean and definitely not dynamic.

By example, I mean design wise. What parameters should collision functions take? Where should these functions be located? The same 2 questions for collision reaction. Since I have multiple things that need to collide with each other (player with enemy, player with items, enemy with items, enemy with enemy, player with player, etc...), and the world has to be treated differently, things get complicated. There is no block class, just a vertex array, so collision with the world is based purely on coordinates taken from that array in the world class, which, considering it's the world and not something like a player or an enemy, doesn't inherit from the same base class that they do.

View 7 Replies View Related

Visual C++ :: Ceil Function Name Collision

Sep 29, 2014

Code:
cv::Size output_size
(gallerycols * 2 * its[0].cols(), ceil(4 / gallerycols) * 2 * its[0].rows());

Error18error C2668: 'ceil' : ambiguous call to overloaded functionE:JackyDownloadsvoronoivoronoi est_voronoi.cpp2071voronoi

I try to #include <cmath>

and use std::ceil to no avail

There are still function names clashing.

View 2 Replies View Related

C++ :: 2D Shooter - Collision Detection Design (Monsters And Bullets)

Jul 28, 2013

I have made a simple 2d shooter (bird eye view) and want implementing the collision detection between the monsters and bullets. The problem is as follows

Each monster has locationX, locationY as coordinates.
Each monster has a Rectangle representing its collision box, (if bullet inside rectangle then its a collision).
Each bullet has locationX, locationY as coordinates as well.

pretty standard up till now.

each frame I need to check if some bullet collided with some monster.

the brutal force is to keep a list of all the bullets and monsters and to check the possibility of collision between all of them which takes O(#bullets * #monsters).

View 2 Replies View Related

C :: Segmentation Fault At Free Call

Jul 7, 2014

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
/* h(a)=abcab,h(b)=acabcb,h(c)=acbcacb */
void h_i(int i, char *w, char *a, char *b, char *c)

[Code] .....

Above program increases string like this example.

Let say h(0)=01 and h(1)=10 and let say our first string is w=0 h(w)=01, h^2(w)=0110 h^3(w)=01101001..etc.

We have used h map, which is given in the program comment statement. Same thing, program is doing for three letters. These three letters we have passed as argument in h_i function. e.g. h_i(2,w,"a","d","g") function will apply the 3 letter map h(definition is given in commented form in program) 2 times on string w.

In program w=a; and three letters are a, d and g. /* h(a)=abcab,h(b)=acabcb,h(c)=acbcacb */ here b=d and c=g.

Above program gives core dump at free(w2) free(w1). if we remove these free statements then it gives correct answer. But, we want to free w1 and w2 in the above code. How can we make free both w1 and w2 strings?

View 4 Replies View Related

C :: Way To Free Unsigned Pointer Array In Best Way

Feb 24, 2013

how is the best way to free unsigned pointer array allocated with cmallc?

Code:

uint8_t *buf;
buf = cs_calloc(ca->len + 13);

i do like this , but i know this is not quite right , since i got compile warning passing argument 1 of ‘free’ makes pointer from integer without a cast

Code:

for (i = 0; i < ca->len + 13; i++)
{
free(buf[i]);
buf[i] = NULL;
}

free(buf); do i need to free each element of array like above?

View 6 Replies View Related

C :: Free A String Literal From Memory?

Jan 8, 2014

This compiles o.k.:

Code:

int main(void){
char *a;
a = (char*) malloc (100*sizeof(char));

[Code]....

I get an error saying "pointer being freed was not allocated". This happens for free(a), free(*a), free(&a), free(&*a).

So if I no longer need "1234567"... how do I get rid of this memory element?

View 7 Replies View Related

C :: Free Allocated Memory For Structure?

Mar 16, 2014

I'm trying to free allocated memory for structure. It seems like free() gets only pointer and not regular types . my question is basic and simple – is passing pointer to free() frees the pointer or the variable it points at? or both?

View 2 Replies View Related

C :: Detect CPU Usage And Free RAM On Windows X86 In C?

Feb 20, 2015

I don't use Visual Studio and/or C++ so I would like to do it without them. I found this article c++ - How to determine CPU and memory consumption from inside a process? - Stack Overflow

I tried some lines of code but no one works for me.

Code:

#include "windows.h"
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;

[Code]....

These was just my first tries to work with da MEMORYSTATUSEX.

I would like to find out if there is free memory at least ... (some value) and similar.

View 1 Replies View Related

C++ :: Printing Square Free Numbers?

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.

A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"

#include <iostream>
#include <vector>
using namespace std;

[Code]........

View 1 Replies View Related

C/C++ :: Printing Square Free Numbers

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.

The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.

A square-free number is a number that is not evenly divisible by the square of any prime number ....

#include <iostream>
#include <vector>
using namespace std;
bool noSquare (int num); //Function to determine if the number is square-free
vector<int> getPrimes(int num); //Function to get a vector of all primes below num
bool isPrime (int number); //Function to determine if individual numbers are prime
int main()

[Code]...

By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.

View 3 Replies View Related

C++ :: Member Variables On Stack Or Free Store?

Feb 18, 2014

I'm struggling with the whole stack/heap thing. I totally see the need to create objects on the free store to outlive functions, however, I don't see the purpose of "new" when working with classes.

Code:
class Person{
public:
Person(std::string strName, int number);
~Person(void);

Resource r;

[Code] .....

Now, what is the difference? Why would I need to create a Resource on the free store? Both variables named r live until the destructor runs, right?

View 1 Replies View Related

C :: Malloc Is Used To Allocate Free Memory To A Pointer

Nov 5, 2014

There is a part in the lesson that explains how malloc is used to allocate free memory to a pointer and gives us 2 examples:

Code:

float *ptr = malloc( sizeof(*ptr) ); and Code: float *ptr;
ptr = malloc( sizeof(*ptr) );

From my logic in the first case we allocate the memory to *ptr and in the second to ptr.

It's a bit confusing, am I missing something?

View 14 Replies View Related

C :: Free Not Working After Malloc Was Used To Allocate Memory

Jun 13, 2014

Consider this program:

Code:

// sb_string class v1.04

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct sb_string {

[Code] ....

And here is the output I got:

Code:
[harshvardhan@hari-rudra] ~/Desktop% gcc49 -o test test.c
[harshvardhan@hari-rudra] ~/Desktop% ./test
-before Value of len = 1
(in_function)-before Value of len = 1
(in_function)-after Value of len = 1

-after Value of len = 1 I was trying to make a little easier to work with string. Once the memory is allocated by malloc via sb_init() function, the sb_massacre function wasn't working to deallocate the memory. I had used multiple versions of gcc and clang but the result is same.

View 4 Replies View Related

C++ :: Free Up Memory In Client Server Program

Nov 22, 2013

How to free the memory and address,value

Server:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>

[Code] .....

Client:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>

[Code] .....

View 1 Replies View Related

Visual C++ :: Getting Free Disk Space Of Certain Directory?

Nov 23, 2014

Code:

_int64 free_space_64bit;
PULARGE_INTEGER lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes;
//char currentPath[MAX_PATH];
//GetCurrentDirectoryA(MAX_PATH, currentPath);
GetDiskFreeSpaceExA("H:C", lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
free_space_64bit = lpFreeBytesAvailable->HighPart << 32 | lpFreeBytesAvailable->LowPart;

This directory "H:C" does exist, if I comment out the GetDiskFreeSpaceExA line, the program doesn't crash, but it leads to some peculiar results (some uninitialized and random value, but at least it doesn't crash)

View 8 Replies View Related

C :: Eliminating Use Of Malloc / Free When Copying Char Arrays

Apr 6, 2014

This program works as expected:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
}

[code]....

But I don't like how I had to use malloc and free. Is there a different way to accomplish copying the string into a char pointer without resorting to dynamic memory allocation?

View 1 Replies View Related

C/C++ :: Implementation Of Stress Test For Lock Free Queue

Aug 31, 2014

I am trying to compare performance of different lock-free queues, therefore, I want to create a stress test - which includes pushing/popping user-defined pre-built objects to and from the queue. My question is how can perform the stress test with pushing and popping objects instead of pointers to object like I have done in my code. What is the different in terms of performance of pushing/popping objects Vs. pushing/popping pointers.

#include <cstdlib>
#include <stdio.h>
#include <string>

[Code]....

View 3 Replies View Related

C++ :: Using Malloc / Free Multiple Times Leaves Less Memory?

Apr 17, 2014

My application calls malloc in multiple subroutines, finally releasing all using free. This is done using my zalloc library (see my other post: [URL] .....

Somehow, when the applications tries to detect the available ammount of memory at the end of the test (allocating, freeing, testing), the freemem function gives me about 4-6MB less memory than at the start of the test? (out of 21MB available on the device at the start).

All memory is allocated and freed using the malloc/free routines within the library, with the exception of the SDL functions, which are registered externally on allocation and release.

View 3 Replies View Related

Visual C++ :: Free Image Library That Handle PNG Resolution

Mar 14, 2013

Need a free image library that can handle png xresolution and yresolution. I need it to be compatible with visual studio 6.0

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved