1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-04-19 10:47:13 +02:00

Separate the code that actually allocates the entity instance so it can be shared by entity pool change events from the server.

This commit is contained in:
Sandu Liviu Catalin 2016-03-22 03:29:27 +02:00
parent b8ddc7f3b8
commit b60c8bc12c
2 changed files with 432 additions and 167 deletions

View File

@ -426,68 +426,418 @@ void Core::CompilerErrorHandler(HSQUIRRELVM /*vm*/, CSStr desc, CSStr src, SQInt
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
Object & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Object & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & payload)
Int32 scale, Uint32 color, Int32 sprid,
Int32 header, Object & payload)
{ {
Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid); // Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
if (INVALID_ENTITY(id))
{ {
STHROWF("Server returned invalid blip: %d", id); STHROWF("Cannot allocate blip with invalid identifier: %d", id);
} }
// Retrieve the specified entity instance
BlipInst & inst = m_Blips.at(id); BlipInst & inst = m_Blips.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Blips[id].mID))
{
STHROWF("Cannot allocate blip that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CBlip(id); inst.mInst = new CBlip(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM); inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull()) if (!inst.mInst || inst.mObj.IsNull())
{ {
ResetInst(inst); ResetInst(inst);
STHROWF("Unable to create a blip instance for: %d", id); STHROWF("Unable to create a blip instance for: %d", id);
} }
// Assign the specified entity identifier
inst.mID = id; inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED; inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitBlipCreated(id, header, payload); EmitBlipCreated(id, header, payload);
// Return the script object
return inst.mObj; return inst.mObj;
} }
// --------------------------------------------------------------------------------------------
Object & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Cannot allocate checkpoint with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
CheckpointInst & inst = m_Checkpoints.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Checkpoints[id].mID))
{
STHROWF("Cannot allocate checkpoint that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CCheckpoint(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a checkpoint instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitCheckpointCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocForcefield(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_FORCEFIELD_POOL))
{
STHROWF("Cannot allocate forcefield with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
ForcefieldInst & inst = m_Forcefields.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Forcefields[id].mID))
{
STHROWF("Cannot allocate forcefield that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CForcefield(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a forcefield instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitForcefieldCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("Cannot allocate keybind with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
KeybindInst & inst = m_Keybinds.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Keybinds[id].mID))
{
STHROWF("Cannot allocate keybind that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CKeybind(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a keybind instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitKeybindCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocObject(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Cannot allocate object with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
ObjectInst & inst = m_Objects.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Objects[id].mID))
{
STHROWF("Cannot allocate object that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CObject(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a object instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitObjectCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Cannot allocate pickup with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
PickupInst & inst = m_Pickups.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Pickups[id].mID))
{
STHROWF("Cannot allocate pickup that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CPickup(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a pickup instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitPickupCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocSprite(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_SPRITE_POOL))
{
STHROWF("Cannot allocate sprite with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
SpriteInst & inst = m_Sprites.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Sprites[id].mID))
{
STHROWF("Cannot allocate sprite that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CSprite(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a sprite instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitSpriteCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocTextdraw(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_TEXTDRAW_POOL))
{
STHROWF("Cannot allocate textdraw with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
TextdrawInst & inst = m_Textdraws.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Textdraws[id].mID))
{
STHROWF("Cannot allocate textdraw that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CTextdraw(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a textdraw instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitTextdrawCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Object & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Cannot allocate vehicle with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
VehicleInst & inst = m_Vehicles.at(id);
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(m_Vehicles[id].mID))
{
STHROWF("Cannot allocate vehicle that already exists: %d", id);
}
// Instantiate the entity manager
inst.mInst = new CVehicle(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a vehicle instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Let the script listeners know about this entity
EmitVehicleCreated(id, header, payload);
// Return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
Object & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint32 color, Int32 sprid,
Int32 header, Object & payload)
{
// Request the server to create this entity
Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid);
// Validate the identifier returned by the server
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Server returned invalid blip: %d", id);
}
// Attempt to allocate this entity and return the result
return AllocBlip(id, true, header, payload);
}
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
Object & Core::NewCheckpoint(Int32 player, Int32 world, Float32 x, Float32 y, Float32 z, Object & Core::NewCheckpoint(Int32 player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Is the specified player instance even valid?
if (INVALID_ENTITY(m_Players.at(player).mID)) if (INVALID_ENTITY(m_Players.at(player).mID))
{ {
STHROWF("Invalid player reference: %d", player); STHROWF("Invalid player reference: %d", player);
} }
// Request the server to create this entity
Int32 id = _Func->CreateCheckpoint(player, world, x, y, z, r, g, b, a, radius); Int32 id = _Func->CreateCheckpoint(player, world, x, y, z, r, g, b, a, radius);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{ {
STHROWF("Server returned invalid checkpoint: %d", id); STHROWF("Server returned invalid checkpoint: %d", id);
} }
// Attempt to allocate this entity and return the result
CheckpointInst & inst = m_Checkpoints.at(id); return AllocCheckpoint(id, true, header, payload);
inst.mInst = new CCheckpoint(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a checkpoint instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitCheckpointCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -495,34 +845,20 @@ Object & Core::NewForcefield(Int32 player, Int32 world, Float32 x, Float32 y, Fl
Uint8 r, Uint8 g, Uint8 b, Float32 radius, Uint8 r, Uint8 g, Uint8 b, Float32 radius,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Is the specified player instance even valid?
if (INVALID_ENTITY(m_Players.at(player).mID)) if (INVALID_ENTITY(m_Players.at(player).mID))
{ {
STHROWF("Invalid player reference: %d", player); STHROWF("Invalid player reference: %d", player);
} }
// Request the server to create this entity
Int32 id = _Func->CreateSphere(player, world, x, y, z, r, g, b, radius); Int32 id = _Func->CreateSphere(player, world, x, y, z, r, g, b, radius);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_FORCEFIELD_POOL))
{ {
STHROWF("Server returned invalid forcefield: %d", id); STHROWF("Server returned invalid forcefield: %d", id);
} }
// Attempt to allocate this entity and return the result
ForcefieldInst & inst = m_Forcefields.at(id); return AllocForcefield(id, true, header, payload);
inst.mInst = new CForcefield(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a forcefield instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitForcefieldCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -530,58 +866,30 @@ Object & Core::NewKeybind(Int32 slot, bool release,
Int32 primary, Int32 secondary, Int32 alternative, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative); Int32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{ {
STHROWF("Server returned invalid keybind: %d", id); STHROWF("Server returned invalid keybind: %d", id);
} }
// Attempt to allocate this entity and return the result
KeybindInst & inst = m_Keybinds.at(id); return AllocKeybind(id, true, header, payload);
inst.mInst = new CKeybind(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a keybind instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitKeybindCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
Object & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Object & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha, Int32 header, Object & payload) Int32 alpha, Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->CreateObject(model, world, x, y, z, alpha); Int32 id = _Func->CreateObject(model, world, x, y, z, alpha);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{ {
STHROWF("Server returned invalid object: %d", id); STHROWF("Server returned invalid object: %d", id);
} }
// Attempt to allocate this entity and return the result
ObjectInst & inst = m_Objects.at(id); return AllocObject(id, true, header, payload);
inst.mInst = new CObject(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a object instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitObjectCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -589,29 +897,15 @@ Object & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic, Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic); Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{ {
STHROWF("Server returned invalid pickup: %d", id); STHROWF("Server returned invalid pickup: %d", id);
} }
// Attempt to allocate this entity and return the result
PickupInst & inst = m_Pickups.at(id); return AllocPickup(id, true, header, payload);
inst.mInst = new CPickup(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a pickup instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitPickupCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -619,58 +913,30 @@ Object & Core::NewSprite(Int32 index, CSStr file, Int32 xp, Int32 yp,
Int32 xr, Int32 yr, Float32 angle, Int32 alpha, bool rel, Int32 xr, Int32 yr, Float32 angle, Int32 alpha, bool rel,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->CreateSprite(index, file, xp, yp, xr, yr, angle, alpha, rel); Int32 id = _Func->CreateSprite(index, file, xp, yp, xr, yr, angle, alpha, rel);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_SPRITE_POOL))
{ {
STHROWF("Server returned invalid sprite: %d", id); STHROWF("Server returned invalid sprite: %d", id);
} }
// Attempt to allocate this entity and return the result
SpriteInst & inst = m_Sprites.at(id); return AllocSprite(id, true, header, payload);
inst.mInst = new CSprite(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a sprite instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitSpriteCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
Object & Core::NewTextdraw(Int32 index, CSStr text, Int32 xp, Int32 yp, Object & Core::NewTextdraw(Int32 index, CSStr text, Int32 xp, Int32 yp,
Uint32 color, bool rel, Int32 header, Object & payload) Uint32 color, bool rel, Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->CreateTextdraw(index, text, xp, yp, color, rel); Int32 id = _Func->CreateTextdraw(index, text, xp, yp, color, rel);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_TEXTDRAW_POOL))
{ {
STHROWF("Server returned invalid textdraw: %d", id); STHROWF("Server returned invalid textdraw: %d", id);
} }
// Attempt to allocate this entity and return the result
TextdrawInst & inst = m_Textdraws.at(id); return AllocTextdraw(id, true, header, payload);
inst.mInst = new CTextdraw(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a textdraw instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitTextdrawCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
@ -678,29 +944,15 @@ Object & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float3
Float32 angle, Int32 primary, Int32 secondary, Float32 angle, Int32 primary, Int32 secondary,
Int32 header, Object & payload) Int32 header, Object & payload)
{ {
// Request the server to create this entity
Int32 id = _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary); Int32 id = _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary);
// Validate the identifier returned by the server
if (INVALID_ENTITY(id)) if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{ {
STHROWF("Server returned invalid vehicle: %d", id); STHROWF("Server returned invalid vehicle: %d", id);
} }
// Attempt to allocate this entity and return the result
VehicleInst & inst = m_Vehicles.at(id); return AllocVehicle(id, true, header, payload);
inst.mInst = new CVehicle(id);
inst.mObj = Object(inst.mInst, m_VM);
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
STHROWF("Unable to create a vehicle instance for: %d", id);
}
inst.mID = id;
inst.mFlags |= ENF_OWNED;
EmitVehicleCreated(id, header, payload);
return inst.mObj;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------

View File

@ -530,6 +530,19 @@ protected:
static void CompilerErrorHandler(HSQUIRRELVM vm, CSStr desc, CSStr src, static void CompilerErrorHandler(HSQUIRRELVM vm, CSStr desc, CSStr src,
SQInteger line, SQInteger column); SQInteger line, SQInteger column);
/* --------------------------------------------------------------------------------------------
* Instance allocators.
*/
Object & AllocBlip(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocCheckpoint(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocForcefield(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocKeybind(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocObject(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocPickup(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocSprite(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocTextdraw(Int32 id, bool owned, Int32 header, Object & payload);
Object & AllocVehicle(Int32 id, bool owned, Int32 header, Object & payload);
public: public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------