Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Sep 2012
Offline Last Active Today, 11:51 AM

#5298743 Does adding Delegates/Function pointers to an entity break ECS ideology?

Posted by on 01 July 2016 - 03:30 PM

I'd say "pure ECS ideology" means: Entity doesn't has any logic, and components either. Logic goes into your systems. Entities are IDs, components are data, systems have all the logic. End of story.


So you wouldn't do any of what you mentioned (neither adding functions to an entity nor adding functions to a component).

#5298742 Creating OpenGL context in different OpenGL driver versions

Posted by on 01 July 2016 - 03:19 PM

Do yourself a favor and use GLFW, or SDL to handle contexts. No one will look down on you for not learning all that platform specific stuff, and if they do, they're idiots, so you shouldn't listen to them anyway.

#5297768 Is there any reason to prefer procedural programming over OOP

Posted by on 23 June 2016 - 07:33 PM

Don't look at me. I think the "but but I have to type "static" and put it in a class file!" complaint is stupid. If it looks like a duck and quacks like a duck... C# has exactly the same requirements thus why I dont see the point.

#5297764 Is there any reason to prefer procedural programming over OOP

Posted by on 23 June 2016 - 06:42 PM

All right, lets see...


You cannot do procedural programming in Java


You can't do it in C# either yet you use it as an example.



Writing a simple 'Hello World' program in Java isn't contrived OOP as an exercise, its contrived OOP because that's what the language demands.

Yes, thats true because it isn't a language designed to make "Hello world" programs. If all you want is to write short "Hello world" programs I'd recommend something else, like just make an HTML label tag and open it with a browser.


 We can agree though, that most early programming habits anyone picks up in any language are best to hit the dustbin sooner than later. Rarely are first habits good habits.
 Of course.


it just so happens that among those goals are enforcing a particular and rigid view of OOP best-practices, protecting fully-functioning programmers from themselves, and a misguided attempt to make Java programmers interchangeable by creating a language that forces them into the lowest-common denominator.  
And why don't you say the same of say, Python which heavily discourages implementing your own data structures by ubiquitously using their own and having special syntax only for that purpose? Why dont you say the same of JavaScript from which until very recently was confined to be a browser scripting language? Why single out Java as the dogmatic example in the age where all the most used languages, except very few exceptions, are just as opinionated, or even more?


You could say that of most of modern languages. Nevermind the recent wave of people advocating even more religiously opinionated languages in the functional paradigm. Fixating on Java seems such a 90s thing to do. Where the concept was relatively new. Python was new, JavaScript was new. C and C++ were the way of making applications. Nowadays? Makes no sense, but I see people repeating it again and again.


IMO, C# did a much better job achieving Java's technical goals, and was better for throwing off as much dogma as it could.


