|
It's all in the "detecting". Collision detection involves enemies AND friendlies. Is the collision a "blocking" situation, or a "merge" in terms of hand to hand.
What you're refering to are "bugs": "trapped" sprites.
Regarding "group collisions": in the some "systems", any party "within a minute", is considered party to the "collision" / conflict; i.e. 100 yds for infantry, 300 yds for cavalry.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thanks for your comments Gerry
|
|
|
|
|
You're welcome!
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Code Segment (I) :
int dequeue() {
if (isFull(f)){
printf("Queue Underflow! Nothing
to Dequeue");
}
int dqd =f->data;
f = f->next;
return dqd;
}
Code Segment (II) :
int dequeue(){
int val=-1;
struct Node *ptr=f;
if(f==NULL){
printf("Empty\n");
}
else{
f=f->next;
val=ptr->data;
free(ptr);
return val;
}
}
In Code I, DeQueue operation is being carried out directly using front pointer.
In Code II, The same is happening but this time another Node pointer is created to store the front pointer.
So, What's is the Difference in these two methods!
|
|
|
|
|
Well...
The second one releases memory (while the first one does NOT relaase memory).
Moreover, in the first one, the
if (isFull(f)){ line looks suspicious.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Sir, first code doesn't actually need to free something as it is not creating a node to perform operation rather doing the same thing using the front pointer directly.
And yes I have wrote a function 'isFull' already
|
|
|
|
|
Quote: first code doesn't actually need to free something as it is not creating a node Neither the second one is. So the second code wrongly releases memory.
Quote: And yes I have wrote a function 'isFull' already But you should check for not-empty condition, with is NOT quite the same of is-full, is it?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
How is that possible sir! Second code is written by a renowned youtuber 'code_with_harry'. Okk, for your better understanding i'm pasting full source code here:
#include <stdio.h>
#include <stdlib.h>
struct Node *f = NULL;
struct Node *r = NULL;
struct Node{
int data;
struct Node *next;
};
void traversal(struct Node *f){
struct Node *ptr=f;
printf("------------\n");
while(ptr!=NULL){
printf("%d ",ptr->data);
ptr=ptr->next;
}
printf("\n------------\n");
}
int isEmpty(struct Node *f){
if (f == NULL){
return 1;
}
return 0;
}
int isFull(struct Node *f){
struct Node *n = (struct Node *)malloc(sizeof(struct Node));
if (n == NULL){
return 1;
}
return 0;
}
struct Node *enqueue(int val){
if (isFull(f)){
printf("Queue Overflow! Can't Enqueue %d\n", val);
return f;
}
else{
struct Node *n = (struct Node *)malloc(sizeof(struct Node));
n->data = val;
n->next = NULL;
if (isEmpty(f)){
f = r = n;
}
r->next = n;
r = n;
return f;
}
}
// int dequeue(){
// if (isFull(f)){
// printf("Queue Underflow! Nothing to Dequeue");
// }
// int dqd = f->data;
// f = f->next;
// return dqd;
// }
int dequeue(){
int val=-1;
struct Node *ptr=f;
if (f==NULL){
printf("Empty\n");
}
else{
f=f->next;
val=ptr->data;
free(ptr);
return val;
}
}
int main(){
enqueue(11);
enqueue(22);
enqueue(33);
enqueue(44);
traversal(f);
dequeue();
dequeue();
traversal(f);
return 0;
}
|
|
|
|
|
ZAID razvi wrote: Second code is written by a renowned youtuber
At least 90% of YouTube coding tutorial videos aren't worth the paper they're printed on.
And how do you know that this Harry is "renowned"? Is this something that other well-known, competent, and respected developers have said? Or is it an adjective he's applied to himself?
Either way, if the code doesn't work, there are two options: either you've made a mistake in copying it, or he made a mistake in writing it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay sir! Got your point, please calm down 😊
|
|
|
|
|
Quote: ouTube coding tutorial videos aren't worth the paper they're printed on.
Or the screen they are presented on.
Quote: either you've made a mistake in copying it, or he made a mistake in writing it Indeed, back to the drawing board.
|
|
|
|
|
Andre Oosthuizen wrote: Or the screen they are presented on.
That's the point - the screen they're presented on is worth much more than the paper they're (not) printed on.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ZAID razvi wrote: written by a renowned youtuber 'code_with_harry'.
Believe that and you will believe anything. And if that is an example of his output I would say he is renowned for writing poor code.
|
|
|
|
|
Harry is "renowned"? Prolific YouTube creator, maybe, but not renowned.
A 125 video series on "How to become a job ready programmer in 3 months"? BWAHAHAHAHA! That's bullshit, and everybody in this field knows it. He's got a sh*t-ton of self-promotion marketing, but that doesn't mean he can teach.
modified 30-Aug-23 9:59am.
|
|
|
|
|
Dave Kreskowiak wrote: that doesn't mean he can teach
Or even write code, from the sounds of it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Quote: How is that possible sir! Second code is written by a renowned youtuber 'code_with_harry'. I know. But here is renowed expert CPallini .
If you run Harry's code using Valgrind, then you get (something similar to)
==3144== LEAK SUMMARY:
==3144== definitely lost: 64 bytes in 4 blocks
==3144== indirectly lost: 0 bytes in 0 blocks
==3144== possibly lost: 0 bytes in 0 blocks
==3144== still reachable: 0 bytes in 0 blocks
==3144== suppressed: 0 bytes in 0 blocks
==3144==
==3144== For lists of detected and suppressed errors, rerun with: -s
==3144== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
On the other hand, if you run the following, alternative code
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int val;
struct Node * next;
};
void traversal(const struct Node * p)
{
printf("------------\n");
while (p)
{
printf("%d ",p->val);
p = p->next;
}
printf("\n------------\n");
}
struct Node * enqueue(struct Node *p, int val)
{
struct Node * prev = NULL;
while (p)
{
prev = p;
p = p->next;
}
p = malloc(sizeof(struct Node ));
if ( p )
{
p->val = val;
p->next = NULL;
if ( prev )
prev->next = p;
}
return p;
}
int dequeue(struct Node ** pp)
{
int val = -1;
struct Node * p = *pp;
if ( p )
{
val = p->val;
*pp = p->next;
free(p);
}
return val;
}
int main()
{
struct Node * ph = enqueue(NULL, 11);
enqueue(ph, 22);
enqueue(ph, 33);
enqueue(ph, 44);
traversal(ph);
dequeue(&ph);
dequeue(&ph);
traversal(ph);
dequeue(&ph);
dequeue(&ph);
return 0;
}
then Valgrind is somewhat happier:
==3153== HEAP SUMMARY:
==3153== in use at exit: 0 bytes in 0 blocks
==3153== total heap usage: 5 allocs, 5 frees, 1,088 bytes allocated
==3153==
==3153== All heap blocks were freed -- no leaks are possible
==3153==
==3153== For lists of detected and suppressed errors, rerun with: -s
==3153== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
|
|
Thanks for replying sir
The problem is solved
I'll let you know If encountered any other
|
|
|
|
|
The error message is clear: at the point the compiler encounters sizeof(struct Node) (or sizeof(nd) , or whatever...) it doesn't know the size, because the complete declaration of struct Node is missing.
You could post the relevant code, in order to get better help.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Still here
|
|
|
|
|
It's been a while...
Nice to see you again.
How do you do?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks sir it helped me alot
|
|
|
|
|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
in visual studio c++ / x64:
what are way safest to convert from:
1.INT_PTR to int?
2.LRESULT to BOOL?
3.LRESULT to int?
|
|
|
|