Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Khatharr

Member Since 24 Apr 2010
Offline Last Active Private

#5038359 Inline assembly

Posted by Khatharr on 02 March 2013 - 04:33 AM

Dynamically allocated. I actually allocated a huge buffer, then calculated the amount of it to use for data and the part to use for the bytecode that would manipulate said data. Insane laughter ensued.

Could have been DEP. I've upgraded my OS since then, so I can't check to see what the setting was.


#5038355 Late night coding

Posted by Khatharr on 02 March 2013 - 04:11 AM

May years ago when I was still young and handsome I'd literally stay up for days on end continually manufacturing and consuming iced tea and writing Ruby scripts for RPG Maker. Toward the end of the consciousness curve I'd generate some really really scary stuff that would actually run correctly. I'd end up passing out at the desk and after convalescence I'd look at the gibberish I'd written and not be able to understand how it worked.


#5037868 How many draw calls per frame are possible without awful performance?

Posted by Khatharr on 28 February 2013 - 08:48 PM

Rather than optimizing your entire code base over the course of 3 months and then finding out that it was some esoteric compiler option why not just run a profiler?


#5037117 Multithreaded programming

Posted by Khatharr on 27 February 2013 - 06:35 AM

Natpick: Hyperspatial computing can provide the results of concurrent operations prior to program start.


#5037009 score change effect

Posted by Khatharr on 26 February 2013 - 11:16 PM

I've always like morphing number animations. You can to create a pre-rendered animation sequence for every possible transition. If you realize that you can play an animation either forward or backward then you can get the number of required animation sequences down to 45. It takes a bit of coding and graphics effort to get it to work properly, but once it's done it's very light-wieght in terms of rendering.


#5037006 Creating a level editor alongside the game, how to apply it?

Posted by Khatharr on 26 February 2013 - 11:09 PM

How "close" to the game code should the editor code be?

Identical. Ideally they'd both use the same dll or else your notion of including the editor in the game is also a good option. Personally I prefer external editors unless I plan to include the editor as a user feature, but that's just me. If you're using the same models in the game and the editor, though, just use the same graphics code. If your implementation is properly abstracted you should be able to pull the graphics code out with minimal fuss and build the editor around it.

Alternatively, if you have found a good editor somewhere that will work for your game then you'd save yourself time by just abandoning the WYSIWYG preference and using the existing editor. It's something you'd have to weigh against the limitations it would impose on you.


#5036518 Multithreaded programming

Posted by Khatharr on 25 February 2013 - 06:03 PM

alnite, on 25 Feb 2013 - 15:21, said:
As people have said, multithreading needs to be threaded carefully (pun intended).

If you truly want to learn it, here's a fun thing you can do: make an audio player. With SDL/SFML or whatever GUI lib you decide to use, create a Load, Play, Pause, Stop buttons. Then there should be an audio playing in the background. Try playing a really big audio file (100MB WAVs), without loading it all up at once. Playing audio must be done on a separate thread. Load/Play/Pause/Stop buttons must be able to signal that thread appropriately, and the audio thread must signal back to the main thread.

That's actually what I was going to suggest. +1

Before you get into that bundle of fun, though, you should probably just sit down and play with making small threaded programs that don't do much of anything, like looping counters and the like. Understand what mutexes and critical sections and such do and how to use them. Understand how to terminate a thread from within itself or from another thread. Get familiar with the functionality of your chosen thread-lib basically.


#5036420 Get unique IDs by reading the Instruction Pointer Register

Posted by Khatharr on 25 February 2013 - 01:36 PM

http://en.wikipedia.org/wiki/KISS_principle


#5034836 Creating an MMORPG - Connecting/Opening Ports?

Posted by Khatharr on 20 February 2013 - 08:31 PM

As for which ports are firewalled, any or all of them could be. Really you just have to pick an arbitrary number (above 1024, preferably) and let the client know which one it is.

This is the accepted method. Port numbers lower than 1024 are 'reserved' for specific purposes. In terms of programming and socket access this means almost nothing. You can use those port numbers just like any other. It just means that when people see those numbers they may expect the associated service on that port, so typically you want to use one that's not in the reserved range. Port numbers are 16 bits and unsigned. The maximum value is typically not used, so any number between 1024 and 65534 is available to you.

