Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411432 Posts in 69363 Topics- by 58417 Members - Latest Member: gigig987

April 20, 2024, 04:54:09 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 5 6 [7] 8 9 ... 69
Print
Author Topic: General thread for quick questions  (Read 134722 times)
oahda
Level 10
*****



View Profile
« Reply #120 on: August 03, 2015, 03:45:17 AM »

I don't think you can target a prefab in itself and modify it at runtime. Prefabs are not objects in your scene but templates for creating objects. Even if you can, whatever changes you make would affect all objects created from the prefab at that point, and not just those currently in the scene.

What you're doing here is grabbing the first object with the tag specified. There should be a plural function along the lines of FindGameObjectsWithTag instead (note 'objects' instead of 'object'), which returns an array of all the matching objects, which you can modify in a loop.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #121 on: August 03, 2015, 12:09:03 PM »

Code:
foreach(var obect in GameObject.FindGameObjectsWithTag("enemy"))
{
  var enemycode = object.GetComponent<EnemyCode>();
  ...
}
Logged
Billy Ninja
Level 0
**



View Profile
« Reply #122 on: August 03, 2015, 02:05:09 PM »

I'm using SDL2 (in Go programming language, using a binding)

trying to render some text, i see that it only retrieves me text as Surface, not as texture directly.

Quote
// First get the surface
surface, err := font.RenderUTF8_Solid("HELLO, SDL2!", sdl.Color{255, 255, 255, 255})
   
// Then convert it to a texture
txtr, err := renderer.CreateTextureFromSurface(surface)

// set it to be destroyed at the end of this function call
defer txtr.Destroy()
   
//Finally copy it to my renderer buffer
renderer.Copy(txtr, &sdl.Rect{0, 0, 255, 255}, &sdl.Rect{0, 0, 255, 255})

It seems too expensive for a simple text rendering, considering that I'll have to do it for every piece of text, every frame. Is this normal/ok? Do ppl use some work around/stategy? Like only converting the text to texture once it is created or altered? (quite a hassle to keep track of)
« Last Edit: August 03, 2015, 02:13:41 PM by Billy Ninja » Logged

"Life is short, art long, opportunity fleeting, experience misleading, judgement difficult."
Mightymcc21
Level 0
*


View Profile
« Reply #123 on: August 03, 2015, 07:23:20 PM »

Thank you so much guys, I had a feeling the answer was in arrays but I wasn't sure where to start!
Logged
VampireSquid
Level 0
***


View Profile
« Reply #124 on: August 04, 2015, 06:39:15 PM »

I'm using SDL2 (in Go programming language, using a binding)

trying to render some text, i see that it only retrieves me text as Surface, not as texture directly.

Quote
// First get the surface
surface, err := font.RenderUTF8_Solid("HELLO, SDL2!", sdl.Color{255, 255, 255, 255})
   
// Then convert it to a texture
txtr, err := renderer.CreateTextureFromSurface(surface)

// set it to be destroyed at the end of this function call
defer txtr.Destroy()
   
//Finally copy it to my renderer buffer
renderer.Copy(txtr, &sdl.Rect{0, 0, 255, 255}, &sdl.Rect{0, 0, 255, 255})

It seems too expensive for a simple text rendering, considering that I'll have to do it for every piece of text, every frame. Is this normal/ok? Do ppl use some work around/stategy? Like only converting the text to texture once it is created or altered? (quite a hassle to keep track of)


So I am not very familiar with GO or SDL but I think the general solution is to cache the rendered text, I think this is what you are considering in your last comment.  I would create a hashtable with the text as the key and the value as the textured text.  I am thinking the majority of the time the text won't change so you will find the value in the hashtable and avoid that process.  You will have to build a proces though, to ocassionally clean up old entries from the hashtable that are no longer used or else you will have a memory leak.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #125 on: August 05, 2015, 04:51:28 AM »

Does anyone know of some utility or program so that when you hit a c++ error that is the result of generated code from the template preprocessor it shows you the expanded form?

I feel like someone must have written something like that already.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #126 on: August 05, 2015, 10:46:43 AM »

The Clang compiler has got a good track reputation for giving sensible error messages. But I've never had your problem - compilers usually give too expanded information for my taste.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #127 on: August 06, 2015, 06:39:01 AM »

The Clang compiler has got a good track reputation for giving sensible error messages. But I've never had your problem - compilers usually give too expanded information for my taste.

Too expanded? You have a compiler that's showing expanded template code? Or do you mean the error messages are too much?

I am using clang along with a handfull of other compilers but basically I'm trying to reverse engineer some pretty complex template metaprogramming. I can solve the error but it would help a ton to see the expanded form of some code with certain traits applied etc.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #128 on: August 06, 2015, 12:46:49 PM »

Yes, I meant the error messages. The *types* are expanded. I see you are expecting to actually hoping to see what templates have resolved and so on - I had misunderstood.
Logged
zleub
Level 0
**


View Profile WWW
« Reply #129 on: August 07, 2015, 05:47:37 AM »

Hi !

I have a quick question. I'm making a little 2D collider naively, checking in my update function for collisions between Entities and Blocks. That makes a Entities.len * Blocks.len iteration. Is making a tree-thing for space's repartition (or something else ?) worth it ?

Edit: Sorry, i just figured out.
« Last Edit: August 07, 2015, 05:57:01 AM by zleub » Logged
Sqorgar
Level 0
**


View Profile
« Reply #130 on: August 07, 2015, 07:27:34 AM »

Hi !

I have a quick question. I'm making a little 2D collider naively, checking in my update function for collisions between Entities and Blocks. That makes a Entities.len * Blocks.len iteration. Is making a tree-thing for space's repartition (or something else ?) worth it ?

Edit: Sorry, i just figured out.

