Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Mar 2005
Online Last Active Today, 08:26 PM

#5300757 How To Write Resource Manager

Posted by frob on 14 July 2016 - 11:42 AM

Typically "manager" is evidence of a bad design. Every class should have a single responsibility. "Manage" is not a single responsibility.

In bigger games these are typically implemented with four primary classes: xxStore, xxProxy, xxCache, xxLoader. xx is whatever thing you are working with. The Store represents all the objects. You request one and are given back a Proxy. A Proxy might contain the fully loaded object, or it might contain a different placeholder object. The Cache is a collection of objects currently loaded. The Loader finds resources that people want to use but are not loaded, and loads them up, then updates the proxy to switch out to the real loaded module. You'll probably reach the point where you need to load more things but can't, so you swap them out of the proxy to unload it and replace it with the placeholder, then dump the unused item from the cache.

#5300754 Copyright

Posted by frob on 14 July 2016 - 11:35 AM

That is not my intention as I said I wont use anything

You don't have to use the elements directly, even indirect use is enough to get in trouble for various forms of IP infringement.

In the opening post of the discussion you wrote:

I have recently come to an idea that I make movie based on video game.

Because it is based on another product many IP laws apply that say you need permission. No matter how loose the connection is, if you admit it is based on another product then yours is a derivative.

There is a more difficult area, where you claim you didn't know about the other stuff or didn't base your work on theirs, then the other group has to convince a judge that you really did. But that doesn't apply here. You readily admit in your first post that you want to make a derivative work. Therefore, you need permission.

Games Workshop is not going to give you permission to work with their brand without a truckload of money and some ironclad contracts. That brand represents most of their company value, they protect it vigorously.

#5300595 Copyright

Posted by frob on 13 July 2016 - 02:06 PM

It is fine to make a game about orcs.  Just don't make them Tolkien Orcs, or Warcraft Orcs, or Warhammer Orcs or Game Of Thrones Orcs, or Elder Scrolls Orcs.


Generic muscled green ugly creature is fine. 


But the moment you steal names of people or places or things from a book or movie or game, or steal plot lines, or steal world elements, or anything AT ALL that is recognizable, you've got a derivative work.


In the music world, after one famous composition of silence all the people who used extended silence were shut down on copyright claims.  Music has been shut down for using just three chords in a specific progression.

Books have had their ownership revoked and rights (and money) transferred because judges felt they were too similar to another work and were derivative.


The professional games world usually settles before judgement, but there have been game developers that have been sued for infringement which ended up destroying studios. 



Don't be lazy about it. Don't use other people's stuff.  Be creative and make something UNIQUELY your own.  Don't base it on anyone else's story, that's their story. Don't base it on someone else's games. Don't base it on their worlds, that is theirs.  Make your own story, make your own worlds, make your own games. 

#5300593 Making an object move back and forth.

Posted by frob on 13 July 2016 - 01:54 PM

frob question:
 what is the industry term used among software developers on how to break down a game development into steps and objectives like that. I'm looking for some books on the topic. thanks

There is the term I linked to: rubber duck debugging.

If you can explain all the steps to a rubber duck, step by step, line by line, and make sure the rubber duck understands it, then you can probably find a way to make the computer understand, too.

You've just got to break down the problems into smaller and smaller pieces until they are pieces you can handle.  There is a name for that sort of thing, too: divide and conquer.  Break the problem down smaller and smaller until you are able to solve every part.




Whatever you end up calling it, that is the set of steps you need to follow. I described two different ways to figure out the motion. Personally I prefer the direct numerical approach of finding the portion of the interval that is complete and then solving for it's position along the path. It is less prone to numeric errors and drift over time, and less subject to skips in time processing delays.



#5300569 c++: replace word in char array?

Posted by frob on 13 July 2016 - 10:50 AM

That's a neat little homework project with all kinds of fun potential 'gotcha' elements.