You may want to look into WireShark if you're working with networking. It will let you peek at what's actually going over the wire.




#5034430 [C++] Snake movement problem

Posted by Khatharr on 20 February 2013 - 12:39 AM

As to a the Node's, what do you mean a payload? To hold what sort of information, the coordinates and things like that? How would it retrieve it - I'm sorry just a tad confused about it. I'll try to puzzle it out, like I said brain isn't working.
And I've never done a doubly linked list, just single. Hence further confusion.

A dequeue is the STL version of a doubly linked list. It can be traversed in either direction. The payload is simply a pointer to whatever you want to store, organized into a struct or class. Whatever information a segment needs, make a struct to hold it all, then create an instance of that to act as the payload for a new node. For instance, if you're storing an x coordinate in your payload you could refer to it as node->payload->x.

And in your instance, the snake will grow from the inside out ( inserting in the middle ) ?

The head and tail are 'bookend' nodes. They do not store payloads, they only serve as entry points to the list stored between them.
struct SnakeNode {
  SnakeNode *prev;
  SnakeNode *next;
  SnakeSegment* segment; //this is the payload
}
SnakeNode root_node; //using stack objects will give you an error to alert you if you do something wrong and delete a bookend.
SnakeNode tail_node;

Most of my confusion was how to correctly pass the head's( or root ) coordinates to the rest of the list, and the tail knowing where it was in order to delete behind it AND either save the node next to last or save the coordinates for where the head turns.

You may want to simply unlink the last node and insert it to the front of the list and change its coordinates. If your snake segments are interchangeable this will save you some fiddly work.

Also yes, Grid is the class that draws the board - it isn't an error in the drawing. ( Also fyi, the snake starts off with 3 nodes, first move to the left it's still 3, second move to the left it starts growing, etc )

Hmm... Have you run it through the debugger to see what's happening differently on in the second movement?


#5034079 Issues with animating for a durating, relative to game loops?

Posted by Khatharr on 19 February 2013 - 02:44 AM

This is just a fixed timestep as described in L.Spiro's article. If you want simplicity in this case then just don't implement graphics interpolation and do all your motion interpolation in the simulation as was discussed. In other words, draw as often as you like, but update the logic at a fixed rate. Something like:
 
loop {
  prev_time = now
  now = get_current_time() //use a high performance timer for this
  elapsed_time += (prev_time - now)
  if(elapsed_time < FRAME_DURATION) {
    //this branch will reduce your cpu usage if you're running fast
    yield_to_thread_scheduler() //on windows this function is 'SwitchToThread()'
    continue //as in return to start of 'loop'
  }
  while(elapsed_time >= FRAME_DURATION) {
    //this loop will catch you up if you're running slow
    update_logic() //process one logical frame
    elapsed_time -= FRAME_DURATION
  }
  //note that elapsed_time may be non-zero at this point. the excess will carry into the next iteration of 'loop'
  render()
}



#5034073 Collision detection

Posted by Khatharr on 19 February 2013 - 02:24 AM

Glad it's working. A few issues, though.

 

Do not do this:

 

if(condition) {
  //do nothing
}
else {
  //do something
}

 

Do this:

 

if(condition == false) {
  //do something
}

 

Also, why are you testing every which case except the one you're actually looking for?

 

    for(int row = 0; row < 4; row++) {
      for(int col = 0; col < 4; col++) {
        if((shape[row][col] == 1) && (board[x+row][y+col] == 1)) {
          return false;
        }
      }
    }
    return true;

Also, the x axis travels left and right. The y axis travels up and down. In this function you've inverted them. This won't cause a bug since the inversion is universal in the scope of the variables, but it can confuse people coming into the function and may lead them to do something incorrect since the variable names are misleading.




#5033192 Collision detection

Posted by Khatharr on 16 February 2013 - 06:21 PM

Define current x by x argument. Define current y by y argument. Define j and k as zero. If piece [j,k] is occupied and board [x,y] is occupied then collision occurred. Otherwise increase x and j by one. If j is equal to four then subtract four from j and x and increase y and k by one. If k is equal to four then the process is complete and no collision occurred. Otherwise continue testing.

