About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Dynamically create a local controlled player
Author Message
EnergyX Offline
Member

Post: #1
Dynamically create a local controlled player
My question is similar like this thread but the answer didn't help me much.

I am trying to create my local player dynamically without having something to do with the world editor at all.

My current code is:
PHP Code:
Game::ObjMemx<Game::Static> Statics;
Game::ObjMemx<Game::ItemItems ;
Game::ObjMemx<PlayerPlayers;

Init():
Game::World.init()
              .
setObjType(StaticsOBJ_STATIC)
              .
setObjType(PlayersOBJ_PLAYER)
              .
setObjType(Items  OBJ_ITEM  )
              .New(
"world/Start1.world");



Update():
if(
Kb.bp(KB_SPACE))
   {
       
Game::ObjParams param;
       
param.mesh(true,Meshes.ptrRequire("Obj/Warrior/body.mesh"));
       
param.skeleton(true,Skeletons("Obj/Warrior/body.skel"));
       
param.matrix.setScalePos(1.0f,Cam.at);
       
param.type(true"OBJ_PLAYER");
       
Game::World.objCreate(param,Matrix(param.scale(), Cam.at));
   } 

But when pressing the space button, nothing appears.
I don't know why it doesn't work.

Thanks for any help.
(This post was last modified: 09-06-2011 02:31 AM by EnergyX.)
09-06-2011 02:30 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Dynamically create a local controlled player
Exact code works over here, except I had to change the path to "Obj/Chr/Warrior/". Place this code in the Draw function to see if the number of players increases:

Code:
D.text(0, -0.9f, S + "Number of players: " + Players.elms());

You are calling Game::World.update(), correct?
(This post was last modified: 09-06-2011 03:26 AM by Driklyn.)
09-06-2011 03:24 AM
Find all posts by this user Quote this message in a reply
EnergyX Offline
Member

Post: #3
RE: Dynamically create a local controlled player
After pressing the space bar; "Number of players: 0"
And yes, "Game::World.update(Cam.at);" is called in Update().
I also moved the Warrior folder into "Chr" folder to match your path "Obj/Chr/Warrior/" and edited the code, still nothing appears and 0 elements.
A screenshot of my code to read better.
[Image: UyTAF9.png]
Bigger: http://screensnapr.com/e/EMxlMw.png
(This post was last modified: 09-06-2011 03:42 AM by EnergyX.)
09-06-2011 03:36 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: Dynamically create a local controlled player
It doesn't have to be in the Chr folder, just making sure you have the right path.

  1. Try OBJ_STATIC instead of OBJ_PLAYER.
  2. Try logging the return value to see if it actually created the obj or not:

    Code:
    LogN(S + Game::World.objCreate(param,Matrix(param.scale(), Cam.at)));

    Check your build folder for "log.txt". If it contains a 1, then it succeeded in creating the obj.
09-06-2011 03:48 AM
Find all posts by this user Quote this message in a reply
EnergyX Offline
Member

Post: #5
RE: Dynamically create a local controlled player
I did the 2 things you told me, and i got "0" in the log file.
09-06-2011 03:51 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: Dynamically create a local controlled player
  • Is your entire world being dynamically created?
  • Are any OBJ_STATIC/OBJ_ITEM objects being loaded and drawn?
  • Do you have a Game folder in your "world/Start1.world" folder?
(This post was last modified: 09-06-2011 04:01 AM by Driklyn.)
09-06-2011 03:58 AM
Find all posts by this user Quote this message in a reply
EnergyX Offline
Member

Post: #7
RE: Dynamically create a local controlled player
Ok, its a little confusing.
I copied the whole data folder that is shipped with EsenthelSDK download to my game data folder and now it works fine.

Before that, i copied only the Warrior folder which i thought it was enough in order to use it; Could you please tell me what are the other files that Warrior meshs uses ?

I also have another question.
Is it possible to create an object with "param.type(false);" and get the object pointer ? I am trying to avoid declaring an object type and an array for something that isn't used in big amount, such as the local player which there is only one of this.

Thank you very much for your help Driklyn.
(This post was last modified: 09-06-2011 04:07 AM by EnergyX.)
09-06-2011 04:07 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #8
RE: Dynamically create a local controlled player
(09-06-2011 04:07 AM)EnergyX Wrote:  Could you please tell me what are the other files that Warrior meshs uses ?

I think everything you need for the Warrior is in that folder itself. Strange, must have been some other file that was missing, not really sure what that could be though.

