|
Do not repost questions, you have already posted the same question here, Class shape and related functions. If someone is active to answer your question, they will do it. If there is no one, reposting the question doesn't help at all.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
What kind of errors do you get ?
|
|
|
|
|
See Afzaal's reply above.
|
|
|
|
|
kumn1d wrote: This is the output I am supposed to get but I am getting errors please help me
What error? The compiler ones? - Then show us the errors.
Or you meant the incorrect output? - Then try to debug your code.
|
|
|
|
|
I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function .
I want to know how to implement anf declare this function . Beside that , I corrected the rest of code
|
|
|
|
|
There does not seem to be a Rectangle::printFourVertices() method. There is a redundant assignment operator in the Point::setX() method.
Short of that, what's the issue? "I am getting errors" is meaningless.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function .
I want to know how to implement anf declare this function . Beside that , I corrected the rest of code
|
|
|
|
|
How would you do it using pencil and paper? If you coded up everything that calculates said vertices, printing them should be a non-issue, yes?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello. It my first message here, I'll try to do it the right way.
The programming is my hobby (MinGW 32bit). About topic. I would like to represent my C++ code for buffer scroll. Perhaps I designing another bike, but still... What I mean about scrolling. For example, I have some buffer in which data starts somewhere in the middle:
char * buffer = "World!Hello, ";
But I need:
char * buffer = "Hello, World!";
So I need to cut out data at the end, move the rest of data to the end of buffer and paste cutted data to the beginning. This is "lossless buffer scrolling" of what I am talking about.
This is a trivial job if ones use temporary buffer not less than half of the *buffer's length, few memcpy() statements and so on. But this is not my case.
Condition 1. Source buffer size is very large (1/2 or 2/3 of total physical ram). So it is not good idea to allocate temporary buffer.
Condition 2. I can not use data storage like HDD drive. I can not use any kind of swap techniques. (It will produces temporary system freeses.)
Condition 3. I am not what to use virtual addressing techniques to virtually scroll buffer.
Condition 4. The buffer size and scroll distance is arbitrary (sets as function parameters).
So I created a scrolling buffer by permutation, which source code I would like to public. It is quite tested by brutte-force method (buffer size and scrolling distance were alternated, the result is compared with alternative scrolling techniques). In my opinion, the implementation of the method is unusual (or, at least, interesting).
Here it is:
namespace CommonTools
{
#ifdef DEBUG
uint32_t scroll_raw_buffer_last_rounds = 0;
#endif
void scroll_raw_buffer (void *data , const uint32_t buffer_size, uint32_t distance)
{
#ifdef DEBUG
scroll_raw_buffer_last_rounds = 0; #endif
if (buffer_size >= INT_MAX)
throw CommonTools::Errors::Simple (CommonTools::Errors::StE_Overflow, __PLACE__);
if ( (!data) || (buffer_size < 2)) return;
distance %= buffer_size;
if (!distance) return;
TRAP_in_DEBUG (distance >= buffer_size, msg_interror)
uint8_t *buf = (uint8_t *) data;
const uint32_t shift_value = distance;
#ifdef DEBUG
static const size_t max_stack_buffer = 256;
#else
static const size_t max_stack_buffer = 1024;
#endif
if (buffer_size <= max_stack_buffer)
{
uint8_t *tmp_buf = (uint8_t *) alloca (buffer_size);
memcpy (tmp_buf, buf, buffer_size);
memcpy (buf + shift_value, tmp_buf, buffer_size - shift_value);
memcpy (buf, tmp_buf + buffer_size - shift_value, shift_value);
return;
}
#ifdef DEBUG
scroll_raw_buffer_last_rounds = 1;
#endif
uint32_t bytes_left = buffer_size, bytes_per_round = 0;
uint32_t total_rounds = 0;
uint32_t round_number = 1; uint8_t *next_data_buffer = 0;
uint32_t dest_index;
#ifdef DEBUG
const uint8_t * const out_of_buffer = buf + buffer_size;
#endif
do {
{
const uint32_t round_start_offset = round_number - 1;
dest_index = round_start_offset;
if (dest_index >= buffer_size) dest_index -= buffer_size;
uint8_t next_data = buf[dest_index];
do
{
dest_index += shift_value; if (dest_index >= buffer_size) dest_index -= buffer_size;
register uint8_t &destination = buf [dest_index];
swap (destination, next_data);
bytes_left--;
}
while (dest_index != round_start_offset);
}
if (!bytes_left) break;
if (round_number == 1)
{
bytes_per_round = buffer_size - bytes_left;
total_rounds = buffer_size / bytes_per_round;
#ifdef DEBUG
scroll_raw_buffer_last_rounds = total_rounds;
#endif
TRAP_in_DEBUG (buffer_size % bytes_per_round, msg_bogus_state)
}
round_number++;
if (!next_data_buffer) next_data_buffer = (uint8_t *) alloca (max_stack_buffer);
for (;round_number < total_rounds;) {
const uint32_t rounds_left = total_rounds - round_number + 1;
const size_t block_size = min_ct (max_stack_buffer, rounds_left);
const uint32_t round_start_offset = round_number - 1;
dest_index = round_start_offset;
if (dest_index >= buffer_size) dest_index -= buffer_size;
TRAP_in_DEBUG (buf + dest_index + block_size >= out_of_buffer, msg_interror)
memcpy (next_data_buffer, buf + dest_index, block_size);
TRAP_in_DEBUG (bytes_left < bytes_per_round*block_size, msg_interror)
do {
dest_index += shift_value; if (dest_index >= buffer_size) dest_index -= buffer_size;
register uint8_t *destination = buf + dest_index;
memswap (destination, next_data_buffer, block_size);
} while (dest_index != round_start_offset);
bytes_left -= bytes_per_round * block_size;
round_number += block_size;
} } while (bytes_left > 0);
return;
}
}
Important notes:
1. If ones need negative direction you can use distance=buffer_size-1 as -1 direction.
2. swap() is just variables swapping, min_ct() function returns the minimum value from two arguments.
3. TRAP_in_DEBUG() or TRAP() are macroses to terminate program with message if first parameter is true (message is in 2nd parameter, like ASSERT() but little different way).
4. Function has size limit of scrolling buffer (up to INT_MAX, about 2 Gb in my case).
5. If someone would like to use this code, I will be pleasured if my name is mentioned somewhere in credits..
Echo7
modified 22-Jul-17 11:27am.
|
|
|
|
|
|
Quote: This looks more like a Tip than a question and would be better posted at Submit a new Article[^].
I'll do it, when I have read about rules.
Echo7
|
|
|
|
|
yes it belongs in tips but I also have a little tip for you.
memmove from the C/C++ standards library can deal with source and destination memory overlapping and it can do it with no extra buffers at all.
So you really only need the string search parts of your code and then use memmove to do the shuffle replacing the memcpy's
memmove[^]
memmove ensures that the original source bytes in the overlapping region are copied before being overwritten.
It was probably a good learning excercise and you can rate how you went against a standards library and here is the code
public source Implementation of memcopy[^]
It's never wasted time to learn the standards libraries
In vino veritas
modified 22-Jul-17 7:22am.
|
|
|
|
|
Quote: memmove from the C/C++ standards library can deal with source and destination memory overlapping and it can do it with no extra buffers at all
I know it. But I can not implement memmove() to my task. memmove() will ovewrite some part of my buffer (or I have to use temporary buffer to store that part) so I'll loose some data. Perhaps there is a way to use it, but I do not yet know how.
Quote: you really only need the string search parts of your code
char * buffer = "World!Hello, ";
It was only the small example to illustrate what I meaning under "buffer scrolling" term. In real code I have more that 100Mb binary (non-text) raw data which I have got from external device.
I do not know (in advance) the size, and I do not know the move distance.
Echo7
modified 22-Jul-17 11:21am.
|
|
|
|
|
SOCKETS - SERVER & CLIENT in c++ code for making a project on server & client site plzzz tell me
|
|
|
|
|
Use any boost or Qt libraries. They both offer networking capabilities for your applications, that you can use and build the apps that support networking features. Server and clients are just the applications that either take control of communication, or are guests. Network Examples | Qt Network 5.9 see this for examples on this. They might have something as a working sample, but you will still require some tweaks.
One thing, do not go onwards toward ACE framework — it is just painful, I am currently trying to get it to work and say hello, but it does not even work at all. If someone ever offers you the code, just away from it.
Qt | Cross-platform software development for embedded & desktop
Boost C++ Libraries
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Single Server With Multiple Clients : a Simple C++ Implementation[^]
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Read #2 here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi
I found the source of problem the exception occurred when I did CAsncSocket::Receive(CString*,int) I has previously done a GetBufferSetLength to a large enough size so I don't
understand why I got an exception
|
|
|
|
|
Check the documentation: CAsyncSocket::Receive[^]. The first parameter should be a pointer to a byte buffer, which CString* is not.
|
|
|
|
|
The CString class is not thread safe but using CAsyncSocket indicates that you are using multiple threads.
When using GetBuffer[Xxx] , the string object is locked until ReleaseBuffer is called (which must be called from the same thread).
As Richard already noted, you need a byte buffer. While this can be achieved by using CStringA , I recommend to rethink your design. Don't use string classes for binary data and ensure thread safety.
|
|
|
|
|
Are you to
CByteArray if so how can I ensure the size
|
|
|
|
|
You should just use a simple array of bytes, which is what the socket method requires.
|
|
|
|
|
You probably don't need an array class if you just want to copy data and do not need inserting or removing of items. If you know the (max.) size in advance just use a plain array allocated with new . If not, you can still grow by allocating a new array, copying data from the old, and delete the old.
CByteArray is also an MFC class which is probably also not thread safe. But it is impossible to help without knowing what your code is doing.
The question are (you may ask and solve them yourself):
Does my array require special modification functions besides copying?
Which functions use my array under which conditions (read only, write only, both)?
Where is may array allocated (this might be at different code points if resizing is necessary)?
Where it is deleted?
Do I need thread safety?
|
|
|
|
|
I'm reading this excellent book. I considered to use steering behavior in our MMORPG game server project.
but if we use it all,it would consume a lot of cpu time which would be unacceptable for a server project.
does any one have any experience on this topic?How could I find a proper way to use steering behavior in MMORPG server?
Thank you very much.
|
|
|
|
|
You write the search algorthim as an iteration, with adjustable resolution and trigger(s).
If two objects are more than X apart the search doesn't run at all unless there is a special trigger. If you haven't been "spotted" there is no need for an enemy to search and so they usually just walk a defined set of waypoints called "pathing".
So movement especially for NPC's or bots usually have two different behaviours being "pathing" and "searching". Often there is also a way to get "unspotted" and NPC's/BOTs may be leashed to some co-ordinate. If they get more than some distance from the leash point they will drop "seaching" behaviour and resume "pathing".
The trigger whatever that is usually establishes the "target" and it is at that point the search AI kicks in. The game design thus far made sure searching is used sparingly.
Now when the search algorthim kicks in, it sets a resolution grid based upon how far the target is away. You don't need a fine grid for a target far away. So you will have a raycast which you run to each point on the grid. So when target is a long way away you still only get a small grid just they represent a big distance. That is the bit your code you currently have probably doesn't do and so you have a huge grid when the target is a long way away.
So now with your grid you run the AI search algorthim to work out what direction to move to the target allowing for walls etc. If the target is a long way away the direction will only be rough but that is all it needs it will fine up as it gets closer.
The problem you probably have with the AI search they have given you is the grid is massive and it gets bigger and bigger the further a target is away.
That would be how the vast majority of games not just MMORPG games work. Suggested start point for reading
Near-Optimal Hierarchical Pathfinding (HPA*) | AiGameDev.com[^]
In vino veritas
modified 20-Jul-17 3:34am.
|
|
|
|