I know you figured it out, but in case someone else wanted the answer, it depends on the number of collisions you need to test. If you have a handful, test each against each other all you want. If you have a few hundred, it is beneficial to break the space up so that you aren't testing a collision between two entities a mile apart. If you are only testing entities vs blocks (and not entity/entity and the blocks don't move), you can store the blocks in an array based on physical location, for easy collision testing.

Quadtrees/BSP trees are used to break the world space into increasingly small areas, so that each zone only has a few entities in it, limiting collision tests to a single zone and its neighbors. I'd only bother using one for a large number of objects, where testing collisions is a speed bottleneck in your application.
Logged
indie11
Level 2
**


View Profile
« Reply #131 on: August 09, 2015, 07:49:17 AM »

I have a big 3D environment in Unity with 2 points marked on it with latitude and longitude values. How can I convert these 2 points to unity world coordinates?

 
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #132 on: August 09, 2015, 08:37:52 AM »

https://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_and_Cartesian_coordinates
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #133 on: August 09, 2015, 12:56:56 PM »

I have a big 3D environment in Unity with 2 points marked on it with latitude and longitude values. How can I convert these 2 points to unity world coordinates?

 

I'm not sure of the context, do you want to convert the polar coordinate to a flat map (the big environment with lat/lon) or do just want to find the equivalent 3D point from polar coordinate to carthesian?

if the latter look the post above, else you have a "torus paradox" (made up term) on your hand
Logged

oahda
Level 10
*****



View Profile
« Reply #134 on: August 10, 2015, 05:52:23 AM »

It seems too expensive for a simple text rendering, considering that I'll have to do it for every piece of text, every frame. Is this normal/ok? Do ppl use some work around/stategy? Like only converting the text to texture once it is created or altered? (quite a hassle to keep track of)
I would indeed only update the texture when the text changes, and keep track of it. Is it really a hassle? You'd just encapsulate the SDL struct or whatever into one of your own and then use it similarly. That's what I'm doing in my SDL 2 system, which also manages font sizes and stuff in the background so that I won't have to manually specify to reload every font at every font size and so on.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #135 on: August 10, 2015, 06:43:16 AM »

Yes, I meant the error messages. The *types* are expanded. I see you are expecting to actually hoping to see what templates have resolved and so on - I had misunderstood.

Yeah it's really for those cases where you have a big mess of templates that take other templates as parameters and it becomes hard to track in your head.

I've been told I might be able to extract that information using libclang but I was kind of hoping there was some solution already out there. I've found stuff for macro expansion but that's usually not a big problem for me. 
Logged

oahda
Level 10
*****



View Profile
« Reply #136 on: August 11, 2015, 07:17:53 AM »

What's really the truth behind batched textures and stuff?

Would a system that batches tiles onto larger a larger texture be faster because it only requires one draw call or would having all the tiles individual be faster after all since the program can simply not draw a bunch of tiles that aren't visible at the moment, and only draw those much smaller (than a big single batched texture) that are?

Like if a big wall is made up of tiles and only a third of the wall is visible, wouldn't it be faster if it really only did have to send draw calls for that third of the wall and not the whole wall?

I'm definitely noticing huge decreases in performance whenever I try to draw big things, at least (OpenGL and GLSL, 2D), but I feel like I hear about tiles getting batched into single textures a lot??

Have I forgotten some setting that makes OpenGL actually not attempt to draw pixels outside of the screen (when stuff is at least partially visible — my system already manages not drawing stuff at all if it's completely outside of the screen) at all, or does it, and it doesn't matter anyway?
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #137 on: August 11, 2015, 07:57:45 AM »

What's really the truth behind batched textures and stuff?

Would a system that batches tiles onto larger a larger texture be faster because it only requires one draw call or would having all the tiles individual be faster after all since the program can simply not draw a bunch of tiles that aren't visible at the moment, and only draw those much smaller (than a big single batched texture) that are?

Like if a big wall is made up of tiles and only a third of the wall is visible, wouldn't it be faster if it really only did have to send draw calls for that third of the wall and not the whole wall?

I'm definitely noticing huge decreases in performance whenever I try to draw big things, at least (OpenGL and GLSL, 2D), but I feel like I hear about tiles getting batched into single textures a lot??

Have I forgotten some setting that makes OpenGL actually not attempt to draw pixels outside of the screen (when stuff is at least partially visible — my system already manages not drawing stuff at all if it's completely outside of the screen) at all, or does it, and it doesn't matter anyway?

One drawcall with 500 vertices will always be faster than 20 drawcalls with 6 vertices in OpenGL. What you can do is use chunks to still have less draw calls while only drawing what's visible. Profile to see what works best for your goals.
Logged
oahda
Level 10
*****



View Profile
« Reply #138 on: August 11, 2015, 10:16:18 AM »

Do you mean that if I simply split the bitriangular quad into a bunch of more triangles, OpenGL will optimise out all the triangles outside of the screen automatically, even if there's still just one big texture UV-mapped over the whole mesh, making it faster than drawing the same one big texture on a quad made up of only two triangles? Or something else?
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #139 on: August 11, 2015, 10:19:33 AM »

Do you mean that if I simply split the bitriangular quad into a bunch of more triangles, OpenGL will optimise out all the triangles outside of the screen automatically, even if there's still just one big texture UV-mapped over the whole mesh, making it faster than drawing the same one big texture on a quad made up of only two triangles? Or something else?

OpenGL will optimize that out as much as that it will not run the fragment shader, it still has to run the vertex shader of course, and you still have to send all the vertices to the GPU. One single big quad is better than many small ones, but it takes time to generate that big quad if you do it dynamically.
Logged
Pages: 1 ... 5 6 [7] 8 9 ... 69
Print
Jump to:  

Theme orange-lt created by panic