Have you ever developed an application in .NET? Language is fine, (and practically Java in PascalCase 90% of the time regardless of what most C# purists say) but the ecosystem is centered around Bill Gates butt. I dont even know how could you paint it as the "least dogmatic" of the two.


Yeah, its the "least dogmatic" if you already use Visual Studio all day and deploy to a Windows Server computer every day, and only do fat destkop clients for Windows 7+ in WPF. As soon as you get out of that tiny cage you're thrown to the wolves. GUI solutions for other platforms are broken. Web solutions for other platforms are either broken (Xamarin) or in alpha stage (.NET Core). Nevermind finding tools to help you out in that endeavor because there is like only one half assed IDE out there that manages to understand C# and Linux/OSX at the same time.


Yeah C/C++ are not very dogmatic, but people are constantly trying to replace them with more dogmatic equivalents (Rust, Go among others), and C# is Microsoft's eco system baby and barely knows how to crawl anywhere else, nevermind the fact that C# 7 stuff and above are very, very close into making it a kitchen sink of features like C++ is.


I'm just not seeing your counter examples at all man.

#5297757 Best Java Engine?

Posted by on 23 June 2016 - 05:36 PM

LWJGL isn't an engine. Its "just" provides bindings to OpenGL, OpenAL, and a couple of assorted libraries (jemalloc, nanovg, nuklear, etc). Fairly similar to starting from scratch in C++. The developer knows what he is doing, and its really nice stuff only if you want to start from scratch, and probably never finish anything.


jMonkeyEngine is a "proper" engine. With a GUI editor (last time I checked), and all systems (animations, ai, terrain, graphics, physics, etc) you need to make a game.


libGDX is more of a "framework", all the code, systems and infrastructure you need to start making a game, but code only. There are other projects that build editors on top of it.


As for something really on par with Unity but made in Java, nothing really. Big name engines are made in C++ with various scripting layers on top of it. I've seen Lua, C#, Python and C++ itself as "scripting" layers, but not Java (90% sure because native interop with Java is a PITA, and general distrust of Java as a language for doing anything making games).


There are possibly hundreds of mobile games made with libGDX, and a bunch made with jMonkeyEngine. LWJGL powers the rendering backends of both.

#5297359 Is there any reason to prefer procedural programming over OOP

Posted by on 20 June 2016 - 02:18 PM

One problem is that the style of OOP taught in many colleges, universities, and books borrows very heavily from Java's over-orthodox view of what OOP is.


Eh no. What you find in universities are a lot of people who are not exposed to codebases beyond the really basics they teach in the courses. They read software engineering books (that are for the most part, language agnostic, and UML centered), and try to apply that to their "hello world" examples. Results are obviously disastrous since software engineering books are targeted at big organizations, with big codebases, and with complex projects, often much more complex than whatever the professor has ever done.


There is a lot of awful code written in Python by people who particularly dont like coding at all, just are doing some research project and want calculations done, heard of "numpy" and started using it. Yet you wouldn't declare that kind of code a reference for what coding in Python is. Neither would you declare the kind of C code produced in introductory courses the reference as how C is done. At least I wouldn't.


Worst of all is that people get out of those courses thinking "This is how Java is done!" "This is how C is done!" and dont understand that no, even if all you did in the introductory course is to make CLI applications, it doesnt means you cant do a GUI in C/Pascal/structured language X. And that no, even if all you did in the OOP course is to make InterfaceX and InterfaceXImpl interfaces/classes respectively, it doesnt means thats how you code things in Java/C#/OOP language X.


 Having learned Java-style OOP hasa lasting effect on a programmer. Its like an embarrassing accent
Whereas Zee Plus Plus was given to us, unworthy mortals, from the hand of God, through the visions of Prophet Bjarne Stroustrup himself. Teaching us the One True Language To Rule Them All. Obviously. Just look at Boost.

#5297158 Trying to remove bullets and get 'java.util.ConcurrentModificationExcepti...

Posted by on 18 June 2016 - 07:06 PM

I'd use Aldacron's method, it should be faster.


Actually, after looking at removeIf implementation, Oberon's method could be even faster.

  1. GlassKnife's method does a first pass looking for elements, then a linear search through the array every time it needs to remove each element inside 'removeAll'.
  2. Aldacron's method does a single pass, but it needs two "long lived" lists and copying the element's references around.
  3. Oberon's does a single pass, and it only uses internally a short lived BitSet, which will probably be ruled out by escape analysis.

I'd go with 3 if Java 8 is available, otherwise with 2.


EDIT: Ohh dude, you're calling remove twice probably. Duh. 

for(Iterator<Bullet> it = bullet.iterator(); it.hasNext(); bullet = it.next()) {
 if(bullet.rectangleBullet.x > screenSize || bullet.rectangleBullet.x < 0) {

Doing two ifs separately there makes it so you'll be calling 'remove' twice for bullets that meet both conditions. That throws an error obviously since you can't remove the same element twice. So you should remove once if it meets any of the two conditions.

#5296240 Component based architecture .... for game!

Posted by on 12 June 2016 - 12:23 PM

If I create some component/system that depends on two (e.g. BulletRocketSystem) , I will have to aware the order of execution.

BulletRocketSystem should execute after Bullet and Rocket's system.  

If Bullet will be deleted by Bullet_System's command, the BulletRocketSystem must be notified and remove reference of it.


This promotes couple between System, which is bad.

Moreover, there have to be a headquarter to enforce the order, I don't know if there is non-ugly way to do it.


Order of systems is a very basic thing that will need to be set one way or the other. You can't have all systems running in whatever order. Doesn't makes sense to render if the transforms haven't been updated. Doesn't makes sense to run the sound system or the asset streaming system if no movement was processed yet.


In Artemis ECS, and consequently, the fork I've been working on (dustArtemis, look at my signature), all systems get notified when entities get added, removed or changed. So they have the opportunity to react to situations like yours, or if an entity mutates (ie, you remove/add an effect over an entity).


Order is enforced because you set it indirectly (by the order in which you added sub systems to the World instance) or directly (via a priority value). Here:



Thats the main processing routine. First it notifies all systems of entity changes made during the last tick, then it notifies the entity and component managers of the same changes (so components can be removed/entities deleted) then it lets systems process their main workload, which might end up in more entity additions/removals. Rinse and repeat.


Moreover, the main focus of decoupling system ordering always seemed to be so you can run each system in their own thread. Over the years developers realized it isn't a good idea. Workloads of each subsystem vary a lot, so most of the time one thread would get chewed while the others would barely do anything. Nowadays the approach is to go "wide"  at each system. Got a couple thousand tasks to run in the movement system? Parallelize them in groups, then collect the results (if such step is needed) and move to the next system.

#5295356 Is redundant state checking still a thing?

Posted by on 06 June 2016 - 02:55 PM

I'm guessing here the driver is actually checking if the bindings are actually changed before doing anything when you rebind the resources. Rebinding the same resources again and again makes it go through this fast path so you see no differences.


Thing is, you'd be relying on driver specific behavior. You should try on different hardware.

#5293993 Testing If 2 Objects Are The Same

Posted by on 28 May 2016 - 08:38 PM

You need to override "equals(Object)" of your class, and make the comparisons you need there. Probably whatever IDE you're using has a "generate equals/hashCode" refactor option to do it for you.


Object equality is loosely defined, so you need to provide a concrete implementation of how you expect it to be done. If you dont override "equals", you'd be calling the default equals implementation, which just compares by reference.


EDIT: An implementation could be something like this:

public class Test {
  String a;
  int b;
  public Test(String a, int b){
    this.a = a;
    this.b = b;
  public boolean equals(Object o) {
    // Tiny optimization.
    if (this == o) return true;
    // Null check and type check.
    if (o == null || !(o instanceof Test)) return false;
    // We know its of type Test, cast it back.
    Test tmp = (Test) o;
    // Compare int first since its faster. Then use string equality here to compare a.
    return this.b == tmp.b && Objects.equals(this.a, tmp.a); 

Notice the Objects.equals(this.a, tmp.a). If you do this.a.equals(tmp.b), or vice versa, you risk a NPE if 'a' or 'b' is null. Objects.equals has this in mind so it checks inside first for null, then call the equals safely.

#5293868 how to chose open_gl libary?

Posted by on 27 May 2016 - 03:27 PM

Throw a coin.


EDIT: Omg I downvoted GlassKnife by mistake, sorry!  :unsure:

#5293482 Can I write a browser game only using Java?

Posted by on 25 May 2016 - 08:02 PM



And libGDX supports it, which is a game development framework for Java.


EDIT: God the GWT site sucks at explaining what it is, its a toolchain in which you can code in Java (under some restrictions), then compile that to JS/HTML/etc to deploy a web application.


[randomrant] All web-related libraries have sites that spew 90% fluff and no actual "Here is the actual stuff this fucking thing does" explanation [/randomrant]

#5292725 can a generic engine do something like skyrim?

Posted by on 20 May 2016 - 10:46 PM

neither is designed to take advantage of the most modern video cards like Skyrim does, but the engine can be modified easily enough.  

It does? Skyrim was released very late 2011 and it uses D3D 9 (and nothing else). Doesn't has any occlusion effect (5 years after Crytek introduced it), nor atmospheric scattering, nor volumetric lighting. Supports up to 4 shadow casting lights, they're really bad quality and they're all selected by hand (so the level designer has to mark which lights cast shadows, which meshes cast shadows, and pray it doesnt has more than 4 in the same scene, no dynamic LOD of lights or anything, just distance based).


All water in the game is represented with a flat plane and watery normal maps on top of it (again, Crytek in 2007 did it much better). Most of the things in the world dont cast a shadow, like clutter and medium sized rocks, which CryEngine did in 2007, also GTA IV in 2008 did actual ocean waves AND the whole open world shebang, procedural cluttering, real dynamic shadows, you name it.


Whatever animation system or blending system it has is straight from 2006 (or new but very badly used). Most "advanced" part is that feet accommodate along the floor, a bit, so most of the time everything looks as if its floating on the terrain.


It apparently can use multiple threads, but it keeps one or two to 80% utilization, rest unused.


Unity/UE4 can do any of those with ease. Skyrim was anything but technically advanced for its time. Default UE4 shooter scene thingy already looks better and is better animated than Skyrim.


The places where you are going to have a problem arent the big "systems" (rendering, physics, sound, animations), those are well covered. You're going to have issues with other things. Managing the world data, LODing systems, daily AI routines (did any game had that before Oblivion in 2006?), and also a very important thing: Modding API.


UE4 and Unity are really hard to mod. Skyrim's engine is practically made to be modded. It has its own versioning of world references, so plugins that modify the same things can overwrite eachother depending on some order and keep working. Literally the game updates are stuffed in an additional plugin, like any mod, that applies over the base game and the engine just fucking picks it up and makes everything work. Its awesome. Last time I checked they also implemented hot reloading of plugins, in the shipped game!


Also load times are really tiny. No clue how they do it, but quick save and quick load work really well.


EDIT: Oh and they have their own seemingly asynchronous scripting system, works really well, and a huge event system to fetch data from and run those scripts. Very nice stuff.

#5292531 Moving to OpenGL 3.1

Posted by on 19 May 2016 - 02:50 PM

Just std140 all the things. Its basically what D3D does, and look how popular it is.


Well, I'm done with porting to 3.1. I've lost about 10 FPS (from 462 -> 452)
 You're looking at this from a bad perspective. Don't measure FPS, measure milliseconds per frame.


462 fps is a grand total of 2.164 milliseconds per frame.

452 fps is a grand total of 2.212 milliseconds per frame.


Less than half a millisecond of difference (0.47ms). Thats nothing. You can probably chalk those margins up to measuring error.


Now, say that you're at 30 fps, and you loose 10 fps.


30 fps is 33.333 ms.

20 fps is 50.000 ms.


Difference is a whooping 16.666 milliseconds per frame. Thats a lot. And the difference from a playable 30 fps to a horribly unplayable 20 fps. Whereas from 460 fps to 450 fps, you probably cant physically notice a difference.

#5291701 Vulkan render-call performance drain

Posted by on 15 May 2016 - 10:01 AM

... What if you don't wait until the device has executed all the commands? 90% of the point with GPUs these days is that you submit work, and then (hopefully, otherwise you'll require fences) forget about it, so they can work asynchronously while the CPU builds the next set of commands.


If you wait for the device every frame you're basically synchronizing the CPU with the GPU, not allowing the CPU to work ahead on more commands. Like calling glFlush/glFinish every frame.


Then again, I haven't delved in Vulkan so I dunno if there is any specific use for vkDeviceWaitIdle.


EDIT: Good job on the OP for measuring the actual issue btw! Most often the code provided has nothing to do with the actual issue since no one bothers to profile.