What you proposed worked just as I wanted it to work. Thank you!
Oh good, I wasn't sure if I was totally misreading the Unity docs
I'm trying to get better at writing cleaner code for game development.
In my current Unity C# project, I have the goal of not using any singletons or global references. Much of my behavior is driven by UnityEvents and Scriptable objects. In my previous projects, I've always resorted to writing a large "Game Manager" singleton that uses some form of a finite state machine. All other objects then end up checking the current game state from this manager to determine what to do.
More recently I've just been using the game manager to fire off events indicating a state change, but that still requires an object to have some sort of reference to the global game manager. Any suggestions on how I can abstract the most important features of a game manager?
Nothing wrong with singletons IMO. The general developer community hates them because amateur programmers use them to solve issues that shouldn't be solved with singletons.
As long as you're using a single manager that just manages a single aspect of your game you're good.
Just make sure to initialize your manager classes in a well defined order somewhere so that first-time access doesn't instantiate the object.
The cleaner alternative is that you pass references of your manager classes into newly constructed objects. You'll have to make the right decisions while designing your architecture to prevent this from coming a mess, unless 10+ argument constructors are your forte. I prefer this method as well, but it's often not worth the effort IMO.
Also look into using static methods for things like saving, checking online privileges, loading maps etc. A lot of times these kind of operations don't need data from the classes you're calling them on, a reference to a relevant objects and a couple arguments are usually sufficient.
Another thing is don't make a class a singleton, even if you use it like one, unless it's necessary. What I mean is instead of Foo::getInstance() just have static Foo fooInstance; so that you can unit test it easier later, and if you ever need to have two Foos you can do that easily.
Is it possible to add a variable into another variable in c++? I need to make a movie quiz game and i need to do the inputs so that they go movie1, movie2 etc. but i cant seem to work out something like moviex and change the x in a for loop.
Not exactly as you describe it, however you can achieve that using arrays. movie1 and movie2 become movie[0] and movie[1].
Alright i will try that. I want it to be endless though, arent arrays limited?
std::vector for runetime sized arrays, std::array for compile time sized arrays (you probably want vector for this).
Anyone use ThreadPoolExecutors in Java so far? I am running into a problem which involves filling the executor with shit tonnes of runnables and I get java.util.concurrent.RejectedExecutionException as a result.
ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newCachedThreadPool();
pool.setMaximumPoolSize(this.maxThreads);
while...{
// here is a while loop which fills the pool using pool.execute(runnable);
...
}
//directly outside of the while loop
pool.shutdown();
The exception is either because I call the shutdown function of because the queue of the pool is full. I am not really sure as I have never used a ThreadPoolExecutor before. Any ideas?
Okay i just can't do it. I need to make a movie quiz game using linked lists and i just cant find a way to store strings inside a list, internet isnt helping either.
Show us some code that you're trying that isn't working
Or better yet, some pseudocode showing what you're trying to do.
hastebin
This is the code, i tried to make it with the built-in lists but the code is not working and full of errors probably, i'll try to sort it out by the time the demos start to come up.
Earlier the vector class was brought up, but you seem to be trying to use the list class
Do you necessarily need to use list over vector?
iirc both use a similar template anyways
you add elements to them by push_back, and you can access elements using the get(<index>) function OR like an array with '[<index>]' brackets
These classes emulate a dynamic sized array, so if you know how to work with an array, then handling these should come naturally.
Here's a code snippet example which may help: hastebin
On a side note: Facepunch's code blocks fucking suck holy shit
it just decimates basic formatting and merges multiple lines together.
Sadly it is said in the assignment that i need to be using linked lists. Thank you for the help, i'll be sure to check it rn.
It's apparently just an issue with Chrome from what I've heard. It doesn't happen on Firefox.
Hello peeps.
I got this gig recently that wants me to create some C# CRUD for daily operations of a shipping warehouse. Now it's just your regular Microsoft-based thing with C#, winforms, and ADO connection to the central MS SQL Server.
I got told that it would be great if there was some kind of thing tacked on for 3D visualization of the current state of the warehouse, directly fetched from the same SQL connection and rendered -- along with interactive controls for browsing the place and clicking on shelves for further information about contents and such.
I don't have much graphics experience but I would like to try my hand here. What do you guys think would be the best approach? What kind of frameworks/technologies should I look into to be able to create what I described without sinking too much into low-level graphics details and also be able to easily integrate/package it with my .NET winforms application? I would appreciate it if you could show me a direction or give me some keywords.
Thank you.
Greetings yall.
Okay, first time poster here. I have to edit the Android NDK code sample "Endless Tunnel" so that it saves and this and that. Apparently, the sample already has several functions related to saving and loading. However, despite the code being as simple and straightforward as possible, it seems to fail (but the game runs smoothly otherwise).
The code for the writing of a save file is as follows:
LOGD("Saving progress (level %d) to file: %s", level, mSaveFileName);
FILE *f;
f = fopen(mSaveFileName, "w"); // literally where shit goes wrong
(!f) { // where it tells me the shit is NULL, instead of proper
LOGE("Error writing to save game file.");
return;
}
fprintf(f, "v1 %d", level);
fclose(f);
mSaveFileName is a char pointer, essentially a string without being one (I have only a background in C++, not C). It contains a proper path, and the file name to be created (/mnt/sdcard/com.google.example.games.tunnel.fix/tunnel.dat). Ive scoured the internet for info regarding this kind of error, and solutions presented have not fixed it. These attempts include:
Adding permissions for external i/o operations to the manifest
trying to save outside of the class this function is a member of (dont know why I thought it would work, literally at wits end)
changing the path to internal storage
My project hinges on saving a single number to a textfile, and everything beyond that revolves around this. Can anyone help?
I'll also add that the android SDK and android development, which I have a little experience with on the java side but not enough to be competent, was not brought up at all for the entirety of the course and only now, for the final project, is it here. I am shook
Is the sd card mounted?
Does the following command work in the shell?
adb shell "echo \"hello\" > /to/your/path/hello.txt"
Otherwise I don't know what the problem is cause as you already said you have set the permissions...
Figured it out last night, felt dumb as hell. There was a folder that was in the /data/data folder that looked somewhat like the one in that mount path. Apparently setting it to that was the trick.
Maybe someone can help me figure this out. I don't know why but I always struggle with figuring out collisions.
let c = game.player.coord,
s = game.player.stats;
!tilecollide(c, game.player.size, { x: -s.movespeed });
//The above code is a partial snippet of the place the tilecollide function is being called from.
function tilecollide(c, s, d) {
let colliding = [];
d.x = d.x | 0;
d.y = d.y | 0;
for (let i = 0; i < game.rooms[game.curroom].tiles.length; i++) {
let tile = game.rooms[game.curroom].tiles[i],
p = {
x: c.x + d.x,
w: c.x + d.x + s.w,
y: c.y + d.y,
h: c.y + d.y + s.h
},
t = {
x: tile.x,
y: tile.y,
w: tile.x + tile.w,
h: tile.y + tile.h
};
if (t.p === "solid") {
if ((p.x < t.w || p.w > t.x) && (p.y < t.h || p.h > t.y)) {
colliding.push(i);
}
}
}
return colliding.length > 0;
}
I'm already aware that I really need to change how this entire function works to begin with but before I get to that I want to figure out exactly what I'm doing wrong when it comes to calculating collisions to begin with.
Inside the loop, the p object contains the top, bottom, left, and right coordinates for the player. The t object does the same for the current tile. Something in the if check for colliding is fundamentally wrong though because it's never returning true for anything at all.
https://i.imgur.com/v5jSED6.png.
Why doesn't my program work?
3D collision detection Look at the AABB vs AABB section.
Should be p.x < t.w || p.w > t.x should be p.x < t.w && p.w > t.x. Otherwise it will always return true.
Have you tried to put some debug.log to check if you even enter the function or the collision checking condition?
I'll have a look at that article later when I have more time to spend trying to work things out more. I wasn't actually even aware MDN had anything on stuff like that so thanks for the link!
I actually do have a debug check that I removed from what I posted earlier for brevity. The function itself is running properly, it's the condition that's consistently failing.
I just did a really quick check with your suggested code though and figured out the problem. This:
if (t.p === "solid") {
if ((p.x < t.w || p.w > t.x) && (p.y < t.h || p.h > t.y)) {
should be this:
if (tile.p === "solid") {
if (p.x < t.w && p.w > t.x && p.y < t.h && p.h > t.y) {
A really stupid oversight on my end. "t" was just the tile's edge coordinates.
Anybody got any good ideas for a university project? I've been given free reign to pick my own as long as it hits two criteria; must use computer graphics (basic 2d all the way up to complex 3d), and must use computer science
I've got about 2.5 years java, C# and Android experience, and it can be on mobile or PC. Just anything as long as the university can run my application
I've been trying to think of something but drawing blanks, I have a few weeks to decide, it can even be a modification of an existing game/program
I would personally go with C# and OpenGL, maybe some example on how to use modern OpenGL 4 to draw something?
I did these GitHub GitHub GitHub GitHub
Thanks, I'll read up on this, looks P interesting
Does anyone know why this is happening?
https://i.imgur.com/HuuhPEy.png
There is a huge jump in saturation at 66, and at 186, and it's ruining the gradient effect I'm trying to achieve.
The image above should be a smooth transition between pink and black but it's all garbled. Please tell me there's a way to fix this.
I've been tinkering with MonoGame lately in an effort to find a "passion project" that keeps my attention and allows me to flesh out my programming skills - so far, my expertise is limited to the simple assignments I've completed for my college classes. I'd also like to have something that I can show off for job interviews, too. To that end, I'm aiming to recreate a 2D tile-based game that I've played in the past (not that I ever expect to finish it, but I like the game and I need the practice).
The tutorials I've studied online haven't been enormously helpful, though. The code they demonstrate seem fine for one-off examples, but I don't understand how it translates to larger projects. I've been studying the source code for TrueCraft to learn more about MonoGame and how to design bigger programs, but I'm still having a rough time.
In particular, I'm trying to figure out loading textures. I get that you store the texture in the content pipeline and use SpriteBatch to draw the texture, but how do I "give" several different classes' worth of textures to the SpriteBatch so that it can draw their textures? This is my rough thought process:
// File A
class Sprite
{
DrawSprite(txture, sprbatch)
{
// "Hand off" the texture to spritebatch. Somehow.
}
}
// File B
class CarpetFloor : Sprite
{
Texture2D texture = "somefilename";
DrawSprite(texture, spritebatch)
}
// File C
class PottedPlant : Sprite
{
Texture2D texture = "anotherfilename";
DrawSprite(texture , spritebatch)
}
I just don't get it, can someone explain it like I'm five? And if you have any other tips, I'd gladly take them.
I'm looking for someone who can help me with the AI of an NPC for my Half-Life 2 mod. Hitting the use key on them will make them follow you BUT once they're in combat they'll stop following you to engage the enemy, which I'd be okay with if the player didn't have to 'use' them again for them to follow you. If anybody could help me out with this problem I'd really appreciate it!
[C++] npc_conscript
Sorry, you need to Log In to post a reply to this thread.