Fixed buffer lengths, expansion/contraction of data, and steps that can break each other. Forbidding you from using existing libraries for string management or regex replacement makes it even more fun.

I approve of your teacher. I hope they test with names like X1 becomes MOOD, then replace MOOD to whatever, or replace with a name like aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. There are several good real-world issues that could be taught with that example.

#5300559 Copyright

Posted by frob on 13 July 2016 - 10:01 AM

About a game company- there are three of them: THQ Relic Games workshop And THQ ownes the EULA Games workshop has made the game. You may gues what game I am talking about. So what company should I ask for permission?

Ah.  No, you will not be getting permission to make a Warhammer 40,000 clone.


If you try it without permission, you will get your online content taken down. (Search for "Warhammer 40K takedown notice" for all kinds of stories where people hate that their fan content was removed by legal action.)


As Kylotan wrote, you will not get permission for this property on your own.   If you were representing a multinational game development company with a few billion dollars in assets then MAYBE you might be able to negotiate permission for the company to build those products.  That permission would come with a multi-million dollar price tag (you paying them) and several major contracts.



The companies involved vigorously protect their products. You can expect to get a Cease and Desist order and other legal demands the moment they learn it is available.

Don't go there. Be creative and do something new.

#5300490 C++ Book to revise my Knowledge

Posted by frob on 13 July 2016 - 03:42 AM

I disagree with the Stroustrup book. Back in the 1980s his was the only book on the language, so that was all there was. He hasn't been at the helm of the language for two decades, it grew far beyond any individual many years ago. These days his books are interesting for historical notes, but there are more effective teachers out there.

For dead-tree books, Meyer's "Effective Modern C++" is fairly good if you are planning on picking up the big things that changed. Beyond that, a bit of web searches for conference presentations and training material that can educate you on the key useful tidbits.

If you're looking for a particularly in-depth dive, more like an academic course on all the corners and edges, The C++ Standard Library by Josuttis -- the second edition which was updated to C++11 standard -- will get into the nuts and bolts of the language library and covers good chunks of the core features as well.

I haven't read it yet but I've heard Discovering Modern C++ by Peter Gottschling is also fairly good for a more modern resource if you've already got some background.

And finally, if this is just dabbling and you don't care about waiting another year, the language standard is being finalized for the 2017 major update. A new round of books will come out starting in the middle of next year once the final draft gets ratified.

#5300423 Is it ok for a component to expect a gameobject to have certain properties?

Posted by frob on 12 July 2016 - 01:00 PM

As this is For Beginners...


Yes, it is reasonable for you to expect that your code implements specific features.  You can set your own expectations as long as you follow them.


In larger projects the team determines what those expectations are, and team members are expected to ensure their code meets the expectations. Sometimes those expectations are enforced by code, where the code won't compile.  Other times they are enforced by tools that scan the code. Other times they are enforced by code reviews and humans, with the expected occasional human error.


The policies the other posts talk about are good ideas to think about, and each policy comes with its own set of pros and cons. Exactly what you choose and why you choose it may vary from project to project and from team to team. 


In this example of your own code, where you write that you know the only things it will hit have both an "equipped_item" and a "direction" property, then because it is your code you can make that expectation.


As a general rule you should test for existence of the object before using the object.  In this case it might be a simple guard like:  if(gameObject != null && gameObject.equipedItem != null && ...) {...}  That type of guard in front, the tests against null, will verify that it actually exists before you start using it.  

On the other hand, you might want code that crashes or breaks visibly when an object is null.  If it is something that is always expected you will want debug builds to throw up all kinds of warning messages so programmers will fix the bug. 

#5300421 Posibility of getting to game industry?

Posted by frob on 12 July 2016 - 12:50 PM

Bringing out a point that has been touched on by a few people, "the industry" is a big place and there are many needs. 


While many game studios expect programmers have a working knowledge of C++, and jobs where programmers need an expert knowledge of C++, there are jobs and positions where it less necessary or even unnecessary.  Some studios rely heavily on Java, or C#, or JavaScript, or other languages.