(09-06-2011 04:07 AM)EnergyX Wrote:  Is it possible to create an object with "param.type(false);" and get the object pointer ? I am trying to avoid declaring an object type and an array for something that isn't used in big amount, such as the local player which there is only one of this.

Game::World.objCreateNear returns a pointer to the object, but this requires you to use ObjMemx<Player>.

To avoid manually specifying param values via code, you can create .obj files in the Object mode of World Editor. Just fill out the values as you would if you were going to place an object in the world, except hit File > Save (on the same "Temp Object" window) and save it out. Then, you can load it in via code:

Code:
Game::ObjParams &param = *Game::Objs.ptrRequire("Obj/Chr/Warrior/0.obj");
Game::World.objCreate(param, matrix);

----------

I've never tried this, but it might work if you just keep a Player class in constant memory and manually call the create/update/draw methods:

Code:
Player player;

Bool Init()
{
    // ...
    Game::World.New(..);

    ObjParam &param = *Game::Objs.ptrRequire("Obj/Chr/Warrior/0.obj");
    player.create(param);
}

Bool Update()
{
    // ...

    Game::World.update();
    Player.update();
}

void Render()
{
    Game::World.draw();

    switch(Renderer()) {
        case RM_PREPARE: {
            player.drawPrepare();
            break;
        }

        case RM_SHADOW: {
            player.drawShadow();
            break;
        }
    }
}

Never tested this, so code might not be bug-free or even work. Think I might try testing it after this...

----------

So, I tried testing this code just now and, to my surprise, it worked first try! lol

Honestly, I think I may just like this technique better than using an ObjMemx container for the Player class (assuming you're only ever going to need 1 player). Good question! smile
(This post was last modified: 09-06-2011 04:53 AM by Driklyn.)
09-06-2011 04:37 AM
Find all posts by this user Quote this message in a reply
EnergyX Offline
Member

Post: #9
RE: Dynamically create a local controlled player
Works perfectly, thanks grin
09-06-2011 04:53 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #10
RE: Dynamically create a local controlled player
No problem. Even I learned something new from this thread. pfft
09-06-2011 04:56 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Dynamically create a local controlled player
Code:
ObjParam &param = *Game::Objs.ptrRequire("Obj/Chr/Warrior/0.obj");
player.create(param);
this is incorrect, you should do:
Code:
player.create(*Game::Objs.ptrRequire("Obj/Chr/Warrior/0.obj"));
or:
Code:
Game::ObjParamsPtr obj; obj="Obj/Chr/Warrior/0.obj"; player.create(*obj);


ptrRequire returns a reference pointer, which if it's not copied to other Game::ObjParamsPtr, it will be automatically deleted after the line of code executes
09-06-2011 01:19 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #12
RE: Dynamically create a local controlled player
Good point. This works however (param instead of &param).

Code:
Game::ObjParams param = *Game::Objs.ptrRequire("Obj/Chr/Warrior/0.obj");
player.create(param);

Is that okay to do? Meant to write it like that earlier, couldn't remember if it needed a reference or not (I didn't actually test the code by loading a .obj, just using a manually created one).

(09-06-2011 01:19 PM)Esenthel Wrote:  
Code:
Game::ObjParamsPtr obj; obj="Obj/Chr/Warrior/0.obj"; player.create(*obj);

Interesting. Didn't know you could do that, but it gives me a "cannot access private member declared in class 'EE::CacheElmPtr<TYPE,CACHE>'" error.
09-06-2011 06:56 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
RE: Dynamically create a local controlled player
Quote:Is that okay to do?
yes

Quote:Didn't know you could do that, but it gives me a "cannot access private member declared in class 'EE::CacheElmPtr<TYPE,CACHE>'" error.
Code:
Game::Chr player;
   Game::ObjParamsPtr obj; obj="Obj/Chr/Warrior/0.obj"; player.create(*obj);
works for me
09-06-2011 07:55 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #14
RE: Dynamically create a local controlled player
I was using Code Editor. Are you? Maybe that's the problem. I'll try again later...
09-06-2011 08:03 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #15
RE: Dynamically create a local controlled player
Okay, found the problem. I was writing it like this, which doesn't work:

Code:
Game::ObjParamsPtr obj = "Obj/Chr/Warrior/0.obj";
player.create(*obj);
09-07-2011 04:52 AM
Find all posts by this user Quote this message in a reply
Post Reply