Jump to content

How to access objects from my SBX map


Raul
 Share

Recommended Posts

I had a look over the Blitzmax templates from the LEBuilder and remake the tutorials. I was able now to load and render my map made with the Editor.

 

Just wondering how could I access my objects from the map now.

 

 

Also I am interested in adding some models. I tried this simple code right after my map was loaded and before entering in main loop:

 

body:TBody = CreateBodyBox()
SetBodyMass body, 1
For n = 1 To 100
body = TBody(CopyEntity(body))
PositionEntity body, Vec3(Rnd(-5, 5), n, Rnd(-5, 5))
Next

 

but no cubes were visible..

i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64

rvlgames.com - my games

RVL Games Facebook Page, YouTube Channel

 

Blitzmax :)

Link to comment
Share on other sites

Hi Raul, good to see you back :)

 

The variable you used when using the LoadScene command is effectively a pointer to a collection with all of the sbx file's objects as children. You can iterate through these to access them and if need be build your own specialised collections.

 

Bodies in LE are a physics type representation for use with meshes and not actually meshes themselves, so you will have no visible component for a body!

 

Worth taking a look at the Leadwerks Developer Wiki on these items.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

@Pixel Perfect: right. my bad. forgot to actually add a Mesh... now is working. thanks

The only problem is that all the boxes are going through the terrain. How should I add the collision between the rest of the world and my boxes?

 

@Cassius:

ok. right before starting the main loop I entered the following:

 

For Local e:TEntity = EachIn CurrentWorld().Entities
    Select GetEntityKey(e, "Name")
         Case "a_1"
         MoveEntity(e, [e.position.x, e.position.y + 5, e.position.z])
    End Select
Next

 

And my tree was up there. That's good.

 

My next question would be: is this a good practice in real time? I mean, let's assume I have a character and I move it through the world. I want to check if my character is near a door and when I press "E" to open that door... or do anything with it. is there ok to make a "search" through all the entities and when I found the door to retrieve it? Is there another way to directly access that object?

i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64

rvlgames.com - my games

RVL Games Facebook Page, YouTube Channel

 

Blitzmax :)

Link to comment
Share on other sites

To get your meshes reacting to anything other than straight collision you need to create bodies for them, either in code or using the phygen tool. Then set up collision between them by assigning an entity type to each and using the Collisions command.

 

In terms of efficiency I'm not sure how things are handled in BMax but in C++ you would probably want to use something like a Map container which allows you to tag the object pointer with a text label and the pair are indexed by the label; making for fast and efficient retrieval. If you only have a few objects then indexed retrieval is not important, but if you have hundreds or thousands then it starts to make a difference.

 

I would strongly recommend reading through Aggror's Leadwerks Guide here it will save you much time in the long run

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

@Pixel Perfect:

I already have the body for that boxes. I just added EntityType = 1 for every box. Now I have coll detection with the ground and with my rocks.

 

For point 2, I might create (after my scene is loaded) an array of entitites... I could store what I need and make the checks during the mainloop.

 

Damn this is difficult. I do not have any REAL experience with 3D games. Except these little tests I never tried to code a 3D application... I still do not have that knowledge.

 

I download Aggror's pdf and I will have a look over it. Thank you.

i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64

rvlgames.com - my games

RVL Games Facebook Page, YouTube Channel

 

Blitzmax :)

Link to comment
Share on other sites

In terms of efficiency I'm not sure how things are handled in BMax but in C++ you would probably want to use something like a Map container which allows you to tag the object pointer with a text label and the pair are indexed by the label; making for fast and efficient retrieval.

 

Do you have a code for this in C++?

i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64

rvlgames.com - my games

RVL Games Facebook Page, YouTube Channel

 

Blitzmax :)

Link to comment
Share on other sites

A quick search on the net revealed a TMap object in BMax which appears to be the equivalent.

 

Two useful links:

 

http://en.wikibooks.org/wiki/BlitzMax/Modules/Data_structures/Maps

 

http://www.blitzbasic.com/bmdocs/command.php?name=CreateMap&ref=2d_cat

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

ok, this will be at least funny for you guys but: how do I "store" the pointer?

 

I tried this:

 

For Local e:TEntity = EachIn CurrentWorld().Entities

Select GetEntityKey(e, "Name")
    Case "a_1"
         MapInsert(map, "tree1", e)

    End Select
Next

 

but then I cannot "read" the info in no way..

i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64

rvlgames.com - my games

RVL Games Facebook Page, YouTube Channel

 

Blitzmax :)

Link to comment
Share on other sites

Not sure if I understand you but if this helps

 

Global pos:TEntity

 

For Local e:TEntity = EachIn CurrentWorld().Entities

Select GetEntityKey(e, "Name")

Case "bg_pos"

pos = TEntity(e)

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

Guest Red Ocktober

i took a slightly different approach to finding "objects" (using BlitzMax, but code and logic is simple enough to translate to c++), though it is basically similar to the one suggested above...

 

the first thing i did was to make my BlitzMax code aware of the lua framework...

 

'To create a new lua-gluefunctions.bmx file, comment and uncomment the following lines.
Include "lua-gluefunctions.bmx" '--Comment this line out to create new lua-gluefunctions.bmx
'Import lugi.generator		 '--Uncomment this line to create new lua-gluefunctions.bmx
'GenerateGlueCode("lua-gluefunctions.bmx") '--Uncomment this line to create new lua-gluefunctions.bmx
'Notify("All Done", 0)					 '--Uncomment this line to create new lua-gluefunctions.bmx
'End

...
...

' Create framework 'fw''
Global fw:TFramework = CreateFramework()
If Not fw RuntimeError "Failed to initialize engine."

' Pass to the lua state'
SetScriptObject("fw", fw)

 

then, i find the submarine in my .sbx map (instead of searching the world, i search the map) with the following simple function...

 

Function FindChild:TEntity(scene:TEntity, name:String)
 For Local entity:TEntity=EachIn scene.kids
   If entity.getkey("name","")=name
     Return entity
   EndIf
 Next
End Function

 

and then before the main loop call the function to get the object and position it slightly above level in the editor...

Local theSub:TEntity=FindChild(scene,"type232s_1")
MoveEntity theSub,Vec3(0,2,0)

 

the, in the main loop i can move the object...

moveEntity theSub,Vec3(0,0,-.06*AppSpeed())

 

i think this is the simplest way to do what you're looking to do (a simple procedural approach), and i'm sure you can rotate the object without resorting to physics bodys and forces (depending on the type game you're making) to make the mesh move in whatever direction you wish...

 

the key part here is exposing the lua scripted objects and states to the BlitzMax code...

 

i hope this helps...

 

--Mike

Link to comment
Share on other sites

if I am doing that I will just copy the "bg_pos" entity to the Pos entity, but I will not be able later to move that object for example. I will need to search again through all...

 

I don't know Blitzmax, but in the C/C++ version of LE2 every TEntity, TModel, TMesh, TWhatever is just a pointer.

That means you are not creating a copy of the actual thing, just a copy of the pointer to it.

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...