I recommend programmers attempt to learn at least one programming language every year.  The languages C++, Java, C#, JavaScript, and Python are currently the standard set of languages for professional work. Fortunately once you are comfortable with programming, picking up another language in the set is not particularly difficult. 


If you know how to program in a game-related language you can still apply to jobs in your area. Learn about what they need, and if you've got those skills you might get the job.  But recall that you don't exist in a vacuum, and if they look better on paper or show better in the interview they will be selected instead of you.  But if you're one of a small number of applicants you may get the job.  


While there are many people who work in the depths of game engines and C++ code, there are also programmers who never touch C++ code year after year. Don't give up hope, just be mindful of the jobs you apply for. 

#5300407 Division of labor: managing an artist as a buisness partner?

Posted by frob on 12 July 2016 - 11:32 AM

Should I be offended if he refuses to sign a contributor agreement, with my name as "the company"?


Unless you are starting a company with your name as the company, no.


You absolutely should talk to him.  


You absolute should get a legal structure in place


You absolutely should assign all work everyone does to the legal structure.



If you don't have a proper assignment of rights then each person independently owns their own contributions, and the group does not own any of the contributions.  That means you can only use the product as long as every individual agrees to use the product that way.


Without those agreements in place, if any person EVER leaves the group the project is tainted. If any person EVER wants their stuff removed, the project is tainted.  If any person EVER dies or becomes incapacitated then their estate, spouse, parents, or someone must also agree to all future use.  There is no good way to remove their content since it is likely fully integrated.   

Without those agreements in place you will not be able to get a proper publisher. You will not be able to get a proper distributor.  You will not be able to sell the product to a company. 


In short, without those agreements in place your product is legally tainted, it is a piece of poison no sane company will want to touch.


You, or someone else in your collaborative group, needs to ensure the legal side of the project is taken care of.


In order to do that without offending people too badly, you need to actually talk to people and get their agreement.

#5300403 The big face-off between inheritance/interfacing

Posted by frob on 12 July 2016 - 11:20 AM

So with programming conventions side, is it about operating on the upper layer rather than inside the class to an extent?

Yes, that is the intent.  Work with a system, work with abstractions, work with the base classes.
What you have in your code is a good start. (There are ways to prune the work so you only call the ones that need it rather than all objects in existence.)  
Move the CheckForDamage into the BaseMonster class.  You've already got that written in your code, B.CheckForDamage(). That's a member function of BaseMonster.
In your code you are iterating through all the monsters and calling the same function for everything is working with a system.  That is good, it is working with a system. Your base class would then have a CheckForDamage() function.  Then if you want to make modifiable behavior, BaseMonster::CheckForDamage() should then call its own virtual functions that concrete monster types can override.  
So perhaps instead of just passing a numeric damage you would pass a damage structure. Then it might grow like this:

abstract class BaseMonster {
public struct MonsterInfo {
  bool HasFireSpecialty = false;
  bool HasIceSpecialty = false;
  bool HasElectricSpecialty = false;
  bool HasPoisonSpecialty = false;
} monsterInfo;
protected virtual void OnFireSpecialty( ref DamageInfo damage) {}; // these are intentionally not public.
protected virtual void OnIceSpecialty( ref DamageInfo damage) {};
protected virtual void OnElectricSpeciality( ref DamageInfo damage) {};
protected virtual void OnPoisonSpeciality( ref DamageInfo damage) {};

// This is not virtual. Let the non-virtual base function call the virtual functions.
// It is a bad practice to have virtual functions as the interface. Have a non-virtual interface with internal virtual
// functions that modify the 
public void CheckForDamage( DamageInfo damage) {
  if(damage.HasFireComponent && monsterInfo.HasFireSpecialty) OnFireSpecialty( ref damage);
  if(damage.HasIceComponent && monsterInfo.HasIceSpecialty) OnIceSpecialty( ref damage);

class Balrog : public BaseMonster {
protected virtual void OnFireSpecialty( ref DamageInfo damage )
   // Balrog is a fire monster. Do something special when they hit me with fire

This way at a later time, months later or years later or even as a standalone expansion pack or mod, somebody can derive a class from BaseMonster. As long as they implement all the functions and interfaces a monster requires it will seamlessly integrate with all the other monster types.
What you DON'T want to implement is something like this:

if( monster is Dragon ) { ... }
else if (monster is Knight ) { ... }
else if (monster is Ghost ) { ... }

Or this:

if( monster.GetMonsterType() == MonsterType.Dragon ) { ... }
else if( monster.GetMonsterType() == MonsterType.Knight ) { ... }
else if( monster.GetMonsterType() == MonsterType.Ghost ) { ...} 

Instead you should implement actions and verbs on your base abstract type. 

If you are going more for an ECS style architecture, you would probably attach components that you would call.  Then it would become something like this:


// Somewhere in your code you created an interface called DamageModifyingComponent, 
// and all your damage modifying components implement the interface.

CheckForDamage( DamageInfo damage )

  foreach( c in components ) {
    DamageModifyingComponent dmc = c as DamageModifyingComponent;
    if(dmc) {
      dmc.ModifyDamage(ref damage);

#5300280 Making an object move back and forth.

Posted by frob on 11 July 2016 - 07:13 PM

(moderator hat on)

A gentle reminder about the special rules of the For Beginners forum


* This forum is for beginners to ask questions without being harassed because someone more experienced thinks the answer should be obvious.


* Make sure replies are helpful and guiding the beginner in the right direction.


The focus in For Beginners is to help educate, guide, and answer questions in a reasonably safe environment.  Even the experts were beginners once.  Sometimes the best answers are a code snippet, or a link to a tutorial.  Other times the best answers are step-by-step guidance to help think and reason and guide to reach a viable solution.


(moderator hat off)

In a more useful note, it looks like Alberth has been guiding toward the right answer, and those are the correct things to think about to solve this problem and other problems like it.  

I'd also break it down similarly:
1. First you need to figure out generally how you are going to move objects. It looks like you've described some shapes.
2. After you know how objects will move, describe those motions as very specific steps. Looks like you've got back-and-forth and square, and possibly circle. Describe those motions in terms of world coordinates and game systems. Describe every step precisely. Eventually you will need to explain it to the computer that will only do exactly what you tell it, nothing more or less. You might try explaining it to an obnoxious person who only does exactly the words you say to make sure you really understand the steps involved.
3. Take the descriptions in regular words, and figure out how to describe it as a series of math steps.  For example, a math function where you pass in the current time and the details of the path to follow, then you divide the time by the time it takes to complete a full cycle (at the current time step it is on cycle 2341.36), then compute the portion within the current cycle (it is 36% complete), then compute the position at that time in the cycle (36% of the distance on the path yields coordinates (X,Y,Z) which should be where you set the position).  Or another approach might mean a math function where you evaluate the time that has passed (it has moved for 14.6 milliseconds), evaluate the speed and direction it is traveling (7.83 pixels per millisecond in a specific direction), then advance the position based on the time (elapsed time * speed at direction).  There are many other ways you might describe the direction.
4. After you've got the steps figured out and you can describe it using math, then attempt to describe it in computer code. 

It looks like you're somewhere between step 2 and 3. It can be a struggle, but the skills are vital if you want to develop software.  Even in professional work environments we will talk to others to explain every individual step, then explain the steps using the right notations.  Sometimes we'll even explain it to an inanimate object to help reason through the steps.

#5300274 The big face-off between inheritance/interfacing

Posted by frob on 11 July 2016 - 06:31 PM

Inheretence generally means it is exactly interchangable.



As an example, if I ask for a D3D11 device I do not care what the underlying type is.  I should never need to know if underlying device is a GeForce GTX 750, or a Radeon R7 360, or an Intel HD 4600. All of them are D3D11 devices and all of them operate interchangeably.  Every action I tell it to do should work the same no matter what action I use.


As another example, if I am writing code that operates on a GameObject class, I do not care if that is a player, a bazooka, a rock, or a shoe. If it inherits from GameObject I should never care what the concrete type is, I should never do anything different based on what the leaf type happens to be.  All GameObject items should be completely interchangeable. If I can do something with one of them I should expect the action to work properly on all of them.


In most languages base classes should generally be kept abstract. You should not be able to create them directly, you should only be able to create child objects, but you should use the base class everywhere as the type of object.  Much like with graphics you might create a D3D11Device, you don't create an NVidiaGtx780Device. 

In your hierarchy, every operation that works on a BaseEntity should work exactly the same on every object.  It doesn't matter if the concrete type happens to be a player, enemy, projectile, or prop, all the operations should work exactly the same.

Similarly, it should not matter what concrete type of creature you've got, if it inherits from Creature then it is completely interchangeable with any other thing that is a creature and you never do anything different based on what kind of creature it is.  All creatures are interchangeable and their concrete types make absolutely no difference.


If you haven't already, read up on SOLID development patterns. 


Most Entity/Component System designs generally follow SOLID principles, components all implement interchangeable abstract interfaces, any component is interchangeable with other components, you can mix and match and assign them, you work on the abstract types rather than concrete types, they all have a single responsibility of whatever the component happens to be, and so on.  Then you use composition to build up all the behaviors your game object needs by adding component after component until it does everything you need.

#5300033 Finding that balance between optimization and legibility.

Posted by frob on 10 July 2016 - 03:23 PM

After crunching some numbers, I calculated that my cache hit was approximately 70%, so I'm thinking about keeping this example in my code for now (if not for the performance gain, then at the very least as a reminder).  


Given your usage pattern, and considering the size of the CPU's data cache on today's processors, this may work out well in your use pattern.  If you are frequently computing the trig functions on a small set of common angles, and you are doing it frequently enough that they stay local to the CPU instead of getting evicted from the cache, it will absolutely help.


But as others point out, keep measuring and monitoring.  


It looks like for now you are only using it where it makes sense. But add some debug blocks to your code to notify you when the situation changes.


If you reach the point where your comparisons are no longer in the cache, or if you are multithreaded and your writes need to be slowly propagated to all the processors, then you'll need to revisit your design.  If you start doing more operations on a wider variety of values, or values that are not quite identical, those could also trip your routine up.

#5300018 LibGDX Multi-touch finger index tracking

Posted by frob on 10 July 2016 - 01:16 PM

It looks like LibGDX does some slight behind the scenes and calls both IDs and indexes 'pointers', so you'll need to double-check with the code to verify the details of which one you've got.
Here is what happens in the raw, underneath LibGDX.
On Android devices there are pointers that generate MotionEvent data.  Each pointer can be a mouse, a finger, multiple fingers, etc. It is a potentially confusing name with some programming languages using the word pointer to mean the address of an object.  Here a pointer refers to something generating input data at a position.
Pointers have both a pointer index and a pointer ID.  Both are integers. 
Every time there is a new touch or pointer a new data structure is created. That data structure contains a unique ID.  Those data structures are placed inside an array of MotionEvent data, and the position inside the array is the index.  Between events and behind your back the system can move items around inside the array, which changes their index.  That is why index values may change between calls and should not be kept around between calls. ID values should remain the same between calls.  
The system provides convenience methods to switch between the ID and index.  getPointerId(int) takes an index and returns the ID of whatever value is in that array position.  getPointerIndex(int) takes a pointer ID and returns the index in the array, or -1 if that ID is not in the array.
Do not rely on index values, they are just array locations that are meaningless between calls.  If you need to track over time use the ID, which should remain the same between calls.