Your code uses this 'Grid' class for pieces and boards. If you can add grids or extract grid sections then you could copy the board data, add the piece values to it, then check for any value '2' indicating collision. Is this a Java class or one of your own?


#5032950 Issues with animating for a durating, relative to game loops?

Posted by Khatharr on 16 February 2013 - 03:00 AM

If you're basing on time then you need to use time instead of frames as your metric for the fraction in the interpolation. For tiled 2D RPGs you can get usually away with just v-syncing and per-pixel movement, though I may get yelled at for saying that.

In the case you'd want to decide how many milliseconds you want it to take to walk one tile and then:

start process:
motion_end_time = now + TIME_IT_TAKES_TO_WALK_ONE_FRAME;
is_moving = true;
then have:
if(is_moving) {
  if(now > motion_end_time) {
    position = destination_position;
    is_moving = false;
  }
  else {
    time_elapsed = motion_end_time - now;
    motion_completion_fraction = time_elapsed / TIME_IT_TAKES_TO_WALK_ONE_FRAME;
    position = start_position + (PIXELS_PER_TILE * motion_completion_fraction);
  }
}
If you're basing it off a timer don't reset the timer. At the start of the logical frame (the 'logical frame' being a single 'tick' of your simulation, not an animation frame) get the current time, subtract the previous frame's time from it and use that as your elapsed time for everything that gets updated in the frame. Definitely do not allow things within the logical frame to do this independently or you'll lose sync between your entities and get weird behavior, since they'll all have different values for elapsed time.

In other words, if you have 3 things that need updated:

Do:
get elapsed time
pass it to thing1's update
pass it to thing2's update
pass it to thing3's update
[everything is synchronized]

Do not:
update thing1 (thing1 determines elapsed time)
update thing2 (thing2 determines elapsed time)
update thing3 (thing3 determines elapsed time)
[time passes while things update - synchronization was lost!]


#5032558 Issues with animating for a durating, relative to game loops?

Posted by Khatharr on 15 February 2013 - 04:16 AM

Those functions are placing the sprite in the location of the destination tile. Whatever you have that determines where a specific tile position is on the screen, those functions should return a pixel x/y in terms of the screen based on the map tile x/y passed in. Immediately after that the sprite gets placed in this position it gets 'backed up' to its interpolated position between the destination tile and the origin tile.

FRAMES_FOR_SINGLE_TILE_MOTION would be the 'duration' that Spiro was telling you about. The number of frames it takes to walk from one tile to the next.

STEPPING_FRAME_DISTANCE would be the number of pixels traveled in one frame.

So if you had 32-pixel wide tiles and you want to make the trip in 8 frames then FRAMES_FOR_SINGLE_TILE_MOTION would be 8 and STEPPING_FRAME_DISTANCE would be 4, which is 32 divided by 8.

So say you're on a tile and you start a move to the left.
Your tile position gets changed and:
pendingMotionFrames = FRAMES_FOR_SINGLE_TILE_MOTION; //8
The sprite facing gets changed (which is not in the code) but the sprite is not moved yet.

Next frame:
pendingMotionFrames is reduced to 7
int positionOffset = pendingMotionFrames * STEPPING_FRAME_DISTANCE; //7 * 4 = 28
sprite gets moved to the target tile, it's facing is still leftwards
since it's facing leftwards sprite.x -= positionOffset, so the sprite gets moved back by 28 pixels. It's effectively moved 4 pixels from its starting tile.

The next frame pendingMotionFrames is reduced to 6, so positionOffset will be 24. The sprite gets put on the destination tile and then moved backwards 24 pixels. It now appears to have moved 8 pixels.

This repeats until pendingMotionFrames gets set to zero. The sprite will get placed on the destination tile, but positionOffset will be zero, so it will stay put there and the movement is complete.

This is just a different way of implementing the same interpolation Spiro-sama was telling you about. She's discussing it in a more general sense. The method I'm talking about is specific to the type of game you're working on. You should really look into what she's talking about and learn the general case, then try to see how that's implemented in what I'm talking about.




PARTNERS