Code Monkey home page Code Monkey logo

cpp-sdk's Introduction

altMP Module SDK

cpp-sdk's People

Contributors

7hazard avatar doxoh avatar durtyfree avatar el-carlitto avatar emcifuntik avatar fabianterhorst avatar leonmrbonnie avatar martonp96 avatar marvisak avatar olegtrofimov avatar vadzz-dev avatar xluxy avatar xxshady avatar zackaryh8 avatar zziger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-sdk's Issues

Getters at IVehicle

Don't you think that the getters in IVehicle should add the const qualifier? And in general, all interfaces seem to need to add noexcept.

Add to SDK.h new files

I think the SDK.h is missing these headers:

#include <events/CFireEvent.h> #include <events/CStartProjectileEvent.h> #include <events/CPlayerWeaponChangeEvent.h> #include <events/CVehicleAttachEvent.h> #include <events/CVehicleDetachEvent.h> #include <events/CNetOwnerChangeEvent.h> #include <events/CPlayerEnteringVehicleEvent.h>

Maybe there are some more. But it seems like everything.

Move instead of copy.

Place

There will be a deep copying of the object, and here just moving it is enough. Change to:
newData[i] = std::move(data[i]);

IColshape::IsEntityIdIn doesn't make sense anymore

I just noticed that some of our old scripts were using IColshape::IsEntityIdIn through JavaScript module, and it got broken. I realized that the definition for the function is maybe wrong / outdated, because there can be entities sharing same id but having a different type.

At latest release version JS module still supports IColshape::IsEntityIdIn, but it doesn't work anymore, IsEntityIn still works.

The CPP-SDK code i'm talking about:

virtual bool IsEntityIdIn(uint16_t id) const = 0;

Support inside Javascript module: https://github.com/altmp/altv-js-module/blob/5ddb005d367c09795c3c61a1523d85c7a1758911/shared/bindings/ColShape.cpp#L7

Cast an explicit double to float.

The compiler complains about the implicit conversion of double to float. Make it explicit so that there is no warning.

Place

Change to:
return (float)(fmod(fmod(ang - PI, TWO_PI) + TWO_PI, TWO_PI) - PI);

Fix wrong IBlip param and return types

The follow methods of the IBlip class have wrong return/arg types:

IBlip::SetScaleXY - Should take one arg that is a Vector2f instead of 2 args for x and y
IBlip::GetGxtName & IBlip::SetGxtName - Return / Arg type should be a StringView instead of const char*
IBlip::GetName & IBlip::SetName - Return / Arg type should be a StringView instead of const char*

`Expected` in ICore create methods

Currently SDK returns nullptr if it fails to create some base object, in some cases not even printing reason of it to console.

Suggestion

Make use of Expected in ICore base objects create methods, so modules implementing alt:V API can provide more info right in code to server developers.

Rust API example (Rust's Result<Ok, Err> is very similar to Expected type in SDK)

let result = altv::VoiceChannel::new(...);
match (result) {
  Ok(channel) => {
    // ...
  }
  Err(altv::VoiceChannelCreationError::VoiceChatIsNotEnabled) => {
    // ...
  }
}

SDK example

auto expected = alt::ICore::Instance().CreateVoiceChannel(...);

if(expected.success) {
    // using expected.value
} else {
  switch(expected.error) {
    case alt::VoiceChannelCreationError::VoiceChatIsNotEnabled:
      // ...
      break;
  }
}

Process events through the ScriptRuntime once instead of multiple times for every resource

Every kind of event gets triggered for every resource, for no good reason other than "the resource might want to handle the event", which leads to duplicative processing (eg. deserialization) of the event when it can be done once if managed from the ScriptRuntime's point of view.

A smarter and more efficient method would be to have ScriptRuntime handle the event. The ScriptHandler would keep track of all event subscriptions in a hash table of handlers and trigger all the handlers for the event in question, once rather that multiple times.

This would also strengthen the reason and possibility of cancelling triggered events.

Add OnCreate/Remove Base object event or callbacks to IServer

For my current Java module, I'll need to keep an updated HashMap with the key being the pointer to the BaseObject and the value being the java BaseObject as there will be a main .jar module. However there is no way for me to update that list on entity creation/deletion if there is currently no resource loaded as I can't subscribe to BaseObject creation/deletion. The only way for me to achieve this would be to use a callback from each resource, which would mean:

  1. I'll need to add unecessary verification, so it adds the entity only one time (as the callback would get called multiple times if there are multiple resources)
  2. If in the future the feature to load resources on the fly (after the server started, so after some entities will be already created) then those resource callbacks wouldn't have been already called and my hashmap would be already out of date (not containing all entities).

I see there is already a RemoveEntityEvent, that could be changed to RemoveBaseObjectEvent and then add another one for CreateBaseObjectEvent, which would allow to use server->SubscribeEvent on both of them, that way I'll be sure I can keep the hashmap up to date even if there is currently no resource loaded.

Possible memory leak

If you move an Array into itself (let's say by a pointer), there will be a memory leak.

Place

You need to add a check.
if (this != &that)

For copying, too, would not hurt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.