Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "g_local.h"
- #include "cgame/cg_local.h"
- #include <vector>
- // RTLED - Realtime Light Editor for rend2
- #define RTLCMD_NOOPTIONAL 1 // No optional arguments allowed
- #define RTLCMD_INRTLED 2 // Only allowed to access this command when RTLEd is enabled
- #define RTLCMD_SELECTED 4 // This command requires a selected light
- enum realtimeLightStyle_e {
- RL_POINTLIGHT,
- RL_SPOTLIGHT,
- RL_TUBELIGHT
- };
- struct rtlCmd_t {
- char* command;
- char* usage;
- char* help;
- int flags;
- int minimumArgs;
- void (*Command)(gentity_t*);
- };
- struct realtimeLight_t;
- rtlCmd_t rtlCommands[];
- realtimeLight_t* selectedLight = nullptr;
- std::vector<realtimeLight_t> lights;
- qboolean rtlEdEnabled = qfalse;
- qboolean rtlHudEnabled = qtrue;
- int lastUsedLightNum = 0;
- struct realtimeLight_t {
- int lightNum;
- realtimeLightStyle_e lightStyle;
- qboolean bSelected;
- qboolean bLightPreview;
- vec3_t origin;
- vec3_t orientation;
- qboolean bUseTemperature;
- vec3_t color;
- float temperature;
- float attenuation;
- float intensity;
- float radius;
- float length;
- realtimeLight_t() {
- realtimeLight_t(lastUsedLightNum++, g_entities[0].currentOrigin);
- }
- realtimeLight_t(int _lightNum, vec3_t _origin) {
- lightNum = _lightNum;
- bSelected = qtrue;
- selectedLight->bSelected = qfalse;
- selectedLight = this;
- VectorCopy(_origin, origin);
- VectorClear(orientation);
- bUseTemperature = qfalse;
- temperature = 1000.0f;
- bLightPreview = qtrue;
- lightStyle = RL_POINTLIGHT;
- attenuation = 128.0f;
- intensity = 300.0f;
- radius = 128.0f;
- length = 50.0f;
- gi.Printf("Created new light: %i\n", lightNum);
- gi.Printf("Selected light: %i\n", lightNum);
- }
- realtimeLight_t(realtimeLight_t& other) {
- realtimeLight_t(lastUsedLightNum++, other.origin);
- gi.Printf("Copying light %i\n", other.lightNum);
- VectorCopy(other.orientation, orientation);
- bUseTemperature = other.bUseTemperature;
- temperature = other.temperature;
- bLightPreview = other.bLightPreview;
- lightStyle = other.lightStyle;
- attenuation = other.attenuation;
- intensity = other.intensity;
- radius = other.radius;
- length = other.length;
- }
- ~realtimeLight_t() {
- gi.Printf("Deleted light: %i\n", lightNum);
- if (bSelected) {
- selectedLight = nullptr;
- }
- }
- };
- void Rtl_f(gentity_t* ent) {
- rtlEdEnabled = (qboolean)!rtlEdEnabled;
- if (rtlEdEnabled) {
- gi.Printf("Realtime Lighting Editor enabled\n");
- }
- else {
- gi.Printf("Realtime Lighting Editor disabled\n");
- }
- }
- void Rtl_Help_f(gentity_t* ent) {
- }
- void Rtl_Hud_f(gentity_t* ent) {
- rtlHudEnabled = (qboolean)!rtlHudEnabled;
- if (rtlHudEnabled) {
- gi.Printf("Realtime Lighting Editor HUD enabled\n");
- }
- else {
- gi.Printf("Realtime Lighting Editor HUD disabled\n");
- }
- }
- void Rtl_List_f(gentity_t* ent) {
- int i = 0;
- gi.Printf("List of Realtime Lighting editor commands:\n\n");
- while (rtlCommands[i].Command) {
- gi.Printf("\t ^%i%s^%i - ^%i%s\n", COLOR_YELLOW, rtlCommands[i].command, COLOR_WHITE, COLOR_CYAN, rtlCommands[i].usage);
- i++;
- }
- }
- void Rtl_Select_f(gentity_t* ent) {
- int lightNum = atoi(gi.argv(1));
- if (lightNum < 0 || lightNum >= lights.size()) {
- gi.Printf("Invalid light number, must be between 0 and %d\n", lastUsedLightNum);
- }
- for (auto it = lights.begin(); it != lights.end(); ++it) {
- if (it->lightNum == lightNum) {
- selectedLight = &(*it);
- gi.Printf("Selected light %d\n", lightNum);
- return;
- }
- }
- gi.Printf("Couldn't find light %d\n", lightNum);
- }
- void Rtl_Info_f(gentity_t* ent) {
- gi.Printf("LIGHT %d ", selectedLight->lightNum);
- switch (selectedLight->lightStyle) {
- case RL_POINTLIGHT:
- gi.Printf("(POINT)\n");
- break;
- case RL_SPOTLIGHT:
- gi.Printf("(SPOT)\n");
- break;
- case RL_TUBELIGHT:
- gi.Printf("(TUBE)\n");
- break;
- }
- gi.Printf("Origin: %.2f %.2f %.2f\n", selectedLight->origin[0], selectedLight->origin[1], selectedLight->origin[2]);
- gi.Printf("Orientation: %.2f %.2f %.2f\n", selectedLight->orientation[0], selectedLight->orientation[1], selectedLight->orientation[2]);
- if (selectedLight->bLightPreview) {
- gi.Printf("IN PREVIEW\n");
- }
- if (selectedLight->bUseTemperature) {
- gi.Printf("Temperature: %.2f\n", selectedLight->temperature);
- }
- else {
- gi.Printf("RGB Color: %.2f %.2f %.2f\n", selectedLight->color[0], selectedLight->color[1], selectedLight->color[2]);
- }
- gi.Printf("Radius: %.2f\n", selectedLight->radius);
- gi.Printf("Intensity: %.2f\n", selectedLight->intensity);
- gi.Printf("Attenuation: %.2f\n", selectedLight->attenuation);
- gi.Printf("Length: %.2f\n", selectedLight->length);
- }
- void Rtl_New_f(gentity_t* ent) {
- realtimeLight_t light;
- lights.push_back(light);
- }
- void Rtl_Delete_f(gentity_t* ent) {
- if (gi.argc() > 1) {
- int num = atoi(gi.argv(1));
- for (auto it = lights.begin(); it != lights.end(); ++it) {
- if (it->lightNum == num) {
- it = lights.erase(it);
- return;
- }
- }
- gi.Printf("Could not find light number %i\n");
- }
- else if (selectedLight != nullptr) {
- for (auto it = lights.begin(); it != lights.end(); ++it) {
- if (it->lightNum == selectedLight->lightNum) {
- it = lights.erase(it);
- return;
- }
- }
- }
- else {
- gi.Printf("Usage: rtl_delete [index]\n");
- }
- }
- void Rtl_DeleteAll_f(gentity_t* ent) {
- size_t len = lights.size();
- selectedLight = nullptr;
- lights.clear();
- gi.Printf("Deleted %d lights\n", len);
- }
- void Rtl_Save_f(gentity_t* ent) {
- }
- void Rtl_Load_f(gentity_t* ent) {
- }
- void Rtl_Style_f(gentity_t* ent) {
- char* style = gi.argv(1);
- if (!Q_stricmp(style, "point")) {
- selectedLight->lightStyle = RL_POINTLIGHT;
- }
- else if (!Q_stricmp(style, "tube")) {
- selectedLight->lightStyle = RL_TUBELIGHT;
- }
- else if (!Q_stricmp(style, "spot")) {
- selectedLight->lightStyle = RL_SPOTLIGHT;
- }
- }
- void Rtl_Color_f(gentity_t* ent) {
- float r = atof(gi.argv(1));
- float g = atof(gi.argv(2));
- float b = atof(gi.argv(3));
- vec3_t color = { r, g, b };
- if (selectedLight->bUseTemperature) {
- gi.Printf("This light uses temperature settings instead of RGB color. \n\
- Use the temperature command first to enable RGB color.\n");
- return;
- }
- VectorCopy(color, selectedLight->color);
- }
- void Rtl_Temperature_f(gentity_t* ent) {
- int usetemp = atoi(gi.argv(1));
- if (usetemp) {
- selectedLight->bUseTemperature = qtrue;
- }
- else {
- selectedLight->bUseTemperature = qfalse;
- }
- if (gi.argc() > 2) {
- float temp = atof(gi.argv(2));
- selectedLight->temperature = temp;
- }
- }
- void Rtl_Attenuation_f(gentity_t* ent) {
- float atten = atof(gi.argv(1));
- selectedLight->attenuation = atten;
- }
- void Rtl_Intensity_f(gentity_t* ent) {
- float intensity = atof(gi.argv(1));
- selectedLight->intensity = intensity;
- }
- void Rtl_Radius_f(gentity_t* ent) {
- float radius = atof(gi.argv(1));
- selectedLight->radius = radius;
- }
- void Rtl_Length_f(gentity_t* ent) {
- float length = atof(gi.argv(1));
- selectedLight->length = length;
- }
- void Rtl_Orientation_f(gentity_t* ent) {
- float pitch = atof(gi.argv(1));
- float yaw = atof(gi.argv(2));
- float roll = atof(gi.argv(3));
- vec3_t angles = { pitch, yaw, roll };
- VectorCopy(selectedLight->orientation, angles);
- }
- void Rtl_Origin_f(gentity_t* ent) {
- VectorCopy(ent->currentOrigin, selectedLight->origin);
- gi.Printf("Light moved to %.2f %.2f %.2f\n", selectedLight->origin[0], selectedLight->origin[1], selectedLight->origin[2]);
- }
- void Rtl_Nudge_f(gentity_t* ent) {
- float nudgeX = atof(gi.argv(1));
- float nudgeY = atof(gi.argv(2));
- float nudgeZ = atof(gi.argv(3));
- selectedLight->origin[0] += nudgeX;
- selectedLight->origin[1] += nudgeY;
- selectedLight->origin[2] += nudgeZ;
- gi.Printf("Light moved to %.2f %.2f %.2f\n", selectedLight->origin[0], selectedLight->origin[1], selectedLight->origin[2]);
- }
- void Rtl_Preview_f(gentity_t* ent) {
- selectedLight->bLightPreview = (qboolean)!selectedLight->bLightPreview;
- if (selectedLight->bLightPreview) {
- gi.Printf("Preview mode enabled\n");
- }
- else {
- gi.Printf("Preview mode disabled\n");
- }
- }
- rtlCmd_t rtlCommands[] = {
- {
- "rtl",
- "rtl",
- "Toggles the rend2 Realtime Light Editor (\"SLIGHTED\")",
- RTLCMD_NOOPTIONAL,
- 0,
- Rtl_f
- },
- {
- "rtl_help",
- "rtl_help [command name]",
- "Lists all of the commands, or probes a specific command for help.",
- 0,
- 0,
- Rtl_Help_f
- },
- {
- "rtl_hud",
- "rtl_hud",
- "Toggles the SLIGHTED heads up display",
- RTLCMD_NOOPTIONAL | RTLCMD_INRTLED,
- 0,
- Rtl_Hud_f
- },
- {
- "rtl_list",
- "rtl_list",
- "Lists all of the static lights on the map.",
- RTLCMD_INRTLED | RTLCMD_NOOPTIONAL,
- 0,
- Rtl_List_f
- },
- {
- "rtl_select",
- "rtl_select <index>",
- "Selects a specific light index.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL,
- 1,
- Rtl_Select_f
- },
- {
- "rtl_info",
- "rtl_info [index]",
- "Retrieves all possible info about either a specific light index or the currently selected light.",
- RTLCMD_INRTLED,
- 0,
- Rtl_Info_f
- },
- {
- "rtl_new",
- "rtl_new",
- "Creates a new light",
- RTLCMD_INRTLED | RTLCMD_NOOPTIONAL,
- 0,
- Rtl_New_f
- },
- {
- "rtl_delete",
- "rtl_delete [index]",
- "Deletes either the currently selected light, or a specific index.",
- RTLCMD_INRTLED,
- 0,
- Rtl_Delete_f
- },
- {
- "rtl_deleteall",
- "rtl_deleteall",
- "Deletes all static lights on the level",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL,
- 0,
- Rtl_DeleteAll_f
- },
- {
- "rtl_save",
- "rtl_save [filename]",
- "Saves all of the static lights. The name of the map is the default file name.",
- RTLCMD_INRTLED,
- 0,
- Rtl_Save_f
- },
- {
- "rtl_load",
- "rtl_load [filename]",
- "Purges all of the existing static lights and loads a new file. The default is the name of the map.",
- RTLCMD_INRTLED,
- 0,
- Rtl_Load_f
- },
- {
- "rtl_style",
- "rtl_style <style>",
- "Tells the renderer how this light should be rendered. 'Style' can be one of the following: \n\
- 'point' for pointlights \n\
- 'tube' for tubelights \n\
- 'spot' for spotlights \n",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 1,
- Rtl_Style_f
- },
- {
- "rtl_color",
- "rtl_color <R> <G> <B>",
- "Adjusts the color of the currently selected light. The color values should be between 0 and 1.0. \n\
- This command doesn't do anything if temperature-based lighting is enabled for this light.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 3,
- Rtl_Color_f
- },
- {
- "rtl_temperature",
- "rtl_temperature <0/1> [Temperature]",
- "Use temperature-based lighting instead of RGB? (true/false) \n\
- The second parameter uses the Kelvin scale (default temperature is 1000 degrees).",
- RTLCMD_INRTLED|RTLCMD_SELECTED,
- 1,
- Rtl_Temperature_f
- },
- {
- "rtl_attenuation",
- "rtl_attenuation <radius>",
- "Adjusts the attenuation radius of the light, or how far the light reaches.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 1,
- Rtl_Attenuation_f
- },
- {
- "rtl_intensity",
- "rtl_intensity <intensity>",
- "Adjusts how intense the light is, or how brightly it appears.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 1,
- Rtl_Intensity_f
- },
- {
- "rtl_radius",
- "rtl_radius <radius>",
- "Adjusts the radius of the light, or how large the emitting light source should be.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 1,
- Rtl_Radius_f
- },
- {
- "rtl_length",
- "rtl_length <length>",
- "For tubelights only - adjusts how long the emitting light source should be.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 1,
- Rtl_Length_f
- },
- {
- "rtl_orientation",
- "rtl_orientation <pitch> <yaw> <roll>",
- "For spotlights and tubelights only - adjusts the angle that the light is facing.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 3,
- Rtl_Orientation_f
- },
- {
- "rtl_origin",
- "rtl_origin",
- "Moves the light to your current player origin.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 0,
- Rtl_Origin_f
- },
- {
- "rtl_nudge",
- "rtl_nudge <X> <Y> <Z>",
- "Moves the light a certain number of units in a particular direction.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 3,
- Rtl_Nudge_f
- },
- {
- "rtl_preview",
- "rtl_preview",
- "Toggles previewing of this light. \n\
- Note that if a light already has static lights on it, this will lead to an incorrect preview. \n\
- Only pointlights can be previewed.",
- RTLCMD_INRTLED|RTLCMD_NOOPTIONAL|RTLCMD_SELECTED,
- 0,
- Rtl_Preview_f
- },
- {
- nullptr,
- nullptr,
- nullptr,
- 0, 0,
- nullptr
- }
- };
- qboolean Rend2Enabled() {
- return qtrue; // TODO: need a better method of determining this.
- }
- qboolean Rtl_Command_f(gentity_t* ent) {
- int i = 0;
- int argc = gi.argc();
- char* cmd = gi.argv(0);
- if (!Rend2Enabled()) {
- return qfalse;
- }
- while (rtlCommands[i].command) {
- if (!Q_stricmp(rtlCommands[i].command, cmd)) {
- if (argc - 1 < rtlCommands[i].minimumArgs) {
- usage:
- gi.Printf("usage: %s\n", rtlCommands[i].usage);
- }
- else if (argc - 1 != rtlCommands[i].minimumArgs && rtlCommands[i].flags & RTLCMD_NOOPTIONAL) {
- goto usage;
- }
- else if (rtlCommands[i].flags & RTLCMD_INRTLED && !rtlEdEnabled) {
- gi.Printf("The Realtime Lighting Editor must be enabled to use this command.\n\
- (Hint: try enabling it with \"rtl\")\n");
- }
- else if (rtlCommands[i].flags & RTLCMD_SELECTED && selectedLight == nullptr) {
- gi.Printf("You need to select a light in order to use this command.\n\
- (Hint: you can select a light using \"rtl_select\".)\n");
- }
- else {
- rtlCommands[i].Command(ent);
- }
- return qtrue;
- }
- i++;
- }
- return qfalse;
- }
- // Initialization / shutdown code, which occurs at the start and end of the game, or upon level load.
- // This is responsible for loading the realtime lighting file which rend2 uses.
- void Rtl_Initialize() {
- if (!Rend2Enabled()) {
- return;
- }
- // When we load the .rtl file, we keep the array of lights alive so that we can open them up in the editor if we want to.
- }
- void Rtl_Shutdown() {
- // Just remove the light list
- lights.clear();
- selectedLight = nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment