Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 Jun 2001
Offline Last Active Yesterday, 01:18 PM

#5298545 Sharing object between 2 threads

Posted by BeerNutts on 29 June 2016 - 12:21 PM

Thanks for all the good answers. I realize that the better approach would be to use the same data structure in both threads, while having different classes.

What I am actually trying to do is:


The main thread handles the game logic and works on the resources (reading/writing them). The auxiliary thread handles the display only, reading only from the resources.


I want at a later point to be able to either have the render thread:


1. either read from the original data while the game logic thread waits (thus avoiding copying the resources at all).

2. either read from a copy of the original data, while the game logic continues its work.


In case 2 above, copying the resources will be done as a light copy first (i.e. actually sharing the resource until the point where the main thread modifies it: in that case, the main thread will first deep-copy the resource before modifying it, while the render thread will still read from the old, unmodified resource, thus avoiding a crash).

Why do you have a separate thread for Rendering? Is the Rendering phase a bottleneck in your program?  What happens if you simply render all your object within the main game loop?


Basically, are you sure what you're doing is worth the trouble?  Multithreaded programming can be difficult to do correctly, and if you miss 1 thing, you'll start having odd bugs that are very hard to debug.  Be sure you really need to do it before trying to do it.


If it's as an exercise, then disregard, but if it's a solution to a bigger problem (like making a game), then I'd re-evaluate and ensure it's really needed.


FWIW, in my hobby games I've written, I've never seen the need for more than 1 thread.  Some big games will need more, but they have to have good reasons for them.

#5298536 PowerUp stuck

Posted by BeerNutts on 29 June 2016 - 10:16 AM

Maybe, instead of having an index stored in the power up, you have the actual type stored and duration, and there's no need for an if in your loop.  You can also update before checking collision to also condense it.  Something  Like this:


            for(int i = 0; i < PowerUpses.Count; i++)
                if (PowerUpses[i].PowerUpPaddleCollision(paddle))
                    paddle.pickPowerUp(PowerUpses[i].Type, PowerUpses[i].Duration);

#5296810 Peer-to-peer Massive Multiplayer Game

Posted by BeerNutts on 16 June 2016 - 07:53 AM

Also this whole peer-to-peer architecture would at most take me one day to write up, so it's really not that big of a deal.


MAYBE the initial structure you think will work will take a day.  Then, when you start to use it, you'll run into an issue.  then, when you get more users, you'll get more issues.  Then, when you have a lot of players, you'll be running into different issues all the time, all related to trying to use peer-to-peer, and you're time will be dedicated 100% to trying to find a solution for all the problems.  You'll fix one problem, and another will arise, all the while, you'll be hearing about cheaters doing this or that.


Obviously, with any networking solution you select you're going to have some amount of debugging you're going to run into, but, if you're trying to do peer-to-peer with any sort of game that requires sub-second communications amongst all the players, it's going to be 1000x worse.


With that said, if you're still going to write this peer-to-peer framework, I truly hope it does well, and you can come back with a synopsis of it and we can all learn from it.

#5296656 Peer-to-peer Massive Multiplayer Game

Posted by BeerNutts on 15 June 2016 - 08:42 AM

Wow, you're doing all this extra complex work just to

benefit of not having to purchase a dedicated server.

And, this is for a game with 50-100 players.  I think this is like a case of cutting off your nose to spite your face.  IMO, you're going to go through so much heart-ache, you'll be wishing you had spent a little money for that dedicated server.

#5296492 How to make spot lights in darkness for 2D games

Posted by BeerNutts on 14 June 2016 - 09:40 AM

For SFML, Let there be Light 2


A really good lighting system for 2d games, but it relies on SFML.

#5295493 Can't Get Bullets to Shoot

Posted by BeerNutts on 07 June 2016 - 07:47 AM

Now I just need to make it so that the bullet fires from the player and not from the left side of the screen.

You'll want to set the bullet's rectangle X to the player's X position on initial creation.


I'd also suggest removing the  X, Y, Width, and Height variables in the Bullet struct since all of those values are repeated in the Rect Variable.


Also, you might want to look into creating a vector of bullets, so you can have more than 1 bullet at a time, but that's obviously gameplay specific.  And, instead of using a timer to kill the bullet, remove it when it either leaves the view-able screen, or it has collided with an enemy.


Good luck and have fun!

#5293060 Kinda hard to explain this

Posted by BeerNutts on 23 May 2016 - 09:14 AM

Also, this is wrong:

    item_holder = input(subcores_prompt)
    if item_holder in subcores:
        print("This isn't an item, sorry.")
        active = 0
    if add_item_active == 1:


You're setting active to 0, you need to be setting add_item_active = 0


Good luck, and keep working at it!

#5292497 Best Programming Language for Simple Multiplayer Sport Simulation Game

Posted by BeerNutts on 19 May 2016 - 09:01 AM

Javascript/html5 isn't a bad (look into phaser.io) but python would be a good solutoin too.


Realize, you'll need 2 sides to this: a client (javascript/html5 would be good for this) and a server (javascript woudl not be good IMO, but python would).


IMO, since you'll need to write both sides, I'd just do them both in python.


Good luck and have fun!

#5292102 Any Mentors Out There?

Posted by BeerNutts on 17 May 2016 - 12:11 PM

The only difficulty that could be faced by a "whole forum of mentors" is each mentor might have a slightly different perspective on things, and everyone of them could be a good way to do things, but they are different.That could often be confusing for a begineer.


Whereas, with a single mentor, he will lead him down one specific path.  Hopefully it is a good path, but it will be a single path that he believes in, and without the confusion of the specific direction to take.

#5290990 I aspire to be an app developer

Posted by BeerNutts on 10 May 2016 - 10:52 AM

Just because you know how to program, and even if you're very good at it and know most of the ins and outs of game programming, doesn't mean you'll be able to make a living with "going commercial with any games i create".  There's a HUGE difference between knowing how to write games, and creating a good game that makes a sizable amount of money.


I'm not telling you this to get you down; rather, you might want to think about finding a career working for a company (making games if you can, else a typical programming job), and maybe work on your game making on the side.  Assuming you'll be able to make a living making games by yourself isn't a good long term plan (especially since you've just started learning to program).


Either way, good luck, and have fun.

#5287498 How did you learn making games?

Posted by BeerNutts on 18 April 2016 - 12:15 PM

They were popular in much of the US as well in the peak time frame, from 1990-1995, hitting a sudden drop-off with the invention and popularization of the World Wide Web.


For many of us (including me) the BBS was my preferred way to access Usenet groups, since paid access to a BBS that processed subjects I was interested in was far cheaper than access to the school's SLIP services as a non-student.



Haven't heard anyone mention SLIP in a long time, we used to use slurp over our terminals to access the internet and browse the web with graphics using Mosaic!  It sure beat Lynx text browser, although the text browser was great for looking up fantasy football stats :)


I suppose I should answer the questions here too:


I 1st programmed BASIC on an Apple IIe, 5th grade, probably 1986, and I made text adventure games.  I never truly "learned the language" I only learned the parts of the language needed to make text games, but, considering it was simple input and if/then mechanisms, it didn't take too long.


No, I didn't upload any of those early games anywhere, and games I'm made more recently have mostly been just for me, or I've shared wqith a few friends as a hobby.


Occasionally, I'll get the urge to dabble with game making, but it's not as often any more, and if I do, again, it's just for fun as a hobby.

#5287495 Memory Allocation

Posted by BeerNutts on 18 April 2016 - 12:03 PM

 sizeof(struct Node *) <- isn't this wrong??


for a node you should allocate sizeof(struct node) otherwise you allocate only pointer size space (4 or 8 bytes?)


Yes, this is the problem, you should be calling malloc(sizeof(struct Node)) .


However, you can make life easier using new and delete, like this

// in push()
Node* temp = new Node;
// later, in pop()
delete temp;


And, I just noticed, in pop(), why are you calling malloc() on temp again, then immediately assigning temp to headNode?  Don't malloc temp in pop().


You need to understand memory allocation a little more, then you should be able to tackle this problem fine.

#5286913 Data Structures Help!

Posted by BeerNutts on 14 April 2016 - 01:59 PM

A few things:

#0, you really should've started a new thread for this.


#1, there's a major leak since you call malloc() every time push is called, you need to have a cooresponding call to free() when you pop or pop_all.  My suggesiton is to make pop() such that it calls free() on the node being deleted, and then, in pop_all, just call pop() until isEmpty() is true.


#2, you shouldn't have Queue as an include file (.inl).  Just make it a separate .cpp file and include it when compiling.


#3, it's bad practice to have a single include file (LibIncludes.h) which includes all the include files you need.  Just include the files the current file needs to operate properly on it's own.


#4, the Queue class should only be responsible for handling the data for insertion and retrieval, it should not be printing as well; rather, retreive the data from the Queue class, and print the results in the main class (or make a separate class call QueuePrint if you so desire).  Right now your Queue class is useless as an actual Queue.  it simply prints the data it has, a user can't use it at all to add and retreive items for use.


Just a few thoughts I had.


good luck!

#5285616 Data Structures Help!

Posted by BeerNutts on 07 April 2016 - 12:45 PM

You must have changed something else, but isn't this a problem too:

  linkedList.data = null;

You're assign null to an unknown data type.  It will probably work for all types, but it's not good programming.


and this

  headNode = linkedList;

headNode is a pointer to a node, while linkedList is a node.  That shouldn't compile. I suppose this would work though:

  headNode = &linkedList;

#5285484 how we do a collision?

Posted by BeerNutts on 06 April 2016 - 02:42 PM

Spatial hashing:

See here and here